mm/sparse-vmemmap: Provide generic vmemmap_set_pmd() and vmemmap_check_pmd()
Subsystems (6)
v3 cover mm/sparse-vmemmap: Provide generic vmemmap_set_pmd() and vmemmap_check_pmd()
The weak vmemmap_set_pmd() and vmemmap_check_pmd() hooks are currently no-ops in the generic code, which leaves architectures that need PMD-level handling to open-code the same logic locally.
This series provides generic implementations for both helpers in mm/sparse-vmemmap.c. vmemmap_set_pmd() installs a huge PMD with PAGE_KERNEL protection, and vmemmap_check_pmd() verifies a present leaf PMD before reusing the existing vmemmap_verify() helper.
With those generic helpers in place, patches 2-5 remove the now redundant arch-specific implementations from arm64, riscv, loongarch, and sparc.
v2 -> v3:
- Replace BUG_ON() with WARN_ON_ONCE() in patch 1
- Add Will Deacon's Acked-by to patch 2
Muchun Song (5):
mm/sparse-vmemmap: provide generic vmemmap_set_pmd() and
vmemmap_check_pmd()
arm64/mm: drop vmemmap_pmd helpers and use generic code riscv/mm: drop vmemmap_pmd helpers and use generic code loongarch/mm: drop vmemmap_check_pmd helper and use generic code sparc/mm: drop vmemmap_check_pmd helper and use generic code
arch/arm64/mm/mmu.c | 14 -------------- arch/loongarch/mm/init.c | 11 ----------- arch/riscv/mm/init.c | 13 ------------- arch/sparc/mm/init_64.c | 11 ----------- mm/sparse-vmemmap.c | 7 ++++++- 5 files changed, 6 insertions(+), 50 deletions(-)
base-commit: 7da7f07112610a520567421dd2ffcb51beaefbcc
Signature · 1 line
2.54.0
PATCH v3 1/5 mm/sparse-vmemmap: provide generic vmemmap_set_pmd() and vmemmap_check_pmd()
The two weak functions are currently no-ops on every architecture, forcing each platform that needs them to duplicate the same handful of lines. Provide a generic implementation:
- vmemmap_set_pmd() simply sets a huge PMD with PAGE_KERNEL protection.
- vmemmap_check_pmd() verifies that the PMD is present and leaf, then calls the existing vmemmap_verify() helper.
Architectures that need special handling can continue to override the weak symbols; everyone else gets the standard version for free.
---v2->v3:
- Replace BUG_ON() with WARN_ON_ONCE() in vmemmap_set_pmd()
--- mm/sparse-vmemmap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
mm/sparse-vmemmap.c +6 -1
@@ -386,12 +386,17 @@ int __meminit vmemmap_populate_hvo(unsigned long addr, unsigned long end,void __weak __meminit vmemmap_set_pmd (pmd_t *pmd,void *p,int node,unsigned long addr,unsigned long next) { +WARN_ON_ONCE (!pmd_set_huge (pmd,virt_to_phys (p),PAGE_KERNEL )); }int __weak __meminit vmemmap_check_pmd (pmd_t *pmd,int node,unsigned long addr,unsigned long next) { -return 0 ; +if (!pmd_leaf (pmdp_get (pmd))) +return 0 ; +vmemmap_verify ((pte_t *)pmd, node, addr, next); + +return 1 ; } int __meminit vmemmap_populate_hugepages(unsigned long start, unsigned long end,
Signature · 1 line
2.54.0
Re: [PATCH v3 1/5] mm/sparse-vmemmap: provide generic vmemmap_set_pmd() and vmemmap_check_pmd()
Quoted 25 lines · Muchun Song
The two weak functions are currently no-ops on every architecture, forcing each platform that needs them to duplicate the same handful of lines. Provide a generic implementation:
-
vmemmap_set_pmd()simply sets a huge PMD withPAGE_KERNELprotection.-
vmemmap_check_pmd()verifies that the PMD is present and leaf, then calls the existingvmemmap_verify()helper.Architectures that need special handling can continue to override the weak symbols; everyone else gets the standard version for free.
Signed-off-by Muchun Song <[email protected]>---
v2->v3:
- ReplaceBUG_ON()withWARN_ON_ONCE()invmemmap_set_pmd()--- mm/sparse-vmemmap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)mm/sparse-vmemmap.c +0
-0
mm/sparse-vmemmap.c int __meminit vmemmap_populate_hvo(unsigned long addr, unsigned long end, · line 389
Quoted 4 lines
mm/sparse-vmemmap.c +1
-0@@ -386,12 +386,17 @@ int __meminit vmemmap_populate_hvo(unsigned long addr, unsigned long end,void __weak __meminit vmemmap_set_pmd (pmd_t *pmd,void *p,int node,unsigned long addr,unsigned long next) { +WARN_ON_ONCE (!pmd_set_huge (pmd,virt_to_phys (p),PAGE_KERNEL ));
Not sure if a VM_WARN_ON_ONCE() would be appropriate. (then, we have to move the pmd_set_huge() out of the statement).
Signature · 3 lines
Cheers, David
Re: [PATCH v3 1/5] mm/sparse-vmemmap: provide generic vmemmap_set_pmd() and vmemmap_check_pmd()
Quoted 25 lines · David Hildenbrand (Arm)
Quoted 20 lines · Muchun Song
The two weak functions are currently no-ops on every architecture, forcing each platform that needs them to duplicate the same handful of lines. Provide a generic implementation:
-
vmemmap_set_pmd()simply sets a huge PMD withPAGE_KERNELprotection.-
vmemmap_check_pmd()verifies that the PMD is present and leaf, then calls the existingvmemmap_verify()helper.Architectures that need special handling can continue to override the weak symbols; everyone else gets the standard version for free.
Signed-off-by Muchun Song <[email protected]>---
v2->v3:
- ReplaceBUG_ON()withWARN_ON_ONCE()invmemmap_set_pmd()
---mm/sparse-vmemmap.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)
Quoted 13 lines
mm/sparse-vmemmap.c int __meminit vmemmap_populate_hvo(unsigned long addr, unsigned long end, · line 389
Quoted 9 lines
mm/sparse-vmemmap.c +1
-0@@ -386,12 +386,17 @@ int __meminit vmemmap_populate_hvo(unsigned long addr, unsigned long end,void __weak __meminit vmemmap_set_pmd (pmd_t *pmd,void *p,int node,unsigned long addr,unsigned long next) { +WARN_ON_ONCE (!pmd_set_huge (pmd,virt_to_phys (p),PAGE_KERNEL ));Not sure if a
VM_WARN_ON_ONCE()would be appropriate. (then, we have to move thepmd_set_huge()out of the statement).
I think it might be better to keep WARN_ON_ONCE here. This way, we can still monitor for warnings in production while keeping the code simple.
Quoted 2 lines
Thanks.
Quoted 6 lines
Signature · 4 lines
-- Cheers, David
Re: [PATCH v3 1/5] mm/sparse-vmemmap: provide generic vmemmap_set_pmd() and vmemmap_check_pmd()
Quoted 39 lines · Muchun Song
Quoted 25 lines · David Hildenbrand (Arm)
Quoted 20 lines · Muchun Song
The two weak functions are currently no-ops on every architecture, forcing each platform that needs them to duplicate the same handful of lines. Provide a generic implementation:
-
vmemmap_set_pmd()simply sets a huge PMD withPAGE_KERNELprotection.-
vmemmap_check_pmd()verifies that the PMD is present and leaf, then calls the existingvmemmap_verify()helper.Architectures that need special handling can continue to override the weak symbols; everyone else gets the standard version for free.
Signed-off-by Muchun Song <[email protected]>---
v2->v3:
- ReplaceBUG_ON()withWARN_ON_ONCE()invmemmap_set_pmd()
---mm/sparse-vmemmap.c| 7 ++++++-1 file changed, 6 insertions(+), 1 deletion(-)Quoted 13 lines
mm/sparse-vmemmap.c int __meminit vmemmap_populate_hvo(unsigned long addr, unsigned long end, · line 389
Quoted 9 lines
mm/sparse-vmemmap.c +1
-0@@ -386,12 +386,17 @@ int __meminit vmemmap_populate_hvo(unsigned long addr, unsigned long end,void __weak __meminit vmemmap_set_pmd (pmd_t *pmd,void *p,int node,unsigned long addr,unsigned long next) { +WARN_ON_ONCE (!pmd_set_huge (pmd,virt_to_phys (p),PAGE_KERNEL ));Not sure if a
VM_WARN_ON_ONCE()would be appropriate. (then, we have to move thepmd_set_huge()out of the statement).
Quoted 2 lines
I think it might be better to keep
WARN_ON_ONCEhere. This way, we can still monitor for warnings in production while keeping the code simple.
IIRC there was a discussion about this some time ago, given the fact that quite some people out there tend to have 'panic_on_warn', but then again, if we fail to set a PMD here it means something pretty nasty happened, so I am ok with that.
Signature · 2 lines
Oscar Salvador SUSE Labs
Re: [PATCH v3 1/5] mm/sparse-vmemmap: provide generic vmemmap_set_pmd() and vmemmap_check_pmd()
In reply to Muchun SongQuoted 6 lines · Muchun Song
The two weak functions are currently no-ops on every architecture, forcing each platform that needs them to duplicate the same handful of lines. Provide a generic implementation:
-
vmemmap_set_pmd()simply sets a huge PMD withPAGE_KERNELprotection.
Quoted 7 lines
-
vmemmap_check_pmd()verifies that the PMD is present and leaf, then calls the existingvmemmap_verify()helper.Architectures that need special handling can continue to override the weak symbols; everyone else gets the standard version for free.
Signed-off-by Muchun Song <[email protected]>
Signature · 2 lines
Oscar Salvador SUSE Labs
PATCH v3 2/5 arm64/mm: drop vmemmap_pmd helpers and use generic code
In reply to Muchun SongThe generic implementations now suffice; remove the arm64 copies.
---v2->v3:
- Collect Acked-by from Will Deacon
--- arch/arm64/mm/mmu.c | 14 -------------- 1 file changed, 14 deletions(-)
arch/arm64/mm/mmu.c +0 -14
@@ -1776,20 +1776,6 @@ static void free_empty_tables(unsigned long addr, unsigned long end, }#endif -void __meminit vmemmap_set_pmd (pmd_t *pmdp,void *p,int node, -unsigned long addr,unsigned long next) -{ -pmd_set_huge (pmdp,__pa (p),__pgprot (PROT_SECT_NORMAL )); -} - -int __meminit vmemmap_check_pmd (pmd_t *pmdp,int node, -unsigned long addr,unsigned long next) -{ -vmemmap_verify ((pte_t *)pmdp, node, addr, next); - -return pmd_leaf (READ_ONCE (*pmdp)); -} -int __meminit vmemmap_populate (unsigned long start,unsigned long end,int node,struct vmem_altmap *altmap) {
Signature · 1 line
2.54.0
Re: [PATCH v3 2/5] arm64/mm: drop vmemmap_pmd helpers and use generic code
Quoted 5 lines · Muchun Song
The generic implementations now suffice; remove the arm64 copies.
Signed-off-by Muchun Song <[email protected]>Acked-by Will Deacon <[email protected]>---
Signature · 3 lines
Cheers, David
Re: [PATCH v3 2/5] arm64/mm: drop vmemmap_pmd helpers and use generic code
In reply to Muchun SongQuoted 4 lines · Muchun Song
The generic implementations now suffice; remove the arm64 copies.
Signed-off-by Muchun Song <[email protected]>Acked-by Will Deacon <[email protected]>
Quoted 36 lines
---
v2->v3:
- Collect Acked-by from Will Deacon--- arch/arm64/mm/mmu.c | 14 -------------- 1 file changed, 14 deletions(-)arch/arm64/mm/mmu.c +0
-14@@ -1776,20 +1776,6 @@ static void free_empty_tables(unsigned long addr, unsigned long end, }#endif -void __meminit vmemmap_set_pmd (pmd_t *pmdp,void *p,int node, -unsigned long addr,unsigned long next) -{ -pmd_set_huge (pmdp,__pa (p),__pgprot (PROT_SECT_NORMAL )); -} - -int __meminit vmemmap_check_pmd (pmd_t *pmdp,int node, -unsigned long addr,unsigned long next) -{ -vmemmap_verify ((pte_t *)pmdp, node, addr, next); - -return pmd_leaf (READ_ONCE (*pmdp)); -} -int __meminit vmemmap_populate (unsigned long start,unsigned long end,int node,struct vmem_altmap *altmap) {Signature · 1 line
2.54.0
Signature · 2 lines
Oscar Salvador SUSE Labs
PATCH v3 3/5 riscv/mm: drop vmemmap_pmd helpers and use generic code
In reply to Muchun SongThe generic implementations now suffice; remove the riscv copies.
--- arch/riscv/mm/init.c | 13 ------------- 1 file changed, 13 deletions(-)
arch/riscv/mm/init.c +0 -13
@@ -1359,19 +1359,6 @@ void __init misc_mem_init(void) }#ifdef CONFIG_SPARSEMEM_VMEMMAP -void __meminit vmemmap_set_pmd (pmd_t *pmd,void *p,int node, -unsigned long addr,unsigned long next) -{ -pmd_set_huge (pmd,virt_to_phys (p),PAGE_KERNEL ); -} - -int __meminit vmemmap_check_pmd (pmd_t *pmdp,int node, -unsigned long addr,unsigned long next) -{ -vmemmap_verify ((pte_t *)pmdp, node, addr, next); -return 1 ; -} -int __meminit vmemmap_populate (unsigned long start,unsigned long end,int node,struct vmem_altmap *altmap) {
Signature · 1 line
2.54.0
Re: [PATCH v3 3/5] riscv/mm: drop vmemmap_pmd helpers and use generic code
Quoted 4 lines · Muchun Song
The generic implementations now suffice; remove the riscv copies.
Signed-off-by Muchun Song <[email protected]>---
Signature · 3 lines
Cheers, David
Re: [PATCH v3 3/5] riscv/mm: drop vmemmap_pmd helpers and use generic code
In reply to Muchun SongQuoted 3 lines · Muchun Song
The generic implementations now suffice; remove the riscv copies.
Signed-off-by Muchun Song <[email protected]>
Signature · 2 lines
Oscar Salvador SUSE Labs
PATCH v3 4/5 loongarch/mm: drop vmemmap_check_pmd helper and use generic code
In reply to Muchun SongThe generic implementations now suffice; remove the loongarch copies.
--- arch/loongarch/mm/init.c | 11 ----------- 1 file changed, 11 deletions(-)
arch/loongarch/mm/init.c +0 -11
@@ -140,17 +140,6 @@ void __meminit vmemmap_set_pmd(pmd_t *pmd, void *p, int node,set_pmd_at (&init_mm, addr, pmd, entry); } -int __meminit vmemmap_check_pmd (pmd_t *pmd,int node, -unsigned long addr,unsigned long next) -{ -int huge =pmd_val (pmdp_get (pmd)) & _PAGE_HUGE; - -if (huge) -vmemmap_verify ((pte_t *)pmd, node, addr, next); - -return huge; -} -int __meminit vmemmap_populate (unsigned long start,unsigned long end,int node,struct vmem_altmap *altmap) {
Signature · 1 line
2.54.0
Re: [PATCH v3 4/5] loongarch/mm: drop vmemmap_check_pmd helper and use generic code
Quoted 1 line · Muchun Song
The generic implementations now suffice; remove the loongarch copies.
You are only removing a single function? So "copy"
Signature · 3 lines
Cheers, David
Re: [PATCH v3 4/5] loongarch/mm: drop vmemmap_check_pmd helper and use generic code
Quoted 8 lines · David Hildenbrand (Arm)
Quoted 1 line · Muchun Song
The generic implementations now suffice; remove the loongarch copies.
You are only removing a single function? So "copy"
Yes. I copied the commit message from other commit and forgot to update accordingly.
Quoted 3 lines
Reviewed-by David Hildenbrand (Arm) <[email protected]>
Thanks.
Quoted 5 lines
Signature · 4 lines
-- Cheers, David
Re: [PATCH v3 4/5] loongarch/mm: drop vmemmap_check_pmd helper and use generic code
In reply to Muchun SongQuoted 3 lines · Muchun Song
The generic implementations now suffice; remove the loongarch copies.
Signed-off-by Muchun Song <[email protected]>
Signature · 2 lines
Oscar Salvador SUSE Labs
PATCH v3 5/5 sparc/mm: drop vmemmap_check_pmd helper and use generic code
In reply to Muchun SongThe generic implementations now suffice; remove the sparc copies.
--- arch/sparc/mm/init_64.c | 11 ----------- 1 file changed, 11 deletions(-)
arch/sparc/mm/init_64.c +0 -11
@@ -2559,17 +2559,6 @@ void __meminit vmemmap_set_pmd(pmd_t *pmd, void *p, int node,pmd_val (*pmd) = pte_base |__pa (p); } -int __meminit vmemmap_check_pmd (pmd_t *pmdp,int node, -unsigned long addr,unsigned long next) -{ -int large =pmd_leaf (*pmdp); - -if (large) -vmemmap_verify ((pte_t *)pmdp, node, addr, next); - -return large; -} -int __meminit vmemmap_populate (unsigned long vstart,unsigned long vend,int node,struct vmem_altmap *altmap) {
Signature · 1 line
2.54.0
Re: [PATCH v3 5/5] sparc/mm: drop vmemmap_check_pmd helper and use generic code
Quoted 1 line · Muchun Song
The generic implementations now suffice; remove the sparc copies.
"copy"
Signature · 3 lines
Cheers, David
Re: [PATCH v3 5/5] sparc/mm: drop vmemmap_check_pmd helper and use generic code
In reply to Muchun SongQuoted 3 lines · Muchun Song
The generic implementations now suffice; remove the sparc copies.
Signed-off-by Muchun Song <[email protected]>
Signature · 2 lines
Oscar Salvador SUSE Labs
This series was applied to riscv/linux.git (fixes) by Andrew Morton <[email protected]>:
Hello:
This series was applied to riscv/linux.git (fixes) by Andrew Morton <[email protected]>:
Quoted 10 lines · On Mon, 1 Jun 2026 16:48:39 +0800 you wrote:
The weak
vmemmap_set_pmd()andvmemmap_check_pmd()hooks are currently no-ops in the generic code, which leaves architectures that need PMD-level handling to open-code the same logic locally.This series provides generic implementations for both helpers in
mm/sparse-vmemmap.c.vmemmap_set_pmd()installs a huge PMD withPAGE_KERNELprotection, andvmemmap_check_pmd()verifies a present leaf PMD before reusing the existingvmemmap_verify()helper.[...]
Here is the summary with links:
- [v3,1/5] mm/sparse-vmemmap: provide generic vmemmap_set_pmd() and vmemmap_check_pmd()
https://git.kernel.org/riscv/c/0b6073ff1574 - [v3,2/5] arm64/mm: drop vmemmap_pmd helpers and use generic code https://git.kernel.org/riscv/c/f521f198b50a - [v3,3/5] riscv/mm: drop vmemmap_pmd helpers and use generic code https://git.kernel.org/riscv/c/abff0ecf7602 - [v3,4/5] loongarch/mm: drop vmemmap_check_pmd helper and use generic code https://git.kernel.org/riscv/c/ecca7da924b1 - [v3,5/5] sparc/mm: drop vmemmap_check_pmd helper and use generic code https://git.kernel.org/riscv/c/d3d58e946900
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html