diff mbox series

[v6,5/5] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware

Message ID 20240607093326.369090-6-arnaud.pouliquen@foss.st.com (mailing list archive)
State New, archived
Headers show
Series Introduction of a remoteproc tee to load signed firmware | expand

Commit Message

Arnaud Pouliquen June 7, 2024, 9:33 a.m. UTC
The new TEE remoteproc device is used to manage remote firmware in a
secure, trusted context. The 'st,stm32mp1-m4-tee' compatibility is
introduced to delegate the loading of the firmware to the trusted
execution context. In such cases, the firmware should be signed and
adhere to the image format defined by the TEE.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
---
Update from previous version
- replace find_loaded_rsc_table by  find_loaded_rsc_table ops.
---
 drivers/remoteproc/stm32_rproc.c | 63 ++++++++++++++++++++++++++++++--
 1 file changed, 60 insertions(+), 3 deletions(-)

Comments

kernel test robot June 8, 2024, 3:30 a.m. UTC | #1
Hi Arnaud,

kernel test robot noticed the following build errors:

[auto build test ERROR on 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0]

url:    https://github.com/intel-lab-lkp/linux/commits/Arnaud-Pouliquen/remoteproc-core-Introduce-rproc_pa_to_va-helper/20240607-183305
base:   1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0
patch link:    https://lore.kernel.org/r/20240607093326.369090-6-arnaud.pouliquen%40foss.st.com
patch subject: [PATCH v6 5/5] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware
config: i386-buildonly-randconfig-002-20240608 (https://download.01.org/0day-ci/archive/20240608/202406081159.KM501g5C-lkp@intel.com/config)
compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240608/202406081159.KM501g5C-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202406081159.KM501g5C-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from drivers/remoteproc/stm32_rproc.c:23:
>> include/linux/tee_remoteproc.h:94:2: error: expected parameter declarator
      94 |         WARN_ON(1);
         |         ^
   include/asm-generic/bug.h:122:29: note: expanded from macro 'WARN_ON'
     122 | #define WARN_ON(condition) ({                                           \
         |                             ^
   In file included from drivers/remoteproc/stm32_rproc.c:23:
>> include/linux/tee_remoteproc.h:94:2: error: expected ')'
   include/asm-generic/bug.h:122:29: note: expanded from macro 'WARN_ON'
     122 | #define WARN_ON(condition) ({                                           \
         |                             ^
   include/linux/tee_remoteproc.h:94:2: note: to match this '('
   include/asm-generic/bug.h:122:28: note: expanded from macro 'WARN_ON'
     122 | #define WARN_ON(condition) ({                                           \
         |                            ^
   In file included from drivers/remoteproc/stm32_rproc.c:23:
>> include/linux/tee_remoteproc.h:92:32: error: function cannot return function type 'struct resource_table *()'
      92 | tee_rproc_find_loaded_rsc_table(struct rproc *rproc, const struct firmware *fw)
         |                                ^
>> include/linux/tee_remoteproc.h:94:2: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes]
      94 |         WARN_ON(1);
         |         ^
   include/asm-generic/bug.h:122:28: note: expanded from macro 'WARN_ON'
     122 | #define WARN_ON(condition) ({                                           \
         |                            ^
   In file included from drivers/remoteproc/stm32_rproc.c:23:
>> include/linux/tee_remoteproc.h:96:2: error: expected identifier or '('
      96 |         return NULL;
         |         ^
>> include/linux/tee_remoteproc.h:97:1: error: extraneous closing brace ('}')
      97 | }
         | ^
   6 errors generated.


vim +94 include/linux/tee_remoteproc.h

5c0eb7b2737b6e Arnaud Pouliquen 2024-06-07  90  
5c0eb7b2737b6e Arnaud Pouliquen 2024-06-07  91  static inline struct resource_table *
5c0eb7b2737b6e Arnaud Pouliquen 2024-06-07 @92  tee_rproc_find_loaded_rsc_table(struct rproc *rproc, const struct firmware *fw)
5c0eb7b2737b6e Arnaud Pouliquen 2024-06-07  93  	/* This shouldn't be possible */
5c0eb7b2737b6e Arnaud Pouliquen 2024-06-07 @94  	WARN_ON(1);
5c0eb7b2737b6e Arnaud Pouliquen 2024-06-07  95  
5c0eb7b2737b6e Arnaud Pouliquen 2024-06-07 @96  	return NULL;
5c0eb7b2737b6e Arnaud Pouliquen 2024-06-07 @97  }
kernel test robot June 8, 2024, 4:45 a.m. UTC | #2
Hi Arnaud,

kernel test robot noticed the following build errors:

[auto build test ERROR on 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0]

url:    https://github.com/intel-lab-lkp/linux/commits/Arnaud-Pouliquen/remoteproc-core-Introduce-rproc_pa_to_va-helper/20240607-183305
base:   1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0
patch link:    https://lore.kernel.org/r/20240607093326.369090-6-arnaud.pouliquen%40foss.st.com
patch subject: [PATCH v6 5/5] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware
config: s390-allyesconfig (https://download.01.org/0day-ci/archive/20240608/202406081214.qFAil90A-lkp@intel.com/config)
compiler: s390-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240608/202406081214.qFAil90A-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202406081214.qFAil90A-lkp@intel.com/

All errors (new ones prefixed by >>):

   In file included from include/linux/bug.h:5,
                    from include/linux/fortify-string.h:6,
                    from include/linux/string.h:374,
                    from include/linux/dma-mapping.h:7,
                    from drivers/remoteproc/stm32_rproc.c:9:
>> arch/s390/include/asm/bug.h:53:21: error: expected declaration specifiers or '...' before '{' token
      53 | #define WARN_ON(x) ({                                   \
         |                     ^
   include/linux/tee_remoteproc.h:94:9: note: in expansion of macro 'WARN_ON'
      94 |         WARN_ON(1);
         |         ^~~~~~~
   In file included from drivers/remoteproc/stm32_rproc.c:23:
   include/linux/tee_remoteproc.h:96:9: error: expected identifier or '(' before 'return'
      96 |         return NULL;
         |         ^~~~~~
   include/linux/tee_remoteproc.h:97:1: error: expected identifier or '(' before '}' token
      97 | }
         | ^
   drivers/remoteproc/stm32_rproc.c:717:34: error: 'tee_rproc_find_loaded_rsc_table' undeclared here (not in a function); did you mean 'rproc_find_loaded_rsc_table'?
     717 |         .find_loaded_rsc_table = tee_rproc_find_loaded_rsc_table,
         |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                                  rproc_find_loaded_rsc_table


vim +53 arch/s390/include/asm/bug.h

a9df8e325d0de5 arch/s390/include/asm/bug.h Heiko Carstens 2010-01-13  52  
c0007f1a65762e include/asm-s390/bug.h      Heiko Carstens 2007-04-27 @53  #define WARN_ON(x) ({					\
fd0cbdd378258f include/asm-s390/bug.h      Heiko Carstens 2007-08-02  54  	int __ret_warn_on = !!(x);			\
c0007f1a65762e include/asm-s390/bug.h      Heiko Carstens 2007-04-27  55  	if (__builtin_constant_p(__ret_warn_on)) {	\
c0007f1a65762e include/asm-s390/bug.h      Heiko Carstens 2007-04-27  56  		if (__ret_warn_on)			\
b2be05273a1744 arch/s390/include/asm/bug.h Ben Hutchings  2010-04-03  57  			__WARN();			\
c0007f1a65762e include/asm-s390/bug.h      Heiko Carstens 2007-04-27  58  	} else {					\
c0007f1a65762e include/asm-s390/bug.h      Heiko Carstens 2007-04-27  59  		if (unlikely(__ret_warn_on))		\
b2be05273a1744 arch/s390/include/asm/bug.h Ben Hutchings  2010-04-03  60  			__WARN();			\
c0007f1a65762e include/asm-s390/bug.h      Heiko Carstens 2007-04-27  61  	}						\
c0007f1a65762e include/asm-s390/bug.h      Heiko Carstens 2007-04-27  62  	unlikely(__ret_warn_on);			\
c0007f1a65762e include/asm-s390/bug.h      Heiko Carstens 2007-04-27  63  })
c0007f1a65762e include/asm-s390/bug.h      Heiko Carstens 2007-04-27  64
diff mbox series

Patch

diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c
index 8cd838df4e92..c1262e1ccc96 100644
--- a/drivers/remoteproc/stm32_rproc.c
+++ b/drivers/remoteproc/stm32_rproc.c
@@ -20,6 +20,7 @@ 
 #include <linux/remoteproc.h>
 #include <linux/reset.h>
 #include <linux/slab.h>
+#include <linux/tee_remoteproc.h>
 #include <linux/workqueue.h>
 
 #include "remoteproc_internal.h"
@@ -257,6 +258,19 @@  static int stm32_rproc_release(struct rproc *rproc)
 	return 0;
 }
 
+static int stm32_rproc_tee_stop(struct rproc *rproc)
+{
+	int err;
+
+	stm32_rproc_request_shutdown(rproc);
+
+	err = tee_rproc_stop(rproc);
+	if (err)
+		return err;
+
+	return stm32_rproc_release(rproc);
+}
+
 static int stm32_rproc_prepare(struct rproc *rproc)
 {
 	struct device *dev = rproc->dev.parent;
@@ -693,8 +707,20 @@  static const struct rproc_ops st_rproc_ops = {
 	.get_boot_addr	= rproc_elf_get_boot_addr,
 };
 
+static const struct rproc_ops st_rproc_tee_ops = {
+	.prepare	= stm32_rproc_prepare,
+	.start		= tee_rproc_start,
+	.stop		= stm32_rproc_tee_stop,
+	.kick		= stm32_rproc_kick,
+	.load		= tee_rproc_load_fw,
+	.parse_fw	= tee_rproc_parse_fw,
+	.find_loaded_rsc_table = tee_rproc_find_loaded_rsc_table,
+
+};
+
 static const struct of_device_id stm32_rproc_match[] = {
 	{ .compatible = "st,stm32mp1-m4" },
+	{ .compatible = "st,stm32mp1-m4-tee" },
 	{},
 };
 MODULE_DEVICE_TABLE(of, stm32_rproc_match);
@@ -853,17 +879,42 @@  static int stm32_rproc_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct stm32_rproc *ddata;
 	struct device_node *np = dev->of_node;
+	struct tee_rproc *trproc = NULL;
 	struct rproc *rproc;
 	unsigned int state;
+	u32 proc_id;
 	int ret;
 
 	ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
 	if (ret)
 		return ret;
 
-	rproc = devm_rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata));
-	if (!rproc)
-		return -ENOMEM;
+	if (of_device_is_compatible(np, "st,stm32mp1-m4-tee")) {
+		/*
+		 * Delegate the firmware management to the secure context.
+		 * The firmware loaded has to be signed.
+		 */
+		ret = of_property_read_u32(np, "st,proc-id", &proc_id);
+		if (ret) {
+			dev_err(dev, "failed to read st,rproc-id property\n");
+			return ret;
+		}
+
+		rproc = devm_rproc_alloc(dev, np->name, &st_rproc_tee_ops, NULL, sizeof(*ddata));
+		if (!rproc)
+			return -ENOMEM;
+
+		trproc = tee_rproc_register(dev, rproc, proc_id);
+		if (IS_ERR(trproc)) {
+			dev_err_probe(dev, PTR_ERR(trproc),
+				      "signed firmware not supported by TEE\n");
+			return PTR_ERR(trproc);
+		}
+	} else {
+		rproc = devm_rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata));
+		if (!rproc)
+			return -ENOMEM;
+	}
 
 	ddata = rproc->priv;
 
@@ -915,6 +966,9 @@  static int stm32_rproc_probe(struct platform_device *pdev)
 		dev_pm_clear_wake_irq(dev);
 		device_init_wakeup(dev, false);
 	}
+	if (trproc)
+		tee_rproc_unregister(trproc);
+
 	return ret;
 }
 
@@ -935,6 +989,9 @@  static void stm32_rproc_remove(struct platform_device *pdev)
 		dev_pm_clear_wake_irq(dev);
 		device_init_wakeup(dev, false);
 	}
+	if (rproc->tee_interface)
+		tee_rproc_unregister(rproc->tee_interface);
+
 }
 
 static int stm32_rproc_suspend(struct device *dev)