From nobody Fri Oct 31 16:06:13 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 1747926540325214.60705876088764; Thu, 22 May 2025 08:09:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.994206.1377285 (Exim 4.92) (envelope-from ) id 1uI7XG-0007cM-R0; Thu, 22 May 2025 15:08:42 +0000 Received: by outflank-mailman (output) from mailman id 994206.1377285; Thu, 22 May 2025 15:08:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uI7XG-0007cF-Mm; Thu, 22 May 2025 15:08:42 +0000 Received: by outflank-mailman (input) for mailman id 994206; Thu, 22 May 2025 15:08:41 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1uI7XF-0006dU-Av for xen-devel@lists.xenproject.org; Thu, 22 May 2025 15:08:41 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id a45a25eb-371e-11f0-b892-0df219b8e170; Thu, 22 May 2025 17:08:39 +0200 (CEST) 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 C4C251A32; Thu, 22 May 2025 08:08:24 -0700 (PDT) Received: from C3HXLD123V.arm.com (unknown [10.57.50.224]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BAC293F673; Thu, 22 May 2025 08:08:37 -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: a45a25eb-371e-11f0-b892-0df219b8e170 From: Bertrand Marquis To: xen-devel@lists.xenproject.org Cc: jens.wiklander@linaro.org, Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Michal Orzel Subject: [PATCH v6 4/6] xen/arm: ffa: Add buffer full notification support Date: Thu, 22 May 2025 17:08:05 +0200 Message-ID: <7e206a2e4f093af965a134bda23e3c4104267826.1747925287.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: 1747926541832116600 Content-Type: text/plain; charset="utf-8" Add support to raise a Rx buffer full notification to a VM. This function will be used for indirect message support between VM and is only activated if CONFIG_FFA_VM_TO_VM is selected. Even if there are 32 framework notifications possible, right now only one is defined so the implementation is simplified to only handle the buffer full notification using a boolean. If other framework notifications have to be supported one day, the design will have to be modified to handle it properly. Signed-off-by: Bertrand Marquis Reviewed-by: Jens Wiklander Acked-by: Julien Grall --- Changes in v6: - None Changes in v5: - None Changes in v4: - Add Jens R-b Changes in v3: - introduce a vm_pending boolean to track if VM notifications are pending and allow to decorelate pending secure notifications from pending vm ones - remove ifdef around boolean entries for notifications and make use of IS_ENABLED instead of ifdefs when possible - Fix notification number signaled to VMs for buffer full to use the proper GUEST_FFA_NOTIF_PEND_INTR_ID instead of the identifier received from the SPMC. - Move back into this patch ffa_private.h part which was wrongly in the patch for indirect messages between VM Changes in v2: - Switch ifdef to IS_ENABLED when possible --- xen/arch/arm/tee/ffa_notif.c | 36 ++++++++++++++++++++++++++++------ xen/arch/arm/tee/ffa_private.h | 23 +++++++++++++++++++++- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/tee/ffa_notif.c b/xen/arch/arm/tee/ffa_notif.c index 00efaf8f7353..f6df2f15bb00 100644 --- a/xen/arch/arm/tee/ffa_notif.c +++ b/xen/arch/arm/tee/ffa_notif.c @@ -69,6 +69,7 @@ void ffa_handle_notification_info_get(struct cpu_user_reg= s *regs) { struct domain *d =3D current->domain; struct ffa_ctx *ctx =3D d->arch.tee; + bool notif_pending; =20 if ( !notif_enabled ) { @@ -76,7 +77,11 @@ void ffa_handle_notification_info_get(struct cpu_user_re= gs *regs) return; } =20 - if ( test_and_clear_bool(ctx->notif.secure_pending) ) + notif_pending =3D test_and_clear_bool(ctx->notif.secure_pending); + if ( IS_ENABLED(CONFIG_FFA_VM_TO_VM) ) + notif_pending |=3D test_and_clear_bool(ctx->notif.vm_pending); + + if ( notif_pending ) { /* A pending global notification for the guest */ ffa_set_regs(regs, FFA_SUCCESS_64, 0, @@ -93,6 +98,7 @@ void ffa_handle_notification_info_get(struct cpu_user_reg= s *regs) void ffa_handle_notification_get(struct cpu_user_regs *regs) { struct domain *d =3D current->domain; + struct ffa_ctx *ctx =3D d->arch.tee; uint32_t recv =3D get_user_reg(regs, 1); uint32_t flags =3D get_user_reg(regs, 2); uint32_t w2 =3D 0; @@ -132,11 +138,7 @@ void ffa_handle_notification_get(struct cpu_user_regs = *regs) */ if ( ( flags & FFA_NOTIF_FLAG_BITMAP_SP ) && ( flags & FFA_NOTIF_FLAG_BITMAP_SPM ) ) - { - struct ffa_ctx *ctx =3D d->arch.tee; - - ACCESS_ONCE(ctx->notif.secure_pending) =3D false; - } + ACCESS_ONCE(ctx->notif.secure_pending) =3D false; =20 arm_smccc_1_2_smc(&arg, &resp); e =3D ffa_get_ret_code(&resp); @@ -156,6 +158,14 @@ void ffa_handle_notification_get(struct cpu_user_regs = *regs) w6 =3D resp.a6; } =20 + if ( IS_ENABLED(CONFIG_FFA_VM_TO_VM) && + flags & FFA_NOTIF_FLAG_BITMAP_HYP && + test_and_clear_bool(ctx->notif.buff_full_pending) ) + { + ACCESS_ONCE(ctx->notif.vm_pending) =3D false; + w7 =3D FFA_NOTIF_RX_BUFFER_FULL; + } + ffa_set_regs(regs, FFA_SUCCESS_32, 0, w2, w3, w4, w5, w6, w7); } =20 @@ -178,6 +188,20 @@ int ffa_handle_notification_set(struct cpu_user_regs *= regs) bitmap_hi); } =20 +#ifdef CONFIG_FFA_VM_TO_VM +void ffa_raise_rx_buffer_full(struct domain *d) +{ + struct ffa_ctx *ctx =3D d->arch.tee; + + if ( !ctx ) + return; + + ACCESS_ONCE(ctx->notif.buff_full_pending) =3D true; + if ( !test_and_set_bool(ctx->notif.vm_pending) ) + vgic_inject_irq(d, d->vcpu[0], GUEST_FFA_NOTIF_PEND_INTR_ID, true); +} +#endif + /* * Extract a 16-bit ID (index n) from the successful return value from * FFA_NOTIFICATION_INFO_GET_64 or FFA_NOTIFICATION_INFO_GET_32. IDs are diff --git a/xen/arch/arm/tee/ffa_private.h b/xen/arch/arm/tee/ffa_private.h index 08dbdf9fcddd..d39aca4500b9 100644 --- a/xen/arch/arm/tee/ffa_private.h +++ b/xen/arch/arm/tee/ffa_private.h @@ -218,6 +218,8 @@ #define FFA_NOTIF_INFO_GET_ID_COUNT_SHIFT 7 #define FFA_NOTIF_INFO_GET_ID_COUNT_MASK 0x1F =20 +#define FFA_NOTIF_RX_BUFFER_FULL BIT(0, U) + /* Feature IDs used with FFA_FEATURES */ #define FFA_FEATURE_NOTIF_PEND_INTR 0x1U #define FFA_FEATURE_SCHEDULE_RECV_INTR 0x2U @@ -303,9 +305,20 @@ struct ffa_mem_region { struct ffa_ctx_notif { /* * True if domain is reported by FFA_NOTIFICATION_INFO_GET to have - * pending global notifications. + * pending notifications from the secure world. */ bool secure_pending; + + /* + * True if domain is reported by FFA_NOTIFICATION_INFO_GET to have + * pending notifications from VMs (including framework ones). + */ + bool vm_pending; + + /* + * True if domain has buffer full notification pending + */ + bool buff_full_pending; }; =20 struct ffa_ctx { @@ -418,6 +431,14 @@ void ffa_handle_notification_info_get(struct cpu_user_= regs *regs); void ffa_handle_notification_get(struct cpu_user_regs *regs); 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 + void ffa_handle_msg_send_direct_req(struct cpu_user_regs *regs, uint32_t f= id); int32_t ffa_handle_msg_send2(struct cpu_user_regs *regs); =20 --=20 2.47.1