qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 1/2] hw/arm/virt: Consolidate GIC finalize logic


From: Alexander Graf
Subject: Re: [PATCH v3 1/2] hw/arm/virt: Consolidate GIC finalize logic
Date: Fri, 23 Dec 2022 17:37:43 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.6.0

Hey Cornelia,

On 23.12.22 13:30, Cornelia Huck wrote:
On Fri, Dec 23 2022, Alexander Graf <agraf@csgraf.de> wrote:

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 <agraf@csgraf.de>

---

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, int 
pa_bits)
      }
  }
+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=host requires KVM");
+            exit(1);
+        }
+
+        /* For KVM, gic-version=host means gic-version=max */
+        return finalize_gic_version_do(accel_name, VIRT_GIC_VERSION_MAX,
+                                       gics_supported, max_cpus);
I think I'd still rather use /* fallthrough */ here, but let's leave
that decision to the maintainers.


I originally had a fallthrough here, then looked at the code and concluded for myself that I dislike fallthroughs :). They make more complicated code flows insanely complicated and are super error prone.

In any case,

Reviewed-by: Cornelia Huck <cohuck@redhat.com>

[As an aside, we have a QEMU_FALLTHROUGH #define that maps to
__attribute__((fallthrough)) if available, but unlike the Linux kernel,
we didn't bother to convert everything to use it in QEMU. Should we?
Would using the attribute give us some extra benefits?]


IMHO we're be better off just refactoring code in ways that don't require fall-throughs. Modern compilers inline functions pretty well, so I think there's very little reason for them anymore.

Thanks a lot for the reviews!


Alex





reply via email to

[Prev in Thread] Current Thread [Next in Thread]