Skip to contentSkip to conversation

optee: Add support for enumerating RPMB-dependent services

PATCH Superseded Jan Kiszka 3 participants 16 messages Sep 8 – Sep 9

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
author
#4 lore raw

PATCH v3 3/5 tee: optee: Do not warn about TEE_ERROR_STORAGE_NOT_AVAILABLE

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

This is a transitional error that is resolved once an RPMB becomes available. Keep it as debug output only.

---
 drivers/tee/optee/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/tee/optee/core.c +4 -1
index ed8f2b6ec74..d3b5811afb8 100644
@@ -106,7 +106,10 @@ static int __enum_services(struct udevice *dev, struct tee_shm *shm, size_t *shm
 
 	ret = tee_invoke_func(dev, &arg, 1, &param);
 	if (ret || (arg.ret && arg.ret != TEE_ERROR_SHORT_BUFFER)) {
-		dev_err(dev, "Enumeration command 0x%x failed: 0x%x\n", pta_cmd, arg.ret);
+		if (arg.ret != TEE_ERROR_STORAGE_NOT_AVAILABLE)
+			dev_err(dev, "Enumeration command 0x%x failed: 0x%x\n", pta_cmd, arg.ret);
+		else
+			dev_dbg(dev, "Enumeration command 0x%x failed due to unavailable storage\n", pta_cmd);
 		return -EINVAL;
 	}
 
Signature · 1 line
2.47.3
author
#1 lore raw

PATCH v3 1/5 tee: optee: Factor out service enumeration and binding functions

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

This already avoids code duplication between the different enumeration commands. It will furthermore allow to implement a third one for services with RPMB needs.

---
 drivers/tee/optee/core.c          | 33 +++++++++++++++++--------------
 drivers/tee/optee/optee_private.h |  3 +++
 2 files changed, 21 insertions(+), 15 deletions(-)
drivers/tee/optee/core.c +18 -15
index 4d67c948ec1..2871760a7b7 100644
@@ -156,7 +156,7 @@ static int enum_services(struct udevice *dev, struct tee_shm **shm, size_t *coun
 	return ret;
 }
 
-static int open_enum_session(struct udevice *dev, u32 *tee_sess)
+int optee_open_enum_session(struct udevice *dev, u32 *tee_sess)
 {
 	const struct tee_optee_ta_uuid pta_uuid = PTA_DEVICE_ENUM;
 	struct tee_open_session_arg arg = { };
@@ -176,31 +176,34 @@ static int open_enum_session(struct udevice *dev, u32 *tee_sess)
 	return 0;
 }
 
-static int bind_service_drivers(struct udevice *dev)
+int optee_bind_services(struct udevice *dev, u32 tee_sess,
+			unsigned int pta_cmd)
 {
 	struct tee_shm *service_list = NULL;
 	size_t service_count;
-	u32 tee_sess;
-	int ret, ret2;
-
-	ret = open_enum_session(dev, &tee_sess);
-	if (ret)
-		return ret;
+	int ret;
 
 	ret = enum_services(dev, &service_list, &service_count, tee_sess,
-			    PTA_CMD_GET_DEVICES);
+			    pta_cmd);
 	if (!ret && service_count)
 		ret = bind_service_list(dev, service_list, service_count);
 
 	tee_shm_free(service_list);
-	service_list = NULL;
 
-	ret2 = enum_services(dev, &service_list, &service_count, tee_sess,
-			     PTA_CMD_GET_DEVICES_SUPP);
-	if (!ret2 && service_count)
-		ret2 = bind_service_list(dev, service_list, service_count);
+	return ret;
+}
+
+static int bind_service_drivers(struct udevice *dev)
+{
+	u32 tee_sess;
+	int ret, ret2;
 
-	tee_shm_free(service_list);
+	ret = optee_open_enum_session(dev, &tee_sess);
+	if (ret)
+		return ret;
+
+	ret = optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES);
+	ret2 = optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES_SUPP);
 
 	tee_close_session(dev, tee_sess);
 
