mm: use standard page table accessors
Subsystems (3)
PATCH 1/1 mm: use standard page table accessors
Use standard page table accessors i.e pxdp_get() to get the value of pxdp.
--- include/linux/pgtable.h | 2 +- mm/huge_memory.c | 2 +- mm/memory.c | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-)
include/linux/pgtable.h +1 -1
@@ -1810,7 +1810,7 @@ static inline int pud_trans_unstable(pud_t *pud) {#if defined(CONFIG_TRANSPARENT_HUGEPAGE ) && \ defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD ) -pud_t pudval =READ_ONCE (*pud); +pud_t pudval =pudp_get (pud);if (pud_none (pudval) ||pud_trans_huge (pudval))return 1 ;
mm/huge_memory.c +1 -1
@@ -1486,7 +1486,7 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf) } vmf->ptl =pmd_lock (vma->vm_mm, vmf->pmd); ret =0 ; -if (pmd_none (*vmf->pmd)) { +if (pmd_none (pmdp_get (vmf->pmd))) { ret =check_stable_address_space (vma->vm_mm);if (ret) {spin_unlock (vmf->ptl);
mm/memory.c +4 -4
@@ -6193,7 +6193,7 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) {pte_t entry; -if (unlikely (pmd_none (*vmf->pmd))) { +if (unlikely (pmd_none (pmdp_get (vmf->pmd)))) {/* * Leave __pte_alloc() until later: because vm_ops->fault may * want to allocate huge page, and if we expose page table
@@ -6309,13 +6309,13 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma,if (!vmf.pud)return VM_FAULT_OOM ; retry_pud: -if (pud_none (*vmf.pud) && +if (pud_none (pudp_get (vmf.pud)) &&thp_vma_allowable_order (vma, vm_flags,TVA_PAGEFAULT ,PUD_ORDER )) { ret =create_huge_pud (&vmf);if (!(ret &VM_FAULT_FALLBACK ))return ret; }else { -pud_t orig_pud = *vmf.pud; +pud_t orig_pud =pudp_get (vmf.pud);barrier ();if (pud_trans_huge (orig_pud)) {
@@ -6343,7 +6343,7 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma,if (pud_trans_unstable (vmf.pud)) goto retry_pud; -if (pmd_none (*vmf.pmd) && +if (pmd_none (pmdp_get (vmf.pmd)) &&thp_vma_allowable_order (vma, vm_flags,TVA_PAGEFAULT ,PMD_ORDER )) { ret =create_huge_pmd (&vmf);if (ret &VM_FAULT_FALLBACK )
Signature · 1 line
2.34.1
Le 26/11/2025 à 07:47, Wei Yang a écrit :
Quoted 2 lines
Use standard page table accessors i.e
pxdp_get()to get the value of pxdp.
Please provide more detail of why you want to do that and how you are sure it doesn't break existing implementation.
There was similar tentative in the past already which proved to give suboptimal results, see discussion here:
https://lore.kernel.org/all/[email protected]/
Christophe
Quoted 72 lines
Signed-off-by Wei Yang <[email protected]>--- include/linux/pgtable.h | 2 +- mm/huge_memory.c | 2 +- mm/memory.c | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-)include/linux/pgtable.h +1
-1@@ -1810,7 +1810,7 @@ static inline int pud_trans_unstable(pud_t *pud) {#if defined(CONFIG_TRANSPARENT_HUGEPAGE ) && \ defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD ) -pud_t pudval =READ_ONCE (*pud); +pud_t pudval =pudp_get (pud);if (pud_none (pudval) ||pud_trans_huge (pudval))return 1 ;mm/huge_memory.c +1
-1@@ -1486,7 +1486,7 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf) } vmf->ptl =pmd_lock (vma->vm_mm, vmf->pmd); ret =0 ; -if (pmd_none (*vmf->pmd)) { +if (pmd_none (pmdp_get (vmf->pmd))) { ret =check_stable_address_space (vma->vm_mm);if (ret) {spin_unlock (vmf->ptl);mm/memory.c +4
-4@@ -6193,7 +6193,7 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) {pte_t entry; -if (unlikely (pmd_none (*vmf->pmd))) { +if (unlikely (pmd_none (pmdp_get (vmf->pmd)))) {/* * Leave __pte_alloc() until later: because vm_ops->fault may * want to allocate huge page, and if we expose page table @@ -6309,13 +6309,13 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma,if (!vmf.pud)return VM_FAULT_OOM ; retry_pud: -if (pud_none (*vmf.pud) && +if (pud_none (pudp_get (vmf.pud)) &&thp_vma_allowable_order (vma, vm_flags,TVA_PAGEFAULT ,PUD_ORDER )) { ret =create_huge_pud (&vmf);if (!(ret &VM_FAULT_FALLBACK ))return ret; }else { -pud_t orig_pud = *vmf.pud; +pud_t orig_pud =pudp_get (vmf.pud);barrier ();if (pud_trans_huge (orig_pud)) {@@ -6343,7 +6343,7 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma,if (pud_trans_unstable (vmf.pud)) goto retry_pud; -if (pmd_none (*vmf.pmd) && +if (pmd_none (pmdp_get (vmf.pmd)) &&thp_vma_allowable_order (vma, vm_flags,TVA_PAGEFAULT ,PMD_ORDER )) { ret =create_huge_pmd (&vmf);if (ret &VM_FAULT_FALLBACK )
Quoted 6 lines · Christophe Leroy (CS GROUP)
Le 26/11/2025 à 07:47, Wei Yang a écrit :
Quoted 2 lines
Use standard page table accessors i.e
pxdp_get()to get the value of pxdp.
Quoted 7 lines
Please provide more detail of why you want to do that and how you are sure it doesn't break existing implementation.
There was similar tentative in the past already which proved to give suboptimal results, see discussion here:
Interesting.
The reason is P4D/PUD/PMD on PPC32 actually just has PGD/PMD. So it is not necessary to retrieve P4D and PUD.
If this is the case, sounds other platform with less pagetable level would be affected too.
And this looks only affect when we walk the pagetable from pgd. If we just iterating pmd/pte, we won't have this issue, right?
Quoted 2 lines
Christophe
Signature · 2 lines
Wei Yang Help you, Help me
Le 26/11/2025 à 11:03, Wei Yang a écrit :
Quoted 13 lines · Christophe Leroy (CS GROUP)
Quoted 12 lines
Le 26/11/2025 à 07:47, Wei Yang a écrit :
Quoted 2 lines
Use standard page table accessors i.e
pxdp_get()to get the value of pxdp.Please provide more detail of why you want to do that and how you are sure it doesn't break existing implementation.
There was similar tentative in the past already which proved to give suboptimal results, see discussion here:
Quoted 6 lines
Interesting.
The reason is P4D/PUD/PMD on PPC32 actually just has PGD/PMD. So it is not necessary to retrieve P4D and PUD.
More exactly, PPC32 just has PGD and PTE, no PMD either:
arch/powerpc/include/asm/book3s/32/pgtable.h:#include <asm-generic/pgtable-nopmd.h> arch/powerpc/include/asm/nohash/32/pgtable.h:#include <asm-generic/pgtable-nopmd.h>
Quoted 3 lines
If this is the case, sounds other platform with less pagetable level would be affected too.
Indeed.
Quoted 3 lines
And this looks only affect when we walk the pagetable from pgd. If we just iterating pmd/pte, we won't have this issue, right?
Maybe. I have not looked at your changes in details, it just lit up a memory in my mind.
Christophe
Quoted 35 lines · Christophe Leroy (CS GROUP)
Le 26/11/2025 à 11:03, Wei Yang a écrit :
Quoted 13 lines · Christophe Leroy (CS GROUP)
Quoted 12 lines
Le 26/11/2025 à 07:47, Wei Yang a écrit :
Quoted 2 lines
Use standard page table accessors i.e
pxdp_get()to get the value of pxdp.Please provide more detail of why you want to do that and how you are sure it doesn't break existing implementation.
There was similar tentative in the past already which proved to give suboptimal results, see discussion here:
Quoted 6 lines
Interesting.
The reason is P4D/PUD/PMD on PPC32 actually just has PGD/PMD. So it is not necessary to retrieve P4D and PUD.
More exactly, PPC32 just has PGD and PTE, no PMD either:
arch/powerpc/include/asm/book3s/32/pgtable.h:#include <
asm-generic/pgtable-nopmd.h> arch/powerpc/include/asm/nohash/32/pgtable.h:#include <asm-generic/pgtable-nopmd.h>Quoted 3 lines
If this is the case, sounds other platform with less pagetable level would be affected too.
Quoted 9 lines
Indeed.
Quoted 3 lines
And this looks only affect when we walk the pagetable from pgd. If we just iterating pmd/pte, we won't have this issue, right?
Maybe. I have not looked at your changes in details, it just lit up a memory in my mind.
Thanks for noticing me this, I learned a lesson from you :-)
Quoted 1 line
Christophe
Signature · 2 lines
Wei Yang Help you, Help me
David Hildenbrand (Red Hat)
maintainerQuoted 3 lines · Wei Yang
Use standard page table accessors i.e
pxdp_get()to get the value of pxdp.
Isn't this covered by
https://lkml.kernel.org/r/[email protected]
In particular
https://lkml.kernel.org/r/[email protected]
?
Signature · 3 lines
Cheers David
Quoted 7 lines · David Hildenbrand (Red Hat)
Quoted 3 lines · Wei Yang
Use standard page table accessors i.e
pxdp_get()to get the value of pxdp.Isn't this covered by
Quoted 8 lines
https://lkml.kernel.org/r/[email protected]
In particular
https://lkml.kernel.org/r/[email protected]
?
You are right, just see it.
Signature · 2 lines
Wei Yang Help you, Help me
Ryan Roberts
reviewer+ Anshuman
Quoted 7 lines · David Hildenbrand (Red Hat)
Quoted 3 lines · Wei Yang
Use standard page table accessors i.e
pxdp_get()to get the value of pxdp.Isn't this covered by
Quoted 7 lines
https://lkml.kernel.org/r/[email protected]
In particular
https://lkml.kernel.org/r/[email protected]
?
Ahh this is very interesting - I wasn't aware of this new attempt! We could benefit from this on arm64 too.
We have some experience and opinions about this; I'll reply to the patch with some details...
But as for this patch, I don't see the value in changing just a few instances. I'd prefer to see it converted systematically, taking into consideration all the complexities.
Thanks,
Ryan
Ryan Roberts
reviewerQuoted 16 lines · Ryan Roberts
+ Anshuman
Quoted 13 lines · David Hildenbrand (Red Hat)
Quoted 3 lines · Wei Yang
Use standard page table accessors i.e
pxdp_get()to get the value of pxdp.Isn't this covered by
https://lkml.kernel.org/r/[email protected]
In particular
Quoted 7 lines
Quoted 1 line
?
Ahh this is very interesting - I wasn't aware of this new attempt! We could benefit from this on arm64 too.
We have some experience and opinions about this; I'll reply to the patch with some details...
https://lore.kernel.org/all/[email protected]/
Quoted 8 lines
But as for this patch, I don't see the value in changing just a few instances. I'd prefer to see it converted systematically, taking into consideration all the complexities.
Thanks,
Ryan