FAILED: patch "[PATCH] tee: Correct inappropriate usage of TEE_SHM_DMA_BUF flag" failed to apply to 5.4-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 376e4199e327a5cf29b8ec8fb0f64f3d8b429819 Mon Sep 17 00:00:00 2001
From: Sumit Garg <[email protected]>
Date: Mon, 14 Jun 2021 17:33:15 -0500
Subject: [PATCH] tee: Correct inappropriate usage of TEE_SHM_DMA_BUF flag
Currently TEE_SHM_DMA_BUF flag has been inappropriately used to not register shared memory allocated for private usage by underlying TEE
driver: OP-TEE in this case. So rather add a new flag as TEE_SHM_PRIV that can be utilized by underlying TEE drivers for private allocation and usage of shared memory.
With this corrected, allow tee_shm_alloc_kernel_buf() to allocate a shared memory region without the backing of dma-buf.
drivers/tee/optee/call.c +1 -1
@@ -184,7 +184,7 @@ static struct tee_shm *get_msg_arg(struct tee_context *ctx, size_t num_params,struct optee_msg_arg *ma; shm =tee_shm_alloc (ctx,OPTEE_MSG_GET_ARG_SIZE (num_params), -TEE_SHM_MAPPED ); +TEE_SHM_MAPPED |TEE_SHM_PRIV );if (IS_ERR (shm))return shm;
drivers/tee/optee/core.c +2 -1
@@ -278,7 +278,8 @@ static void optee_release(struct tee_context *ctx)if (!ctxdata)return ; - shm =tee_shm_alloc (ctx,sizeof (struct optee_msg_arg ),TEE_SHM_MAPPED ); + shm =tee_shm_alloc (ctx,sizeof (struct optee_msg_arg ), +TEE_SHM_MAPPED |TEE_SHM_PRIV );if (!IS_ERR (shm)) { arg =tee_shm_get_va (shm,0 );/*
drivers/tee/optee/rpc.c +3 -2
@@ -314,7 +314,7 @@ static void handle_rpc_func_cmd_shm_alloc(struct tee_context *ctx, shm =cmd_alloc_suppl (ctx, sz);break ;case OPTEE_RPC_SHM_TYPE_KERNEL : - shm =tee_shm_alloc (ctx, sz,TEE_SHM_MAPPED ); + shm =tee_shm_alloc (ctx, sz,TEE_SHM_MAPPED |TEE_SHM_PRIV );break ;default : arg->ret =TEEC_ERROR_BAD_PARAMETERS ;
@@ -502,7 +502,8 @@ void optee_handle_rpc(struct tee_context *ctx, struct optee_rpc_param *param,switch (OPTEE_SMC_RETURN_GET_RPC_FUNC (param->a0)) {case OPTEE_SMC_RPC_FUNC_ALLOC : - shm =tee_shm_alloc (ctx, param->a1,TEE_SHM_MAPPED ); + shm =tee_shm_alloc (ctx, param->a1, +TEE_SHM_MAPPED |TEE_SHM_PRIV );if (!IS_ERR (shm) && !tee_shm_get_pa (shm,0 , &pa)) {reg_pair_from_64 (¶m->a1, ¶m->a2, pa); reg_pair_from_64(¶m->a4, ¶m->a5,
drivers/tee/optee/shm_pool.c +6 -2
@@ -27,7 +27,11 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm, shm->paddr =page_to_phys (page); shm->size =PAGE_SIZE << order; -if (shm->flags &TEE_SHM_DMA_BUF ) { +/* +* Shared memory private to the OP-TEE driver doesn't need +* to be registered with OP-TEE. +*/ +if (!(shm->flags &TEE_SHM_PRIV )) {unsigned int nr_pages =1 << order, i;struct page **pages;
@@ -60,7 +64,7 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,static void pool_op_free (struct tee_shm_pool_mgr *poolm,struct tee_shm *shm) { -if (shm->flags &TEE_SHM_DMA_BUF ) +if (!(shm->flags &TEE_SHM_PRIV ))optee_shm_unregister (shm->ctx, shm);free_pages ((unsigned long )shm->kaddr,get_order (shm->size));
drivers/tee/tee_shm.c +2 -2
@@ -117,7 +117,7 @@ struct tee_shm *tee_shm_alloc(struct tee_context *ctx, size_t size, u32 flags)return ERR_PTR (-EINVAL ); } -if ((flags & ~(TEE_SHM_MAPPED |TEE_SHM_DMA_BUF ))) { +if ((flags & ~(TEE_SHM_MAPPED |TEE_SHM_DMA_BUF |TEE_SHM_PRIV ))) {dev_err (teedev->dev.parent,"invalid shm flags 0x%x" , flags);return ERR_PTR (-EINVAL ); }
@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(tee_shm_alloc);*/ struct tee_shm *tee_shm_alloc_kernel_buf (struct tee_context *ctx,size_t size) { -return tee_shm_alloc (ctx, size,TEE_SHM_MAPPED |TEE_SHM_DMA_BUF ); +return tee_shm_alloc (ctx, size,TEE_SHM_MAPPED ); }EXPORT_SYMBOL_GPL (tee_shm_alloc_kernel_buf);
include/linux/tee_drv.h +1 -0
@@ -27,6 +27,7 @@#define TEE_SHM_USER_MAPPED BIT(4)/* Memory mapped in user space */ #define TEE_SHM_POOL BIT(5)/* Memory allocated from pool */ #define TEE_SHM_KERNEL_MAPPED BIT(6)/* Memory mapped in kernel space */ +#define TEE_SHM_PRIV BIT(7)/* Memory private to TEE driver */ struct device ;struct tee_device ;
PATCH 1/1 tee: Correct inappropriate usage of TEE_SHM_DMA_BUF flag
From: Sumit Garg <[email protected]>
commit 376e4199e327a5cf29b8ec8fb0f64f3d8b429819 upstream.
Currently TEE_SHM_DMA_BUF flag has been inappropriately used to not register shared memory allocated for private usage by underlying TEE
driver: OP-TEE in this case. So rather add a new flag as TEE_SHM_PRIV that can be utilized by underlying TEE drivers for private allocation and usage of shared memory.
With this corrected, allow tee_shm_alloc_kernel_buf() to allocate a shared memory region without the backing of dma-buf.
---
Hi Greg - Please include this backported patch in the 5.14-stable queue since the upstream commit couldn't be automatically backported. We've been using this backported version of the patch on top of 5.4.134 and it has received real world usage in production environments.
drivers/tee/optee/call.c | 2 +- drivers/tee/optee/core.c | 3 ++- drivers/tee/optee/rpc.c | 5 +++-- drivers/tee/optee/shm_pool.c | 8 ++++++-- drivers/tee/tee_shm.c | 4 ++-- include/linux/tee_drv.h | 1 + 6 files changed, 15 insertions(+), 8 deletions(-)
drivers/tee/optee/call.c +1 -1
@@ -181,7 +181,7 @@ static struct tee_shm *get_msg_arg(struct tee_context *ctx, size_t num_params,struct optee_msg_arg *ma; shm =tee_shm_alloc (ctx,OPTEE_MSG_GET_ARG_SIZE (num_params), -TEE_SHM_MAPPED ); +TEE_SHM_MAPPED |TEE_SHM_PRIV );if (IS_ERR (shm))return shm;
drivers/tee/optee/core.c +2 -1
@@ -254,7 +254,8 @@ static void optee_release(struct tee_context *ctx)if (!ctxdata)return ; - shm =tee_shm_alloc (ctx,sizeof (struct optee_msg_arg ),TEE_SHM_MAPPED ); + shm =tee_shm_alloc (ctx,sizeof (struct optee_msg_arg ), +TEE_SHM_MAPPED |TEE_SHM_PRIV );if (!IS_ERR (shm)) { arg =tee_shm_get_va (shm,0 );/*
drivers/tee/optee/rpc.c +3 -2
@@ -220,7 +220,7 @@ static void handle_rpc_func_cmd_shm_alloc(struct tee_context *ctx, shm =cmd_alloc_suppl (ctx, sz);break ;case OPTEE_MSG_RPC_SHM_TYPE_KERNEL : - shm =tee_shm_alloc (ctx, sz,TEE_SHM_MAPPED ); + shm =tee_shm_alloc (ctx, sz,TEE_SHM_MAPPED |TEE_SHM_PRIV );break ;default : arg->ret =TEEC_ERROR_BAD_PARAMETERS ;
@@ -405,7 +405,8 @@ void optee_handle_rpc(struct tee_context *ctx, struct optee_rpc_param *param,switch (OPTEE_SMC_RETURN_GET_RPC_FUNC (param->a0)) {case OPTEE_SMC_RPC_FUNC_ALLOC : - shm =tee_shm_alloc (ctx, param->a1,TEE_SHM_MAPPED ); + shm =tee_shm_alloc (ctx, param->a1, +TEE_SHM_MAPPED |TEE_SHM_PRIV );if (!IS_ERR (shm) && !tee_shm_get_pa (shm,0 , &pa)) {reg_pair_from_64 (¶m->a1, ¶m->a2, pa); reg_pair_from_64(¶m->a4, ¶m->a5,
drivers/tee/optee/shm_pool.c +6 -2
@@ -27,7 +27,11 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm, shm->paddr =page_to_phys (page); shm->size =PAGE_SIZE << order; -if (shm->flags &TEE_SHM_DMA_BUF ) { +/* +* Shared memory private to the OP-TEE driver doesn't need +* to be registered with OP-TEE. +*/ +if (!(shm->flags &TEE_SHM_PRIV )) {unsigned int nr_pages =1 << order, i;struct page **pages;
@@ -60,7 +64,7 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm,static void pool_op_free (struct tee_shm_pool_mgr *poolm,struct tee_shm *shm) { -if (shm->flags &TEE_SHM_DMA_BUF ) +if (!(shm->flags &TEE_SHM_PRIV ))optee_shm_unregister (shm->ctx, shm);free_pages ((unsigned long )shm->kaddr,get_order (shm->size));
drivers/tee/tee_shm.c +2 -2
@@ -117,7 +117,7 @@ static struct tee_shm *__tee_shm_alloc(struct tee_context *ctx,return ERR_PTR (-EINVAL ); } -if ((flags & ~(TEE_SHM_MAPPED |TEE_SHM_DMA_BUF ))) { +if ((flags & ~(TEE_SHM_MAPPED |TEE_SHM_DMA_BUF |TEE_SHM_PRIV ))) {dev_err (teedev->dev.parent,"invalid shm flags 0x%x" , flags);return ERR_PTR (-EINVAL ); }
@@ -233,7 +233,7 @@ EXPORT_SYMBOL_GPL(tee_shm_priv_alloc);*/ struct tee_shm *tee_shm_alloc_kernel_buf (struct tee_context *ctx,size_t size) { -return tee_shm_alloc (ctx, size,TEE_SHM_MAPPED |TEE_SHM_DMA_BUF ); +return tee_shm_alloc (ctx, size,TEE_SHM_MAPPED ); }EXPORT_SYMBOL_GPL (tee_shm_alloc_kernel_buf);
include/linux/tee_drv.h +1 -0
@@ -26,6 +26,7 @@#define TEE_SHM_REGISTER BIT(3)/* Memory registered in secure world */ #define TEE_SHM_USER_MAPPED BIT(4)/* Memory mapped in user space */ #define TEE_SHM_POOL BIT(5)/* Memory allocated from pool */ +#define TEE_SHM_PRIV BIT(7)/* Memory private to TEE driver */ struct device ;struct tee_device ;
Signature · 1 line
2.25.1