optee: add timeout value to optee_notif_wait() to support timeout
Subsystems (3)
PATCH v3 1/1 optee: add timeout value to optee_notif_wait() to support timeout
From: Gavin Liu <[email protected]>
Add timeout value to support self waking when timeout to avoid waiting indefinitely.
---
change in v3:
1. change the comment in optee_rpc_cmd.h
2. add macro for "TEE_ERROR_TIMEOUT"
3. change from "TEEC_ERROR_BUSY" to "TEE_ERROR_TIMEOUT"
--- drivers/tee/optee/notif.c | 9 +++++++-- drivers/tee/optee/optee_private.h | 5 ++++- drivers/tee/optee/optee_rpc_cmd.h | 1 + drivers/tee/optee/rpc.c | 10 ++++++++-- 4 files changed, 20 insertions(+), 5 deletions(-)
drivers/tee/optee/notif.c +7 -2
@@ -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);
drivers/tee/optee/optee_private.h +4 -1
@@ -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,
drivers/tee/optee/optee_rpc_cmd.h +1 -0
@@ -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
drivers/tee/optee/rpc.c +8 -2
@@ -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)
Signature · 1 line
2.18.0
Hi,
Quoted 12 lines · gavin.liu
From: Gavin Liu <[email protected]>
Add timeout value to support self waking when timeout to avoid waiting indefinitely.
Signed-off-by Gavin Liu <[email protected]>---
change in v3:
1. change the comment inoptee_rpc_cmd.h
2. add macro for "TEE_ERROR_TIMEOUT"
3. change from "TEEC_ERROR_BUSY" to "TEE_ERROR_TIMEOUT"
Quoted 7 lines
--- drivers/tee/optee/notif.c | 9 +++++++-- drivers/tee/optee/optee_private.h | 5 ++++- drivers/tee/optee/optee_rpc_cmd.h | 1 + drivers/tee/optee/rpc.c | 10 ++++++++-- 4 files changed, 20 insertions(+), 5 deletions(-)
Although the change looks reasonable to me, can you point me to corresponding OP-TEE OS changes to be sure that ABI compatibility is maintained?
-Sumit
Quoted 100 lines
drivers/tee/optee/notif.c +7
-2@@ -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);drivers/tee/optee/optee_private.h +4
-1@@ -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,drivers/tee/optee/optee_rpc_cmd.h +1
-0@@ -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 drivers/tee/optee/rpc.c +8
-3@@ -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) --2.18.0
Hi, Sumit,
The corresponding OPTEE-OS pull request and change is here.
https://github.com/OP-TEE/optee_os/pull/6641
Quoted 121 lines · Sumit Garg
External email : Please do not click links or open attachments until you have verified the sender or the content.
Hi,Quoted 4 lines · gavin.liu
From: Gavin Liu <[email protected]>
Add timeout value to support self waking when timeout to avoid
waiting
Quoted 8 lines
indefinitely.
Signed-off-by Gavin Liu <[email protected]>---
change in v3:
1. change the comment inoptee_rpc_cmd.h
2. add macro for "TEE_ERROR_TIMEOUT"
3. change from "TEEC_ERROR_BUSY" to "TEE_ERROR_TIMEOUT"Quoted 7 lines
--- drivers/tee/optee/notif.c | 9 +++++++-- drivers/tee/optee/optee_private.h | 5 ++++- drivers/tee/optee/optee_rpc_cmd.h | 1 + drivers/tee/optee/rpc.c | 10 ++++++++-- 4 files changed, 20 insertions(+), 5 deletions(-)Although the change looks reasonable to me, can you point me to corresponding OP-TEE OS changes to be sure that ABI compatibility is maintained?
-Sumit
drivers/tee/optee/notif.c static bool have_key(struct optee *optee, u_int
Quoted 5 lines
drivers/tee/optee/notif.c +0
-0@@ -29,7 +29,7 @@ static bool have_key(struct optee *optee, u_intkey)
drivers/tee/optee/notif.c int optee_notif_wait(struct optee *optee, u_int
Quoted 9 lines
drivers/tee/optee/notif.c +1
-1return 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_intkey)
drivers/tee/optee/notif.c int optee_notif_wait(struct optee *optee, u_int key)
Quoted 6 lines
drivers/tee/optee/notif.c +2
-1* 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))
Review
Quoted 8 lines
drivers/tee/optee/notif.c +4
-0+ rc = -ETIMEDOUT ; + }else { +wait_for_completion (&entry->c); + }spin_lock_irqsave (&optee->notif.lock, flags);list_del (&entry->link);(quoted diff) +0
-0
b/drivers/tee/optee/optee_private.hdrivers/tee/optee/optee_private.h line 29
Quoted 8 lines
index
429cc20be5cc..424898cdc4e9100644drivers/tee/optee/optee_private.h +1
-0@@ -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 */
Quoted 6 lines
drivers/tee/optee/optee_private.h +2
-0+#define TEE_ERROR_TIMEOUT 0xFFFF3001 +#define TEEC_ORIGIN_COMMS 0x00000002/* drivers/tee/optee/optee_private.h struct optee_call_ctx { · line 261
Quoted 8 lines
drivers/tee/optee/optee_private.h +1
-1@@ -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,Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/tee/optee/optee_rpc_cmd.hdrivers/tee/optee/optee_rpc_cmd.h line 44
Quoted 8 lines
index
f3f06e0994a7..4576751b490c100644drivers/tee/optee/optee_rpc_cmd.h +1
-0@@ -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
drivers/tee/optee/rpc.c static void
Quoted 8 lines
drivers/tee/optee/optee_rpc_cmd.h +0
-0* * Sending a synchronous notification * [in] value[0].a OPTEE_RPC_NOTIFICATION_SEND drivers/tee/optee/rpc.c +0
-0@@ -130,6 +130,8 @@ static voidhandle_rpc_func_cmd_i2c_transfer(struct
tee_context*ctx,drivers/tee/optee/rpc.c static void handle_rpc_func_cmd_wq(struct optee
Quoted 9 lines
drivers/tee/optee/rpc.c +2
-0static 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,
Quoted 1 line
Quoted 25 lines
drivers/tee/optee/rpc.c static void handle_rpc_func_cmd_wq(struct
Quoted 11 lines
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);drivers/tee/optee/rpc.c +1
-0+if (rc) goto bad;break ;case OPTEE_RPC_NOTIFICATION_SEND :@@ -153,7 +156,10 @@ static void handle_rpc_func_cmd_wq(structoptee *optee,
Quoted 13 lines
drivers/tee/optee/rpc.c +4
-2arg->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) --2.18.0
Regards,
Gavin Liu
Quoted 1 line
Quoted 1 line
Sumit Garg
Reviewed-byQuoted 6 lines · Gavin Liu (劉哲廷)
Hi, Sumit,
The corresponding OPTEE-OS pull request and change is here.
As this is an ABI change where I see backwards compatibility is maintained. However, the forwards compatibility requires this change to be backported to stable releases. So for the next version please CC stable ML.
Quoted 16 lines · Sumit Garg
Quoted 14 lines
External email : Please do not click links or open attachments until you have verified the sender or the content.
Hi,Quoted 4 lines · gavin.liu
From: Gavin Liu <[email protected]>
Add timeout value to support self waking when timeout to avoid
waiting
Quoted 2 lines
indefinitely.
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Signed-off-by Gavin Liu <[email protected]>---
change in v3:
1. change the comment inoptee_rpc_cmd.h
2. add macro for "TEE_ERROR_TIMEOUT"Quoted 8 lines
Quoted 8 lines
3. change from "
TEEC_ERROR_BUSY" to "TEE_ERROR_TIMEOUT"--- drivers/tee/optee/notif.c | 9 +++++++-- drivers/tee/optee/optee_private.h | 5 ++++- drivers/tee/optee/optee_rpc_cmd.h | 1 + drivers/tee/optee/rpc.c | 10 ++++++++-- 4 files changed, 20 insertions(+), 5 deletions(-)
FWIW:
Quoted 118 lines
Quoted 88 lines
drivers/tee/optee/notif.c static bool have_key(struct optee *optee, u_int
Quoted 6 lines
drivers/tee/optee/notif.c +0
-0@@ -29,7 +29,7 @@ static bool have_key(struct optee *optee, u_intkey)
drivers/tee/optee/notif.c int optee_notif_wait(struct optee *optee, u_int
Quoted 9 lines
drivers/tee/optee/notif.c +1
-1return 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_intkey)
drivers/tee/optee/notif.c int optee_notif_wait(struct optee *optee, u_int key)
Quoted 6 lines
drivers/tee/optee/notif.c +2
-1* 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))
Review
Quoted 8 lines
drivers/tee/optee/notif.c +4
-0+ rc = -ETIMEDOUT ; + }else { +wait_for_completion (&entry->c); + }spin_lock_irqsave (&optee->notif.lock, flags);list_del (&entry->link);(quoted diff) +0
-0
b/drivers/tee/optee/optee_private.hdrivers/tee/optee/optee_private.h line 29
Quoted 8 lines
index
429cc20be5cc..424898cdc4e9100644drivers/tee/optee/optee_private.h +1
-0@@ -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 */
Quoted 6 lines
drivers/tee/optee/optee_private.h +2
-0+#define TEE_ERROR_TIMEOUT 0xFFFF3001 +#define TEEC_ORIGIN_COMMS 0x00000002/* drivers/tee/optee/optee_private.h struct optee_call_ctx { · line 261
Quoted 8 lines
drivers/tee/optee/optee_private.h +1
-1@@ -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,Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/tee/optee/optee_rpc_cmd.hdrivers/tee/optee/optee_rpc_cmd.h line 44
Quoted 8 lines
index
f3f06e0994a7..4576751b490c100644drivers/tee/optee/optee_rpc_cmd.h +1
-0@@ -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
drivers/tee/optee/rpc.c static void
Quoted 8 lines
drivers/tee/optee/optee_rpc_cmd.h +0
-0* * Sending a synchronous notification * [in] value[0].a OPTEE_RPC_NOTIFICATION_SEND drivers/tee/optee/rpc.c +0
-0@@ -130,6 +130,8 @@ static voidhandle_rpc_func_cmd_i2c_transfer(struct
tee_context*ctx,drivers/tee/optee/rpc.c static void handle_rpc_func_cmd_wq(struct optee
Quoted 9 lines
drivers/tee/optee/rpc.c +2
-0static 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,
Quoted 1 line
Quoted 25 lines
drivers/tee/optee/rpc.c static void handle_rpc_func_cmd_wq(struct
Quoted 11 lines
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);drivers/tee/optee/rpc.c +1
-0+if (rc) goto bad;break ;case OPTEE_RPC_NOTIFICATION_SEND :@@ -153,7 +156,10 @@ static void handle_rpc_func_cmd_wq(structoptee *optee,
Quoted 13 lines
drivers/tee/optee/rpc.c +4
-2arg->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) --2.18.0
Regards,
Gavin LiuQuoted 1 line
Quoted 1 line
Quoted 12 lines
************* MEDIATEK Confidentiality Notice ******************** The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!
This text is not meant for public mailing lists. So please work with your IT team to allow you to post to public mailing lists without this text.
-Sumit
Quoted 44 lines · Sumit Garg
Quoted 6 lines · Gavin Liu (劉哲廷)
Hi, Sumit,
The corresponding OPTEE-OS pull request and change is here.
As this is an ABI change where I see backwards compatibility is maintained. However, the forwards compatibility requires this change to be backported to stable releases. So for the next version please CC stable ML.
Quoted 16 lines · Sumit Garg
Quoted 14 lines
External email : Please do not click links or open attachments until you have verified the sender or the content.
Hi,Quoted 4 lines · gavin.liu
From: Gavin Liu <[email protected]>
Add timeout value to support self waking when timeout to avoid
waiting
Quoted 2 lines
indefinitely.
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Signed-off-by Gavin Liu <[email protected]>---
change in v3:
1. change the comment inoptee_rpc_cmd.h
2. add macro for "TEE_ERROR_TIMEOUT"Quoted 8 lines
Quoted 8 lines
3. change from "
TEEC_ERROR_BUSY" to "TEE_ERROR_TIMEOUT"--- drivers/tee/optee/notif.c | 9 +++++++-- drivers/tee/optee/optee_private.h | 5 ++++- drivers/tee/optee/optee_rpc_cmd.h | 1 + drivers/tee/optee/rpc.c | 10 ++++++++-- 4 files changed, 20 insertions(+), 5 deletions(-)
Quoted 3 lines
FWIW:
Reviewed-by Sumit Garg <[email protected]>
I'm picking up this.
Thanks,
Jens