2024-01-15 13:54:29

by Arnaud Pouliquen

[permalink] [raw]
Subject: [PATCH 0/4] Introduction of a remoteproc tee to load signed firmware

This series proposes the implementation of a remoteproc tee driver to
communicate with a TEE trusted application responsible for authenticating and
loading the remoteproc firmware image in an Arm secure context.

1) Principle:

The remoteproc tee driver provides services to communicate with the OP-TEE
trusted application running on the Trusted Execution Context (TEE).
The trusted application in TEE manages the remote processor lifecycle:

- authenticating and loading firmware images,
- isolating and securing the remote processor memories,
- supporting multi-firmware (e.g., TF-M + Zephyr on a Cortex-M33),
- managing the start and stop of the firmware by the TEE.

2) Format of the signed image:

Refer to:
https://github.com/OP-TEE/optee_os/blob/master/ta/remoteproc/src/remoteproc_core.c#L18-L57

3) OP-TEE trusted application API:

Refer to:
https://github.com/OP-TEE/optee_os/blob/master/ta/remoteproc/include/ta_remoteproc.h

4) OP-TEE signature script

Refer to:
https://github.com/OP-TEE/optee_os/blob/master/scripts/sign_rproc_fw.py

Example of usage:
sign_rproc_fw.py --in <fw1.elf> --in <fw2.elf> --out <signed_fw.sign> --key ${OP-TEE_PATH}/keys/default.pem


5) Impact on User space Application

No sysfs impact.the user only needs to provide the signed firmware image
instead of the ELF image.


For more information about the implementation, a presentation is available here
(note that the format of the signed image has evolved between the presentation
and the integration in OP-TEE).

https://resources.linaro.org/en/resource/6c5bGvZwUAjX56fvxthxds


Arnaud Pouliquen (4):
remoteproc: Add TEE support
dt-bindings: remoteproc: add compatibility for TEE support
remoteproc: stm32: create sub-functions to request shutdown and
release
remoteproc: stm32: Add support of an OP-TEE TA to load the firmware

.../bindings/remoteproc/st,stm32-rproc.yaml | 53 ++-
drivers/remoteproc/Kconfig | 10 +
drivers/remoteproc/Makefile | 1 +
drivers/remoteproc/stm32_rproc.c | 233 +++++++++--
drivers/remoteproc/tee_remoteproc.c | 393 ++++++++++++++++++
include/linux/tee_remoteproc.h | 99 +++++
6 files changed, 742 insertions(+), 47 deletions(-)
create mode 100644 drivers/remoteproc/tee_remoteproc.c
create mode 100644 include/linux/tee_remoteproc.h

--
2.25.1



2024-01-15 13:54:43

by Arnaud Pouliquen

[permalink] [raw]
Subject: [PATCH 2/4] dt-bindings: remoteproc: add compatibility for TEE support

The "st,stm32mp1-m4-tee" compatible is utilized in a system configuration
where the Cortex-M4 firmware is loaded by the Trusted execution Environment
(TEE).
This compatible is used in both the Linux and OP-TEE device-tree.
- In OP-TEE, a node is defined in the device tree with the
st,stm32mp1-m4-tee to support signed remoteproc firmware.
Based on DT properties, OP-TEE authenticates, loads, starts, and stops
the firmware.
- On Linux, when the compatibility is set, the Cortex-M resets should not
be declared in the device tree.

Signed-off-by: Arnaud Pouliquen <[email protected]>
---
.../bindings/remoteproc/st,stm32-rproc.yaml | 53 +++++++++++++++----
1 file changed, 44 insertions(+), 9 deletions(-)

diff --git a/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml b/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml
index 370af61d8f28..9fdfa30eff20 100644
--- a/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml
+++ b/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml
@@ -16,7 +16,12 @@ maintainers:

properties:
compatible:
- const: st,stm32mp1-m4
+ enum:
+ - st,stm32mp1-m4
+ - st,stm32mp1-m4-tee
+ description:
+ Use "st,stm32mp1-m4" for the Cortex-M4 coprocessor management by Linux
+ Use "st,stm32mp1-m4-tee" for the Cortex-M4 coprocessor management by secure context

reg:
description:
@@ -142,21 +147,41 @@ properties:
required:
- compatible
- reg
- - resets

allOf:
- if:
properties:
- reset-names:
- not:
- contains:
- const: hold_boot
+ compatible:
+ contains:
+ const: st,stm32mp1-m4
+ then:
+ if:
+ properties:
+ reset-names:
+ not:
+ contains:
+ const: hold_boot
+ then:
+ required:
+ - st,syscfg-holdboot
+ - resets
+ else:
+ properties:
+ st,syscfg-holdboot: false
+ required:
+ - reset-names
+ - resets
+
+ - if:
+ properties:
+ compatible:
+ contains:
+ const: st,stm32mp1-m4-tee
then:
- required:
- - st,syscfg-holdboot
- else:
properties:
st,syscfg-holdboot: false
+ reset-names: false
+ resets: false

additionalProperties: false

@@ -188,5 +213,15 @@ examples:
st,syscfg-rsc-tbl = <&tamp 0x144 0xFFFFFFFF>;
st,syscfg-m4-state = <&tamp 0x148 0xFFFFFFFF>;
};
+ - |
+ #include <dt-bindings/reset/stm32mp1-resets.h>
+ m4@10000000 {
+ compatible = "st,stm32mp1-m4-tee";
+ reg = <0x10000000 0x40000>,
+ <0x30000000 0x40000>,
+ <0x38000000 0x10000>;
+ st,syscfg-rsc-tbl = <&tamp 0x144 0xFFFFFFFF>;
+ st,syscfg-m4-state = <&tamp 0x148 0xFFFFFFFF>;
+ };

...
--
2.25.1


2024-01-15 13:54:45

by Arnaud Pouliquen

[permalink] [raw]
Subject: [PATCH 4/4] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware

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 <[email protected]>
---
drivers/remoteproc/Kconfig | 3 +-
drivers/remoteproc/stm32_rproc.c | 149 +++++++++++++++++++++++++++++--
2 files changed, 146 insertions(+), 6 deletions(-)

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 85299606806c..e5bb675b5fc5 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -316,6 +316,7 @@ config STM32_RPROC
depends on ARCH_STM32 || COMPILE_TEST
depends on REMOTEPROC
select MAILBOX
+ select TEE_REMOTEPROC
help
Say y here to support STM32 MCU processors via the
remote processor framework.
@@ -367,7 +368,7 @@ config XLNX_R5_REMOTEPROC


config TEE_REMOTEPROC
- tristate "trusted firmware support by a TEE application"
+ tristate "trusted firmware support by a trusted application"
depends on OPTEE
help
Support for trusted remote processors firmware. The firmware
diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c
index fcc0001e2657..16dcf36ceeb6 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"
@@ -49,6 +50,9 @@
#define M4_STATE_STANDBY 4
#define M4_STATE_CRASH 5

+/* Remote processor unique identifier aligned with the Trusted Execution Environment definitions */
+#define STM32_MP1_M4_PROC_ID 0
+
struct stm32_syscon {
struct regmap *map;
u32 reg;
@@ -90,6 +94,8 @@ struct stm32_rproc {
struct stm32_mbox mb[MBOX_NB_MBX];
struct workqueue_struct *workqueue;
bool hold_boot_smc;
+ bool fw_loaded;
+ struct tee_rproc *trproc;
void __iomem *rsc_va;
};

@@ -257,6 +263,91 @@ static int stm32_rproc_release(struct rproc *rproc)
return err;
}

+static int stm32_rproc_tee_elf_sanity_check(struct rproc *rproc,
+ const struct firmware *fw)
+{
+ struct stm32_rproc *ddata = rproc->priv;
+ unsigned int ret = 0;
+
+ if (rproc->state == RPROC_DETACHED)
+ return 0;
+
+ ret = tee_rproc_load_fw(ddata->trproc, fw);
+ if (!ret)
+ ddata->fw_loaded = true;
+
+ return ret;
+}
+
+static int stm32_rproc_tee_elf_load(struct rproc *rproc,
+ const struct firmware *fw)
+{
+ struct stm32_rproc *ddata = rproc->priv;
+ unsigned int ret;
+
+ /*
+ * This function can be called by remote proc for recovery
+ * without the sanity check. In this case we need to load the firmware
+ * else nothing done here as the firmware has been preloaded for the
+ * sanity check to be able to parse it for the resource table.
+ */
+ if (ddata->fw_loaded)
+ return 0;
+
+ ret = tee_rproc_load_fw(ddata->trproc, fw);
+ if (ret)
+ return ret;
+ ddata->fw_loaded = true;
+
+ /* Update the resource table parameters. */
+ if (rproc_tee_get_rsc_table(ddata->trproc)) {
+ /* No resource table: reset the related fields. */
+ rproc->cached_table = NULL;
+ rproc->table_ptr = NULL;
+ rproc->table_sz = 0;
+ }
+
+ return 0;
+}
+
+static struct resource_table *
+stm32_rproc_tee_elf_find_loaded_rsc_table(struct rproc *rproc,
+ const struct firmware *fw)
+{
+ struct stm32_rproc *ddata = rproc->priv;
+
+ return tee_rproc_get_loaded_rsc_table(ddata->trproc);
+}
+
+static int stm32_rproc_tee_start(struct rproc *rproc)
+{
+ struct stm32_rproc *ddata = rproc->priv;
+
+ return tee_rproc_start(ddata->trproc);
+}
+
+static int stm32_rproc_tee_attach(struct rproc *rproc)
+{
+ /* Nothing to do, remote proc already started by the secured context. */
+ return 0;
+}
+
+static int stm32_rproc_tee_stop(struct rproc *rproc)
+{
+ struct stm32_rproc *ddata = rproc->priv;
+ int err;
+
+ stm32_rproc_request_shutdown(rproc);
+
+ err = tee_rproc_stop(ddata->trproc);
+ if (err)
+ return err;
+
+ ddata->fw_loaded = false;
+
+ return stm32_rproc_release(rproc);
+}
+
static int stm32_rproc_prepare(struct rproc *rproc)
{
struct device *dev = rproc->dev.parent;
@@ -319,7 +410,14 @@ static int stm32_rproc_prepare(struct rproc *rproc)

static int stm32_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
{
- if (rproc_elf_load_rsc_table(rproc, fw))
+ struct stm32_rproc *ddata = rproc->priv;
+ int ret;
+
+ if (ddata->trproc)
+ ret = rproc_tee_get_rsc_table(ddata->trproc);
+ else
+ ret = rproc_elf_load_rsc_table(rproc, fw);
+ if (ret)
dev_warn(&rproc->dev, "no resource table found for this firmware\n");

return 0;
@@ -693,8 +791,22 @@ 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 = stm32_rproc_tee_start,
+ .stop = stm32_rproc_tee_stop,
+ .attach = stm32_rproc_tee_attach,
+ .kick = stm32_rproc_kick,
+ .parse_fw = stm32_rproc_parse_fw,
+ .find_loaded_rsc_table = stm32_rproc_tee_elf_find_loaded_rsc_table,
+ .get_loaded_rsc_table = stm32_rproc_get_loaded_rsc_table,
+ .sanity_check = stm32_rproc_tee_elf_sanity_check,
+ .load = stm32_rproc_tee_elf_load,
+};
+
static const struct of_device_id stm32_rproc_match[] = {
- { .compatible = "st,stm32mp1-m4" },
+ {.compatible = "st,stm32mp1-m4",},
+ {.compatible = "st,stm32mp1-m4-tee",},
{},
};
MODULE_DEVICE_TABLE(of, stm32_rproc_match);
@@ -853,6 +965,7 @@ 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;
struct rproc *rproc;
unsigned int state;
int ret;
@@ -861,11 +974,31 @@ static int stm32_rproc_probe(struct platform_device *pdev)
if (ret)
return ret;

- rproc = 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")) {
+ trproc = tee_rproc_register(dev, STM32_MP1_M4_PROC_ID);
+ if (IS_ERR(trproc)) {
+ dev_err_probe(dev, PTR_ERR(trproc),
+ "signed firmware not supported by TEE\n");
+ return PTR_ERR(trproc);
+ }
+ /*
+ * Delegate the firmware management to the secure context.
+ * The firmware loaded has to be signed.
+ */
+ dev_info(dev, "Support of signed firmware only\n");
+ }
+ rproc = rproc_alloc(dev, np->name,
+ trproc ? &st_rproc_tee_ops : &st_rproc_ops,
+ NULL, sizeof(*ddata));
+ if (!rproc) {
+ ret = -ENOMEM;
+ goto free_tee;
+ }

ddata = rproc->priv;
+ ddata->trproc = trproc;
+ if (trproc)
+ trproc->rproc = rproc;

rproc_coredump_set_elf_info(rproc, ELFCLASS32, EM_NONE);

@@ -916,6 +1049,10 @@ static int stm32_rproc_probe(struct platform_device *pdev)
device_init_wakeup(dev, false);
}
rproc_free(rproc);
+free_tee:
+ if (trproc)
+ tee_rproc_unregister(trproc);
+
return ret;
}

@@ -937,6 +1074,8 @@ static void stm32_rproc_remove(struct platform_device *pdev)
device_init_wakeup(dev, false);
}
rproc_free(rproc);
+ if (ddata->trproc)
+ tee_rproc_unregister(ddata->trproc);
}

static int stm32_rproc_suspend(struct device *dev)
--
2.25.1


2024-01-15 13:55:01

by Arnaud Pouliquen

[permalink] [raw]
Subject: [PATCH 3/4] remoteproc: stm32: create sub-functions to request shutdown and release

To prepare for the support of TEE remoteproc, create sub-functions
that can be used in both cases, with and without TEE support.

Signed-off-by: Arnaud Pouliquen <[email protected]>
---
drivers/remoteproc/stm32_rproc.c | 84 +++++++++++++++++++-------------
1 file changed, 51 insertions(+), 33 deletions(-)

diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c
index 4f469f0bcf8b..fcc0001e2657 100644
--- a/drivers/remoteproc/stm32_rproc.c
+++ b/drivers/remoteproc/stm32_rproc.c
@@ -209,6 +209,54 @@ static int stm32_rproc_mbox_idx(struct rproc *rproc, const unsigned char *name)
return -EINVAL;
}

+static void stm32_rproc_request_shutdown(struct rproc *rproc)
+{
+ struct stm32_rproc *ddata = rproc->priv;
+ int err, dummy_data, idx;
+
+ /* Request shutdown of the remote processor */
+ if (rproc->state != RPROC_OFFLINE && rproc->state != RPROC_CRASHED) {
+ idx = stm32_rproc_mbox_idx(rproc, STM32_MBX_SHUTDOWN);
+ if (idx >= 0 && ddata->mb[idx].chan) {
+ /* A dummy data is sent to allow to block on transmit. */
+ err = mbox_send_message(ddata->mb[idx].chan,
+ &dummy_data);
+ if (err < 0)
+ dev_warn(&rproc->dev, "warning: remote FW shutdown without ack\n");
+ }
+ }
+}
+
+static int stm32_rproc_release(struct rproc *rproc)
+{
+ struct stm32_rproc *ddata = rproc->priv;
+ unsigned int err = 0;
+
+ /* To allow platform Standby power mode, set remote proc Deep Sleep. */
+ if (ddata->pdds.map) {
+ err = regmap_update_bits(ddata->pdds.map, ddata->pdds.reg,
+ ddata->pdds.mask, 1);
+ if (err) {
+ dev_err(&rproc->dev, "failed to set pdds\n");
+ return err;
+ }
+ }
+
+ /* Update coprocessor state to OFF if available. */
+ if (ddata->m4_state.map) {
+ err = regmap_update_bits(ddata->m4_state.map,
+ ddata->m4_state.reg,
+ ddata->m4_state.mask,
+ M4_STATE_OFF);
+ if (err) {
+ dev_err(&rproc->dev, "failed to set copro state\n");
+ return err;
+ }
+ }
+
+ return err;
+}
+
static int stm32_rproc_prepare(struct rproc *rproc)
{
struct device *dev = rproc->dev.parent;
@@ -519,17 +567,9 @@ static int stm32_rproc_detach(struct rproc *rproc)
static int stm32_rproc_stop(struct rproc *rproc)
{
struct stm32_rproc *ddata = rproc->priv;
- int err, idx;
+ int err;

- /* request shutdown of the remote processor */
- if (rproc->state != RPROC_OFFLINE && rproc->state != RPROC_CRASHED) {
- idx = stm32_rproc_mbox_idx(rproc, STM32_MBX_SHUTDOWN);
- if (idx >= 0 && ddata->mb[idx].chan) {
- err = mbox_send_message(ddata->mb[idx].chan, "detach");
- if (err < 0)
- dev_warn(&rproc->dev, "warning: remote FW shutdown without ack\n");
- }
- }
+ stm32_rproc_request_shutdown(rproc);

err = stm32_rproc_set_hold_boot(rproc, true);
if (err)
@@ -541,29 +581,7 @@ static int stm32_rproc_stop(struct rproc *rproc)
return err;
}

- /* to allow platform Standby power mode, set remote proc Deep Sleep */
- if (ddata->pdds.map) {
- err = regmap_update_bits(ddata->pdds.map, ddata->pdds.reg,
- ddata->pdds.mask, 1);
- if (err) {
- dev_err(&rproc->dev, "failed to set pdds\n");
- return err;
- }
- }
-
- /* update coprocessor state to OFF if available */
- if (ddata->m4_state.map) {
- err = regmap_update_bits(ddata->m4_state.map,
- ddata->m4_state.reg,
- ddata->m4_state.mask,
- M4_STATE_OFF);
- if (err) {
- dev_err(&rproc->dev, "failed to set copro state\n");
- return err;
- }
- }
-
- return 0;
+ return stm32_rproc_release(rproc);
}

static void stm32_rproc_kick(struct rproc *rproc, int vqid)
--
2.25.1


2024-01-15 13:55:05

by Arnaud Pouliquen

[permalink] [raw]
Subject: [PATCH 1/4] remoteproc: Add TEE support

