Skip to contentSkip to conversation

arm: better handling of nr_spis

PATCH In review Michal Orzel 2 participants 4 messages Mar 12, 2025

lore
Share & tools
lore
#0 lore raw

v2 cover arm: better handling of nr_spis

Refer:
https://lore.kernel.org/xen-devel/[email protected]/T/#mc15ab00940d5964b18b3d6092869dae6f85af1dc

Michal Orzel (2):
xen/arm: Improve handling of nr_spis
tools/arm: Reject configuration with incorrect nr_spis value

 docs/man/xl.cfg.5.pod.in        | 13 +++++--------
 tools/libs/light/libxl_arm.c    |  6 ++++++
 xen/arch/arm/dom0less-build.c   |  2 +-
 xen/arch/arm/domain_build.c     |  8 +-------
 xen/arch/arm/gic.c              |  3 +++
 xen/arch/arm/include/asm/vgic.h |  6 ++++++
 6 files changed, 22 insertions(+), 16 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/2 xen/arm: Improve handling of nr_spis

At the moment, we print a warning about max number of IRQs supported by GIC bigger than vGIC only for hardware domain. This check is not hwdom special, and should be made common. Also, in case of user not specifying nr_spis for dom0less domUs, we should take into account max number of IRQs supported by vGIC if it's smaller than for GIC.

Introduce VGIC_MAX_IRQS macro and use it instead of hardcoded 992 value. Introduce VGIC_DEF_NR_SPIS macro to store the default number of vGIC SPIs. Fix calculation of nr_spis for dom0less domUs and make the GIC/vGIC max IRQs comparison common.

---
Changes in v2:
- add macro for: min(gic_number_lines(), VGIC_MAX_IRQS) - 32

---
 xen/arch/arm/dom0less-build.c   | 2 +-
 xen/arch/arm/domain_build.c     | 8 +-------
 xen/arch/arm/gic.c              | 3 +++
 xen/arch/arm/include/asm/vgic.h | 6 ++++++
 4 files changed, 11 insertions(+), 8 deletions(-)
xen/arch/arm/dom0less-build.c +1 -1
index 31f31c38da3f..573b0d25ae41 100644
@@ -1018,7 +1018,7 @@ void __init create_domUs(void)
         {
             int vpl011_virq = GUEST_VPL011_SPI;
 
-            d_cfg.arch.nr_spis = gic_number_lines() - 32;
+            d_cfg.arch.nr_spis = VGIC_DEF_NR_SPIS;
 
             /*
              * The VPL011 virq is GUEST_VPL011_SPI, unless direct-map is
xen/arch/arm/domain_build.c +1 -7
index 7cc141ef75e9..2b5b4331834f 100644
@@ -2371,13 +2371,7 @@ void __init create_dom0(void)
 
     /* The vGIC for DOM0 is exactly emulating the hardware GIC */
     dom0_cfg.arch.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
-    /*
-     * Xen vGIC supports a maximum of 992 interrupt lines.
-     * 32 are substracted to cover local IRQs.
-     */
-    dom0_cfg.arch.nr_spis = min(gic_number_lines(), (unsigned int) 992) - 32;
-    if ( gic_number_lines() > 992 )
-        printk(XENLOG_WARNING "Maximum number of vGIC IRQs exceeded.\n");
+    dom0_cfg.arch.nr_spis = VGIC_DEF_NR_SPIS;
     dom0_cfg.arch.tee_type = tee_get_type();
     dom0_cfg.max_vcpus = dom0_max_vcpus();
 
xen/arch/arm/gic.c +3 -0
index acf61a4de373..e80fe0ca2421 100644
@@ -251,6 +251,9 @@ void __init gic_init(void)
         panic("Failed to initialize the GIC drivers\n");
     /* Clear LR mask for cpu0 */
     clear_cpu_lr_mask();
+
+    if ( gic_number_lines() > VGIC_MAX_IRQS )
+        printk(XENLOG_WARNING "Maximum number of vGIC IRQs exceeded\n");
 }
 
 void send_SGI_mask(const cpumask_t *cpumask, enum gic_sgi sgi)
