hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/tee/optee/supp.c
....@@ -1,15 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2015, Linaro Limited
3
- *
4
- * This software is licensed under the terms of the GNU General Public
5
- * License version 2, as published by the Free Software Foundation, and
6
- * may be copied, distributed, and modified under those terms.
7
- *
8
- * This program is distributed in the hope that it will be useful,
9
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- * GNU General Public License for more details.
12
- *
134 */
145 #include <linux/device.h>
156 #include <linux/slab.h>
....@@ -88,10 +79,21 @@
8879 {
8980 struct optee *optee = tee_get_drvdata(ctx->teedev);
9081 struct optee_supp *supp = &optee->supp;
91
- struct optee_supp_req *req = kzalloc(sizeof(*req), GFP_KERNEL);
82
+ struct optee_supp_req *req;
9283 bool interruptable;
9384 u32 ret;
85
+ unsigned long timeleft;
86
+ int id;
87
+ struct optee_supp_req *get_req;
9488
89
+ /*
90
+ * Return in case there is no supplicant available and
91
+ * non-blocking request.
92
+ */
93
+ if (!supp->ctx && ctx->supp_nowait)
94
+ return TEEC_ERROR_COMMUNICATION;
95
+
96
+ req = kzalloc(sizeof(*req), GFP_KERNEL);
9597 if (!req)
9698 return TEEC_ERROR_OUT_OF_MEMORY;
9799
....@@ -115,8 +117,17 @@
115117 * exclusive access again.
116118 */
117119 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
+
118130 mutex_lock(&supp->mutex);
119
- interruptable = !supp->ctx;
120131 if (interruptable) {
121132 /*
122133 * There's no supplicant available and since the
....@@ -135,6 +146,14 @@
135146 list_del(&req->link);
136147 req->in_queue = false;
137148 }
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
+ }
138157 }
139158 mutex_unlock(&supp->mutex);
140159