902636
From 3899672db472c1ca530badd49d17726a1057f8af Mon Sep 17 00:00:00 2001
902636
From: Thomas Huth <thuth@redhat.com>
902636
Date: Fri, 5 Jun 2020 07:41:10 -0400
902636
Subject: [PATCH 40/42] kvm: introduce kvm_kernel_irqchip_* functions
902636
MIME-Version: 1.0
902636
Content-Type: text/plain; charset=UTF-8
902636
Content-Transfer-Encoding: 8bit
902636
902636
RH-Author: Thomas Huth <thuth@redhat.com>
902636
Message-id: <20200605074111.2185-3-thuth@redhat.com>
902636
Patchwork-id: 97369
902636
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH 2/3] kvm: introduce kvm_kernel_irqchip_* functions
902636
Bugzilla: 1756946
902636
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
902636
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
902636
RH-Acked-by: David Hildenbrand <david@redhat.com>
902636
902636
From: Paolo Bonzini <pbonzini@redhat.com>
902636
902636
The KVMState struct is opaque, so provide accessors for the fields
902636
that will be moved from current_machine to the accelerator.  For now
902636
they just forward to the machine object, but this will change.
902636
902636
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
902636
(cherry picked from commit 4376c40dedb22530738eeb104a603e94ed03f719)
902636
902636
Conflicts:
902636
	accel/kvm/kvm-all.c
902636
	(contextual conflict due to missing other commits in downstream)
902636
Signed-off-by: Thomas Huth <thuth@redhat.com>
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 accel/kvm/kvm-all.c  | 23 +++++++++++++++++++----
902636
 hw/ppc/e500.c        |  5 ++---
902636
 hw/ppc/spapr_irq.c   | 16 ++++------------
902636
 include/sysemu/kvm.h |  7 +++++--
902636
 target/arm/kvm.c     |  8 ++++----
902636
 target/i386/kvm.c    |  4 ++--
902636
 target/mips/kvm.c    |  2 +-
902636
 target/ppc/kvm.c     |  2 +-
902636
 target/s390x/kvm.c   |  2 +-
902636
 9 files changed, 39 insertions(+), 30 deletions(-)
902636
902636
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
902636
index 5007bdad96..b0250209f5 100644
902636
--- a/accel/kvm/kvm-all.c
902636
+++ b/accel/kvm/kvm-all.c
902636
@@ -1772,7 +1772,7 @@ void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi)
902636
     g_hash_table_insert(s->gsimap, irq, GINT_TO_POINTER(gsi));
902636
 }
902636
 
