Re: [PATCH v3 2/6] mm: gup: clarify a reason to check pte/pmd in gup_fast_pte_range()

From: Yeoreum Yun

Date: Tue Nov 10 2026 - 06:57:26 EST


On Mon, Nov 09, 2026 at 10:50:32PM -0500, Rik van Riel wrote:
> On Mon, 2026-11-09 at 12:32 +0000, Yeoreum Yun wrote:
> > Clarify a reason to check pte/pmd in gup_fast_pte_range().
> >
> > Signed-off-by: Yeoreum Yun <yeoreum.yun@xxxxxxx>
> > ---
> >  mm/gup.c | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> >
> > diff --git a/mm/gup.c b/mm/gup.c
> > index 7d43ce717b246..7f9348c633d58 100644
> > --- a/mm/gup.c
> > +++ b/mm/gup.c
> > @@ -2881,6 +2881,14 @@ static unsigned long gup_fast_pte_range(pmd_t
> > pmd, pmd_t *pmdp,
> >   if (!folio)
> >   goto pte_unmap;
> >  
> > + /*
> > + * Recheck the PTE after grabbing the folio to
> > detect concurrent
> > + * unmapping or protection changes such as by KSM.
> > + *
> > + * Also, recheck the PMD: THP collpase can detach
> > the PTE table
>
> collapse

Okay.

>
> > + * while its entries remain unchaged. Checking the
> > PTE alone
>
> unchanged

Acked.

>
> > + * would not dtect that we are walking a detached
> > page table.
>
> detect

Sorry for typos..


>
> Other than that, Reviewed-by: Rik van Riel <riel@xxxxxxxxxxx>

Thanks ;)


>
> > + */
> >   if (unlikely(pmd_val(pmd) !=
> > pmd_val(pmdp_get_lockless(pmdp))) ||
> >       unlikely(pte_val(pte) !=
> > pte_val(ptep_get_lockless(ptep)))) {
> >   gup_put_folio(folio, 1, flags);
>
> --
> All Rights Reversed.

--
Sincerely,
Yeoreum Yun