arm64: mm: Do not defer reserve_crashkernel()
v3 cover arm64: mm: Do not defer reserve_crashkernel()
Commit 031495635b46 ("arm64: Do not defer reserve_crashkernel() for platforms with no DMA memory zones"), this lets the kernel benifit due to BLOCK_MAPPINGS, we could do more if ZONE_DMA and ZONE_DMA32 enabled.
1) Don't defer reserve_crashkernel() if only ZONE_DMA32
2) Don't defer reserve_crashkernel() if ZONE_DMA with dma_force_32bit kernel parameter(newly added)
Here is another case to show the benefit of the block mapping.
Unixbench benchmark result shows between the block mapping and page mapping.
----------------+------------------+-------------------
| block mapping | page mapping
----------------+------------------+-------------------
Process Creation| 5,030.7 | 4,711.8 (in unixbench) | |
----------------+------------------+-------------------
note: RODATA_FULL_DEFAULT_ENABLED is not enabled
v3:
- renaming crashkernel_could_early_reserve() to crashkernel_early_reserve()
- drop dma32_phys_limit, directly use max_zone_phys(32)
- fix no previous prototype issue
- add RB of Vijay to patch2/3
v2 resend:
- fix build error reported-by lkp
v2:
- update patch1 according to Vijay and Florian, and RB of Vijay
- add new patch2
Kefeng Wang (3):
arm64: mm: Do not defer reserve_crashkernel() if only ZONE_DMA32
arm64: mm: Don't defer reserve_crashkernel() with dma_force_32bit
arm64: mm: Cleanup useless parameters in zone_sizes_init()
arch/arm64/include/asm/kexec.h | 1 + arch/arm64/mm/init.c | 60 ++++++++++++++++++++++++---------- arch/arm64/mm/mmu.c | 6 ++-- 3 files changed, 46 insertions(+), 21 deletions(-)
Signature · 1 line
2.26.2
PATCH v3 1/3 arm64: mm: Do not defer reserve_crashkernel() if only ZONE_DMA32
The kernel could benefit due to BLOCK_MAPPINGS, see commit 031495635b46 ("arm64: Do not defer reserve_crashkernel() for platforms with no DMA memory zones"), if only with ZONE_DMA32, set arm64_dma_phys_limit to max_zone_phys(32) earlier in arm64_memblock_init(), so platforms with just ZONE_DMA32 config enabled will benefit.
--- arch/arm64/mm/init.c | 23 ++++++++++++----------- arch/arm64/mm/mmu.c | 6 ++---- 2 files changed, 14 insertions(+), 15 deletions(-)
arch/arm64/mm/init.c +12 -11
@@ -65,8 +65,9 @@ EXPORT_SYMBOL(memstart_addr);* Memory reservation for crash kernel either done early or deferred * depending on DMA memory zones configs (ZONE_DMA) -- * -* In absence of ZONE_DMA configs arm64_dma_phys_limit initialized -* here instead of max_zone_phys(). This lets early reservation of +* In absence of ZONE_DMA and ZONE_DMA32 configs arm64_dma_phys_limit +* initialized here and if only with ZONE_DMA32 arm64_dma_phys_limit +* initialised to max_zone_phys(32). This lets early reservation of * crash kernel memory which has a dependency on arm64_dma_phys_limit. * Reserving memory early for crash kernel allows linear creation of block * mappings (greater than page-granularity) for all the memory bank rangs.
@@ -160,11 +161,10 @@ static phys_addr_t __init max_zone_phys(unsigned int zone_bits)static void __init zone_sizes_init (unsigned long min,unsigned long max) {unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 }; -unsigned int __maybe_unused acpi_zone_dma_bits; -unsigned int __maybe_unused dt_zone_dma_bits; -phys_addr_t __maybe_unused dma32_phys_limit =max_zone_phys (32 ); -#ifdef CONFIG_ZONE_DMA +unsigned int acpi_zone_dma_bits; +unsigned int dt_zone_dma_bits; + acpi_zone_dma_bits =fls64 (acpi_iort_dma_get_max_cpu_address ()); dt_zone_dma_bits =fls64 (of_dma_get_max_cpu_address (NULL )); zone_dma_bits =min3 (32U , dt_zone_dma_bits, acpi_zone_dma_bits);
@@ -172,9 +172,7 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max) max_zone_pfns[ZONE_DMA ] =PFN_DOWN (arm64_dma_phys_limit);#endif #ifdef CONFIG_ZONE_DMA32 - max_zone_pfns[ZONE_DMA32 ] =PFN_DOWN (dma32_phys_limit); -if (!arm64_dma_phys_limit) - arm64_dma_phys_limit = dma32_phys_limit; + max_zone_pfns[ZONE_DMA32 ] =PFN_DOWN (max_zone_phys (32 ));#endif max_zone_pfns[ZONE_NORMAL ] = max;
@@ -336,8 +334,11 @@ void __init arm64_memblock_init(void)early_init_fdt_scan_reserved_mem (); -if (!IS_ENABLED (CONFIG_ZONE_DMA ) && !IS_ENABLED (CONFIG_ZONE_DMA32 )) +if (!IS_ENABLED (CONFIG_ZONE_DMA )) { +if (IS_ENABLED (CONFIG_ZONE_DMA32 )) + arm64_dma_phys_limit =max_zone_phys (32 );reserve_crashkernel (); + } high_memory =__va (memblock_end_of_DRAM () -1 ) +1 ; }
@@ -385,7 +386,7 @@ void __init bootmem_init(void)* request_standard_resources() depends on crashkernel's memory being * reserved, so do it here. */ -if (IS_ENABLED (CONFIG_ZONE_DMA ) ||IS_ENABLED (CONFIG_ZONE_DMA32 )) +if (IS_ENABLED (CONFIG_ZONE_DMA ))reserve_crashkernel ();memblock_dump_all ();
arch/arm64/mm/mmu.c +2 -4
@@ -529,8 +529,7 @@ static void __init map_mem(pgd_t *pgdp)#ifdef CONFIG_KEXEC_CORE if (crash_mem_map) { -if (IS_ENABLED (CONFIG_ZONE_DMA ) || -IS_ENABLED (CONFIG_ZONE_DMA32 )) +if (IS_ENABLED (CONFIG_ZONE_DMA )) flags |=NO_BLOCK_MAPPINGS |NO_CONT_MAPPINGS ;else if (crashk_res.end) memblock_mark_nomap(crashk_res.start,
@@ -571,8 +570,7 @@ static void __init map_mem(pgd_t *pgdp)* through /sys/kernel/kexec_crash_size interface. */ #ifdef CONFIG_KEXEC_CORE -if (crash_mem_map && - !IS_ENABLED (CONFIG_ZONE_DMA ) && !IS_ENABLED (CONFIG_ZONE_DMA32 )) { +if (crash_mem_map && !IS_ENABLED (CONFIG_ZONE_DMA )) {if (crashk_res.end) { __map_memblock(pgdp, crashk_res.start, crashk_res.end + 1,
Signature · 1 line
2.26.2
PATCH v3 2/3 arm64: mm: Don't defer reserve_crashkernel() with dma_force_32bit
In reply to Kefeng WangARM64 enable ZONE_DMA by default, and with ZONE_DMA crash kernel memory reservation is delayed until DMA zone memory range size initilazation performed in zone_sizes_init(), but for most platforms use 32bit dma_zone_bits, so add dma_force_32bit kernel parameter if ZONE_DMA enabled, and initialize arm64_dma_phys_limit to max_zone_phys(32) in arm64_memblock_init() if dma_force_32bit is setup, this could let the crash kernel reservation earlier, and allows linear creation with block mapping.
--- arch/arm64/include/asm/kexec.h | 1 + arch/arm64/mm/init.c | 43 +++++++++++++++++++++++++++------- arch/arm64/mm/mmu.c | 4 ++-- 3 files changed, 37 insertions(+), 11 deletions(-)
arch/arm64/include/asm/kexec.h +1 -0
@@ -95,6 +95,7 @@ void cpu_soft_restart(unsigned long el2_switch, unsigned long entry, unsigned long arg0, unsigned long arg1, unsigned long arg2);#endif +bool crashkernel_early_reserve (void );#define ARCH_HAS_KIMAGE_ARCH
arch/arm64/mm/init.c +34 -9
80 lines not on this page · raw message
arch/arm64/mm/mmu.c +2 -2
@@ -529,7 +529,7 @@ static void __init map_mem(pgd_t *pgdp)#ifdef CONFIG_KEXEC_CORE if (crash_mem_map) { -if (IS_ENABLED (CONFIG_ZONE_DMA )) +if (!crashkernel_early_reserve ()) flags |=NO_BLOCK_MAPPINGS |NO_CONT_MAPPINGS ;else if (crashk_res.end) memblock_mark_nomap(crashk_res.start,
@@ -570,7 +570,7 @@ static void __init map_mem(pgd_t *pgdp)* through /sys/kernel/kexec_crash_size interface. */ #ifdef CONFIG_KEXEC_CORE -if (crash_mem_map && !IS_ENABLED (CONFIG_ZONE_DMA )) { +if (crash_mem_map &&crashkernel_early_reserve ()) {if (crashk_res.end) { __map_memblock(pgdp, crashk_res.start, crashk_res.end + 1,
Signature · 1 line
2.26.2
PATCH v3 3/3 arm64: mm: Cleanup useless parameters in zone_sizes_init()
In reply to Kefeng WangDirectly use max_pfn for max and no one use min, kill them.
--- arch/arm64/mm/init.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/arm64/mm/init.c +3 -3
@@ -181,7 +181,7 @@ static phys_addr_t __init max_zone_phys(unsigned int zone_bits)return min (zone_mask,memblock_end_of_DRAM () -1 ) +1 ; } -static void __init zone_sizes_init (unsigned long min,unsigned long max) +static void __init zone_sizes_init (void ) {unsigned long max_zone_pfns[MAX_NR_ZONES ] = {0 };#ifdef CONFIG_ZONE_DMA
@@ -199,7 +199,7 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max)#ifdef CONFIG_ZONE_DMA32 max_zone_pfns[ZONE_DMA32 ] =PFN_DOWN (max_zone_phys (32 ));#endif - max_zone_pfns[ZONE_NORMAL ] = max; + max_zone_pfns[ZONE_NORMAL ] = max_pfn;free_area_init (max_zone_pfns); }
@@ -400,7 +400,7 @@ void __init bootmem_init(void)* done after the fixed reservations */ sparse_init (); -zone_sizes_init (min, max); +zone_sizes_init ();/* * Reserve the CMA area after arm64_dma_phys_limit was initialised.
Signature · 1 line
2.26.2
Hi Catalin and Will, any comments, thanks.
Quoted 42 lines · Kefeng Wang
Commit
031495635b46("arm64: Do not deferreserve_crashkernel()for platforms with no DMA memory zones"), this lets the kernel benifit due toBLOCK_MAPPINGS, we could do more ifZONE_DMAandZONE_DMA32enabled.1) Don't defer
reserve_crashkernel()if onlyZONE_DMA32
2) Don't deferreserve_crashkernel()ifZONE_DMAwithdma_force_32bitkernel parameter(newly added)Here is another case to show the benefit of the block mapping.
Unixbench benchmark result shows between the block mapping and page mapping.
----------------+------------------+-------------------
| block mapping | page mapping
----------------+------------------+-------------------Process Creation| 5,030.7 | 4,711.8 (in unixbench) | |----------------+------------------+-------------------
note:
RODATA_FULL_DEFAULT_ENABLEDis not enabledv3:
- renamingcrashkernel_could_early_reserve()tocrashkernel_early_reserve()
- dropdma32_phys_limit, directly usemax_zone_phys(32)
- fix no previous prototype issue
- add RB of Vijay to patch2/3
v2 resend:
- fix build error reported-by lkp
v2:
- update patch1 according to Vijay and Florian, and RB of Vijay
- add new patch2Kefeng Wang (3):
arm64: mm: Do not deferreserve_crashkernel()if onlyZONE_DMA32
arm64: mm: Don't deferreserve_crashkernel()withdma_force_32bit
arm64: mm: Cleanup useless parameters inzone_sizes_init()arch/arm64/include/asm/kexec.h | 1 + arch/arm64/mm/init.c | 60 ++++++++++++++++++++++++---------- arch/arm64/mm/mmu.c | 6 ++-- 3 files changed, 46 insertions(+), 21 deletions(-)
Catalin Marinas
maintainerQuoted 8 lines · Kefeng Wang
Commit
031495635b46("arm64: Do not deferreserve_crashkernel()for platforms with no DMA memory zones"), this lets the kernel benifit due toBLOCK_MAPPINGS, we could do more ifZONE_DMAandZONE_DMA32enabled.1) Don't defer
reserve_crashkernel()if onlyZONE_DMA32
2) Don't deferreserve_crashkernel()ifZONE_DMAwithdma_force_32bitkernel parameter(newly added)
I'm not really keen on a new kernel parameter for this. But even with such parameter, there is another series that allows crashkernel reservations above ZONE_DMA32, so that would also need NO_BLOCK_MAPPINGS, at least initially. I think there was a proposal to do the high reservation first and only defer the low one in ZONE_DMA but suggested we get the reservations sorted first and look at optimisations later.
If hardware is so bad with page mappings, I think we need to look at different ways to enable the block mappings, e.g. some safe break before make change of the mappings or maybe switching to another TTBR1 during boot.
Does FEAT_BBM level 2 allow us to change the block size without a break before make? I think that can still trigger a TLB conflict abort, maybe we can trap it and invalidate the TLBs (the conflict should be on the linear map not where the kernel image is mapped).
Signature · 1 line
Catalin
Quoted 9 lines · Catalin Marinas
Quoted 8 lines · Kefeng Wang
Commit
031495635b46("arm64: Do not deferreserve_crashkernel()for platforms with no DMA memory zones"), this lets the kernel benifit due toBLOCK_MAPPINGS, we could do more ifZONE_DMAandZONE_DMA32enabled.1) Don't defer
reserve_crashkernel()if onlyZONE_DMA32
2) Don't deferreserve_crashkernel()ifZONE_DMAwithdma_force_32bitkernel parameter(newly added)
Quoted 7 lines
I'm not really keen on a new kernel parameter for this. But even with such parameter, there is another series that allows crashkernel reservations above
ZONE_DMA32, so that would also needNO_BLOCK_MAPPINGS, at least initially. I think there was a proposal to do the high reservation first and only defer the low one inZONE_DMAbut suggested we get the reservations sorted first and look at optimisations later.
OK, we could look it again after patch "support reserving crashkernel above 4G on arm64 kdump".
The patch3 is a small cleanup, could you pick it up?
Quoted 9 lines
If hardware is so bad with page mappings, I think we need to look at different ways to enable the block mappings, e.g. some safe break before make change of the mappings or maybe switching to another TTBR1 during boot.
Does
FEAT_BBMlevel 2 allow us to change the block size without a break before make? I think that can still trigger a TLB conflict abort, maybe we can trap it and invalidate the TLBs (the conflict should be on the linear map not where the kernel image is mapped).
Block mapping is better than page mapping in some testcase(unixbench, booting time, and mysql, maybe more). KFENCE will make the liner mapping to page mapping too. If there is a new way to let's enable the block mapping, that's great.
Re: (subset) [PATCH v3 0/3] arm64: mm: Do not defer reserve_crashkernel()
In reply to Kefeng WangQuoted 10 lines · Kefeng Wang
Commit
031495635b46("arm64: Do not deferreserve_crashkernel()for platforms with no DMA memory zones"), this lets the kernel benifit due toBLOCK_MAPPINGS, we could do more ifZONE_DMAandZONE_DMA32enabled.1) Don't defer
reserve_crashkernel()if onlyZONE_DMA32
2) Don't deferreserve_crashkernel()ifZONE_DMAwithdma_force_32bitkernel parameter(newly added)[...]
Applied to arm64 (for-next/misc), thanks!
[3/3] arm64: mm: Cleanup useless parameters in zone_sizes_init()
https://git.kernel.org/arm64/c/f41ef4c2ee99
Signature · 1 line
Catalin