902636
-static void kvm_irqchip_create(MachineState *machine, KVMState *s)
902636
+static void kvm_irqchip_create(KVMState *s)
902636
 {
902636
     int ret;
902636
 
902636
@@ -1790,9 +1790,9 @@ static void kvm_irqchip_create(MachineState *machine, KVMState *s)
902636
 
902636
     /* First probe and see if there's a arch-specific hook to create the
902636
      * in-kernel irqchip for us */
902636
-    ret = kvm_arch_irqchip_create(machine, s);
902636
+    ret = kvm_arch_irqchip_create(s);
902636
     if (ret == 0) {
902636
-        if (machine_kernel_irqchip_split(machine)) {
902636
+        if (kvm_kernel_irqchip_split()) {
902636
             perror("Split IRQ chip mode not supported.");
902636
             exit(1);
902636
         } else {
902636
@@ -2076,7 +2076,7 @@ static int kvm_init(MachineState *ms)
902636
     }
902636
 
902636
     if (machine_kernel_irqchip_allowed(ms)) {
902636
-        kvm_irqchip_create(ms, s);
902636
+        kvm_irqchip_create(s);
902636
     }
902636
 
902636
     if (kvm_eventfds_allowed) {
902636
@@ -2966,6 +2966,21 @@ static bool kvm_accel_has_memory(MachineState *ms, AddressSpace *as,
902636
     return false;
902636
 }
902636
 
902636
+bool kvm_kernel_irqchip_allowed(void)
902636
+{
902636
+    return machine_kernel_irqchip_allowed(current_machine);
902636
+}
902636
+
902636
+bool kvm_kernel_irqchip_required(void)
902636
+{
902636
+    return machine_kernel_irqchip_required(current_machine);
902636
+}
902636
+
902636
+bool kvm_kernel_irqchip_split(void)
902636
+{
902636
+    return machine_kernel_irqchip_split(current_machine);
902636
+}
902636
+
902636
 static void kvm_accel_class_init(ObjectClass *oc, void *data)
902636
 {
902636
     AccelClass *ac = ACCEL_CLASS(oc);
902636
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
902636
index 91cd4c26f9..12b6a5b2a8 100644
902636
--- a/hw/ppc/e500.c
902636
+++ b/hw/ppc/e500.c
902636
@@ -793,7 +793,6 @@ static DeviceState *ppce500_init_mpic(PPCE500MachineState *pms,
902636
                                       MemoryRegion *ccsr,
902636
                                       IrqLines *irqs)
902636
 {
902636
-    MachineState *machine = MACHINE(pms);
902636
     const PPCE500MachineClass *pmc = PPCE500_MACHINE_GET_CLASS(pms);
902636
     DeviceState *dev = NULL;
902636
     SysBusDevice *s;
902636
@@ -801,10 +800,10 @@ static DeviceState *ppce500_init_mpic(PPCE500MachineState *pms,
902636
     if (kvm_enabled()) {
902636
         Error *err = NULL;
902636
 
902636
-        if (machine_kernel_irqchip_allowed(machine)) {
902636
+        if (kvm_kernel_irqchip_allowed()) {
902636
             dev = ppce500_init_mpic_kvm(pmc, irqs, &err;;
902636
         }
902636
-        if (machine_kernel_irqchip_required(machine) && !dev) {
902636
+        if (kvm_kernel_irqchip_required() && !dev) {
902636
             error_reportf_err(err,
902636
                               "kernel_irqchip requested but unavailable: ");
902636
             exit(1);
902636
diff --git a/hw/ppc/spapr_irq.c b/hw/ppc/spapr_irq.c
902636
index 9da423658a..f388d07bf9 100644
902636
--- a/hw/ppc/spapr_irq.c
902636
+++ b/hw/ppc/spapr_irq.c
902636
@@ -75,12 +75,11 @@ int spapr_irq_init_kvm(SpaprInterruptControllerInitKvm fn,
902636
                        uint32_t nr_servers,
902636
                        Error **errp)
902636
 {
902636
-    MachineState *machine = MACHINE(qdev_get_machine());
902636
     Error *local_err = NULL;
902636
 
902636
-    if (kvm_enabled() && machine_kernel_irqchip_allowed(machine)) {
902636
+    if (kvm_enabled() && kvm_kernel_irqchip_allowed()) {
902636
         if (fn(intc, nr_servers, &local_err) < 0) {
902636
-            if (machine_kernel_irqchip_required(machine)) {
902636
+            if (kvm_kernel_irqchip_required()) {
902636
                 error_prepend(&local_err,
902636
                               "kernel_irqchip requested but unavailable: ");
902636
                 error_propagate(errp, local_err);
902636
@@ -185,7 +184,7 @@ static int spapr_irq_check(SpaprMachineState *spapr, Error **errp)
902636
      */
902636
     if (kvm_enabled() &&
902636
         spapr->irq == &spapr_irq_dual &&
902636
-        machine_kernel_irqchip_required(machine) &&
902636
+        kvm_kernel_irqchip_required() &&
902636
         xics_kvm_has_broken_disconnect(spapr)) {
902636
         error_setg(errp, "KVM is too old to support ic-mode=dual,kernel-irqchip=on");
902636
         return -1;
902636
@@ -288,20 +287,13 @@ uint32_t spapr_irq_nr_msis(SpaprMachineState *spapr)
902636
 
902636
 void spapr_irq_init(SpaprMachineState *spapr, Error **errp)
902636
 {
902636
-    MachineState *machine = MACHINE(spapr);
902636
     SpaprMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr);
902636
 
902636
-    if (machine_kernel_irqchip_split(machine)) {
902636
+    if (kvm_enabled() && kvm_kernel_irqchip_split()) {
902636
         error_setg(errp, "kernel_irqchip split mode not supported on pseries");
902636
         return;
902636
     }
902636
 
902636
-    if (!kvm_enabled() && machine_kernel_irqchip_required(machine)) {
902636
-        error_setg(errp,
902636
-                   "kernel_irqchip requested but only available with KVM");
902636
-        return;
902636
-    }
902636
-
902636
     if (spapr_irq_check(spapr, errp) < 0) {
902636
         return;
902636
     }
902636
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
902636
index 9fe233b9bf..aaf2a502e8 100644
902636
--- a/include/sysemu/kvm.h
902636
+++ b/include/sysemu/kvm.h
902636
@@ -519,10 +519,13 @@ void kvm_pc_gsi_handler(void *opaque, int n, int level);
902636
 void kvm_pc_setup_irq_routing(bool pci_enabled);
902636
 void kvm_init_irq_routing(KVMState *s);
902636
 
902636
+bool kvm_kernel_irqchip_allowed(void);
902636
+bool kvm_kernel_irqchip_required(void);
902636
+bool kvm_kernel_irqchip_split(void);
902636
+
902636
 /**
902636
  * kvm_arch_irqchip_create:
902636
  * @KVMState: The KVMState pointer
902636
- * @MachineState: The MachineState pointer
902636
  *
902636
  * Allow architectures to create an in-kernel irq chip themselves.
902636
  *
902636
@@ -530,7 +533,7 @@ void kvm_init_irq_routing(KVMState *s);
902636
  *            0: irq chip was not created
902636
  *          > 0: irq chip was created
902636
  */
902636
-int kvm_arch_irqchip_create(MachineState *ms, KVMState *s);
902636
+int kvm_arch_irqchip_create(KVMState *s);
902636
 
902636
 /**
902636
  * kvm_set_one_reg - set a register value in KVM via KVM_SET_ONE_REG ioctl
902636
diff --git a/target/arm/kvm.c b/target/arm/kvm.c
902636
index 4be9497402..418bcedc3e 100644
902636
--- a/target/arm/kvm.c
902636
+++ b/target/arm/kvm.c
902636
@@ -861,11 +861,11 @@ void kvm_arch_init_irq_routing(KVMState *s)
902636
 {
902636
 }
902636
 
902636
-int kvm_arch_irqchip_create(MachineState *ms, KVMState *s)
902636
+int kvm_arch_irqchip_create(KVMState *s)
902636
 {
902636
-     if (machine_kernel_irqchip_split(ms)) {
902636
-         perror("-machine kernel_irqchip=split is not supported on ARM.");
902636
-         exit(1);
902636
+    if (kvm_kernel_irqchip_split()) {
902636
+        perror("-machine kernel_irqchip=split is not supported on ARM.");
902636
+        exit(1);
902636
     }
902636
 
902636
     /* If we can create the VGIC using the newer device control API, we
902636
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
902636
index fcc8f7d1f3..f5c17e0028 100644
902636
--- a/target/i386/kvm.c
902636
+++ b/target/i386/kvm.c
902636
@@ -4532,10 +4532,10 @@ void kvm_arch_init_irq_routing(KVMState *s)
902636
     }
902636
 }
902636
 
902636
-int kvm_arch_irqchip_create(MachineState *ms, KVMState *s)
902636
+int kvm_arch_irqchip_create(KVMState *s)
902636
 {
902636
     int ret;
902636
-    if (machine_kernel_irqchip_split(ms)) {
902636
+    if (kvm_kernel_irqchip_split()) {
902636
         ret = kvm_vm_enable_cap(s, KVM_CAP_SPLIT_IRQCHIP, 0, 24);
902636
         if (ret) {
902636
             error_report("Could not enable split irqchip mode: %s",
902636
diff --git a/target/mips/kvm.c b/target/mips/kvm.c
902636
index 578bc14625..de3e26ef1f 100644
902636
--- a/target/mips/kvm.c
902636
+++ b/target/mips/kvm.c
902636
@@ -57,7 +57,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
902636
     return 0;
902636
 }
902636
 
902636
-int kvm_arch_irqchip_create(MachineState *ms, KVMState *s)
902636
+int kvm_arch_irqchip_create(KVMState *s)
902636
 {
902636
     return 0;
902636
 }
902636
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
902636
index c77f9848ec..461dc6dae1 100644
902636
--- a/target/ppc/kvm.c
902636
+++ b/target/ppc/kvm.c
902636
@@ -152,7 +152,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
902636
     return 0;
902636
 }
902636
 
902636
-int kvm_arch_irqchip_create(MachineState *ms, KVMState *s)
902636
+int kvm_arch_irqchip_create(KVMState *s)
902636
 {
902636
     return 0;
902636
 }
902636
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
902636
index 84d7cadd09..c589ef9034 100644
902636
--- a/target/s390x/kvm.c
902636
+++ b/target/s390x/kvm.c
902636
@@ -386,7 +386,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
902636
     return 0;
902636
 }
902636
 
902636
-int kvm_arch_irqchip_create(MachineState *ms, KVMState *s)
902636
+int kvm_arch_irqchip_create(KVMState *s)
902636
 {
902636
     return 0;
902636
 }
902636
-- 
902636
2.27.0
902636