Skip to contentSkip to conversation

powerpc/fadump: allocate memory for additional parameters early

PATCH In review Sourabh Jain 2 participants 5 messages Nov 13, 2024 – Jan 17, 2025 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 powerpc/fadump: allocate memory for additional parameters early

From: Hari Bathini <[email protected]>

Memory for passing additional parameters to fadump capture kernel is allocated during subsys_initcall level, using memblock. But as slab is already available by this time, allocation happens via the buddy allocator. This may work for radix MMU but is likely to fail in most cases for hash MMU as hash MMU needs this memory in the first memory block for it to be accessible in real mode in the capture kernel (second boot). So, allocate memory for additional parameters area as soon as MMU mode is obvious.

Fixes 683eab94da75 ("powerpc/fadump: setup additional parameters for dump capture kernel")
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>

---

Changelog:

Since v1: https://lore.kernel.org/all/[email protected]/
- Drop extern keyword from fadump_setup_param_area function declaration
- Don't use __va() while resetting param memory area

Since v2: https://lore.kernel.org/all/[email protected]/
- Update comment around fadump_setup_param_area() to indicate its dependency on MMU type
- Add Reviewed-by tag
- No functional change

---
 arch/powerpc/include/asm/fadump.h |  2 ++
 arch/powerpc/kernel/fadump.c      | 15 ++++++++++-----
 arch/powerpc/kernel/prom.c        |  7 +++++++
 3 files changed, 19 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/fadump.h +2 -0
index ef40c9b6972a..7b3473e05273 100644
@@ -19,6 +19,7 @@ extern int is_fadump_active(void);
 extern int should_fadump_crash(void);
 extern void crash_fadump(struct pt_regs *, const char *);
 extern void fadump_cleanup(void);
+void fadump_setup_param_area(void);
 extern void fadump_append_bootargs(void);
 
 #else	/* CONFIG_FA_DUMP */
@@ -26,6 +27,7 @@ static inline int is_fadump_active(void) { return 0; }
 static inline int should_fadump_crash(void) { return 0; }
 static inline void crash_fadump(struct pt_regs *regs, const char *str) { }
 static inline void fadump_cleanup(void) { }
+static inline void fadump_setup_param_area(void) { }
 static inline void fadump_append_bootargs(void) { }
 #endif /* !CONFIG_FA_DUMP */
 
arch/powerpc/kernel/fadump.c +10 -5
index a612e7513a4f..3a2863307863 100644
@@ -1586,6 +1586,12 @@ static void __init fadump_init_files(void)
 		return;
 	}
 
+	if (fw_dump.param_area) {
+		rc = sysfs_create_file(fadump_kobj, &bootargs_append_attr.attr);
+		if (rc)
+			pr_err("unable to create bootargs_append sysfs file (%d)\n", rc);
+	}
+
 	debugfs_create_file("fadump_region", 0444, arch_debugfs_dir, NULL,
 			    &fadump_region_fops);
 
@@ -1740,7 +1746,7 @@ static void __init fadump_process(void)
  * Reserve memory to store additional parameters to be passed
  * for fadump/capture kernel.
  */
