Skip to contentSkip to conversation

Introduce SPAPR_NR_IPIS and fix max-cpus

PATCH RESEND Superseded Harsh Prateek Bora 4 participants 13 messages Nov 22, 2023 – Nov 23, 2023

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Introduce SPAPR_NR_IPIS and fix max-cpus

On spapr, the max number of CPU IPIs are 4096 which is accounted during spapr_irq_init but currently existing macro SPAPR_XIRQ_BASE is being used to refer to that. Introducing SPAPR_NR_IPIS to refer to the range of CPU IPIS which is being further used to initialize mc->max_cpus during spapr_machine_class_init().

Harsh Prateek Bora (2):
ppc/spapr: Introduce SPAPR_NR_IPIS to refer IRQ range for CPU IPIs. ppc/spapr: Initialize max_cpus limit to SPAPR_NR_IPIS.

 hw/ppc/spapr.c             | 9 +++------
 hw/ppc/spapr_irq.c         | 4 ++--
 include/hw/ppc/spapr_irq.h | 1 +
 3 files changed, 6 insertions(+), 8 deletions(-)
Signature · 1 line
2.39.3
#1 lore raw

PATCH v2 1/2 ppc/spapr: Introduce SPAPR_NR_IPIS to refer IRQ range for CPU IPIs.

spapr_irq_init currently uses existing macro SPAPR_XIRQ_BASE to refer to the range of CPU IPIs during initialization of nr-irqs property. It is more appropriate to have its own define which can be further reused as appropriate for correct interpretation.

---
 hw/ppc/spapr_irq.c         | 4 ++--
 include/hw/ppc/spapr_irq.h | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)
hw/ppc/spapr_irq.c +2 -2
index a0d1e1298e..0c5db6b161 100644
@@ -329,7 +329,7 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp)
         int i;
 
         dev = qdev_new(TYPE_SPAPR_XIVE);
-        qdev_prop_set_uint32(dev, "nr-irqs", smc->nr_xirqs + SPAPR_XIRQ_BASE);
+        qdev_prop_set_uint32(dev, "nr-irqs", smc->nr_xirqs + SPAPR_NR_IPIS);
         /*
          * 8 XIVE END structures per CPU. One for each available
          * priority
@@ -356,7 +356,7 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp)
     }
 
     spapr->qirqs = qemu_allocate_irqs(spapr_set_irq, spapr,
-                                      smc->nr_xirqs + SPAPR_XIRQ_BASE);
+                                      smc->nr_xirqs + SPAPR_NR_IPIS);
 
     /*
      * Mostly we don't actually need this until reset, except that not
include/hw/ppc/spapr_irq.h +1 -0
index c22a72c9e2..e7a80a8349 100644
@@ -28,6 +28,7 @@
 #define SPAPR_IRQ_MSI        (SPAPR_XIRQ_BASE + 0x0300)
 
 #define SPAPR_NR_XIRQS       0x1000
+#define SPAPR_NR_IPIS        0x1000
 
 struct SpaprMachineState;
 
Signature · 1 line
2.39.3
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] ppc/spapr: Introduce SPAPR_NR_IPIS to refer IRQ range for CPU IPIs.

Quoted 11 lines · Harsh Prateek Bora

spapr_irq_init currently uses existing macro SPAPR_XIRQ_BASE to refer to the range of CPU IPIs during initialization of nr-irqs property. It is more appropriate to have its own define which can be further reused as appropriate for correct interpretation.

---
  hw/ppc/spapr_irq.c         | 4 ++--
  include/hw/ppc/spapr_irq.h | 1 +
  2 files changed, 3 insertions(+), 2 deletions(-)
#3 lore raw

Re: [PATCH v2 1/2] ppc/spapr: Introduce SPAPR_NR_IPIS to refer IRQ range for CPU IPIs.

In reply to Harsh Prateek Bora

Hi Harsh,

Quoted 18 lines · Harsh Prateek Bora

spapr_irq_init currently uses existing macro SPAPR_XIRQ_BASE to refer to the range of CPU IPIs during initialization of nr-irqs property. It is more appropriate to have its own define which can be further reused as appropriate for correct interpretation.

---
  hw/ppc/spapr_irq.c         | 4 ++--
  include/hw/ppc/spapr_irq.h | 1 +
  2 files changed, 3 insertions(+), 2 deletions(-)
include/hw/ppc/spapr_irq.h +0 -0
index c22a72c9e2..e7a80a8349 100644

include/hw/ppc/spapr_irq.h line 31

Quoted 4 lines
include/hw/ppc/spapr_irq.h +1 -0
@@ -28,6 +28,7 @@
  #define SPAPR_IRQ_MSI        (SPAPR_XIRQ_BASE + 0x0300)
 
  #define SPAPR_NR_XIRQS       0x1000
+#define SPAPR_NR_IPIS        0x1000

BTW why hexadecimal and not decimal?

Regards,

Phil.

#4 lore raw

Re: [PATCH v2 1/2] ppc/spapr: Introduce SPAPR_NR_IPIS to refer IRQ range for CPU IPIs.

Quoted 16 lines · Philippe Mathieu-Daudé

Hi Harsh,

Quoted 11 lines · Harsh Prateek Bora

spapr_irq_init currently uses existing macro SPAPR_XIRQ_BASE to refer to the range of CPU IPIs during initialization of nr-irqs property. It is more appropriate to have its own define which can be further reused as appropriate for correct interpretation.

---
  hw/ppc/spapr_irq.c         | 4 ++--
  include/hw/ppc/spapr_irq.h | 1 +

  2 files changed, 3 insertions(+), 2 deletions(-)
Quoted 10 lines

include/hw/ppc/spapr_irq.h line 30

Quoted 8 lines
include/hw/ppc/spapr_irq.h +1 -0
index c22a72c9e2..e7a80a8349 100644
@@ -28,6 +28,7 @@
   #define SPAPR_IRQ_MSI        (SPAPR_XIRQ_BASE + 0x0300)
   #define SPAPR_NR_XIRQS       0x1000
+#define SPAPR_NR_IPIS        0x1000

BTW why hexadecimal and not decimal?

I think because the HW IRQs are displayed in hex under Linux. Probably. It has been a while.

Thanks,

C.

#5 lore raw

Re: [PATCH v2 1/2] ppc/spapr: Introduce SPAPR_NR_IPIS to refer IRQ range for CPU IPIs.

In reply to Harsh Prateek Bora

Hello Harsh,

Please add to your .git/config file:

[diff]
orderFile = /path/to/qemu/scripts/git.orderfile

Quoted 17 lines · Harsh Prateek Bora

spapr_irq_init currently uses existing macro SPAPR_XIRQ_BASE to refer to the range of CPU IPIs during initialization of nr-irqs property. It is more appropriate to have its own define which can be further reused as appropriate for correct interpretation.

---
  hw/ppc/spapr_irq.c         | 4 ++--
  include/hw/ppc/spapr_irq.h | 1 +
  2 files changed, 3 insertions(+), 2 deletions(-)
hw/ppc/spapr_irq.c +0 -0
index a0d1e1298e..0c5db6b161 100644

hw/ppc/spapr_irq.c void spapr_irq_init(SpaprMachineState *spapr, Error **errp) · line 332

Quoted 5 lines
hw/ppc/spapr_irq.c +1 -1
@@ -329,7 +329,7 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp)
          int i;
 
          dev = qdev_new(TYPE_SPAPR_XIVE);
-        qdev_prop_set_uint32(dev, "nr-irqs", smc->nr_xirqs + SPAPR_XIRQ_BASE);
+        qdev_prop_set_uint32(dev, "nr-irqs", smc->nr_xirqs + SPAPR_NR_IPIS);

SPAPR_IRQ_NR_IPIS ?

include/hw/ppc/spapr_irq.h

Quoted 17 lines
hw/ppc/spapr_irq.c +1 -1
          /*
           * 8 XIVE END structures per CPU. One for each available
           * priority
@@ -356,7 +356,7 @@ void spapr_irq_init(SpaprMachineState *spapr, Error **errp)
      }
 
      spapr->qirqs = qemu_allocate_irqs(spapr_set_irq, spapr,
-                                      smc->nr_xirqs + SPAPR_XIRQ_BASE);
+                                      smc->nr_xirqs + SPAPR_NR_IPIS);
 
      /*
       * Mostly we don't actually need this until reset, except that not
include/hw/ppc/spapr_irq.h +0 -0
index c22a72c9e2..e7a80a8349 100644
@@ -28,6 +28,7 @@

In include/hw/ppc/spapr_irq.h, we should describe the ranges a bit more. See commit dcc345b61ebe and ad8de98636e7 for more info. Something like :

/*
* The XIVE IRQ backend uses the same layout as the XICS backend but
* covers the full range of the IRQ number space. The IRQ numbers for
* the CPU IPIs are allocated at the bottom of this space, below 4K,
* to preserve compatibility with XICS which does not use that range. */

  /*
   * CPU IPI range (XIVE only)
   */
  #define SPAPR_IRQ_IPI        0x0
  #define SPAPR_IRQ_NR_IPIS    0x1000

/*
* IRQ range offsets per device type
*/
#define SPAPR_XIRQ_BASE XICS_IRQ_BASE /* 0x1000 */

And to make sure the ranges don't overlap, let's add :

QEMU_BUILD_BUG_ON(SPAPR_IRQ_NR_IPIS > SPAPR_XIRQ_BASE)

Thanks,

C.

#6 lore raw

Re: [PATCH v2 1/2] ppc/spapr: Introduce SPAPR_NR_IPIS to refer IRQ range for CPU IPIs.

Quoted 7 lines · Cédric Le Goater

Hello Harsh,

Please add to your .git/config file:

[diff]
    orderFile = /path/to/qemu/scripts/git.orderfile

Sure, thanks for the suggestion.

Quoted 68 lines · Harsh Prateek Bora
Quoted 17 lines

spapr_irq_init currently uses existing macro SPAPR_XIRQ_BASE to refer to the range of CPU IPIs during initialization of nr-irqs property. It is more appropriate to have its own define which can be further reused as appropriate for correct interpretation.

---
  hw/ppc/spapr_irq.c         | 4 ++--
  include/hw/ppc/spapr_irq.h | 1 +

  2 files changed, 3 insertions(+), 2 deletions(-)
hw/ppc/spapr_irq.c +0 -0
index a0d1e1298e..0c5db6b161 100644

hw/ppc/spapr_irq.c void spapr_irq_init(SpaprMachineState *spapr, · line 334

Quoted 7 lines
hw/ppc/spapr_irq.c +1 -1
@@ -329,7 +329,7 @@ void spapr_irq_init(SpaprMachineState *spapr, 
 Error **errp)
           int i;
           dev = qdev_new(TYPE_SPAPR_XIVE);
-        qdev_prop_set_uint32(dev, "nr-irqs", smc->nr_xirqs + 
 SPAPR_XIRQ_BASE);
+        qdev_prop_set_uint32(dev, "nr-irqs", smc->nr_xirqs + 
 SPAPR_NR_IPIS);

SPAPR_IRQ_NR_IPIS ?

include/hw/ppc/spapr_irq.h

Quoted 16 lines
hw/ppc/spapr_irq.c +0 -0
           /*

           * 8 XIVE END structures per CPU. One for each available
           * priority

hw/ppc/spapr_irq.c +1 -1
@@ -356,7 +356,7 @@ void spapr_irq_init(SpaprMachineState *spapr, 
 Error **errp)
       }
       spapr->qirqs = qemu_allocate_irqs(spapr_set_irq, spapr,
-                                      smc->nr_xirqs + SPAPR_XIRQ_BASE);
+                                      smc->nr_xirqs + SPAPR_NR_IPIS);
       /*
        * Mostly we don't actually need this until reset, except that not
include/hw/ppc/spapr_irq.h +0 -0
index c22a72c9e2..e7a80a8349 100644
@@ -28,6 +28,7 @@

In include/hw/ppc/spapr_irq.h, we should describe the ranges a bit more. See commit dcc345b61ebe and ad8de98636e7 for more info. Something like :

  /*
   * The XIVE IRQ backend uses the same layout as the XICS backend but
   * covers the full range of the IRQ number space. The IRQ numbers for
   * the CPU IPIs are allocated at the bottom of this space, below 4K,
   * to preserve compatibility with XICS which does not use that range. */

  /*
   * CPU IPI range (XIVE only)
   */
  #define SPAPR_IRQ_IPI        0x0
  #define SPAPR_IRQ_NR_IPIS    0x1000

  /*
   * IRQ range offsets per device type
   */
  #define SPAPR_XIRQ_BASE      XICS_IRQ_BASE /* 0x1000 */

Quoted 4 lines

And to make sure the ranges don't overlap, let's add :

  QEMU_BUILD_BUG_ON(SPAPR_IRQ_NR_IPIS > SPAPR_XIRQ_BASE)

Yeh, this looks much better. Will update and post.

regards,
Harsh

Quoted 6 lines

Thanks,

C.

#7 lore raw

PATCH v2 2/2 ppc/spapr: Initialize max_cpus limit to SPAPR_NR_IPIS.

In reply to Harsh Prateek Bora

Initialize the machine specific max_cpus limit as per the maximum range of CPU IPIs available. Keeping between 4096 to 8192 will throw IRQ not free error due to XIVE/XICS limitation and keeping beyond 8192 will hit assert in tcg_region_init or spapr_xive_claim_irq.

Logs:

Without patch fix:

[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=4097
qemu-system-ppc64: IRQ 4096 is not free
[root@host build]#

On LPAR:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=8193 **
ERROR:../tcg/region.c:774:tcg_region_init: assertion failed:
(region_size >= 2 * page_size)
Bail out! ERROR:../tcg/region.c:774:tcg_region_init: assertion failed:
(region_size >= 2 * page_size)
Aborted (core dumped)
[root@host build]#

On x86:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=8193
qemu-system-ppc64: ../hw/intc/spapr_xive.c:596: spapr_xive_claim_irq:
Assertion `lisn < xive->nr_irqs' failed.
Aborted (core dumped)
[root@host build]#

With patch fix:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=4097
qemu-system-ppc64: Invalid SMP CPUs 4097. The max CPUs supported by machine 'pseries-8.2' is 4096
[root@host build]#

---
 hw/ppc/spapr.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
hw/ppc/spapr.c +3 -6
index df09aa9d6a..0de11a4458 100644
@@ -4647,13 +4647,10 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
     mc->block_default_type = IF_SCSI;
 
     /*
-     * Setting max_cpus to INT32_MAX. Both KVM and TCG max_cpus values
-     * should be limited by the host capability instead of hardcoded.
-     * max_cpus for KVM guests will be checked in kvm_init(), and TCG
-     * guests are welcome to have as many CPUs as the host are capable
-     * of emulate.
+     * While KVM determines max cpus in kvm_init() using kvm_max_vcpus(),
+     * In TCG the limit is restricted by the range of CPU IPIs available.
      */
-    mc->max_cpus = INT32_MAX;
+    mc->max_cpus = SPAPR_NR_IPIS;
 
     mc->no_parallel = 1;
     mc->default_boot_order = "";
Signature · 1 line
2.39.3
#8 lore raw

Re: [PATCH v2 2/2] ppc/spapr: Initialize max_cpus limit to SPAPR_NR_IPIS.

Hi Harsh,

Quoted 49 lines · Harsh Prateek Bora

Initialize the machine specific max_cpus limit as per the maximum range of CPU IPIs available. Keeping between 4096 to 8192 will throw IRQ not free error due to XIVE/XICS limitation and keeping beyond 8192 will hit assert in tcg_region_init or spapr_xive_claim_irq.

Logs:

Without patch fix:

[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=4097
qemu-system-ppc64: IRQ 4096 is not free
[root@host build]#

On LPAR:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=8193 **
ERROR:../tcg/region.c:774:tcg_region_init: assertion failed:
(region_size >= 2 * page_size)
Bail out! ERROR:../tcg/region.c:774:tcg_region_init: assertion failed:
(region_size >= 2 * page_size)
Aborted (core dumped)
[root@host build]#

On x86:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=8193
qemu-system-ppc64: ../hw/intc/spapr_xive.c:596: spapr_xive_claim_irq:
Assertion `lisn < xive->nr_irqs' failed.
Aborted (core dumped)
[root@host build]#

With patch fix:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=4097
qemu-system-ppc64: Invalid SMP CPUs 4097. The max CPUs supported by machine 'pseries-8.2' is 4096
[root@host build]#

---
  hw/ppc/spapr.c | 9 +++------
  1 file changed, 3 insertions(+), 6 deletions(-)
hw/ppc/spapr.c +0 -0
index df09aa9d6a..0de11a4458 100644
@@ -4647,13 +4647,10 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
      mc->block_default_type = IF_SCSI;
 
      /*

hw/ppc/spapr.c static void spapr_machine_class_init(ObjectClass *oc, void *data) · line 4653

Quoted 10 lines
hw/ppc/spapr.c +3 -6
-     * Setting max_cpus to INT32_MAX. Both KVM and TCG max_cpus values
-     * should be limited by the host capability instead of hardcoded.
-     * max_cpus for KVM guests will be checked in kvm_init(), and TCG
-     * guests are welcome to have as many CPUs as the host are capable
-     * of emulate.
+     * While KVM determines max cpus in kvm_init() using kvm_max_vcpus(),
+     * In TCG the limit is restricted by the range of CPU IPIs available.
       */
-    mc->max_cpus = INT32_MAX;
+    mc->max_cpus = SPAPR_NR_IPIS;

Is SPAPR_NR_IPIS also the upper limit for KVM?

Quoted 2 lines
hw/ppc/spapr.c +0 -0
      mc->no_parallel = 1;
      mc->default_boot_order = "";
#9 lore raw

Re: [PATCH v2 2/2] ppc/spapr: Initialize max_cpus limit to SPAPR_NR_IPIS.

Hi Philippe,

Quoted 58 lines · Philippe Mathieu-Daudé

Hi Harsh,

Quoted 55 lines · Harsh Prateek Bora

Initialize the machine specific max_cpus limit as per the maximum range of CPU IPIs available. Keeping between 4096 to 8192 will throw IRQ not free error due to XIVE/XICS limitation and keeping beyond 8192 will hit assert in tcg_region_init or spapr_xive_claim_irq.

Logs:

Without patch fix:

[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=4097
qemu-system-ppc64: IRQ 4096 is not free
[root@host build]#

On LPAR:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=8193 **
ERROR:../tcg/region.c:774:tcg_region_init: assertion failed:
(region_size >= 2 * page_size)
Bail out! ERROR:../tcg/region.c:774:tcg_region_init: assertion failed:
(region_size >= 2 * page_size)
Aborted (core dumped)
[root@host build]#

On x86:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=8193
qemu-system-ppc64: ../hw/intc/spapr_xive.c:596: spapr_xive_claim_irq:
Assertion `lisn < xive->nr_irqs' failed.
Aborted (core dumped)
[root@host build]#

With patch fix:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=4097
qemu-system-ppc64: Invalid SMP CPUs 4097. The max CPUs supported by machine 'pseries-8.2' is 4096
[root@host build]#

---
  hw/ppc/spapr.c | 9 +++------

  1 file changed, 3 insertions(+), 6 deletions(-)
hw/ppc/spapr.c +1 -5
index df09aa9d6a..0de11a4458 100644
@@ -4647,13 +4647,10 @@ static void 
 spapr_machine_class_init(ObjectClass *oc, void *data)
       mc->block_default_type = IF_SCSI;
       /*
-     * Setting max_cpus to INT32_MAX. Both KVM and TCG max_cpus values
-     * should be limited by the host capability instead of hardcoded.
-     * max_cpus for KVM guests will be checked in kvm_init(), and TCG
-     * guests are welcome to have as many CPUs as the host are capable
-     * of emulate.
+     * While KVM determines max cpus in kvm_init() using 
Quoted 8 lines
Quoted 6 lines
hw/ppc/spapr.c +1 -0
 kvm_max_vcpus(),
+     * In TCG the limit is restricted by the range of CPU IPIs 

available.
       */
-    mc->max_cpus = INT32_MAX;
+    mc->max_cpus = SPAPR_NR_IPIS;

Is SPAPR_NR_IPIS also the upper limit for KVM?

In KVM mode, the limit is restricted to what is supported by KVM which is checked using kvm_ioctl via wrappers in kvm_init and appears to be evaluating to 2048. So, having a larger default works for both case.

regards,
Harsh

Quoted 4 lines
Quoted 3 lines

      mc->no_parallel = 1;
      mc->default_boot_order = "";

#10 lore raw

Re: [PATCH v2 2/2] ppc/spapr: Initialize max_cpus limit to SPAPR_NR_IPIS.

Quoted 67 lines · Harsh Prateek Bora

Hi Philippe,

Quoted 55 lines · Philippe Mathieu-Daudé

Hi Harsh,

Quoted 52 lines · Harsh Prateek Bora

Initialize the machine specific max_cpus limit as per the maximum range of CPU IPIs available. Keeping between 4096 to 8192 will throw IRQ not free error due to XIVE/XICS limitation and keeping beyond 8192 will hit assert in tcg_region_init or spapr_xive_claim_irq.

Logs:

Without patch fix:

[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=4097
qemu-system-ppc64: IRQ 4096 is not free
[root@host build]#

On LPAR:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=8193 **
ERROR:../tcg/region.c:774:tcg_region_init: assertion failed:
(region_size >= 2 * page_size)
Bail out! ERROR:../tcg/region.c:774:tcg_region_init: assertion failed:
(region_size >= 2 * page_size)
Aborted (core dumped)
[root@host build]#

On x86:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=8193
qemu-system-ppc64: ../hw/intc/spapr_xive.c:596: spapr_xive_claim_irq:
Assertion `lisn < xive->nr_irqs' failed.
Aborted (core dumped)
[root@host build]#

With patch fix:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=4097
qemu-system-ppc64: Invalid SMP CPUs 4097. The max CPUs supported by machine 'pseries-8.2' is 4096
[root@host build]#

---
  hw/ppc/spapr.c | 9 +++------

  1 file changed, 3 insertions(+), 6 deletions(-)
hw/ppc/spapr.c +0 -4
index df09aa9d6a..0de11a4458 100644
@@ -4647,13 +4647,10 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
       mc->block_default_type = IF_SCSI;
       /*
-     * Setting max_cpus to INT32_MAX. Both KVM and TCG max_cpus values
-     * should be limited by the host capability instead of hardcoded.
-     * max_cpus for KVM guests will be checked in kvm_init(), and TCG
-     * guests are welcome to have as many CPUs as the host are capable
Quoted 8 lines

hw/ppc/spapr.c static void spapr_machine_class_init(ObjectClass *oc, void *data) · line 4653

Quoted 6 lines
hw/ppc/spapr.c +3 -2
-     * of emulate.
+     * While KVM determines max cpus in kvm_init() using kvm_max_vcpus(),
+     * In TCG the limit is restricted by the range of CPU IPIs available.
        */
-    mc->max_cpus = INT32_MAX;
+    mc->max_cpus = SPAPR_NR_IPIS;

Is SPAPR_NR_IPIS also the upper limit for KVM?

Quoted 1 line

In KVM mode, the limit is restricted to what is supported by KVM which is checked using kvm_ioctl via wrappers in kvm_init and appears to be evaluating to 2048. So, having a larger default works for both case.

QEMU sets the number of cpus with KVM ioctls :

KVM_DEV_XICS_NR_SERVERS
KVM_DEV_XIVE_NR_SERVERS

This is important for the host since the interrupt controller is then configured with these values through FW.

The default value is indeed 2K but this is large and wastes a lot of HW resources, page mappings, etc.

Thanks,

C.

#11 lore raw

Re: [PATCH v2 2/2] ppc/spapr: Initialize max_cpus limit to SPAPR_NR_IPIS.

Quoted 75 lines · Cédric Le Goater
Quoted 70 lines · Harsh Prateek Bora

Hi Philippe,

Quoted 58 lines · Philippe Mathieu-Daudé

Hi Harsh,

Quoted 55 lines · Harsh Prateek Bora

Initialize the machine specific max_cpus limit as per the maximum range of CPU IPIs available. Keeping between 4096 to 8192 will throw IRQ not free error due to XIVE/XICS limitation and keeping beyond 8192 will hit assert in tcg_region_init or spapr_xive_claim_irq.

Logs:

Without patch fix:

[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=4097
qemu-system-ppc64: IRQ 4096 is not free
[root@host build]#

On LPAR:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=8193 **
ERROR:../tcg/region.c:774:tcg_region_init: assertion failed:
(region_size >= 2 * page_size)
Bail out! ERROR:../tcg/region.c:774:tcg_region_init: assertion failed:
(region_size >= 2 * page_size)
Aborted (core dumped)
[root@host build]#

On x86:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=8193
qemu-system-ppc64: ../hw/intc/spapr_xive.c:596: spapr_xive_claim_irq:
Assertion `lisn < xive->nr_irqs' failed.
Aborted (core dumped)
[root@host build]#

With patch fix:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=4097
qemu-system-ppc64: Invalid SMP CPUs 4097. The max CPUs supported by machine 'pseries-8.2' is 4096
[root@host build]#

---
  hw/ppc/spapr.c | 9 +++------

  1 file changed, 3 insertions(+), 6 deletions(-)
hw/ppc/spapr.c +1 -5
index df09aa9d6a..0de11a4458 100644
@@ -4647,13 +4647,10 @@ static void 
 spapr_machine_class_init(ObjectClass *oc, void *data)
       mc->block_default_type = IF_SCSI;
       /*
-     * Setting max_cpus to INT32_MAX. Both KVM and TCG max_cpus values
-     * should be limited by the host capability instead of hardcoded.
-     * max_cpus for KVM guests will be checked in kvm_init(), and TCG
-     * guests are welcome to have as many CPUs as the host are capable
-     * of emulate.
+     * While KVM determines max cpus in kvm_init() using 
Quoted 8 lines
Quoted 6 lines
hw/ppc/spapr.c +1 -0
 kvm_max_vcpus(),
+     * In TCG the limit is restricted by the range of CPU IPIs 

available.
       */
-    mc->max_cpus = INT32_MAX;
+    mc->max_cpus = SPAPR_NR_IPIS;

Is SPAPR_NR_IPIS also the upper limit for KVM?

Quoted 1 line

In KVM mode, the limit is restricted to what is supported by KVM which is checked using kvm_ioctl via wrappers in kvm_init and appears to be evaluating to 2048. So, having a larger default works for both case.

QEMU sets the number of cpus with KVM ioctls :

Quoted 8 lines

    KVM_DEV_XICS_NR_SERVERS
    KVM_DEV_XIVE_NR_SERVERS

This is important for the host since the interrupt controller is then configured with these values through FW.

The default value is indeed 2K but this is large and wastes a lot of HW resources, page mappings, etc.

I was wondering if one day KVM raise its limit to 5k, then the machine will clamp to 4k, and someone will have to debug that. Not a big deal ;)

#12 lore raw

Re: [PATCH v2 2/2] ppc/spapr: Initialize max_cpus limit to SPAPR_NR_IPIS.

Quoted 79 lines · Philippe Mathieu-Daudé
Quoted 78 lines · Cédric Le Goater
Quoted 67 lines · Harsh Prateek Bora

Hi Philippe,

Quoted 55 lines · Philippe Mathieu-Daudé

Hi Harsh,

Quoted 52 lines · Harsh Prateek Bora

Initialize the machine specific max_cpus limit as per the maximum range of CPU IPIs available. Keeping between 4096 to 8192 will throw IRQ not free error due to XIVE/XICS limitation and keeping beyond 8192 will hit assert in tcg_region_init or spapr_xive_claim_irq.

Logs:

Without patch fix:

[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=4097
qemu-system-ppc64: IRQ 4096 is not free
[root@host build]#

On LPAR:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=8193 **
ERROR:../tcg/region.c:774:tcg_region_init: assertion failed:
(region_size >= 2 * page_size)
Bail out! ERROR:../tcg/region.c:774:tcg_region_init: assertion failed:
(region_size >= 2 * page_size)
Aborted (core dumped)
[root@host build]#

On x86:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=8193
qemu-system-ppc64: ../hw/intc/spapr_xive.c:596: spapr_xive_claim_irq:
Assertion `lisn < xive->nr_irqs' failed.
Aborted (core dumped)
[root@host build]#

With patch fix:
[root@host build]# qemu-system-ppc64 -accel tcg -smp 10,maxcpus=4097
qemu-system-ppc64: Invalid SMP CPUs 4097. The max CPUs supported by machine 'pseries-8.2' is 4096
[root@host build]#

---
  hw/ppc/spapr.c | 9 +++------

  1 file changed, 3 insertions(+), 6 deletions(-)
hw/ppc/spapr.c +0 -4
index df09aa9d6a..0de11a4458 100644
@@ -4647,13 +4647,10 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
       mc->block_default_type = IF_SCSI;
       /*
-     * Setting max_cpus to INT32_MAX. Both KVM and TCG max_cpus values
-     * should be limited by the host capability instead of hardcoded.
-     * max_cpus for KVM guests will be checked in kvm_init(), and TCG
-     * guests are welcome to have as many CPUs as the host are capable
Quoted 8 lines

hw/ppc/spapr.c static void spapr_machine_class_init(ObjectClass *oc, void *data) · line 4653

Quoted 6 lines
hw/ppc/spapr.c +3 -2
-     * of emulate.
+     * While KVM determines max cpus in kvm_init() using kvm_max_vcpus(),
+     * In TCG the limit is restricted by the range of CPU IPIs available.
        */
-    mc->max_cpus = INT32_MAX;
+    mc->max_cpus = SPAPR_NR_IPIS;

Is SPAPR_NR_IPIS also the upper limit for KVM?

Quoted 1 line

In KVM mode, the limit is restricted to what is supported by KVM which is checked using kvm_ioctl via wrappers in kvm_init and appears to be evaluating to 2048. So, having a larger default works for both case.

QEMU sets the number of cpus with KVM ioctls :

     KVM_DEV_XICS_NR_SERVERS
     KVM_DEV_XIVE_NR_SERVERS

This is important for the host since the interrupt controller is then configured with these values through FW.

Quoted 6 lines
Quoted 2 lines

The default value is indeed 2K but this is large and wastes a lot of HW resources, page mappings, etc.

I was wondering if one day KVM raise its limit to 5k, then the machine will clamp to 4k, and someone will have to debug that. Not a big deal ;)

Changing the number of CPUs will require some work in Linux first. I think we (as ppc) tried to push it to 8K but there was some push back upstream. Anyhow, there are DT issues also, memory layout, etc. It won't happen without being noticed I am sure :)

Anyhow, If we need more IPIs to support more CPUs, the IRQ number space will need an extra range after the device range to preserve compatibility.

Thanks,

C.