hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/tee/optee/call.c
....@@ -1,21 +1,13 @@
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/arm-smccc.h>
156 #include <linux/device.h>
167 #include <linux/err.h>
178 #include <linux/errno.h>
189 #include <linux/mm.h>
10
+#include <linux/sched.h>
1911 #include <linux/slab.h>
2012 #include <linux/tee_drv.h>
2113 #include <linux/types.h>
....@@ -157,6 +149,8 @@
157149 */
158150 optee_cq_wait_for_completion(&optee->call_queue, &w);
159151 } else if (OPTEE_SMC_RETURN_IS_RPC(res.a0)) {
152
+ if (need_resched())
153
+ cond_resched();
160154 param.a0 = res.a0;
161155 param.a1 = res.a1;
162156 param.a2 = res.a2;
....@@ -187,7 +181,7 @@
187181 struct optee_msg_arg *ma;
188182
189183 shm = tee_shm_alloc(ctx, OPTEE_MSG_GET_ARG_SIZE(num_params),
190
- TEE_SHM_MAPPED);
184
+ TEE_SHM_MAPPED | TEE_SHM_PRIV);
191185 if (IS_ERR(shm))
192186 return shm;
193187
....@@ -223,6 +217,7 @@
223217 struct optee_msg_arg *msg_arg;
224218 phys_addr_t msg_parg;
225219 struct optee_session *sess = NULL;
220
+ uuid_t client_uuid;
226221
227222 /* +2 for the meta parameters added below */
228223 shm = get_msg_arg(ctx, arg->num_params + 2, &msg_arg, &msg_parg);
....@@ -241,8 +236,13 @@
241236 msg_arg->params[1].attr = OPTEE_MSG_ATTR_TYPE_VALUE_INPUT |
242237 OPTEE_MSG_ATTR_META;
243238 memcpy(&msg_arg->params[0].u.value, arg->uuid, sizeof(arg->uuid));
244
- memcpy(&msg_arg->params[1].u.value, arg->uuid, sizeof(arg->clnt_uuid));
245239 msg_arg->params[1].u.value.c = arg->clnt_login;
240
+
241
+ rc = tee_session_calc_client_uuid(&client_uuid, arg->clnt_login,
242
+ arg->clnt_uuid);
243
+ if (rc)
244
+ goto out;
245
+ export_uuid(msg_arg->params[1].u.octets, &client_uuid);
246246
247247 rc = optee_to_msg_param(msg_arg->params + 2, arg->num_params, param);
248248 if (rc)
....@@ -593,10 +593,17 @@
593593 struct mm_struct *mm = current->mm;
594594 int rc;
595595
596
- down_read(&mm->mmap_sem);
596
+ /*
597
+ * Allow kernel address to register with OP-TEE as kernel
598
+ * pages are configured as normal memory only.
599
+ */
600
+ if (virt_addr_valid(start))
601
+ return 0;
602
+
603
+ mmap_read_lock(mm);
597604 rc = __check_mem_type(find_vma(mm, start),
598605 start + num_pages * PAGE_SIZE);
599
- up_read(&mm->mmap_sem);
606
+ mmap_read_unlock(mm);
600607
601608 return rc;
602609 }