Skip to contentSkip to conversation

arm: cache-cp15: add error when region is not aligned on MMU_SECTION

PATCH New Patrick Delaunay 2 participants 5 messages Nov 3, 2020 – Dec 1, 2020 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 arm: cache-cp15: add error when region is not aligned on MMU_SECTION

Since commit d877f8fd0f09 ("arm: provide a function for boards init code to modify MMU virtual-physical map"), the mmu_set_region_dcache_behaviour_phys parameter need to be aligned on MMU_SECTION_SIZE to avoid unpredictable behavior (alignment was done previously done in the function mmu_set_region_dcache_behaviour_phys).

This patch raised a error when this alignment is not respected. Even if this function is called so early, this message can be printed when CONFIG_DEBUG_UART is activated or can be treated later with CONFIG_PRE_CONSOLE_BUFFER.

CC Marek Szyprowski <[email protected]>

---
See complete analysis in comment #3 of patch [1] For example of workaround patch already sent see [2]

[1] http://patchwork.ozlabs.org/project/uboot/patch/20200603124345.18595-4-m.szyprowski at samsung.com/#2490603
[2] stm32mp1: mmu_set_region_dcache_behaviour

    http://patchwork.ozlabs.org/project/uboot/patch/20200724092151.21335-1-patrick.delaunay at st.com/
 arch/arm/lib/cache-cp15.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm/lib/cache-cp15.c +5 -0
