qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Miguel Luis <miguel.luis@oracle.com>
To: Peter Maydell <peter.maydell@linaro.org>,
	"Michael S . Tsirkin" <mst@redhat.com>,
	Cornelia Huck <cohuck@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	qemu-arm@nongnu.org, qemu-devel@nongnu.org,
	Haibo Xu <haibo.xu@linaro.org>, Andrew Jones <drjones@redhat.com>,
	Marc Zyngier <maz@kernel.org>
Cc: Miguel Luis <miguel.luis@oracle.com>
Subject: [RFC PATCH 2/5] hw/intc/gicv3: add support for setting KVM vGIC maintenance IRQ
Date: Mon, 27 Feb 2023 15:37:15 -0100	[thread overview]
Message-ID: <20230227163718.62003-3-miguel.luis@oracle.com> (raw)
In-Reply-To: <20230227163718.62003-1-miguel.luis@oracle.com>

From: Haibo Xu <haibo.xu@linaro.org>

Use the VGIC maintenance IRQ if VHE is requested. As per the ARM GIC
Architecture Specification for GICv3 and GICv4 Arm strongly recommends that
maintenance interrupts are configured to use INTID 25 matching the
Server Base System Architecture (SBSA) recomendation.

Ref: https://lore.kernel.org/qemu-devel/49a4944e2f148c56938380b981afe154b7a8b7ee.1617281290.git.haibo.xu@linaro.org/

Signed-off-by: Haibo Xu <haibo.xu@linaro.org>
[Miguel Luis: avoid direct usage of helpers (_check_attr(); _access())]
Signed-off-by: Miguel Luis <miguel.luis@oracle.com>
---
 hw/arm/virt.c                      |  5 +++++
 hw/intc/arm_gicv3_common.c         |  1 +
 hw/intc/arm_gicv3_kvm.c            | 25 +++++++++++++++++++++++++
 include/hw/intc/arm_gicv3_common.h |  1 +
 4 files changed, 32 insertions(+)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index b871350856..377181e009 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -759,6 +759,11 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem)
             qdev_prop_set_uint32(vms->gic, "redist-region-count[1]",
                 MIN(smp_cpus - redist0_count, redist1_capacity));
         }
