Skip to content

Commit e6c7ea7

Browse files
Hisping Linrkhuangtao
authored andcommitted
tee: optee: interrupt an RPC when supplicant has been killed
check supplicant is dead or alive when get signal, run normal program if supplicant is alive, interrupting an RPC if supplicant is dead, Otherwise, the current thread will be stuck in the optee driver. The error is printed as follows: INFO: task gatekeeper@1.0-:461 blocked for more than 20 seconds. Not tainted 5.10.66 friendlyarm#2 task:gatekeeper@1.0- state:D stack: 0 pid: 461 ppid: 1 flags:0x0400002d Call trace: switch_to+0x180/0x230 __schedule+0x49c/0x704 schedule+0xa0/0xe8 schedule_timeout+0x38/0x124 wait_for_common+0xa4/0x134 wait_for_completion+0x1c/0x2c optee_handle_rpc+0x1a4/0x6ec optee_do_call_with_arg+0x1a4/0x298 optee_release+0x134/0x1bc tee_release+0xa4/0x100 Change-Id: I2f82338ecccc1bc97bb5a6c25767eca4542cbcdf Signed-off-by: Hisping Lin <hisping.lin@rock-chips.com>
1 parent 2c94291 commit e6c7ea7

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

drivers/tee/optee/supp.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params,
8282
struct optee_supp_req *req;
8383
bool interruptable;
8484
u32 ret;
85+
unsigned long timeleft;
86+
int id;
87+
struct optee_supp_req *get_req;
8588

8689
/*
8790
* Return in case there is no supplicant available and
@@ -114,8 +117,17 @@ u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params,
114117
* exclusive access again.
115118
*/
116119
while (wait_for_completion_interruptible(&req->c)) {
120+
pr_err("Warning, Interrupting an RPC to supplicant!\n");
121+
timeleft = wait_for_completion_timeout(&req->c, msecs_to_jiffies(2000));
122+
if (timeleft) {
123+
/* get completion, it means tee-supplicant is alive. */
124+
break;
125+
} else {
126+
/* timeout, it means tee-supplicant is dead, interrupting an RPC. */
127+
interruptable = true;
128+
}
129+
117130
mutex_lock(&supp->mutex);
118-
interruptable = !supp->ctx;
119131
if (interruptable) {
120132
/*
121133
* There's no supplicant available and since the
@@ -134,6 +146,14 @@ u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params,
134146
list_del(&req->link);
135147
req->in_queue = false;
136148
}
149+
150+
idr_for_each_entry(&supp->idr, get_req, id) {
151+
if (get_req == req) {
152+
idr_remove(&supp->idr, id);
153+
supp->req_id = -1;
154+
break;
155+
}
156+
}
137157
}
138158
mutex_unlock(&supp->mutex);
139159

0 commit comments

Comments
 (0)