From: Harry Yoo <harry.yoo@oracle.com>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Suren Baghdasaryan <surenb@google.com>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
David Hildenbrand <david@redhat.com>, Kees Cook <kees@kernel.org>,
Vlastimil Babka <vbabka@suse.cz>,
Shakeel Butt <shakeel.butt@linux.dev>,
Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>,
Jonathan Corbet <corbet@lwn.net>, Jann Horn <jannh@google.com>,
Pedro Falcato <pfalcato@suse.de>, Rik van Riel <riel@surriel.com>,
linux-mm@kvack.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH V1 2/2] mm: document when rmap locks can be skipped when setting need_rmap_locks
Date: Wed, 27 Aug 2025 15:52:12 +0900 [thread overview]
Message-ID: <aK6rHBaQ-gpzgEVt@hyeyoo> (raw)
In-Reply-To: <6a8a32a5-95f0-4dc7-8a75-80cf639069ef@lucifer.local>
On Tue, Aug 26, 2025 at 10:46:24AM +0100, Lorenzo Stoakes wrote:
> On Tue, Aug 26, 2025 at 03:58:48PM +0900, Harry Yoo wrote:
> > While move_ptes() explains when rmap locks can be skipped, when reading
> > the code setting pmc.need_rmap_locks it is not immediately obvious when
> > need_rmap_locks can be false. Add a brief explanation in copy_vma() and
> > relocate_vma_down(), and add a pointer to the comment in move_ptes().
> >
> > Meanwhile, fix and improve the comment in move_ptes().
> >
> > Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
>
> This is great thanks! :)
You're welcome!
> > ---
> > mm/mremap.c | 4 +++-
> > mm/vma.c | 7 +++++++
> > mm/vma_exec.c | 5 +++++
> > 3 files changed, 15 insertions(+), 1 deletion(-)
> >
> > diff --git a/mm/mremap.c b/mm/mremap.c
> > index e618a706aff5..86adb872bea0 100644
> > --- a/mm/mremap.c
> > +++ b/mm/mremap.c
> > @@ -218,8 +218,10 @@ static int move_ptes(struct pagetable_move_control *pmc,
> > * When need_rmap_locks is false, we use other ways to avoid
> > * such races:
> > *
> > - * - During exec() shift_arg_pages(), we use a specially tagged vma
> > + * - During exec() relocate_vma_down(), we use a specially tagged vma
> > * which rmap call sites look for using vma_is_temporary_stack().
> > + * Folios mapped in the temporary stack vma cannot be migrated until
> > + * the relocation is complete.
>
> Can we actually move this comment over to move_page_tables()? As this is
> relevant to the whole operation.
Sounds good, will do.
> Also could you put a comment referencing this
> comment in copy_vma_and_data() as this is where we actually determine whether
> this is the case or not in _most cases_.
>
> Let's just get all the 'need rmap locks' and 'corner cases where it's fine
> anyway' in one place that is logical :)
Will do.
> Also could you put a comment in copy_vma() over in mm/vma.c saying 'see the
> comment in mm/mremap.c' or even risk mentioning the function name (risky as code
> changes but still :P) e.g. 'see comment in move_page_tables()' or something.
Will take a risk and do "See the comment in move_page_tables()" :)
> I'm confused by the 'folios mapped' and 'migrate' bits - and I think people will
> be confused by that.
>
> I think better to say 'page tables for the temporary stack cannot be adjusted
> until the relocation is complete'.
But is that correct?
Out of all rmap users, only try_to_migrate() cares about
VM_STACK_INCOMPLETE_SETUP via invalid_migration_vma().
I'm not sure what prevents from try_to_unmap() from unmapping it while
it's relocated?
Looks like it's always been like this since a8bef8ff6ea1 ("mm: migration:
avoid race between shift_arg_pages() and rmap_walk() during migration by
not migrating temporary stacks")
> > *
> > * - During mremap(), new_vma is often known to be placed after vma
> > * in rmap traversal order. This ensures rmap will always observe
>
> This whole bit after could really do with some ASCII diagrams btw :)) ;) but you
> know maybe out of scope here.
>
> > diff --git a/mm/vma.c b/mm/vma.c
> > index 3b12c7579831..3da49f79e9ba 100644
> > --- a/mm/vma.c
> > +++ b/mm/vma.c
> > @@ -1842,6 +1842,11 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
> > vmg.next = vma_iter_next_rewind(&vmi, NULL);
> > new_vma = vma_merge_new_range(&vmg);
> >
> > + /*
> > + * rmap locks can be skipped as long as new_vma is traversed
> > + * after vma during rmap walk (new_vma->vm_pgoff >= vma->vm_pgoff).
> > + * See the comment in move_ptes().
> > + */
>
> Obv. would prefer this to say 'move_page_tables()' as mentioned above :P
Will do.
> > if (new_vma) {
> > /*
> > * Source vma may have been merged into new_vma
> > @@ -1879,6 +1884,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
> > new_vma->vm_ops->open(new_vma);
> > if (vma_link(mm, new_vma))
> > goto out_vma_link;
> > +
> > + /* new_vma->pg_off is always >= vma->pg_off if not merged */
>
> Err, new_vma is NULL? :) I'm not sure this comment is too useful.
Sometimes the line between "worth commenting" and "too much comment" is
vague to me :) I'll remove it. Thanks.
> > *need_rmap_locks = false;
> > }
> > return new_vma;
> > diff --git a/mm/vma_exec.c b/mm/vma_exec.c
> > index 922ee51747a6..a895dd39ac46 100644
> > --- a/mm/vma_exec.c
> > +++ b/mm/vma_exec.c
> > @@ -63,6 +63,11 @@ int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift)
> > * process cleanup to remove whatever mess we made.
> > */
> > pmc.for_stack = true;
> > + /*
> > + * pmc.need_rmap_locks is false since rmap locks can be safely skipped
> > + * because migration is disabled for this vma during relocation.
> > + * See the comment in move_ptes().
> > + */
>
> Let's reword this also, people will get confused about migration here.
>
> 'pmc.need_rmap_locks is false since rmap explicitly checks for
> vma_is_temporary_stack() and thus extra care does not need to be taken here
> during stack relocation. See the comment in move_page_tables().'
This looks good! except for one thing, not all rmap users check for
vma_is_temporary_stack().
> > if (length != move_page_tables(&pmc))
> > return -ENOMEM;
> >
> > --
> > 2.43.0
> >
>
> Cheers, Lorenzo
--
Cheers,
Harry / Hyeonggon
next prev parent reply other threads:[~2025-08-27 6:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-26 6:58 [PATCH V1 1/2] docs/mm: explain when and why rmap locks need to be taken during mremap() Harry Yoo
2025-08-26 6:58 ` [PATCH V1 2/2] mm: document when rmap locks can be skipped when setting need_rmap_locks Harry Yoo
2025-08-26 9:46 ` Lorenzo Stoakes
2025-08-27 6:52 ` Harry Yoo [this message]
2025-08-27 11:16 ` Lorenzo Stoakes
2025-08-26 7:22 ` [PATCH V1 1/2] docs/mm: explain when and why rmap locks need to be taken during mremap() Jonathan Corbet
2025-08-26 8:37 ` Lorenzo Stoakes
2025-08-26 9:48 ` Harry Yoo
2025-08-26 9:58 ` Lorenzo Stoakes
2025-08-27 7:18 ` Harry Yoo
2025-08-27 9:25 ` Lorenzo Stoakes
2025-08-26 9:55 ` 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=aK6rHBaQ-gpzgEVt@hyeyoo \
--to=harry.yoo@oracle.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=david@redhat.com \
--cc=jannh@google.com \
--cc=kees@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=pfalcato@suse.de \
--cc=riel@surriel.com \
--cc=rppt@kernel.org \
--cc=shakeel.butt@linux.dev \
--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;
as well as URLs for NNTP newsgroup(s).