+
+        if (kvm_irqchip_in_kernel()) {
+            qdev_prop_set_bit(vms->gic, "has-virtualization-extensions",
+                              vms->virt);
+        }
     } else {
         if (!kvm_irqchip_in_kernel()) {
             qdev_prop_set_bit(vms->gic, "has-virtualization-extensions",
diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c
index 351843db4a..e2a6ff1b49 100644
--- a/hw/intc/arm_gicv3_common.c
+++ b/hw/intc/arm_gicv3_common.c
@@ -563,6 +563,7 @@ static Property arm_gicv3_common_properties[] = {
     DEFINE_PROP_UINT32("revision", GICv3State, revision, 3),
     DEFINE_PROP_BOOL("has-lpi", GICv3State, lpi_enable, 0),
     DEFINE_PROP_BOOL("has-security-extensions", GICv3State, security_extn, 0),
+    DEFINE_PROP_BOOL("has-virtualization-extensions", GICv3State, virt_extn, 0),
     /*
      * Compatibility property: force 8 bits of physical priority, even
      * if the CPU being emulated should have fewer.
diff --git a/hw/intc/arm_gicv3_kvm.c b/hw/intc/arm_gicv3_kvm.c
index 3ca643ecba..ce924753bb 100644
--- a/hw/intc/arm_gicv3_kvm.c
+++ b/hw/intc/arm_gicv3_kvm.c
@@ -22,6 +22,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "hw/intc/arm_gicv3_common.h"
+#include "hw/arm/virt.h"
 #include "qemu/error-report.h"
 #include "qemu/module.h"
 #include "sysemu/kvm.h"
@@ -803,6 +804,30 @@ static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+
+    if (s->virt_extn) {
+        /*
+         * Arm strongly recommends that maintenance interrupts are configured
+         * to use INTID 25. For more information, see Server Base System
+         * Architecture (SBSA)
+         */
+        uint32_t maint_irq = PPI(ARCH_GIC_MAINT_IRQ);
+
+        struct kvm_device_attr kdevattr = {
+            .group = KVM_DEV_ARM_VGIC_GRP_MAINT_IRQ,
+            .addr = (uint64_t)&maint_irq
+        };
+
+        if (!kvm_device_ioctl(s->dev_fd, KVM_GET_DEVICE_ATTR, &kdevattr)) {
+            error_setg(errp, "VGICv3 setting maintenance IRQ are not "
+                            "supported by this host kernel");
+            return;
+        }
+
+        kvm_device_ioctl(s->dev_fd, KVM_SET_DEVICE_ATTR, &kdevattr);
+    }
+
+
     gicv3_init_irqs_and_mmio(s, kvm_arm_gicv3_set_irq, NULL);
 
     for (i = 0; i < s->num_cpu; i++) {
diff --git a/include/hw/intc/arm_gicv3_common.h b/include/hw/intc/arm_gicv3_common.h
index ab5182a28a..91e1c1a45a 100644
--- a/include/hw/intc/arm_gicv3_common.h
+++ b/include/hw/intc/arm_gicv3_common.h
@@ -248,6 +248,7 @@ struct GICv3State {
     uint32_t revision;
     bool lpi_enable;
     bool security_extn;
+    bool virt_extn;
     bool force_8bit_prio;
     bool irq_reset_nonsecure;
     bool gicd_no_migration_shift_bug;
-- 
2.39.2



  parent reply	other threads:[~2023-02-27 16:38 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-27 16:37 [RFC PATCH 0/5] QEMU v7.2.0 aarch64 Nested Virtualization Support Miguel Luis
2023-02-27 16:37 ` [RFC PATCH 1/5] linux-headers: [kvm, arm64] add the necessary definitions to match host kernel Miguel Luis
2023-02-27 16:49   ` Cornelia Huck
2023-02-28 10:01     ` Miguel Luis
2023-02-27 16:37 ` Miguel Luis [this message]
2023-03-06 14:02   ` [RFC PATCH 2/5] hw/intc/gicv3: add support for setting KVM vGIC maintenance IRQ Peter Maydell
2023-03-06 14:32     ` Marc Zyngier
2023-03-06 20:04       ` Miguel Luis
2023-03-06 18:34     ` Miguel Luis
2023-02-27 16:37 ` [RFC PATCH 3/5] target/arm/kvm: add helper to detect EL2 when using KVM Miguel Luis
2023-02-27 19:27   ` Richard Henderson
2023-02-27 16:37 ` [RFC PATCH 4/5] target/arm: enable feature ARM_FEATURE_EL2 if EL2 is supported Miguel Luis
2023-02-27 19:24   ` Richard Henderson
2023-02-28 12:23     ` Miguel Luis
2023-07-06  8:16   ` Eric Auger
2023-07-14 12:45     ` Miguel Luis
2023-02-27 16:37 ` [RFC PATCH 5/5] arm/virt: provide virtualization extensions to the guest Miguel Luis
2023-02-27 19:26   ` Richard Henderson
2023-02-28 12:31     ` Miguel Luis
2024-02-08 16:55 ` [RFC PATCH 0/5] QEMU v7.2.0 aarch64 Nested Virtualization Support Eric Auger
2024-02-08 17:33   ` Miguel Luis
2024-02-08 18:23     ` Eric Auger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230227163718.62003-3-miguel.luis@oracle.com \
    --to=miguel.luis@oracle.com \
    --cc=cohuck@redhat.com \
    --cc=drjones@redhat.com \
    --cc=haibo.xu@linaro.org \
    --cc=maz@kernel.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).