From: Hugh Dickins <hughd@google.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Hugh Dickins <hughd@google.com>, 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 12:07:18 -0700 (PDT) [thread overview]
Message-ID: <alpine.LSU.2.11.2106031142250.11088@eggly.anvils> (raw)
In-Reply-To: <CAHk-=wiHJ2GF503wnhCC4jsaSWNyq5=NqOy7jpF_v_t82AY0UA@mail.gmail.com>
On Thu, 3 Jun 2021, Linus Torvalds wrote:
> 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)".
But no!
Sorry, I don't have time for this at present, so haven't looked at
your original patch.
But the point that we've arrived at, that I'm actually now fairly
happy with, is do *not* permit MAP_NOSIGBUS on MAP_SHARED mappings.
I didn't check the placement yet, easy to get wrong, but I believe
Ming Lin is now enforcing that over at the mmap() end.
On a MAP_PRIVATE mapping, the nasty opaque blob of zeroes can
claim some precedent in what already happens with COW'ed pages.
Which leaves MAP_NOSIGBUS on MAP_SHARED as currently unsupported,
perhaps never supported on anything, perhaps one day supported on
shmem; but if it's ever supported then that one will naturally be
transparent to future changes in page cache - we call that "shared".
Of course, internally, there's the in-between case of MAP_SHARED
without PROT_WRITE and without writable fd: VM_MAYSHARE without
VM_SHARED or VM_MAYWRITE. We *could* let that one accept
MAP_NOSIGBUS, but who wants to write the manpage for it?
Please stick to MAP_PRIVATE: that's good enough.
>
> 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.
Obviously the finished patch will need to be scrutinized carefully, but
I think the mprotect() questions vanish when restricted to MAP_PRIVATE.
>
> 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?
Comments above, just stick to MAP_PRIVATE.
Hugh
>
> 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
next prev parent reply other threads:[~2021-06-03 19:07 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-01 23:22 [PATCH 0/2] mm: adds MAP_NOSIGBUS extension for " 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 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 1:06 ` Ming Lin
2021-06-02 2:13 ` Hugh Dickins
2021-06-02 2:02 ` kernel test robot
2021-06-02 3:49 ` Hugh Dickins
2021-06-03 0:05 ` Ming Lin
2021-06-03 0:46 ` Hugh Dickins
2021-06-03 18:25 ` Linus Torvalds
2021-06-03 19:07 ` Hugh Dickins [this message]
2021-06-03 19:12 ` 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
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=alpine.LSU.2.11.2106031142250.11088@eggly.anvils \
--to=hughd@google.com \
--cc=contact@emersion.fr \
--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 \
--cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox