Skip to contentSkip to conversation

arm64: kdump: Function supplement and performance optimization

PATCH Superseded Zhen Lei 1 participant 5 messages Jun 21, 2022 – Jun 28, 2022

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Zhen Lei

author
#0 lore raw

v2 cover arm64: kdump: Function supplement and performance optimization

v1 --> v2:
1. Update the commit message of Patch 1, explicitly indicates that "crashkernel=X,high" is specified but "crashkernel=Y,low" is not specified.
2. Drop Patch 4-5. Currently, focus on function integrity, performance optimization will be considered in later versions.
3. Patch 3 is not mandatory, it's just a cleanup now, although it is a must for patch 4-5. But to avoid subsequent duplication of effort, I'm glad it was accepted.

v1:
After the basic functions of "support reserving crashkernel above 4G on arm64 kdump"(see https://lkml.org/lkml/2022/5/6/428) are implemented, we still have three features to be improved.
1. When crashkernel=X,high is specified but crashkernel=Y,low is not specified, the default crash low memory size is provided.
2. For crashkernel=X without '@offset', if the low memory fails to be allocated, fall back to reserve region from high memory(above DMA zones).
3. If crashkernel=X,high is used, page mapping is performed only for the crash high memory, and block mapping is still used for other linear address spaces. Compared to the previous version:
(1) For crashkernel=X[@offset], the memory above 4G is not changed to block mapping, leave it to the next time.
(2) The implementation method is modified. Now the implementation is simpler and clearer.

Zhen Lei (3):
arm64: kdump: Provide default size when crashkernel=Y,low is not
specified
arm64: kdump: Support crashkernel=X fall back to reserve region above
DMA zones
arm64: kdump: Remove some redundant checks in map_mem()

 .../admin-guide/kernel-parameters.txt         | 10 ++-----
 arch/arm64/mm/init.c                          | 28 +++++++++++++++++--
 arch/arm64/mm/mmu.c                           | 25 ++++++++---------
 3 files changed, 39 insertions(+), 24 deletions(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 1/3 arm64: kdump: Provide default size when crashkernel=Y,low is not specified

To be consistent with the implementation of x86 and improve cross-platform user experience. Try to allocate at least 256 MiB low memory automatically for the case that crashkernel=,high is explicitly specified, while crashkenrel=,low is omitted.

---
 Documentation/admin-guide/kernel-parameters.txt |  8 +-------
 arch/arm64/mm/init.c                            | 12 +++++++++++-
 2 files changed, 12 insertions(+), 8 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +1 -7
index 2522b11e593f239..65a2c3a22a4b57d 100644
@@ -843,7 +843,7 @@
 			available.
 			It will be ignored if crashkernel=X is specified.
 	crashkernel=size[KMG],low
-			[KNL, X86-64] range under 4G. When crashkernel=X,high
+			[KNL, X86-64, ARM64] range under 4G. When crashkernel=X,high
 			is passed, kernel could allocate physical memory region
 			above 4G, that cause second kernel crash on system
 			that require some amount of low memory, e.g. swiotlb
@@ -857,12 +857,6 @@
 			It will be ignored when crashkernel=X,high is not used
 			or memory reserved is below 4G.
 
-			[KNL, ARM64] range in low memory.
-			This one lets the user specify a low range in the
-			DMA zone for the crash dump kernel.
-			It will be ignored when crashkernel=X,high is not used
-			or memory reserved is located in the DMA zones.
-
 	cryptomgr.notests
 			[KNL] Disable crypto self-tests
 
arch/arm64/mm/init.c +11 -1
index 339ee84e5a61a0b..5390f361208ccf7 100644
@@ -96,6 +96,14 @@ phys_addr_t __ro_after_init arm64_dma_phys_limit = PHYS_MASK + 1;
 #define CRASH_ADDR_LOW_MAX		arm64_dma_phys_limit
 #define CRASH_ADDR_HIGH_MAX		(PHYS_MASK + 1)
 
+/*
+ * This is an empirical value in x86_64 and taken here directly. Please
+ * refer to the code comment in reserve_crashkernel_low() of x86_64 for more
+ * details.
+ */
+#define DEFAULT_CRASH_KERNEL_LOW_SIZE	\
+	max(swiotlb_size_or_default() + (8UL << 20), 256UL << 20)
+
 static int __init reserve_crashkernel_low(unsigned long long low_size)
 {
 	unsigned long long low_base;
@@ -147,7 +155,9 @@ static void __init reserve_crashkernel(void)
 		 * is not allowed.
 		 */
 		ret = parse_crashkernel_low(cmdline, 0, &crash_low_size, &crash_base);
-		if (ret && (ret != -ENOENT))
+		if (ret == -ENOENT)
+			crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE;
+		else if (ret)
 			return;
 
 		crash_max = CRASH_ADDR_HIGH_MAX;
Signature · 1 line
2.25.1
author
#2 lore raw

PATCH v2 2/3 arm64: kdump: Support crashkernel=X fall back to reserve region above DMA zones

In reply to Zhen Lei

For crashkernel=X without '@offset', select a region within DMA zones first, and fall back to reserve region above DMA zones. This allows users to use the same configuration on multiple platforms.

---
 Documentation/admin-guide/kernel-parameters.txt |  2 +-
 arch/arm64/mm/init.c                            | 16 +++++++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +1 -1
index 65a2c3a22a4b57d..cb6a346419a1fe0 100644
@@ -823,7 +823,7 @@
 			memory region [offset, offset + size] for that kernel
 			image. If '@offset' is omitted, then a suitable offset
 			is selected automatically.
-			[KNL, X86-64] Select a region under 4G first, and
+			[KNL, X86-64, ARM64] Select a region under 4G first, and
 			fall back to reserve region above 4G when '@offset'
 			hasn't been specified.
 			See Documentation/admin-guide/kdump/kdump.rst for further details.
arch/arm64/mm/init.c +15 -1
index 5390f361208ccf7..8539598f9e58b4d 100644
@@ -138,6 +138,7 @@ static void __init reserve_crashkernel(void)
 	unsigned long long crash_max = CRASH_ADDR_LOW_MAX;
 	char *cmdline = boot_command_line;
 	int ret;
+	bool fixed_base;
 
 	if (!IS_ENABLED(CONFIG_KEXEC_CORE))
 		return;
@@ -166,15 +167,28 @@ static void __init reserve_crashkernel(void)
 		return;
 	}
 
+	fixed_base = !!crash_base;
 	crash_size = PAGE_ALIGN(crash_size);
 
 	/* User specifies base address explicitly. */
-	if (crash_base)
+	if (fixed_base)
 		crash_max = crash_base + crash_size;
 
+retry:
 	crash_base = memblock_phys_alloc_range(crash_size, CRASH_ALIGN,
 					       crash_base, crash_max);
 	if (!crash_base) {
+		/*
+		 * Attempt to fully allocate low memory failed, fall back
+		 * to high memory, the minimum required low memory will be
+		 * reserved later.
+		 */
+		if (!fixed_base && (crash_max == CRASH_ADDR_LOW_MAX)) {
+			crash_max = CRASH_ADDR_HIGH_MAX;
+			crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE;
+			goto retry;
+		}
+
 		pr_warn("cannot allocate crashkernel (size:0x%llx)\n",
 			crash_size);
 		return;
Signature · 1 line
2.25.1
author
#3 lore raw

PATCH v2 3/3 arm64: kdump: Remove some redundant checks in map_mem()

In reply to Zhen Lei

arm64_memblock_init()

	if (!IS_ENABLED(CONFIG_ZONE_DMA/DMA32))
		reserve_crashkernel()
			//initialize crashk_res when
			//"crashkernel=" is correctly specified
paging_init()
	map_mem()

As shown in the above pseudo code, the crashk_res.end can only be initialized to non-zero when both "!IS_ENABLED(CONFIG_ZONE_DMA/DMA32)" and crash_mem_map are true. So some checks in map_mem() can be adjusted or optimized.

---
 arch/arm64/mm/mmu.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
arch/arm64/mm/mmu.c +11 -14
index 626ec32873c6c36..6028a5757e4eae2 100644
@@ -529,12 +529,12 @@ 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))
-			flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS;
-		else if (crashk_res.end)
+		if (crashk_res.end)
 			memblock_mark_nomap(crashk_res.start,
 			    resource_size(&crashk_res));
+		else if (IS_ENABLED(CONFIG_ZONE_DMA) ||
+			 IS_ENABLED(CONFIG_ZONE_DMA32))
+			flags |= NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS;
 	}
 #endif
 
@@ -571,16 +571,13 @@ 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 (crashk_res.end) {
-			__map_memblock(pgdp, crashk_res.start,
-				       crashk_res.end + 1,
-				       PAGE_KERNEL,
-				       NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS);
-			memblock_clear_nomap(crashk_res.start,
-					     resource_size(&crashk_res));
-		}
+	if (crashk_res.end) {
+		__map_memblock(pgdp, crashk_res.start,
+			       crashk_res.end + 1,
+			       PAGE_KERNEL,
+			       NO_BLOCK_MAPPINGS | NO_CONT_MAPPINGS);
+		memblock_clear_nomap(crashk_res.start,
+				     resource_size(&crashk_res));
 	}
 #endif
 }
Signature · 1 line
2.25.1
#4 lore raw
In reply to Zhen Lei
Quoted 7 lines · Zhen Lei

v1 --> v2:
1. Update the commit message of Patch 1, explicitly indicates that "crashkernel=X,high" is specified but "crashkernel=Y,low" is not specified.
2. Drop Patch 4-5. Currently, focus on function integrity, performance optimization will be considered in later versions.
3. Patch 3 is not mandatory, it's just a cleanup now, although it is a must for patch 4-5. But to avoid subsequent duplication of effort, I'm glad it was accepted.

Hi Catalin:
Do you have time to review Patch 1-2? Please ignore Patch 3, because now someone has
proposed the following new approach:

https://lore.kernel.org/linux-mm/[email protected]/T/

Quoted 30 lines

v1:
After the basic functions of "support reserving crashkernel above 4G on arm64 kdump"(see https://lkml.org/lkml/2022/5/6/428) are implemented, we still have three features to be improved.
1. When crashkernel=X,high is specified but crashkernel=Y,low is not specified, the default crash low memory size is provided.
2. For crashkernel=X without '@offset', if the low memory fails to be allocated, fall back to reserve region from high memory(above DMA zones).
3. If crashkernel=X,high is used, page mapping is performed only for the crash high memory, and block mapping is still used for other linear address spaces. Compared to the previous version:
(1) For crashkernel=X[@offset], the memory above 4G is not changed to block mapping, leave it to the next time.
(2) The implementation method is modified. Now the implementation is simpler and clearer.

Zhen Lei (3):
arm64: kdump: Provide default size when crashkernel=Y,low is not
specified
arm64: kdump: Support crashkernel=X fall back to reserve region above
DMA zones
arm64: kdump: Remove some redundant checks in map_mem()

 .../admin-guide/kernel-parameters.txt         | 10 ++-----
 arch/arm64/mm/init.c                          | 28 +++++++++++++++++--
 arch/arm64/mm/mmu.c                           | 25 ++++++++---------
 3 files changed, 39 insertions(+), 24 deletions(-)
Signature · 2 lines
Regards,
  Zhen Lei