From: Arnaud Pouliquen <[email protected]>

Add a remoteproc TEE (Trusted Execution Environment) device
that will be probed by the TEE bus. If the associated Trusted
application is supported on secure part this device offers a client
interface to load a firmware in the secure part.
This firmware could be authenticated and decrypted by the secure
trusted application.

Signed-off-by: Arnaud Pouliquen <[email protected]>
---
drivers/remoteproc/Kconfig | 9 +
drivers/remoteproc/Makefile | 1 +
drivers/remoteproc/tee_remoteproc.c | 393 ++++++++++++++++++++++++++++
include/linux/tee_remoteproc.h | 99 +++++++
4 files changed, 502 insertions(+)
create mode 100644 drivers/remoteproc/tee_remoteproc.c
create mode 100644 include/linux/tee_remoteproc.h

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 48845dc8fa85..85299606806c 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -365,6 +365,15 @@ config XLNX_R5_REMOTEPROC

It's safe to say N if not interested in using RPU r5f cores.

+
+config TEE_REMOTEPROC
+ tristate "trusted firmware support by a TEE application"
+ depends on OPTEE
+ help
+ Support for trusted remote processors firmware. The firmware
+ authentication and/or decryption are managed by a trusted application.
+ This can be either built-in or a loadable module.
+
endif # REMOTEPROC

