[PATCH v3 1/4] powerpc/mmu: do MMU type discovery before crashkernel reservation

Sourabh Jain <[email protected]>
Newsgroups org.ozlabs.lists.linuxppc-dev
Message-ID <[email protected]>
Crashkernel reservation on high memory depends on the MMU type. In
particular, arch_reserve_crashkernel() needs to know whether the radix
MMU is enabled when selecting the crashkernel reservation.

arch_reserve_crashkernel() is intentionally called early during boot.
The crashkernel memory needs to be reserved before other components
make memory reservations, as those reservations could interfere with
finding a suitable region for the crashkernel at the required offset.
Therefore, moving arch_reserve_crashkernel() to a later point is not a
suitable solution.

Instead, make the MMU type available before arch_reserve_crashkernel()
is called. The MMU type is determined from the FDT and kernel
configuration and is recorded in cur_cpu_spec->mmu_features.

early_radix_enabled() uses cur_cpu_spec->mmu_features to determine
whether the radix MMU is enabled. However, the MMU type discovery was
previously performed as part of mmu_early_init_devtree(), which runs
after arch_reserve_crashkernel(). Split the MMU type discovery from the
rest of mmu_early_init_devtree() and perform it before
arch_reserve_crashkernel().

This makes early_radix_enabled() usable from
arch_reserve_crashkernel(), which will be used by the following patch
to select the appropriate crashkernel reservation on high memory.

Signed-off-by: Sourabh Jain <[email protected]>
Reviewed-by: Ritesh Harjani (IBM) <[email protected]>
---
 arch/powerpc/include/asm/book3s/64/mmu.h |  1 +
 arch/powerpc/include/asm/mmu.h           |  1 +
 arch/powerpc/kernel/prom.c               | 29 +++++++++++++-----------
 arch/powerpc/mm/init_64.c                | 26 +++++++++++++--------
 4 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/arch/powerpc/include/asm/book3s/64/mmu.h b/arch/powerpc/include/asm/book3s/64/mmu.h
index 48631365b48c..d820640f2739 100644
--- a/arch/powerpc/include/asm/book3s/64/mmu.h
+++ b/arch/powerpc/include/asm/book3s/64/mmu.h
@@ -208,6 +208,7 @@ extern int mmu_vmemmap_psize;
 
 /* MMU initialization */
 void mmu_early_init_devtree(void);
+void mmu_early_init_type(void);
 void hash__early_init_devtree(void);
 void radix__early_init_devtree(void);
 #ifdef CONFIG_PPC_PKEY
diff --git a/arch/powerpc/include/asm/mmu.h b/arch/powerpc/include/asm/mmu.h
index 5f9c5d436e17..da0b498bd475 100644
--- a/arch/powerpc/include/asm/mmu.h
+++ b/arch/powerpc/include/asm/mmu.h
@@ -384,6 +384,7 @@ extern void early_init_mmu_secondary(void);
 extern void setup_initial_memory_limit(phys_addr_t first_memblock_base,
 				       phys_addr_t first_memblock_size);
 static inline void mmu_early_init_devtree(void) { }
+static inline void mmu_early_init_type(void) { }
 
 static inline void pkey_early_init_devtree(void) {}
 
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c
index 9ed9dde7d231..4fc53129e6ee 100644
--- a/arch/powerpc/kernel/prom.c
+++ b/arch/powerpc/kernel/prom.c
@@ -853,6 +853,22 @@ void __init early_init_devtree(void *params)
 	if (PHYSICAL_START > MEMORY_START)
 		memblock_reserve(MEMORY_START, int_vector_size);
 	reserve_kdump_trampoline();
+
+	DBG("Scanning CPUs ...\n");
+
+	dt_cpu_ftrs_scan();
+
+	/* Retrieve CPU related informations from the flat tree
+	 * (altivec support, boot CPU ID, ...)
+	 */
+	of_scan_flat_dt(early_init_dt_scan_cpus, NULL);
+	if (boot_cpuid < 0) {
+		printk("Failed to identify boot CPU !\n");
+		BUG();
+	}
+
+	mmu_early_init_type();
+
 #if defined(CONFIG_FA_DUMP) || defined(CONFIG_PRESERVE_FA_DUMP)
 	/*
 	 * If we fail to reserve memory for firmware-assisted dump then
@@ -884,19 +900,6 @@ void __init early_init_devtree(void *params)
 	 * FIXME .. and the initrd too? */
 	move_device_tree();
 
-	DBG("Scanning CPUs ...\n");
-
-	dt_cpu_ftrs_scan();
-
-	/* Retrieve CPU related informations from the flat tree
-	 * (altivec support, boot CPU ID, ...)
-	 */
-	of_scan_flat_dt(early_init_dt_scan_cpus, NULL);
-	if (boot_cpuid < 0) {
-		printk("Failed to identify boot CPU !\n");
-		BUG();
-	}
-
 	save_fscr_to_task();
 
 #if defined(CONFIG_SMP) && defined(CONFIG_PPC64)
diff --git a/arch/powerpc/mm/init_64.c b/arch/powerpc/mm/init_64.c
index 64f0df5bb5cd..4916ed230600 100644
--- a/arch/powerpc/mm/init_64.c
+++ b/arch/powerpc/mm/init_64.c
@@ -614,7 +614,8 @@ static void __init early_init_memory_block_size(void)
 	of_scan_flat_dt(probe_memory_block_size, &memory_block_size);
 }
 
-void __init mmu_early_init_devtree(void)
+
+void __init mmu_early_init_type(void)
 {
 	bool hvmode = !!(mfmsr() & MSR_HV);
 
@@ -626,6 +627,20 @@ void __init mmu_early_init_devtree(void)
 			pr_warn("WARNING: Ignoring cmdline option disable_radix\n");
 	}
 
+	/*
+	 * Check /chosen/ibm,architecture-vec-5 if running as a guest.
+	 * When running bare-metal, we can use radix if we like
+	 * even though the ibm,architecture-vec-5 property created by
+	 * skiboot doesn't have the necessary bits set.
+	 */
+	if (!hvmode)
+		early_check_vec5();
+}
+
+void __init mmu_early_init_devtree(void)
+{
+	bool hvmode = !!(mfmsr() & MSR_HV);
+
 	of_scan_flat_dt(dt_scan_mmu_pid_width, NULL);
 	if (hvmode && !mmu_lpid_bits) {
 		if (early_cpu_has_feature(CPU_FTR_ARCH_207S))
@@ -638,15 +653,6 @@ void __init mmu_early_init_devtree(void)
 			mmu_pid_bits = 20; /* POWER9-10 */
 	}
 
-	/*
-	 * Check /chosen/ibm,architecture-vec-5 if running as a guest.
-	 * When running bare-metal, we can use radix if we like
-	 * even though the ibm,architecture-vec-5 property created by
-	 * skiboot doesn't have the necessary bits set.
-	 */
-	if (!hvmode)
-		early_check_vec5();
-
 	early_init_memory_block_size();
 
 	if (early_radix_enabled()) {
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.