Skip to content

Commit ee5dde7

Browse files
committed
Merge tag 'tee-sysfs-for-6.20' of git://git.kernel.org/pub/scm/linux/kernel/git/jenswi/linux-tee into soc/drivers
TEE sysfs for 6.20 - Add an optional generic sysfs attribute for TEE revision - Implement revision reporting for OP-TEE using both SMC and FF-A ABIs * tag 'tee-sysfs-for-6.20' of git://git.kernel.org/pub/scm/linux/kernel/git/jenswi/linux-tee: tee: optee: store OS revision for TEE core tee: add revision sysfs attribute Signed-off-by: Arnd Bergmann <arnd@arndb.de>
2 parents 4b45c2f + c19faf5 commit ee5dde7

7 files changed

Lines changed: 163 additions & 18 deletions

File tree

Documentation/ABI/testing/sysfs-class-tee

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ Description:
1313
space if the variable is absent. The primary purpose
1414
of this variable is to let systemd know whether
1515
tee-supplicant is needed in the early boot with initramfs.
16+
17+
What: /sys/class/tee/tee{,priv}X/revision
18+
Date: Jan 2026
19+
KernelVersion: 6.19
20+
Contact: op-tee@lists.trustedfirmware.org
21+
Description:
22+
Read-only revision string reported by the TEE driver. This is
23+
for diagnostics only and must not be used to infer feature
24+
support. Use TEE_IOC_VERSION for capability and compatibility
25+
checks.

drivers/tee/optee/core.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,29 @@ int optee_set_dma_mask(struct optee *optee, u_int pa_width)
6363
return dma_coerce_mask_and_coherent(&optee->teedev->dev, mask);
6464
}
6565