endmenu
diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile
index 91314a9b43ce..fa8daebce277 100644
--- a/drivers/remoteproc/Makefile
+++ b/drivers/remoteproc/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_RCAR_REMOTEPROC) += rcar_rproc.o
obj-$(CONFIG_ST_REMOTEPROC) += st_remoteproc.o
obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o
obj-$(CONFIG_STM32_RPROC) += stm32_rproc.o
+obj-$(CONFIG_TEE_REMOTEPROC) += tee_remoteproc.o
obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o
obj-$(CONFIG_TI_K3_R5_REMOTEPROC) += ti_k3_r5_remoteproc.o
obj-$(CONFIG_XLNX_R5_REMOTEPROC) += xlnx_r5_remoteproc.o
diff --git a/drivers/remoteproc/tee_remoteproc.c b/drivers/remoteproc/tee_remoteproc.c
new file mode 100644
index 000000000000..d089087eb1f6
--- /dev/null
+++ b/drivers/remoteproc/tee_remoteproc.c
@@ -0,0 +1,393 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) STMicroelectronics 2023 - All Rights Reserved
+ * Author: Arnaud Pouliquen <[email protected]>
+ */
+
+#include <linux/firmware.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+#include <linux/of_reserved_mem.h>
+#include <linux/remoteproc.h>
+#include <linux/slab.h>
+#include <linux/tee_drv.h>
+#include <linux/tee_remoteproc.h>
+
+#include "remoteproc_internal.h"
+
+#define MAX_TEE_PARAM_ARRY_MEMBER 4
+
+/*
+ * Authentication of the firmware and load in the remote processor memory
+ *
+ * [in] params[0].value.a: unique 32bit identifier of the remote processor
+ * [in] params[1].memref: buffer containing the image of the buffer
+ */
+#define TA_RPROC_FW_CMD_LOAD_FW 1
+
+/*
+ * Start the remote processor
+ *
+ * [in] params[0].value.a: unique 32bit identifier of the remote processor
+ */
+#define TA_RPROC_FW_CMD_START_FW 2
+
+/*
+ * Stop the remote processor
+ *
+ * [in] params[0].value.a: unique 32bit identifier of the remote processor
+ */
+#define TA_RPROC_FW_CMD_STOP_FW 3
+
+/*
+ * Return the address of the resource table, or 0 if not found
+ * No check is done to verify that the address returned is accessible by
+ * the non secure context. If the resource table is loaded in a protected
+ * memory the access by the non secure context will lead to a data abort.
+ *
+ * [in] params[0].value.a: unique 32bit identifier of the remote processor
+ * [out] params[1].value.a: 32bit LSB resource table memory address
+ * [out] params[1].value.b: 32bit MSB resource table memory address
+ * [out] params[2].value.a: 32bit LSB resource table memory size
+ * [out] params[2].value.b: 32bit MSB resource table memory size
+ */
+#define TA_RPROC_FW_CMD_GET_RSC_TABLE 4
+
+/*
+ * Return the address of the core dump
+ *
+ * [in] params[0].value.a: unique 32bit identifier of the remote processor
+ * [out] params[1].memref: address of the core dump image if exist,
+ * else return Null
+ */
+#define TA_RPROC_FW_CMD_GET_COREDUMP 5
+
+struct tee_rproc_mem {
+ char name[20];
+ void __iomem *cpu_addr;
+ phys_addr_t bus_addr;
+ u32 dev_addr;
+ size_t size;
+};
+
+struct tee_rproc_context {
+ struct list_head sessions;
+ struct tee_context *tee_ctx;
+ struct device *dev;
+};
+
+struct tee_rproc_context *tee_rproc_ctx;
+
+static void prepare_args(struct tee_rproc *trproc, int cmd, struct tee_ioctl_invoke_arg *arg,
+ struct tee_param *param, unsigned int num_params)
+{
+ memset(arg, 0, sizeof(*arg));
+ memset(param, 0, MAX_TEE_PARAM_ARRY_MEMBER * sizeof(*param));
+
+ arg->func = cmd;
+ arg->session = trproc->session_id;
+ arg->num_params = num_params + 1;
+
+ param[0] = (struct tee_param) {
+ .attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
+ .u.value.a = trproc->rproc_id,
+ };
+}
+
+int tee_rproc_load_fw(struct tee_rproc *trproc, const struct firmware *fw)
+{
+ struct tee_ioctl_invoke_arg arg;
+ struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER];
+ struct tee_shm *fw_shm;
+ int ret;
+
+ fw_shm = tee_shm_register_kernel_buf(tee_rproc_ctx->tee_ctx, (void *)fw->data, fw->size);
+ if (IS_ERR(fw_shm))
+ return PTR_ERR(fw_shm);
+
+ prepare_args(trproc, TA_RPROC_FW_CMD_LOAD_FW, &arg, param, 1);
+
+ /* Provide the address of the firmware image */
+ param[1] = (struct tee_param) {
+ .attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT,
+ .u.memref = {
+ .shm = fw_shm,
+ .size = fw->size,
+ .shm_offs = 0,
+ },
+ };
+
+ ret = tee_client_invoke_func(tee_rproc_ctx->tee_ctx, &arg, param);
+ if (ret < 0 || arg.ret != 0) {
+ dev_err(tee_rproc_ctx->dev,
+ "TA_RPROC_FW_CMD_LOAD_FW invoke failed TEE err: %x, ret:%x\n",
+ arg.ret, ret);
+ if (!ret)
+ ret = -EIO;
+ }
+
+ tee_shm_free(fw_shm);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(tee_rproc_load_fw);
+
+int rproc_tee_get_rsc_table(struct tee_rproc *trproc)
+{
+ struct tee_ioctl_invoke_arg arg;
+ struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER];
+ struct rproc *rproc = trproc->rproc;
+ size_t rsc_size;
+ int ret;
+
+ prepare_args(trproc, TA_RPROC_FW_CMD_GET_RSC_TABLE, &arg, param, 2);
+
+ param[1].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT;
+ param[2].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT;
+
+ ret = tee_client_invoke_func(tee_rproc_ctx->tee_ctx, &arg, param);
+ if (ret < 0 || arg.ret != 0) {
+ dev_err(tee_rproc_ctx->dev,
+ "TA_RPROC_FW_CMD_GET_RSC_TABLE invoke failed TEE err: %x, ret:%x\n",
+ arg.ret, ret);
+ return -EIO;
+ }
+
+ rsc_size = param[2].u.value.a;
+
+ /* If the size is null no resource table defined in the image */
+ if (!rsc_size)
+ return 0;
+
+ /* Store the resource table address that would be updated by the remote core . */
+ trproc->rsc_va = ioremap_wc(param[1].u.value.a, rsc_size);
+ if (IS_ERR_OR_NULL(trproc->rsc_va)) {
+ dev_err(tee_rproc_ctx->dev, "Unable to map memory region: %lld+%zx\n",
+ param[1].u.value.a, rsc_size);
+ trproc->rsc_va = NULL;
+ return -ENOMEM;
+ }
+
+ /*
+ * A cached table is requested as the physical address is not mapped yet
+ * but remoteproc needs to parse the table for resources.
+ */
+ rproc->cached_table = kmemdup(trproc->rsc_va, rsc_size, GFP_KERNEL);
+ if (!rproc->cached_table)
+ return -ENOMEM;
+
+ rproc->table_ptr = rproc->cached_table;
+ rproc->table_sz = rsc_size;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(rproc_tee_get_rsc_table);
+
+struct resource_table *tee_rproc_get_loaded_rsc_table(struct tee_rproc *trproc)
+{
+ return (struct resource_table *)trproc->rsc_va;
+}
+EXPORT_SYMBOL_GPL(tee_rproc_get_loaded_rsc_table);
+
+int tee_rproc_start(struct tee_rproc *trproc)
+{
+ struct tee_ioctl_invoke_arg arg;
+ struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER];
+ int ret;
+
+ prepare_args(trproc, TA_RPROC_FW_CMD_START_FW, &arg, param, 0);
+
+ ret = tee_client_invoke_func(tee_rproc_ctx->tee_ctx, &arg, param);
+ if (ret < 0 || arg.ret != 0) {
+ dev_err(tee_rproc_ctx->dev,
+ "TA_RPROC_FW_CMD_START_FW invoke failed TEE err: %x, ret:%x\n",
+ arg.ret, ret);
+ if (!ret)
+ ret = -EIO;
+ }
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(tee_rproc_start);
+
+int tee_rproc_stop(struct tee_rproc *trproc)
+{
+ struct tee_ioctl_invoke_arg arg;
+ struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER];
+ int ret;
+
+ prepare_args(trproc, TA_RPROC_FW_CMD_STOP_FW, &arg, param, 0);
+
+ ret = tee_client_invoke_func(tee_rproc_ctx->tee_ctx, &arg, param);
+ if (ret < 0 || arg.ret != 0) {
+ dev_err(tee_rproc_ctx->dev,
+ "TA_RPROC_FW_CMD_STOP_FW invoke failed TEE err: %x, ret:%x\n",
+ arg.ret, ret);
+ if (!ret)
+ ret = -EIO;
+ }
+ if (trproc->rsc_va)
+ iounmap(trproc->rsc_va);
+ trproc->rsc_va = NULL;
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(tee_rproc_stop);
+
+static const struct tee_client_device_id stm32_tee_rproc_id_table[] = {
+ {UUID_INIT(0x80a4c275, 0x0a47, 0x4905,
+ 0x82, 0x85, 0x14, 0x86, 0xa9, 0x77, 0x1a, 0x08)},
+ {}
+};
+
+struct tee_rproc *tee_rproc_register(struct device *dev, unsigned int rproc_id)
+{
+ struct tee_client_device *rproc_tee_device;
+ struct tee_ioctl_open_session_arg sess_arg;
+ struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER];
+ struct tee_rproc *trproc;
+ int ret;
+
+ /*
+ * The device is not probed by the TEE bus. We ignore the reason (bus could be not yet
+ * probed or service not available in the secure firmware)
+ * Assumption here is that the TEE bus is not probed.
+ */
+ if (!tee_rproc_ctx)
+ return ERR_PTR(-EPROBE_DEFER);
+
+ trproc = devm_kzalloc(dev, sizeof(*trproc), GFP_KERNEL);
+ if (!trproc)
+ return ERR_PTR(-ENOMEM);
+
+ rproc_tee_device = to_tee_client_device(tee_rproc_ctx->dev);
+ memset(&sess_arg, 0, sizeof(sess_arg));
+
+ /* Open session with rproc_tee load the OP-TEE Trusted Application */
+ memcpy(sess_arg.uuid, rproc_tee_device->id.uuid.b, TEE_IOCTL_UUID_LEN);
+
+ sess_arg.clnt_login = TEE_IOCTL_LOGIN_REE_KERNEL;
+ sess_arg.num_params = 1;
+
+ param[0] = (struct tee_param) {
+ .attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
+ .u.value.a = rproc_id,
+ };
+
+ ret = tee_client_open_session(tee_rproc_ctx->tee_ctx, &sess_arg, param);
+ if (ret < 0 || sess_arg.ret != 0) {
+ dev_err(dev, "tee_client_open_session failed, err: %x\n", sess_arg.ret);
+ return ERR_PTR(-EINVAL);
+ }
+
+ trproc->parent = dev;
+ trproc->rproc_id = rproc_id;
+ trproc->session_id = sess_arg.session;
+
+ list_add_tail(&trproc->node, &tee_rproc_ctx->sessions);
+
+ return trproc;
+}
+EXPORT_SYMBOL_GPL(tee_rproc_register);
+
+int tee_rproc_unregister(struct tee_rproc *trproc)
+{
+ int ret;
+
+ if (!tee_rproc_ctx)
+ return -ENODEV;
+
+ ret = tee_client_close_session(tee_rproc_ctx->tee_ctx, trproc->session_id);
+ if (ret < 0)
+ dev_err(trproc->parent, "tee_client_close_session failed, err: %x\n", ret);
+
+ list_del(&trproc->node);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(tee_rproc_unregister);
+
+static int tee_ctx_match(struct tee_ioctl_version_data *ver, const void *data)
+{
+ /* Today we support only the OP-TEE, could be extend to other tees */
+ return (ver->impl_id == TEE_IMPL_ID_OPTEE);
+}
+
+static int tee_rproc_probe(struct device *dev)
+{
+ struct tee_context *tee_ctx;
+ int ret;
+
+ /* Only one RPROC OP-TEE device allowed */
+ if (tee_rproc_ctx) {
+ dev_err(dev, "An RPROC OP-TEE device was already initialized: only one allowed\n");
+ return -EBUSY;
+ }
+
+ /* Open context with TEE driver */
+ tee_ctx = tee_client_open_context(NULL, tee_ctx_match, NULL, NULL);
+ if (IS_ERR(tee_ctx))
+ return PTR_ERR(tee_ctx);
+
+ tee_rproc_ctx = devm_kzalloc(dev, sizeof(*tee_ctx), GFP_KERNEL);
+ if (!tee_ctx) {
+ ret = -ENOMEM;
+ goto err;
+ }
+
+ tee_rproc_ctx->dev = dev;
+ tee_rproc_ctx->tee_ctx = tee_ctx;
+ INIT_LIST_HEAD(&tee_rproc_ctx->sessions);
+
+ return 0;
+err:
+ tee_client_close_context(tee_ctx);
+
+ return ret;
+}
+
+static int tee_rproc_remove(struct device *dev)
+{
+ struct tee_rproc *entry, *tmp;
+
+ list_for_each_entry_safe(entry, tmp, &tee_rproc_ctx->sessions, node) {
+ tee_client_close_session(tee_rproc_ctx->tee_ctx, entry->session_id);
+ list_del(&entry->node);
+ kfree(entry);
+ }
+
+ tee_client_close_context(tee_rproc_ctx->tee_ctx);
+
+ return 0;
+}
+
+MODULE_DEVICE_TABLE(tee, stm32_tee_rproc_id_table);
+
+static struct tee_client_driver tee_rproc_fw_driver = {
+ .id_table = stm32_tee_rproc_id_table,
+ .driver = {
+ .name = KBUILD_MODNAME,
+ .bus = &tee_bus_type,
+ .probe = tee_rproc_probe,
+ .remove = tee_rproc_remove,
+ },
+};
+
+static int __init tee_rproc_fw_mod_init(void)
+{
+ return driver_register(&tee_rproc_fw_driver.driver);
+}
+
+static void __exit tee_rproc_fw_mod_exit(void)
+{
+ driver_unregister(&tee_rproc_fw_driver.driver);
+}
+
+module_init(tee_rproc_fw_mod_init);
+module_exit(tee_rproc_fw_mod_exit);
+
+MODULE_DESCRIPTION(" TEE remote processor control driver");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/tee_remoteproc.h b/include/linux/tee_remoteproc.h
new file mode 100644
index 000000000000..0e11e5b8b524
--- /dev/null
+++ b/include/linux/tee_remoteproc.h
@@ -0,0 +1,99 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright(c) 2023 STMicroelectronics - All Rights Reserved
+ */
+
+#ifndef TEE_REMOTEPROC_H
+#define TEE_REMOTEPROC_H
+
+#include <linux/remoteproc.h>
+#include <linux/tee_drv.h>
+
+/**
+ * struct tee_rproc - TEE remoteproc structure
+ * @node: Reference in list
+ * @rproc: Remoteproc reference
+ * @parent: Parent device
+ * @rproc_id: Identifier of the target firmware
+ * @session_id: TEE session identifier
+ * @rsc_va: Resource table virtual address.
+ */
+struct tee_rproc {
+ struct list_head node;
+ struct rproc *rproc;
+ struct device *parent;
+ u32 rproc_id;
+ u32 session_id;
+ void *rsc_va;
+};
+
+#if IS_ENABLED(CONFIG_TEE_REMOTEPROC)
+
+struct tee_rproc *tee_rproc_register(struct device *dev, unsigned int rproc_id);
+int tee_rproc_unregister(struct tee_rproc *trproc);
+
+int tee_rproc_load_fw(struct tee_rproc *trproc, const struct firmware *fw);
+int rproc_tee_get_rsc_table(struct tee_rproc *trproc);
+struct resource_table *tee_rproc_get_loaded_rsc_table(struct tee_rproc *trproc);
+int tee_rproc_start(struct tee_rproc *trproc);
+int tee_rproc_stop(struct tee_rproc *trproc);
+
+#else
+
+static inline struct tee_rproc *tee_rproc_register(struct device *dev, unsigned int rproc_id)
+{
+ return ERR_PTR(-ENODEV);
+}
+
+static inline int tee_rproc_unregister(struct tee_rproc *trproc)
+{
+ /* This shouldn't be possible */
+ WARN_ON(1);
+
+ return 0;
+}
+
+static inline int tee_rproc_load_fw(struct tee_rproc *trproc,
+ const struct firmware *fw)
+{
+ /* This shouldn't be possible */
+ WARN_ON(1);
+
+ return 0;
+}
+
+static inline int tee_rproc_start(struct tee_rproc *trproc)
+{
+ /* This shouldn't be possible */
+ WARN_ON(1);
+
+ return 0;
+}
+
+static inline int tee_rproc_stop(struct tee_rproc *trproc)
+{
+ /* This shouldn't be possible */
+ WARN_ON(1);
+
+ return 0;
+}
+
+static inline int rproc_tee_get_rsc_table(struct tee_rproc *trproc)
+{
+ /* This shouldn't be possible */
+ WARN_ON(1);
+
+ return 0;
+}
+
+static inline struct resource_table *
+ tee_rproc_get_loaded_rsc_table(struct tee_rproc *trproc)
+{
+ /* This shouldn't be possible */
+ WARN_ON(1);
+
+ return NULL;
+}
+
+#endif /* CONFIG_TEE_REMOTEPROC */
+#endif /* TEE_REMOTEPROC_H */
--
2.25.1


2024-01-16 06:22:56

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 4/4] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware

Hi Arnaud,

kernel test robot noticed the following build warnings:

[auto build test WARNING on remoteproc/rproc-next]
[also build test WARNING on robh/for-next linus/master v6.7 next-20240112]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Arnaud-Pouliquen/remoteproc-Add-TEE-support/20240115-215613
base: git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc/linux.git rproc-next
patch link: https://lore.kernel.org/r/20240115135249.296822-5-arnaud.pouliquen%40foss.st.com
patch subject: [PATCH 4/4] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware
config: alpha-kismet-CONFIG_TEE_REMOTEPROC-CONFIG_STM32_RPROC-0-0 (https://download.01.org/0day-ci/archive/20240116/[email protected]/config)
reproduce: (https://download.01.org/0day-ci/archive/20240116/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

kismet warnings: (new ones prefixed by >>)
>> kismet: WARNING: unmet direct dependencies detected for TEE_REMOTEPROC when selected by STM32_RPROC

WARNING: unmet direct dependencies detected for TEE_REMOTEPROC
Depends on [n]: REMOTEPROC [=y] && OPTEE [=n]
Selected by [y]:
- STM32_RPROC [=y] && (ARCH_STM32 || COMPILE_TEST [=y]) && REMOTEPROC [=y]

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

2024-01-16 08:16:01

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 4/4] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware

Hi Arnaud,

kernel test robot noticed the following build warnings:

[auto build test WARNING on remoteproc/rproc-next]
[also build test WARNING on robh/for-next linus/master v6.7 next-20240112]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Arnaud-Pouliquen/remoteproc-Add-TEE-support/20240115-215613
base: git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc/linux.git rproc-next
patch link: https://lore.kernel.org/r/20240115135249.296822-5-arnaud.pouliquen%40foss.st.com
patch subject: [PATCH 4/4] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware
config: um-randconfig-r113-20240116 (https://download.01.org/0day-ci/archive/20240116/[email protected]/config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240116/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)
>> drivers/remoteproc/tee_remoteproc.c:82:26: sparse: sparse: symbol 'tee_rproc_ctx' was not declared. Should it be static?
>> drivers/remoteproc/tee_remoteproc.c:166:24: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected void *rsc_va @@ got void [noderef] __iomem * @@
drivers/remoteproc/tee_remoteproc.c:166:24: sparse: expected void *rsc_va
drivers/remoteproc/tee_remoteproc.c:166:24: sparse: got void [noderef] __iomem *
>> drivers/remoteproc/tee_remoteproc.c:233:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void volatile [noderef] __iomem *addr @@ got void *rsc_va @@
drivers/remoteproc/tee_remoteproc.c:233:31: sparse: expected void volatile [noderef] __iomem *addr
drivers/remoteproc/tee_remoteproc.c:233:31: sparse: got void *rsc_va
drivers/remoteproc/tee_remoteproc.c: note: in included file (through include/linux/preempt.h, include/linux/spinlock.h, include/linux/mmzone.h, ...):
include/linux/list.h:83:21: sparse: sparse: self-comparison always evaluates to true

vim +/tee_rproc_ctx +82 drivers/remoteproc/tee_remoteproc.c

6805d1065198e1 Arnaud Pouliquen 2024-01-15 81
6805d1065198e1 Arnaud Pouliquen 2024-01-15 @82 struct tee_rproc_context *tee_rproc_ctx;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 83
6805d1065198e1 Arnaud Pouliquen 2024-01-15 84 static void prepare_args(struct tee_rproc *trproc, int cmd, struct tee_ioctl_invoke_arg *arg,
6805d1065198e1 Arnaud Pouliquen 2024-01-15 85 struct tee_param *param, unsigned int num_params)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 86 {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 87 memset(arg, 0, sizeof(*arg));
6805d1065198e1 Arnaud Pouliquen 2024-01-15 88 memset(param, 0, MAX_TEE_PARAM_ARRY_MEMBER * sizeof(*param));
6805d1065198e1 Arnaud Pouliquen 2024-01-15 89
6805d1065198e1 Arnaud Pouliquen 2024-01-15 90 arg->func = cmd;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 91 arg->session = trproc->session_id;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 92 arg->num_params = num_params + 1;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 93
6805d1065198e1 Arnaud Pouliquen 2024-01-15 94 param[0] = (struct tee_param) {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 95 .attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT,
6805d1065198e1 Arnaud Pouliquen 2024-01-15 96 .u.value.a = trproc->rproc_id,
6805d1065198e1 Arnaud Pouliquen 2024-01-15 97 };
6805d1065198e1 Arnaud Pouliquen 2024-01-15 98 }
6805d1065198e1 Arnaud Pouliquen 2024-01-15 99
6805d1065198e1 Arnaud Pouliquen 2024-01-15 100 int tee_rproc_load_fw(struct tee_rproc *trproc, const struct firmware *fw)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 101 {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 102 struct tee_ioctl_invoke_arg arg;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 103 struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER];
6805d1065198e1 Arnaud Pouliquen 2024-01-15 104 struct tee_shm *fw_shm;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 105 int ret;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 106
6805d1065198e1 Arnaud Pouliquen 2024-01-15 107 fw_shm = tee_shm_register_kernel_buf(tee_rproc_ctx->tee_ctx, (void *)fw->data, fw->size);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 108 if (IS_ERR(fw_shm))
6805d1065198e1 Arnaud Pouliquen 2024-01-15 109 return PTR_ERR(fw_shm);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 110
6805d1065198e1 Arnaud Pouliquen 2024-01-15 111 prepare_args(trproc, TA_RPROC_FW_CMD_LOAD_FW, &arg, param, 1);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 112
6805d1065198e1 Arnaud Pouliquen 2024-01-15 113 /* Provide the address of the firmware image */
6805d1065198e1 Arnaud Pouliquen 2024-01-15 114 param[1] = (struct tee_param) {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 115 .attr = TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT,
6805d1065198e1 Arnaud Pouliquen 2024-01-15 116 .u.memref = {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 117 .shm = fw_shm,
6805d1065198e1 Arnaud Pouliquen 2024-01-15 118 .size = fw->size,
6805d1065198e1 Arnaud Pouliquen 2024-01-15 119 .shm_offs = 0,
6805d1065198e1 Arnaud Pouliquen 2024-01-15 120 },
6805d1065198e1 Arnaud Pouliquen 2024-01-15 121 };
6805d1065198e1 Arnaud Pouliquen 2024-01-15 122
6805d1065198e1 Arnaud Pouliquen 2024-01-15 123 ret = tee_client_invoke_func(tee_rproc_ctx->tee_ctx, &arg, param);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 124 if (ret < 0 || arg.ret != 0) {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 125 dev_err(tee_rproc_ctx->dev,
6805d1065198e1 Arnaud Pouliquen 2024-01-15 126 "TA_RPROC_FW_CMD_LOAD_FW invoke failed TEE err: %x, ret:%x\n",
6805d1065198e1 Arnaud Pouliquen 2024-01-15 127 arg.ret, ret);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 128 if (!ret)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 129 ret = -EIO;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 130 }
6805d1065198e1 Arnaud Pouliquen 2024-01-15 131
6805d1065198e1 Arnaud Pouliquen 2024-01-15 132 tee_shm_free(fw_shm);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 133
6805d1065198e1 Arnaud Pouliquen 2024-01-15 134 return ret;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 135 }
6805d1065198e1 Arnaud Pouliquen 2024-01-15 136 EXPORT_SYMBOL_GPL(tee_rproc_load_fw);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 137
6805d1065198e1 Arnaud Pouliquen 2024-01-15 138 int rproc_tee_get_rsc_table(struct tee_rproc *trproc)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 139 {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 140 struct tee_ioctl_invoke_arg arg;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 141 struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER];
6805d1065198e1 Arnaud Pouliquen 2024-01-15 142 struct rproc *rproc = trproc->rproc;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 143 size_t rsc_size;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 144 int ret;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 145
6805d1065198e1 Arnaud Pouliquen 2024-01-15 146 prepare_args(trproc, TA_RPROC_FW_CMD_GET_RSC_TABLE, &arg, param, 2);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 147
6805d1065198e1 Arnaud Pouliquen 2024-01-15 148 param[1].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 149 param[2].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 150
6805d1065198e1 Arnaud Pouliquen 2024-01-15 151 ret = tee_client_invoke_func(tee_rproc_ctx->tee_ctx, &arg, param);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 152 if (ret < 0 || arg.ret != 0) {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 153 dev_err(tee_rproc_ctx->dev,
6805d1065198e1 Arnaud Pouliquen 2024-01-15 154 "TA_RPROC_FW_CMD_GET_RSC_TABLE invoke failed TEE err: %x, ret:%x\n",
6805d1065198e1 Arnaud Pouliquen 2024-01-15 155 arg.ret, ret);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 156 return -EIO;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 157 }
6805d1065198e1 Arnaud Pouliquen 2024-01-15 158
6805d1065198e1 Arnaud Pouliquen 2024-01-15 159 rsc_size = param[2].u.value.a;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 160
6805d1065198e1 Arnaud Pouliquen 2024-01-15 161 /* If the size is null no resource table defined in the image */
6805d1065198e1 Arnaud Pouliquen 2024-01-15 162 if (!rsc_size)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 163 return 0;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 164
6805d1065198e1 Arnaud Pouliquen 2024-01-15 165 /* Store the resource table address that would be updated by the remote core . */
6805d1065198e1 Arnaud Pouliquen 2024-01-15 @166 trproc->rsc_va = ioremap_wc(param[1].u.value.a, rsc_size);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 167 if (IS_ERR_OR_NULL(trproc->rsc_va)) {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 168 dev_err(tee_rproc_ctx->dev, "Unable to map memory region: %lld+%zx\n",
6805d1065198e1 Arnaud Pouliquen 2024-01-15 169 param[1].u.value.a, rsc_size);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 170 trproc->rsc_va = NULL;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 171 return -ENOMEM;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 172 }
6805d1065198e1 Arnaud Pouliquen 2024-01-15 173
6805d1065198e1 Arnaud Pouliquen 2024-01-15 174 /*
6805d1065198e1 Arnaud Pouliquen 2024-01-15 175 * A cached table is requested as the physical address is not mapped yet
6805d1065198e1 Arnaud Pouliquen 2024-01-15 176 * but remoteproc needs to parse the table for resources.
6805d1065198e1 Arnaud Pouliquen 2024-01-15 177 */
6805d1065198e1 Arnaud Pouliquen 2024-01-15 178 rproc->cached_table = kmemdup(trproc->rsc_va, rsc_size, GFP_KERNEL);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 179 if (!rproc->cached_table)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 180 return -ENOMEM;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 181
6805d1065198e1 Arnaud Pouliquen 2024-01-15 182 rproc->table_ptr = rproc->cached_table;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 183 rproc->table_sz = rsc_size;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 184
6805d1065198e1 Arnaud Pouliquen 2024-01-15 185 return 0;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 186 }
6805d1065198e1 Arnaud Pouliquen 2024-01-15 187 EXPORT_SYMBOL_GPL(rproc_tee_get_rsc_table);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 188
6805d1065198e1 Arnaud Pouliquen 2024-01-15 189 struct resource_table *tee_rproc_get_loaded_rsc_table(struct tee_rproc *trproc)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 190 {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 191 return (struct resource_table *)trproc->rsc_va;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 192 }
6805d1065198e1 Arnaud Pouliquen 2024-01-15 193 EXPORT_SYMBOL_GPL(tee_rproc_get_loaded_rsc_table);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 194
6805d1065198e1 Arnaud Pouliquen 2024-01-15 195 int tee_rproc_start(struct tee_rproc *trproc)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 196 {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 197 struct tee_ioctl_invoke_arg arg;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 198 struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER];
6805d1065198e1 Arnaud Pouliquen 2024-01-15 199 int ret;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 200
6805d1065198e1 Arnaud Pouliquen 2024-01-15 201 prepare_args(trproc, TA_RPROC_FW_CMD_START_FW, &arg, param, 0);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 202
6805d1065198e1 Arnaud Pouliquen 2024-01-15 203 ret = tee_client_invoke_func(tee_rproc_ctx->tee_ctx, &arg, param);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 204 if (ret < 0 || arg.ret != 0) {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 205 dev_err(tee_rproc_ctx->dev,
6805d1065198e1 Arnaud Pouliquen 2024-01-15 206 "TA_RPROC_FW_CMD_START_FW invoke failed TEE err: %x, ret:%x\n",
6805d1065198e1 Arnaud Pouliquen 2024-01-15 207 arg.ret, ret);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 208 if (!ret)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 209 ret = -EIO;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 210 }
6805d1065198e1 Arnaud Pouliquen 2024-01-15 211
6805d1065198e1 Arnaud Pouliquen 2024-01-15 212 return ret;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 213 }
6805d1065198e1 Arnaud Pouliquen 2024-01-15 214 EXPORT_SYMBOL_GPL(tee_rproc_start);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 215
6805d1065198e1 Arnaud Pouliquen 2024-01-15 216 int tee_rproc_stop(struct tee_rproc *trproc)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 217 {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 218 struct tee_ioctl_invoke_arg arg;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 219 struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER];
6805d1065198e1 Arnaud Pouliquen 2024-01-15 220 int ret;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 221
6805d1065198e1 Arnaud Pouliquen 2024-01-15 222 prepare_args(trproc, TA_RPROC_FW_CMD_STOP_FW, &arg, param, 0);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 223
6805d1065198e1 Arnaud Pouliquen 2024-01-15 224 ret = tee_client_invoke_func(tee_rproc_ctx->tee_ctx, &arg, param);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 225 if (ret < 0 || arg.ret != 0) {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 226 dev_err(tee_rproc_ctx->dev,
6805d1065198e1 Arnaud Pouliquen 2024-01-15 227 "TA_RPROC_FW_CMD_STOP_FW invoke failed TEE err: %x, ret:%x\n",
6805d1065198e1 Arnaud Pouliquen 2024-01-15 228 arg.ret, ret);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 229 if (!ret)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 230 ret = -EIO;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 231 }
6805d1065198e1 Arnaud Pouliquen 2024-01-15 232 if (trproc->rsc_va)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 @233 iounmap(trproc->rsc_va);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 234 trproc->rsc_va = NULL;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 235
6805d1065198e1 Arnaud Pouliquen 2024-01-15 236 return ret;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 237 }
6805d1065198e1 Arnaud Pouliquen 2024-01-15 238 EXPORT_SYMBOL_GPL(tee_rproc_stop);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 239

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