xen/arch/arm/include/asm/vgic.h +6 -0
index e309dca1ad01..35c0c6a8b0b0 100644
@@ -329,6 +329,12 @@ extern void vgic_check_inflight_irqs_pending(struct vcpu *v,
  */
 #define vgic_num_irqs(d)        ((d)->arch.vgic.nr_spis + 32)
 
+/* Maximum number of IRQs supported by vGIC */
+#define VGIC_MAX_IRQS 992U
+
+/* Default number of vGIC SPIs. 32 are substracted to cover local IRQs. */
+#define VGIC_DEF_NR_SPIS (min(gic_number_lines(), VGIC_MAX_IRQS) - 32)
+
 /*
  * Allocate a guest VIRQ
  *  - spi == 0 => allocate a PPI. It will be the same on every vCPU
Signature · 1 line
2.25.1
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] xen/arm: Improve handling of nr_spis

Hi Michal,

Quoted 8 lines · Michal Orzel

At the moment, we print a warning about max number of IRQs supported by GIC bigger than vGIC only for hardware domain. This check is not hwdom special, and should be made common. Also, in case of user not specifying nr_spis for dom0less domUs, we should take into account max number of IRQs supported by vGIC if it's smaller than for GIC.

Quoted 6 lines

Introduce VGIC_MAX_IRQS macro and use it instead of hardcoded 992 value. Introduce VGIC_DEF_NR_SPIS macro to store the default number of vGIC SPIs. Fix calculation of nr_spis for dom0less domUs and make the GIC/vGIC max IRQs comparison common.

Cheers
Bertrand

Quoted 76 lines

---
Changes in v2:
- add macro for: min(gic_number_lines(), VGIC_MAX_IRQS) - 32
---

xen/arch/arm/dom0less-build.c   | 2 +-
xen/arch/arm/domain_build.c     | 8 +-------
xen/arch/arm/gic.c              | 3 +++
xen/arch/arm/include/asm/vgic.h | 6 ++++++
4 files changed, 11 insertions(+), 8 deletions(-)
xen/arch/arm/dom0less-build.c +1 -1
index 31f31c38da3f..573b0d25ae41 100644
@@ -1018,7 +1018,7 @@ void __init create_domUs(void)
        {
            int vpl011_virq = GUEST_VPL011_SPI;
 
-            d_cfg.arch.nr_spis = gic_number_lines() - 32;
+            d_cfg.arch.nr_spis = VGIC_DEF_NR_SPIS;
 
            /*
             * The VPL011 virq is GUEST_VPL011_SPI, unless direct-map is
xen/arch/arm/domain_build.c +1 -7
index 7cc141ef75e9..2b5b4331834f 100644
@@ -2371,13 +2371,7 @@ void __init create_dom0(void)
 
    /* The vGIC for DOM0 is exactly emulating the hardware GIC */
    dom0_cfg.arch.gic_version = XEN_DOMCTL_CONFIG_GIC_NATIVE;
-    /*
-     * Xen vGIC supports a maximum of 992 interrupt lines.
-     * 32 are substracted to cover local IRQs.
-     */
-    dom0_cfg.arch.nr_spis = min(gic_number_lines(), (unsigned int) 992) - 32;
-    if ( gic_number_lines() > 992 )
-        printk(XENLOG_WARNING "Maximum number of vGIC IRQs exceeded.\n");
+    dom0_cfg.arch.nr_spis = VGIC_DEF_NR_SPIS;
    dom0_cfg.arch.tee_type = tee_get_type();
    dom0_cfg.max_vcpus = dom0_max_vcpus();
 
xen/arch/arm/gic.c +3 -0
index acf61a4de373..e80fe0ca2421 100644
@@ -251,6 +251,9 @@ void __init gic_init(void)
        panic("Failed to initialize the GIC drivers\n");
    /* Clear LR mask for cpu0 */
    clear_cpu_lr_mask();
+
+    if ( gic_number_lines() > VGIC_MAX_IRQS )
+        printk(XENLOG_WARNING "Maximum number of vGIC IRQs exceeded\n");
 }
 
 void send_SGI_mask(const cpumask_t *cpumask, enum gic_sgi sgi)
xen/arch/arm/include/asm/vgic.h +6 -0
index e309dca1ad01..35c0c6a8b0b0 100644
@@ -329,6 +329,12 @@ extern void vgic_check_inflight_irqs_pending(struct vcpu *v,
 */
 #define vgic_num_irqs(d)        ((d)->arch.vgic.nr_spis + 32)
 
+/* Maximum number of IRQs supported by vGIC */
+#define VGIC_MAX_IRQS 992U
+
+/* Default number of vGIC SPIs. 32 are substracted to cover local IRQs. */
+#define VGIC_DEF_NR_SPIS (min(gic_number_lines(), VGIC_MAX_IRQS) - 32)
+
 /*
 * Allocate a guest VIRQ
 *  - spi == 0 => allocate a PPI. It will be the same on every vCPU
Signature · 1 line
2.25.1
#3 lore raw

PATCH v2 2/2 tools/arm: Reject configuration with incorrect nr_spis value

In reply to Michal Orzel

If the calculated value for nr_spis by the toolstack is bigger than the value provided by the user, we silently ignore the latter. This is not consistent with the approach we have in Xen on Arm when we try to reject incorrect configuration. Also, the documentation for nr_spis is incorrect as it mentions 991 as the number of max SPIs, where it should be 960 i.e. (1020 - 32) rounded down to the nearest multiple of 32.

---
Changes in v2:
- s/required/minimum required/

---
 docs/man/xl.cfg.5.pod.in     | 13 +++++--------
 tools/libs/light/libxl_arm.c |  6 ++++++
 2 files changed, 11 insertions(+), 8 deletions(-)
docs/man/xl.cfg.5.pod.in +5 -8
index 8e1422104e50..7339c44efd54 100644
@@ -3083,14 +3083,11 @@ interval of colors (such as "0-4").
 =item B<nr_spis="NR_SPIS">
 
 An optional integer parameter specifying the number of SPIs (Shared
-Peripheral Interrupts) to allocate for the domain. Max is 991 SPIs. If
-the value specified by the `nr_spis` parameter is smaller than the
-number of SPIs calculated by the toolstack based on the devices
-allocated for the domain, or the `nr_spis` parameter is not specified,
-the value calculated by the toolstack will be used for the domain.
-Otherwise, the value specified by the `nr_spis` parameter will be used.
-The number of SPIs should match the highest interrupt ID that will be
-assigned to the domain.
+Peripheral Interrupts) to allocate for the domain. Max is 960 SPIs. If
+the `nr_spis` parameter is not specified, the value calculated by the toolstack
+will be used for the domain. Otherwise, the value specified by the `nr_spis`
+parameter will be used. The number of SPIs should match the highest interrupt
+ID that will be assigned to the domain.
 
 =back
 
tools/libs/light/libxl_arm.c +6 -0
index 5a9db5e85f6f..2d895408cac3 100644
@@ -181,6 +181,12 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
 
     LOG(DEBUG, "Configure the domain");
 
+    if (nr_spis > d_config->b_info.arch_arm.nr_spis) {
+        LOG(ERROR, "Provided nr_spis value is too small (minimum required %u)\n",
+            nr_spis);
+        return ERROR_FAIL;
+    }
+
     config->arch.nr_spis = max(nr_spis, d_config->b_info.arch_arm.nr_spis);
     LOG(DEBUG, " - Allocate %u SPIs", config->arch.nr_spis);
 
Signature · 1 line
2.25.1