From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: "David Hildenbrand (Red Hat)" <david@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>, Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Jann Horn <jannh@google.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] mm/madvise: allow guard page install/remove under VMA lock
Date: Mon, 10 Nov 2025 16:29:47 +0000 [thread overview]
Message-ID: <41d3da5f-70a7-4c42-b579-06cee613ef77@lucifer.local> (raw)
In-Reply-To: <a65dcd48-d3aa-4372-9c58-2278fc161b68@kernel.org>
On Mon, Nov 10, 2025 at 04:44:45PM +0100, David Hildenbrand (Red Hat) wrote:
> On 09.11.25 12:16, Lorenzo Stoakes wrote:
> > We only need to keep the page table stable so we can perform this operation
> > under the VMA lock. PTE installation is stabilised via the PTE lock.
> >
> > One caveat is that, if we prepare vma->anon_vma we must hold the mmap read
> > lock. We can account for this by adapting the VMA locking logic to
> > explicitly check for this case and prevent a VMA lock from being acquired
> > should it be the case.
> >
> > This check is safe, as while we might be raced on anon_vma installation,
> > this would simply make the check conservative, there's no way for us to see
> > an anon_vma and then for it to be cleared, as doing so requires the
> > mmap/VMA write lock.
> >
> > We abstract the VMA lock validity logic to is_vma_lock_valid() for this
> > purpose, and add prepares_anon_vma() to abstract the anon_vma logic.
> >
> > In order to do this we need to have a way of installing page tables
> > explicitly for an identified VMA, so we export walk_page_range_vma() in an
> > unsafe variant - walk_page_range_vma_unsafe() and use this should the VMA
> > read lock be taken.
> >
> > We additionally update the comments in madvise_guard_install() to more
> > accurately reflect the cases in which the logic may be reattempted,
> > specifically THP huge pages being present.
> >
> > Suggested-by: Vlastimil Babka <vbabka@suse.cz>
> > Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> > ---
>
> [...]
>
> >
> > +/* Does this operation invoke anon_vma_prepare()? */
> > +static bool prepares_anon_vma(int behavior)
> > +{
> > + switch (behavior) {
> > + case MADV_GUARD_INSTALL:
> > + return true;
> > + default:
> > + return false;
> > + }
> > +}
> > +
> > +/*
> > + * We have acquired a VMA read lock, is the VMA valid to be madvise'd under VMA
> > + * read lock only now we have a VMA to examine?
> > + */
> > +static bool is_vma_lock_valid(struct vm_area_struct *vma,
> > + struct madvise_behavior *madv_behavior)
>
>
> Not sure about the "valid" terminology here.
>
> Would "is_vma_lock_sufficient" be a better name, that would imply when
> "false" that another lock is required, because the VMA lock is insufficient?
OK makes sense, will change
>
>
> --
> Cheers
>
> David
Cheers, Lorenzo
prev parent reply other threads:[~2025-11-10 16:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-09 11:16 [PATCH 0/2] mm: perform guard region " Lorenzo Stoakes
2025-11-09 11:16 ` [PATCH 1/2] mm: rename walk_page_range_mm() Lorenzo Stoakes
2025-11-10 15:48 ` David Hildenbrand (Red Hat)
2025-11-10 16:28 ` Lorenzo Stoakes
2025-11-09 11:16 ` [PATCH 2/2] mm/madvise: allow guard page install/remove under VMA lock Lorenzo Stoakes
2025-11-10 15:44 ` David Hildenbrand (Red Hat)
2025-11-10 16:29 ` Lorenzo Stoakes [this message]
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=41d3da5f-70a7-4c42-b579-06cee613ef77@lucifer.local \
--to=lorenzo.stoakes@oracle.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
/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