2024-01-16 08:47:18

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 4/4] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware

Hi Arnaud,

kernel test robot noticed the following build warnings:

[auto build test WARNING on remoteproc/rproc-next]
[also build test WARNING on robh/for-next linus/master v6.7 next-20240112]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Arnaud-Pouliquen/remoteproc-Add-TEE-support/20240115-215613
base: git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc/linux.git rproc-next
patch link: https://lore.kernel.org/r/20240115135249.296822-5-arnaud.pouliquen%40foss.st.com
patch subject: [PATCH 4/4] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware
config: arm64-allyesconfig (https://download.01.org/0day-ci/archive/20240116/[email protected]/config)
compiler: clang version 18.0.0git (https://github.com/llvm/llvm-project 9bde5becb44ea071f5e1fa1f5d4071dc8788b18c)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240116/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/remoteproc/stm32_rproc.c:977:6: warning: variable 'trproc' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
977 | if (of_device_is_compatible(np, "st,stm32mp1-m4-tee")) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/remoteproc/stm32_rproc.c:991:8: note: uninitialized use occurs here
991 | trproc ? &st_rproc_tee_ops : &st_rproc_ops,
| ^~~~~~
drivers/remoteproc/stm32_rproc.c:977:2: note: remove the 'if' if its condition is always true
977 | if (of_device_is_compatible(np, "st,stm32mp1-m4-tee")) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/remoteproc/stm32_rproc.c:968:26: note: initialize the variable 'trproc' to silence this warning
968 | struct tee_rproc *trproc;
| ^
| = NULL
1 warning generated.


vim +977 drivers/remoteproc/stm32_rproc.c

962
963 static int stm32_rproc_probe(struct platform_device *pdev)
964 {
965 struct device *dev = &pdev->dev;
966 struct stm32_rproc *ddata;
967 struct device_node *np = dev->of_node;
968 struct tee_rproc *trproc;
969 struct rproc *rproc;
970 unsigned int state;
971 int ret;
972
973 ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
974 if (ret)
975 return ret;
976
> 977 if (of_device_is_compatible(np, "st,stm32mp1-m4-tee")) {
978 trproc = tee_rproc_register(dev, STM32_MP1_M4_PROC_ID);
979 if (IS_ERR(trproc)) {
980 dev_err_probe(dev, PTR_ERR(trproc),
981 "signed firmware not supported by TEE\n");
982 return PTR_ERR(trproc);
983 }
984 /*
985 * Delegate the firmware management to the secure context.
986 * The firmware loaded has to be signed.
987 */
988 dev_info(dev, "Support of signed firmware only\n");
989 }
990 rproc = rproc_alloc(dev, np->name,
991 trproc ? &st_rproc_tee_ops : &st_rproc_ops,
992 NULL, sizeof(*ddata));
993 if (!rproc) {
994 ret = -ENOMEM;
995 goto free_tee;
996 }
997
998 ddata = rproc->priv;
999 ddata->trproc = trproc;
1000 if (trproc)
1001 trproc->rproc = rproc;
1002
1003 rproc_coredump_set_elf_info(rproc, ELFCLASS32, EM_NONE);
1004
1005 ret = stm32_rproc_parse_dt(pdev, ddata, &rproc->auto_boot);
1006 if (ret)
1007 goto free_rproc;
1008
1009 ret = stm32_rproc_of_memory_translations(pdev, ddata);
1010 if (ret)
1011 goto free_rproc;
1012
1013 ret = stm32_rproc_get_m4_status(ddata, &state);
1014 if (ret)
1015 goto free_rproc;
1016
1017 if (state == M4_STATE_CRUN)
1018 rproc->state = RPROC_DETACHED;
1019
1020 rproc->has_iommu = false;
1021 ddata->workqueue = create_workqueue(dev_name(dev));
1022 if (!ddata->workqueue) {
1023 dev_err(dev, "cannot create workqueue\n");
1024 ret = -ENOMEM;
1025 goto free_resources;
1026 }
1027
1028 platform_set_drvdata(pdev, rproc);
1029
1030 ret = stm32_rproc_request_mbox(rproc);
1031 if (ret)
1032 goto free_wkq;
1033
1034 ret = rproc_add(rproc);
1035 if (ret)
1036 goto free_mb;
1037
1038 return 0;
1039
1040 free_mb:
1041 stm32_rproc_free_mbox(rproc);
1042 free_wkq:
1043 destroy_workqueue(ddata->workqueue);
1044 free_resources:
1045 rproc_resource_cleanup(rproc);
1046 free_rproc:
1047 if (device_may_wakeup(dev)) {
1048 dev_pm_clear_wake_irq(dev);
1049 device_init_wakeup(dev, false);
1050 }
1051 rproc_free(rproc);
1052 free_tee:
1053 if (trproc)
1054 tee_rproc_unregister(trproc);
1055
1056 return ret;
1057 }
1058

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

2024-01-16 19:22:11

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH 2/4] dt-bindings: remoteproc: add compatibility for TEE support

On Mon, Jan 15, 2024 at 02:52:47PM +0100, Arnaud Pouliquen wrote:
> The "st,stm32mp1-m4-tee" compatible is utilized in a system configuration
> where the Cortex-M4 firmware is loaded by the Trusted execution Environment
> (TEE).
> This compatible is used in both the Linux and OP-TEE device-tree.
> - In OP-TEE, a node is defined in the device tree with the
> st,stm32mp1-m4-tee to support signed remoteproc firmware.
> Based on DT properties, OP-TEE authenticates, loads, starts, and stops
> the firmware.
> - On Linux, when the compatibility is set, the Cortex-M resets should not
> be declared in the device tree.
>
> Signed-off-by: Arnaud Pouliquen <[email protected]>
> ---
> .../bindings/remoteproc/st,stm32-rproc.yaml | 53 +++++++++++++++----
> 1 file changed, 44 insertions(+), 9 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml b/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml
> index 370af61d8f28..9fdfa30eff20 100644
> --- a/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml
> +++ b/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml
> @@ -16,7 +16,12 @@ maintainers:
>
> properties:
> compatible:
> - const: st,stm32mp1-m4
> + enum:
> + - st,stm32mp1-m4
> + - st,stm32mp1-m4-tee
> + description:
> + Use "st,stm32mp1-m4" for the Cortex-M4 coprocessor management by Linux

What if other OSs want to manage the M4?

> + Use "st,stm32mp1-m4-tee" for the Cortex-M4 coprocessor management by secure context
>
> reg:
> description:
> @@ -142,21 +147,41 @@ properties:
> required:
> - compatible
> - reg
> - - resets
>
> allOf:
> - if:
> properties:
> - reset-names:
> - not:
> - contains:
> - const: hold_boot
> + compatible:
> + contains:
> + const: st,stm32mp1-m4
> + then:
> + if:
> + properties:
> + reset-names:
> + not:
> + contains:
> + const: hold_boot
> + then:
> + required:
> + - st,syscfg-holdboot
> + - resets
> + else:
> + properties:
> + st,syscfg-holdboot: false
> + required:
> + - reset-names

Looks like a new required property.

> + - resets
> +
> + - if:
> + properties:
> + compatible:
> + contains:
> + const: st,stm32mp1-m4-tee
> then:
> - required:
> - - st,syscfg-holdboot
> - else:
> properties:
> st,syscfg-holdboot: false
> + reset-names: false
> + resets: false
>
> additionalProperties: false
>
> @@ -188,5 +213,15 @@ examples:
> st,syscfg-rsc-tbl = <&tamp 0x144 0xFFFFFFFF>;
> st,syscfg-m4-state = <&tamp 0x148 0xFFFFFFFF>;
> };
> + - |
> + #include <dt-bindings/reset/stm32mp1-resets.h>
> + m4@10000000 {
> + compatible = "st,stm32mp1-m4-tee";
> + reg = <0x10000000 0x40000>,
> + <0x30000000 0x40000>,
> + <0x38000000 0x10000>;
> + st,syscfg-rsc-tbl = <&tamp 0x144 0xFFFFFFFF>;
> + st,syscfg-m4-state = <&tamp 0x148 0xFFFFFFFF>;
> + };
>
> ...
> --
> 2.25.1
>

