From nobody Thu Dec 5 02:42:43 2024 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 9C3221865EE; Tue, 3 Dec 2024 04:20:24 +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=1733199628; cv=none; b=fYeYtF99d1aXg2HTwKB7tTLJpY7bXp05O8b48JgVe8wbIQmEfnsvCtV9j68iFyJIhEmKxe+MaZqnDsuvqdS2U8GgcacWeJsYdjH8bUzNkFNcYhxICUYE8lF4F+oM5swQNSTXxqCNKbPT+Jc5kXbLdKjFOFlGwVFDefkV1Lu+s8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733199628; c=relaxed/simple; bh=3i/3N33GOjM+TRUYdEPkKA9tAtATAOGKoiWjEBrayg8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=NvayCcacdbDY/orGQujt+DiBW8BBoi36iNvSNPP5PMT+87Me0ghR7J+4qprSrp6/9b21ekuwWDtzgadQlUlbAl+9OaQ6JRRrmUncjMBTYuxOpSQ07CqQRM6bUxmBTtgdl/34tYiN7Cxe0p5lGPFz6UsL7RB2C/AfQkc537F4kXo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=QOT3yHy5; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="QOT3yHy5" Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B2NLL5e026307; Tue, 3 Dec 2024 04:20:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 9aNXv5On+dFmkzecaFA/cMCc+Ygz0XIJ35BiM+VNrVo=; b=QOT3yHy5ozh21wrn b6SbcKOyrkV8e4V5L+rsigvzlIz2QBE738GxLJu+ZIoJqm/p1bKnNovLCnTN7y27 /U6qjBjynM7xH2k/unT4HHXRQfLAjSn719xSdo9sAq+mQYzMer/P0GFp26M6nEbK L2ltCH8s4DftGykIZyERWl7EA0A94yUkjG1iU6FvTNrA8RF3YNl6B9Ok+WPbrUbc +RQvGa+9f9HLPm6tJVHgWlY/z/8stnRclCqRDdu/9lctN2+DYVc11z7eM+YOOScO gy7v5dUDmSa1O7r++UQPh4J7S8qzCcxU9OLwtN0eAj7Xjar83iC2gP1NZPMcrXrW uosePg== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 437ufe6p2v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 03 Dec 2024 04:20:06 +0000 (GMT) Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA01.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4B34K5t0031186 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 3 Dec 2024 04:20:05 GMT Received: from hu-azarrabi-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Mon, 2 Dec 2024 20:20:05 -0800 From: Amirreza Zarrabi Date: Mon, 2 Dec 2024 20:19:18 -0800 Subject: [PATCH 02/10] tee: add TEE_IOCTL_PARAM_ATTR_TYPE_MEMBUF 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: <20241202-qcom-tee-using-tee-ss-without-mem-obj-v1-2-f502ef01e016@quicinc.com> References: <20241202-qcom-tee-using-tee-ss-without-mem-obj-v1-0-f502ef01e016@quicinc.com> In-Reply-To: <20241202-qcom-tee-using-tee-ss-without-mem-obj-v1-0-f502ef01e016@quicinc.com> To: Jens Wiklander , Sumit Garg , Bjorn Andersson , "Konrad Dybcio" , Rob Herring , "Krzysztof Kozlowski" , Conor Dooley , "Bartosz Golaszewski" , Srinivas Kandagatla CC: , , , , , Amirreza Zarrabi X-Mailer: b4 0.13.0 X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: 8XTfu1P-uI3ZOeF2M7W4crw0o68Sbb-N X-Proofpoint-GUID: 8XTfu1P-uI3ZOeF2M7W4crw0o68Sbb-N X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 spamscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 mlxlogscore=999 clxscore=1011 adultscore=0 bulkscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2411120000 definitions=main-2412030034 For drivers that can transfer data to the TEE without needing shared memory from client, it is necessary to receive the user address directly, bypassing any processing by the TEE subsystem. Introduce TEE_IOCTL_PARAM_ATTR_TYPE_MEMBUF_INPUT/OUTPUT/INOUT to represent userspace buffers. Signed-off-by: Amirreza Zarrabi --- drivers/tee/tee_core.c | 26 ++++++++++++++++++++++++++ include/linux/tee_drv.h | 6 ++++++ include/uapi/linux/tee.h | 22 ++++++++++++++++------ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/drivers/tee/tee_core.c b/drivers/tee/tee_core.c index 24edce4cdbaa..942ff5b359b2 100644 --- a/drivers/tee/tee_core.c +++ b/drivers/tee/tee_core.c @@ -381,6 +381,16 @@ static int params_from_user(struct tee_context *ctx, s= truct tee_param *params, params[n].u.value.b =3D ip.b; params[n].u.value.c =3D ip.c; break; + case TEE_IOCTL_PARAM_ATTR_TYPE_MEMBUF_INPUT: + case TEE_IOCTL_PARAM_ATTR_TYPE_MEMBUF_OUTPUT: + case TEE_IOCTL_PARAM_ATTR_TYPE_MEMBUF_INOUT: + params[n].u.membuf.uaddr =3D u64_to_user_ptr(ip.a); + params[n].u.membuf.size =3D ip.b; + + if (!access_ok(params[n].u.membuf.uaddr, params[n].u.membuf.size)) + return -EFAULT; + + break; case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT: @@ -449,6 +459,11 @@ static int params_to_user(struct tee_ioctl_param __use= r *uparams, put_user(p->u.value.c, &up->c)) return -EFAULT; break; + case TEE_IOCTL_PARAM_ATTR_TYPE_MEMBUF_OUTPUT: + case TEE_IOCTL_PARAM_ATTR_TYPE_MEMBUF_INOUT: + if (put_user((u64)p->u.membuf.size, &up->b)) + return -EFAULT; + break; case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT: if (put_user((u64)p->u.memref.size, &up->b)) @@ -649,6 +664,12 @@ static int params_to_supp(struct tee_context *ctx, ip.b =3D p->u.value.b; ip.c =3D p->u.value.c; break; + case TEE_IOCTL_PARAM_ATTR_TYPE_MEMBUF_INPUT: + case TEE_IOCTL_PARAM_ATTR_TYPE_MEMBUF_INOUT: + ip.a =3D (u64)p->u.membuf.uaddr; + ip.b =3D p->u.membuf.size; + ip.c =3D 0; + break; case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT: @@ -751,6 +772,11 @@ static int params_from_supp(struct tee_param *params, = size_t num_params, p->u.value.b =3D ip.b; p->u.value.c =3D ip.c; break; + case TEE_IOCTL_PARAM_ATTR_TYPE_MEMBUF_OUTPUT: + case TEE_IOCTL_PARAM_ATTR_TYPE_MEMBUF_INOUT: + p->u.membuf.uaddr =3D u64_to_user_ptr(ip.a); + p->u.membuf.size =3D ip.b; + break; case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT: case TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT: /* diff --git a/include/linux/tee_drv.h b/include/linux/tee_drv.h index a54c203000ed..b66e611fece4 100644 --- a/include/linux/tee_drv.h +++ b/include/linux/tee_drv.h @@ -82,6 +82,11 @@ struct tee_param_memref { struct tee_shm *shm; }; =20 +struct tee_param_membuf { + void * __user uaddr; + size_t size; +}; + struct tee_param_value { u64 a; u64 b; @@ -92,6 +97,7 @@ struct tee_param { u64 attr; union { struct tee_param_memref memref; + struct tee_param_membuf membuf; struct tee_param_value value; } u; }; diff --git a/include/uapi/linux/tee.h b/include/uapi/linux/tee.h index d0430bee8292..fae68386968a 100644 --- a/include/uapi/linux/tee.h +++ b/include/uapi/linux/tee.h @@ -151,6 +151,13 @@ struct tee_ioctl_buf_data { #define TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_OUTPUT 6 #define TEE_IOCTL_PARAM_ATTR_TYPE_MEMREF_INOUT 7 /* input and output */ =20 +/* + * These defines memory buffer parameters. + */ +#define TEE_IOCTL_PARAM_ATTR_TYPE_MEMBUF_INPUT 8 +#define TEE_IOCTL_PARAM_ATTR_TYPE_MEMBUF_OUTPUT 9 +#define TEE_IOCTL_PARAM_ATTR_TYPE_MEMBUF_INOUT 10 /* input and output */ + /* * Mask for the type part of the attribute, leaves room for more types */ @@ -186,14 +193,17 @@ struct tee_ioctl_buf_data { /** * struct tee_ioctl_param - parameter * @attr: attributes - * @a: if a memref, offset into the shared memory object, else a value par= ameter - * @b: if a memref, size of the buffer, else a value parameter + * @a: if a memref, offset into the shared memory object, + * else if a membuf, address into the user buffer, + * else a value parameter + * @b: if a memref or membuf, size of the buffer, else a value parameter * @c: if a memref, shared memory identifier, else a value parameter * - * @attr & TEE_PARAM_ATTR_TYPE_MASK indicates if memref or value is used in - * the union. TEE_PARAM_ATTR_TYPE_VALUE_* indicates value and - * TEE_PARAM_ATTR_TYPE_MEMREF_* indicates memref. TEE_PARAM_ATTR_TYPE_NONE - * indicates that none of the members are used. + * @attr & TEE_PARAM_ATTR_TYPE_MASK indicates if memref, membuf, or value = is + * used in the union. TEE_PARAM_ATTR_TYPE_VALUE_* indicates value, + * TEE_PARAM_ATTR_TYPE_MEMREF_* indicates memref, and TEE_PARAM_ATTR_TYPE_= MEMBUF_* + * indicates membuf. TEE_PARAM_ATTR_TYPE_NONE indicates that none of the m= embers + * are used. * * Shared memory is allocated with TEE_IOC_SHM_ALLOC which returns an * identifier representing the shared memory object. A memref can reference --=20 2.34.1