-static void __init fadump_setup_param_area(void)
+void __init fadump_setup_param_area(void)
 {
 	phys_addr_t range_start, range_end;
 
@@ -1748,7 +1754,7 @@ static void __init fadump_setup_param_area(void)
 		return;
 
 	/* This memory can't be used by PFW or bootloader as it is shared across kernels */
-	if (radix_enabled()) {
+	if (early_radix_enabled()) {
 		/*
 		 * Anywhere in the upper half should be good enough as all memory
 		 * is accessible in real mode.
@@ -1776,12 +1782,12 @@ static void __init fadump_setup_param_area(void)
 						       COMMAND_LINE_SIZE,
 						       range_start,
 						       range_end);
-	if (!fw_dump.param_area || sysfs_create_file(fadump_kobj, &bootargs_append_attr.attr)) {
+	if (!fw_dump.param_area) {
 		pr_warn("WARNING: Could not setup area to pass additional parameters!\n");
 		return;
 	}
 
-	memset(phys_to_virt(fw_dump.param_area), 0, COMMAND_LINE_SIZE);
+	memset((void *)fw_dump.param_area, 0, COMMAND_LINE_SIZE);
 }
 
 /*
@@ -1807,7 +1813,6 @@ int __init setup_fadump(void)
 	}
 	/* Initialize the kernel dump memory structure and register with f/w */
 	else if (fw_dump.reserve_dump_area_size) {
-		fadump_setup_param_area();
 		fw_dump.ops->fadump_init_mem_struct(&fw_dump);
 		register_fadump();
 	}
arch/powerpc/kernel/prom.c +7 -0
index 0be07ed407c7..7ac03655338d 100644
@@ -908,6 +908,13 @@ void __init early_init_devtree(void *params)
 
 	mmu_early_init_devtree();
 
+	/*
+	 * Setup param area for passing additional parameters to the fadump
+	 * capture kernel. Since this depends on the MMU type, the function
+	 * must be called after the MMU type is finalized.
+	 */
+	fadump_setup_param_area();
+
 #ifdef CONFIG_PPC_POWERNV
 	/* Scan and build the list of machine check recoverable ranges */
 	of_scan_flat_dt(early_init_dt_scan_recoverable_ranges, NULL);
Signature · 1 line
2.46.2
#1 lore raw

PATCH v3 2/2 fadump: reserve param area if below boot_mem_top

The param area is a memory region where the kernel places additional command-line arguments for fadump kernel. Currently, the param memory area is reserved in fadump kernel if it is above boot_mem_top. However, it should be reserved if it is below boot_mem_top because the fadump kernel already preserves memory from boot_mem_top to the end of DRAM.

Currently, there is no impact from not reserving param memory if it is below boot_mem_top, as it is not used after the early boot phase of the fadump kernel. However, if this changes in the future, it could lead to issues in the fadump kernel.

Fixes 3416c9daa6b1 ("powerpc/fadump: pass additional parameters when fadump is active")
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>

---

Changelog:

Since v1: https://lore.kernel.org/all/[email protected]/
- Include Fixes and Acked-by tag in the commit message
- No functional changes

Since v2: https://lore.kernel.org/all/[email protected]/
- Add Reviewed-by tag
- No functional change

---
 arch/powerpc/kernel/fadump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/fadump.c +1 -1
index 3a2863307863..3f3674060164 100644
@@ -143,7 +143,7 @@ void __init fadump_append_bootargs(void)
 	if (!fw_dump.dump_active || !fw_dump.param_area_supported || !fw_dump.param_area)
 		return;
 
-	if (fw_dump.param_area >= fw_dump.boot_mem_top) {
+	if (fw_dump.param_area < fw_dump.boot_mem_top) {
 		if (memblock_reserve(fw_dump.param_area, COMMAND_LINE_SIZE)) {
 			pr_warn("WARNING: Can't use additional parameters area!\n");
 			fw_dump.param_area = 0;
Signature · 1 line
2.46.2
#2 lore raw
In reply to Sourabh Jain

Le 13/11/2024 à 08:06, Sourabh Jain a écrit :

Quoted 11 lines

From: Hari Bathini <[email protected]>

Memory for passing additional parameters to fadump capture kernel is allocated during subsys_initcall level, using memblock. But as slab is already available by this time, allocation happens via the buddy allocator. This may work for radix MMU but is likely to fail in most cases for hash MMU as hash MMU needs this memory in the first memory block for it to be accessible in real mode in the capture kernel (second boot). So, allocate memory for additional parameters area as soon as MMU mode is obvious.

Quoted 8 lines
Fixes 683eab94da75 ("powerpc/fadump: setup additional parameters for dump capture kernel")
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>

Version v2 of this series was applied.

If needed, can you rebase this patch ?

#3 lore raw

Hello Christophe,

Quoted 23 lines · Christophe Leroy

Le 13/11/2024 à 08:06, Sourabh Jain a écrit :

Quoted 11 lines

From: Hari Bathini <[email protected]>

Memory for passing additional parameters to fadump capture kernel is allocated during subsys_initcall level, using memblock. But as slab is already available by this time, allocation happens via the buddy allocator. This may work for radix MMU but is likely to fail in most cases for hash MMU as hash MMU needs this memory in the first memory block for it to be accessible in real mode in the capture kernel (second boot). So, allocate memory for additional parameters area as soon as MMU mode is obvious.

Quoted 8 lines
Fixes 683eab94da75 ("powerpc/fadump: setup additional parameters for dump capture kernel")
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>
Quoted 4 lines

Version v2 of this series was applied.

If needed, can you rebase this patch ?

Sorry, I didn't get that. Rebase on top of which tree/branch?

FYI, there was no functional change from v2 to v3. Only a "Reviewed-by" tag was added.

Thanks,
Sourabh Jain

#4 lore raw

Le 17/01/2025 à 13:32, Sourabh Jain a écrit :

Quoted 26 lines

Hello Christophe,

Quoted 23 lines · Christophe Leroy

Le 13/11/2024 à 08:06, Sourabh Jain a écrit :

Quoted 19 lines

From: Hari Bathini <[email protected]>

Memory for passing additional parameters to fadump capture kernel is allocated during subsys_initcall level, using memblock. But as slab is already available by this time, allocation happens via the buddy allocator. This may work for radix MMU but is likely to fail in most cases for hash MMU as hash MMU needs this memory in the first memory block for it to be accessible in real mode in the capture kernel (second boot). So, allocate memory for additional parameters area as soon as MMU mode is obvious.

Fixes 683eab94da75 ("powerpc/fadump: setup additional parameters for dump capture kernel")
Closes https://eur01.safelinks.protection.outlook.com/? url=https%3A%2F%2Flore.kernel.org%2Flkml%2Fa70e4064- a040-447b-8556-1fd02f19383d%40linux.vnet.ibm.com%2FT%2F%23u&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C9df078759a2c42b044cf08dd36f3183b%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638727139896068824%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=iZfkQKw4wJAvwAj%2BbGOS5kcrVtAg8xg%2FFl6ojEYZ6ls%3D&reserved=0
Cc Mahesh Salgaonkar <[email protected]>
Cc Michael Ellerman <[email protected]>
Quoted 5 lines
Quoted 4 lines

Version v2 of this series was applied.

If needed, can you rebase this patch ?

Sorry, I didn't get that. Rebase on top of which tree/branch?

I meant on top of any tree including the applied version.

Quoted 3 lines

FYI, there was no functional change from v2 to v3. Only a "Reviewed-by" tag was added.

Then I guess there is nothing to do.

Christophe