Re: [PATCH v2 1/2] mm/memory: recheck PG_uptodate after ->page_mkwrite()
From: Kiryl Shutsemau
Date: Mon Nov 09 2026 - 09:41:39 EST
On Mon, Nov 09, 2026 at 02:11:23PM +0000, Pedro Falcato wrote:
> > diff --git a/mm/memory.c b/mm/memory.c
> > index fe72e66c9c2e..cc1d0b7d15c7 100644
> > --- a/mm/memory.c
> > +++ b/mm/memory.c
> > @@ -5613,6 +5613,18 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf)
> > return VM_FAULT_OOM;
> > }
> >
> > +/*
> > + * A page cache folio that is not uptodate holds data that was never read in
> > + * or cleared, and mapping it leaks stale memory to userspace.
> > + */
> > +static bool file_folio_not_uptodate(struct folio *folio)
> > +{
> > + if (likely(folio_test_uptodate(folio)))
> > + return false;
> > + /* Driver pages from ->fault() never get PG_uptodate */
> > + return !folio_test_anon(folio) && folio->mapping;
>
> FYI you can wrap this line in an unlikely() and it has the same effect as
> wrapping every call:
> return unlikely(!folio_test_anon(folio) && folio->mapping);
I prefer it at the call site. That is where the reader needs to see
that the retry is the rare path.
> > +}
> > +
> > /*
> > * Either the VMA lock or the mmap_lock must have been held on entry
> > * (see FAULT_FLAG_VMA_LOCK) and may have been released depending on
> > @@ -6163,6 +6175,16 @@ static vm_fault_t do_shared_fault(struct vm_fault *vmf)
> > folio_put(folio);
> > return tmp;
> > }
> > +
> > + /*
> > + * The folio was unlocked for ->page_mkwrite(). If it lost
> > + * PG_uptodate meanwhile, retry the fault to read it in again.
> > + */
>
> The "read it in again" sounds a bit too prescriptive but, apart from that:
Okay, will drop it if respin needed.
David, could you adjust it on apply otherwise?
> Reviewed-by: Pedro Falcato <pfalcato@xxxxxxx>
Thanks!
--
Kiryl Shutsemau / Kirill A. Shutemov