diff mbox series

[for-6.0,v2,3/3] spapr/xive: Fix the "ibm, xive-lisn-ranges" property

Message ID 20201130165258.744611-4-groug@kaod.org
State New
Headers show
Series spapr: Address the confusion between IPI numbers and vCPU ids | expand

Commit Message

Greg Kurz Nov. 30, 2020, 4:52 p.m. UTC
The dt() callback of the sPAPR IC class has a "nr_servers"
argument which is used by both XIVE and XICS to setup the
"interrupt-controller" node in the DT.

The machine currently passes spapr_max_server_number() to
spapr_irq_dt(). This is perfectly fine to populate the range
of vCPU ids in the "ibm,interrupt-server-ranges" property
for XICS. However, this doesn't makes sense for XIVE's
"ibm,xive-lisn-ranges" property which really expects the
maximum number of vCPUs instead.

Add a new "max_cpus" argument to spapr_irq_dt() and the
dt() handler to convey the maximum number of vCPUs. Have
the latest machine type to pass smp.max_cpus and sPAPR XIVE
to use that for "ibm,xive-lisn-ranges". Older machine types
go on with the previous behavior since this is guest visible.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 include/hw/ppc/spapr_irq.h | 4 ++--
 hw/intc/spapr_xive.c       | 3 ++-
 hw/intc/xics_spapr.c       | 3 ++-
 hw/ppc/spapr.c             | 3 ++-
 hw/ppc/spapr_irq.c         | 8 ++++++--
 5 files changed, 14 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/include/hw/ppc/spapr_irq.h b/include/hw/ppc/spapr_irq.h
index 2e53fc9e6cbb..1edf4851afa4 100644
--- a/include/hw/ppc/spapr_irq.h
+++ b/include/hw/ppc/spapr_irq.h
@@ -63,7 +63,7 @@  struct SpaprInterruptControllerClass {
     void (*set_irq)(SpaprInterruptController *intc, int irq, int val);
     void (*print_info)(SpaprInterruptController *intc, Monitor *mon);
     void (*dt)(SpaprInterruptController *intc, uint32_t max_vcpu_ids,
-               void *fdt, uint32_t phandle);
+               uint32_t max_cpus, void *fdt, uint32_t phandle);
     int (*post_load)(SpaprInterruptController *intc, int version_id);
 };
 
@@ -75,7 +75,7 @@  void spapr_irq_cpu_intc_reset(struct SpaprMachineState *spapr, PowerPCCPU *cpu);
 void spapr_irq_cpu_intc_destroy(struct SpaprMachineState *spapr, PowerPCCPU *cpu);
 void spapr_irq_print_info(struct SpaprMachineState *spapr, Monitor *mon);
 void spapr_irq_dt(struct SpaprMachineState *spapr, uint32_t max_vcpu_ids,
-                  void *fdt, uint32_t phandle);
+                  uint32_t max_cpus, void *fdt, uint32_t phandle);
 
 uint32_t spapr_irq_nr_msis(struct SpaprMachineState *spapr);
 int spapr_irq_msi_alloc(struct SpaprMachineState *spapr, uint32_t num, bool align,
diff --git a/hw/intc/spapr_xive.c b/hw/intc/spapr_xive.c
index d0a0ca822367..f9a563cd0a9b 100644
--- a/hw/intc/spapr_xive.c
+++ b/hw/intc/spapr_xive.c
@@ -670,6 +670,7 @@  static void spapr_xive_print_info(SpaprInterruptController *intc, Monitor *mon)
 }
 
 static void spapr_xive_dt(SpaprInterruptController *intc, uint32_t max_vcpu_ids,
+                          uint32_t max_cpus,
                           void *fdt, uint32_t phandle)
 {
     SpaprXive *xive = SPAPR_XIVE(intc);
@@ -678,7 +679,7 @@  static void spapr_xive_dt(SpaprInterruptController *intc, uint32_t max_vcpu_ids,
     /* Interrupt number ranges for the IPIs */
     uint32_t lisn_ranges[] = {
         cpu_to_be32(SPAPR_IRQ_IPI),
-        cpu_to_be32(SPAPR_IRQ_IPI + max_vcpu_ids),
+        cpu_to_be32(SPAPR_IRQ_IPI + max_cpus),
     };
     /*
      * EQ size - the sizes of pages supported by the system 4K, 64K,
diff --git a/hw/intc/xics_spapr.c b/hw/intc/xics_spapr.c
index 8f753a858cc2..d9f887dfd303 100644
--- a/hw/intc/xics_spapr.c
+++ b/hw/intc/xics_spapr.c
@@ -309,7 +309,8 @@  static void ics_spapr_realize(DeviceState *dev, Error **errp)
 }
 
 static void xics_spapr_dt(SpaprInterruptController *intc, uint32_t max_vcpu_ids,
-                          void *fdt, uint32_t phandle)
+                          uint32_t max_cpus, void *fdt,
+                          uint32_t phandle)
 {
     uint32_t interrupt_server_ranges_prop[] = {
         0, cpu_to_be32(max_vcpu_ids),
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 227a926dfd48..be3b4b9119b7 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1164,7 +1164,8 @@  void *spapr_build_fdt(SpaprMachineState *spapr, bool reset, size_t space)
     _FDT(fdt_setprop_cell(fdt, 0, "#size-cells", 2));
 
     /* /interrupt controller */
-    spapr_irq_dt(spapr, spapr_max_vcpu_ids(spapr), fdt, PHANDLE_INTC);
+    spapr_irq_dt(spapr, spapr_max_vcpu_ids(spapr), machine->smp.max_cpus,
+                 fdt, PHANDLE_INTC);
 
     ret = spapr_dt_memory(spapr, fdt);
     if (ret < 0) {
diff --git a/hw/ppc/spapr_irq.c b/hw/ppc/spapr_irq.c
index 4d9ecd5d0af8..e1fd777aff62 100644
--- a/hw/ppc/spapr_irq.c
+++ b/hw/ppc/spapr_irq.c
@@ -272,12 +272,16 @@  void spapr_irq_print_info(SpaprMachineState *spapr, Monitor *mon)
 }
 
 void spapr_irq_dt(SpaprMachineState *spapr, uint32_t max_vcpu_ids,
-                  void *fdt, uint32_t phandle)
+                  uint32_t max_cpus, void *fdt, uint32_t phandle)
 {
     SpaprInterruptControllerClass *sicc
         = SPAPR_INTC_GET_CLASS(spapr->active_intc);
 
-    sicc->dt(spapr->active_intc, max_vcpu_ids, fdt, phandle);
+    /* For older machine types in case they have an unusual VSMT setting */
+    if (SPAPR_MACHINE_GET_CLASS(spapr)->pre_6_0_xive_max_cpus) {
+        max_cpus = spapr_max_vcpu_ids(spapr);
+    }
+    sicc->dt(spapr->active_intc, max_vcpu_ids, max_cpus, fdt, phandle);
 }
 
 uint32_t spapr_irq_nr_msis(SpaprMachineState *spapr)