linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch v2] tee: optee: Fix dynamic shm pool allocations
@ 2019-11-08 11:27 Sumit Garg
  2019-11-15 10:35 ` Jens Wiklander
  0 siblings, 1 reply; 2+ messages in thread
From: Sumit Garg @ 2019-11-08 11:27 UTC (permalink / raw)
  To: jens.wiklander, Volodymyr_Babchuk
  Cc: tee-dev, linux-kernel, etienne.carriere, Sumit Garg

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>
---

Changes in v2:
Merge the dependency patch: https://lkml.org/lkml/2019/10/31/431

 drivers/tee/optee/call.c     |  7 +++++++
 drivers/tee/optee/shm_pool.c | 12 +++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/tee/optee/call.c b/drivers/tee/optee/call.c
index 13b0269..cf2367b 100644
--- a/drivers/tee/optee/call.c
+++ b/drivers/tee/optee/call.c
@@ -554,6 +554,13 @@ static int check_mem_type(unsigned long start, size_t num_pages)
 	struct mm_struct *mm = current->mm;
 	int rc;
 
+	/*
+	 * Allow kernel address to register with OP-TEE as kernel
+	 * pages are configured as normal memory only.
+	 */
+	if (virt_addr_valid(start))
+		return 0;
+
 	down_read(&mm->mmap_sem);
 	rc = __check_mem_type(find_vma(mm, start),
 			      start + num_pages * PAGE_SIZE);
diff --git a/drivers/tee/optee/shm_pool.c b/drivers/tee/optee/shm_pool.c
index de1d9b8..0332a53 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;
 }
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Patch v2] tee: optee: Fix dynamic shm pool allocations
  2019-11-08 11:27 [Patch v2] tee: optee: Fix dynamic shm pool allocations Sumit Garg
@ 2019-11-15 10:35 ` Jens Wiklander
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Wiklander @ 2019-11-15 10:35 UTC (permalink / raw)
  To: Sumit Garg; +Cc: Volodymyr_Babchuk, tee-dev, linux-kernel, etienne.carriere

Hi Sumit,

On Fri, Nov 08, 2019 at 04:57:14PM +0530, Sumit Garg wrote:
> 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>
> ---
> 
> Changes in v2:
> Merge the dependency patch: https://lkml.org/lkml/2019/10/31/431
> 

Looks good, I'm picking this up.

Thanks,
Jens

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-15 10:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-08 11:27 [Patch v2] tee: optee: Fix dynamic shm pool allocations Sumit Garg
2019-11-15 10:35 ` Jens Wiklander

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).