Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp120740rdb; Wed, 18 Oct 2023 21:46:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGshf/grNeRfz3GA5mJE4muu9wckQTO4oGN50qJJnPmW0MHy8+pUB3yjzWcwmlXfAEA0kob X-Received: by 2002:a17:902:db11:b0:1ca:8629:829f with SMTP id m17-20020a170902db1100b001ca8629829fmr1335897plx.26.1697690809835; Wed, 18 Oct 2023 21:46:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697690809; cv=none; d=google.com; s=arc-20160816; b=Ihwu0BU748nUxIYejGhIOPe58nJ+IvMHt0xMI+R8XthyInklZrkszbeVDeeWjl2KBB 0YiiqnSHXMaDKZH+tOJj0YpRmv4roNvDQZzwm+45WMyLIwkut5r8YomdeOx30SMcougy YXj29Ad3gU8Gvhk+GYwe9qexkHcQQ/tpTy/G6PIHyO08dUBpwH01LFDu8WsodQyQmmGx vS1H/4zD0VaPd3B2HW3PrRtACedV6hAP/s3ftJUUY9/YMlVCPHrAtHXjhzwSW2w6jtVu 6KPM1PIhOyK9C4BT1FJuWAq3TDcPVBWUokRdPVhfWn5BlkFtN4NXcNd8T1w5ZKZyG+Yn U/+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=cgGbWowjAL2zs3mLBEJcUx/pV6qG4ZvKU4TS6EdpuLU=; fh=LxyKaKqDeH/gFpDNDs6cgGqhxLbRECS7xvDUvdFwNZU=; b=Uw+T0uCeOJ9aOShhw445THASgXMgib6khFIux4Mb6fEBC7qyR/FWQ9OcMuzbKh5zoh ia8nXFT3YIn2gkShmTa5rGXBChxvFrBzPpDttvtLunefKOGq+DRD+fZlzZkMI5tFSIZG USEUZ7Vx6GE3dOJDm1cPbZvi2TWw+nfMQ4wpxdd4nvK9PyiqzCR9AY5XiWlNgAjZyKcN cuaIyH9uskpauOIIKkfYSqpa/VXG7jvxdOyaxNyV8w5sJJ99f3V/gEbu3kQECaRKu8HX 2MMKHk8lBKWizKOsIJaI3RuPyimPp48SBoH7mjOpRnvJQd3dHuJbMNLZfl77SmXBocsW TvIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VjfazaVu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id y13-20020a17090322cd00b001c89c86160bsi1461775plg.385.2023.10.18.21.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 21:46:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=VjfazaVu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 17DD4806E171; Wed, 18 Oct 2023 21:46:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232601AbjJSEq2 (ORCPT + 99 others); Thu, 19 Oct 2023 00:46:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232076AbjJSEq0 (ORCPT ); Thu, 19 Oct 2023 00:46:26 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FDA39F; Wed, 18 Oct 2023 21:46:24 -0700 (PDT) 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 CC: Krzysztof Kozlowski , Conor Dooley , Benjamin Gaignard , Brian Starkey , John Stultz , , AngeloGioacchino Del Regno , , , , , , , , , , Anan Sun 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-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 18 Oct 2023 21:46:47 -0700 (PDT) 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);