mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: lst@pengutronix.de, Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 2/2] habv4: drop cache maintenance around HAB SiP calls
Date: Tue,  3 Nov 2026 14:16:09 +0100	[thread overview]
Message-ID: <20261103131652.663786-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20261103131652.663786-1-a.fatoum@pengutronix.de>

From: Ahmad Fatoum <a.fatoum@barebox.org>

On i.MX8M, barebox runs in non-secure EL2 and queries the HAB status and,
except on i.MX8MQ, the HAB events via SMC. So far, we cleaned and
invalidated the caller's variables before the SMC and only invalidated
them afterwards.

TF-A doesn't do any cache maintenance itself on the buffers and the
BootROM doesn't do any either: The BootROM disables the MMU it had setup
and cleans and invalidates the D-cache before jumping to the boot image.

The results are thus written through TF-A's mapping of DRAM
(SCTLR_EL3.{M,C} = 1, MT_MEMORY | MT_RW | MT_NS), i.e. Normal
Write-Back, Inner Shareable, Non-secure, and may still be dirty in the
cache when the SMC returns. Now that barebox maps normal memory the same
way, no maintenance is needed at all and no alignment requirements exist
for buffers.

Dropping the cache maintenance also fixes a bug: The invalidate after
the SMC was wrong, as it may discard updates not yet cleaned from the
cache, such as unrelated stack data in the same lines.

This was not observed to cause issues thus far, presumably because the
Cortex-A53 on the i.MX8M cleans dirty lines on DC IVAC when invalidating
them[1].

So let's drop the maintenance. With the MMU disabled, our accesses would
be Device-nGnRnE and need it again, so make HABV4 depend on MMU for
ARMv8 systems instead.

[1]: Arm DDI 0500J, Cortex-A53 TRM, 6.2.4 Data cache maintenance
     considerations, 6-3

Fixes: 6c4d5bb5acfe ("i.MX: HABv4: implement interface for i.MX8MQ")
Fixes: 3177ed294444 ("habv4: use hab rom implementation of report_event")
Assisted-by: Claude:opus-5.5
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
While a fix, I am not in a hurry to get this merged. next is fine to get
some more testing.
---
 arch/arm/mach-imx/Kconfig |  2 +-
 drivers/hab/habv4.c       | 33 ++-------------------------------
 2 files changed, 3 insertions(+), 32 deletions(-)

diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 5a5931f1a33d..0910eaa439c8 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -907,7 +907,7 @@ config HABV4
 	select HAB
 	select NVMEM
 	select IMX_OCOTP
-	depends on ARCH_IMX6 || ARCH_IMX8M
+	depends on ARCH_IMX6 || (ARCH_IMX8M && MMU)
 	help
 	  High Assurance Boot, as found on i.MX28/i.MX6/i.MX8M.
 
diff --git a/drivers/hab/habv4.c b/drivers/hab/habv4.c
index 83ee06a6aa46..e6244c96556e 100644
--- a/drivers/hab/habv4.c
+++ b/drivers/hab/habv4.c
@@ -7,16 +7,13 @@
 
 #define pr_fmt(fmt)  "HABv4: " fmt
 
-#include <common.h>
 #include <hab.h>
 #include <init.h>
 #include <types.h>
 #include <mmu.h>
-#include <dma.h>
 #include <zero_page.h>
 #include <linux/sizes.h>
 #include <linux/arm-smccc.h>
-#include <asm/cache.h>
 
 #include <mach/imx/generic.h>
 #include <mach/imx/imx8mq.h>
@@ -196,24 +193,10 @@ static enum hab_status hab_sip_report_event(enum hab_status status,
 {
 	struct arm_smccc_res res;
 
-	v8_flush_dcache_range((unsigned long)bytes,
-			      (unsigned long)bytes + sizeof(*bytes));
-
-	if (event)
-		v8_flush_dcache_range((unsigned long)event,
-				      (unsigned long)event + *bytes);
-
 	arm_smccc_smc(FSL_SIP_HAB, FSL_SIP_HAB_REPORT_EVENT,
 		      (unsigned long)index, (unsigned long)event,
 		      (unsigned long)bytes, 0, 0, 0, &res);
 
-	v8_inv_dcache_range((unsigned long)bytes,
-			    (unsigned long)bytes + sizeof(*bytes));
-
-	if (event)
-		v8_inv_dcache_range((unsigned long)event,
-				    (unsigned long)event + *bytes);
-
 	return (enum hab_status)res.a0;
 }
 
@@ -222,22 +205,10 @@ static enum hab_status hab_sip_report_status(enum hab_config *config,
 {
 	struct arm_smccc_res res;
 
-	if (state)
-		v8_flush_dcache_range((unsigned long)state,
-				      (unsigned long)state + sizeof(*config));
-	if (config)
-		v8_flush_dcache_range((unsigned long)config,
-				      (unsigned long)config + sizeof(*state));
-
 	arm_smccc_smc(FSL_SIP_HAB, FSL_SIP_HAB_REPORT_STATUS,
 		      (unsigned long) config,
 		      (unsigned long) state, 0, 0, 0, 0, &res);
-	if (state)
-		v8_inv_dcache_range((unsigned long)state,
-				    (unsigned long)state + sizeof(*config));
-	if (config)
-		v8_inv_dcache_range((unsigned long)config,
-				    (unsigned long)config + sizeof(*state));
+
 	return (enum hab_status)res.a0;
 }
 
@@ -587,7 +558,7 @@ static uint8_t *hab_get_event(const struct habv4_rvt *rvt, int index, size_t *le
 	if (err != HAB_STATUS_SUCCESS)
 		return NULL;
 
-	buf = dma_alloc(*len);
+	buf = malloc(*len);
 	if (!buf)
 		return NULL;
 
-- 
2.47.3




      reply	other threads:[~2026-11-03 13:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 13:16 [PATCH 1/2] ARM64: mmu: map normal memory Inner Shareable Ahmad Fatoum
2026-11-03 13:16 ` Ahmad Fatoum [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261103131652.663786-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    --cc=lst@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox