From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 33768CDB465 for ; Thu, 19 Oct 2023 08:35:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C017810E0B8; Thu, 19 Oct 2023 08:35:47 +0000 (UTC) Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by gabe.freedesktop.org (Postfix) with ESMTPS id F3E4110E1CD for ; Thu, 19 Oct 2023 04:46:19 +0000 (UTC) Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39J47toU010578; Thu, 19 Oct 2023 04:46:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=qcppdkim1; bh=cgGbWowjAL2zs3mLBEJcUx/pV6qG4ZvKU4TS6EdpuLU=; b=VjfazaVu5K1pCGlRWGA2ekNNn4kqyassqIhdc+iFxaaygvJ2mdaCd/7b9yJIoM5F4cEx xYf6IDbQzpTLjZ8wUxkwkqRCjCfCT+ArdkdYlUr8Al5KwEN9mkvDjKauO5j4Q4gsZmFY D1DMZZs9S8ShjZt8+rcy3Spb5z9UJFizEpz6r3qN5mTUt0IV7INC1SZiXklswkRGOK7z 8WuGdz6P6hFKLEdimH19dWNIiEMGpYDgleN1oR0NlYpj+kxBngg7R2q+BW+YWXosoYaD qulGlvwE0+7khqhp7itNNp0MMgVb9WlvjpkUGHl1y9WNrvQn9iyd9Iw+WZln3WFzTR8X 0g== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ttnnagwwh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 19 Oct 2023 04:46:08 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39J4k7qw002336 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 19 Oct 2023 04:46:07 GMT Received: from [10.216.19.246] (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Wed, 18 Oct 2023 21:45:58 -0700 Message-ID: Date: Thu, 19 Oct 2023 10:15:58 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 6/9] dma-buf: heaps: mtk_sec_heap: Add tee service call for buffer allocating/freeing Content-Language: en-US To: Yong Wu , Rob Herring , Sumit Semwal , , Matthias Brugger References: <20230911023038.30649-1-yong.wu@mediatek.com> <20230911023038.30649-7-yong.wu@mediatek.com> From: Vijayanand Jitta In-Reply-To: <20230911023038.30649-7-yong.wu@mediatek.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: 31cIZ-IT-H_-Z_BV13ryeh6KElChoOsz X-Proofpoint-ORIG-GUID: 31cIZ-IT-H_-Z_BV13ryeh6KElChoOsz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-19_02,2023-10-18_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 phishscore=0 adultscore=0 malwarescore=0 spamscore=0 bulkscore=0 clxscore=1011 mlxlogscore=999 impostorscore=0 suspectscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310190039 X-Mailman-Approved-At: Thu, 19 Oct 2023 08:35:42 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Anan Sun , devicetree@vger.kernel.org, Conor Dooley , Benjamin Gaignard , kuohong.wang@mediatek.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, tjmercier@google.com, linaro-mm-sig@lists.linaro.org, John Stultz , jianjiao.zeng@mediatek.com, Krzysztof Kozlowski , linux-mediatek@lists.infradead.org, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, AngeloGioacchino Del Regno Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On 9/11/2023 8:00 AM, Yong Wu wrote: > Add TEE service call for secure memory allocating/freeing. > > Signed-off-by: Anan Sun > Signed-off-by: Yong Wu > --- > drivers/dma-buf/heaps/mtk_secure_heap.c | 69 ++++++++++++++++++++++++- > 1 file changed, 68 insertions(+), 1 deletion(-) > > diff --git a/drivers/dma-buf/heaps/mtk_secure_heap.c b/drivers/dma-buf/heaps/mtk_secure_heap.c > index e3da33a3d083..14c2a16a7164 100644 > --- a/drivers/dma-buf/heaps/mtk_secure_heap.c > +++ b/drivers/dma-buf/heaps/mtk_secure_heap.c > @@ -17,6 +17,9 @@ > > #define MTK_TEE_PARAM_NUM 4 > > +#define TZCMD_MEM_SECURECM_UNREF 7 > +#define TZCMD_MEM_SECURECM_ZALLOC 15 > + > /* > * MediaTek secure (chunk) memory type > * > @@ -29,6 +32,8 @@ enum kree_mem_type { > struct mtk_secure_heap_buffer { > struct dma_heap *heap; > size_t size; > + > + u32 sec_handle; > }; > > struct mtk_secure_heap { > @@ -80,6 +85,63 @@ static int mtk_kree_secure_session_init(struct mtk_secure_heap *sec_heap) > return ret; > } > > +static int > +mtk_sec_mem_tee_service_call(struct tee_context *tee_ctx, u32 session, > + unsigned int command, struct tee_param *params) > +{ > + struct tee_ioctl_invoke_arg arg = {0}; > + int ret; > + > + arg.num_params = MTK_TEE_PARAM_NUM; > + arg.session = session; > + arg.func = command; > + > + ret = tee_client_invoke_func(tee_ctx, &arg, params); > + if (ret < 0 || arg.ret) { > + pr_err("%s: cmd %d ret %d:%x.\n", __func__, command, ret, arg.ret); > + ret = -EOPNOTSUPP; > + } > + return ret; > +} > + > +static int mtk_sec_mem_allocate(struct mtk_secure_heap *sec_heap, > + struct mtk_secure_heap_buffer *sec_buf) > +{ > + struct tee_param params[MTK_TEE_PARAM_NUM] = {0}; > + u32 mem_session = sec_heap->mem_session; > + int ret; > + > + params[0].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT; > + params[0].u.value.a = SZ_4K; /* alignment */ > + params[0].u.value.b = sec_heap->mem_type; /* memory type */ > + params[1].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT; > + params[1].u.value.a = sec_buf->size; > + params[2].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INOUT; > + > + /* Always request zeroed buffer */ > + ret = mtk_sec_mem_tee_service_call(sec_heap->tee_ctx, mem_session, > + TZCMD_MEM_SECURECM_ZALLOC, params); I see here optee calls are being used to secure memory. For a secure heap, there can be multiple ways on how we want to secure memory, for eg : by using qcom_scm_assign_mem. This interface restricts securing memory to only optee calls. can we have a way to choose ops that we want to secure memory ? Thanks, Vijay > + if (ret) > + return -ENOMEM; > + > + sec_buf->sec_handle = params[2].u.value.a; > + return 0; > +} > + > +static void mtk_sec_mem_release(struct mtk_secure_heap *sec_heap, > + struct mtk_secure_heap_buffer *sec_buf) > +{ > + struct tee_param params[MTK_TEE_PARAM_NUM] = {0}; > + u32 mem_session = sec_heap->mem_session; > + > + params[0].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_INPUT; > + params[0].u.value.a = sec_buf->sec_handle; > + params[1].attr = TEE_IOCTL_PARAM_ATTR_TYPE_VALUE_OUTPUT; > + > + mtk_sec_mem_tee_service_call(sec_heap->tee_ctx, mem_session, > + TZCMD_MEM_SECURECM_UNREF, params); > +} > + > static struct dma_buf * > mtk_sec_heap_allocate(struct dma_heap *heap, size_t size, > unsigned long fd_flags, unsigned long heap_flags) > @@ -107,6 +169,9 @@ mtk_sec_heap_allocate(struct dma_heap *heap, size_t size, > sec_buf->size = size; > sec_buf->heap = heap; > > + ret = mtk_sec_mem_allocate(sec_heap, sec_buf); > + if (ret) > + goto err_free_buf; > exp_info.exp_name = dma_heap_get_name(heap); > exp_info.size = sec_buf->size; > exp_info.flags = fd_flags; > @@ -115,11 +180,13 @@ mtk_sec_heap_allocate(struct dma_heap *heap, size_t size, > dmabuf = dma_buf_export(&exp_info); > if (IS_ERR(dmabuf)) { > ret = PTR_ERR(dmabuf); > - goto err_free_buf; > + goto err_free_sec_mem; > } > > return dmabuf; > > +err_free_sec_mem: > + mtk_sec_mem_release(sec_heap, sec_buf); > err_free_buf: > kfree(sec_buf); > return ERR_PTR(ret);