All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Hugh Dickins <hughd@google.com>
Cc: Ming Lin <mlin@kernel.org>, Simon Ser <contact@emersion.fr>,
	Linux-MM <linux-mm@kvack.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	Linux API <linux-api@vger.kernel.org>
Subject: Re: [PATCH 2/2] mm: adds NOSIGBUS extension for out-of-band shmem read
Date: Thu, 3 Jun 2021 11:25:15 -0700	[thread overview]
Message-ID: <CAHk-=wiHJ2GF503wnhCC4jsaSWNyq5=NqOy7jpF_v_t82AY0UA@mail.gmail.com> (raw)
In-Reply-To: <alpine.LSU.2.11.2106021719500.8333@eggly.anvils>

[-- Attachment #1: Type: text/plain, Size: 1973 bytes --]

On Wed, Jun 2, 2021 at 5:46 PM Hugh Dickins <hughd@google.com> 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

[-- Attachment #2: VM_NOSIGBUS.patch --]
[-- Type: text/x-patch, Size: 904 bytes --]

 mm/memory.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index 550405fc3b5e..bbede6b52f7a 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -4312,10 +4312,21 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf)
 	}
 
 	if (!vmf->pte) {
-		if (vma_is_anonymous(vmf->vma))
-			return do_anonymous_page(vmf);
-		else
-			return do_fault(vmf);
+		if (!vma_is_anonymous(vmf->vma)) {
+			vm_fault_t ret = do_fault(vmf);
+			if (ret & VM_FAULT_RETRY)
+				return ret;
+			if (!(ret & VM_FAULT_SIGBUS))
+				return ret;
+/* FIXME! We don't have a VM_NOFAULT bit */
+#if 0
+			/* See if we should turn a SIGBUS into an anonymous page */
+			if (!(vma->vm_flags & VM_NOFAULT))
+				return ret;
+#endif
+/* Fall back on do_anonymous_page() instead of SIGBUS */
+		}
+		return do_anonymous_page(vmf);
 	}
 
 	if (!pte_present(vmf->orig_pte))

  reply	other threads:[~2021-06-03 18:25 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-01 23:22 [PATCH 0/2] mm: adds MAP_NOSIGBUS extension for shmem read Ming Lin
2021-06-01 23:22 ` [PATCH 1/2] mm: make "vm_flags" be an u64 Ming Lin
2021-06-02  1:58   ` kernel test robot
2021-06-02  1:58     ` kernel test robot
2021-06-02  2:06   ` kernel test robot
2021-06-02  2:06     ` kernel test robot
2021-06-01 23:22 ` [PATCH 2/2] mm: adds NOSIGBUS extension for out-of-band shmem read Ming Lin
2021-06-02  0:16   ` Linus Torvalds
2021-06-02  0:16     ` Linus Torvalds
2021-06-02  1:06     ` Ming Lin
2021-06-02  1:06       ` Ming Lin
2021-06-02  2:13     ` Hugh Dickins
2021-06-02  2:13       ` Hugh Dickins
2021-06-02  2:02   ` kernel test robot
2021-06-02  2:02     ` kernel test robot
2021-06-02  3:49   ` Hugh Dickins
2021-06-02  3:49     ` Hugh Dickins
2021-06-03  0:05     ` Ming Lin
2021-06-03  0:46       ` Hugh Dickins
2021-06-03  0:46         ` Hugh Dickins
2021-06-03 18:25         ` Linus Torvalds [this message]
2021-06-03 18:25           ` Linus Torvalds
2021-06-03 19:07           ` Hugh Dickins
2021-06-03 19:07             ` Hugh Dickins
2021-06-03 19:12             ` Linus Torvalds
2021-06-03 19:12               ` Linus Torvalds
2021-06-03 19:15               ` Linus Torvalds
2021-06-03 19:15                 ` Linus Torvalds
2021-06-03 19:24               ` Andy Lutomirski
2021-06-03 19:35                 ` Simon Ser
2021-06-03 19:57         ` Ming Lin
2021-06-02  9:30   ` kernel test robot
2021-06-02  9:30     ` kernel test robot
2021-06-02  0:16 kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHk-=wiHJ2GF503wnhCC4jsaSWNyq5=NqOy7jpF_v_t82AY0UA@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=contact@emersion.fr \
    --cc=hughd@google.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mlin@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.