index abd81d21c7..e2efe6f244 100644
@@ -68,6 +68,11 @@ void mmu_set_region_dcache_behaviour_phys(phys_addr_t start, phys_addr_t phys,
 	unsigned long startpt, stoppt;
 	unsigned long upto, end;
 
+	if (!IS_ALIGNED(start, MMU_SECTION_SIZE) ||
+	    !IS_ALIGNED(size, MMU_SECTION_SIZE))
+		log_err("%s: start=%p or size =%zx is not aligned with MMU_SECTION_SIZE (%x)\n",
+			__func__, (void *)start, size, MMU_SECTION_SIZE);
+
 	/* div by 2 before start + size to avoid phys_addr_t overflow */
 	end = ALIGN((start / 2) + (size / 2), MMU_SECTION_SIZE / 2)
 	      >> (MMU_SECTION_SHIFT - 1);
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/4 arm: cache-cp15: simplify trace support for LPAE

Add a new define OPTIONF to handle enum dcache_option option size.

This patch avoid one #ifdef CONFIG_ARMV7_LPAE in
mmu_set_region_dcache_behaviour_phys code.

---

 arch/arm/lib/cache-cp15.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
arch/arm/lib/cache-cp15.c +10 -7
index e2efe6f244..6f154de4c3 100644
@@ -12,6 +12,13 @@
 #include <linux/compiler.h>
 #include <asm/armv7_mpu.h>
 
+/* for LPAE : enum dcache_option option is ULL*/
+#ifdef CONFIG_ARMV7_LPAE
+#define OPTIONF "%llx"
+#else
+#define OPTIONF "%x"
+#endif
+
 #if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -78,13 +85,9 @@ void mmu_set_region_dcache_behaviour_phys(phys_addr_t start, phys_addr_t phys,
 	      >> (MMU_SECTION_SHIFT - 1);
 	start = start >> MMU_SECTION_SHIFT;
 
-#ifdef CONFIG_ARMV7_LPAE
-	debug("%s: start=%pa, size=%zu, option=%llx\n", __func__, &start, size,
-	      option);
-#else
-	debug("%s: start=%pa, size=%zu, option=0x%x\n", __func__, &start, size,
-	      option);
-#endif
+	debug("%s: start=%pa, size=%zu, option=0x" OPTIONF "\n",
+	      __func__, &start, size, option);
+
 	for (upto = start; upto < end; upto++, phys += MMU_SECTION_SIZE)
 		set_section_phys(upto, phys, option);
 
Signature · 1 line
2.17.1
#2 lore raw

PATCH 3/4 arm: cache-cp15: correct debug trace

In reply to Patrick Delaunay

Display in the debug trace the needed information, start and phys address (and not the &start) in mmu_set_region_dcache_behaviour_phys, before shift operation by MMU_SECTION_SHIFT.

For example, a debug trace for STM32MP157C-EV1 is:
mmu_set_region_dcache_behaviour_phys: start=c0000000, phys=c0000000,\
size=10000000, option=0x1e

---

 arch/arm/lib/cache-cp15.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
arch/arm/lib/cache-cp15.c +3 -2
index 6f154de4c3..2b94e62894 100644
@@ -80,13 +80,14 @@ void mmu_set_region_dcache_behaviour_phys(phys_addr_t start, phys_addr_t phys,
 		log_err("%s: start=%p or size =%zx is not aligned with MMU_SECTION_SIZE (%x)\n",
 			__func__, (void *)start, size, MMU_SECTION_SIZE);
 
+	debug("%s: start=%p, phys=%p, size=%zx, option=0x" OPTIONF "\n",
+	      __func__, (void *)start, (void *)phys, size, option);
+
 	/* div by 2 before start + size to avoid phys_addr_t overflow */
 	end = ALIGN((start / 2) + (size / 2), MMU_SECTION_SIZE / 2)
 	      >> (MMU_SECTION_SHIFT - 1);
 	start = start >> MMU_SECTION_SHIFT;
 
-	debug("%s: start=%pa, size=%zu, option=0x" OPTIONF "\n",
-	      __func__, &start, size, option);
 
 	for (upto = start; upto < end; upto++, phys += MMU_SECTION_SIZE)
 		set_section_phys(upto, phys, option);
Signature · 1 line
2.17.1
#3 lore raw

PATCH 4/4 scmi: smt: correct mmu_set_region_dcache_behaviour parameters

In reply to Patrick Delaunay

Since commit d877f8fd0f09 ("arm: provide a function for boards init code to modify MMU virtual-physical map"), the mmu_set_region_dcache_behaviour_phys parameters need to be aligned on MMU_SECTION_SIZE to avoid unpredictable behavior (alignment was done previously done in the function mmu_set_region_dcache_behaviour_phys).

CC Etienne Carriere <[email protected]>
Fixes 240720e9052f ("firmware: scmi: mailbox/smt agent device")

---

 drivers/firmware/scmi/smt.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/firmware/scmi/smt.c +6 -3
index d25478796a..b88e228dc8 100644
@@ -53,9 +53,12 @@ int scmi_dt_get_smt_buffer(struct udevice *dev, struct scmi_smt *smt)
 		return -ENOMEM;
 
 #ifdef CONFIG_ARM
-	if (dcache_status())
-		mmu_set_region_dcache_behaviour((uintptr_t)smt->buf,
-						smt->size, DCACHE_OFF);
+	if (dcache_status()) {
+		uintptr_t start = ALIGN_DOWN((uintptr_t)smt->buf, MMU_SECTION_SIZE);
+		size_t size = ALIGN((uintptr_t)smt->buf - start + smt->size, MMU_SECTION_SIZE);
+
+		mmu_set_region_dcache_behaviour(start, size, DCACHE_OFF);
+    }
 #endif
 
 	return 0;
Signature · 1 line
2.17.1
#4 lore raw

PATCH 1/4 arm: cache-cp15: add error when region is not aligned on MMU_SECTION

In reply to Patrick Delaunay
Quoted 6 lines · Patrick Delaunay

Since commit d877f8fd0f09 ("arm: provide a function for boards init code to modify MMU virtual-physical map"), the mmu_set_region_dcache_behaviour_phys parameter need to be aligned on MMU_SECTION_SIZE to avoid unpredictable behavior (alignment was done previously done in the function mmu_set_region_dcache_behaviour_phys).

Quoted 8 lines

This patch raised a error when this alignment is not respected. Even if this function is called so early, this message can be printed when CONFIG_DEBUG_UART is activated or can be treated later with CONFIG_PRE_CONSOLE_BUFFER.

CC Marek Szyprowski <[email protected]>

So, this series causes build problems on rpi_4_32b dra7xx_evm dra7xx_hs_evm dra7xx_hs_evm_usb at least. Please address as soon as possible as I'd like to pull this in to -next for maximum testing time. Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201201/051242f3/attachment.sig>