drivers/tee/optee/optee_private.h +3 -0
index 1f07a27ee4b..25b6b3c3218 100644
@@ -27,6 +27,9 @@ struct optee_msg_arg;
 
 void optee_suppl_cmd(struct udevice *dev, struct tee_shm *shm_arg,
 		     void **page_list);
+int optee_open_enum_session(struct udevice *dev, u32 *tee_sess);
+int optee_bind_services(struct udevice *dev, u32 tee_sess,
+			unsigned int pta_cmd);
 
 #ifdef CONFIG_SUPPORT_EMMC_RPMB
 /**
Signature · 1 line
2.47.3

Jan Kiszka

author
#0 lore raw

v3 cover optee: Add support for enumerating RPMB-dependent services

This allows to find firmware TPM again with recent OP-TEE versions, possibly also other services. The StMM service was not affected because it is directly invoked by efi_variable_tee when needed, and that is late enough so that all dependencies are available by then.

See patches for further details.

Changes in v3:
- don't use dev_dev if there is no valid dev
- add device_active check to optee_rpmb_available

Changes in v2:
- fix build breakages with disabled CONFIGs
- structure code differently between optee core and rpmb
- debug() -> dev_dbg()

Jan

Jan Kiszka (5):
tee: optee: Factor out service enumeration and binding functions
tee: optee: Add support for enumerating services that only need RPMB
tee: optee: Do not warn about TEE_ERROR_STORAGE_NOT_AVAILABLE
mmc: Call back to optee after a successful mmc_init
mmc: Make "MMC Device not found" a debug output

 drivers/mmc/mmc-uclass.c          |  2 +-
 drivers/mmc/mmc.c                 |  4 +++
 drivers/mmc/mmc_legacy.c          |  2 +-
 drivers/tee/optee/core.c          | 58 +++++++++++++++----------------
 drivers/tee/optee/optee_private.h | 24 +++++++++++++
 drivers/tee/optee/rpmb.c          | 20 +++++++++++
 include/tee/optee.h               |  6 ++++
 7 files changed, 84 insertions(+), 32 deletions(-)
Signature · 1 line
2.47.3
author
#3 lore raw

PATCH v3 2/5 tee: optee: Add support for enumerating services that only need RPMB

From: Jan Kiszka <[email protected]>

Up to OP-TEE 4.4.0, all services that needed a supplicant where returned by PTA_CMD_GET_DEVICES_SUPP. Since then, services that only need a supplicant for the purpose of accessing the RPMB are only enumerated by the new, separate PTA_CMD_GET_DEVICES_RPMB. U-Boot so far lacks support for that, thus no longer finds such services, e.g. fTPM.

Perform the separate enumeration during probe but, as that may fail if the MMC is not probed yet, also provide a callback to trigger a retry when another MMC device becomes available.

---
 drivers/tee/optee/core.c          | 22 +++++++---------------
 drivers/tee/optee/optee_private.h | 21 +++++++++++++++++++++
 drivers/tee/optee/rpmb.c          | 20 ++++++++++++++++++++
 include/tee/optee.h               |  6 ++++++
 4 files changed, 54 insertions(+), 15 deletions(-)
drivers/tee/optee/core.c +7 -15
index 2871760a7b7..ed8f2b6ec74 100644
@@ -27,19 +27,6 @@
  */
 #define PTA_DEVICE_ENUM		{ 0x7011a688, 0xddde, 0x4053, \
 				  { 0xa5, 0xa9, 0x7b, 0x3c, 0x4d, 0xdf, 0x13, 0xb8 } }
