Skip to contentSkip to conversation

imx9: scmi: Fix cache issue in calling ele_get_info

PATCH In review [email protected] 2 participants 4 messages Nov 30

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 imx9: scmi: Fix cache issue in calling ele_get_info

From: Ye Li <[email protected]>

With MMU enabled, speculative accesses can cache the ELE get-info buffer before ELE updates it. Without invalidating the buffer after ele_get_info(), set_cpu_info() may read stale data and set an incorrect soc_rev.

On i.MX952, this can cause the SoC detection to fail and select the non-v2x container parsing path, resulting in image loading failures during SD/eMMC reboot stress tests.

Use a cache-aligned buffer and invalidate it after a successful ele_get_info() call, before consuming the returned data.

---
 arch/arm/mach-imx/imx9/scmi/soc.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
arch/arm/mach-imx/imx9/scmi/soc.c +9 -4
index 2f1a4c70fc7..bc60b071e02 100644
@@ -21,6 +21,7 @@
 #include <imx_thermal.h>
 #include <linux/bitfield.h>
 #include <linux/iopoll.h>
+#include <memalign.h>
 #include <scmi_agent.h>
 #include <scmi_nxp_protocols.h>
 #include "common.h"
@@ -1261,7 +1262,8 @@ int imx9_probe_mu(void)
 	struct udevice *dev;
 	int ret;
 	u32 res;
-	struct ele_get_info_data info;
+	ALLOC_CACHE_ALIGN_BUFFER(struct ele_get_info_data, info, 1);
+	ulong end = (ulong)info + sizeof(*info);
 
 	ret = uclass_get_device_by_driver(UCLASS_SCMI_AGENT, DM_DRIVER_GET(scmi_mbox), &dev);
 	if (ret)
@@ -1278,12 +1280,15 @@ int imx9_probe_mu(void)
 	if (gd->flags & GD_FLG_RELOC)
 		return 0;
 
-	flush_dcache_range((ulong)&info, (ulong)&info + sizeof(struct ele_get_info_data));
-	ret = ele_get_info(&info, &res);
+	flush_dcache_range((ulong)info, end);
+	ret = ele_get_info(info, &res);
 	if (ret)
 		return ret;
 
-	set_cpu_info(&info);
+	/* invalidate it to avoid any speculative access */
+	invalidate_dcache_range((ulong)info, end);
+
+	set_cpu_info(info);
 
 	arch_init_post_dm_f();
 
Signature · 1 line
2.50.1
#1 lore raw

PATCH 2/2 imx9: scmi: Extend early DDR mapping to cover U-Boot

From: Ye Li <[email protected]>

The early MMU table maps only the first 64 MiB of non-secure DDR as normal memory, leaving the remaining DDR mapped as device memory. This can cause problems when CONFIG_TEXT_BASE lies outside the initial normal-memory region.

Extend the normal-memory mapping from PHYS_SDRAM to 64 MiB beyond CONFIG_TEXT_BASE aligned down to a 2 MiB boundary. Place the early MMU page tables in the final 2 MiB of this region.

Adjust the subsequent DDR remapping to start at the end of the expanded region and update the attributes only when additional memory remains within the effective DDR range.

---
 arch/arm/mach-imx/imx9/scmi/soc.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
arch/arm/mach-imx/imx9/scmi/soc.c +12 -8
index bc60b071e02..657b71a6701 100644
@@ -619,7 +619,7 @@ __weak unsigned long board_spl_mmu_tlb_base(void)
  */
 __weak unsigned long board_early_mmu_tlb_base(void)
 {
-	return CFG_SYS_SDRAM_BASE + SZ_64M - SZ_2M;
+	return ALIGN_DOWN(CONFIG_TEXT_BASE, SZ_2M) + SZ_64M - SZ_2M;
 }
 
 /*
@@ -664,7 +664,9 @@ static void early_enable_dcache(void)
 			/* Use the empty slot reserved in imx9_mem_map */
 			imx9_mem_map[i].phys = PHYS_SDRAM;
 			imx9_mem_map[i].virt = PHYS_SDRAM;
-			imx9_mem_map[i].size = SZ_64M;
+			/* map from PHYS_SDRAM to u-boot TEXT BASE + 64MB */
+			imx9_mem_map[i].size = ALIGN_DOWN(CONFIG_TEXT_BASE, SZ_2M) -
+					       PHYS_SDRAM + SZ_64M;
 			imx9_mem_map[i].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
 						PTE_BLOCK_OUTER_SHARE;
 			e = i;
@@ -697,6 +699,7 @@ static void early_enable_dcache(void)
 static void update_early_mmu_table(void)
 {
 	phys_size_t effective_sz;
+	phys_addr_t val;
 
 	if (CONFIG_IS_ENABLED(SYS_ICACHE_OFF) || CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
 		return;
@@ -706,13 +709,14 @@ static void update_early_mmu_table(void)
 
 	/* Remap u-boot effective size to normal memory */
 	effective_sz = get_effective_memsize();
-	if (effective_sz <= SZ_64M)
-		return;
 
-	mmu_change_region_attr(PHYS_SDRAM + SZ_64M, effective_sz - SZ_64M,
-			       PTE_BLOCK_MEMTYPE(MT_NORMAL)	|
-			       PTE_BLOCK_OUTER_SHARE		|
-			       PTE_TYPE_VALID);
+	val = ALIGN_DOWN(CONFIG_TEXT_BASE, SZ_2M) + SZ_64M;
+	if (val < PHYS_SDRAM + effective_sz) {
+		mmu_change_region_attr(val, PHYS_SDRAM + effective_sz - val,
+				       PTE_BLOCK_MEMTYPE(MT_NORMAL)	|
+				       PTE_BLOCK_OUTER_SHARE		|
+				       PTE_TYPE_VALID);
+	}
 }
 
 void spl_board_prepare_for_boot(void)
Signature · 1 line
2.50.1
Reviewed-by Peng Fan on v1 2/2
#2 lore raw

Re: [PATCH 2/2] imx9: scmi: Extend early DDR mapping to cover U-Boot

Quoted 11 lines · On Mon, 30 Nov 2026 10:49:35 +0800 [email protected] wrote:

From: Ye Li <[email protected]>

The early MMU table maps only the first 64 MiB of non-secure DDR as normal memory, leaving the remaining DDR mapped as device memory. This can cause problems when CONFIG_TEXT_BASE lies outside the initial normal-memory region.

Extend the normal-memory mapping from PHYS_SDRAM to 64 MiB beyond CONFIG_TEXT_BASE aligned down to a 2 MiB boundary. Place the early MMU page tables in the final 2 MiB of this region.

Quoted 5 lines

Adjust the subsequent DDR remapping to start at the end of the expanded region and update the attributes only when additional memory remains within the effective DDR range.

Reviewed-by Peng Fan on v1 1/2
#3 lore raw
In reply to [email protected]
Quoted 7 lines · On Mon, 30 Nov 2026 10:49:34 +0800 [email protected] wrote:

From: Ye Li <[email protected]>

With MMU enabled, speculative accesses can cache the ELE get-info buffer before ELE updates it. Without invalidating the buffer after ele_get_info(), set_cpu_info() may read stale data and set an incorrect soc_rev.

Quoted 8 lines

On i.MX952, this can cause the SoC detection to fail and select the non-v2x container parsing path, resulting in image loading failures during SD/eMMC reboot stress tests.

Use a cache-aligned buffer and invalidate it after a successful ele_get_info() call, before consuming the returned data.