thebeanogamer / rpms / qemu-kvm

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