optee: add timeout parameter for notification wait

-----BEGIN PGP SIGNATURE-----
 
 iQJOBAABCgA4FiEEFV+gSSXZJY9ZyuB5LinzTIcAHJcFAmZ9M1IaHGplbnMud2lr
 bGFuZGVyQGxpbmFyby5vcmcACgkQLinzTIcAHJdnng/+JR9RDaFSfa02pnHPzSnX
 KQcIRL0YUv2go5RQHXC9lzN+t/oDo/pC4PGmxU3RQX/PQYFwGDWeer30VSdA8Emm
 zDNl+K2YTocGXvKB1dXWOwtNPtDYgKNkpsIk+RZQzsj/6mAsanCHP9cv0kAMPrVt
 Cv9tj7U8PcgD8OujqW0b7rq5CmgGJpGcOtk/I8E97pcBXbpPLLIGHlMFYeQZgelC
 4vd9RzOPGCEtKK79ZAh5rc7z7RymPDA1Ada2MYG/J54iiRe43xgRaCxiq2SuvNHq
 5yKL+ZDBo38ejAQwOV6xUsXo7XaOu6+seyVA/GGqBoB+RAPCjMGqzZmQDEJwYFQW
 2X8ViYXO3MMOPT9kmtt/1oPq50xP3EbvwnaOJws9fbSG+n6cc3ZmCB65ByaO8LbZ
 5/hu6zKZ+b5L0m3QSQjkanoVFwRm6oefeQB/kHHNqgzGEh9ijogWf1boWui2wKpF
 pO7ohQlxQzpkAvUF0HmWM4JmTSsmyYYMqbLRIJXJRTX/KdrHZFcS7NuRnOuXE3qf
 uyiXo4rzUZhtecgyCiTJ7Pb20NuvaWR49RADASk+D5OP6pfbhw0wVGP9Kc/icU9h
 AdUYUbGokrFxSCGYx/+wnBEuR5Nf1f35/9VWhs+UXkfuy38B6qxnv7/ePDD3/pcu
 VReDFHMF6GlWTXX1nRiLIWk=
 =mkge
 -----END PGP SIGNATURE-----
gpgsig -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEiK/NIGsWEZVxh/FrYKtH/8kJUicFAmZ9etUACgkQYKtH/8kJ
 UifBJRAAqh9Od+EkNpFSukrWorFUlt794wS/n6YxR2vWB+RJsQsbH1KIh+F5/GJl
 5RD97ZCfz095njxgTQD/344oldvAf1EBEkpyyebVn71pTAn2QpglrisI4t0lba4F
 nzlOtud7AEDReaPR1z5VUB/S2eF+33/N4/U8I7/JOiEjNmEK6UGPm9o/1T6UVxNv
 hIRpdNv3SBy/0KDv1SXlhLlXxIN5akNomPQncOGL2e7tLQgGIjGstvyADZ6fkSey
 hLvovuyRD06fLyqE+IhWmjwr0pgZ1kq32Cbeq2n2yns42hsy7wwelODcQibv5PYs
 +Vq+gbgCThxyRAL/8bsg0fR7sUSUm6UJ07MLFsP0J4U21wjqlr2VEKHNuurpAWPy
 /TAk8LqC7ZtxwfaT1c4yor0euGjCw8xBn4JjADLdixPCHPqOwBUvKCWxVP1HaTOc
 7u+ijpRRIZxNHsErbUP08TjXOEF3wi00sQygxZed0Sm8faQRfGRySiUQ3Lt6LJlv
 /wxXW9/ARW55K3AOoIsd47EG9MT+y3FwAc9R5NKIpHsshvCstgWnJgTCOuQaPyEo
 YyXYsiZlh94b308EwyIRnVmtbiby7htKbmD6DeC8CaBabMmvaaHTCH9wRyyi+w5J
 rLKqYqMTyCRnF/xILdq9fUmdG9I4FIQEBrQXrhIlpdwCg9a0dNs=
 =bm1W
 -----END PGP SIGNATURE-----

