]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
tee: add revision sysfs attribute
authorAristo Chen <aristo.chen@canonical.com>
Mon, 12 Jan 2026 15:48:29 +0000 (23:48 +0800)
committerJens Wiklander <jens.wiklander@linaro.org>
Wed, 14 Jan 2026 11:04:34 +0000 (12:04 +0100)
Add a generic TEE revision sysfs attribute backed by a new
optional get_tee_revision() callback. The revision string is
diagnostic-only and must not be used to infer feature support.

Signed-off-by: Aristo Chen <aristo.chen@canonical.com>
Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Documentation/ABI/testing/sysfs-class-tee
drivers/tee/tee_core.c
include/linux/tee_core.h

index c9144d16003e6f7a53b8d35e2fc0c96284da15a8..1a0a3050aaa9b2af1c9b7f38958c78658b07bb51 100644 (file)
@@ -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.
index d65d47cc154e34cd02037525b68a640b8f5ee99f..0a00499811c1f5da63a3cd8ecb7393556cef993b 100644 (file)
@@ -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",
index 1f3e5dad6d0d94aba05e474bfb12ad91de8f4f01..ee5f0bd41f43aaaf6a18111dc53bfdb81b16abaf 100644 (file)
@@ -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