From nobody Wed May 15 09:12:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671786120761351.1491132309794; Fri, 23 Dec 2022 01:02:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8dvq-0002Y6-F6; Fri, 23 Dec 2022 04:01:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p8dvW-0002Rc-Ez; Fri, 23 Dec 2022 04:01:14 -0500 Received: from mail.csgraf.de ([85.25.223.15] helo=zulu616.server4you.de) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8dvS-0001Ox-NH; Fri, 23 Dec 2022 04:01:14 -0500 Received: from localhost.localdomain (dynamic-095-118-065-151.95.118.pool.telefonica.de [95.118.65.151]) by csgraf.de (Postfix) with ESMTPSA id 3D27C60804D4; Fri, 23 Dec 2022 10:01:08 +0100 (CET) From: Alexander Graf To: qemu-devel@nongnu.org Cc: Peter Maydell , qemu-arm@nongnu.org, Zenghui Yu , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck Subject: [PATCH v3 1/2] hw/arm/virt: Consolidate GIC finalize logic Date: Fri, 23 Dec 2022 10:01:06 +0100 Message-Id: <20221223090107.98888-2-agraf@csgraf.de> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20221223090107.98888-1-agraf@csgraf.de> References: <20221223090107.98888-1-agraf@csgraf.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=85.25.223.15; envelope-from=agraf@csgraf.de; helo=zulu616.server4you.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1671786122391100006 Content-Type: text/plain; charset="utf-8" Up to now, the finalize_gic_version() code open coded what is essentially a support bitmap match between host/emulation environment and desired target GIC type. This open coding leads to undesirable side effects. For example, a VM with KVM and -smp 10 will automatically choose GICv3 while the same command line with TCG will stay on GICv2 and fail the launch. This patch combines the TCG and KVM matching code paths by making everything a 2 pass process. First, we determine which GIC versions the current environment is able to support, then we go through a single state machine to determine which target GIC mode that means for us. After this patch, the only user noticable changes should be consolidated error messages as well as TCG -M virt supporting -smp > 8 automatically. Signed-off-by: Alexander Graf Reviewed-by: Cornelia Huck Reviewed-by: Richard Henderson Reviewed-by: Zenghui Yu --- v1 -> v2: - Leave VIRT_GIC_VERSION defines intact, we need them for MADT generation v2 -> v3: - Fix comment - Flip kvm-enabled logic for host around --- hw/arm/virt.c | 198 ++++++++++++++++++++++-------------------- include/hw/arm/virt.h | 15 ++-- 2 files changed, 112 insertions(+), 101 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index ea2413a0ba..6d27f044fe 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1820,6 +1820,84 @@ static void virt_set_memmap(VirtMachineState *vms, i= nt pa_bits) } } =20 +static VirtGICType finalize_gic_version_do(const char *accel_name, + VirtGICType gic_version, + int gics_supported, + unsigned int max_cpus) +{ + /* Convert host/max/nosel to GIC version number */ + switch (gic_version) { + case VIRT_GIC_VERSION_HOST: + if (!kvm_enabled()) { + error_report("gic-version=3Dhost requires KVM"); + exit(1); + } + + /* For KVM, gic-version=3Dhost means gic-version=3Dmax */ + return finalize_gic_version_do(accel_name, VIRT_GIC_VERSION_MAX, + gics_supported, max_cpus); + case VIRT_GIC_VERSION_MAX: + if (gics_supported & VIRT_GIC_VERSION_4_MASK) { + gic_version =3D VIRT_GIC_VERSION_4; + } else if (gics_supported & VIRT_GIC_VERSION_3_MASK) { + gic_version =3D VIRT_GIC_VERSION_3; + } else { + gic_version =3D VIRT_GIC_VERSION_2; + } + break; + case VIRT_GIC_VERSION_NOSEL: + if ((gics_supported & VIRT_GIC_VERSION_2_MASK) && + max_cpus <=3D GIC_NCPU) { + gic_version =3D VIRT_GIC_VERSION_2; + } else if (gics_supported & VIRT_GIC_VERSION_3_MASK) { + /* + * in case the host does not support v2 emulation or + * the end-user requested more than 8 VCPUs we now default + * to v3. In any case defaulting to v2 would be broken. + */ + gic_version =3D VIRT_GIC_VERSION_3; + } else if (max_cpus > GIC_NCPU) { + error_report("%s only supports GICv2 emulation but more than 8= " + "vcpus are requested", accel_name); + exit(1); + } + break; + case VIRT_GIC_VERSION_2: + case VIRT_GIC_VERSION_3: + case VIRT_GIC_VERSION_4: + break; + } + + /* Check chosen version is effectively supported */ + switch (gic_version) { + case VIRT_GIC_VERSION_2: + if (!(gics_supported & VIRT_GIC_VERSION_2_MASK)) { + error_report("%s does not support GICv2 emulation", accel_name= ); + exit(1); + } + break; + case VIRT_GIC_VERSION_3: + if (!(gics_supported & VIRT_GIC_VERSION_3_MASK)) { + error_report("%s does not support GICv3 emulation", accel_name= ); + exit(1); + } + break; + case VIRT_GIC_VERSION_4: + if (!(gics_supported & VIRT_GIC_VERSION_4_MASK)) { + error_report("%s does not support GICv4 emulation, is virtuali= zation=3Don?", + accel_name); + exit(1); + } + break; + default: + error_report("logic error in finalize_gic_version"); + exit(1); + break; + } + + return gic_version; +} + /* * finalize_gic_version - Determines the final gic_version * according to the gic-version property @@ -1828,118 +1906,46 @@ static void virt_set_memmap(VirtMachineState *vms,= int pa_bits) */ static void finalize_gic_version(VirtMachineState *vms) { + const char *accel_name =3D current_accel_name(); unsigned int max_cpus =3D MACHINE(vms)->smp.max_cpus; + int gics_supported =3D 0; =20 - if (kvm_enabled()) { - int probe_bitmap; + /* Determine which GIC versions the current environment supports */ + if (kvm_enabled() && kvm_irqchip_in_kernel()) { + int probe_bitmap =3D kvm_arm_vgic_probe(); =20 - if (!kvm_irqchip_in_kernel()) { - switch (vms->gic_version) { - case VIRT_GIC_VERSION_HOST: - warn_report( - "gic-version=3Dhost not relevant with kernel-irqchip= =3Doff " - "as only userspace GICv2 is supported. Using v2 ..."); - return; - case VIRT_GIC_VERSION_MAX: - case VIRT_GIC_VERSION_NOSEL: - vms->gic_version =3D VIRT_GIC_VERSION_2; - return; - case VIRT_GIC_VERSION_2: - return; - case VIRT_GIC_VERSION_3: - error_report( - "gic-version=3D3 is not supported with kernel-irqchip= =3Doff"); - exit(1); - case VIRT_GIC_VERSION_4: - error_report( - "gic-version=3D4 is not supported with kernel-irqchip= =3Doff"); - exit(1); - } - } - - probe_bitmap =3D kvm_arm_vgic_probe(); if (!probe_bitmap) { error_report("Unable to determine GIC version supported by hos= t"); exit(1); } =20 - switch (vms->gic_version) { - case VIRT_GIC_VERSION_HOST: - case VIRT_GIC_VERSION_MAX: - if (probe_bitmap & KVM_ARM_VGIC_V3) { - vms->gic_version =3D VIRT_GIC_VERSION_3; - } else { - vms->gic_version =3D VIRT_GIC_VERSION_2; - } - return; - case VIRT_GIC_VERSION_NOSEL: - if ((probe_bitmap & KVM_ARM_VGIC_V2) && max_cpus <=3D GIC_NCPU= ) { - vms->gic_version =3D VIRT_GIC_VERSION_2; - } else if (probe_bitmap & KVM_ARM_VGIC_V3) { - /* - * in case the host does not support v2 in-kernel emulatio= n or - * the end-user requested more than 8 VCPUs we now default - * to v3. In any case defaulting to v2 would be broken. - */ - vms->gic_version =3D VIRT_GIC_VERSION_3; - } else if (max_cpus > GIC_NCPU) { - error_report("host only supports in-kernel GICv2 emulation= " - "but more than 8 vcpus are requested"); - exit(1); - } - break; - case VIRT_GIC_VERSION_2: - case VIRT_GIC_VERSION_3: - break; - case VIRT_GIC_VERSION_4: - error_report("gic-version=3D4 is not supported with KVM"); - exit(1); + if (probe_bitmap & KVM_ARM_VGIC_V2) { + gics_supported |=3D VIRT_GIC_VERSION_2_MASK; } - - /* Check chosen version is effectively supported by the host */ - if (vms->gic_version =3D=3D VIRT_GIC_VERSION_2 && - !(probe_bitmap & KVM_ARM_VGIC_V2)) { - error_report("host does not support in-kernel GICv2 emulation"= ); - exit(1); - } else if (vms->gic_version =3D=3D VIRT_GIC_VERSION_3 && - !(probe_bitmap & KVM_ARM_VGIC_V3)) { - error_report("host does not support in-kernel GICv3 emulation"= ); - exit(1); + if (probe_bitmap & KVM_ARM_VGIC_V3) { + gics_supported |=3D VIRT_GIC_VERSION_3_MASK; } - return; - } - - /* TCG mode */ - switch (vms->gic_version) { - case VIRT_GIC_VERSION_NOSEL: - vms->gic_version =3D VIRT_GIC_VERSION_2; - break; - case VIRT_GIC_VERSION_MAX: + } else if (kvm_enabled() && !kvm_irqchip_in_kernel()) { + /* KVM w/o kernel irqchip can only deal with GICv2 */ + gics_supported |=3D VIRT_GIC_VERSION_2_MASK; + accel_name =3D "KVM with kernel-irqchip=3Doff"; + } else { + gics_supported |=3D VIRT_GIC_VERSION_2_MASK; if (module_object_class_by_name("arm-gicv3")) { - /* CONFIG_ARM_GICV3_TCG was set */ + gics_supported |=3D VIRT_GIC_VERSION_3_MASK; if (vms->virt) { /* GICv4 only makes sense if CPU has EL2 */ - vms->gic_version =3D VIRT_GIC_VERSION_4; - } else { - vms->gic_version =3D VIRT_GIC_VERSION_3; + gics_supported |=3D VIRT_GIC_VERSION_4_MASK; } - } else { - vms->gic_version =3D VIRT_GIC_VERSION_2; - } - break; - case VIRT_GIC_VERSION_HOST: - error_report("gic-version=3Dhost requires KVM"); - exit(1); - case VIRT_GIC_VERSION_4: - if (!vms->virt) { - error_report("gic-version=3D4 requires virtualization enabled"= ); - exit(1); } - break; - case VIRT_GIC_VERSION_2: - case VIRT_GIC_VERSION_3: - break; } + + /* + * Then convert helpers like host/max to concrete GIC versions and ens= ure + * the desired version is supported + */ + vms->gic_version =3D finalize_gic_version_do(accel_name, vms->gic_vers= ion, + gics_supported, max_cpus); } =20 /* diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index c7dd59d7f1..e1ddbea96b 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -109,14 +109,19 @@ typedef enum VirtMSIControllerType { } VirtMSIControllerType; =20 typedef enum VirtGICType { - VIRT_GIC_VERSION_MAX, - VIRT_GIC_VERSION_HOST, - VIRT_GIC_VERSION_2, - VIRT_GIC_VERSION_3, - VIRT_GIC_VERSION_4, + VIRT_GIC_VERSION_MAX =3D 0, + VIRT_GIC_VERSION_HOST =3D 1, + /* The concrete GIC values have to match the GIC version number */ + VIRT_GIC_VERSION_2 =3D 2, + VIRT_GIC_VERSION_3 =3D 3, + VIRT_GIC_VERSION_4 =3D 4, VIRT_GIC_VERSION_NOSEL, } VirtGICType; =20 +#define VIRT_GIC_VERSION_2_MASK BIT(VIRT_GIC_VERSION_2) +#define VIRT_GIC_VERSION_3_MASK BIT(VIRT_GIC_VERSION_3) +#define VIRT_GIC_VERSION_4_MASK BIT(VIRT_GIC_VERSION_4) + struct VirtMachineClass { MachineClass parent; bool disallow_affinity_adjustment; --=20 2.37.1 (Apple Git-137.1) From nobody Wed May 15 09:12:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1671786121006834.5398434928877; Fri, 23 Dec 2022 01:02:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8dvi-0002ST-5x; Fri, 23 Dec 2022 04:01:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p8dvW-0002RH-2P; Fri, 23 Dec 2022 04:01:14 -0500 Received: from mail.csgraf.de ([85.25.223.15] helo=zulu616.server4you.de) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8dvT-0001P5-Qw; Fri, 23 Dec 2022 04:01:13 -0500 Received: from localhost.localdomain (dynamic-095-118-065-151.95.118.pool.telefonica.de [95.118.65.151]) by csgraf.de (Postfix) with ESMTPSA id A0C366080975; Fri, 23 Dec 2022 10:01:08 +0100 (CET) From: Alexander Graf To: qemu-devel@nongnu.org Cc: Peter Maydell , qemu-arm@nongnu.org, Zenghui Yu , Eric Auger , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Cornelia Huck Subject: [PATCH v3 2/2] hw/arm/virt: Make accels in GIC finalize logic explicit Date: Fri, 23 Dec 2022 10:01:07 +0100 Message-Id: <20221223090107.98888-3-agraf@csgraf.de> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) In-Reply-To: <20221223090107.98888-1-agraf@csgraf.de> References: <20221223090107.98888-1-agraf@csgraf.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=85.25.223.15; envelope-from=agraf@csgraf.de; helo=zulu616.server4you.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1671786122527100011 Let's explicitly list out all accelerators that we support when trying to determine the supported set of GIC versions. KVM was already separate, so the only missing one is HVF which simply reuses all of TCG's emulation code and thus has the same compatibility matrix. Signed-off-by: Alexander Graf Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Cornelia Huck Reviewed-by: Richard Henderson Tested-by: Philippe Mathieu-Daud=C3=A9 --- v1 -> v2: - Include TCG header for tcg_enabled() --- hw/arm/virt.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 6d27f044fe..611f40c1da 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -47,6 +47,7 @@ #include "sysemu/numa.h" #include "sysemu/runstate.h" #include "sysemu/tpm.h" +#include "sysemu/tcg.h" #include "sysemu/kvm.h" #include "sysemu/hvf.h" #include "hw/loader.h" @@ -1929,7 +1930,7 @@ static void finalize_gic_version(VirtMachineState *vm= s) /* KVM w/o kernel irqchip can only deal with GICv2 */ gics_supported |=3D VIRT_GIC_VERSION_2_MASK; accel_name =3D "KVM with kernel-irqchip=3Doff"; - } else { + } else if (tcg_enabled() || hvf_enabled()) { gics_supported |=3D VIRT_GIC_VERSION_2_MASK; if (module_object_class_by_name("arm-gicv3")) { gics_supported |=3D VIRT_GIC_VERSION_3_MASK; @@ -1938,6 +1939,9 @@ static void finalize_gic_version(VirtMachineState *vm= s) gics_supported |=3D VIRT_GIC_VERSION_4_MASK; } } + } else { + error_report("Unsupported accelerator, can not determine GIC suppo= rt"); + exit(1); } =20 /* --=20 2.37.1 (Apple Git-137.1)