tee: optee: Fix dynamic shm pool allocations
Subsystems (2)
PATCH 1/1 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().
---
Depends on patch: https://lkml.org/lkml/2019/7/30/506 that adds support to allow registration of kernel buffers with OP-TEE.
drivers/tee/optee/shm_pool.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/tee/optee/shm_pool.c +11 -1
@@ -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 ; }
Signature · 1 line
2.7.4
Hi Sumit,
Quoted 9 lines · Sumit Garg
In case of dynamic shared memory pool, kernel memory allocated using
dmabuf_mgrpool needs to be registered with OP-TEE prior to its usage duringoptee_open_session()oroptee_invoke_func().So fix
dmabuf_mgrpool allocations via an additional call tooptee_shm_register().Fixes 9733b072a12a ("optee: allow to work without static shared memory")Signed-off-by Sumit Garg <[email protected]>
Looks good, I'm picking this up. Etienne told me has tested this on some of his hardware so I'll add:
Thanks,
Jens
Quoted 46 lines
---
Depends on patch: https://lkml.org/lkml/2019/7/30/506 that adds support to allow registration of kernel buffers with OP-TEE.
drivers/tee/optee/shm_pool.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/tee/optee/shm_pool.c +11
-1@@ -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 ; }Signature · 1 line
2.7.4
Hi Jens,
Quoted 11 lines · Jens Wiklander
Hi Sumit,
Quoted 7 lines · Sumit Garg
In case of dynamic shared memory pool, kernel memory allocated using
dmabuf_mgrpool needs to be registered with OP-TEE prior to its usage duringoptee_open_session()oroptee_invoke_func().So fix
dmabuf_mgrpool allocations via an additional call tooptee_shm_register().
Quoted 7 lines
Quoted 2 lines
Fixes 9733b072a12a ("optee: allow to work without static shared memory")Signed-off-by Sumit Garg <[email protected]>Looks good, I'm picking this up. Etienne told me has tested this on some of his hardware so I'll add:
Tested-by Etienne Carriere <[email protected]>
Thanks for picking this up.
Quoted 5 lines
Quoted 5 lines
---
Depends on patch: https://lkml.org/lkml/2019/7/30/506 that adds support to allow registration of kernel buffers with OP-TEE.
You also need to pick up the dependency patch too. The latest v3 of this patch is here [1] although its unchanged from v2. Also, If you pick that up I will drop it from future revisions of Trusted Keys patchset [2].
[1] https://lkml.org/lkml/2019/10/31/431
[2] https://lkml.org/lkml/2019/10/31/430
-Sumit
Quoted 42 lines
Quoted 42 lines
drivers/tee/optee/shm_pool.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/tee/optee/shm_pool.c +11
-2@@ -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
Hi Sumit,
Quoted 31 lines · Sumit Garg
Hi Jens,
Quoted 11 lines · Jens Wiklander
Hi Sumit,
Quoted 7 lines · Sumit Garg
In case of dynamic shared memory pool, kernel memory allocated using
dmabuf_mgrpool needs to be registered with OP-TEE prior to its usage duringoptee_open_session()oroptee_invoke_func().So fix
dmabuf_mgrpool allocations via an additional call tooptee_shm_register().Quoted 7 lines
Quoted 2 lines
Fixes 9733b072a12a ("optee: allow to work without static shared memory")Signed-off-by Sumit Garg <[email protected]>Looks good, I'm picking this up. Etienne told me has tested this on some of his hardware so I'll add:
Tested-by Etienne Carriere <[email protected]>Thanks for picking this up.
Quoted 5 lines
Quoted 5 lines
---
Depends on patch: https://lkml.org/lkml/2019/7/30/506 that adds support to allow registration of kernel buffers with OP-TEE.
Quoted 7 lines
You also need to pick up the dependency patch too. The latest v3 of this patch is here [1] although its unchanged from v2. Also, If you pick that up I will drop it from future revisions of Trusted Keys patchset [2].
[1] https://lkml.org/lkml/2019/10/31/431
[2] https://lkml.org/lkml/2019/10/31/430
So I missed taking [1] into account. I think that it would make more sense to merge this patch ("tee: optee: Fix dynamic shm pool allocations") with [1] ("tee: optee: allow kernel pages to register as shm") into a new patch.
Cheers,
Jens
Quoted 45 lines
-Sumit
Quoted 42 lines
Quoted 42 lines
drivers/tee/optee/shm_pool.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/tee/optee/shm_pool.c +11
-2@@ -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
Hi Jens,
Quoted 40 lines · Jens Wiklander
Hi Sumit,
Quoted 36 lines · Sumit Garg
Hi Jens,
Quoted 11 lines · Jens Wiklander
Hi Sumit,
Quoted 7 lines · Sumit Garg
In case of dynamic shared memory pool, kernel memory allocated using
dmabuf_mgrpool needs to be registered with OP-TEE prior to its usage duringoptee_open_session()oroptee_invoke_func().So fix
dmabuf_mgrpool allocations via an additional call tooptee_shm_register().Quoted 7 lines
Quoted 2 lines
Fixes 9733b072a12a ("optee: allow to work without static shared memory")Signed-off-by Sumit Garg <[email protected]>Looks good, I'm picking this up. Etienne told me has tested this on some of his hardware so I'll add:
Tested-by Etienne Carriere <[email protected]>Thanks for picking this up.
Quoted 5 lines
Quoted 5 lines
---
Depends on patch: https://lkml.org/lkml/2019/7/30/506 that adds support to allow registration of kernel buffers with OP-TEE.
You also need to pick up the dependency patch too. The latest v3 of this patch is here [1] although its unchanged from v2. Also, If you pick that up I will drop it from future revisions of Trusted Keys patchset [2].
Quoted 7 lines
Quoted 2 lines
[1] https://lkml.org/lkml/2019/10/31/431
[2] https://lkml.org/lkml/2019/10/31/430So I missed taking [1] into account. I think that it would make more sense to merge this patch ("tee: optee: Fix dynamic shm pool allocations") with [1] ("tee: optee: allow kernel pages to register as shm") into a new patch.
Sure, will send v2 as merged patch instead.
-Sumit
Quoted 48 lines
Cheers,
JensQuoted 45 lines
-Sumit
Quoted 42 lines
Quoted 42 lines
drivers/tee/optee/shm_pool.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/tee/optee/shm_pool.c +11
-2@@ -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