Skip to contentSkip to conversation

optee: Add support for enumerating RPMB-dependent services

PATCH Superseded Jan Kiszka 2 participants 11 messages Aug 21 – Aug 23

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
author
#1 lore raw

PATCH 1/4 tee: optee: Add support for enumerating services that only need RPMB

In reply to Jan Kiszka

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          | 32 +++++++++++++++++++++++++++++++
 drivers/tee/optee/optee_private.h |  2 ++
 drivers/tee/optee/rpmb.c          | 11 +++++++++++
 include/tee/optee.h               |  2 ++
 4 files changed, 47 insertions(+)
drivers/tee/optee/core.c +32 -0
index 4d67c948ec1..5600d5a4c7d 100644
@@ -41,6 +41,13 @@
  */
 #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
+
 typedef void (optee_invoke_fn)(unsigned long, unsigned long, unsigned long,
 			       unsigned long, unsigned long, unsigned long,
 			       unsigned long, unsigned long,
@@ -210,6 +217,29 @@ static int bind_service_drivers(struct udevice *dev)
 	return ret2;
 }
 
+#ifdef CONFIG_SUPPORT_EMMC_RPMB
+void optee_bind_service_drivers_rpmb(struct udevice *dev)
+{
+	struct tee_shm *service_list = NULL;
+	size_t service_count;
+	u32 tee_sess;
+	int ret;
+
+	ret = open_enum_session(dev, &tee_sess);
+	if (ret)
+		return;
+
+	ret = enum_services(dev, &service_list, &service_count, tee_sess,
+			    PTA_CMD_GET_DEVICES_RPMB);
+	if (!ret && service_count)
+		ret = bind_service_list(dev, service_list, service_count);
+
+	tee_shm_free(service_list);
+
+	tee_close_session(dev, tee_sess);
+}
+#endif
+
 /**
  * reg_pair_to_ptr() - Make a pointer of 2 32-bit values
  * @reg0:	High bits of the pointer
@@ -852,6 +882,8 @@ static int optee_probe(struct udevice *dev)
 		ret = bind_service_drivers(dev);
 		if (ret)
 			dev_warn(dev, "optee service enumeration failed: %d\n", ret);
+		else
+			optee_bind_service_drivers_rpmb(dev);
 	} else if (IS_ENABLED(CONFIG_RNG_OPTEE)) {
 		/*
 		 * Discovery of TAs on the TEE bus is not supported in U-Boot:
drivers/tee/optee/optee_private.h +2 -0
index 1f07a27ee4b..b5a58df5b96 100644
@@ -79,4 +79,6 @@ static inline void optee_suppl_cmd_i2c_transfer(struct optee_msg_arg *arg)
 
 void *optee_alloc_and_init_page_list(void *buf, ulong len, u64 *phys_buf_ptr);
 
+void optee_bind_service_drivers_rpmb(struct udevice *dev);
+
 #endif /* __OPTEE_PRIVATE_H */
drivers/tee/optee/rpmb.c +11 -0
index bacced6af6c..f4a66641755 100644
@@ -191,3 +191,14 @@ 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;
+
+	uclass_id_foreach_dev(UCLASS_TEE, dev, uc) {
+		if (strcmp(dev->driver->name, "optee") == 0)
+			optee_bind_service_drivers_rpmb(dev);
+	}
+}
include/tee/optee.h +2 -0
index d1194493780..c12fda3cc73 100644
@@ -74,4 +74,6 @@ static inline bool is_optee_smc_api(void)
 }
 #endif
 
+void optee_rpmb_available(void);
+
 #endif /* _OPTEE_H */
Signature · 1 line
2.47.3
author
#10 lore raw

PATCH 4/4 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

Jan Kiszka

author
#0 lore raw

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.

Jan

Jan Kiszka (4):
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          | 37 ++++++++++++++++++++++++++++++-
 drivers/tee/optee/optee_private.h |  2 ++
 drivers/tee/optee/rpmb.c          | 11 +++++++++
 include/tee/optee.h               |  2 ++
 7 files changed, 57 insertions(+), 3 deletions(-)
