From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: David Hildenbrand <david@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Suren Baghdasaryan <surenb@google.com>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
Matthew Wilcox <willy@infradead.org>,
"Paul E . McKenney" <paulmck@kernel.org>,
Jann Horn <jannh@google.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Shuah Khan <shuah@kernel.org>,
linux-kselftest@vger.kernel.org, linux-api@vger.kernel.org,
John Hubbard <jhubbard@nvidia.com>,
Juan Yescas <jyescas@google.com>,
Kalesh Singh <kaleshsingh@google.com>
Subject: Re: [PATCH 0/4] mm: permit guard regions for file-backed/shmem mappings
Date: Tue, 25 Feb 2025 16:37:40 +0000 [thread overview]
Message-ID: <3102ab3b-67b6-4047-9db7-e83c3b9c1c53@lucifer.local> (raw)
In-Reply-To: <e0954e13-2c7d-447c-ba86-19875c74bc3b@suse.cz>
On Tue, Feb 25, 2025 at 04:54:22PM +0100, Vlastimil Babka wrote:
> On 2/18/25 18:28, Lorenzo Stoakes wrote:
> > On Tue, Feb 18, 2025 at 06:25:35PM +0100, David Hildenbrand wrote:
> >>
> >> > > >
> >> > > > It fails because it tries to 'touch' the memory, but 'touching' guard
> >> > > > region memory causes a segfault. This kind of breaks the idea of
> >> > > > mlock()'ing guard regions.
> >> > > >
> >> > > > I think adding workarounds to make this possible in any way is not really
> >> > > > worth it (and would probably be pretty gross).
> >> > > >
> >> > > > We already document that 'mlock()ing lightweight guard regions will fail'
> >> > > > as per man page so this is all in line with that.
> >> > >
> >> > > Right, and I claim that supporting VM_LOCKONFAULT might likely be as easy as
> >> > > allowing install/remove of guard regions when that flag is set.
> >> >
> >> > We already allow this flag! VM_LOCKED and VM_HUGETLB are the only flags we
> >> > disallow.
> >>
> >>
> >> See mlock2();
> >>
> >> SYSCALL_DEFINE3(mlock2, unsigned long, start, size_t, len, int, flags)
> >> {
> >> vm_flags_t vm_flags = VM_LOCKED;
> >>
> >> if (flags & ~MLOCK_ONFAULT)
> >> return -EINVAL;
> >>
> >> if (flags & MLOCK_ONFAULT)
> >> vm_flags |= VM_LOCKONFAULT;
> >>
> >> return do_mlock(start, len, vm_flags);
> >> }
> >>
> >>
> >> VM_LOCKONFAULT always as VM_LOCKED set as well.
> >
> > OK cool, that makes sense.
> >
> > As with much kernel stuff, I knew this in the past. Then I forgot. Then I knew
> > again, then... :P if only somebody would write it down in a book...
> >
> > Yeah then that makes sense to check explicitly for (VM_LOCKED | VM_LOCKONFAULT)
> > in any MADV_GUARD_INSTALL_LOCKED variant as obviously this would be passively
> > excluded right now.
>
> Sorry for the late reply. So AFAIU from your conversations, guards can't be
> compatible with VM_LOCKED, which means e.g. any attempts of glibc to use
> guards for stacks will soon discover that mlockall() users exist and are
> broken by this, and the attempts will fail? That's a bummer.
>
Yeah damn, this pushes up the priority on this.
Yeah unfortunately we cannot support this with guard regions being installed
_after_ the mlockall() but can for before.
Let me write this on my eternal whiteboard of doom (TM), because that ups the
priority on this. I want to have a good think and see if it might after all be
possible to find a way to make things work here for sake of this case.
This thing is already shipped now, so it is inevitably going to be an add-on.
I will try some experiments when I get a sec.
Thanks very much for bringing this point up! This is pretty key.
> As for compatibility with VM_LOCKONFAULT, do we need a new
> MADV_GUARD_INSTALL_LOCKED or can we say MADV_GUARD_INSTALL is new enough
> that it can be just retrofitted (like you retrofit file backed mappings)?
> AFAIU the only risk would be breaking somebody that already relies on a
> failure for VM_LOCKONFAULT, and it's unlikely there's such a somebody now.
>
>
Hmm yeah I suppose. I guess just to be consistent with the other _LOCKED
variants? (which seem to be... undocumented at least in man pages :P, and yes I
realise this is me semi-volunteering to do that obviously...).
But on the other hand, we could also expand this if you and I see also Dave feel
this makes sense and wouldn't be confusing.
Agreed entirely that it'd be very very odd for a user to rely on that so I think
we'll be fine.
I shall return to this topic later, in the form of a series, probably!
Cheers!
next prev parent reply other threads:[~2025-02-25 16:38 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-13 18:16 Lorenzo Stoakes
2025-02-13 18:17 ` [PATCH 1/4] mm: allow guard regions in file-backed and read-only mappings Lorenzo Stoakes
2025-02-18 14:15 ` Vlastimil Babka
2025-02-18 16:01 ` David Hildenbrand
2025-02-18 16:12 ` Lorenzo Stoakes
2025-02-18 16:17 ` David Hildenbrand
2025-02-18 16:21 ` Lorenzo Stoakes
2025-02-18 16:27 ` David Hildenbrand
2025-02-18 16:49 ` Lorenzo Stoakes
2025-02-18 17:00 ` David Hildenbrand
2025-02-18 17:04 ` Lorenzo Stoakes
2025-02-24 14:02 ` Lorenzo Stoakes
2025-02-13 18:17 ` [PATCH 2/4] selftests/mm: rename guard-pages to guard-regions Lorenzo Stoakes
2025-02-18 14:15 ` Vlastimil Babka
2025-03-02 8:35 ` Lorenzo Stoakes
2025-02-13 18:17 ` [PATCH 3/4] tools/selftests: expand all guard region tests to file-backed Lorenzo Stoakes
2025-02-18 14:17 ` Vlastimil Babka
2025-04-22 10:37 ` Ryan Roberts
2025-04-22 10:47 ` Lorenzo Stoakes
2025-04-22 11:03 ` Ryan Roberts
2025-04-22 11:07 ` Lorenzo Stoakes
2025-04-22 11:11 ` Ryan Roberts
2025-02-13 18:17 ` [PATCH 4/4] tools/selftests: add file/shmem-backed mapping guard region tests Lorenzo Stoakes
2025-02-18 14:18 ` Vlastimil Babka
2025-02-18 12:12 ` [PATCH 0/4] mm: permit guard regions for file-backed/shmem mappings Vlastimil Babka
2025-02-18 13:05 ` Lorenzo Stoakes
2025-02-18 14:35 ` David Hildenbrand
2025-02-18 14:53 ` Lorenzo Stoakes
2025-02-18 15:20 ` David Hildenbrand
2025-02-18 16:43 ` Lorenzo Stoakes
2025-02-18 17:14 ` David Hildenbrand
2025-02-18 17:20 ` Lorenzo Stoakes
2025-02-18 17:25 ` David Hildenbrand
2025-02-18 17:28 ` Lorenzo Stoakes
2025-02-18 17:31 ` David Hildenbrand
2025-02-25 15:54 ` Vlastimil Babka
2025-02-25 16:31 ` David Hildenbrand
2025-02-25 16:37 ` Lorenzo Stoakes [this message]
2025-02-25 16:48 ` David Hildenbrand
2025-02-19 8:25 ` Kalesh Singh
2025-02-19 8:35 ` Kalesh Singh
2025-02-19 9:15 ` Lorenzo Stoakes
2025-02-19 17:32 ` Liam R. Howlett
2025-02-19 9:03 ` Lorenzo Stoakes
2025-02-19 9:15 ` David Hildenbrand
2025-02-19 9:17 ` Lorenzo Stoakes
2025-02-19 18:52 ` Kalesh Singh
2025-02-19 19:20 ` Lorenzo Stoakes
2025-02-19 20:56 ` Kalesh Singh
2025-02-20 8:51 ` Lorenzo Stoakes
2025-02-20 8:57 ` David Hildenbrand
2025-02-20 9:04 ` Lorenzo Stoakes
2025-02-20 9:23 ` David Hildenbrand
2025-02-20 9:47 ` Lorenzo Stoakes
2025-02-20 10:03 ` David Hildenbrand
2025-02-20 10:15 ` Lorenzo Stoakes
2025-02-20 12:44 ` David Hildenbrand
2025-02-20 13:18 ` Lorenzo Stoakes
2025-02-20 16:21 ` Suren Baghdasaryan
2025-02-20 18:08 ` Kalesh Singh
2025-02-21 11:04 ` Lorenzo Stoakes
2025-02-21 17:24 ` Kalesh Singh
2025-02-20 9:22 ` Vlastimil Babka
2025-02-20 9:53 ` Lorenzo Stoakes
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=3102ab3b-67b6-4047-9db7-e83c3b9c1c53@lucifer.local \
--to=lorenzo.stoakes@oracle.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=jannh@google.com \
--cc=jhubbard@nvidia.com \
--cc=jyescas@google.com \
--cc=kaleshsingh@google.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=paulmck@kernel.org \
--cc=shuah@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.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
all inboxes | Powered by JetHome®