Merge tag 'optee-notif-wait-timeout-for-v6.11' of https://git.linaro.org/people/jens.wiklander/linux-tee into soc/drivers

optee: add timeout parameter for notification wait

* tag 'optee-notif-wait-timeout-for-v6.11' of https://git.linaro.org/people/jens.wiklander/linux-tee:
  optee: add timeout value to optee_notif_wait() to support timeout

Link: https://lore.kernel.org/r/20240627095325.GA2585076@rayden
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
This commit is contained in:
Arnd Bergmann 2024-06-27 16:44:37 +02:00
commit 30c577a852
4 changed files with 20 additions and 5 deletions

View File

@ -29,7 +29,7 @@ static bool have_key(struct optee *optee, u_int key)
return false;
}
int optee_notif_wait(struct optee *optee, u_int key)
int optee_notif_wait(struct optee *optee, u_int key, u32 timeout)
{
unsigned long flags;
struct notif_entry *entry;
@ -70,7 +70,12 @@ int optee_notif_wait(struct optee *optee, u_int key)
* Unlock temporarily and wait for completion.
*/
spin_unlock_irqrestore(&optee->notif.lock, flags);
wait_for_completion(&entry->c);
if (timeout != 0) {
if (!wait_for_completion_timeout(&entry->c, timeout))
rc = -ETIMEDOUT;
} else {
wait_for_completion(&entry->c);
}
spin_lock_irqsave(&optee->notif.lock, flags);
list_del(&entry->link);

View File

@ -26,6 +26,9 @@
#define TEEC_ERROR_BUSY 0xFFFF000D
#define TEEC_ERROR_SHORT_BUFFER 0xFFFF0010
/* API Return Codes are from the GP TEE Internal Core API Specification */
#define TEE_ERROR_TIMEOUT 0xFFFF3001
#define TEEC_ORIGIN_COMMS 0x00000002
/*
@ -252,7 +255,7 @@ struct optee_call_ctx {
int optee_notif_init(struct optee *optee, u_int max_key);
void optee_notif_uninit(struct optee *optee);
int optee_notif_wait(struct optee *optee, u_int key);
int optee_notif_wait(struct optee *optee, u_int key, u32 timeout);
int optee_notif_send(struct optee *optee, u_int key);
u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params,

View File

@ -41,6 +41,7 @@
* Waiting on notification
* [in] value[0].a OPTEE_RPC_NOTIFICATION_WAIT
* [in] value[0].b notification value
* [in] value[0].c timeout in milliseconds or 0 if no timeout
*
* Sending a synchronous notification
* [in] value[0].a OPTEE_RPC_NOTIFICATION_SEND

View File

@ -130,6 +130,8 @@ static void handle_rpc_func_cmd_i2c_transfer(struct tee_context *ctx,
static void handle_rpc_func_cmd_wq(struct optee *optee,
struct optee_msg_arg *arg)
{
int rc = 0;
if (arg->num_params != 1)
goto bad;
@ -139,7 +141,8 @@ static void handle_rpc_func_cmd_wq(struct optee *optee,
switch (arg->params[0].u.value.a) {
case OPTEE_RPC_NOTIFICATION_WAIT:
if (optee_notif_wait(optee, arg->params[0].u.value.b))
rc = optee_notif_wait(optee, arg->params[0].u.value.b, arg->params[0].u.value.c);
if (rc)
goto bad;
break;
case OPTEE_RPC_NOTIFICATION_SEND:
@ -153,7 +156,10 @@ static void handle_rpc_func_cmd_wq(struct optee *optee,
arg->ret = TEEC_SUCCESS;
return;
bad:
arg->ret = TEEC_ERROR_BAD_PARAMETERS;
if (rc == -ETIMEDOUT)
arg->ret = TEE_ERROR_TIMEOUT;
else
arg->ret = TEEC_ERROR_BAD_PARAMETERS;
}
static void handle_rpc_func_cmd_wait(struct optee_msg_arg *arg)