Signature · 1 line
2.47.3
author
#6 lore raw

PATCH 2/4 tee: optee: Do not warn about TEE_ERROR_STORAGE_NOT_AVAILABLE

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 5600d5a4c7d..4b1396b8652 100644
@@ -126,7 +126,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
+			debug("Enumeration command 0x%x failed due to unavailable storage\n", pta_cmd);
 		return -EINVAL;
 	}
 
Signature · 1 line
2.47.3
author
#8 lore raw

PATCH 3/4 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
#2 lore raw

Re: [PATCH 1/4] tee: optee: Add support for enumerating services that only need RPMB

In reply to Jan Kiszka

Hi Jan,

I am not an expert in TEE, but I went through this patch while reviewing the MMC side of the series and found a few issues.

Quoted 39 lines · Jan Kiszka

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          | 32 +++++++++++++++++++++++++++++++
  drivers/tee/optee/optee_private.h |  2 ++
  drivers/tee/optee/rpmb.c          | 11 +++++++++++
  include/tee/optee.h               |  2 ++
  4 files changed, 47 insertions(+)
drivers/tee/optee/core.c +7 -0
index 4d67c948ec1..5600d5a4c7d 100644
@@ -41,6 +41,13 @@
   */
  #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
+
  typedef void (optee_invoke_fn)(unsigned long, unsigned long, unsigned long,
  			       unsigned long, unsigned long, unsigned long,
  			       unsigned long, unsigned long,

drivers/tee/optee/core.c static int bind_service_drivers(struct udevice *dev) · line 221

Quoted 5 lines
drivers/tee/optee/core.c +2 -0
@@ -210,6 +217,29 @@ static int bind_service_drivers(struct udevice *dev)
  	return ret2;
  }
 
+#ifdef CONFIG_SUPPORT_EMMC_RPMB
+void optee_bind_service_drivers_rpmb(struct udevice *dev)

This function is only compiled when SUPPORT_EMMC_RPMB is set, but optee_probe() calls it unconditionally after a successful bind_service_drivers(). optee_private.h stubs other functions for the !RPMB case, this new prototype has no such stub, so for SUPPORT_EMMC_RPMB=n should fail to link.

Quoted 4 lines
drivers/tee/optee/core.c +4 -0
+{
+	struct tee_shm *service_list = NULL;
+	size_t service_count;
+	u32 tee_sess;

drivers/tee/optee/core.c static int bind_service_drivers(struct udevice *dev) · line 235

Quoted 10 lines
drivers/tee/optee/core.c +10 -0
+	int ret;
+
+	ret = open_enum_session(dev, &tee_sess);
+	if (ret)
+		return;
+
+	ret = enum_services(dev, &service_list, &service_count, tee_sess,
+			    PTA_CMD_GET_DEVICES_RPMB);
+	if (!ret && service_count)
+		ret = bind_service_list(dev, service_list, service_count);

A dev_dbg print would help here.

Quoted 24 lines
drivers/tee/optee/core.c +9 -0
+
+	tee_shm_free(service_list);
+
+	tee_close_session(dev, tee_sess);
+}
+#endif
+
  /**
   * reg_pair_to_ptr() - Make a pointer of 2 32-bit values
   * @reg0:	High bits of the pointer
@@ -852,6 +882,8 @@ static int optee_probe(struct udevice *dev)
  		ret = bind_service_drivers(dev);
  		if (ret)
  			dev_warn(dev, "optee service enumeration failed: %d\n", ret);
+		else
+			optee_bind_service_drivers_rpmb(dev);
  	} else if (IS_ENABLED(CONFIG_RNG_OPTEE)) {
  		/*
  		 * Discovery of TAs on the TEE bus is not supported in U-Boot:
drivers/tee/optee/optee_private.h +0 -0
index 1f07a27ee4b..b5a58df5b96 100644

drivers/tee/optee/optee_private.h static inline void optee_suppl_cmd_i2c_transfer(struct optee_msg_arg *arg) · line 83

Quoted 5 lines
drivers/tee/optee/optee_private.h +2 -0
@@ -79,4 +79,6 @@ static inline void optee_suppl_cmd_i2c_transfer(struct optee_msg_arg *arg)
 
  void *optee_alloc_and_init_page_list(void *buf, ulong len, u64 *phys_buf_ptr);
 
+void optee_bind_service_drivers_rpmb(struct udevice *dev);
+

Please wrap this like the other RPMB helpers in this header (#ifdef CONFIG_SUPPORT_EMMC_RPMB plus an empty inline stub), rather than a bare prototype.

Quoted 25 lines
drivers/tee/optee/optee_private.h +0 -0
  #endif /* __OPTEE_PRIVATE_H */
