From nobody Fri Nov 22 02:29:46 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 1729070824914638.3598664856831; Wed, 16 Oct 2024 02:27:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.819798.1233286 (Exim 4.92) (envelope-from ) id 1t10Ir-00069v-7R; Wed, 16 Oct 2024 09:26:49 +0000 Received: by outflank-mailman (output) from mailman id 819798.1233286; Wed, 16 Oct 2024 09:26:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1t10Ir-00069o-2W; Wed, 16 Oct 2024 09:26:49 +0000 Received: by outflank-mailman (input) for mailman id 819798; Wed, 16 Oct 2024 09:26:48 +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 1t10En-0001Po-DN for xen-devel@lists.xenproject.org; Wed, 16 Oct 2024 09:22:37 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id 2ce41d79-8ba0-11ef-99a3-01e77a169b0f; Wed, 16 Oct 2024 11:22:33 +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 C70891007; Wed, 16 Oct 2024 02:23:02 -0700 (PDT) Received: from C3HXLD123V.arm.com (unknown [10.57.21.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0223A3F528; Wed, 16 Oct 2024 02:22:31 -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: 2ce41d79-8ba0-11ef-99a3-01e77a169b0f From: Bertrand Marquis To: xen-devel@lists.xenproject.org Cc: jens.wiklander@linaro.org, Volodymyr Babchuk , Stefano Stabellini , Julien Grall , Michal Orzel Subject: [RFC PATCH 4/4] xen/arm: ffa: Enable VM to VM without firmware Date: Wed, 16 Oct 2024 11:21:58 +0200 Message-ID: <57c59cae4141dd9601d7b4e9260030a16809b764.1729069025.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: 1729070826318116600 Content-Type: text/plain; charset="utf-8" When VM to VM support is activated and there is no suitable FF-A support in the firmware, enable FF-A support for VMs to allow using it for VM to VM communications. If there is Optee running in the secure world and using the non FF-A communication system, having CONFIG_FFA_VM_TO_VM could be non functional (if optee is probed first) or Optee could be non functional (if FF-A is probed first) so it is not recommended to activate the configuration option for such systems. To make buffer full notification work between VMs when there is not firmware, rework the notification handling and modify the global flag to only be used as check for firmware notification support instead. Modify part_info_get to return the list of VMs when there is no firmware support. Signed-off-by: Bertrand Marquis --- xen/arch/arm/tee/ffa.c | 11 +++ xen/arch/arm/tee/ffa_notif.c | 118 ++++++++++++++++---------------- xen/arch/arm/tee/ffa_partinfo.c | 2 + 3 files changed, 73 insertions(+), 58 deletions(-) diff --git a/xen/arch/arm/tee/ffa.c b/xen/arch/arm/tee/ffa.c index 21d41b452dc9..6d427864f3da 100644 --- a/xen/arch/arm/tee/ffa.c +++ b/xen/arch/arm/tee/ffa.c @@ -324,8 +324,11 @@ static int ffa_domain_init(struct domain *d) struct ffa_ctx *ctx; int ret; =20 +#ifndef CONFIG_FFA_VM_TO_VM if ( !ffa_fw_version ) return -ENODEV; +#endif + /* * 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 @@ -549,7 +552,15 @@ err_no_fw: bitmap_zero(ffa_fw_abi_supported, FFA_ABI_BITMAP_SIZE); printk(XENLOG_WARNING "ARM FF-A No firmware support\n"); =20 +#ifdef CONFIG_FFA_VM_TO_VM + INIT_LIST_HEAD(&ffa_teardown_head); + init_timer(&ffa_teardown_timer, ffa_teardown_timer_callback, NULL, 0); + + printk(XENLOG_INFO "ARM FF-A only available between VMs\n"); + return true; +#else return false; +#endif } =20 static const struct tee_mediator_ops ffa_ops =3D diff --git a/xen/arch/arm/tee/ffa_notif.c b/xen/arch/arm/tee/ffa_notif.c index 052b3e364a70..f2c87d1320de 100644 --- a/xen/arch/arm/tee/ffa_notif.c +++ b/xen/arch/arm/tee/ffa_notif.c @@ -16,7 +16,7 @@ =20 #include "ffa_private.h" =20 -static bool __ro_after_init notif_enabled; +static bool __ro_after_init fw_notif_enabled; static unsigned int __ro_after_init notif_sri_irq; =20 int ffa_handle_notification_bind(struct cpu_user_regs *regs) @@ -27,21 +27,17 @@ int ffa_handle_notification_bind(struct cpu_user_regs *= regs) uint32_t bitmap_lo =3D get_user_reg(regs, 3); uint32_t bitmap_hi =3D get_user_reg(regs, 4); =20 - if ( !notif_enabled ) - return FFA_RET_NOT_SUPPORTED; - if ( (src_dst & 0xFFFFU) !=3D ffa_get_vm_id(d) ) return FFA_RET_INVALID_PARAMETERS; =20 if ( flags ) /* Only global notifications are supported */ return FFA_RET_DENIED; =20 - /* - * We only support notifications from SP so no need to check the sender - * endpoint ID, the SPMC will take care of that for us. - */ - return ffa_simple_call(FFA_NOTIFICATION_BIND, src_dst, flags, bitmap_h= i, - bitmap_lo); + if ( FFA_ID_IS_SECURE(src_dst>>16) && fw_notif_enabled ) + return ffa_simple_call(FFA_NOTIFICATION_BIND, src_dst, flags, + bitmap_hi, bitmap_lo); + + return FFA_RET_NOT_SUPPORTED; } =20 int ffa_handle_notification_unbind(struct cpu_user_regs *regs) @@ -51,32 +47,36 @@ int ffa_handle_notification_unbind(struct cpu_user_regs= *regs) uint32_t bitmap_lo =3D get_user_reg(regs, 3); uint32_t bitmap_hi =3D get_user_reg(regs, 4); =20 - if ( !notif_enabled ) - return FFA_RET_NOT_SUPPORTED; - if ( (src_dst & 0xFFFFU) !=3D ffa_get_vm_id(d) ) return FFA_RET_INVALID_PARAMETERS; =20 - /* - * We only support notifications from SP so no need to check the - * destination endpoint ID, the SPMC will take care of that for us. - */ - return ffa_simple_call(FFA_NOTIFICATION_UNBIND, src_dst, 0, bitmap_hi, - bitmap_lo); + if ( FFA_ID_IS_SECURE(src_dst>>16) && fw_notif_enabled ) + return ffa_simple_call(FFA_NOTIFICATION_UNBIND, src_dst, 0, bitma= p_hi, + bitmap_lo); + + return FFA_RET_NOT_SUPPORTED; } =20 void ffa_handle_notification_info_get(struct cpu_user_regs *regs) { struct domain *d =3D current->domain; struct ffa_ctx *ctx =3D d->arch.tee; + bool notif_pending =3D false; =20 - if ( !notif_enabled ) +#ifndef CONFIG_FFA_VM_TO_VM + if ( !fw_notif_enabled ) { ffa_set_regs_error(regs, FFA_RET_NOT_SUPPORTED); return; } +#endif =20 - if ( test_and_clear_bool(ctx->notif.secure_pending) ) + notif_pending =3D ctx->notif.secure_pending; +#ifdef CONFIG_FFA_VM_TO_VM + notif_pending |=3D ctx->notif.buff_full_pending; +#endif + + if ( notif_pending ) { /* A pending global notification for the guest */ ffa_set_regs(regs, FFA_SUCCESS_64, 0, @@ -103,11 +103,13 @@ void ffa_handle_notification_get(struct cpu_user_regs= *regs) uint32_t w6 =3D 0; uint32_t w7 =3D 0; =20 - if ( !notif_enabled ) +#ifndef CONFIG_FFA_VM_TO_VM + if ( !fw_notif_enabled ) { ffa_set_regs_error(regs, FFA_RET_NOT_SUPPORTED); return; } +#endif =20 if ( (recv & 0xFFFFU) !=3D ffa_get_vm_id(d) ) { @@ -115,7 +117,8 @@ void ffa_handle_notification_get(struct cpu_user_regs *= regs) return; } =20 - if ( flags & ( FFA_NOTIF_FLAG_BITMAP_SP | FFA_NOTIF_FLAG_BITMAP_SPM ) ) + if ( fw_notif_enabled && (flags & ( FFA_NOTIF_FLAG_BITMAP_SP + | FFA_NOTIF_FLAG_BITMAP_SPM )) ) { struct arm_smccc_1_2_regs arg =3D { .a0 =3D FFA_NOTIFICATION_GET, @@ -170,15 +173,14 @@ int ffa_handle_notification_set(struct cpu_user_regs = *regs) uint32_t bitmap_lo =3D get_user_reg(regs, 3); uint32_t bitmap_hi =3D get_user_reg(regs, 4); =20 - if ( !notif_enabled ) - return FFA_RET_NOT_SUPPORTED; - if ( (src_dst >> 16) !=3D ffa_get_vm_id(d) ) return FFA_RET_INVALID_PARAMETERS; =20 - /* Let the SPMC check the destination of the notification */ - return ffa_simple_call(FFA_NOTIFICATION_SET, src_dst, flags, bitmap_lo, - bitmap_hi); + if ( FFA_ID_IS_SECURE(src_dst>>16) && fw_notif_enabled ) + return ffa_simple_call(FFA_NOTIFICATION_SET, src_dst, flags, bitma= p_lo, + bitmap_hi); + + return FFA_RET_NOT_SUPPORTED; } =20 #ifdef CONFIG_FFA_VM_TO_VM @@ -190,7 +192,7 @@ void ffa_raise_rx_buffer_full(struct domain *d) return; =20 if ( !test_and_set_bool(ctx->notif.buff_full_pending) ) - vgic_inject_irq(d, d->vcpu[0], notif_sri_irq, true); + vgic_inject_irq(d, d->vcpu[0], GUEST_FFA_NOTIF_PEND_INTR_ID, true); } #endif =20 @@ -363,7 +365,7 @@ void ffa_notif_init_interrupt(void) { int ret; =20 - if ( notif_enabled && notif_sri_irq < NR_GIC_SGI ) + if ( fw_notif_enabled && notif_sri_irq < NR_GIC_SGI ) { /* * An error here is unlikely since the primary CPU has already @@ -394,47 +396,47 @@ void ffa_notif_init(void) int ret; =20 /* Only enable fw notification if all ABIs we need are supported */ - if ( !(ffa_fw_supports_fid(FFA_NOTIFICATION_BITMAP_CREATE) && - ffa_fw_supports_fid(FFA_NOTIFICATION_BITMAP_DESTROY) && - ffa_fw_supports_fid(FFA_NOTIFICATION_GET) && - ffa_fw_supports_fid(FFA_NOTIFICATION_INFO_GET_64)) ) - return; - - arm_smccc_1_2_smc(&arg, &resp); - if ( resp.a0 !=3D FFA_SUCCESS_32 ) - return; - - irq =3D resp.a2; - notif_sri_irq =3D irq; - if ( irq >=3D NR_GIC_SGI ) - irq_set_type(irq, IRQ_TYPE_EDGE_RISING); - ret =3D request_irq(irq, 0, notif_irq_handler, "FF-A notif", NULL); - if ( ret ) + if ( ffa_fw_supports_fid(FFA_NOTIFICATION_BITMAP_CREATE) && + ffa_fw_supports_fid(FFA_NOTIFICATION_BITMAP_DESTROY) && + ffa_fw_supports_fid(FFA_NOTIFICATION_GET) && + ffa_fw_supports_fid(FFA_NOTIFICATION_INFO_GET_64) ) { - printk(XENLOG_ERR "ffa: request_irq irq %u failed: error %d\n", - irq, ret); - return; - } + arm_smccc_1_2_smc(&arg, &resp); + if ( resp.a0 !=3D FFA_SUCCESS_32 ) + return; =20 - notif_enabled =3D true; + irq =3D resp.a2; + notif_sri_irq =3D irq; + if ( irq >=3D NR_GIC_SGI ) + irq_set_type(irq, IRQ_TYPE_EDGE_RISING); + ret =3D request_irq(irq, 0, notif_irq_handler, "FF-A notif", NULL); + if ( ret ) + { + printk(XENLOG_ERR "ffa: request_irq irq %u failed: error %d\n", + irq, ret); + return; + } + fw_notif_enabled =3D true; + } } =20 int ffa_notif_domain_init(struct domain *d) { int32_t res; =20 - if ( !notif_enabled ) - return 0; + if ( fw_notif_enabled ) + { =20 - res =3D ffa_notification_bitmap_create(ffa_get_vm_id(d), d->max_vcpus); - if ( res ) - return -ENOMEM; + res =3D ffa_notification_bitmap_create(ffa_get_vm_id(d), d->max_vc= pus); + if ( res ) + return -ENOMEM; + } =20 return 0; } =20 void ffa_notif_domain_destroy(struct domain *d) { - if ( notif_enabled ) + if ( fw_notif_enabled ) ffa_notification_bitmap_destroy(ffa_get_vm_id(d)); } diff --git a/xen/arch/arm/tee/ffa_partinfo.c b/xen/arch/arm/tee/ffa_partinf= o.c index d699a267cc76..2e09440fe6c2 100644 --- a/xen/arch/arm/tee/ffa_partinfo.c +++ b/xen/arch/arm/tee/ffa_partinfo.c @@ -128,12 +128,14 @@ void ffa_handle_partition_info_get(struct cpu_user_re= gs *regs) goto out; } =20 +#ifndef CONFIG_FFA_VM_TO_VM if ( !ffa_fw_supports_fid(FFA_PARTITION_INFO_GET) ) { /* Just give an empty partition list to the caller */ ret =3D FFA_RET_OK; goto out; } +#endif =20 ret =3D ffa_rx_acquire(d); if ( ret !=3D FFA_RET_OK ) --=20 2.47.0