Re: [RFC PATCH 2/2] mm/gup: add lockless access semantics on entries validation

From: David Hildenbrand (Arm)

Date: Mon Apr 20 2026 - 15:29:57 EST


On 4/20/26 14:13, Alexander Gordeev wrote:
> The PTE validation in gup_fast_pte_range() is inconsistent with the
> prior value acquisition in the sense that it drops the lockless
> access semantics.
>
> Although this is highly unlikely, prevent a future scenario in which
> a semantically mismatching ptep_get() incorrectly yields the same
> result as the preceding ptep_get_lockless(), while ptep_get_lockless()
> would otherwise return a different value.
>
> Likewise the PMD validation is inconsistent with the prior value
> acquisition in gup_fast_pmd_range().
>
> Signed-off-by: Alexander Gordeev <agordeev@xxxxxxxxxxxxx>
> ---
> mm/gup.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/mm/gup.c b/mm/gup.c
> index d149a4b0df71..236450feea9a 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -2865,8 +2865,8 @@ static int gup_fast_pte_range(pmd_t pmd, pmd_t *pmdp, unsigned long addr,
> if (!folio)
> goto pte_unmap;
>
> - if (unlikely(pmd_val(pmd) != pmd_val(pmdp_get(pmdp))) ||
> - unlikely(pte_val(pte) != pte_val(ptep_get(ptep)))) {
> + 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);
> goto pte_unmap;
> }
> @@ -2942,7 +2942,7 @@ static int gup_fast_pmd_leaf(pmd_t orig, pmd_t *pmdp, unsigned long addr,
> if (!folio)
> return 0;
>
> - if (unlikely(pmd_val(orig) != pmd_val(pmdp_get(pmdp)))) {
> + if (unlikely(pmd_val(orig) != pmd_val(pmdp_get_lockless(pmdp)))) {
> gup_put_folio(folio, refs, flags);
> return 0;
> }

Oh, that should be squashed into #1 :)

--
Cheers,

David