From nobody Tue Dec 16 03:02:17 2025 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 1741618326415221.137829668844; Mon, 10 Mar 2025 07:52:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.906553.1313995 (Exim 4.92) (envelope-from ) id 1treTK-0003zx-8b; Mon, 10 Mar 2025 14:51:14 +0000 Received: by outflank-mailman (output) from mailman id 906553.1313995; Mon, 10 Mar 2025 14:51:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1treTK-0003z4-4t; Mon, 10 Mar 2025 14:51:14 +0000 Received: by outflank-mailman (input) for mailman id 906553; Mon, 10 Mar 2025 14:51:13 +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 1treTJ-0002rH-3D for xen-devel@lists.xenproject.org; Mon, 10 Mar 2025 14:51:13 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-sth1.inumbo.com (Halon) with ESMTP id 1bfedb14-fdbf-11ef-9ab8-95dc52dad729; Mon, 10 Mar 2025 15:51:12 +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 57F0626BE; Mon, 10 Mar 2025 07:51:23 -0700 (PDT) Received: from C3HXLD123V.arm.com (unknown [10.57.38.103]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ABFF63F5A1; Mon, 10 Mar 2025 07:51:10 -0700 (PDT) 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: 1bfedb14-fdbf-11ef-9ab8-95dc52dad729 From: Bertrand Marquis To: xen-devel@lists.xenproject.org Cc: jens.wiklander@linaro.org, Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Michal Orzel Subject: [PATCH v2 4/5] xen/arm: ffa: Add indirect message between VM Date: Mon, 10 Mar 2025 15:50:36 +0100 Message-ID: <2265f8a8c22034c629025f384acb4f33a4235387.1741617888.git.bertrand.marquis@arm.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1741618327073019000 Content-Type: text/plain; charset="utf-8" Add support for indirect messages between VMs. This is only enabled if CONFIG_FFA_VM_TO_VM is selected. Signed-off-by: Bertrand Marquis --- Changes in v2: - Switch ifdef to IS_ENABLED --- xen/arch/arm/tee/ffa_msg.c | 96 +++++++++++++++++++++++++++++++--- xen/arch/arm/tee/ffa_private.h | 4 ++ 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/xen/arch/arm/tee/ffa_msg.c b/xen/arch/arm/tee/ffa_msg.c index ee594e737fc7..336d5bbf64f6 100644 --- a/xen/arch/arm/tee/ffa_msg.c +++ b/xen/arch/arm/tee/ffa_msg.c @@ -96,9 +96,6 @@ int32_t ffa_handle_msg_send2(struct cpu_user_regs *regs) uint16_t dst_id, src_id; int32_t ret; =20 - if ( !ffa_fw_supports_fid(FFA_MSG_SEND2) ) - return FFA_RET_NOT_SUPPORTED; - if ( !spin_trylock(&src_ctx->tx_lock) ) return FFA_RET_BUSY; =20 @@ -106,10 +103,10 @@ int32_t ffa_handle_msg_send2(struct cpu_user_regs *re= gs) src_id =3D src_msg->send_recv_id >> 16; dst_id =3D src_msg->send_recv_id & GENMASK(15,0); =20 - if ( src_id !=3D ffa_get_vm_id(src_d) || !FFA_ID_IS_SECURE(dst_id) ) + if ( src_id !=3D ffa_get_vm_id(src_d) ) { ret =3D FFA_RET_INVALID_PARAMETERS; - goto out_unlock_tx; + goto out; } =20 /* check source message fits in buffer */ @@ -118,13 +115,96 @@ int32_t ffa_handle_msg_send2(struct cpu_user_regs *re= gs) src_msg->msg_offset < sizeof(struct ffa_part_msg_rxtx) ) { ret =3D FFA_RET_INVALID_PARAMETERS; - goto out_unlock_tx; + goto out; } =20 - ret =3D ffa_simple_call(FFA_MSG_SEND2, + if ( FFA_ID_IS_SECURE(dst_id) ) + { + /* Message for a secure partition */ + if ( !ffa_fw_supports_fid(FFA_MSG_SEND2) ) + { + ret =3D FFA_RET_NOT_SUPPORTED; + goto out; + } + + ret =3D ffa_simple_call(FFA_MSG_SEND2, ((uint32_t)ffa_get_vm_id(src_d)) << 16, 0, 0, 0); + goto out; + } =20 -out_unlock_tx: + /* Message for a VM */ + if ( IS_ENABLED(CONFIG_FFA_VM_TO_VM) ) + { + struct domain *dst_d; + struct ffa_ctx *dst_ctx; + struct ffa_part_msg_rxtx *dst_msg; + int err; + + if ( dst_id =3D=3D 0 ) + { + /* FF-A ID 0 is the hypervisor, this is not valid */ + ret =3D FFA_RET_INVALID_PARAMETERS; + goto out; + } + + /* This is also checking that dest is not src */ + err =3D rcu_lock_live_remote_domain_by_id(dst_id - 1, &dst_d); + if ( err ) + { + ret =3D FFA_RET_INVALID_PARAMETERS; + goto out; + } + + if ( dst_d->arch.tee =3D=3D NULL ) + { + ret =3D FFA_RET_INVALID_PARAMETERS; + goto out_unlock; + } + + dst_ctx =3D dst_d->arch.tee; + if ( !dst_ctx->guest_vers ) + { + ret =3D FFA_RET_INVALID_PARAMETERS; + goto out_unlock; + } + + /* This also checks that destination has set a Rx buffer */ + ret =3D ffa_rx_acquire(dst_d); + if ( ret ) + goto out_unlock; + + /* we need to have enough space in the destination buffer */ + if ( dst_ctx->page_count * FFA_PAGE_SIZE < + (sizeof(struct ffa_part_msg_rxtx) + src_msg->msg_size) ) + { + ret =3D FFA_RET_NO_MEMORY; + ffa_rx_release(dst_d); + goto out_unlock; + } + + dst_msg =3D dst_ctx->rx; + + /* prepare destination header */ + dst_msg->flags =3D 0; + dst_msg->reserved =3D 0; + dst_msg->msg_offset =3D sizeof(struct ffa_part_msg_rxtx); + dst_msg->send_recv_id =3D src_msg->send_recv_id; + dst_msg->msg_size =3D src_msg->msg_size; + + memcpy(dst_ctx->rx + sizeof(struct ffa_part_msg_rxtx), + src_ctx->tx + src_msg->msg_offset, src_msg->msg_size); + + /* receiver rx buffer will be released by the receiver*/ + +out_unlock: + rcu_unlock_domain(dst_d); + if ( !ret ) + ffa_raise_rx_buffer_full(dst_d); + } + else + ret =3D FFA_RET_INVALID_PARAMETERS; + +out: spin_unlock(&src_ctx->tx_lock); return ret; } diff --git a/xen/arch/arm/tee/ffa_private.h b/xen/arch/arm/tee/ffa_private.h index 1f5067d5d0c9..340db229453c 100644 --- a/xen/arch/arm/tee/ffa_private.h +++ b/xen/arch/arm/tee/ffa_private.h @@ -380,6 +380,10 @@ int ffa_handle_notification_set(struct cpu_user_regs *= regs); =20 #ifdef CONFIG_FFA_VM_TO_VM void ffa_raise_rx_buffer_full(struct domain *d); +#else +static inline void ffa_raise_rx_buffer_full(struct domain *d) +{ +} #endif =20 void ffa_handle_msg_send_direct_req(struct cpu_user_regs *regs, uint32_t f= id); --=20 2.47.1