66+
int optee_get_revision(struct tee_device *teedev, char *buf, size_t len)
67+
{
68+
struct optee *optee = tee_get_drvdata(teedev);
69+
u64 build_id;
70+
71+
if (!optee)
72+
return -ENODEV;
73+
if (!buf || !len)
74+
return -EINVAL;
75+
76+
build_id = optee->revision.os_build_id;
77+
if (build_id)
78+
scnprintf(buf, len, "%u.%u (%016llx)",
79+
optee->revision.os_major,
80+
optee->revision.os_minor,
81+
(unsigned long long)build_id);
82+
else
83+
scnprintf(buf, len, "%u.%u", optee->revision.os_major,
84+
optee->revision.os_minor);
85+
86+
return 0;
87+
}
88+
6689
static void optee_bus_scan(struct work_struct *work)
6790
{
6891
WARN_ON(optee_enumerate_devices(PTA_CMD_GET_DEVICES_SUPP));

drivers/tee/optee/ffa_abi.c

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,39 @@ static int optee_ffa_reclaim_protmem(struct optee *optee,
775775
* with a matching configuration.
776776
*/
777777

778+
static bool optee_ffa_get_os_revision(struct ffa_device *ffa_dev,
779+
const struct ffa_ops *ops,
780+
struct optee_revision *revision)
781+
{
782+
const struct ffa_msg_ops *msg_ops = ops->msg_ops;
783+
struct ffa_send_direct_data data = {
784+
.data0 = OPTEE_FFA_GET_OS_VERSION,
785+
};
786+
int rc;
787+
788+
msg_ops->mode_32bit_set(ffa_dev);
789+
790+
rc = msg_ops->sync_send_receive(ffa_dev, &data);
791+
if (rc) {
792+
pr_err("Unexpected error %d\n", rc);
793+
return false;
794+
}
795+
796+
if (revision) {
797+
revision->os_major = data.data0;
798+
revision->os_minor = data.data1;
799+
revision->os_build_id = data.data2;
800+
}
801+
802+
if (data.data2)
803+
pr_info("revision %lu.%lu (%08lx)",
804+
data.data0, data.data1, data.data2);
805+
else
806+
pr_info("revision %lu.%lu", data.data0, data.data1);
807+
808+
return true;
809+
}
810+
778811
static bool optee_ffa_api_is_compatible(struct ffa_device *ffa_dev,
779812
const struct ffa_ops *ops)
780813
{
@@ -798,20 +831,6 @@ static bool optee_ffa_api_is_compatible(struct ffa_device *ffa_dev,
798831
return false;
799832
}
800833

801-
data = (struct ffa_send_direct_data){
802-
.data0 = OPTEE_FFA_GET_OS_VERSION,
803-
};
804-
rc = msg_ops->sync_send_receive(ffa_dev, &data);
805-
if (rc) {
806-
pr_err("Unexpected error %d\n", rc);
807-
return false;
808-
}
809-
if (data.data2)
810-
pr_info("revision %lu.%lu (%08lx)",
811-
data.data0, data.data1, data.data2);
812-
else
813-
pr_info("revision %lu.%lu", data.data0, data.data1);
814-
815834
return true;
816835
}
817836

@@ -900,6 +919,7 @@ static int optee_ffa_open(struct tee_context *ctx)
900919

901920
static const struct tee_driver_ops optee_ffa_clnt_ops = {
902921
.get_version = optee_ffa_get_version,
922+
.get_tee_revision = optee_get_revision,
903923
.open = optee_ffa_open,
904924
.release = optee_release,
905925
.open_session = optee_open_session,
@@ -918,6 +938,7 @@ static const struct tee_desc optee_ffa_clnt_desc = {
918938

919939
static const struct tee_driver_ops optee_ffa_supp_ops = {
920940
.get_version = optee_ffa_get_version,
941+
.get_tee_revision = optee_get_revision,
921942
.open = optee_ffa_open,
922943
.release = optee_release_supp,
923944
.supp_recv = optee_supp_recv,
@@ -1060,6 +1081,11 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
10601081
if (!optee)
10611082
return -ENOMEM;
10621083

1084+
if (!optee_ffa_get_os_revision(ffa_dev, ffa_ops, &optee->revision)) {
1085+
rc = -EINVAL;
1086+
goto err_free_optee;
1087+
}
1088+
10631089
pool = optee_ffa_shm_pool_alloc_pages();
10641090
if (IS_ERR(pool)) {
10651091
rc = PTR_ERR(pool);

drivers/tee/optee/optee_private.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,24 @@ struct optee_ffa {
171171

172172
struct optee;
173173

174+
/**
175+
* struct optee_revision - OP-TEE OS revision reported by secure world
176+
* @os_major: OP-TEE OS major version
177+
* @os_minor: OP-TEE OS minor version
178+
* @os_build_id: OP-TEE OS build identifier (0 if unspecified)
179+
*
180+
* Values come from OPTEE_SMC_CALL_GET_OS_REVISION (SMC ABI) or
181+
* OPTEE_FFA_GET_OS_VERSION (FF-A ABI); this is the trusted OS revision, not an
182+
* FF-A ABI version.
183+
*/
184+
struct optee_revision {
185+
u32 os_major;
186+
u32 os_minor;
187+
u64 os_build_id;
188+
};
189+
190+
int optee_get_revision(struct tee_device *teedev, char *buf, size_t len);
191+
174192
/**
175193
* struct optee_ops - OP-TEE driver internal operations
176194
* @do_call_with_arg: enters OP-TEE in secure world
@@ -249,6 +267,7 @@ struct optee {
249267
bool in_kernel_rpmb_routing;
250268
struct work_struct scan_bus_work;
251269
struct work_struct rpmb_scan_bus_work;
270+
struct optee_revision revision;
252271
};
253272

254273
struct optee_session {

drivers/tee/optee/smc_abi.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,7 @@ static int optee_smc_open(struct tee_context *ctx)
12421242

12431243
static const struct tee_driver_ops optee_clnt_ops = {
12441244
.get_version = optee_get_version,
1245+
.get_tee_revision = optee_get_revision,
12451246
.open = optee_smc_open,
12461247
.release = optee_release,
12471248
.open_session = optee_open_session,
@@ -1261,6 +1262,7 @@ static const struct tee_desc optee_clnt_desc = {
12611262

12621263
static const struct tee_driver_ops optee_supp_ops = {
12631264
.get_version = optee_get_version,
1265+
.get_tee_revision = optee_get_revision,
12641266
.open = optee_smc_open,
12651267
.release = optee_release_supp,
12661268
.supp_recv = optee_supp_recv,
@@ -1323,7 +1325,8 @@ static bool optee_msg_api_uid_is_optee_image_load(optee_invoke_fn *invoke_fn)
13231325
}
13241326
#endif
13251327

1326-
static void optee_msg_get_os_revision(optee_invoke_fn *invoke_fn)
1328+
static void optee_msg_get_os_revision(optee_invoke_fn *invoke_fn,
1329+
struct optee_revision *revision)
13271330
{
13281331
union {
13291332
struct arm_smccc_res smccc;
@@ -1337,6 +1340,12 @@ static void optee_msg_get_os_revision(optee_invoke_fn *invoke_fn)
13371340
invoke_fn(OPTEE_SMC_CALL_GET_OS_REVISION, 0, 0, 0, 0, 0, 0, 0,
13381341
&res.smccc);
13391342

1343+
if (revision) {
1344+
revision->os_major = res.result.major;
1345+
revision->os_minor = res.result.minor;
1346+
revision->os_build_id = res.result.build_id;
1347+
}
1348+
13401349
if (res.result.build_id)
13411350
pr_info("revision %lu.%lu (%0*lx)", res.result.major,
13421351
res.result.minor, (int)sizeof(res.result.build_id) * 2,
@@ -1745,8 +1754,6 @@ static int optee_probe(struct platform_device *pdev)
17451754
return -EINVAL;
17461755
}
17471756

1748-
optee_msg_get_os_revision(invoke_fn);
1749-
17501757
if (!optee_msg_api_revision_is_compatible(invoke_fn)) {
17511758
pr_warn("api revision mismatch\n");
17521759
return -EINVAL;
@@ -1815,6 +1822,8 @@ static int optee_probe(struct platform_device *pdev)
18151822
goto err_free_shm_pool;
18161823
}
18171824

1825+
optee_msg_get_os_revision(invoke_fn, &optee->revision);
1826+
18181827
optee->ops = &optee_ops;
18191828
optee->smc.invoke_fn = invoke_fn;
18201829
optee->smc.sec_caps = sec_caps;

drivers/tee/tee_core.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,56 @@ static struct attribute *tee_dev_attrs[] = {
11461146
NULL
11471147
};
11481148

1149-
ATTRIBUTE_GROUPS(tee_dev);
1149+
static const struct attribute_group tee_dev_group = {
1150+
.attrs = tee_dev_attrs,
1151+
};
1152+
1153+
static ssize_t revision_show(struct device *dev,
1154+
struct device_attribute *attr, char *buf)
1155+
{
1156+
struct tee_device *teedev = container_of(dev, struct tee_device, dev);
1157+
char version[TEE_REVISION_STR_SIZE];
1158+
int ret;
1159+
1160+
if (!teedev->desc->ops->get_tee_revision)
1161+
return -ENODEV;
1162+
1163+
ret = teedev->desc->ops->get_tee_revision(teedev, version,
1164+
sizeof(version));
1165+
if (ret)
1166+
return ret;
1167+
1168+
return sysfs_emit(buf, "%s\n", version);
1169+
}
1170+
static DEVICE_ATTR_RO(revision);
1171+
1172+
static struct attribute *tee_revision_attrs[] = {
1173+
&dev_attr_revision.attr,
1174+
NULL
1175+
};
1176+
1177+
static umode_t tee_revision_attr_is_visible(struct kobject *kobj,
1178+
struct attribute *attr, int n)
1179+
{
1180+
struct device *dev = kobj_to_dev(kobj);
1181+
struct tee_device *teedev = container_of(dev, struct tee_device, dev);
1182+
1183+
if (teedev->desc->ops->get_tee_revision)
1184+
return attr->mode;
1185+
1186+
return 0;
1187+
}
1188+
1189+
static const struct attribute_group tee_revision_group = {
1190+
.attrs = tee_revision_attrs,
1191+
.is_visible = tee_revision_attr_is_visible,
1192+
};
1193+
1194+
static const struct attribute_group *tee_dev_groups[] = {
1195+
&tee_dev_group,
1196+
&tee_revision_group,
1197+
NULL
1198+
};
11501199

11511200
static const struct class tee_class = {
11521201
.name = "tee",

include/linux/tee_core.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ struct tee_device {
7676
/**
7777
* struct tee_driver_ops - driver operations vtable
7878
* @get_version: returns version of driver
79+
* @get_tee_revision: returns revision string (diagnostic only);
80+
* do not infer feature support from this, use
81+
* TEE_IOC_VERSION instead
7982
* @open: called for a context when the device file is opened
8083
* @close_context: called when the device file is closed
8184
* @release: called to release the context
@@ -95,9 +98,12 @@ struct tee_device {
9598
* client closes the device file, even if there are existing references to the
9699
* context. The TEE driver can use @close_context to start cleaning up.
97100
*/
101+
98102
struct tee_driver_ops {
99103
void (*get_version)(struct tee_device *teedev,
100104
struct tee_ioctl_version_data *vers);
105+
int (*get_tee_revision)(struct tee_device *teedev,
106+
char *buf, size_t len);
101107
int (*open)(struct tee_context *ctx);
102108
void (*close_context)(struct tee_context *ctx);
103109
void (*release)(struct tee_context *ctx);
@@ -123,6 +129,9 @@ struct tee_driver_ops {
123129
int (*shm_unregister)(struct tee_context *ctx, struct tee_shm *shm);
124130
};
125131

132+
/* Size for TEE revision string buffer used by get_tee_revision(). */
133+
#define TEE_REVISION_STR_SIZE 128
134+
126135
/**
127136
* struct tee_desc - Describes the TEE driver to the subsystem
128137
* @name: name of driver

0 commit comments

Comments
 (0)