From nobody Thu Dec 5 02:38:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1732723719947832.1276620081653; Wed, 27 Nov 2024 08:08:39 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.844903.1260462 (Exim 4.92) (envelope-from ) id 1tGKaZ-0004rX-O3; Wed, 27 Nov 2024 16:08:27 +0000 Received: by outflank-mailman (output) from mailman id 844903.1260462; Wed, 27 Nov 2024 16:08:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tGKaZ-0004qM-Im; Wed, 27 Nov 2024 16:08:27 +0000 Received: by outflank-mailman (input) for mailman id 844903; Wed, 27 Nov 2024 16:08:26 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tGKaY-0002q2-5L for xen-devel@lists.xenproject.org; Wed, 27 Nov 2024 16:08:26 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id d3ff74cd-acd9-11ef-a0cd-8be0dac302b0; Wed, 27 Nov 2024 17:08:23 +0100 (CET) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6F1A31477; Wed, 27 Nov 2024 08:08:53 -0800 (PST) Received: from C3HXLD123V.arm.com (unknown [10.57.58.181]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 056973F5A1; Wed, 27 Nov 2024 08:08:21 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d3ff74cd-acd9-11ef-a0cd-8be0dac302b0 X-Custom-Connection: eyJyZW1vdGVpcCI6IjIxNy4xNDAuMTEwLjE3MiIsImhlbG8iOiJmb3NzLmFybS5jb20ifQ== X-Custom-Transaction: eyJpZCI6ImQzZmY3NGNkLWFjZDktMTFlZi1hMGNkLThiZTBkYWMzMDJiMCIsInRzIjoxNzMyNzIzNzA0LjE5Nzk3Nywic2VuZGVyIjoiYmVydHJhbmQubWFycXVpc0Bhcm0uY29tIiwicmVjaXBpZW50IjoieGVuLWRldmVsQGxpc3RzLnhlbnByb2plY3Qub3JnIn0= From: Bertrand Marquis To: xen-devel@lists.xenproject.org Cc: jens.wiklander@linaro.org, Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Michal Orzel Subject: [PATCH v3 06/10] xen/arm: ffa: Use bit 15 convention for SPs Date: Wed, 27 Nov 2024 17:07:38 +0100 Message-ID: <0b987183498242587f3795e870a7395b132ec9ee.1732702210.git.bertrand.marquis@arm.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1732723721910019100 Content-Type: text/plain; charset="utf-8" Make use and required to have bit 15 convention respected by secure world (having bit 15 of IDs set for secure endpoints and non-set for non-secure ones). If any secure partition has an ID with bit 15 not set, it will not be possible to contact or detect them. Print an error log during probe for each secure endpoint detected with bit 15 not set. We are switching to this convention because Xen is currently not using VMIDs with bit 15 set so we are sure that no VM will have it set (this is ensured by BUILD_BUG_ON in case this becomes false in the future). It is allowing to easily distinguish between secure and non-secure endpoints, preventing the need to store a list of secure endpoint IDs in Xen. Signed-off-by: Bertrand Marquis --- Changes in v3: - rename real_num to n_limit - remove log of skipped SP due to invalid ID as it is already printed Changes in v2: - rebase --- xen/arch/arm/tee/ffa.c | 22 ++++++++++---- xen/arch/arm/tee/ffa_partinfo.c | 51 +++++++++++++++++++++++++-------- xen/arch/arm/tee/ffa_private.h | 7 +++++ xen/arch/arm/tee/ffa_shm.c | 12 +++++++- 4 files changed, 74 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 4b283a4de5d0..0026ac9134ad 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -195,6 +195,14 @@ static void handle_msg_send_direct_req(struct cpu_user= _regs *regs, uint32_t fid) goto out; } =20 + /* we do not support direct messages to VMs */ + if ( !FFA_ID_IS_SECURE(src_dst & GENMASK(15,0)) ) + { + resp.a0 =3D FFA_ERROR; + resp.a2 =3D FFA_RET_NOT_SUPPORTED; + goto out; + } + arg.a1 =3D src_dst; arg.a2 =3D get_user_reg(regs, 2) & mask; arg.a3 =3D get_user_reg(regs, 3) & mask; @@ -391,11 +399,15 @@ static int ffa_domain_init(struct domain *d) =20 if ( !ffa_fw_version ) return -ENODEV; - /* - * We can't use that last possible domain ID or ffa_get_vm_id() would - * cause an overflow. - */ - if ( d->domain_id >=3D UINT16_MAX) + /* + * We are using the domain_id + 1 as the FF-A ID for VMs as FF-A ID 0 = is + * reserved for the hypervisor and we only support secure endpoints us= ing + * FF-A IDs with BIT 15 set to 1 so make sure those are not used by Xe= n. + */ + BUILD_BUG_ON(DOMID_FIRST_RESERVED >=3D UINT16_MAX); + BUILD_BUG_ON((DOMID_MASK & BIT(15, U)) !=3D 0); + + if ( d->domain_id >=3D DOMID_FIRST_RESERVED ) return -ERANGE; =20 ctx =3D xzalloc(struct ffa_ctx); diff --git a/xen/arch/arm/tee/ffa_partinfo.c b/xen/arch/arm/tee/ffa_partinf= o.c index 75a073d090e0..74324e1d9d3f 100644 --- a/xen/arch/arm/tee/ffa_partinfo.c +++ b/xen/arch/arm/tee/ffa_partinfo.c @@ -169,14 +169,23 @@ void ffa_handle_partition_info_get(struct cpu_user_re= gs *regs) =20 if ( ffa_sp_count > 0 ) { - uint32_t n; + uint32_t n, n_limit =3D ffa_sp_count; void *src_buf =3D ffa_rx; =20 /* copy the secure partitions info */ - for ( n =3D 0; n < ffa_sp_count; n++ ) + for ( n =3D 0; n < n_limit; n++ ) { - memcpy(dst_buf, src_buf, dst_size); - dst_buf +=3D dst_size; + struct ffa_partition_info_1_1 *fpi =3D src_buf; + + /* filter out SP not following bit 15 convention if any */ + if ( FFA_ID_IS_SECURE(fpi->id) ) + { + memcpy(dst_buf, src_buf, dst_size); + dst_buf +=3D dst_size; + } + else + ffa_sp_count--; + src_buf +=3D src_size; } } @@ -276,10 +285,25 @@ static bool init_subscribers(uint16_t count, uint32_t= fpi_size) { fpi =3D ffa_rx + n * fpi_size; =20 - if ( fpi->partition_properties & FFA_PART_PROP_NOTIF_CREATED ) - subscr_vm_created_count++; - if ( fpi->partition_properties & FFA_PART_PROP_NOTIF_DESTROYED ) - subscr_vm_destroyed_count++; + /* + * We need to have secure partitions using bit 15 set convention f= or + * secure partition IDs. + * Inform the user with a log and discard giving created or destroy + * event to those IDs. + */ + if ( !FFA_ID_IS_SECURE(fpi->id) ) + { + printk(XENLOG_ERR "ffa: Firmware is not using bit 15 conventio= n for IDs !!\n" + "ffa: Secure partition with id 0x%04x cannot= be used\n", + fpi->id); + } + else + { + if ( fpi->partition_properties & FFA_PART_PROP_NOTIF_CREATED ) + subscr_vm_created_count++; + if ( fpi->partition_properties & FFA_PART_PROP_NOTIF_DESTROYED= ) + subscr_vm_destroyed_count++; + } } =20 if ( subscr_vm_created_count ) @@ -299,10 +323,13 @@ static bool init_subscribers(uint16_t count, uint32_t= fpi_size) { fpi =3D ffa_rx + n * fpi_size; =20 - if ( fpi->partition_properties & FFA_PART_PROP_NOTIF_CREATED ) - subscr_vm_created[c_pos++] =3D fpi->id; - if ( fpi->partition_properties & FFA_PART_PROP_NOTIF_DESTROYED ) - subscr_vm_destroyed[d_pos++] =3D fpi->id; + if ( FFA_ID_IS_SECURE(fpi->id) ) + { + if ( fpi->partition_properties & FFA_PART_PROP_NOTIF_CREATED ) + subscr_vm_created[c_pos++] =3D fpi->id; + if ( fpi->partition_properties & FFA_PART_PROP_NOTIF_DESTROYED= ) + subscr_vm_destroyed[d_pos++] =3D fpi->id; + } } =20 return true; diff --git a/xen/arch/arm/tee/ffa_private.h b/xen/arch/arm/tee/ffa_private.h index e5bc73f9039e..afe69b43dbef 100644 --- a/xen/arch/arm/tee/ffa_private.h +++ b/xen/arch/arm/tee/ffa_private.h @@ -108,6 +108,13 @@ */ #define FFA_CTX_TEARDOWN_DELAY SECONDS(1) =20 +/* + * We rely on the convention suggested but not mandated by the FF-A + * specification that secure world endpoint identifiers have the bit 15 + * set and normal world have it set to 0. + */ +#define FFA_ID_IS_SECURE(id) ((id) & BIT(15, U)) + /* FF-A-1.1-REL0 section 10.9.2 Memory region handle, page 167 */ #define FFA_HANDLE_HYP_FLAG BIT(63, ULL) #define FFA_HANDLE_INVALID 0xffffffffffffffffULL diff --git a/xen/arch/arm/tee/ffa_shm.c b/xen/arch/arm/tee/ffa_shm.c index efa5b67db8e1..29675f9ba3f7 100644 --- a/xen/arch/arm/tee/ffa_shm.c +++ b/xen/arch/arm/tee/ffa_shm.c @@ -469,6 +469,7 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs) int ret =3D FFA_RET_DENIED; uint32_t range_count; uint32_t region_offs; + uint16_t dst_id; =20 if ( !ffa_fw_supports_fid(FFA_MEM_SHARE_64) ) { @@ -537,6 +538,15 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs) goto out_unlock; =20 mem_access =3D ctx->tx + trans.mem_access_offs; + + dst_id =3D ACCESS_ONCE(mem_access->access_perm.endpoint_id); + if ( !FFA_ID_IS_SECURE(dst_id) ) + { + /* we do not support sharing with VMs */ + ret =3D FFA_RET_NOT_SUPPORTED; + goto out_unlock; + } + if ( ACCESS_ONCE(mem_access->access_perm.perm) !=3D FFA_MEM_ACC_RW ) { ret =3D FFA_RET_NOT_SUPPORTED; @@ -567,7 +577,7 @@ void ffa_handle_mem_share(struct cpu_user_regs *regs) goto out_unlock; } shm->sender_id =3D trans.sender_id; - shm->ep_id =3D ACCESS_ONCE(mem_access->access_perm.endpoint_id); + shm->ep_id =3D dst_id; =20 /* * Check that the Composite memory region descriptor fits. --=20 2.47.0