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: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] tee: optee: of_fixup: allow static shared memory size of 0
Date: Thu,  3 Apr 2025 10:35:16 +0200	[thread overview]
Message-ID: <20250403083516.1838668-1-a.fatoum@pengutronix.de> (raw)

We don't necessarily need a static shared memory region for
communication with OP-TEE. Both Linux and barebox support
dynamic shared memory communication and barebox doesn't even
support static shared memory.

Make this clearer in the documentation and adapt the fixup code,
so a shared memory size of zero is handled as one would expect.

While at it, we also fix a typo: reserving too much memory is ok,
but too little can lead to instruction prefetcher crashes.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/Kconfig               | 13 +++++++++----
 drivers/tee/optee/of_fixup.c |  3 +++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/common/Kconfig b/common/Kconfig
index 8fb050a20354..188e3bbc0545 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -1297,8 +1297,8 @@ config OPTEE_SIZE
 	depends on HAVE_OPTEE
 	help
 	  Size to reserve in main memory for OP-TEE.
-	  Can be smaller than the actual size used by OP-TEE, this is used to prevent
-	  barebox from allocating memory in this area.
+	  Can be larger than the actual size used by OP-TEE, this is used to prevent
+	  barebox from using or speculating into this area.
 
 config OPTEE_SHM_SIZE
 	hex
@@ -1306,8 +1306,13 @@ config OPTEE_SHM_SIZE
 	prompt "OP-TEE Shared Memory Size"
 	depends on HAVE_OPTEE
 	help
-	  Size to reserve in main memory for OP-TEE shared memory communication.
-	  Can be used for fixing up the OP-TEE OF node.
+	  Size to reserve in main memory for static OP-TEE shared memory
+	  communication. Can be used for fixing up the OP-TEE OF node.
+
+	  A shared memory size of 0 means that only dynamic shared memory
+	  will be supported for communication with OP-TEE. This is the only
+	  mode supported by barebox anyway, but support needs to be enabled
+	  in OP-TEE at compile-time.
 
 config BOOTM_OPTEE
 	bool
diff --git a/drivers/tee/optee/of_fixup.c b/drivers/tee/optee/of_fixup.c
index e4d3c5f9b0b0..045b5a0bb754 100644
--- a/drivers/tee/optee/of_fixup.c
+++ b/drivers/tee/optee/of_fixup.c
@@ -44,6 +44,9 @@ int of_optee_fixup(struct device_node *root, void *_data)
 	if (ret)
 		return ret;
 
+	if (!fixup_data->shm_size)
+		return 0;
+
 	if (!optee_get_membase(&optee_membase)) {
 		res.start = optee_membase + OPTEE_SIZE - fixup_data->shm_size;
 		res.end = optee_membase + OPTEE_SIZE - 1;
-- 
2.39.5




             reply	other threads:[~2025-04-03  8:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-03  8:35 Ahmad Fatoum [this message]
2025-04-07 13:14 ` Sascha Hauer

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=20250403083516.1838668-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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