Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp486738pxj; Thu, 3 Jun 2021 11:29:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwNjyOcMISY0qi76QN3V3ZEetLvyDqGagMUO9WwRYEL2QK5SoJHJuUZxebqiSvM+qIUnF3 X-Received: by 2002:aa7:c787:: with SMTP id n7mr764806eds.309.1622744986275; Thu, 03 Jun 2021 11:29:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622744986; cv=none; d=google.com; s=arc-20160816; b=kGOm+lEosGJxptD+6ZWs3MYpNI7PdeeuP+7lEA3W7jGp78SwwNfltlSymApPvtCvEF XwugaJPC7aqAfRspoauGH58BlC6Vz2LhPbhvfIcR/VU815CdwPRsHISfEawrcwSdhEfb m7xT5o7Ym/5Mqd2kHcmBO2YUVwJqUk8G8x8lk19lTnadyUQQTnqe96QtxTPr7nUXQl4W K7AWqn4yTVou9jNh+Ic4cnvDPV4mPKnBhfAH1LxTM5ZQhd6QJJS1JE6svzOYtJ2BO02+ 4aO5OXNm8kqT6b2NzyrQAbHnuL6f2MjnK9ovxwtU3iKPB0BZC0mEi5L9tJ6WCLZlE7zr YbcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=4yrZQXkdoWWUth91gvSrDmAM3rcJ5jau3LD6S8sHHrE=; b=sSN36Hq7fFZJ10fKMQ/+ZAHYvFx8f4hnWbyRHtjKyBFuQTjE7ScjHjy5b+S1x0mzUs vEIc859xrk8wyOq/o34SlPQ9+q076CuQOgtsW74pkVB83BHoqgpvF3MWNtpBw34O7w6u THIripF1BTMbvasmFB6af3kVRdW86DoEtiJQOSzFo5sOzPyh9pwV88A9+iz5T9ds2P8P fv/P5Kx8eu//OaHjM5S+kZ1eN5Rnb+KJqKmq8VFMnAN8u/cZD5mBYgNYG+crtGB2xGSP cNDZ+M5g5n/tKCn4ZKCR8refLX0cA6wWe4IagWpRHKoBOyvtdAM9TIo2IUqi/sQwoKd7 FQuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="gkR0j3P/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f22si2605052ejb.54.2021.06.03.11.29.23; Thu, 03 Jun 2021 11:29:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="gkR0j3P/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229888AbhFCS1Y (ORCPT + 99 others); Thu, 3 Jun 2021 14:27:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229835AbhFCS1X (ORCPT ); Thu, 3 Jun 2021 14:27:23 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D746C06174A for ; Thu, 3 Jun 2021 11:25:38 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id p17so9485599lfc.6 for ; Thu, 03 Jun 2021 11:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4yrZQXkdoWWUth91gvSrDmAM3rcJ5jau3LD6S8sHHrE=; b=gkR0j3P/e9anWMAAzOG92R2BRdjIWlcLHPCDChWlOGqnJaz0+Qapx/QB8tuetiHiLa pApFXNfaBQHl1JPVrc5YeamoGvFC963PMzsbyIHRnLn4JEK7WnSBLFslEPF/9i84DqDU 2G1JcwH8LYKBmJsEWWHWGdS86Fq7CrthuiDI4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4yrZQXkdoWWUth91gvSrDmAM3rcJ5jau3LD6S8sHHrE=; b=uDp7kfLK6JTg7KdJX4lkbaGZ17Yfc4acV5fKCp459nlmZhxWd94MyUdjJt5A9Tnj0V 1ZICPDA6TP9IC9sryE7bPszPIt0xXYNgyu3RZ4Xq8/ppH17aHJzFZ5xbIOSJ5fvsQfmX LpUY0He9NE5TjS2ZMO0ZBvR0uvc89FoKNzvceMO+jopeVkc+XQnJrHmK60JzIFZ/z79a lP5YcpjsJzgBLXJC6dAFLlIJVcvUjXGIx8gUa6MLyDcsb6PEQxvsEZFuqV9y4HpgMvNO Fvc0UmBfd2Emncmnjah6u/hQBVXAtlgFwfZi2wde5dmY3gv5eZ7ovy0c2UqEJVupV6ka Pd0g== X-Gm-Message-State: AOAM531B00uWIZ9+Vc8WAwwo8NnW9c61Yxw8xO0JAtWM8soj2KWIHfNa 4ykRF4fUWJrNs/SySPMAo6rPiNkZJrh6Wozr X-Received: by 2002:a19:8b57:: with SMTP id n84mr165230lfd.13.1622744733211; Thu, 03 Jun 2021 11:25:33 -0700 (PDT) Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com. [209.85.167.43]) by smtp.gmail.com with ESMTPSA id c17sm383599lfi.295.2021.06.03.11.25.32 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Jun 2021 11:25:32 -0700 (PDT) Received: by mail-lf1-f43.google.com with SMTP id w33so10253711lfu.7 for ; Thu, 03 Jun 2021 11:25:32 -0700 (PDT) X-Received: by 2002:a05:6512:374b:: with SMTP id a11mr151892lfs.377.1622744732051; Thu, 03 Jun 2021 11:25:32 -0700 (PDT) MIME-Version: 1.0 References: <1622589753-9206-1-git-send-email-mlin@kernel.org> <1622589753-9206-3-git-send-email-mlin@kernel.org> <79a27014-5450-1345-9eea-12fc9ae25777@kernel.org> In-Reply-To: From: Linus Torvalds Date: Thu, 3 Jun 2021 11:25:15 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/2] mm: adds NOSIGBUS extension for out-of-band shmem read To: Hugh Dickins Cc: Ming Lin , Simon Ser , Linux-MM , Linux Kernel Mailing List , linux-fsdevel , Linux API Content-Type: multipart/mixed; boundary="00000000000050d9e705c3e0b31f" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --00000000000050d9e705c3e0b31f Content-Type: text/plain; charset="UTF-8" On Wed, Jun 2, 2021 at 5:46 PM Hugh Dickins wrote: > > Ideally you can simply call do_anonymous_page() from __do_fault() > in the VM_FAULT_SIGBUS on VM_NOSIGBUS case. Heh. We're actually then back to my original patch. That one doesn't handle shared mappings (even read-only ones), for the simple reason that do_anonymous_page() refuses to insert anonymous pages into a shared mapping, and has /* File mapping without ->vm_ops ? */ if (vma->vm_flags & VM_SHARED) return VM_FAULT_SIGBUS; at the very top. But yes, if we just remove that check, I think my original patch should actually "JustWork(tm)". I'm attaching it again, with old name and old commentary (ie that /* FIXME! We don't have a VM_NOFAULT bit */ should just be replaced with that VM_NOSIGBUS bit instead, and the #if'ed out region should be enabled. Oh, and we need to think hard about one more case: mprotect(). In particular, I think the attached patch fails horribly for the case of a shared mapping that starts out read-only, then inserts a zero page, then somebody does mprotect(MAP_WRITE), and then writes to the page. I haven't checked what the write protect fault handler does, but I think that for a shared mapping it will just make the page dirty and writable. Which would be horribly wrong for VM_NOSIGBUS. So that support infrastructure that adds MAP_NOSIGBUS, and checks that it is only done on a read-only mapping, also has to make sure that it clears the VM_MAYWRITE bit when it sets VM_NOSIGBUS. That way mprotect can't then later make it writable. Hugh, comments on this approach? Again: this patch is my *OLD* one, I didn't try to update it to the new world order. It requires - Ming's MAP_NOSIGBUS ccode - removal of that "File mapping without ->vm_ops" case - that FIXME fixed and name updated - and that VM_MAYWRITE clearing if VM_NOSIGBUS is set, to avoid the mprotect issue. Hmm? Linus --00000000000050d9e705c3e0b31f Content-Type: text/x-patch; charset="US-ASCII"; name="VM_NOSIGBUS.patch" Content-Disposition: attachment; filename="VM_NOSIGBUS.patch" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_kph87e4o0 IG1tL21lbW9yeS5jIHwgMTkgKysrKysrKysrKysrKysrLS0tLQogMSBmaWxlIGNoYW5nZWQsIDE1 IGluc2VydGlvbnMoKyksIDQgZGVsZXRpb25zKC0pCgpkaWZmIC0tZ2l0IGEvbW0vbWVtb3J5LmMg Yi9tbS9tZW1vcnkuYwppbmRleCA1NTA0MDVmYzNiNWUuLmJiZWRlNmI1MmY3YSAxMDA2NDQKLS0t IGEvbW0vbWVtb3J5LmMKKysrIGIvbW0vbWVtb3J5LmMKQEAgLTQzMTIsMTAgKzQzMTIsMjEgQEAg c3RhdGljIHZtX2ZhdWx0X3QgaGFuZGxlX3B0ZV9mYXVsdChzdHJ1Y3Qgdm1fZmF1bHQgKnZtZikK IAl9CiAKIAlpZiAoIXZtZi0+cHRlKSB7Ci0JCWlmICh2bWFfaXNfYW5vbnltb3VzKHZtZi0+dm1h KSkKLQkJCXJldHVybiBkb19hbm9ueW1vdXNfcGFnZSh2bWYpOwotCQllbHNlCi0JCQlyZXR1cm4g ZG9fZmF1bHQodm1mKTsKKwkJaWYgKCF2bWFfaXNfYW5vbnltb3VzKHZtZi0+dm1hKSkgeworCQkJ dm1fZmF1bHRfdCByZXQgPSBkb19mYXVsdCh2bWYpOworCQkJaWYgKHJldCAmIFZNX0ZBVUxUX1JF VFJZKQorCQkJCXJldHVybiByZXQ7CisJCQlpZiAoIShyZXQgJiBWTV9GQVVMVF9TSUdCVVMpKQor CQkJCXJldHVybiByZXQ7CisvKiBGSVhNRSEgV2UgZG9uJ3QgaGF2ZSBhIFZNX05PRkFVTFQgYml0 ICovCisjaWYgMAorCQkJLyogU2VlIGlmIHdlIHNob3VsZCB0dXJuIGEgU0lHQlVTIGludG8gYW4g YW5vbnltb3VzIHBhZ2UgKi8KKwkJCWlmICghKHZtYS0+dm1fZmxhZ3MgJiBWTV9OT0ZBVUxUKSkK KwkJCQlyZXR1cm4gcmV0OworI2VuZGlmCisvKiBGYWxsIGJhY2sgb24gZG9fYW5vbnltb3VzX3Bh Z2UoKSBpbnN0ZWFkIG9mIFNJR0JVUyAqLworCQl9CisJCXJldHVybiBkb19hbm9ueW1vdXNfcGFn ZSh2bWYpOwogCX0KIAogCWlmICghcHRlX3ByZXNlbnQodm1mLT5vcmlnX3B0ZSkpCg== --00000000000050d9e705c3e0b31f--