History

tee: enable support to register kernel memory

Enable support to register kernel memory reference with TEE. This change will allow TEE bus drivers to register memory references.

Sumit Garg committed 6 years ago

Commit 2a6ba3f1 parent ae83d0b2 files · +26 −3Browse files

Unified · Split

2 files
  1. drivers/tee/tee_shm.c +25 −3
  2. include/linux/tee_drv.h +1 −0
drivers/tee/tee_shm.c+25−3
@@ -9,6 +9,7 @@ · 8 unmodified lines
99 #include <linux/sched.h>
1010 #include <linux/slab.h>
1111 #include <linux/tee_drv.h>
12+#include <linux/uio.h>
1213 #include "tee_private.h"
1314
1415 static void tee_shm_release(struct tee_shm *shm)
@@ -185,14 +186,15 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, · 170 unmodified lines
185186 size_t length, u32 flags)
186187 {
187188 struct tee_device *teedev = ctx->teedev;
188− const u32 req_flags = TEE_SHM_DMA_BUF | TEE_SHM_USER_MAPPED;
189+ const u32 req_user_flags = TEE_SHM_DMA_BUF | TEE_SHM_USER_MAPPED;
190+ const u32 req_kernel_flags = TEE_SHM_DMA_BUF | TEE_SHM_KERNEL_MAPPED;
189191 struct tee_shm *shm;
190192 void *ret;
191193 int rc;
192194 int num_pages;
193195 unsigned long start;
194196
195− if (flags != req_flags)
197+ if (flags != req_user_flags && flags != req_kernel_flags)
196198 return ERR_PTR(-ENOTSUPP);
197199
198200 if (!tee_device_get(teedev))
@@ -226,7 +228,27 @@ struct tee_shm *tee_shm_register(struct tee_context *ctx, unsigned long addr, · 27 unmodified lines
226228 goto err;
227229 }
228230
229− rc = get_user_pages_fast(start, num_pages, FOLL_WRITE, shm->pages);
231+ if (flags & TEE_SHM_USER_MAPPED) {
232+ rc = get_user_pages_fast(start, num_pages, FOLL_WRITE,
233+ shm->pages);
234+ } else {
235+ struct kvec *kiov;
236+ int i;
237+
238+ kiov = kcalloc(num_pages, sizeof(*kiov), GFP_KERNEL);
239+ if (!kiov) {
240+ ret = ERR_PTR(-ENOMEM);
241+ goto err;
242+ }
243+
244+ for (i = 0; i < num_pages; i++) {
245+ kiov[i].iov_base = (void *)(start + i * PAGE_SIZE);
246+ kiov[i].iov_len = PAGE_SIZE;
247+ }
248+
249+ rc = get_kernel_pages(kiov, num_pages, 0, shm->pages);
250+ kfree(kiov);
251+ }
230252 if (rc > 0)
231253 shm->num_pages = rc;
232254 if (rc != num_pages) {
include/linux/tee_drv.h+1−0
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 #define TEE_SHM_REGISTER BIT(3) /* Memory registered in secure world */
2727 #define TEE_SHM_USER_MAPPED BIT(4) /* Memory mapped in user space */
2828 #define TEE_SHM_POOL BIT(5) /* Memory allocated from pool */
29+#define TEE_SHM_KERNEL_MAPPED BIT(6) /* Memory mapped in kernel space */
2930
3031 struct device;
3132 struct tee_device;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t