drivers/tee/optee/rpmb.c +11 -0
index bacced6af6c..f4a66641755 100644
@@ -191,3 +191,14 @@ 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;
+
+	uclass_id_foreach_dev(UCLASS_TEE, dev, uc) {
+		if (strcmp(dev->driver->name, "optee") == 0)
+			optee_bind_service_drivers_rpmb(dev);
+	}
+}
include/tee/optee.h +0 -0
index d1194493780..c12fda3cc73 100644

include/tee/optee.h static inline bool is_optee_smc_api(void) · line 78

Quoted 5 lines
include/tee/optee.h +2 -0
@@ -74,4 +74,6 @@ static inline bool is_optee_smc_api(void)
  }
  #endif
 
+void optee_rpmb_available(void);
+

When OPTEE=y and SUPPORT_EMMC_RPMB=n, where the call is made to optee_rpmb_avaliable but the symbol only lives in rpmb.o. Either stub when RPMB is off, or you can gate the MMC call on SUPPORT_EMMC_RPMB.

Quoted 1 line
include/tee/optee.h +0 -0
  #endif /* _OPTEE_H */
#7 lore raw

Re: [PATCH 2/4] tee: optee: Do not warn about TEE_ERROR_STORAGE_NOT_AVAILABLE

In reply to Jan Kiszka

Hi Jan,

One minor nit.

Quoted 15 lines · 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 +0 -0
index 5600d5a4c7d..4b1396b8652 100644

drivers/tee/optee/core.c static int __enum_services(struct udevice *dev, struct tee_shm *shm, size_t *shm · line 132

Quoted 8 lines
drivers/tee/optee/core.c +4 -1
@@ -126,7 +126,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
+			debug("Enumeration command 0x%x failed due to unavailable storage\n", pta_cmd);

Prefer dev_dbg() over debug() so the device name stays in the log, same as the dev_err path.

Quoted 1 line
#9 lore raw

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

In reply to Jan Kiszka

Hi Jan,

Quoted 18 lines · 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 +0 -0
index 670e92ee12b..2463e50cd3c 100644

drivers/mmc/mmc.c line 30

Quoted 4 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>

The include is unconditional while the call is not.

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

Quoted 8 lines
drivers/mmc/mmc.c +1 -0
  #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)

It will fail to link when OPTEE=y and SUPPORT_EMMC_RPMB=n. Add SUPPORT_EMMC_RPMB (or stub the symbol when RPMB is off).

Quoted 5 lines
drivers/mmc/mmc.c +2 -0
+		optee_rpmb_available();
+
  	return err;
  }
 
author
#3 lore raw

Re: [PATCH 1/4] tee: optee: Add support for enumerating services that only need RPMB

In reply to Kathpalia, Tanmay
Quoted 48 lines · Tanmay

Hi Jan,

I am not an expert in TEE, but I went through this patch while reviewing the MMC side of the series and found a few issues.

Quoted 42 lines · Jan Kiszka

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          | 32 +++++++++++++++++++++++++++++++ drivers/tee/optee/optee_private.h |  2 ++ drivers/tee/optee/rpmb.c          | 11 +++++++++++ include/tee/optee.h               |  2 ++

  4 files changed, 47 insertions(+)
drivers/tee/optee/core.c +0 -0
index 4d67c948ec1..5600d5a4c7d 100644
@@ -41,6 +41,13 @@
    */
   #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
