mm/vmemmap/devdax: Fix kernel crash when probing devdax devices
Subsystems (8)
PATCH v2 1/2 mm/vmemmap/devdax: Fix kernel crash when probing devdax devices
commit 4917f55b4ef9 ("mm/sparse-vmemmap: improve memory savings for compound devmaps") added support for using optimized vmmemap for devdax devices. But how vmemmap mappings are created are architecture specific. For example, powerpc with hash translation doesn't have vmemmap mappings in init_mm page table instead they are bolted table entries in the hardware page table
vmemmap_populate_compound_pages() used by vmemmap optimization code is not aware of these architecture-specific mapping. Hence allow architecture to opt for this feature. I selected architectures supporting HUGETLB_PAGE_OPTIMIZE_VMEMMAP option as also supporting this feature.
This patch fixes the below crash on ppc64.
BUG: Unable to handle kernel data access on write at 0xc00c000100400038 Faulting instruction address: 0xc000000001269d90 Oops: Kernel access of bad area, sig: 11 [#1] LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries Modules linked in: CPU: 7 PID: 1 Comm: swapper/0 Not tainted 6.3.0-rc5-150500.34-default+ #2 5c90a668b6bbd142599890245c2fb5de19d7d28a Hardware name: IBM,9009-42G POWER9 (raw) 0x4e0202 0xf000005 of:IBM,FW950.40 (VL950_099) hv:phyp pSeries NIP: c000000001269d90 LR: c0000000004c57d4 CTR: 0000000000000000 REGS: c000000003632c30 TRAP: 0300 Not tainted (6.3.0-rc5-150500.34-default+) MSR: 8000000000009033 <SF,EE,ME,IR,DR,RI,LE> CR: 24842228 XER: 00000000 CFAR: c0000000004c57d0 DAR: c00c000100400038 DSISR: 42000000 IRQMASK: 0 .... NIP [c000000001269d90] __init_single_page.isra.74+0x14/0x4c LR [c0000000004c57d4] __init_zone_device_page+0x44/0xd0 Call Trace:
[c000000003632ed0] [c000000003632f60] 0xc000000003632f60 (unreliable) [c000000003632f10] [c0000000004c5ca0] memmap_init_zone_device+0x170/0x250 [c000000003632fe0] [c0000000005575f8] memremap_pages+0x2c8/0x7f0 [c0000000036330c0] [c000000000557b5c] devm_memremap_pages+0x3c/0xa0 [c000000003633100] [c000000000d458a8] dev_dax_probe+0x108/0x3e0 [c0000000036331a0] [c000000000d41430] dax_bus_probe+0xb0/0x140 [c0000000036331d0] [c000000000cef27c] really_probe+0x19c/0x520 [c000000003633260] [c000000000cef6b4] __driver_probe_device+0xb4/0x230 [c0000000036332e0] [c000000000cef888] driver_probe_device+0x58/0x120 [c000000003633320] [c000000000cefa6c] __device_attach_driver+0x11c/0x1e0 [c0000000036333a0] [c000000000cebc58] bus_for_each_drv+0xa8/0x130 [c000000003633400] [c000000000ceefcc] __device_attach+0x15c/0x250 [c0000000036334a0] [c000000000ced458] bus_probe_device+0x108/0x110 [c0000000036334f0] [c000000000ce92dc] device_add+0x7fc/0xa10 [c0000000036335b0] [c000000000d447c8] devm_create_dev_dax+0x1d8/0x530 [c000000003633640] [c000000000d46b60] __dax_pmem_probe+0x200/0x270 [c0000000036337b0] [c000000000d46bf0] dax_pmem_probe+0x20/0x70 [c0000000036337d0] [c000000000d2279c] nvdimm_bus_probe+0xac/0x2b0 [c000000003633860] [c000000000cef27c] really_probe+0x19c/0x520 [c0000000036338f0] [c000000000cef6b4] __driver_probe_device+0xb4/0x230 [c000000003633970] [c000000000cef888] driver_probe_device+0x58/0x120 [c0000000036339b0] [c000000000cefd08] __driver_attach+0x1d8/0x240 [c000000003633a30] [c000000000cebb04] bus_for_each_dev+0xb4/0x130 [c000000003633a90] [c000000000cee564] driver_attach+0x34/0x50 [c000000003633ab0] [c000000000ced878] bus_add_driver+0x218/0x300 [c000000003633b40] [c000000000cf1144] driver_register+0xa4/0x1b0 [c000000003633bb0] [c000000000d21a0c] __nd_driver_register+0x5c/0x100 [c000000003633c10] [c00000000206a2e8] dax_pmem_init+0x34/0x48 [c000000003633c30] [c0000000000132d0] do_one_initcall+0x60/0x320 [c000000003633d00] [c0000000020051b0] kernel_init_freeable+0x360/0x400 [c000000003633de0] [c000000000013764] kernel_init+0x34/0x1d0 [c000000003633e50] [c00000000000de14] ret_from_kernel_thread+0x5c/0x64
---
changes from V1:
* Only disable memory saving part of compound devmaps
* Update the correct Fixes: commit
* Add patch to drop HUGETLB specific kconfig
include/linux/mm.h | 16 ++++++++++++++++ mm/page_alloc.c | 9 ++++++--- mm/sparse-vmemmap.c | 3 +-- 3 files changed, 23 insertions(+), 5 deletions(-)
include/linux/mm.h +16 -0
@@ -3442,6 +3442,22 @@ void vmemmap_populate_print_last(void);void vmemmap_free (unsigned long start,unsigned long end,struct vmem_altmap *altmap);#endif + +#ifdef CONFIG_ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMA +static inline bool vmemmap_can_optimize (struct vmem_altmap *altmap, +struct dev_pagemap *pgmap) +{ +return is_power_of_2 (sizeof (struct page )) && + pgmap && (pgmap_vmemmap_nr (pgmap) >1 ) && !altmap; +} +#else +static inline bool vmemmap_can_optimize (struct vmem_altmap *altmap, +struct dev_pagemap *pgmap) +{ +return false; +} +#endif +void register_page_bootmem_memmap (unsigned long section_nr,struct page *map,unsigned long nr_pages);
mm/page_alloc.c +6 -3
@@ -6844,10 +6844,13 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn,* of an altmap. See vmemmap_populate_compound_pages(). */ static inline unsigned long compound_nr_pages (struct vmem_altmap *altmap, +struct dev_pagemap *pgmap,unsigned long nr_pages) { -return is_power_of_2 (sizeof (struct page )) && - !altmap ?2 * (PAGE_SIZE /sizeof (struct page )) : nr_pages; +if (vmemmap_can_optimize (altmap, pgmap)) +return 2 * (PAGE_SIZE /sizeof (struct page )); +else +return nr_pages; } static void __ref memmap_init_compound(struct page *head,
@@ -6912,7 +6915,7 @@ void __ref memmap_init_zone_device(struct zone *zone,continue ;memmap_init_compound (page, pfn, zone_idx, nid, pgmap, -compound_nr_pages (altmap, pfns_per_compound)); +compound_nr_pages (altmap, pgmap, pfns_per_compound)); } pr_info("%s initialised %lu pages in %ums\n", __func__,
mm/sparse-vmemmap.c +1 -2
@@ -458,8 +458,7 @@ struct page * __meminit __populate_section_memmap(unsigned long pfn, !IS_ALIGNED(nr_pages, PAGES_PER_SUBSECTION)))return NULL ; -if (is_power_of_2 (sizeof (struct page )) && - pgmap &&pgmap_vmemmap_nr (pgmap) >1 && !altmap) +if (vmemmap_can_optimize (altmap, pgmap)) r =vmemmap_populate_compound_pages (pfn, start, end, nid, pgmap);else r =vmemmap_populate (start, end, nid, altmap);
Signature · 1 line
2.39.2
PATCH v2 2/2 m/hugetlb: Rename ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
Now we use ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP config option to indicate devdax and hugetlb vmemmap optimization support. Hence rename that to a generic ARCH_WANT_OPTIMIZE_VMEMMAP
--- arch/arm64/Kconfig | 2 +- arch/loongarch/Kconfig | 2 +- arch/s390/Kconfig | 2 +- arch/x86/Kconfig | 2 +- fs/Kconfig | 9 +-------- include/linux/mm.h | 2 +- mm/Kconfig | 6 ++++++ 7 files changed, 12 insertions(+), 13 deletions(-)
arch/arm64/Kconfig +1 -1
@@ -100,9 +100,9 @@ config ARM64 select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36) - select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP select ARCH_WANT_LD_ORPHAN_WARN select ARCH_WANTS_NO_INSTR + select ARCH_WANT_OPTIMIZE_VMEMMAP select ARCH_WANTS_THP_SWAP if ARM64_4K_PAGES select ARCH_HAS_UBSAN_SANITIZE_ALL select ARM_AMBA
arch/loongarch/Kconfig +1 -1
@@ -53,9 +53,9 @@ config LOONGARCH select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT - select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP select ARCH_WANT_LD_ORPHAN_WARN select ARCH_WANTS_NO_INSTR + select ARCH_WANT_OPTIMIZE_VMEMMAP select BUILDTIME_TABLE_SORT select COMMON_CLK select CPU_PM
arch/s390/Kconfig +1 -1
@@ -126,7 +126,7 @@ config S390 select ARCH_WANTS_NO_INSTR select ARCH_WANT_DEFAULT_BPF_JIT select ARCH_WANT_IPC_PARSE_VERSION - select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP + select ARCH_WANT_OPTIMIZE_VMEMMAP select BUILDTIME_TABLE_SORT select CLONE_BACKWARDS2 select DMA_OPS if PCI
arch/x86/Kconfig +1 -1
@@ -125,8 +125,8 @@ config X86 select ARCH_WANTS_NO_INSTR select ARCH_WANT_GENERAL_HUGETLB select ARCH_WANT_HUGE_PMD_SHARE - select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP if X86_64 select ARCH_WANT_LD_ORPHAN_WARN + select ARCH_WANT_OPTIMIZE_VMEMMAP if X86_64 select ARCH_WANTS_THP_SWAP if X86_64 select ARCH_HAS_PARANOID_L1D_FLUSH select BUILDTIME_TABLE_SORT
fs/Kconfig +1 -8
@@ -250,16 +250,9 @@ config HUGETLBFS config HUGETLB_PAGE def_bool HUGETLBFS -# -# Select this config option from the architecture Kconfig, if it is preferred -# to enable the feature of HugeTLB Vmemmap Optimization (HVO). -# -config ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP - bool - config HUGETLB_PAGE_OPTIMIZE_VMEMMAP def_bool HUGETLB_PAGE - depends on ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP + depends on ARCH_WANT_OPTIMIZE_VMEMMAP depends on SPARSEMEM_VMEMMAP config HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ON
include/linux/mm.h +1 -1
@@ -3443,7 +3443,7 @@ void vmemmap_free(unsigned long start, unsigned long end, struct vmem_altmap *altmap);#endif -#ifdef CONFIG_ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMA +#ifdef CONFIG_ARCH_WANT_OPTIMIZE_VMEMMAP static inline bool vmemmap_can_optimize (struct vmem_altmap *altmap,struct dev_pagemap *pgmap) {
mm/Kconfig +6 -0
@@ -460,6 +460,12 @@ config SPARSEMEM_VMEMMAP SPARSEMEM_VMEMMAP uses a virtually mapped memmap to optimise pfn_to_page and page_to_pfn operations. This is the most efficient option when sufficient kernel resources are available. +# +# Select this config option from the architecture Kconfig, if it is preferred +# to enable the feature of HugeTLB/dev_dax vmemmap optimization. +# +config ARCH_WANT_OPTIMIZE_VMEMMAP + bool config HAVE_MEMBLOCK_PHYS_MAP bool
Signature · 1 line
2.39.2
Re: [PATCH v2 2/2] m/hugetlb: Rename ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
[subject line should be mm/hugetlb as opposed to m/hugetlb]
Quoted 8 lines · Aneesh Kumar K.V
Now we use
ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAPconfig option to indicate devdax and hugetlb vmemmap optimization support. Hence rename that to a genericARCH_WANT_OPTIMIZE_VMEMMAPCc Joao Martins <[email protected]>Cc Muchun Song <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>
+Mike from hugetlb
Quoted 15 lines
--- arch/arm64/Kconfig | 2 +- arch/loongarch/Kconfig | 2 +- arch/s390/Kconfig | 2 +- arch/x86/Kconfig | 2 +- fs/Kconfig | 9 +-------- include/linux/mm.h | 2 +- mm/Kconfig | 6 ++++++ 7 files changed, 12 insertions(+), 13 deletions(-)arch/arm64/Kconfig +0
-0
arch/arm64/Kconfig config ARM64 · line 105
Quoted 7 lines
arch/arm64/Kconfig +1
-1@@ -100,9 +100,9 @@ config ARM64 select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36) - select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP select ARCH_WANT_LD_ORPHAN_WARN select ARCH_WANTS_NO_INSTR + select ARCH_WANT_OPTIMIZE_VMEMMAP
Why don't you just change the line you just deleted?
Quoted 8 lines
arch/arm64/Kconfig +0
-0select ARCH_WANTS_THP_SWAP if ARM64_4K_PAGES select ARCH_HAS_UBSAN_SANITIZE_ALL select ARM_AMBAarch/loongarch/Kconfig +0
-0
arch/loongarch/Kconfig config LOONGARCH · line 58
Quoted 7 lines
arch/loongarch/Kconfig +1
-1@@ -53,9 +53,9 @@ config LOONGARCH select ARCH_USE_QUEUED_RWLOCKS select ARCH_USE_QUEUED_SPINLOCKS select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT - select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP select ARCH_WANT_LD_ORPHAN_WARN select ARCH_WANTS_NO_INSTR + select ARCH_WANT_OPTIMIZE_VMEMMAP
Same comment here
Quoted 8 lines
arch/loongarch/Kconfig +0
-0select BUILDTIME_TABLE_SORT select COMMON_CLK select CPU_PMarch/s390/Kconfig +0
-0
arch/s390/Kconfig config S390 · line 132
Quoted 8 lines
arch/s390/Kconfig +1
-1@@ -126,7 +126,7 @@ config S390 select ARCH_WANTS_NO_INSTR select ARCH_WANT_DEFAULT_BPF_JIT select ARCH_WANT_IPC_PARSE_VERSION - select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP + select ARCH_WANT_OPTIMIZE_VMEMMAP select BUILDTIME_TABLE_SORT select CLONE_BACKWARDS2 select DMA_OPS if PCI
This one is good
Quoted 5 lines
arch/x86/Kconfig +0
-0
arch/x86/Kconfig config X86 · line 132
Quoted 9 lines
arch/x86/Kconfig +1
-1@@ -125,8 +125,8 @@ config X86 select ARCH_WANTS_NO_INSTR select ARCH_WANT_GENERAL_HUGETLB select ARCH_WANT_HUGE_PMD_SHARE - select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP if X86_64 select ARCH_WANT_LD_ORPHAN_WARN + select ARCH_WANT_OPTIMIZE_VMEMMAP if X86_64 select ARCH_WANTS_THP_SWAP if X86_64 select ARCH_HAS_PARANOID_L1D_FLUSH select BUILDTIME_TABLE_SORT
Same comment here
Quoted 52 lines
fs/Kconfig +1
-8@@ -250,16 +250,9 @@ config HUGETLBFS config HUGETLB_PAGE def_bool HUGETLBFS -# -# Select this config option from the architecture Kconfig, if it is preferred -# to enable the feature of HugeTLB Vmemmap Optimization (HVO). -# -config ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP - bool - config HUGETLB_PAGE_OPTIMIZE_VMEMMAP def_bool HUGETLB_PAGE - depends on ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP + depends on ARCH_WANT_OPTIMIZE_VMEMMAP depends on SPARSEMEM_VMEMMAP config HUGETLB_PAGE_OPTIMIZE_VMEMMAP_DEFAULT_ONinclude/linux/mm.h +1
-1@@ -3443,7 +3443,7 @@ void vmemmap_free(unsigned long start, unsigned long end, struct vmem_altmap *altmap);#endif -#ifdef CONFIG_ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMA +#ifdef CONFIG_ARCH_WANT_OPTIMIZE_VMEMMAP static inline bool vmemmap_can_optimize (struct vmem_altmap *altmap,struct dev_pagemap *pgmap) {mm/Kconfig +6
-0@@ -460,6 +460,12 @@ config SPARSEMEM_VMEMMAP SPARSEMEM_VMEMMAP uses a virtually mapped memmap to optimise pfn_to_page and page_to_pfn operations. This is the most efficient option when sufficient kernel resources are available. +# +# Select this config option from the architecture Kconfig, if it is preferred +# to enable the feature of HugeTLB/dev_dax vmemmap optimization. +# +config ARCH_WANT_OPTIMIZE_VMEMMAP + bool config HAVE_MEMBLOCK_PHYS_MAP bool
Re: [PATCH v2 2/2] m/hugetlb: Rename ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
Quoted 24 lines · Joao Martins
[subject line should be mm/hugetlb as opposed to m/hugetlb]
Quoted 8 lines · Aneesh Kumar K.V
Now we use
ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAPconfig option to indicate devdax and hugetlb vmemmap optimization support. Hence rename that to a genericARCH_WANT_OPTIMIZE_VMEMMAPCc Joao Martins <[email protected]>Cc Muchun Song <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>+Mike from hugetlb
Quoted 10 lines
--- arch/arm64/Kconfig | 2 +- arch/loongarch/Kconfig | 2 +- arch/s390/Kconfig | 2 +- arch/x86/Kconfig | 2 +- fs/Kconfig | 9 +-------- include/linux/mm.h | 2 +- mm/Kconfig | 6 ++++++ 7 files changed, 12 insertions(+), 13 deletions(-)
Quoted 15 lines
arch/arm64/Kconfig config ARM64 · line 105
Quoted 12 lines
arch/arm64/Kconfig +1
-1@@ -100,9 +100,9 @@ config ARM64 select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36) - select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP select ARCH_WANT_LD_ORPHAN_WARN select ARCH_WANTS_NO_INSTR + select ARCH_WANT_OPTIMIZE_VMEMMAPWhy don't you just change the line you just deleted?
Those config select statements are sorted?
-aneesh
Re: [PATCH v2 2/2] m/hugetlb: Rename ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
Quoted 41 lines · Aneesh Kumar K V
Quoted 24 lines · Joao Martins
[subject line should be mm/hugetlb as opposed to m/hugetlb]
Quoted 8 lines · Aneesh Kumar K.V
Now we use
ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAPconfig option to indicate devdax and hugetlb vmemmap optimization support. Hence rename that to a genericARCH_WANT_OPTIMIZE_VMEMMAPCc Joao Martins <[email protected]>Cc Muchun Song <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>+Mike from hugetlb
Quoted 10 lines
--- arch/arm64/Kconfig | 2 +- arch/loongarch/Kconfig | 2 +- arch/s390/Kconfig | 2 +- arch/x86/Kconfig | 2 +- fs/Kconfig | 9 +-------- include/linux/mm.h | 2 +- mm/Kconfig | 6 ++++++ 7 files changed, 12 insertions(+), 13 deletions(-)Quoted 15 lines
arch/arm64/Kconfig config ARM64 · line 105
Quoted 12 lines
arch/arm64/Kconfig +1
-1@@ -100,9 +100,9 @@ config ARM64 select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_HUGE_PMD_SHARE if ARM64_4K_PAGES || (ARM64_16K_PAGES && !ARM64_VA_BITS_36) - select ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP select ARCH_WANT_LD_ORPHAN_WARN select ARCH_WANTS_NO_INSTR + select ARCH_WANT_OPTIMIZE_VMEMMAPWhy don't you just change the line you just deleted?
Quoted 1 line
Those config select statements are sorted?
/me facepalm
Totally missed that.
Re: [External] [PATCH v2 2/2] m/hugetlb: Rename ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAP
In reply to Aneesh Kumar K.VQuoted 9 lines · Aneesh Kumar K.V
Now we use
ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMAPconfig option to indicate devdax and hugetlb vmemmap optimization support. Hence rename that to a genericARCH_WANT_OPTIMIZE_VMEMMAPCc Joao Martins <[email protected]>Cc Muchun Song <[email protected]>Cc Dan Williams <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>
I suggest rewording the prefix of subject to "mm/hugetlb_vmemmap:". Renaming LGTM.
Thanks.
Quoted 11 lines · Aneesh Kumar K.V
commit
4917f55b4ef9("mm/sparse-vmemmap: improve memory savings for compound devmaps") added support for using optimized vmmemap for devdax devices. But how vmemmap mappings are created are architecture specific. For example, powerpc with hash translation doesn't have vmemmap mappings ininit_mmpage table instead they are bolted table entries in the hardware page table
vmemmap_populate_compound_pages()used by vmemmap optimization code is not aware of these architecture-specific mapping. Hence allow architecture to opt for this feature. I selected architectures supportingHUGETLB_PAGE_OPTIMIZE_VMEMMAPoption as also supporting this feature.
Perhaps rephrase last sentence to be in imperative form e.g.:
Architectures supporting HUGETLB_PAGE_OPTIMIZE_VMEMMAP option are selected when supporting this feature.
Quoted 2 lines
This patch fixes the below crash on ppc64.
Avoid the 'This patch' per submission guidelines e.g.
'On ppc64 (pmem) where this isn't supported, it fixes below crash:'
Quoted 70 lines
BUG: Unable to handle kernel data access on write at 0xc00c000100400038 Faulting instruction address: 0xc000000001269d90 Oops: Kernel access of bad area, sig: 11 [#1] LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries Modules linked in: CPU: 7 PID: 1 Comm: swapper/0 Not tainted 6.3.0-rc5-150500.34-default+ #2 5c90a668b6bbd142599890245c2fb5de19d7d28a Hardware name: IBM,9009-42G POWER9 (raw) 0x4e0202 0xf000005 of:IBM,FW950.40 (VL950_099) hv:phyp pSeries NIP: c000000001269d90 LR: c0000000004c57d4 CTR: 0000000000000000 REGS: c000000003632c30 TRAP: 0300 Not tainted (6.3.0-rc5-150500.34-default+) MSR: 8000000000009033 <SF,EE,ME,IR,DR,RI,LE> CR: 24842228 XER: 00000000 CFAR: c0000000004c57d0 DAR: c00c000100400038 DSISR: 42000000 IRQMASK: 0 .... NIP [c000000001269d90] __init_single_page.isra.74+0x14/0x4c LR [c0000000004c57d4] __init_zone_device_page+0x44/0xd0 Call Trace:[
c000000003632ed0] [c000000003632f60]0xc000000003632f60(unreliable) [c000000003632f10] [c0000000004c5ca0]memmap_init_zone_device+0x170/0x250[c000000003632fe0] [c0000000005575f8]memremap_pages+0x2c8/0x7f0[c0000000036330c0] [c000000000557b5c]devm_memremap_pages+0x3c/0xa0[c000000003633100] [c000000000d458a8]dev_dax_probe+0x108/0x3e0[c0000000036331a0] [c000000000d41430]dax_bus_probe+0xb0/0x140[c0000000036331d0] [c000000000cef27c]really_probe+0x19c/0x520[c000000003633260] [c000000000cef6b4]__driver_probe_device+0xb4/0x230[c0000000036332e0] [c000000000cef888]driver_probe_device+0x58/0x120[c000000003633320] [c000000000cefa6c]__device_attach_driver+0x11c/0x1e0[c0000000036333a0] [c000000000cebc58]bus_for_each_drv+0xa8/0x130[c000000003633400] [c000000000ceefcc]__device_attach+0x15c/0x250[c0000000036334a0] [c000000000ced458]bus_probe_device+0x108/0x110[c0000000036334f0] [c000000000ce92dc]device_add+0x7fc/0xa10[c0000000036335b0] [c000000000d447c8]devm_create_dev_dax+0x1d8/0x530[c000000003633640] [c000000000d46b60]__dax_pmem_probe+0x200/0x270[c0000000036337b0] [c000000000d46bf0]dax_pmem_probe+0x20/0x70[c0000000036337d0] [c000000000d2279c]nvdimm_bus_probe+0xac/0x2b0[c000000003633860] [c000000000cef27c]really_probe+0x19c/0x520[c0000000036338f0] [c000000000cef6b4]__driver_probe_device+0xb4/0x230[c000000003633970] [c000000000cef888]driver_probe_device+0x58/0x120[c0000000036339b0] [c000000000cefd08]__driver_attach+0x1d8/0x240[c000000003633a30] [c000000000cebb04]bus_for_each_dev+0xb4/0x130[c000000003633a90] [c000000000cee564]driver_attach+0x34/0x50[c000000003633ab0] [c000000000ced878]bus_add_driver+0x218/0x300[c000000003633b40] [c000000000cf1144]driver_register+0xa4/0x1b0[c000000003633bb0] [c000000000d21a0c]__nd_driver_register+0x5c/0x100[c000000003633c10] [c00000000206a2e8]dax_pmem_init+0x34/0x48[c000000003633c30] [c0000000000132d0]do_one_initcall+0x60/0x320[c000000003633d00] [c0000000020051b0]kernel_init_freeable+0x360/0x400[c000000003633de0] [c000000000013764]kernel_init+0x34/0x1d0[c000000003633e50] [c00000000000de14]ret_from_kernel_thread+0x5c/0x64Fixes 4917f55b4ef9 ("mm/sparse-vmemmap: improve memory savings for compound devmaps")Cc Joao Martins <[email protected]>Cc Muchun Song <[email protected]>Cc Dan Williams <[email protected]>Reported-by Tarun Sahu <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>---
changes from V1:
* Only disable memory saving part of compound devmaps
* Update the correct Fixes: commit
* Add patch to drop HUGETLB specific kconfiginclude/linux/mm.h | 16 ++++++++++++++++ mm/page_alloc.c | 9 ++++++--- mm/sparse-vmemmap.c | 3 +-- 3 files changed, 23 insertions(+), 5 deletions(-)include/linux/mm.h +0
-0
include/linux/mm.h void vmemmap_populate_print_last(void); · line 3446
Quoted 5 lines
include/linux/mm.h +2
-0@@ -3442,6 +3442,22 @@ void vmemmap_populate_print_last(void);void vmemmap_free (unsigned long start,unsigned long end,struct vmem_altmap *altmap);#endif + +#ifdef CONFIG_ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMA
You are missing a 'P'
Quoted 26 lines
include/linux/mm.h +14
-0+static inline bool vmemmap_can_optimize (struct vmem_altmap *altmap, +struct dev_pagemap *pgmap) +{ +return is_power_of_2 (sizeof (struct page )) && + pgmap && (pgmap_vmemmap_nr (pgmap) >1 ) && !altmap; +} +#else +static inline bool vmemmap_can_optimize (struct vmem_altmap *altmap, +struct dev_pagemap *pgmap) +{ +return false; +} +#endif +void register_page_bootmem_memmap (unsigned long section_nr,struct page *map,unsigned long nr_pages);mm/page_alloc.c +1
-0@@ -6844,10 +6844,13 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn,* of an altmap. See vmemmap_populate_compound_pages(). */ static inline unsigned long compound_nr_pages(struct vmem_altmap *altmap, + struct dev_pagemap *pgmap,
mm/page_alloc.c static void __ref __init_zone_device_page(struct page *page, unsigned long pfn, · line 6855
Quoted 10 lines
mm/page_alloc.c +4
-2unsigned long nr_pages) { -return is_power_of_2 (sizeof (struct page )) && - !altmap ?2 * (PAGE_SIZE /sizeof (struct page )) : nr_pages; +if (vmemmap_can_optimize (altmap, pgmap)) +return 2 * (PAGE_SIZE /sizeof (struct page )); +else +return nr_pages; }
Keep the ternary operator as already is the case for compound_nr_pages to avoid doing too much in one patch:
return vmemmap_can_optimize(altmap, pgmap) ? 2 * (PAGE_SIZE / sizeof(struct page)) : nr_pages;
Or you really want to remove the ternary operator perhaps take the unnecessary else and make the long line be less indented:
if (!vmemmap_can_optimize(altmap, pgmap)) return nr_pages; return 2 * (PAGE_SIZE / sizeof(struct page));
I don't think the latter is a significant improvement over the ternary one. But I guess that's a matter of preferred style.
Quoted 24 lines
mm/page_alloc.c +1
-1static void __ref memmap_init_compound(struct page *head,@@ -6912,7 +6915,7 @@ void __ref memmap_init_zone_device(struct zone *zone,continue ;memmap_init_compound (page, pfn, zone_idx, nid, pgmap, -compound_nr_pages (altmap, pfns_per_compound)); +compound_nr_pages (altmap, pgmap, pfns_per_compound)); } pr_info("%s initialised %lu pages in %ums\n", __func__,mm/sparse-vmemmap.c +1
-2@@ -458,8 +458,7 @@ struct page * __meminit __populate_section_memmap(unsigned long pfn, !IS_ALIGNED(nr_pages, PAGES_PER_SUBSECTION)))return NULL ; -if (is_power_of_2 (sizeof (struct page )) && - pgmap &&pgmap_vmemmap_nr (pgmap) >1 && !altmap) +if (vmemmap_can_optimize (altmap, pgmap)) r =vmemmap_populate_compound_pages (pfn, start, end, nid, pgmap);else r =vmemmap_populate (start, end, nid, altmap);
Quoted 14 lines · Joao Martins
Quoted 11 lines · Aneesh Kumar K.V
commit
4917f55b4ef9("mm/sparse-vmemmap: improve memory savings for compound devmaps") added support for using optimized vmmemap for devdax devices. But how vmemmap mappings are created are architecture specific. For example, powerpc with hash translation doesn't have vmemmap mappings ininit_mmpage table instead they are bolted table entries in the hardware page table
vmemmap_populate_compound_pages()used by vmemmap optimization code is not aware of these architecture-specific mapping. Hence allow architecture to opt for this feature. I selected architectures supportingHUGETLB_PAGE_OPTIMIZE_VMEMMAPoption as also supporting this feature.Perhaps rephrase last sentence to be in imperative form e.g.:
Quoted 8 lines
Architectures supporting
HUGETLB_PAGE_OPTIMIZE_VMEMMAPoption are selected when supporting this feature.Quoted 2 lines
This patch fixes the below crash on ppc64.
Avoid the 'This patch' per submission guidelines e.g.
'On ppc64 (pmem) where this isn't supported, it fixes below crash:'
ok will update in the next version.
Quoted 7 lines
Quoted 6 lines
BUG: Unable to handle kernel data access on write at 0xc00c000100400038 Faulting instruction address: 0xc000000001269d90 Oops: Kernel access of bad area, sig: 11 [#1] LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries Modules linked in:
...
Quoted 4 lines
Quoted 4 lines
include/linux/mm.h +0
-0
Quoted 8 lines
include/linux/mm.h void vmemmap_populate_print_last(void); · line 3446
Quoted 6 lines
include/linux/mm.h +2
-0@@ -3442,6 +3442,22 @@ void vmemmap_populate_print_last(void);void vmemmap_free (unsigned long start,unsigned long end,struct vmem_altmap *altmap);#endif + +#ifdef CONFIG_ARCH_WANT_HUGETLB_PAGE_OPTIMIZE_VMEMMA You are missing a 'P'
I noticed that after sending v2 and sent v2-updated with that change.
Quoted 47 lines
Quoted 27 lines
include/linux/mm.h +14
-0+static inline bool vmemmap_can_optimize (struct vmem_altmap *altmap, +struct dev_pagemap *pgmap) +{ +return is_power_of_2 (sizeof (struct page )) && + pgmap && (pgmap_vmemmap_nr (pgmap) >1 ) && !altmap; +} +#else +static inline bool vmemmap_can_optimize (struct vmem_altmap *altmap, +struct dev_pagemap *pgmap) +{ +return false; +} +#endif +void register_page_bootmem_memmap (unsigned long section_nr,struct page *map,unsigned long nr_pages);mm/page_alloc.c +1
-0@@ -6844,10 +6844,13 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn,* of an altmap. See vmemmap_populate_compound_pages(). */ static inline unsigned long compound_nr_pages(struct vmem_altmap *altmap, + struct dev_pagemap *pgmap,mm/page_alloc.c static void __ref __init_zone_device_page(struct page *page, unsigned long pfn, · line 6855
Quoted 10 lines
mm/page_alloc.c +4
-2unsigned long nr_pages) { -return is_power_of_2 (sizeof (struct page )) && - !altmap ?2 * (PAGE_SIZE /sizeof (struct page )) : nr_pages; +if (vmemmap_can_optimize (altmap, pgmap)) +return 2 * (PAGE_SIZE /sizeof (struct page )); +else +return nr_pages; }Keep the ternary operator as already is the case for
compound_nr_pagesto avoid doing too much in one patch:return vmemmap_can_optimize(altmap, pgmap) ? 2 * (PAGE_SIZE / sizeof(struct page)) : nr_pages;Or you really want to remove the ternary operator perhaps take the unnecessary else and make the long line be less indented:
Quoted 7 lines
if (!vmemmap_can_optimize(altmap, pgmap)) return nr_pages; return 2 * (PAGE_SIZE / sizeof(struct page));I don't think the latter is a significant improvement over the ternary one. But I guess that's a matter of preferred style.
How about
static inline unsigned long compound_nr_pages(struct vmem_altmap *altmap,
struct dev_pagemap *pgmap)
{
if (!vmemmap_can_optimize(altmap, pgmap)) return pgmap_vmemmap_nr(pgmap); return 2 * (PAGE_SIZE / sizeof(struct page)); }
Quoted 19 lines
Quoted 19 lines
mm/page_alloc.c +1
-1static void __ref memmap_init_compound(struct page *head,@@ -6912,7 +6915,7 @@ void __ref memmap_init_zone_device(struct zone *zone,continue ;memmap_init_compound (page, pfn, zone_idx, nid, pgmap, -compound_nr_pages (altmap, pfns_per_compound)); +compound_nr_pages (altmap, pgmap, pfns_per_compound)); } pr_info("%s initialised %lu pages in %ums\n", __func__,mm/sparse-vmemmap.c +0
-0@@ -458,8 +458,7 @@ struct page * __meminit __populate_section_memmap(unsigned long pfn, !IS_ALIGNED(nr_pages, PAGES_PER_SUBSECTION)))return NULL ;
Quoted 6 lines
mm/sparse-vmemmap.c struct page * __meminit __populate_section_memmap(unsigned long pfn, · line 464
Quoted 6 lines
mm/sparse-vmemmap.c +1
-2-if (is_power_of_2 (sizeof (struct page )) && - pgmap &&pgmap_vmemmap_nr (pgmap) >1 && !altmap) +if (vmemmap_can_optimize (altmap, pgmap)) r =vmemmap_populate_compound_pages (pfn, start, end, nid, pgmap);else r =vmemmap_populate (start, end, nid, altmap);
-aneesh
Quoted 45 lines · Aneesh Kumar K.V
Quoted 30 lines · Joao Martins
Quoted 9 lines · Aneesh Kumar K.V
mm/page_alloc.c +1
-0@@ -6844,10 +6844,13 @@ static void __ref __init_zone_device_page(struct page *page, unsigned long pfn,* of an altmap. See vmemmap_populate_compound_pages(). */ static inline unsigned long compound_nr_pages(struct vmem_altmap *altmap, + struct dev_pagemap *pgmap,mm/page_alloc.c static void __ref __init_zone_device_page(struct page *page, unsigned long pfn, · line 6855
Quoted 10 lines
mm/page_alloc.c +4
-2unsigned long nr_pages) { -return is_power_of_2 (sizeof (struct page )) && - !altmap ?2 * (PAGE_SIZE /sizeof (struct page )) : nr_pages; +if (vmemmap_can_optimize (altmap, pgmap)) +return 2 * (PAGE_SIZE /sizeof (struct page )); +else +return nr_pages; }Keep the ternary operator as already is the case for
compound_nr_pagesto avoid doing too much in one patch:return vmemmap_can_optimize(altmap, pgmap) ? 2 * (PAGE_SIZE / sizeof(struct page)) : nr_pages;Or you really want to remove the ternary operator perhaps take the unnecessary else and make the long line be less indented:
Quoted 7 lines
if (!vmemmap_can_optimize(altmap, pgmap)) return nr_pages; return 2 * (PAGE_SIZE / sizeof(struct page));I don't think the latter is a significant improvement over the ternary one. But I guess that's a matter of preferred style.
How about
static inline unsigned long compound_nr_pages(struct
vmem_altmap*altmap,
structdev_pagemap*pgmap)
{
Quoted 6 lines
if (!vmemmap_can_optimize(altmap, pgmap)) return pgmap_vmemmap_nr(pgmap); return 2 * (PAGE_SIZE / sizeof(struct page)); }
I am a bit more fond of the ternary option. But this snip above is fine as well, including with the s/nr_pages/pgmap_vmemmap_nr(pgmap)/ change you added.