* [RFC PATCH 0/2] mm/gup: pgtable entry acccessors cleanup @ 2026-04-20 12:13 Alexander Gordeev 2026-04-20 12:13 ` [RFC PATCH 1/2] mm/gup: add missing pXdp_get() conversions Alexander Gordeev 2026-04-20 12:13 ` [RFC PATCH 2/2] mm/gup: add lockless access semantics on entries validation Alexander Gordeev 0 siblings, 2 replies; 5+ messages in thread From: Alexander Gordeev @ 2026-04-20 12:13 UTC (permalink / raw) To: Kevin Brodsky, David Hildenbrand, Ryan Roberts, Andrew Morton Cc: linux-s390, linux-mm, linux-kernel, Gerald Schaefer, Heiko Carstens, Vasily Gorbik Hi All, This rework is necessary to allow a KASAN PTE access sanitizer (so far s390-only) that hits on direct PTE entries dereferences, like pte = *ptep as opposed to pte = ptep_get(ptep). I am not posting the sanitizer itself (yet), since it does not fly without the suggested patches, but I am not sure whether these changes make sense for the generic case. Thus, sending it as a RFC. Thanks! Alexander Gordeev (2): mm/gup: add missing pXdp_get() conversions mm/gup: add lockless access semantics on entries validation mm/gup.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) -- 2.51.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC PATCH 1/2] mm/gup: add missing pXdp_get() conversions 2026-04-20 12:13 [RFC PATCH 0/2] mm/gup: pgtable entry acccessors cleanup Alexander Gordeev @ 2026-04-20 12:13 ` Alexander Gordeev 2026-04-20 19:28 ` David Hildenbrand (Arm) 2026-04-20 12:13 ` [RFC PATCH 2/2] mm/gup: add lockless access semantics on entries validation Alexander Gordeev 1 sibling, 1 reply; 5+ messages in thread From: Alexander Gordeev @ 2026-04-20 12:13 UTC (permalink / raw) To: Kevin Brodsky, David Hildenbrand, Ryan Roberts, Andrew Morton Cc: linux-s390, linux-mm, linux-kernel, Gerald Schaefer, Heiko Carstens, Vasily Gorbik PMD and PUD entries revalidation has the same semantics as PTE entry revalidation. Convert the remaining direct entry dereferences to the corresponding pXdp_get() accessors. Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com> --- mm/gup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 8e7dc2c6ee73..d149a4b0df71 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2865,7 +2865,7 @@ 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)) || + if (unlikely(pmd_val(pmd) != pmd_val(pmdp_get(pmdp))) || unlikely(pte_val(pte) != pte_val(ptep_get(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))) { + if (unlikely(pmd_val(orig) != pmd_val(pmdp_get(pmdp)))) { gup_put_folio(folio, refs, flags); return 0; } @@ -2985,7 +2985,7 @@ static int gup_fast_pud_leaf(pud_t orig, pud_t *pudp, unsigned long addr, if (!folio) return 0; - if (unlikely(pud_val(orig) != pud_val(*pudp))) { + if (unlikely(pud_val(orig) != pud_val(pudp_get(pudp)))) { gup_put_folio(folio, refs, flags); return 0; } -- 2.51.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC PATCH 1/2] mm/gup: add missing pXdp_get() conversions 2026-04-20 12:13 ` [RFC PATCH 1/2] mm/gup: add missing pXdp_get() conversions Alexander Gordeev @ 2026-04-20 19:28 ` David Hildenbrand (Arm) 0 siblings, 0 replies; 5+ messages in thread From: David Hildenbrand (Arm) @ 2026-04-20 19:28 UTC (permalink / raw) To: Alexander Gordeev, Kevin Brodsky, Ryan Roberts, Andrew Morton Cc: linux-s390, linux-mm, linux-kernel, Gerald Schaefer, Heiko Carstens, Vasily Gorbik On 4/20/26 14:13, Alexander Gordeev wrote: > PMD and PUD entries revalidation has the same semantics as > PTE entry revalidation. Convert the remaining direct entry > dereferences to the corresponding pXdp_get() accessors. > > Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com> > --- > mm/gup.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/mm/gup.c b/mm/gup.c > index 8e7dc2c6ee73..d149a4b0df71 100644 > --- a/mm/gup.c > +++ b/mm/gup.c > @@ -2865,7 +2865,7 @@ 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)) || > + if (unlikely(pmd_val(pmd) != pmd_val(pmdp_get(pmdp))) || > unlikely(pte_val(pte) != pte_val(ptep_get(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))) { > + if (unlikely(pmd_val(orig) != pmd_val(pmdp_get(pmdp)))) { > gup_put_folio(folio, refs, flags); > return 0; > } > @@ -2985,7 +2985,7 @@ static int gup_fast_pud_leaf(pud_t orig, pud_t *pudp, unsigned long addr, > if (!folio) > return 0; > > - if (unlikely(pud_val(orig) != pud_val(*pudp))) { > + if (unlikely(pud_val(orig) != pud_val(pudp_get(pudp)))) { > gup_put_folio(folio, refs, flags); > return 0; > } These are all on lockless code paths. Shouldn't we be using the lockless pte/pmd variants? (not a matter of correctness, rather a matter of semantics) -- Cheers, David ^ permalink raw reply [flat|nested] 5+ messages in thread
* [RFC PATCH 2/2] mm/gup: add lockless access semantics on entries validation 2026-04-20 12:13 [RFC PATCH 0/2] mm/gup: pgtable entry acccessors cleanup Alexander Gordeev 2026-04-20 12:13 ` [RFC PATCH 1/2] mm/gup: add missing pXdp_get() conversions Alexander Gordeev @ 2026-04-20 12:13 ` Alexander Gordeev 2026-04-20 19:29 ` David Hildenbrand (Arm) 1 sibling, 1 reply; 5+ messages in thread From: Alexander Gordeev @ 2026-04-20 12:13 UTC (permalink / raw) To: Kevin Brodsky, David Hildenbrand, Ryan Roberts, Andrew Morton Cc: linux-s390, linux-mm, linux-kernel, Gerald Schaefer, Heiko Carstens, Vasily Gorbik 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@linux.ibm.com> --- 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; } -- 2.51.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [RFC PATCH 2/2] mm/gup: add lockless access semantics on entries validation 2026-04-20 12:13 ` [RFC PATCH 2/2] mm/gup: add lockless access semantics on entries validation Alexander Gordeev @ 2026-04-20 19:29 ` David Hildenbrand (Arm) 0 siblings, 0 replies; 5+ messages in thread From: David Hildenbrand (Arm) @ 2026-04-20 19:29 UTC (permalink / raw) To: Alexander Gordeev, Kevin Brodsky, Ryan Roberts, Andrew Morton Cc: linux-s390, linux-mm, linux-kernel, Gerald Schaefer, Heiko Carstens, Vasily Gorbik 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@linux.ibm.com> > --- > 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-20 19:29 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-04-20 12:13 [RFC PATCH 0/2] mm/gup: pgtable entry acccessors cleanup Alexander Gordeev 2026-04-20 12:13 ` [RFC PATCH 1/2] mm/gup: add missing pXdp_get() conversions Alexander Gordeev 2026-04-20 19:28 ` David Hildenbrand (Arm) 2026-04-20 12:13 ` [RFC PATCH 2/2] mm/gup: add lockless access semantics on entries validation Alexander Gordeev 2026-04-20 19:29 ` David Hildenbrand (Arm)
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox