From nobody Thu Oct 2 23:47:49 2025 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F6741E491B for ; Wed, 10 Sep 2025 00:11:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757463099; cv=none; b=JVwTaZOhf5ko3s2Mf7yJ1U+nVjSywBYTi24MsTaz+AT7kU+ckX/gwxFnMNYg1BNz2CrjxDiWCGv7Hkf+q6iYw0ym7XMBt9KHZ9WmWhmwzlBa9ZltwdLf1sRmwPYiV3TaqJET2xV2bTqPAqvT7G48RuA6obFTju5l/8mjF+DDiIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757463099; c=relaxed/simple; bh=kENdZrweqhHGnJf6wEosVdgBKcM0+mk+sFhIIGNHgqs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EkgBczf3kOs/iPZiDebBCwBx0oRKM4o/SvY5nHO+wBAx5FbO0fgfVay0JAaFFWS8o1xqgLwpH8/QIcV0u+jjsky/qqpJCxFpwtCO9VfU6vswR5Z8gE/7pqQF+xQZbrKOGuuB+YLZfG8D69CN8YkI9K50XNox3wB4Uurr/3BbDuw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=L57xCdtc; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="L57xCdtc" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 589I6rkW029929 for ; Wed, 10 Sep 2025 00:11:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= XwnYng4J7ze/dOFBSejFi7aWyaFRlAnXEGBPJ3w6NTU=; b=L57xCdtcTJZbHlxY vXyVMuH+EaEG5iDOq8BsWtIsQJub6mSTrlvP4GahzruViahrLF293fZ3dfagweoz dpjEMfNtXmalMHSgk72RtenMdmyA8I81aRzWUtqkRmk9UOjihNlMS0n8pdtptbOI wuBZAk+v4v6l4J43xswLZwb+yscxfHX4TXs5e/WcygYAioD8P+SCDistZfbr7GeU UwXlbelAm2YibCEkYG3aswAevIa5mX3sAcBURIe1y7DyTZ4Ph4r3r2mQ+63TODmv AIhu/eAFXaIkl+OZHxv+WLsTZOiMgENjsvmGWv10VtR936Vbya0254+dkwrY7cB6 QR5YIg== Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 491t37xg93-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 10 Sep 2025 00:11:36 +0000 (GMT) Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2445806b18aso78120565ad.1 for ; Tue, 09 Sep 2025 17:11:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757463095; x=1758067895; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XwnYng4J7ze/dOFBSejFi7aWyaFRlAnXEGBPJ3w6NTU=; b=ejDB0HJ7IZzjcDP+n2huQ58FhWLKC5lLo/zwzXOVq8xFEw5edrW8/+nIsHxsecmOrn XN5lOhpzBDE7Gp584usINGlU1G5AIk8k+2HWS1iY4bpZFPJLzR2HnWVHlGAsjKtFsB7l kvTlqY6bCvBLPc9KgD5nyHGOEQoifWfOB8tc/ezGJD8f+Etcg5K/o3E34Euz1efpwdqZ xtatdT7XPs6haciL9JBwMQgDyUYHv6O/lQbYlJwjN+BG65K+kaOhdIQmpQfsj1dApHFC MsUF4u5ZdphtFFpHd0qOiihC5ahbVgpPhnaPi12XK0O7qzJKZfzQcmkuj7a23YgtZr5e JF/g== X-Forwarded-Encrypted: i=1; AJvYcCWLxOQcrw2IvGjPYvcDx0oSBUAJCzt6W6AxMDePzublkkiDz5C9raQLvrefpMbvBA5nCqFcsST+fdmO2bs=@vger.kernel.org X-Gm-Message-State: AOJu0YxNFnjekPsfAtFFghDRZsDxVW3ZQ/d5ldTnucLZfsEC8U+yM0ku f17bwikY30bWAh9l0Urpvz6OhiBf5fIxhrFPFau8nvEoG1uO3BymdJ6IWt2Tkz8zW1JO5UjUoY6 Gqw+YZsGSh8REN1IwFohSl+riS/mnpqspwaXbD96K4fiiXanh2TMT9qxHb9yLFZ0uqQ== X-Gm-Gg: ASbGncvI6JBnqUluTSHGXMosxhtuTb3yGiRuT+n20lJiL6uVZobI5QTY3fSsGPFfveE Hu+sEq8y57HxL6DgGbWC4tUBWk5AQC/8+bS94K+hpzbqFvMqcBD0XOPjc/H544NNk3Lphem8KLi w1DaZoc+fbJ8HKKL8/6Ah+Doa4JFwk8FTnn3J7tRu0rPcLZ9vQHcVYc3+TGjeXGY+5DcqmB0Wls 6qsyoHsLJKdHPScD3yddWLpgVZ3BFHsN16r0fTHBB+H6JtXPWElKuvgP7ZJpi58TjACvOewgKtW /ar3uR4ThZLWdHg2EopUv5lALwwmxHv90OnurljP+UEWZYttnn1J4rO15Tffxk12UTaDDpgh5DW VUs1J1Gb83PYHQSJQYfssZ0A= X-Received: by 2002:a17:902:e884:b0:248:811e:f873 with SMTP id d9443c01a7336-25170f37b15mr186964895ad.36.1757463094793; Tue, 09 Sep 2025 17:11:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEilbwBQ31JLFCgHV0Qsp9TyCQXSMDjQkN5p6/iQszZoI3MJ+M1ESH5p9AsNGoMZLvc0Il9CA== X-Received: by 2002:a17:902:e884:b0:248:811e:f873 with SMTP id d9443c01a7336-25170f37b15mr186964395ad.36.1757463094184; Tue, 09 Sep 2025 17:11:34 -0700 (PDT) Received: from hu-azarrabi-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32dab6bb655sm1285672a91.10.2025.09.09.17.11.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Sep 2025 17:11:33 -0700 (PDT) From: Amirreza Zarrabi Date: Tue, 09 Sep 2025 17:11:12 -0700 Subject: [PATCH v10 10/11] tee: qcom: enable TEE_IOC_SHM_ALLOC ioctl Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250909-qcom-tee-using-tee-ss-without-mem-obj-v10-10-20b17855ef31@oss.qualcomm.com> References: <20250909-qcom-tee-using-tee-ss-without-mem-obj-v10-0-20b17855ef31@oss.qualcomm.com> In-Reply-To: <20250909-qcom-tee-using-tee-ss-without-mem-obj-v10-0-20b17855ef31@oss.qualcomm.com> To: Jens Wiklander , Sumit Garg , Bjorn Andersson , Konrad Dybcio , Bartosz Golaszewski , Apurupa Pattapu , Kees Cook , "Gustavo A. R. Silva" , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= Cc: Harshal Dev , linux-arm-msm@vger.kernel.org, op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-doc@vger.kernel.org, Amirreza Zarrabi , Neil Armstrong , Sumit Garg X-Mailer: b4 0.13.0 X-Proofpoint-ORIG-GUID: rtnYl7TA30mAiI0DafrmPBQnPwKXRzED X-Proofpoint-GUID: rtnYl7TA30mAiI0DafrmPBQnPwKXRzED X-Authority-Analysis: v=2.4 cv=NdLm13D4 c=1 sm=1 tr=0 ts=68c0c238 cx=c_pps a=JL+w9abYAAE89/QcEU+0QA==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=yJojWOMRYYMA:10 a=KKAkSRfTAAAA:8 a=EUspDBNiAAAA:8 a=COk6AnOGAAAA:8 a=OR1utrCcES5rRZ7Z870A:9 a=DPARgtBJioFDCh1s:21 a=QEXdDO2ut3YA:10 a=324X-CrmTo6CU4MGRt3R:22 a=cvBusfyB2V15izCimMoJ:22 a=TjNXssC_j7lpFel5tvFf:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwOTA4MDA2NiBTYWx0ZWRfX4v89yM+3kXrq aR+2XifdKKsDmxPCVdSC/isKtg0Xn+J1LXAhHjho2uJ3JfevHa/iaiXV8pZiru33Pe75WOGLCf6 Ga6UMfIh7SuL8w7xNPXlVMozyrGQovzfGRBuGB0DJCwC7JhGISwYKrYI4CCyzJ5V0fGXTmYXRYe kxuWiY65gbWF0rJ0Kx45lbh1zAdQf+gyDZH+t8I8+XNYdAHZnAk5fkhCHs/xc7wkaOu7JtaQM/t iNtd9nkR3I5BsxkUuD/+/7SD0rwnoZ90f7mUwZcAE3e4HA1Ufg1wPQVygzH4+JLw2gcP/FGxMU4 qHQY+N9JW2Q5Yy8DiIInbj4ziLLYL7v2m8S9DzW2b8O8j16WtOESiWnyARGVSZ2HQnbk19ylNX0 RJdjUgwn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1117,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-09-09_03,2025-09-08_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 adultscore=0 suspectscore=0 phishscore=0 clxscore=1015 impostorscore=0 spamscore=0 priorityscore=1501 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2507300000 definitions=main-2509080066 Enable userspace to allocate shared memory with QTEE. Since QTEE handles shared memory as object, a wrapper is implemented to represent tee_shm as an object. The shared memory identifier, obtained through TEE_IOC_SHM_ALLOC, is transferred to the driver using TEE_IOCTL_PARAM_ATTR_TYPE_OBJREF_INPUT/OUTPUT. Tested-by: Neil Armstrong Acked-by: Sumit Garg Tested-by: Harshal Dev Signed-off-by: Amirreza Zarrabi --- drivers/tee/qcomtee/Makefile | 1 + drivers/tee/qcomtee/call.c | 9 +- drivers/tee/qcomtee/mem_obj.c | 169 +++++++++++++++++++++++++++++++= ++++ drivers/tee/qcomtee/primordial_obj.c | 50 +++++++++++ drivers/tee/qcomtee/qcomtee.h | 39 ++++++++ drivers/tee/qcomtee/shm.c | 3 - 6 files changed, 267 insertions(+), 4 deletions(-) diff --git a/drivers/tee/qcomtee/Makefile b/drivers/tee/qcomtee/Makefile index 78f8e899d143..7c466c9f32af 100644 --- a/drivers/tee/qcomtee/Makefile +++ b/drivers/tee/qcomtee/Makefile @@ -3,6 +3,7 @@ obj-$(CONFIG_QCOMTEE) +=3D qcomtee.o qcomtee-objs +=3D async.o qcomtee-objs +=3D call.o qcomtee-objs +=3D core.o +qcomtee-objs +=3D mem_obj.o qcomtee-objs +=3D primordial_obj.o qcomtee-objs +=3D shm.o qcomtee-objs +=3D user_obj.o diff --git a/drivers/tee/qcomtee/call.c b/drivers/tee/qcomtee/call.c index 33daa4d7033d..cc17a48d0ab7 100644 --- a/drivers/tee/qcomtee/call.c +++ b/drivers/tee/qcomtee/call.c @@ -122,7 +122,10 @@ int qcomtee_objref_to_arg(struct qcomtee_arg *arg, str= uct tee_param *param, err =3D qcomtee_user_param_to_object(&arg->o, param, ctx); /* param is a QTEE object: */ else if (param->u.objref.flags & QCOMTEE_OBJREF_FLAG_TEE) - err =3D qcomtee_context_find_qtee_object(&arg->o, param, ctx); + err =3D qcomtee_context_find_qtee_object(&arg->o, param, ctx); + /* param is a memory object: */ + else if (param->u.objref.flags & QCOMTEE_OBJREF_FLAG_MEM) + err =3D qcomtee_memobj_param_to_object(&arg->o, param, ctx); =20 /* * For callback objects, call qcomtee_object_get() to keep a temporary @@ -168,6 +171,10 @@ int qcomtee_objref_from_arg(struct tee_param *param, s= truct qcomtee_arg *arg, if (is_qcomtee_user_object(object)) return qcomtee_user_param_from_object(param, object, ctx); + /* object is a memory object: */ + else if (is_qcomtee_memobj_object(object)) + return qcomtee_memobj_param_from_object(param, object, + ctx); =20 break; case QCOMTEE_OBJECT_TYPE_TEE: diff --git a/drivers/tee/qcomtee/mem_obj.c b/drivers/tee/qcomtee/mem_obj.c new file mode 100644 index 000000000000..228a3e30a31b --- /dev/null +++ b/drivers/tee/qcomtee/mem_obj.c @@ -0,0 +1,169 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include + +#include "qcomtee.h" + +/** + * DOC: Memory and Mapping Objects + * + * QTEE uses memory objects for memory sharing with Linux. + * A memory object can be a standard dma_buf or a contiguous memory range, + * e.g., tee_shm. A memory object should support one operation: map. When + * invoked by QTEE, a mapping object is generated. A mapping object suppor= ts + * one operation: unmap. + * + * (1) To map a memory object, QTEE invokes the primordial object with + * %QCOMTEE_OBJECT_OP_MAP_REGION operation; see + * qcomtee_primordial_obj_dispatch(). + * (2) To unmap a memory object, QTEE releases the mapping object which + * calls qcomtee_mem_object_release(). + * + * The map operation is implemented in the primordial object as a privileg= ed + * operation instead of qcomtee_mem_object_dispatch(). Otherwise, on + * platforms without shm_bridge, a user can trick QTEE into writing to the + * kernel memory by passing a user object as a memory object and returning= a + * random physical address as the result of the mapping request. + */ + +struct qcomtee_mem_object { + struct qcomtee_object object; + struct tee_shm *shm; + /* QTEE requires these felids to be page aligned. */ + phys_addr_t paddr; /* Physical address of range. */ + size_t size; /* Size of the range. */ +}; + +#define to_qcomtee_mem_object(o) \ + container_of((o), struct qcomtee_mem_object, object) + +static struct qcomtee_object_operations qcomtee_mem_object_ops; + +/* Is it a memory object using tee_shm? */ +int is_qcomtee_memobj_object(struct qcomtee_object *object) +{ + return object !=3D NULL_QCOMTEE_OBJECT && + typeof_qcomtee_object(object) =3D=3D QCOMTEE_OBJECT_TYPE_CB && + object->ops =3D=3D &qcomtee_mem_object_ops; +} + +static int qcomtee_mem_object_dispatch(struct qcomtee_object_invoke_ctx *o= ic, + struct qcomtee_object *object, u32 op, + struct qcomtee_arg *args) +{ + return -EINVAL; +} + +static void qcomtee_mem_object_release(struct qcomtee_object *object) +{ + struct qcomtee_mem_object *mem_object =3D to_qcomtee_mem_object(object); + + /* Matching get is in qcomtee_memobj_param_to_object(). */ + tee_shm_put(mem_object->shm); + kfree(mem_object); +} + +static struct qcomtee_object_operations qcomtee_mem_object_ops =3D { + .release =3D qcomtee_mem_object_release, + .dispatch =3D qcomtee_mem_object_dispatch, +}; + +/** + * qcomtee_memobj_param_to_object() - OBJREF parameter to &struct qcomtee_= object. + * @object: object returned. + * @param: TEE parameter. + * @ctx: context in which the conversion should happen. + * + * @param is an OBJREF with %QCOMTEE_OBJREF_FLAG_MEM flags. + * + * Return: On success return 0 or <0 on failure. + */ +int qcomtee_memobj_param_to_object(struct qcomtee_object **object, + struct tee_param *param, + struct tee_context *ctx) +{ + struct qcomtee_mem_object *mem_object __free(kfree) =3D NULL; + struct tee_shm *shm; + int err; + + mem_object =3D kzalloc(sizeof(*mem_object), GFP_KERNEL); + if (!mem_object) + return -ENOMEM; + + shm =3D tee_shm_get_from_id(ctx, param->u.objref.id); + if (IS_ERR(shm)) + return PTR_ERR(shm); + + /* mem-object wrapping the memref. */ + err =3D qcomtee_object_user_init(&mem_object->object, + QCOMTEE_OBJECT_TYPE_CB, + &qcomtee_mem_object_ops, "tee-shm-%d", + shm->id); + if (err) { + tee_shm_put(shm); + + return err; + } + + mem_object->paddr =3D shm->paddr; + mem_object->size =3D shm->size; + mem_object->shm =3D shm; + + *object =3D &no_free_ptr(mem_object)->object; + + return 0; +} + +/* Reverse what qcomtee_memobj_param_to_object() does. */ +int qcomtee_memobj_param_from_object(struct tee_param *param, + struct qcomtee_object *object, + struct tee_context *ctx) +{ + struct qcomtee_mem_object *mem_object; + + mem_object =3D to_qcomtee_mem_object(object); + /* Sure if the memobj is in a same context it is originated from. */ + if (mem_object->shm->ctx !=3D ctx) + return -EINVAL; + + param->u.objref.id =3D mem_object->shm->id; + param->u.objref.flags =3D QCOMTEE_OBJREF_FLAG_MEM; + + /* Passing shm->id to userspace; drop the reference. */ + qcomtee_object_put(object); + + return 0; +} + +/** + * qcomtee_mem_object_map() - Map a memory object. + * @object: memory object. + * @map_object: created mapping object. + * @mem_paddr: physical address of the memory. + * @mem_size: size of the memory. + * @perms: QTEE access permissions. + * + * Return: On success return 0 or <0 on failure. + */ +int qcomtee_mem_object_map(struct qcomtee_object *object, + struct qcomtee_object **map_object, u64 *mem_paddr, + u64 *mem_size, u32 *perms) +{ + struct qcomtee_mem_object *mem_object =3D to_qcomtee_mem_object(object); + + /* Reuses the memory object as a mapping object by re-sharing it. */ + qcomtee_object_get(&mem_object->object); + + *map_object =3D &mem_object->object; + *mem_paddr =3D mem_object->paddr; + *mem_size =3D mem_object->size; + *perms =3D QCOM_SCM_PERM_RW; + + return 0; +} diff --git a/drivers/tee/qcomtee/primordial_obj.c b/drivers/tee/qcomtee/pri= mordial_obj.c index 0e43f04493e2..b6f811e83b11 100644 --- a/drivers/tee/qcomtee/primordial_obj.c +++ b/drivers/tee/qcomtee/primordial_obj.c @@ -14,18 +14,31 @@ * for native kernel services or privileged operations. * * We support: + * - %QCOMTEE_OBJECT_OP_MAP_REGION to map a memory object and return mapp= ing + * object and mapping information (see qcomtee_mem_object_map()). * - %QCOMTEE_OBJECT_OP_YIELD to yield by the thread running in QTEE. * - %QCOMTEE_OBJECT_OP_SLEEP to wait for a period of time. */ =20 +#define QCOMTEE_OBJECT_OP_MAP_REGION 0 #define QCOMTEE_OBJECT_OP_YIELD 1 #define QCOMTEE_OBJECT_OP_SLEEP 2 =20 +/* Mapping information format as expected by QTEE. */ +struct qcomtee_mapping_info { + u64 paddr; + u64 len; + u32 perms; +} __packed; + static int qcomtee_primordial_obj_dispatch(struct qcomtee_object_invoke_ctx *oic, struct qcomtee_object *primordial_object_unused, u32 op, struct qcomtee_arg *args) { + struct qcomtee_mapping_info *map_info; + struct qcomtee_object *mem_object; + struct qcomtee_object *map_object; int err =3D 0; =20 switch (op) { @@ -33,6 +46,7 @@ qcomtee_primordial_obj_dispatch(struct qcomtee_object_inv= oke_ctx *oic, cond_resched(); /* No output object. */ oic->data =3D NULL; + break; case QCOMTEE_OBJECT_OP_SLEEP: /* Check message format matched QCOMTEE_OBJECT_OP_SLEEP op. */ @@ -44,6 +58,29 @@ qcomtee_primordial_obj_dispatch(struct qcomtee_object_in= voke_ctx *oic, msleep(*(u32 *)(args[0].b.addr)); /* No output object. */ oic->data =3D NULL; + + break; + case QCOMTEE_OBJECT_OP_MAP_REGION: + if (qcomtee_args_len(args) !=3D 3 || + args[0].type !=3D QCOMTEE_ARG_TYPE_OB || + args[1].type !=3D QCOMTEE_ARG_TYPE_IO || + args[2].type !=3D QCOMTEE_ARG_TYPE_OO || + args[0].b.size < sizeof(struct qcomtee_mapping_info)) + return -EINVAL; + + map_info =3D args[0].b.addr; + mem_object =3D args[1].o; + + qcomtee_mem_object_map(mem_object, &map_object, + &map_info->paddr, &map_info->len, + &map_info->perms); + + args[2].o =3D map_object; + /* One output object; pass it for cleanup to notify. */ + oic->data =3D map_object; + + qcomtee_object_put(mem_object); + break; default: err =3D -EINVAL; @@ -52,8 +89,21 @@ qcomtee_primordial_obj_dispatch(struct qcomtee_object_in= voke_ctx *oic, return err; } =20 +/* Called after submitting the callback response. */ +static void qcomtee_primordial_obj_notify(struct qcomtee_object_invoke_ctx= *oic, + struct qcomtee_object *unused, + int err) +{ + struct qcomtee_object *object =3D oic->data; + + /* If err, QTEE did not obtain mapping object. Drop it. */ + if (object && err) + qcomtee_object_put(object); +} + static struct qcomtee_object_operations qcomtee_primordial_obj_ops =3D { .dispatch =3D qcomtee_primordial_obj_dispatch, + .notify =3D qcomtee_primordial_obj_notify, }; =20 struct qcomtee_object qcomtee_primordial_object =3D { diff --git a/drivers/tee/qcomtee/qcomtee.h b/drivers/tee/qcomtee/qcomtee.h index 084b3882017e..f39bf63fd1c2 100644 --- a/drivers/tee/qcomtee/qcomtee.h +++ b/drivers/tee/qcomtee/qcomtee.h @@ -15,6 +15,7 @@ /* Flags relating to object reference. */ #define QCOMTEE_OBJREF_FLAG_TEE BIT(0) #define QCOMTEE_OBJREF_FLAG_USER BIT(1) +#define QCOMTEE_OBJREF_FLAG_MEM BIT(2) =20 /** * struct qcomtee - Main service struct. @@ -143,4 +144,42 @@ int qcomtee_user_object_submit(struct tee_context *ctx, /* (2) Primordial Object. */ extern struct qcomtee_object qcomtee_primordial_object; =20 +/* (3) Memory Object API. */ + +/* Is it a memory object using tee_shm? */ +int is_qcomtee_memobj_object(struct qcomtee_object *object); + +/** + * qcomtee_memobj_param_to_object() - OBJREF parameter to &struct qcomtee_= object. + * @object: object returned. + * @param: TEE parameter. + * @ctx: context in which the conversion should happen. + * + * @param is an OBJREF with %QCOMTEE_OBJREF_FLAG_MEM flags. + * + * Return: On success return 0 or <0 on failure. + */ +int qcomtee_memobj_param_to_object(struct qcomtee_object **object, + struct tee_param *param, + struct tee_context *ctx); + +/* Reverse what qcomtee_memobj_param_to_object() does. */ +int qcomtee_memobj_param_from_object(struct tee_param *param, + struct qcomtee_object *object, + struct tee_context *ctx); + +/** + * qcomtee_mem_object_map() - Map a memory object. + * @object: memory object. + * @map_object: created mapping object. + * @mem_paddr: physical address of the memory. + * @mem_size: size of the memory. + * @perms: QTEE access permissions. + * + * Return: On success return 0 or <0 on failure. + */ +int qcomtee_mem_object_map(struct qcomtee_object *object, + struct qcomtee_object **map_object, u64 *mem_paddr, + u64 *mem_size, u32 *perms); + #endif /* QCOMTEE_H */ diff --git a/drivers/tee/qcomtee/shm.c b/drivers/tee/qcomtee/shm.c index 2aea76487372..580bd25f98ed 100644 --- a/drivers/tee/qcomtee/shm.c +++ b/drivers/tee/qcomtee/shm.c @@ -117,9 +117,6 @@ static int qcomtee_shm_unregister(struct tee_context *c= tx, struct tee_shm *shm) static int pool_op_alloc(struct tee_shm_pool *pool, struct tee_shm *shm, size_t size, size_t align) { - if (!(shm->flags & TEE_SHM_PRIV)) - return -ENOMEM; - return tee_dyn_shm_alloc_helper(shm, size, align, qcomtee_shm_register); } =20 --=20 2.34.1