+ */

drivers/tee/optee/core.c +2 -0
+#define PTA_CMD_GET_DEVICES_RPMB    0x2
+

  typedef void (optee_invoke_fn)(unsigned long, unsigned long, unsigned long,
                     unsigned long, unsigned long, unsigned long, unsigned long, unsigned long,

drivers/tee/optee/core.c +0 -0
@@ -210,6 +217,29 @@ static int bind_service_drivers(struct udevice *dev)
       return ret2;
   }
Quoted 9 lines
Quoted 2 lines

  +#ifdef CONFIG_SUPPORT_EMMC_RPMB
+void optee_bind_service_drivers_rpmb(struct udevice *dev)

This function is only compiled when SUPPORT_EMMC_RPMB is set, but optee_probe() calls it unconditionally after a successful bind_service_drivers(). optee_private.h stubs other functions for the !RPMB case, this new prototype has no such stub, so for SUPPORT_EMMC_RPMB=n should fail to link.

Yeah, thanks for reminding - I forgot again that the linker won't resolve that. Will also refactor this to move the rpmb part into the rpmb module.

Quoted 8 lines
Quoted 8 lines
drivers/tee/optee/core.c +8 -0
+{
+    struct tee_shm *service_list = NULL;
+    size_t service_count;
+    u32 tee_sess;
+    int ret;
+
+    ret = open_enum_session(dev, &tee_sess);
+    if (ret)
Quoted 9 lines
Quoted 6 lines

+        return;
+
+    ret = enum_services(dev, &service_list, &service_count, tee_sess, +                PTA_CMD_GET_DEVICES_RPMB);
+    if (!ret && service_count)
+        ret = bind_service_list(dev, service_list, service_count);

A dev_dbg print would help here.

Of what exactly?

Thanks for the feedback,
Jan

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

Re: [PATCH 1/4] tee: optee: Add support for enumerating services that only need RPMB

Quoted 77 lines · Jan Kiszka
Quoted 47 lines · Tanmay

Hi Jan,

I am not an expert in TEE, but I went through this patch while reviewing the MMC side of the series and found a few issues.

Quoted 41 lines · Jan Kiszka

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          | 32 +++++++++++++++++++++++++++++++
   drivers/tee/optee/optee_private.h |  2 ++
   drivers/tee/optee/rpmb.c          | 11 +++++++++++
   include/tee/optee.h               |  2 ++
   4 files changed, 47 insertions(+)
drivers/tee/optee/core.c +1 -0
index 4d67c948ec1..5600d5a4c7d 100644
@@ -41,6 +41,13 @@
    */
   #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
+ */

drivers/tee/optee/core.c +2 -0
+#define PTA_CMD_GET_DEVICES_RPMB    0x2
+
   typedef void (optee_invoke_fn)(unsigned long, unsigned long,

unsigned long,
                     unsigned long, unsigned long, unsigned long, unsigned long, unsigned long,

drivers/tee/optee/core.c +0 -0
@@ -210,6 +217,29 @@ static int bind_service_drivers(struct udevice *dev)
       return ret2;
Quoted 9 lines

drivers/tee/optee/core.c static int bind_service_drivers(struct udevice *dev) · line 221

Quoted 3 lines
drivers/tee/optee/core.c +1 -0
   }
   +#ifdef CONFIG_SUPPORT_EMMC_RPMB
+void optee_bind_service_drivers_rpmb(struct udevice *dev)

This function is only compiled when SUPPORT_EMMC_RPMB is set, but optee_probe() calls it unconditionally after a successful bind_service_drivers(). optee_private.h stubs other functions for the !RPMB case, this new prototype has no such stub, so for SUPPORT_EMMC_RPMB=n should fail to link.

Yeah, thanks for reminding - I forgot again that the linker won't resolve that. Will also refactor this to move the rpmb part into the rpmb module.

Quoted 7 lines
Quoted 7 lines
drivers/tee/optee/core.c +7 -0
+{
+    struct tee_shm *service_list = NULL;
+    size_t service_count;
+    u32 tee_sess;
+    int ret;
+
+    ret = open_enum_session(dev, &tee_sess);
Quoted 9 lines

drivers/tee/optee/core.c static int bind_service_drivers(struct udevice *dev) · line 235

Quoted 7 lines
drivers/tee/optee/core.c +7 -0
+    if (ret)
+        return;
+
+    ret = enum_services(dev, &service_list, &service_count, tee_sess,
+                PTA_CMD_GET_DEVICES_RPMB);
+    if (!ret && service_count)
+        ret = bind_service_list(dev, service_list, service_count);

A dev_dbg print would help here.

Quoted 2 lines

Of what exactly?

Sorry, that was unclear. I meant the early returns, not the successful bind.
open_enum_session() and enum_services() can fail and the function just returns. Patch 3 will retry this from mmc_init(), so a dev_dbg() on those failures would make that retry easier to follow.

Thanks,
Tanmay

author
#5 lore raw

Re: [PATCH 1/4] tee: optee: Add support for enumerating services that only need RPMB

Quoted 83 lines · Tanmay
Quoted 81 lines · Jan Kiszka
Quoted 51 lines · Tanmay

Hi Jan,

I am not an expert in TEE, but I went through this patch while reviewing the MMC side of the series and found a few issues.

Quoted 45 lines · Jan Kiszka

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          | 32 ++++++++++++++++++++++++++
+++++
   drivers/tee/optee/optee_private.h |  2 ++ drivers/tee/optee/rpmb.c          | 11 +++++++++++ include/tee/optee.h               |  2 ++

   4 files changed, 47 insertions(+)
drivers/tee/optee/core.c +0 -0
index 4d67c948ec1..5600d5a4c7d 100644
@@ -41,6 +41,13 @@
     */
    #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
+ */

drivers/tee/optee/core.c +2 -0
+#define PTA_CMD_GET_DEVICES_RPMB    0x2
+

   typedef void (optee_invoke_fn)(unsigned long, unsigned long, unsigned long,
                      unsigned long, unsigned long, unsigned long, unsigned long, unsigned long,

drivers/tee/optee/core.c +0 -0
@@ -210,6 +217,29 @@ static int bind_service_drivers(struct udevice
 *dev)
        return ret2;
Quoted 9 lines
Quoted 3 lines
drivers/tee/optee/core.c +0 -0
    }

   +#ifdef CONFIG_SUPPORT_EMMC_RPMB
+void optee_bind_service_drivers_rpmb(struct udevice *dev)

This function is only compiled when SUPPORT_EMMC_RPMB is set, but optee_probe() calls it unconditionally after a successful bind_service_drivers(). optee_private.h stubs other functions for the !RPMB case, this new prototype has no such stub, so for SUPPORT_EMMC_RPMB=n should fail to link.

Yeah, thanks for reminding - I forgot again that the linker won't resolve that. Will also refactor this to move the rpmb part into the rpmb module.

Quoted 16 lines
Quoted 4 lines
drivers/tee/optee/core.c +4 -0
+{
+    struct tee_shm *service_list = NULL;
+    size_t service_count;
+    u32 tee_sess;

drivers/tee/optee/core.c static int bind_service_drivers(struct udevice *dev) · line 235

Quoted 10 lines
drivers/tee/optee/core.c +10 -0
+    int ret;
+
+    ret = open_enum_session(dev, &tee_sess);
+    if (ret)
+        return;
+
+    ret = enum_services(dev, &service_list, &service_count, tee_sess,
+                PTA_CMD_GET_DEVICES_RPMB);
+    if (!ret && service_count)
+        ret = bind_service_list(dev, service_list, service_count);

A dev_dbg print would help here.

Quoted 9 lines
Quoted 2 lines

Of what exactly?

Sorry, that was unclear. I meant the early returns, not the successful bind.
open_enum_session() and enum_services() can fail and the function just returns. Patch 3 will retry this from mmc_init(), so a dev_dbg() on those failures would make that retry easier to follow.

That's what patch 2 is for. Other enumeration errors are printed unconditionally by __enum_services.

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center