Blame SOURCES/kvm-spapr-Pass-the-maximum-number-of-vCPUs-to-the-KVM-in.patch

902636
From 5aea41b56f07f586e0f56a5c8b3e8443e485cd77 Mon Sep 17 00:00:00 2001
902636
From: Thomas Huth <thuth@redhat.com>
902636
Date: Fri, 5 Jun 2020 07:41:09 -0400
902636
Subject: [PATCH 39/42] spapr: Pass the maximum number of vCPUs to the KVM
902636
 interrupt controller
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-2-thuth@redhat.com>
902636
Patchwork-id: 97368
902636
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH 1/3] spapr: Pass the maximum number of vCPUs to the KVM interrupt controller
902636
Bugzilla: 1756946
902636
RH-Acked-by: Greg Kurz <gkurz@redhat.com>
902636
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
902636
RH-Acked-by: David Hildenbrand <david@redhat.com>
902636
902636
From: Greg Kurz <groug@kaod.org>
902636
902636
The XIVE and XICS-on-XIVE KVM devices on POWER9 hosts can greatly reduce
902636
their consumption of some scarce HW resources, namely Virtual Presenter
902636
identifiers, if they know the maximum number of vCPUs that may run in the
902636
VM.
902636
902636
Prepare ground for this by passing the value down to xics_kvm_connect()
902636
and kvmppc_xive_connect(). This is purely mechanical, no functional
902636
change.
902636
902636
Signed-off-by: Greg Kurz <groug@kaod.org>
902636
Message-Id: <157478678301.67101.2717368060417156338.stgit@bahia.tlslab.ibm.com>
902636
Reviewed-by: Cédric Le Goater <clg@kaod.org>
902636
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
902636
(cherry picked from commit 4ffb7496881ec361deaf1f51c41a933bde3cbf7b)
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 hw/intc/spapr_xive.c        |  6 ++++--
902636
 hw/intc/spapr_xive_kvm.c    |  3 ++-
902636
 hw/intc/xics_kvm.c          |  3 ++-
902636
 hw/intc/xics_spapr.c        |  5 +++--
902636
 hw/ppc/spapr_irq.c          |  8 +++++---
902636
 include/hw/ppc/spapr_irq.h  | 10 ++++++++--
902636
 include/hw/ppc/spapr_xive.h |  3 ++-
902636
 include/hw/ppc/xics_spapr.h |  3 ++-
902636
 8 files changed, 28 insertions(+), 13 deletions(-)
902636
902636
diff --git a/hw/intc/spapr_xive.c b/hw/intc/spapr_xive.c
902636
index 9cb8d38a3b..a570e6e90a 100644
902636
--- a/hw/intc/spapr_xive.c
902636
+++ b/hw/intc/spapr_xive.c
902636
@@ -651,12 +651,14 @@ static void spapr_xive_dt(SpaprInterruptController *intc, uint32_t nr_servers,
902636
                      plat_res_int_priorities, sizeof(plat_res_int_priorities)));
902636
 }
902636
 
902636
-static int spapr_xive_activate(SpaprInterruptController *intc, Error **errp)
902636
+static int spapr_xive_activate(SpaprInterruptController *intc,
902636
+                               uint32_t nr_servers, Error **errp)
902636
 {
902636
     SpaprXive *xive = SPAPR_XIVE(intc);
902636
 
902636
     if (kvm_enabled()) {
902636
-        int rc = spapr_irq_init_kvm(kvmppc_xive_connect, intc, errp);
902636
+        int rc = spapr_irq_init_kvm(kvmppc_xive_connect, intc, nr_servers,
902636
+                                    errp);
902636
         if (rc < 0) {
902636
             return rc;
902636
         }
902636
diff --git a/hw/intc/spapr_xive_kvm.c b/hw/intc/spapr_xive_kvm.c
902636
index 08012ac7cd..c1c837a764 100644
902636
--- a/hw/intc/spapr_xive_kvm.c
902636
+++ b/hw/intc/spapr_xive_kvm.c
902636
@@ -740,7 +740,8 @@ static void *kvmppc_xive_mmap(SpaprXive *xive, int pgoff, size_t len,
902636
  * All the XIVE memory regions are now backed by mappings from the KVM
902636
  * XIVE device.
902636
  */
902636
-int kvmppc_xive_connect(SpaprInterruptController *intc, Error **errp)
902636
+int kvmppc_xive_connect(SpaprInterruptController *intc, uint32_t nr_servers,
902636
+                        Error **errp)
902636
 {
902636
     SpaprXive *xive = SPAPR_XIVE(intc);
902636
     XiveSource *xsrc = &xive->source;
902636
diff --git a/hw/intc/xics_kvm.c b/hw/intc/xics_kvm.c
902636
index 954c424b36..a1f1b7b0d3 100644
902636
--- a/hw/intc/xics_kvm.c
902636
+++ b/hw/intc/xics_kvm.c
902636
@@ -342,7 +342,8 @@ void ics_kvm_set_irq(ICSState *ics, int srcno, int val)
902636
     }
902636
 }
902636
 
902636
-int xics_kvm_connect(SpaprInterruptController *intc, Error **errp)
902636
+int xics_kvm_connect(SpaprInterruptController *intc, uint32_t nr_servers,
902636
+                     Error **errp)
902636
 {
902636
     ICSState *ics = ICS_SPAPR(intc);
902636
     int rc;
902636
diff --git a/hw/intc/xics_spapr.c b/hw/intc/xics_spapr.c
902636
index b3705dab0e..8ae4f41459 100644
902636
--- a/hw/intc/xics_spapr.c
902636
+++ b/hw/intc/xics_spapr.c
902636
@@ -422,10 +422,11 @@ static int xics_spapr_post_load(SpaprInterruptController *intc, int version_id)
902636
     return 0;
902636
 }
902636
 
902636
-static int xics_spapr_activate(SpaprInterruptController *intc, Error **errp)
902636
+static int xics_spapr_activate(SpaprInterruptController *intc,
902636
+                               uint32_t nr_servers, Error **errp)
902636
 {
902636
     if (kvm_enabled()) {
902636
-        return spapr_irq_init_kvm(xics_kvm_connect, intc, errp);
902636
+        return spapr_irq_init_kvm(xics_kvm_connect, intc, nr_servers, errp);
902636
     }
902636
     return 0;
902636
 }
902636
diff --git a/hw/ppc/spapr_irq.c b/hw/ppc/spapr_irq.c
902636
index d6bb7fd2d6..9da423658a 100644
902636
--- a/hw/ppc/spapr_irq.c
902636
+++ b/hw/ppc/spapr_irq.c
902636
@@ -70,15 +70,16 @@ void spapr_irq_msi_free(SpaprMachineState *spapr, int irq, uint32_t num)
902636
     bitmap_clear(spapr->irq_map, irq - SPAPR_IRQ_MSI, num);
902636
 }
902636
 
902636
-int spapr_irq_init_kvm(int (*fn)(SpaprInterruptController *, Error **),
902636
+int spapr_irq_init_kvm(SpaprInterruptControllerInitKvm fn,
902636
                        SpaprInterruptController *intc,
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 (fn(intc, &local_err) < 0) {
902636
+        if (fn(intc, nr_servers, &local_err) < 0) {
902636
             if (machine_kernel_irqchip_required(machine)) {
902636
                 error_prepend(&local_err,
902636
                               "kernel_irqchip requested but unavailable: ");
902636
@@ -495,6 +496,7 @@ static void set_active_intc(SpaprMachineState *spapr,
902636
                             SpaprInterruptController *new_intc)
902636
 {
902636
     SpaprInterruptControllerClass *sicc;
902636
+    uint32_t nr_servers = spapr_max_server_number(spapr);
902636
 
902636
     assert(new_intc);
902636
 
902636
@@ -512,7 +514,7 @@ static void set_active_intc(SpaprMachineState *spapr,
902636
 
902636
     sicc = SPAPR_INTC_GET_CLASS(new_intc);
902636
     if (sicc->activate) {
902636
-        sicc->activate(new_intc, &error_fatal);
902636
+        sicc->activate(new_intc, nr_servers, &error_fatal);
902636
     }
902636
 
902636
     spapr->active_intc = new_intc;
902636
diff --git a/include/hw/ppc/spapr_irq.h b/include/hw/ppc/spapr_irq.h
902636
index ff814d13de..ca8cb44213 100644
902636
--- a/include/hw/ppc/spapr_irq.h
902636
+++ b/include/hw/ppc/spapr_irq.h
902636
@@ -43,7 +43,8 @@ typedef struct SpaprInterruptController SpaprInterruptController;
902636
 typedef struct SpaprInterruptControllerClass {
902636
     InterfaceClass parent;
902636
 
902636
-    int (*activate)(SpaprInterruptController *intc, Error **errp);
902636
+    int (*activate)(SpaprInterruptController *intc, uint32_t nr_servers,
902636
+                    Error **errp);
902636
     void (*deactivate)(SpaprInterruptController *intc);
902636
 
902636
     /*
902636
@@ -98,8 +99,13 @@ qemu_irq spapr_qirq(SpaprMachineState *spapr, int irq);
902636
 int spapr_irq_post_load(SpaprMachineState *spapr, int version_id);
902636
 void spapr_irq_reset(SpaprMachineState *spapr, Error **errp);
902636
 int spapr_irq_get_phandle(SpaprMachineState *spapr, void *fdt, Error **errp);
902636
-int spapr_irq_init_kvm(int (*fn)(SpaprInterruptController *, Error **),
902636
+
902636
+typedef int (*SpaprInterruptControllerInitKvm)(SpaprInterruptController *,
902636
+                                               uint32_t, Error **);
902636
+
902636
+int spapr_irq_init_kvm(SpaprInterruptControllerInitKvm fn,
902636
                        SpaprInterruptController *intc,
902636
+                       uint32_t nr_servers,
902636
                        Error **errp);
902636
 
902636
 /*
902636
diff --git a/include/hw/ppc/spapr_xive.h b/include/hw/ppc/spapr_xive.h
902636
index 742b7e834f..3a103c224d 100644
902636
--- a/include/hw/ppc/spapr_xive.h
902636
+++ b/include/hw/ppc/spapr_xive.h
902636
@@ -66,7 +66,8 @@ int spapr_xive_end_to_target(uint8_t end_blk, uint32_t end_idx,
902636
 /*
902636
  * KVM XIVE device helpers
902636
  */
902636
-int kvmppc_xive_connect(SpaprInterruptController *intc, Error **errp);
902636
+int kvmppc_xive_connect(SpaprInterruptController *intc, uint32_t nr_servers,
902636
+                        Error **errp);
902636
 void kvmppc_xive_disconnect(SpaprInterruptController *intc);
902636
 void kvmppc_xive_reset(SpaprXive *xive, Error **errp);
902636
 void kvmppc_xive_set_source_config(SpaprXive *xive, uint32_t lisn, XiveEAS *eas,
902636
diff --git a/include/hw/ppc/xics_spapr.h b/include/hw/ppc/xics_spapr.h
902636
index 28b87038c8..1c65c96e3c 100644
902636
--- a/include/hw/ppc/xics_spapr.h
902636
+++ b/include/hw/ppc/xics_spapr.h
902636
@@ -32,7 +32,8 @@
902636
 #define TYPE_ICS_SPAPR "ics-spapr"
902636
 #define ICS_SPAPR(obj) OBJECT_CHECK(ICSState, (obj), TYPE_ICS_SPAPR)
902636
 
902636
-int xics_kvm_connect(SpaprInterruptController *intc, Error **errp);
902636
+int xics_kvm_connect(SpaprInterruptController *intc, uint32_t nr_servers,
902636
+                     Error **errp);
902636
 void xics_kvm_disconnect(SpaprInterruptController *intc);
902636
 bool xics_kvm_has_broken_disconnect(SpaprMachineState *spapr);
902636
 
902636
-- 
902636
2.27.0
902636