From: Sumit Garg via OP-TEE <op-tee@lists.trustedfirmware.org>
To: Jens Wiklander <jens.wiklander@linaro.org>
Cc: Wei Ming Chen <jj251510319013@gmail.com>,
linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org,
harshal.dev@oss.qualcomm.com,
Aristo Chen <aristo.chen@canonical.com>,
mario.limonciello@amd.com, Rijo Thomas <Rijo-john.Thomas@amd.com>,
Amirreza Zarrabi <amirreza.zarrabi@oss.qualcomm.com>
Subject: Re: [PATCH v2 1/1] tee: optee: expose OS revision via sysfs
Date: Tue, 25 Nov 2025 13:23:22 +0530 [thread overview]
Message-ID: <aSVgctqRSy5_vvkN@sumit-X1> (raw)
In-Reply-To: <CAHUa44HFC+BTO3KfaNF1LHiM7frgt2myzZ_85Mbf1t2gUY9iSg@mail.gmail.com>
On Mon, Nov 24, 2025 at 08:15:04AM +0100, Jens Wiklander wrote:
> Hi,
>
> On Sat, Nov 22, 2025 at 4:00 PM Wei Ming Chen <jj251510319013@gmail.com> wrote:
> >
> > From: Aristo Chen <aristo.chen@canonical.com>
> >
> > Today the only way to read the OP-TEE OS version is from dmesg/journal
> > logs, which can be lost as buffers roll over. Capture the OS revision
> > (major/minor/build_id) from secure world for both SMC and FF-A ABIs, store
> > it in the OP-TEE driver, and expose a stable userspace readout via
> > /sys/class/tee/tee*/optee_os_revision.
> >
> > Signed-off-by: Aristo Chen <aristo.chen@canonical.com>
> > ---
> > drivers/tee/optee/core.c | 19 +++++++++++++++++++
> > drivers/tee/optee/ffa_abi.c | 13 +++++++++++--
> > drivers/tee/optee/optee_private.h | 17 +++++++++++++++++
> > drivers/tee/optee/smc_abi.c | 13 +++++++++++--
> > 4 files changed, 58 insertions(+), 4 deletions(-)
>
> This appears to be a feature that could be useful for all TEEs.
True, it is something that TEE core should support. Although I would
have preferred to extend TEE_IOC_VERSION since that's the common way the
user-space library get's TEE implementation specific information. But
since it being already a user-space ABI which doesn't offer extension.
Maybe we can consider adding TEE_IOC_REVERSION instead of sysfs.
But before doing that we need to know who is the actual consumer here
from user-space perspective? Will the client applications also depend on
the TEE implementation revision?
> If so,
> let's take a step back to see what's needed. We can add the sysfs
> attribute from drivers/tee/tee_core.c and add another optional
> callback to struct tee_driver_ops, such as get_tee_revision(). For
> OP-TEE, the specific information we want to share is clear, but other
> TEEs might have additional or different data. What do others think?
Implementation wise, this sounds like a reasonable approach.
-Sumit
>
> Cheers,
> Jens
>
> >
> > diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
> > index 5b62139714ce..66409cf5da1c 100644
> > --- a/drivers/tee/optee/core.c
> > +++ b/drivers/tee/optee/core.c
> > @@ -83,8 +83,27 @@ static ssize_t rpmb_routing_model_show(struct device *dev,
> > }
> > static DEVICE_ATTR_RO(rpmb_routing_model);
> >
> > +static ssize_t optee_os_revision_show(struct device *dev,
> > + struct device_attribute *attr, char *buf)
> > +{
> > + struct optee *optee = dev_get_drvdata(dev);
> > + struct optee_version_info *v;
> > +
> > + if (!optee)
> > + return -ENODEV;
> > +
> > + v = &optee->version_info;
> > + if (v->os_build_id)
> > + return sysfs_emit(buf, "%u.%u (%016llx)\n", v->os_major,
> > + v->os_minor, (unsigned long long)v->os_build_id);
> > +
> > + return sysfs_emit(buf, "%u.%u\n", v->os_major, v->os_minor);
> > +}
> > +static DEVICE_ATTR_RO(optee_os_revision);
> > +
> > static struct attribute *optee_dev_attrs[] = {
> > &dev_attr_rpmb_routing_model.attr,
> > + &dev_attr_optee_os_revision.attr,
> > NULL
> > };
> >
> > diff --git a/drivers/tee/optee/ffa_abi.c b/drivers/tee/optee/ffa_abi.c
> > index bf8390789ecf..3d4f35599dd1 100644
> > --- a/drivers/tee/optee/ffa_abi.c
> > +++ b/drivers/tee/optee/ffa_abi.c
> > @@ -776,7 +776,8 @@ static int optee_ffa_reclaim_protmem(struct optee *optee,
> > */
> >
> > static bool optee_ffa_api_is_compatible(struct ffa_device *ffa_dev,
> > - const struct ffa_ops *ops)
> > + const struct ffa_ops *ops,
> > + struct optee_version_info *version_info)
> > {
> > const struct ffa_msg_ops *msg_ops = ops->msg_ops;
> > struct ffa_send_direct_data data = {
> > @@ -806,6 +807,12 @@ static bool optee_ffa_api_is_compatible(struct ffa_device *ffa_dev,
> > pr_err("Unexpected error %d\n", rc);
> > return false;
> > }
> > + if (version_info) {
> > + version_info->os_major = data.data0;
> > + version_info->os_minor = data.data1;
> > + version_info->os_build_id = data.data2;
> > + }
> > +
> > if (data.data2)
> > pr_info("revision %lu.%lu (%08lx)",
> > data.data0, data.data1, data.data2);
> > @@ -1034,6 +1041,7 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
> > {
> > const struct ffa_notifier_ops *notif_ops;
> > const struct ffa_ops *ffa_ops;
> > + struct optee_version_info version_info = { };
> > unsigned int max_notif_value;
> > unsigned int rpc_param_count;
> > struct tee_shm_pool *pool;
> > @@ -1047,7 +1055,7 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
> > ffa_ops = ffa_dev->ops;
> > notif_ops = ffa_ops->notifier_ops;
> >
> > - if (!optee_ffa_api_is_compatible(ffa_dev, ffa_ops))
> > + if (!optee_ffa_api_is_compatible(ffa_dev, ffa_ops, &version_info))
> > return -EINVAL;
> >
> > if (!optee_ffa_exchange_caps(ffa_dev, ffa_ops, &sec_caps,
> > @@ -1059,6 +1067,7 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
> > optee = kzalloc(sizeof(*optee), GFP_KERNEL);
> > if (!optee)
> > return -ENOMEM;
> > + optee->version_info = version_info;
> >
> > pool = optee_ffa_shm_pool_alloc_pages();
> > if (IS_ERR(pool)) {
> > diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h
> > index db9ea673fbca..3e7bcd44976b 100644
> > --- a/drivers/tee/optee/optee_private.h
> > +++ b/drivers/tee/optee/optee_private.h
> > @@ -19,6 +19,22 @@
> >
> > #define OPTEE_MAX_ARG_SIZE 1024
> >
> > +/**
> > + * struct optee_version_info - OP-TEE OS revision reported by secure world
> > + * @os_major: OP-TEE OS major version
> > + * @os_minor: OP-TEE OS minor version
> > + * @os_build_id: OP-TEE OS build identifier (0 if unspecified)
> > + *
> > + * Values come from OPTEE_SMC_CALL_GET_OS_REVISION (SMC ABI) or
> > + * OPTEE_FFA_GET_OS_VERSION (FF-A ABI); this is the trusted OS revision, not an
> > + * FF-A ABI version.
> > + */
> > +struct optee_version_info {
> > + u32 os_major;
> > + u32 os_minor;
> > + u64 os_build_id;
> > +};
> > +
> > /* Some Global Platform error codes used in this driver */
> > #define TEEC_SUCCESS 0x00000000
> > #define TEEC_ERROR_BAD_PARAMETERS 0xFFFF0006
> > @@ -249,6 +265,7 @@ struct optee {
> > bool in_kernel_rpmb_routing;
> > struct work_struct scan_bus_work;
> > struct work_struct rpmb_scan_bus_work;
> > + struct optee_version_info version_info;
> > };
> >
> > struct optee_session {
> > diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c
> > index 0be663fcd52b..07c703609320 100644
> > --- a/drivers/tee/optee/smc_abi.c
> > +++ b/drivers/tee/optee/smc_abi.c
> > @@ -1323,7 +1323,8 @@ static bool optee_msg_api_uid_is_optee_image_load(optee_invoke_fn *invoke_fn)
> > }
> > #endif
> >
> > -static void optee_msg_get_os_revision(optee_invoke_fn *invoke_fn)
> > +static void optee_msg_get_os_revision(optee_invoke_fn *invoke_fn,
> > + struct optee_version_info *version_info)
> > {
> > union {
> > struct arm_smccc_res smccc;
> > @@ -1337,6 +1338,12 @@ static void optee_msg_get_os_revision(optee_invoke_fn *invoke_fn)
> > invoke_fn(OPTEE_SMC_CALL_GET_OS_REVISION, 0, 0, 0, 0, 0, 0, 0,
> > &res.smccc);
> >
> > + if (version_info) {
> > + version_info->os_major = res.result.major;
> > + version_info->os_minor = res.result.minor;
> > + version_info->os_build_id = res.result.build_id;
> > + }
> > +
> > if (res.result.build_id)
> > pr_info("revision %lu.%lu (%0*lx)", res.result.major,
> > res.result.minor, (int)sizeof(res.result.build_id) * 2,
> > @@ -1727,6 +1734,7 @@ static int optee_probe(struct platform_device *pdev)
> > unsigned int thread_count;
> > struct tee_device *teedev;
> > struct tee_context *ctx;
> > + struct optee_version_info version_info = { };
> > u32 max_notif_value;
> > u32 arg_cache_flags;
> > u32 sec_caps;
> > @@ -1745,7 +1753,7 @@ static int optee_probe(struct platform_device *pdev)
> > return -EINVAL;
> > }
> >
> > - optee_msg_get_os_revision(invoke_fn);
> > + optee_msg_get_os_revision(invoke_fn, &version_info);
> >
> > if (!optee_msg_api_revision_is_compatible(invoke_fn)) {
> > pr_warn("api revision mismatch\n");
> > @@ -1814,6 +1822,7 @@ static int optee_probe(struct platform_device *pdev)
> > rc = -ENOMEM;
> > goto err_free_shm_pool;
> > }
> > + optee->version_info = version_info;
> >
> > optee->ops = &optee_ops;
> > optee->smc.invoke_fn = invoke_fn;
> > --
> > 2.43.0
> >
next prev parent reply other threads:[~2025-11-25 7:53 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-21 14:12 [PATCH v1 1/1] tee: optee: expose OS revision via sysfs Wei Ming Chen
2025-11-22 7:36 ` Harshal Dev via OP-TEE
2025-11-22 14:59 ` [PATCH v2 " Wei Ming Chen
2025-11-24 7:15 ` Jens Wiklander
2025-11-24 14:28 ` Thomas, Rijo-john via OP-TEE
2025-11-25 7:53 ` Sumit Garg via OP-TEE [this message]
2025-11-25 7:55 ` Sumit Garg via OP-TEE
2025-12-01 11:47 ` Aristo Chen
2025-12-01 13:06 ` Jens Wiklander
2025-12-02 9:54 ` Aristo Chen
2025-12-03 7:50 ` Jens Wiklander
2025-12-07 14:01 ` Aristo Chen
2025-12-09 8:30 ` Jens Wiklander
2025-12-19 15:38 ` Aristo Chen
2025-12-22 8:34 ` Jens Wiklander
2025-12-22 10:07 ` Sumit Garg via OP-TEE
2025-12-23 3:33 ` Aristo Chen via OP-TEE
2025-12-26 13:19 ` [PATCH v3 " Aristo Chen
2025-12-29 4:59 ` Sumit Garg via OP-TEE
2025-12-30 5:17 ` [PATCH v4 1/2] tee: add revision sysfs attribute Aristo Chen
2025-12-30 5:17 ` [PATCH v4 2/2] tee: optee: store OS revision for TEE core Aristo Chen
2026-01-05 5:20 ` Sumit Garg via OP-TEE
2026-01-05 8:13 ` Aristo Chen
2026-01-05 8:48 ` Sumit Garg via OP-TEE
2026-01-05 4:53 ` [PATCH v4 1/2] tee: add revision sysfs attribute Sumit Garg via OP-TEE
2026-01-07 15:26 ` [PATCH v5 " Aristo Chen
2026-01-07 15:26 ` [PATCH v5 2/2] tee: optee: store OS revision for TEE core Aristo Chen
2026-01-07 15:28 ` [PATCH v5 1/2] tee: add revision sysfs attribute Mario Limonciello via OP-TEE
2026-01-08 2:55 ` Aristo Chen
2026-01-08 3:01 ` Mario Limonciello (AMD) (kernel.org) via OP-TEE
2026-01-08 6:45 ` [PATCH v6 " Aristo Chen
2026-01-08 6:45 ` [PATCH v6 2/2] tee: optee: store OS revision for TEE core Aristo Chen
2026-01-09 11:50 ` Sumit Garg via OP-TEE
2026-01-09 15:07 ` Aristo Chen
2026-01-12 11:22 ` Sumit Garg via OP-TEE
2026-01-12 9:55 ` Jens Wiklander
2026-01-12 10:43 ` Aristo Chen
2026-01-09 11:48 ` [PATCH v6 1/2] tee: add revision sysfs attribute Sumit Garg via OP-TEE
2026-01-12 9:50 ` Jens Wiklander
2026-01-12 15:48 ` [PATCH v7 " Aristo Chen via OP-TEE
2026-01-12 15:48 ` [PATCH v7 2/2] tee: optee: store OS revision for TEE core Aristo Chen via OP-TEE
2026-01-14 15:43 ` Jens Wiklander
2026-01-15 6:18 ` Sumit Garg via OP-TEE
2026-01-14 15:42 ` [PATCH v7 1/2] tee: add revision sysfs attribute Jens Wiklander
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aSVgctqRSy5_vvkN@sumit-X1 \
--to=op-tee@lists.trustedfirmware.org \
--cc=Rijo-john.Thomas@amd.com \
--cc=amirreza.zarrabi@oss.qualcomm.com \
--cc=aristo.chen@canonical.com \
--cc=harshal.dev@oss.qualcomm.com \
--cc=jens.wiklander@linaro.org \
--cc=jj251510319013@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=sumit.garg@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox