Skip to content

Commit 70b0d6b

Browse files
b49020arndb
authored andcommitted
tee: optee: Fix supplicant wait loop
OP-TEE supplicant is a user-space daemon and it's possible for it be hung or crashed or killed in the middle of processing an OP-TEE RPC call. It becomes more complicated when there is incorrect shutdown ordering of the supplicant process vs the OP-TEE client application which can eventually lead to system hang-up waiting for the closure of the client application. Allow the client process waiting in kernel for supplicant response to be killed rather than indefinitely waiting in an unkillable state. Also, a normal uninterruptible wait should not have resulted in the hung-task watchdog getting triggered, but the endless loop would. This fixes issues observed during system reboot/shutdown when supplicant got hung for some reason or gets crashed/killed which lead to client getting hung in an unkillable state. It in turn lead to system being in hung up state requiring hard power off/on to recover. Fixes: 4fb0a5e ("tee: add OP-TEE driver") Suggested-by: Arnd Bergmann <arnd@arndb.de> Cc: stable@vger.kernel.org Signed-off-by: Sumit Garg <sumit.garg@linaro.org> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
1 parent dd0f05b commit 70b0d6b

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

drivers/tee/optee/supp.c

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params,
8080
struct optee *optee = tee_get_drvdata(ctx->teedev);
8181
struct optee_supp *supp = &optee->supp;
8282
struct optee_supp_req *req;
83-
bool interruptable;
8483
u32 ret;
8584

8685
/*
@@ -111,36 +110,18 @@ u32 optee_supp_thrd_req(struct tee_context *ctx, u32 func, size_t num_params,
111110
/*
112111
* Wait for supplicant to process and return result, once we've
113112
* returned from wait_for_completion(&req->c) successfully we have
114-
* exclusive access again.
113+
* exclusive access again. Allow the wait to be killable such that
114+
* the wait doesn't turn into an indefinite state if the supplicant
115+
* gets hung for some reason.
115116
*/
116-
while (wait_for_completion_interruptible(&req->c)) {
117+
if (wait_for_completion_killable(&req->c)) {
117118
mutex_lock(&supp->mutex);
118-
interruptable = !supp->ctx;
119-
if (interruptable) {
120-
/*
121-
* There's no supplicant available and since the
122-
* supp->mutex currently is held none can
123-
* become available until the mutex released
124-
* again.
125-
*
126-
* Interrupting an RPC to supplicant is only
127-
* allowed as a way of slightly improving the user
128-
* experience in case the supplicant hasn't been
129-
* started yet. During normal operation the supplicant
130-
* will serve all requests in a timely manner and
131-
* interrupting then wouldn't make sense.
132-
*/
133-
if (req->in_queue) {
134-
list_del(&req->link);
135-
req->in_queue = false;
136-
}
119+
if (req->in_queue) {
120+
list_del(&req->link);
121+
req->in_queue = false;
137122
}
138123
mutex_unlock(&supp->mutex);
139-
140-
if (interruptable) {
141-
req->ret = TEEC_ERROR_COMMUNICATION;
142-
break;
143-
}
124+
req->ret = TEEC_ERROR_COMMUNICATION;
144125
}
145126

146127
ret = req->ret;

0 commit comments

Comments
 (0)