aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tee/optee/shm_pool.c
diff options
context:
space:
mode:
authorSumit Garg <sumit.garg@linaro.org>2019-11-08 16:57:14 +0530
committerJens Wiklander <jens.wiklander@linaro.org>2019-11-15 11:31:11 +0100
commita249dd200d03791cab23e47571f3e13d9c72af6c (patch)
treea4ccc6e51e90c9f04e8ff33703894839193ec55e /drivers/tee/optee/shm_pool.c
parentLinux 5.4-rc3 (diff)
downloadlinux-dev-a249dd200d03791cab23e47571f3e13d9c72af6c.tar.xz
linux-dev-a249dd200d03791cab23e47571f3e13d9c72af6c.zip
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: 9733b072a12a ("optee: allow to work without static shared memory") Signed-off-by: Sumit Garg <sumit.garg@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Diffstat (limited to 'drivers/tee/optee/shm_pool.c')
-rw-r--r--drivers/tee/optee/shm_pool.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/drivers/tee/optee/shm_pool.c b/drivers/tee/optee/shm_pool.c
index de1d9b8fad90..0332a5301d61 100644
--- a/drivers/tee/optee/shm_pool.c
+++ b/drivers/tee/optee/shm_pool.c
@@ -17,6 +17,7 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
{
unsigned int order = get_order(size);
struct page *page;
+ int rc = 0;
page = alloc_pages(GFP_KERNEL | __GFP_ZERO, order);
if (!page)
@@ -26,12 +27,21 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,
shm->paddr = page_to_phys(page);
shm->size = PAGE_SIZE << order;
- return 0;
+ if (shm->flags & TEE_SHM_DMA_BUF) {
+ shm->flags |= TEE_SHM_REGISTER;
+ rc = optee_shm_register(shm->ctx, shm, &page, 1 << order,
+ (unsigned long)shm->kaddr);
+ }
+
+ return rc;
}
static void pool_op_free(struct tee_shm_pool_mgr *poolm,
struct tee_shm *shm)
{
+ if (shm->flags & TEE_SHM_DMA_BUF)
+ optee_shm_unregister(shm->ctx, shm);
+
free_pages((unsigned long)shm->kaddr, get_order(shm->size));
shm->kaddr = NULL;
}