Skip to content

Commit 7269cba

Browse files
b49020jenswi-linaro
authored andcommitted
tee: optee: Fix supplicant based device enumeration
Currently supplicant dependent optee device enumeration only registers devices whenever tee-supplicant is invoked for the first time. But it forgets to remove devices when tee-supplicant daemon stops running and closes its context gracefully. This leads to following error for fTPM driver during reboot/shutdown: [ 73.466791] tpm tpm0: ftpm_tee_tpm_op_send: SUBMIT_COMMAND invoke error: 0xffff3024 Fix this by adding an attribute for supplicant dependent devices so that the user-space service can detect and detach supplicant devices before closing the supplicant: $ for dev in /sys/bus/tee/devices/*; do if [[ -f "$dev/need_supplicant" && -f "$dev/driver/unbind" ]]; \ then echo $(basename "$dev") > $dev/driver/unbind; fi done Reported-by: Jan Kiszka <[email protected]> Closes: OP-TEE/optee_os#6094 Fixes: 5f178bb ("optee: enable support for multi-stage bus enumeration") Signed-off-by: Sumit Garg <[email protected]> Reviewed-by: Ilias Apalodimas <[email protected]> Acked-by: Jerome Forissier <[email protected]> [jw: fixed up Date documentation] Signed-off-by: Jens Wiklander <[email protected]>
1 parent ffc2532 commit 7269cba

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

Documentation/ABI/testing/sysfs-bus-optee-devices

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,12 @@ Description:
66
OP-TEE bus provides reference to registered drivers under this directory. The <uuid>
77
matches Trusted Application (TA) driver and corresponding TA in secure OS. Drivers
88
are free to create needed API under optee-ta-<uuid> directory.
9+
10+
What: /sys/bus/tee/devices/optee-ta-<uuid>/need_supplicant
11+
Date: November 2023
12+
KernelVersion: 6.7
13+
14+
Description:
15+
Allows to distinguish whether an OP-TEE based TA/device requires user-space
16+
tee-supplicant to function properly or not. This attribute will be present for
17+
devices which depend on tee-supplicant to be running.

drivers/tee/optee/device.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@ static void optee_release_device(struct device *dev)
6060
kfree(optee_device);
6161
}
6262

63-
static int optee_register_device(const uuid_t *device_uuid)
63+
static ssize_t need_supplicant_show(struct device *dev,
64+
struct device_attribute *attr,
65+
char *buf)
66+
{
67+
return 0;
68+
}
69+
70+
static DEVICE_ATTR_RO(need_supplicant);
71+
72+
static int optee_register_device(const uuid_t *device_uuid, u32 func)
6473
{
6574
struct tee_client_device *optee_device = NULL;
6675
int rc;
@@ -83,6 +92,10 @@ static int optee_register_device(const uuid_t *device_uuid)
8392
put_device(&optee_device->dev);
8493
}
8594

95+
if (func == PTA_CMD_GET_DEVICES_SUPP)
96+
device_create_file(&optee_device->dev,
97+
&dev_attr_need_supplicant);
98+
8699
return rc;
87100
}
88101

@@ -142,7 +155,7 @@ static int __optee_enumerate_devices(u32 func)
142155
num_devices = shm_size / sizeof(uuid_t);
143156

144157
for (idx = 0; idx < num_devices; idx++) {
145-
rc = optee_register_device(&device_uuid[idx]);
158+
rc = optee_register_device(&device_uuid[idx], func);
146159
if (rc)
147160
goto out_shm;
148161
}

0 commit comments

Comments
 (0)