History

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

Patch series "mm/sparse-vmemmap: Provide generic vmemmap_set_pmd() and vmemmap_check_pmd()", v3. 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. This patch (of 5): 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.

Muchun Song committed 5 months ago

Commit 0b6073f1 parent a71204e1 file · +6 −1Browse files

Unified · Split

mm/sparse-vmemmap.c+6−1
@@ -386,12 +386,17 @@ int __meminit vmemmap_populate_hvo(unsigned long addr, unsigned long end, · 385 unmodified lines
386386 void __weak __meminit vmemmap_set_pmd(pmd_t *pmd, void *p, int node,
387387 unsigned long addr, unsigned long next)
388388 {
389+ WARN_ON_ONCE(!pmd_set_huge(pmd, virt_to_phys(p), PAGE_KERNEL));
389390 }
390391
391392 int __weak __meminit vmemmap_check_pmd(pmd_t *pmd, int node,
392393 unsigned long addr, unsigned long next)
393394 {
394− return 0;
395+ if (!pmd_leaf(pmdp_get(pmd)))
396+ return 0;
397+ vmemmap_verify((pte_t *)pmd, node, addr, next);
398+
399+ return 1;
395400 }
396401
397402 int __meminit vmemmap_populate_hugepages(unsigned long start, unsigned long end,