-/*
- * PTA_CMD_GET_DEVICES - List services without supplicant dependencies
- *
- * [out]    memref[0]: List of the UUIDs of service enumerated by OP-TEE
- */
-#define PTA_CMD_GET_DEVICES		0x0
-
-/*
- * PTA_CMD_GET_DEVICES_SUPP - List services depending on tee supplicant
- *
- * [out]    memref[0]: List of the UUIDs of service enumerated by OP-TEE
- */
-#define PTA_CMD_GET_DEVICES_SUPP	0x1
 
 typedef void (optee_invoke_fn)(unsigned long, unsigned long, unsigned long,
 			       unsigned long, unsigned long, unsigned long,
@@ -195,8 +182,8 @@ int optee_bind_services(struct udevice *dev, u32 tee_sess,
 
 static int bind_service_drivers(struct udevice *dev)
 {
+	int ret, ret2, ret3 = 0;
 	u32 tee_sess;
-	int ret, ret2;
 
 	ret = optee_open_enum_session(dev, &tee_sess);
 	if (ret)
@@ -204,13 +191,18 @@ static int bind_service_drivers(struct udevice *dev)
 
 	ret = optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES);
 	ret2 = optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES_SUPP);
+	if (CONFIG_IS_ENABLED(SUPPORT_EMMC_RPMB))
+		ret3 = optee_bind_services(dev, tee_sess,
+					   PTA_CMD_GET_DEVICES_RPMB);
 
 	tee_close_session(dev, tee_sess);
 
 	if (ret)
 		return ret;
+	if (ret2)
+		return ret2;
 
-	return ret2;
+	return ret3;
 }
 
 /**
drivers/tee/optee/optee_private.h +21 -0
index 25b6b3c3218..daff3e04493 100644
@@ -9,6 +9,27 @@
 #include <tee.h>
 #include <log.h>
 
+/*
+ * PTA_CMD_GET_DEVICES - List services without supplicant dependencies
+ *
+ * [out]    memref[0]: List of the UUIDs of service enumerated by OP-TEE
+ */
+#define PTA_CMD_GET_DEVICES		0x0
+
+/*
+ * PTA_CMD_GET_DEVICES_SUPP - List services depending on tee supplicant
+ *
+ * [out]    memref[0]: List of the UUIDs of service enumerated by OP-TEE
+ */
+#define PTA_CMD_GET_DEVICES_SUPP	0x1
+
+/*
+ * PTA_CMD_GET_DEVICES_RPMB - List services only depending on RPMB support
+ *
+ * [out]    memref[0]: List of the UUIDs of service enumerated by OP-TEE
+ */
+#define PTA_CMD_GET_DEVICES_RPMB	0x2
+
 /**
  * struct optee_private - OP-TEE driver private data
  * @rpmb_mmc:		mmc device for the RPMB partition
drivers/tee/optee/rpmb.c +20 -0
index bacced6af6c..7ae6045511b 100644
@@ -191,3 +191,23 @@ void optee_suppl_rpmb_release(struct udevice *dev)
 {
 	release_mmc(dev_get_priv(dev));
 }
+
+void optee_rpmb_available(void)
+{
+	struct udevice *dev;
+	struct uclass *uc;
+	u32 tee_sess;
+
+	uclass_id_foreach_dev(UCLASS_TEE, dev, uc) {
+		if (strcmp(dev->driver->name, "optee") != 0 ||
+		    !device_active(dev))
+			continue;
+
+		if (optee_open_enum_session(dev, &tee_sess) != 0)
+			continue;
+
+		optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES_RPMB);
+
+		tee_close_session(dev, tee_sess);
+	}
+}
include/tee/optee.h +6 -0
index d1194493780..755533b2c0b 100644
@@ -74,4 +74,10 @@ static inline bool is_optee_smc_api(void)
 }
 #endif
 
+#if defined(CONFIG_OPTEE) && defined(CONFIG_SUPPORT_EMMC_RPMB)
+void optee_rpmb_available(void);
+#else
+static inline void optee_rpmb_available(void) {}
+#endif
+
 #endif /* _OPTEE_H */
Signature · 1 line
2.47.3
author
#5 lore raw

PATCH v3 4/5 mmc: Call back to optee after a successful mmc_init

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

This is needed to that OP-TEE can re-enumerate services which need RPMB access that may have become available now.

---
CC: Peng Fan <[email protected]>
CC: Jaehoon Chung <[email protected]>

---
 drivers/mmc/mmc.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mmc/mmc.c +4 -0
