mirror of
https://github.com/torvalds/linux.git
synced 2026-03-08 04:04:43 +01:00
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 -----BEGIN PGP SIGNATURE----- iQJOBAABCgA4FiEE0qerISgy2SKkqO79Wr/6JGat8H4FAmlrgt0aHGplbnMud2lr bGFuZGVyQGxpbmFyby5vcmcACgkQWr/6JGat8H7ieA/+LWgQ6n9yUUxZ4hnK2538 lSg9vkBuGYeMcObNyKwtehB3+ivjtQB6ZTdV8OCVhduKFXLBb/6Iedf1zHrVrEi2 qXTZutfzPNFD4wfD+VvpfY3ydxbvB+xBOKwNEI+2mUnyxe7RiDWkMKKg6dS2p9uy dvs1+H9yYyL/jMecNbjrBaUFQ80YzHUakQ2ExHWRUZtUHKKVcELlbWzvNxfTa+Xo lyuhWFr9/u6loJ+kyMcq4vaesM8fdfq6ESaeoWGumFyviy3Ds/k9HNyTSwqHn/9S CfcG3souXA/9WUaH9q3pM8pb9VZHfYLIIPZ9LB0qePdJL82Fh16KGWnSEyQyEehJ fpOPui8LAP9siyR9Ett8i1vvXf2qquZxx5Ep+07u+Vx1ho6CfGL30hpzQTBJrHRI GfLyjfZYiR2sOkUE0sfFMxZDy6F5OOJL3/NIAXC4C7MLOFbeFChsbkd9Cz0K4kGA InPBVDVfIANBTGxsZT2YizLPar8Ui1X6L3o1nrb75qEJn86QUdzVgr20XuCfnRi1 W7QIa97QJGA8sBVHLEoZFRSDJjVJP+7vWK2hn6qW6iJiLMkuBoKY741WmEM1wEdW sgZ0D014Oxc7EstWPfbgkX5K/2ABsrtg6Lb1/X39N3uMkvaxRzwhyuCSjeVzlczv AoFdyelBnTLCWemZ/fI8goo= =8kDV -----END PGP SIGNATURE----- gpgsig -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEo6/YBQwIrVS28WGKmmx57+YAGNkFAmlw8S0ACgkQmmx57+YA GNm68A//auSP2t30O+WMO4biHofoKhkgeoj4IkuQKCReKeCukjCRy0Sh+S7XJkbv UYfPhUg44b9p3xjD+jugTv2FqCMV9ivdGAGOLIekEeknIKgHJ0sqCGpKgahL7w17 aWV2eGVe1tnA0RKx51ixHe9m38/esQsxCTFT3dS8RiKvfljhM+KXgH8pNy+aT+QO hazk0uWRsM5rYCbAL5vbt+zjt2lTO34cCp2+OM/18S1x4lgfW2kDQBYYtgAZvZJF MclDCvXP06SOakGmr5sAnRN943fH5zmEGbw1buoXjStsiJX4EHuccHtAmjvOwPD/ p7MKPiSn8WEdhNiLVk9XV/SSs+aYtT69c3uGjV+1MnhsB7RVjqA+xfhK8LZajseb r0ZSReUJF+KpguHqJfNj+bVQQm1KFRsIqurB0Cn7J+fwRAiS5D9Mqku/OGYso2GE RGPavlndN8ytZWJiYKyzsBOkAiYR0jejJbwMH8OA72/mcDsxibLafSr5DSeYpmmS AfXPGkZEluNYW0UccrsFov+rZ6AHiGCuElNVZ2W1l1QKc641aS1y1Ar987ysq1PC KrpSHDihrzbBcIgTKCQoL19vaqusOyDk6RB263zOLrgEWnelxVSLcQWEDTPjX9dV 4Ys/DE+O1dZIZ0Waq88InzpIZlUcLlVMJEEiXSRxIGskFYNgaZM= =lDdi -----END PGP SIGNATURE----- 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>
This commit is contained in:
commit
ee5dde7ed6
7 changed files with 163 additions and 18 deletions
|
|
@ -13,3 +13,13 @@ Description:
|
|||
space if the variable is absent. The primary purpose
|
||||
of this variable is to let systemd know whether
|
||||
tee-supplicant is needed in the early boot with initramfs.
|
||||
|
||||
What: /sys/class/tee/tee{,priv}X/revision
|
||||
Date: Jan 2026
|
||||
KernelVersion: 6.19
|
||||
Contact: op-tee@lists.trustedfirmware.org
|
||||
Description:
|
||||
Read-only revision string reported by the TEE driver. This is
|
||||
for diagnostics only and must not be used to infer feature
|
||||
support. Use TEE_IOC_VERSION for capability and compatibility
|
||||
checks.
|
||||
|
|
|
|||
|
|
@ -63,6 +63,29 @@ int optee_set_dma_mask(struct optee *optee, u_int pa_width)
|
|||
return dma_coerce_mask_and_coherent(&optee->teedev->dev, mask);
|
||||
}
|
||||
|
||||
int optee_get_revision(struct tee_device *teedev, char *buf, size_t len)
|
||||
{
|
||||
struct optee *optee = tee_get_drvdata(teedev);
|
||||
u64 build_id;
|
||||
|
||||
if (!optee)
|
||||
return -ENODEV;
|
||||
if (!buf || !len)
|
||||
return -EINVAL;
|
||||
|
||||
build_id = optee->revision.os_build_id;
|
||||
if (build_id)
|
||||
scnprintf(buf, len, "%u.%u (%016llx)",
|
||||
optee->revision.os_major,
|
||||
optee->revision.os_minor,
|
||||
(unsigned long long)build_id);
|
||||
else
|
||||
scnprintf(buf, len, "%u.%u", optee->revision.os_major,
|
||||
optee->revision.os_minor);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void optee_bus_scan(struct work_struct *work)
|
||||
{
|
||||
WARN_ON(optee_enumerate_devices(PTA_CMD_GET_DEVICES_SUPP));
|
||||
|
|
|
|||
|
|
@ -775,6 +775,39 @@ static int optee_ffa_reclaim_protmem(struct optee *optee,
|
|||
* with a matching configuration.
|
||||
*/
|
||||
|
||||
static bool optee_ffa_get_os_revision(struct ffa_device *ffa_dev,
|
||||
const struct ffa_ops *ops,
|
||||
struct optee_revision *revision)
|
||||
{
|
||||
const struct ffa_msg_ops *msg_ops = ops->msg_ops;
|
||||
struct ffa_send_direct_data data = {
|
||||
.data0 = OPTEE_FFA_GET_OS_VERSION,
|
||||
};
|
||||
int rc;
|
||||
|
||||
msg_ops->mode_32bit_set(ffa_dev);
|
||||
|
||||
rc = msg_ops->sync_send_receive(ffa_dev, &data);
|
||||
if (rc) {
|
||||
pr_err("Unexpected error %d\n", rc);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (revision) {
|
||||
revision->os_major = data.data0;
|
||||
revision->os_minor = data.data1;
|
||||
revision->os_build_id = data.data2;
|
||||
}
|
||||
|
||||
if (data.data2)
|
||||
pr_info("revision %lu.%lu (%08lx)",
|
||||
data.data0, data.data1, data.data2);
|
||||
else
|
||||
pr_info("revision %lu.%lu", data.data0, data.data1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool optee_ffa_api_is_compatible(struct ffa_device *ffa_dev,
|
||||
const struct ffa_ops *ops)
|
||||
{
|
||||
|
|
@ -798,20 +831,6 @@ static bool optee_ffa_api_is_compatible(struct ffa_device *ffa_dev,
|
|||
return false;
|
||||
}
|
||||
|
||||
data = (struct ffa_send_direct_data){
|
||||
.data0 = OPTEE_FFA_GET_OS_VERSION,
|
||||
};
|
||||
rc = msg_ops->sync_send_receive(ffa_dev, &data);
|
||||
if (rc) {
|
||||
pr_err("Unexpected error %d\n", rc);
|
||||
return false;
|
||||
}
|
||||
if (data.data2)
|
||||
pr_info("revision %lu.%lu (%08lx)",
|
||||
data.data0, data.data1, data.data2);
|
||||
else
|
||||
pr_info("revision %lu.%lu", data.data0, data.data1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -900,6 +919,7 @@ static int optee_ffa_open(struct tee_context *ctx)
|
|||
|
||||
static const struct tee_driver_ops optee_ffa_clnt_ops = {
|
||||
.get_version = optee_ffa_get_version,
|
||||
.get_tee_revision = optee_get_revision,
|
||||
.open = optee_ffa_open,
|
||||
.release = optee_release,
|
||||
.open_session = optee_open_session,
|
||||
|
|
@ -918,6 +938,7 @@ static const struct tee_desc optee_ffa_clnt_desc = {
|
|||
|
||||
static const struct tee_driver_ops optee_ffa_supp_ops = {
|
||||
.get_version = optee_ffa_get_version,
|
||||
.get_tee_revision = optee_get_revision,
|
||||
.open = optee_ffa_open,
|
||||
.release = optee_release_supp,
|
||||
.supp_recv = optee_supp_recv,
|
||||
|
|
@ -1060,6 +1081,11 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
|
|||
if (!optee)
|
||||
return -ENOMEM;
|
||||
|
||||
if (!optee_ffa_get_os_revision(ffa_dev, ffa_ops, &optee->revision)) {
|
||||
rc = -EINVAL;
|
||||
goto err_free_optee;
|
||||
}
|
||||
|
||||
pool = optee_ffa_shm_pool_alloc_pages();
|
||||
if (IS_ERR(pool)) {
|
||||
rc = PTR_ERR(pool);
|
||||
|
|
|
|||
|
|
@ -171,6 +171,24 @@ struct optee_ffa {
|
|||
|
||||
struct optee;
|
||||
|
||||
/**
|
||||
* struct optee_revision - 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_revision {
|
||||
u32 os_major;
|
||||
u32 os_minor;
|
||||
u64 os_build_id;
|
||||
};
|
||||
|
||||
int optee_get_revision(struct tee_device *teedev, char *buf, size_t len);
|
||||
|
||||
/**
|
||||
* struct optee_ops - OP-TEE driver internal operations
|
||||
* @do_call_with_arg: enters OP-TEE in secure world
|
||||
|
|
@ -249,6 +267,7 @@ struct optee {
|
|||
bool in_kernel_rpmb_routing;
|
||||
struct work_struct scan_bus_work;
|
||||
struct work_struct rpmb_scan_bus_work;
|
||||
struct optee_revision revision;
|
||||
};
|
||||
|
||||
struct optee_session {
|
||||
|
|
|
|||
|
|
@ -1242,6 +1242,7 @@ static int optee_smc_open(struct tee_context *ctx)
|
|||
|
||||
static const struct tee_driver_ops optee_clnt_ops = {
|
||||
.get_version = optee_get_version,
|
||||
.get_tee_revision = optee_get_revision,
|
||||
.open = optee_smc_open,
|
||||
.release = optee_release,
|
||||
.open_session = optee_open_session,
|
||||
|
|
@ -1261,6 +1262,7 @@ static const struct tee_desc optee_clnt_desc = {
|
|||
|
||||
static const struct tee_driver_ops optee_supp_ops = {
|
||||
.get_version = optee_get_version,
|
||||
.get_tee_revision = optee_get_revision,
|
||||
.open = optee_smc_open,
|
||||
.release = optee_release_supp,
|
||||
.supp_recv = optee_supp_recv,
|
||||
|
|
@ -1323,7 +1325,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_revision *revision)
|
||||
{
|
||||
union {
|
||||
struct arm_smccc_res smccc;
|
||||
|
|
@ -1337,6 +1340,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 (revision) {
|
||||
revision->os_major = res.result.major;
|
||||
revision->os_minor = res.result.minor;
|
||||
revision->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,
|
||||
|
|
@ -1745,8 +1754,6 @@ static int optee_probe(struct platform_device *pdev)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
optee_msg_get_os_revision(invoke_fn);
|
||||
|
||||
if (!optee_msg_api_revision_is_compatible(invoke_fn)) {
|
||||
pr_warn("api revision mismatch\n");
|
||||
return -EINVAL;
|
||||
|
|
@ -1815,6 +1822,8 @@ static int optee_probe(struct platform_device *pdev)
|
|||
goto err_free_shm_pool;
|
||||
}
|
||||
|
||||
optee_msg_get_os_revision(invoke_fn, &optee->revision);
|
||||
|
||||
optee->ops = &optee_ops;
|
||||
optee->smc.invoke_fn = invoke_fn;
|
||||
optee->smc.sec_caps = sec_caps;
|
||||
|
|
|
|||
|
|
@ -1146,7 +1146,56 @@ static struct attribute *tee_dev_attrs[] = {
|
|||
NULL
|
||||
};
|
||||
|
||||
ATTRIBUTE_GROUPS(tee_dev);
|
||||
static const struct attribute_group tee_dev_group = {
|
||||
.attrs = tee_dev_attrs,
|
||||
};
|
||||
|
||||
static ssize_t revision_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct tee_device *teedev = container_of(dev, struct tee_device, dev);
|
||||
char version[TEE_REVISION_STR_SIZE];
|
||||
int ret;
|
||||
|
||||
if (!teedev->desc->ops->get_tee_revision)
|
||||
return -ENODEV;
|
||||
|
||||
ret = teedev->desc->ops->get_tee_revision(teedev, version,
|
||||
sizeof(version));
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return sysfs_emit(buf, "%s\n", version);
|
||||
}
|
||||
static DEVICE_ATTR_RO(revision);
|
||||
|
||||
static struct attribute *tee_revision_attrs[] = {
|
||||
&dev_attr_revision.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static umode_t tee_revision_attr_is_visible(struct kobject *kobj,
|
||||
struct attribute *attr, int n)
|
||||
{
|
||||
struct device *dev = kobj_to_dev(kobj);
|
||||
struct tee_device *teedev = container_of(dev, struct tee_device, dev);
|
||||
|
||||
if (teedev->desc->ops->get_tee_revision)
|
||||
return attr->mode;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct attribute_group tee_revision_group = {
|
||||
.attrs = tee_revision_attrs,
|
||||
.is_visible = tee_revision_attr_is_visible,
|
||||
};
|
||||
|
||||
static const struct attribute_group *tee_dev_groups[] = {
|
||||
&tee_dev_group,
|
||||
&tee_revision_group,
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct class tee_class = {
|
||||
.name = "tee",
|
||||
|
|
|
|||
|
|
@ -76,6 +76,9 @@ struct tee_device {
|
|||
/**
|
||||
* struct tee_driver_ops - driver operations vtable
|
||||
* @get_version: returns version of driver
|
||||
* @get_tee_revision: returns revision string (diagnostic only);
|
||||
* do not infer feature support from this, use
|
||||
* TEE_IOC_VERSION instead
|
||||
* @open: called for a context when the device file is opened
|
||||
* @close_context: called when the device file is closed
|
||||
* @release: called to release the context
|
||||
|
|
@ -95,9 +98,12 @@ struct tee_device {
|
|||
* client closes the device file, even if there are existing references to the
|
||||
* context. The TEE driver can use @close_context to start cleaning up.
|
||||
*/
|
||||
|
||||
struct tee_driver_ops {
|
||||
void (*get_version)(struct tee_device *teedev,
|
||||
struct tee_ioctl_version_data *vers);
|
||||
int (*get_tee_revision)(struct tee_device *teedev,
|
||||
char *buf, size_t len);
|
||||
int (*open)(struct tee_context *ctx);
|
||||
void (*close_context)(struct tee_context *ctx);
|
||||
void (*release)(struct tee_context *ctx);
|
||||
|
|
@ -123,6 +129,9 @@ struct tee_driver_ops {
|
|||
int (*shm_unregister)(struct tee_context *ctx, struct tee_shm *shm);
|
||||
};
|
||||
|
||||
/* Size for TEE revision string buffer used by get_tee_revision(). */
|
||||
#define TEE_REVISION_STR_SIZE 128
|
||||
|
||||
/**
|
||||
* struct tee_desc - Describes the TEE driver to the subsystem
|
||||
* @name: name of driver
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue