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

From: Rik van Riel

Date: Mon Nov 09 2026 - 22:52:27 EST


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

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

unchanged

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

detect

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

> + */
>   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.