index 670e92ee12b..2463e50cd3c 100644
@@ -27,6 +27,7 @@
 #include <linux/list.h>
 #include <linux/printk.h>
 #include <div64.h>
+#include <tee/optee.h>
 #include "mmc_private.h"
 
 #define DEFAULT_CMD6_TIMEOUT_MS  500
@@ -3168,6 +3169,9 @@ int mmc_init(struct mmc *mmc)
 				mmc->cfg->name);
 	}
 
+	if (CONFIG_IS_ENABLED(OPTEE) && mmc->capacity_rpmb > 0)
+		optee_rpmb_available();
+
 	return err;
 }
 
Signature · 1 line
2.47.3
author
#13 lore raw

PATCH v3 5/5 mmc: Make "MMC Device not found" a debug output

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

Callers of find_mmc_device are generally processing and informing about errors already, e.g.

=> mmc dev 2
MMC Device 2 not found
no mmc device at slot 2

---
CC: Peng Fan <[email protected]>
CC: Jaehoon Chung <[email protected]>

---
 drivers/mmc/mmc-uclass.c | 2 +-
 drivers/mmc/mmc_legacy.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/mmc-uclass.c +1 -1
index 698530088fe..cd930807802 100644
@@ -319,7 +319,7 @@ struct mmc *find_mmc_device(int dev_num)
 
 	if (ret) {
 #if !defined(CONFIG_XPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
-		printf("MMC Device %d not found\n", dev_num);
+		debug("MMC Device %d not found\n", dev_num);
 #endif
 		return NULL;
 	}
drivers/mmc/mmc_legacy.c +1 -1
index 8f8ba34be71..2a4a8a83fb3 100644
@@ -45,7 +45,7 @@ struct mmc *find_mmc_device(int dev_num)
 	}
 
 #if !defined(CONFIG_XPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
-	printf("MMC Device %d not found\n", dev_num);
+	debug("MMC Device %d not found\n", dev_num);
 #endif
 
 	return NULL;
Signature · 1 line
2.47.3
Reviewed-by on v3 1/5
#2 lore raw

Re: [PATCH v3 1/5] tee: optee: Factor out service enumeration and binding functions

In reply to Jan Kiszka
Quoted 9 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

This already avoids code duplication between the different enumeration commands. It will furthermore allow to implement a third one for services with RPMB needs.

---

Quoted 83 lines
 drivers/tee/optee/core.c          | 33 +++++++++++++++++--------------
 drivers/tee/optee/optee_private.h |  3 +++
 2 files changed, 21 insertions(+), 15 deletions(-)
drivers/tee/optee/core.c +18 -15
index 4d67c948ec1..2871760a7b7 100644
@@ -156,7 +156,7 @@ static int enum_services(struct udevice *dev, struct tee_shm **shm, size_t *coun
        return ret;
 }
 
-static int open_enum_session(struct udevice *dev, u32 *tee_sess)
+int optee_open_enum_session(struct udevice *dev, u32 *tee_sess)
 {
        const struct tee_optee_ta_uuid pta_uuid = PTA_DEVICE_ENUM;
        struct tee_open_session_arg arg = { };
@@ -176,31 +176,34 @@ static int open_enum_session(struct udevice *dev, u32 *tee_sess)
        return 0;
 }
 
-static int bind_service_drivers(struct udevice *dev)
+int optee_bind_services(struct udevice *dev, u32 tee_sess,
+                       unsigned int pta_cmd)
 {
        struct tee_shm *service_list = NULL;
        size_t service_count;
-       u32 tee_sess;
-       int ret, ret2;
-
-       ret = open_enum_session(dev, &tee_sess);
-       if (ret)
-               return ret;
+       int ret;
 
        ret = enum_services(dev, &service_list, &service_count, tee_sess,
-                           PTA_CMD_GET_DEVICES);
+                           pta_cmd);
        if (!ret && service_count)
                ret = bind_service_list(dev, service_list, service_count);
 
        tee_shm_free(service_list);
-       service_list = NULL;
 