2024-01-17 07:45:31

by Arnaud Pouliquen

[permalink] [raw]
Subject: Re: [PATCH 2/4] dt-bindings: remoteproc: add compatibility for TEE support



On 1/16/24 20:21, Rob Herring wrote:
> On Mon, Jan 15, 2024 at 02:52:47PM +0100, Arnaud Pouliquen wrote:
>> The "st,stm32mp1-m4-tee" compatible is utilized in a system configuration
>> where the Cortex-M4 firmware is loaded by the Trusted execution Environment
>> (TEE).
>> This compatible is used in both the Linux and OP-TEE device-tree.
>> - In OP-TEE, a node is defined in the device tree with the
>> st,stm32mp1-m4-tee to support signed remoteproc firmware.
>> Based on DT properties, OP-TEE authenticates, loads, starts, and stops
>> the firmware.
>> - On Linux, when the compatibility is set, the Cortex-M resets should not
>> be declared in the device tree.
>>
>> Signed-off-by: Arnaud Pouliquen <[email protected]>
>> ---
>> .../bindings/remoteproc/st,stm32-rproc.yaml | 53 +++++++++++++++----
>> 1 file changed, 44 insertions(+), 9 deletions(-)
>>
>> diff --git a/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml b/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml
>> index 370af61d8f28..9fdfa30eff20 100644
>> --- a/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml
>> +++ b/Documentation/devicetree/bindings/remoteproc/st,stm32-rproc.yaml
>> @@ -16,7 +16,12 @@ maintainers:
>>
>> properties:
>> compatible:
>> - const: st,stm32mp1-m4
>> + enum:
>> + - st,stm32mp1-m4
>> + - st,stm32mp1-m4-tee
>> + description:
>> + Use "st,stm32mp1-m4" for the Cortex-M4 coprocessor management by Linux
>
> What if other OSs want to manage the M4?

Right, for instance this compatibles are also used by U-boot. I will change
"by Linux" by "by non secure context"


>
>> + Use "st,stm32mp1-m4-tee" for the Cortex-M4 coprocessor management by secure context
>>
>> reg:
>> description:
>> @@ -142,21 +147,41 @@ properties:
>> required:
>> - compatible
>> - reg
>> - - resets
>>
>> allOf:
>> - if:
>> properties:
>> - reset-names:
>> - not:
>> - contains:
>> - const: hold_boot
>> + compatible:
>> + contains:
>> + const: st,stm32mp1-m4
>> + then:
>> + if:
>> + properties:
>> + reset-names:
>> + not:
>> + contains:
>> + const: hold_boot
>> + then:
>> + required:
>> + - st,syscfg-holdboot
>> + - resets
>> + else:
>> + properties:
>> + st,syscfg-holdboot: false
>> + required:
>> + - reset-names
>
> Looks like a new required property.

I just realize that it does not make sense. We execute this
only if "reset-names" contains "hold_boot".
I will remove it

Thanks!
Arnaud

