Skip to content

Commit a249dd2

Browse files
b49020jenswi-linaro
authored andcommitted
tee: optee: Fix dynamic shm pool allocations
In case of dynamic shared memory pool, kernel memory allocated using dmabuf_mgr pool needs to be registered with OP-TEE prior to its usage during optee_open_session() or optee_invoke_func(). So fix dmabuf_mgr pool allocations via an additional call to optee_shm_register(). Also, allow kernel pages to be registered as shared memory with OP-TEE. Fixes: 9733b07 ("optee: allow to work without static shared memory") Signed-off-by: Sumit Garg <[email protected]> Signed-off-by: Jens Wiklander <[email protected]>
1 parent 4f5cafb commit a249dd2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

drivers/tee/optee/call.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,13 @@ static int check_mem_type(unsigned long start, size_t num_pages)
554554
struct mm_struct *mm = current->mm;
555555
int rc;
556556

557+
/*
558+
* Allow kernel address to register with OP-TEE as kernel
559+
* pages are configured as normal memory only.
560+
*/
561+
if (virt_addr_valid(start))
562+
return 0;
563+
557564
down_read(&mm->mmap_sem);
558565
rc = __check_mem_type(find_vma(mm, start),
559566
start + num_pages * PAGE_SIZE);

drivers/tee/optee/shm_pool.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
1717
{
1818
unsigned int order = get_order(size);
1919
struct page *page;
20+
int rc = 0;
2021

2122
page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
2223
if (!page)
@@ -26,12 +27,21 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
2627
shm->paddr = page_to_phys(page);
2728
shm->size = PAGE_SIZE << order;
2829

29-
return 0;
30+
if (shm->flags & TEE_SHM_DMA_BUF) {
31+
shm->flags |= TEE_SHM_REGISTER;
32+
rc = optee_shm_register(shm->ctx, shm, &page, 1 << order,
33+
(unsigned long)shm->kaddr);
34+
}
35+
36+
return rc;
3037
}
3138

3239
static void pool_op_free(struct tee_shm_pool_mgr *poolm,
3340
struct tee_shm *shm)
3441
{
42+
if (shm->flags & TEE_SHM_DMA_BUF)
43+
optee_shm_unregister(shm->ctx, shm);
44+
3545
free_pages((unsigned long)shm->kaddr, get_order(shm->size));
3646
shm->kaddr = NULL;
3747
}

0 commit comments

Comments
 (0)