-       ret2 = enum_services(dev, &service_list, &service_count, tee_sess,
-                            PTA_CMD_GET_DEVICES_SUPP);
-       if (!ret2 && service_count)
-               ret2 = bind_service_list(dev, service_list, service_count);
+       return ret;
+}
+
+static int bind_service_drivers(struct udevice *dev)
+{
+       u32 tee_sess;
+       int ret, ret2;
 
-       tee_shm_free(service_list);
+       ret = optee_open_enum_session(dev, &tee_sess);
+       if (ret)
+               return ret;
+
+       ret = optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES);
+       ret2 = optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES_SUPP);
 
        tee_close_session(dev, tee_sess);
 
drivers/tee/optee/optee_private.h +3 -1
index 1f07a27ee4b..25b6b3c3218 100644
@@ -27,6 +27,9 @@ struct optee_msg_arg;
 
 void optee_suppl_cmd(struct udevice *dev, struct tee_shm *shm_arg,
                     void **page_list);
+int optee_open_enum_session(struct udevice *dev, u32 *tee_sess);
+int optee_bind_services(struct udevice *dev, u32 tee_sess,
+                       unsigned int pta_cmd);
 
 #ifdef CONFIG_SUPPORT_EMMC_RPMB
 /**
--

2.47.3

Reviewed-by
#15 lore raw

Re: [PATCH v3 5/5] mmc: Make "MMC Device not found" a debug output

In reply to Kathpalia, Tanmay
Quoted 8 lines · Tanmay
Quoted 5 lines · Jan Kiszka

From: Jan Kiszka <[email protected]>

Callers of find_mmc_device are generally processing and informing about errors already, e.g.

Quoted 8 lines
Quoted 5 lines

=> mmc dev 2
MMC Device 2 not found
no mmc device at slot 2

#6 lore raw

Re: [PATCH v3 4/5] mmc: Call back to optee after a successful mmc_init

In reply to Jan Kiszka

Hi Jan

[...]

Quoted 11 lines
drivers/mmc/mmc.c +1 -0
@@ -27,6 +27,7 @@
 #include <linux/list.h>
 #include <linux/printk.h>
 #include <div64.h>
+#include <tee/optee.h>
 #include "mmc_private.h"
 
 #define DEFAULT_CMD6_TIMEOUT_MS  500

drivers/mmc/mmc.c int mmc_init(struct mmc *mmc) · line 3173

Quoted 5 lines
drivers/mmc/mmc.c +2 -0
@@ -3168,6 +3169,9 @@ int mmc_init(struct mmc *mmc)
                                mmc->cfg->name);
        }
 
+       if (CONFIG_IS_ENABLED(OPTEE) && mmc->capacity_rpmb > 0)
+               optee_rpmb_available();

With this we'll end up calling the optee bind methods again for discovered devices calling bind_service_list(). I haven't tested this locally yet, but is there any chance this ends up binding the devices that depend on an RPMB twice?

Thanks
/Ilias

Quoted 7 lines
drivers/mmc/mmc.c +1 -1
+
        return err;
 }
 
--

2.47.3

author
#7 lore raw

Re: [PATCH v3 4/5] mmc: Call back to optee after a successful mmc_init

Quoted 18 lines · Ilias Apalodimas

Hi Jan

[...]

Quoted 14 lines
drivers/mmc/mmc.c +1 -0
@@ -27,6 +27,7 @@
 #include <linux/list.h>
 #include <linux/printk.h>
 #include <div64.h>
+#include <tee/optee.h>
 #include "mmc_private.h"
 
 #define DEFAULT_CMD6_TIMEOUT_MS  500
@@ -3168,6 +3169,9 @@ int mmc_init(struct mmc *mmc)
                                mmc->cfg->name);
        }
 
Quoted 7 lines

drivers/mmc/mmc.c int mmc_init(struct mmc *mmc) · line 3173

Quoted 2 lines
drivers/mmc/mmc.c +2 -0
+       if (CONFIG_IS_ENABLED(OPTEE) && mmc->capacity_rpmb > 0)
+               optee_rpmb_available();

With this we'll end up calling the optee bind methods again for discovered devices calling bind_service_list(). I haven't tested this locally yet, but is there any chance this ends up binding the devices that depend on an RPMB twice?

I don't think we will have an issue here: Either OP-TEE isn't ready yet, or RPMB wasn't yet when we called it first. So I do not see yet who actual successful listing could be done twice.

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
#8 lore raw

Re: [PATCH v3 4/5] mmc: Call back to optee after a successful mmc_init

Quoted 28 lines · Jan Kiszka
Quoted 18 lines · Ilias Apalodimas

Hi Jan

[...]

Quoted 14 lines
drivers/mmc/mmc.c +1 -0
@@ -27,6 +27,7 @@
 #include <linux/list.h>
 #include <linux/printk.h>
 #include <div64.h>
+#include <tee/optee.h>
 #include "mmc_private.h"
 
 #define DEFAULT_CMD6_TIMEOUT_MS  500
@@ -3168,6 +3169,9 @@ int mmc_init(struct mmc *mmc)
                                mmc->cfg->name);
        }
 
Quoted 7 lines

drivers/mmc/mmc.c int mmc_init(struct mmc *mmc) · line 3173

Quoted 2 lines
drivers/mmc/mmc.c +2 -0
+       if (CONFIG_IS_ENABLED(OPTEE) && mmc->capacity_rpmb > 0)
+               optee_rpmb_available();

With this we'll end up calling the optee bind methods again for discovered devices calling bind_service_list(). I haven't tested this locally yet, but is there any chance this ends up binding the devices that depend on an RPMB twice?

Quoted 3 lines

I don't think we will have an issue here: Either OP-TEE isn't ready yet, or RPMB wasn't yet when we called it first. So I do not see yet who actual successful listing could be done twice.

The question is what happens if OP-TEE & the RPMB is ready and you issue an mmc rescan. That will force optee_rpmb_available() to re-run and rediscover all the devices no?

Thanks
/Ilias

Quoted 6 lines

Jan

--
Siemens AG, Foundational Technologies
Linux Expert Center

author
#9 lore raw

Re: [PATCH v3 4/5] mmc: Call back to optee after a successful mmc_init

Quoted 29 lines · Ilias Apalodimas
Quoted 28 lines · Jan Kiszka
Quoted 25 lines · Ilias Apalodimas

Hi Jan

[...]

Quoted 11 lines
drivers/mmc/mmc.c +1 -0
@@ -27,6 +27,7 @@
 #include <linux/list.h>
 #include <linux/printk.h>
 #include <div64.h>
+#include <tee/optee.h>
 #include "mmc_private.h"
 
 #define DEFAULT_CMD6_TIMEOUT_MS  500

drivers/mmc/mmc.c int mmc_init(struct mmc *mmc) · line 3173

Quoted 5 lines
drivers/mmc/mmc.c +2 -0
@@ -3168,6 +3169,9 @@ int mmc_init(struct mmc *mmc)
                                mmc->cfg->name);
        }
 
+       if (CONFIG_IS_ENABLED(OPTEE) && mmc->capacity_rpmb > 0)
+               optee_rpmb_available();

With this we'll end up calling the optee bind methods again for discovered devices calling bind_service_list(). I haven't tested this locally yet, but is there any chance this ends up binding the devices that depend on an RPMB twice?

Quoted 7 lines
Quoted 3 lines

I don't think we will have an issue here: Either OP-TEE isn't ready yet, or RPMB wasn't yet when we called it first. So I do not see yet who actual successful listing could be done twice.

The question is what happens if OP-TEE & the RPMB is ready and you issue an mmc rescan. That will force optee_rpmb_available() to re-run and rediscover all the devices no?

Hmm, let me check...

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
author
#10 lore raw

Re: [PATCH v3 4/5] mmc: Call back to optee after a successful mmc_init

Quoted 34 lines · Jan Kiszka
Quoted 33 lines · Ilias Apalodimas
Quoted 31 lines · Jan Kiszka
Quoted 18 lines · Ilias Apalodimas

Hi Jan

[...]

Quoted 14 lines
drivers/mmc/mmc.c +1 -0
@@ -27,6 +27,7 @@
 #include <linux/list.h>
 #include <linux/printk.h>
 #include <div64.h>
+#include <tee/optee.h>
 #include "mmc_private.h"
 
 #define DEFAULT_CMD6_TIMEOUT_MS  500
@@ -3168,6 +3169,9 @@ int mmc_init(struct mmc *mmc)
                                mmc->cfg->name);
        }
 
Quoted 7 lines

drivers/mmc/mmc.c int mmc_init(struct mmc *mmc) · line 3173

Quoted 2 lines
drivers/mmc/mmc.c +2 -0
+       if (CONFIG_IS_ENABLED(OPTEE) && mmc->capacity_rpmb > 0)
+               optee_rpmb_available();

With this we'll end up calling the optee bind methods again for discovered devices calling bind_service_list(). I haven't tested this locally yet, but is there any chance this ends up binding the devices that depend on an RPMB twice?

I don't think we will have an issue here: Either OP-TEE isn't ready yet, or RPMB wasn't yet when we called it first. So I do not see yet who actual successful listing could be done twice.

Quoted 6 lines
Quoted 3 lines

The question is what happens if OP-TEE & the RPMB is ready and you issue an mmc rescan. That will force optee_rpmb_available() to re-run and rediscover all the devices no?

Hmm, let me check...

It's a problem. Is there a helper/service to check the binding state, or should we track that via a static flag in optee_rpmb_available?

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
author
#11 lore raw

Re: [PATCH v3 4/5] mmc: Call back to optee after a successful mmc_init

Quoted 39 lines · Jan Kiszka
Quoted 38 lines · Jan Kiszka
Quoted 36 lines · Ilias Apalodimas
Quoted 28 lines · Jan Kiszka
Quoted 18 lines · Ilias Apalodimas

Hi Jan

[...]

Quoted 14 lines
drivers/mmc/mmc.c +1 -0
@@ -27,6 +27,7 @@
 #include <linux/list.h>
 #include <linux/printk.h>
 #include <div64.h>
+#include <tee/optee.h>
 #include "mmc_private.h"
 
 #define DEFAULT_CMD6_TIMEOUT_MS  500
@@ -3168,6 +3169,9 @@ int mmc_init(struct mmc *mmc)
                                mmc->cfg->name);
        }
 
Quoted 7 lines

drivers/mmc/mmc.c int mmc_init(struct mmc *mmc) · line 3173

Quoted 2 lines
drivers/mmc/mmc.c +2 -0
+       if (CONFIG_IS_ENABLED(OPTEE) && mmc->capacity_rpmb > 0)
+               optee_rpmb_available();

With this we'll end up calling the optee bind methods again for discovered devices calling bind_service_list(). I haven't tested this locally yet, but is there any chance this ends up binding the devices that depend on an RPMB twice?

Quoted 3 lines

I don't think we will have an issue here: Either OP-TEE isn't ready yet, or RPMB wasn't yet when we called it first. So I do not see yet who actual successful listing could be done twice.

The question is what happens if OP-TEE & the RPMB is ready and you issue an mmc rescan. That will force optee_rpmb_available() to re-run and rediscover all the devices no?

Quoted 6 lines
Quoted 2 lines

Hmm, let me check...

It's a problem. Is there a helper/service to check the binding state, or should we track that via a static flag in optee_rpmb_available?

Didn't find anything, would go with something like this:

drivers/tee/optee/rpmb.c +11 -1
index 7ae6045511b..bcad14a7251 100644
@@ -194,9 +194,14 @@ void optee_suppl_rpmb_release(struct udevice *dev)
 
 void optee_rpmb_available(void)
 {
+	static bool rpmb_services_bound;
 	struct udevice *dev;
 	struct uclass *uc;
 	u32 tee_sess;
+	int ret;
+
+	if (rpmb_services_bound)
+		return;
 
 	uclass_id_foreach_dev(UCLASS_TEE, dev, uc) {
 		if (strcmp(dev->driver->name, "optee") != 0 ||
@@ -206,8 +211,13 @@ void optee_rpmb_available(void)
 		if (optee_open_enum_session(dev, &tee_sess) != 0)
 			continue;
 
-		optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES_RPMB);
+		ret = optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES_RPMB);
 
 		tee_close_session(dev, tee_sess);
+
+		if (!ret) {
+			rpmb_services_bound = true;
+			break;
+		}
 	}
 }

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
#12 lore raw

Re: [PATCH v3 4/5] mmc: Call back to optee after a successful mmc_init

Quoted 41 lines · Jan Kiszka
Quoted 39 lines · Jan Kiszka
Quoted 38 lines · Jan Kiszka
Quoted 36 lines · Ilias Apalodimas
Quoted 28 lines · Jan Kiszka
Quoted 18 lines · Ilias Apalodimas

Hi Jan

[...]

Quoted 14 lines
drivers/mmc/mmc.c +1 -0
@@ -27,6 +27,7 @@
 #include <linux/list.h>
 #include <linux/printk.h>
 #include <div64.h>
+#include <tee/optee.h>
 #include "mmc_private.h"
 
 #define DEFAULT_CMD6_TIMEOUT_MS  500
@@ -3168,6 +3169,9 @@ int mmc_init(struct mmc *mmc)
                                mmc->cfg->name);
        }
 
Quoted 7 lines

drivers/mmc/mmc.c int mmc_init(struct mmc *mmc) · line 3173

Quoted 2 lines
drivers/mmc/mmc.c +2 -0
+       if (CONFIG_IS_ENABLED(OPTEE) && mmc->capacity_rpmb > 0)
+               optee_rpmb_available();

With this we'll end up calling the optee bind methods again for discovered devices calling bind_service_list(). I haven't tested this locally yet, but is there any chance this ends up binding the devices that depend on an RPMB twice?

Quoted 3 lines

I don't think we will have an issue here: Either OP-TEE isn't ready yet, or RPMB wasn't yet when we called it first. So I do not see yet who actual successful listing could be done twice.

The question is what happens if OP-TEE & the RPMB is ready and you issue an mmc rescan. That will force optee_rpmb_available() to re-run and rediscover all the devices no?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Hmm, let me check...

It's a problem. Is there a helper/service to check the binding state, or should we track that via a static flag in optee_rpmb_available?

Didn't find anything, would go with something like this:

I am not sure if I am correct here but looking at the call path optee_bind_services -> bind_service_list -> device_bind_driver_to_node -> device_bind_with_driver_data.
The latter sets DM_FLAG_BOUND. I don't know the DM code too well though to be 100% the flag is safe to use.
There's also DM_FLAG_ACTIVATED

Cheers
/Ilias

Quoted 42 lines
drivers/tee/optee/rpmb.c +11 -1
index 7ae6045511b..bcad14a7251 100644
@@ -194,9 +194,14 @@ void optee_suppl_rpmb_release(struct udevice *dev)
 
 void optee_rpmb_available(void)
 {
+       static bool rpmb_services_bound;
        struct udevice *dev;
        struct uclass *uc;
        u32 tee_sess;
+       int ret;
+
+       if (rpmb_services_bound)
+               return;
 
        uclass_id_foreach_dev(UCLASS_TEE, dev, uc) {
                if (strcmp(dev->driver->name, "optee") != 0 ||
@@ -206,8 +211,13 @@ void optee_rpmb_available(void)
                if (optee_open_enum_session(dev, &tee_sess) != 0)
                        continue;
 
-               optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES_RPMB);
+               ret = optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES_RPMB);
 
                tee_close_session(dev, tee_sess);
+
+               if (!ret) {
+                       rpmb_services_bound = true;
+                       break;
+               }
        }
 }

Jan

--
Siemens AG, Foundational Technologies
Linux Expert Center