>
>> + - resets
>> +
>> + - if:
>> + properties:
>> + compatible:
>> + contains:
>> + const: st,stm32mp1-m4-tee
>> then:
>> - required:
>> - - st,syscfg-holdboot
>> - else:
>> properties:
>> st,syscfg-holdboot: false
>> + reset-names: false
>> + resets: false
>>
>> additionalProperties: false
>>
>> @@ -188,5 +213,15 @@ examples:
>> st,syscfg-rsc-tbl = <&tamp 0x144 0xFFFFFFFF>;
>> st,syscfg-m4-state = <&tamp 0x148 0xFFFFFFFF>;
>> };
>> + - |
>> + #include <dt-bindings/reset/stm32mp1-resets.h>
>> + m4@10000000 {
>> + compatible = "st,stm32mp1-m4-tee";
>> + reg = <0x10000000 0x40000>,
>> + <0x30000000 0x40000>,
>> + <0x38000000 0x10000>;
>> + st,syscfg-rsc-tbl = <&tamp 0x144 0xFFFFFFFF>;
>> + st,syscfg-m4-state = <&tamp 0x148 0xFFFFFFFF>;
>> + };
>>
>> ...
>> --
>> 2.25.1
>>

2024-01-17 23:50:35

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 4/4] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware

Hi Arnaud,

kernel test robot noticed the following build warnings:

[auto build test WARNING on remoteproc/rproc-next]
[also build test WARNING on robh/for-next linus/master v6.7 next-20240117]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Arnaud-Pouliquen/remoteproc-Add-TEE-support/20240115-215613
base: git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc/linux.git rproc-next
patch link: https://lore.kernel.org/r/20240115135249.296822-5-arnaud.pouliquen%40foss.st.com
patch subject: [PATCH 4/4] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware
config: mips-randconfig-r112-20240117 (https://download.01.org/0day-ci/archive/20240118/[email protected]/config)
compiler: clang version 18.0.0git (https://github.com/llvm/llvm-project 9bde5becb44ea071f5e1fa1f5d4071dc8788b18c)
reproduce: (https://download.01.org/0day-ci/archive/20240118/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)
drivers/remoteproc/tee_remoteproc.c:82:26: sparse: sparse: symbol 'tee_rproc_ctx' was not declared. Should it be static?
drivers/remoteproc/tee_remoteproc.c:166:24: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected void *rsc_va @@ got void [noderef] __iomem * @@
drivers/remoteproc/tee_remoteproc.c:166:24: sparse: expected void *rsc_va
drivers/remoteproc/tee_remoteproc.c:166:24: sparse: got void [noderef] __iomem *
>> drivers/remoteproc/tee_remoteproc.c:233:31: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected void const volatile [noderef] __iomem *addr @@ got void *rsc_va @@
drivers/remoteproc/tee_remoteproc.c:233:31: sparse: expected void const volatile [noderef] __iomem *addr
drivers/remoteproc/tee_remoteproc.c:233:31: sparse: got void *rsc_va
drivers/remoteproc/tee_remoteproc.c: note: in included file (through include/linux/preempt.h, include/linux/spinlock.h, include/linux/mmzone.h, ...):
include/linux/list.h:83:21: sparse: sparse: self-comparison always evaluates to true

vim +233 drivers/remoteproc/tee_remoteproc.c

6805d1065198e1 Arnaud Pouliquen 2024-01-15 215
6805d1065198e1 Arnaud Pouliquen 2024-01-15 216 int tee_rproc_stop(struct tee_rproc *trproc)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 217 {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 218 struct tee_ioctl_invoke_arg arg;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 219 struct tee_param param[MAX_TEE_PARAM_ARRY_MEMBER];
6805d1065198e1 Arnaud Pouliquen 2024-01-15 220 int ret;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 221
6805d1065198e1 Arnaud Pouliquen 2024-01-15 222 prepare_args(trproc, TA_RPROC_FW_CMD_STOP_FW, &arg, param, 0);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 223
6805d1065198e1 Arnaud Pouliquen 2024-01-15 224 ret = tee_client_invoke_func(tee_rproc_ctx->tee_ctx, &arg, param);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 225 if (ret < 0 || arg.ret != 0) {
6805d1065198e1 Arnaud Pouliquen 2024-01-15 226 dev_err(tee_rproc_ctx->dev,
6805d1065198e1 Arnaud Pouliquen 2024-01-15 227 "TA_RPROC_FW_CMD_STOP_FW invoke failed TEE err: %x, ret:%x\n",
6805d1065198e1 Arnaud Pouliquen 2024-01-15 228 arg.ret, ret);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 229 if (!ret)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 230 ret = -EIO;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 231 }
6805d1065198e1 Arnaud Pouliquen 2024-01-15 232 if (trproc->rsc_va)
6805d1065198e1 Arnaud Pouliquen 2024-01-15 @233 iounmap(trproc->rsc_va);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 234 trproc->rsc_va = NULL;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 235
6805d1065198e1 Arnaud Pouliquen 2024-01-15 236 return ret;
6805d1065198e1 Arnaud Pouliquen 2024-01-15 237 }
6805d1065198e1 Arnaud Pouliquen 2024-01-15 238 EXPORT_SYMBOL_GPL(tee_rproc_stop);
6805d1065198e1 Arnaud Pouliquen 2024-01-15 239

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

2024-01-18 07:38:52

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 4/4] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware

Hi Arnaud,

kernel test robot noticed the following build errors:

[auto build test ERROR on remoteproc/rproc-next]
[also build test ERROR on linus/master v6.7 next-20240117]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Arnaud-Pouliquen/remoteproc-Add-TEE-support/20240115-215613
base: git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc/linux.git rproc-next
patch link: https://lore.kernel.org/r/20240115135249.296822-5-arnaud.pouliquen%40foss.st.com
patch subject: [PATCH 4/4] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware
config: arm64-randconfig-r081-20240118 (https://download.01.org/0day-ci/archive/20240118/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240118/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

aarch64-linux-ld: drivers/remoteproc/tee_remoteproc.o: in function `tee_rproc_load_fw':
>> tee_remoteproc.c:(.text+0x138): undefined reference to `tee_shm_register_kernel_buf'
>> tee_remoteproc.c:(.text+0x138): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `tee_shm_register_kernel_buf'
>> aarch64-linux-ld: tee_remoteproc.c:(.text+0x18c): undefined reference to `tee_client_invoke_func'
>> tee_remoteproc.c:(.text+0x18c): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `tee_client_invoke_func'
>> aarch64-linux-ld: tee_remoteproc.c:(.text+0x1ac): undefined reference to `tee_shm_free'
>> tee_remoteproc.c:(.text+0x1ac): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `tee_shm_free'
aarch64-linux-ld: drivers/remoteproc/tee_remoteproc.o: in function `tee_rproc_start':
>> tee_remoteproc.c:(.text+0x240): undefined reference to `tee_client_invoke_func'
tee_remoteproc.c:(.text+0x240): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `tee_client_invoke_func'
aarch64-linux-ld: drivers/remoteproc/tee_remoteproc.o: in function `rproc_tee_get_rsc_table':
tee_remoteproc.c:(.text+0x2dc): undefined reference to `tee_client_invoke_func'
tee_remoteproc.c:(.text+0x2dc): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `tee_client_invoke_func'
aarch64-linux-ld: drivers/remoteproc/tee_remoteproc.o: in function `tee_rproc_stop':
tee_remoteproc.c:(.text+0x408): undefined reference to `tee_client_invoke_func'
tee_remoteproc.c:(.text+0x408): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `tee_client_invoke_func'
aarch64-linux-ld: drivers/remoteproc/tee_remoteproc.o: in function `tee_rproc_register':
>> tee_remoteproc.c:(.text+0x51c): undefined reference to `tee_client_open_session'
>> tee_remoteproc.c:(.text+0x51c): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `tee_client_open_session'
aarch64-linux-ld: drivers/remoteproc/tee_remoteproc.o: in function `tee_rproc_unregister':
>> tee_remoteproc.c:(.text+0x624): undefined reference to `tee_client_close_session'
>> tee_remoteproc.c:(.text+0x624): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `tee_client_close_session'
aarch64-linux-ld: drivers/remoteproc/tee_remoteproc.o: in function `tee_rproc_probe':
>> tee_remoteproc.c:(.text+0x6b0): undefined reference to `tee_client_open_context'
>> tee_remoteproc.c:(.text+0x6b0): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `tee_client_open_context'
>> aarch64-linux-ld: tee_remoteproc.c:(.text+0x6e0): undefined reference to `tee_client_close_context'
>> tee_remoteproc.c:(.text+0x6e0): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `tee_client_close_context'
aarch64-linux-ld: drivers/remoteproc/tee_remoteproc.o: in function `tee_rproc_remove':
tee_remoteproc.c:(.text+0x78c): undefined reference to `tee_client_close_session'
tee_remoteproc.c:(.text+0x78c): additional relocation overflows omitted from the output
aarch64-linux-ld: tee_remoteproc.c:(.text+0x7dc): undefined reference to `tee_client_close_context'
>> aarch64-linux-ld: drivers/remoteproc/tee_remoteproc.o:(.data+0x10): undefined reference to `tee_bus_type'

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for TEE_REMOTEPROC
Depends on [m]: REMOTEPROC [=y] && OPTEE [=m]
Selected by [y]:
- STM32_RPROC [=y] && (ARCH_STM32 [=y] || COMPILE_TEST [=y]) && REMOTEPROC [=y]

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki