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

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