Skip to contentSkip to conversation

mm/sparse-vmemmap: provide generic vmemmap_set_pmd() and vmemmap_check_pmd()

PATCH Superseded Muchun Song 3 participants 12 messages Apr 4 – Jun 26

Subsystems (6)

v1 of 3 Superseded 2 of 5 applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover mm/sparse-vmemmap: provide generic vmemmap_set_pmd() and vmemmap_check_pmd()

The two weak functions vmemmap_set_pmd() and vmemmap_check_pmd() 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.

This series drops the custom implementations in arm64, riscv, loongarch, and sparc, replacing them with the generic implementation introduced in the first patch.

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(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/4 arm64/mm: drop vmemmap_pmd helpers and use generic code

The generic implementations now suffice; remove the arm64 copies.

---
 arch/arm64/mm/mmu.c | 14 --------------
 1 file changed, 14 deletions(-)
arch/arm64/mm/mmu.c +0 -14
index ec1c6971a561..b87053452641 100644
@@ -1745,20 +1745,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_sect(READ_ONCE(*pmdp));
-}
-
 int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
 		struct vmem_altmap *altmap)
 {
Signature · 1 line
2.20.1
#2 lore raw

PATCH 1/5 mm/sparse-vmemmap: provide generic vmemmap_set_pmd() and vmemmap_check_pmd()

In reply to 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 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.

---
 mm/sparse-vmemmap.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
mm/sparse-vmemmap.c +6 -1
index 6eadb9d116e4..1eb990610d50 100644
@@ -391,12 +391,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)
 {
+	BUG_ON(!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.20.1
#3 lore raw

PATCH 2/5 arm64/mm: drop vmemmap_pmd helpers and use generic code

In reply to Muchun Song

The generic implementations now suffice; remove the arm64 copies.

---
 arch/arm64/mm/mmu.c | 14 --------------
 1 file changed, 14 deletions(-)
arch/arm64/mm/mmu.c +0 -14
index ec1c6971a561..b87053452641 100644
@@ -1745,20 +1745,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_sect(READ_ONCE(*pmdp));
-}
-
 int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node,
 		struct vmem_altmap *altmap)
 {
Signature · 1 line
2.20.1
#4 lore raw

PATCH 2/4 riscv/mm: drop vmemmap_pmd helpers and use generic code

In reply to Muchun Song

The 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
index 5142ca80be6f..f7e7d7c2e97f 100644
@@ -1429,19 +1429,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.20.1
#5 lore raw

PATCH 3/4 loongarch/mm: drop vmemmap_check_pmd helper and use generic code

In reply to Muchun Song

The 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
index 00f3822b6e47..7356d4eea140 100644
@@ -110,17 +110,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.20.1
#6 lore raw

PATCH 3/5 riscv/mm: drop vmemmap_pmd helpers and use generic code

In reply to Muchun Song

The 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
index 5142ca80be6f..f7e7d7c2e97f 100644
@@ -1429,19 +1429,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.20.1
#7 lore raw

PATCH 4/5 loongarch/mm: drop vmemmap_check_pmd helper and use generic code

In reply to Muchun Song

The 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
index 00f3822b6e47..7356d4eea140 100644
@@ -110,17 +110,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.20.1
#8 lore raw

PATCH 4/4 sparc/mm: drop vmemmap_check_pmd helper and use generic code

In reply to Muchun Song

The 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
index 367c269305e5..4a089da0a490 100644
@@ -2579,17 +2579,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.20.1
#9 lore raw

PATCH 5/5 sparc/mm: drop vmemmap_check_pmd helper and use generic code

In reply to Muchun Song

The 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
index 367c269305e5..4a089da0a490 100644
@@ -2579,17 +2579,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.20.1
#10 lore raw
In reply to Muchun Song
Quoted 19 lines · Muchun Song

The two weak functions vmemmap_set_pmd() and vmemmap_check_pmd() 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.

This series drops the custom implementations in arm64, riscv, loongarch, and sparc, replacing them with the generic implementation introduced in the first patch.

Quoted 7 lines

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

Hi all,

Please accept my sincere apologies for the mailing list noise.

Due to an error in my local scripts (failing to clean up the patch output directory before regenerating the series with an updated commit range), multiple duplicate and conflicting patches were accidentally sent to the list simultaneously (10 patches in total instead of the intended 5).

Sorry again for the inconvenience.

Thanks,
Muchun

Quoted 11 lines
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(-)
Signature · 1 line
2.20.1
#11 lore raw
In reply to Muchun Song
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 Sat, 4 Apr 2026 15:17:04 +0800 you wrote:

The two weak functions vmemmap_set_pmd() and vmemmap_check_pmd() 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.

[...]

Here is the summary with links:
- [2/4] riscv/mm: drop vmemmap_pmd helpers and use generic code

    https://git.kernel.org/riscv/c/abff0ecf7602
  - [3/5] riscv/mm: drop vmemmap_pmd helpers and use generic code
    https://git.kernel.org/riscv/c/abff0ecf7602

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html