Introduce eSPI support
PATCH v7 3/12 xen/arm: vgic: implement helper functions for virq checks
In reply to Leonid KomarianskyiIntroduced two new helper functions for vGIC: vgic_is_valid_line and vgic_is_spi. The functions are similar to the newly introduced gic_is_valid_line and gic_is_spi, but they verify whether a vIRQ is available for a specific domain, while GIC-specific functions validate INTIDs for the real GIC hardware. For example, the GIC may support all 992 SPI lines, but the domain may use only some part of them (e.g., 640), depending on the highest IRQ number defined in the domain configuration. Therefore, for vGIC-related code and checks, the appropriate functions should be used. Also, updated the appropriate checks to use these new helper functions.
The purpose of introducing new helper functions for vGIC is essentially the same as for GIC: to avoid potential confusion with GIC-related checks and to consolidate similar code into separate functions, which can be more easily extended by additional conditions, e.g., when implementing extended SPI interrupts.
Only the validation change in vgic_inject_irq may affect existing functionality, as it currently checks whether the vIRQ is less than or equal to vgic_num_irqs. Since IRQ indexes start from 0 (where 32 is the first SPI), the check should behave consistently with similar logic in other places and should check if the vIRQ number is less than vgic_num_irqs. The remaining changes, which replace open-coded checks with the use of these new helper functions, do not introduce any functional changes, as the helper functions follow the current vIRQ index verification logic.
---
Changes in V7:
- no changes
Changes in V6:
- no changes
Changes in V5:
- added reviewed-by from Oleksandr Tyshchenko and from Volodymyr Babchuk
- added acked-by from Julien Grall
Changes in V4:
- removed redundant parentheses
Changes in V3:
- renamed vgic_is_valid_irq to vgic_is_valid_line and vgic_is_shared_irq to vgic_is_spi
- added vgic_is_valid_line implementation for new-vgic, because vgic_is_valid_line is called from generic code. It is necessary to fix the build for new-vgic.
- updated commit message
Changes in V2:
- introduced this patch
--- xen/arch/arm/gic.c | 3 +-- xen/arch/arm/include/asm/vgic.h | 7 +++++++ xen/arch/arm/irq.c | 4 ++-- xen/arch/arm/vgic.c | 10 ++++++++-- xen/arch/arm/vgic/vgic.c | 5 +++++ 5 files changed, 23 insertions(+), 6 deletions(-)
xen/arch/arm/gic.c +1 -2
@@ -134,8 +134,7 @@ int gic_route_irq_to_guest(struct domain *d, unsigned int virq,ASSERT (spin_is_locked (&desc->lock));/* Caller has already checked that the IRQ is an SPI */ -ASSERT (virq >=32 ); -ASSERT (virq <vgic_num_irqs (d)); +ASSERT (vgic_is_spi (d, virq));ASSERT (!is_lpi (virq)); ret =vgic_connect_hw_irq (d,NULL , virq, desc, true);
xen/arch/arm/include/asm/vgic.h +7 -0
@@ -335,6 +335,13 @@ extern void vgic_check_inflight_irqs_pending(struct vcpu *v,/* 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) +extern bool vgic_is_valid_line (struct domain *d,unsigned int virq); + +static inline bool vgic_is_spi (struct domain *d,unsigned int virq) +{ +return virq >=NR_LOCAL_IRQS &&vgic_is_valid_line (d, virq); +} +/* * Allocate a guest VIRQ * - spi == 0 => allocate a PPI. It will be the same on every vCPU
xen/arch/arm/irq.c +2 -2
@@ -442,7 +442,7 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,unsigned long flags;int retval =0 ; -if ( virq >=vgic_num_irqs (d) ) +if ( !vgic_is_valid_line (d, virq) ) { printk(XENLOG_G_ERR "the vIRQ number %u is too high for domain %u (max = %u)\n",
@@ -560,7 +560,7 @@ int release_guest_irq(struct domain *d, unsigned int virq)int ret;/* Only SPIs are supported */ -if ( virq <NR_LOCAL_IRQS || virq >=vgic_num_irqs (d) ) +if ( !vgic_is_spi (d, virq) )return -EINVAL ; desc =vgic_get_hw_irq_desc (d,NULL , virq);
xen/arch/arm/vgic.c +8 -2
@@ -24,6 +24,12 @@#include <asm/gic.h> #include <asm/vgic.h> + +bool vgic_is_valid_line (struct domain *d,unsigned int virq) +{ +return virq <vgic_num_irqs (d); +} +static inline struct vgic_irq_rank *vgic_get_rank (struct vcpu *v,unsigned int rank) {
@@ -582,7 +588,7 @@ void vgic_inject_irq(struct domain *d, struct vcpu *v, unsigned int virq,if ( !v ) {/* The IRQ needs to be an SPI if no vCPU is specified. */ -ASSERT (virq >=32 && virq <=vgic_num_irqs (d)); +ASSERT (vgic_is_spi (d, virq)); v =vgic_get_target_vcpu (d->vcpu[0 ], virq); };
@@ -659,7 +665,7 @@ bool vgic_emulate(struct cpu_user_regs *regs, union hsr hsr)bool vgic_reserve_virq (struct domain *d,unsigned int virq) { -if ( virq >=vgic_num_irqs (d) ) +if ( !vgic_is_valid_line (d, virq) )return false;return !test_and_set_bit (virq, d->arch.vgic.allocated_irqs);
xen/arch/arm/vgic/vgic.c +5 -0
@@ -718,6 +718,11 @@ bool vgic_reserve_virq(struct domain *d, unsigned int virq)return !test_and_set_bit (virq, d->arch.vgic.allocated_irqs); } +bool vgic_is_valid_line (struct domain *d,unsigned int virq) +{ +return virq <vgic_num_irqs (d); +} +int vgic_allocate_virq (struct domain *d,bool spi) {int first, end;
Signature · 1 line
2.34.1
v7 cover Introduce eSPI support
Hello everyone!
V6 contains an issue for debug builds with CONFIG_GICV3_ESPI=n due to a mistake in the ASSERT() condition in the is_espi() function. This patch series fixes the issue and also includes minor fixes according to the review of V6.
Summarized description:
This patch series adds support for the extended shared peripheral interrupt (eSPI) range (INTIDs 4096-5119 [2](ranges of INTIDs)) for Xen and guest domains. The implementation uses a generic approach to handle eSPIs, similar to regular SPIs, while maintaining compatibility with the existing SPI range. Functionality remains unchanged for setups that do not require eSPIs.
The series includes:
1) General refactoring of common IRQ operations with GIC registers to improve code readability, simplify further maintenance and prepare the key functions for eSPI implementation.
2) Introducing a new Kconfig option (default n) to enable or disable eSPI support. Disabling this option prevents unnecessary resource allocation for setups that do not require eSPIs.
3) Adding additional resources to store required information and operate with up to 1024 interrupts from eSPI range.
4) Adjusting assertions and checks to pass verification for INTIDs in the eSPI range.
5) Configuration of eSPI-specific registers during GIC initialization for systems with GICv3.1+ hardware.
6) Enables eSPI MMIO emulation for vGIC, allowing guest domains to access and operate within the eSPI's INTIDs.
7) Updating documentation and CHANGELOG to reflect the changes made for eSPI support.
Also, to simplify reviewing, please find below link to unsquashed patches, that are on top of every patch, that is changed in the series, compared to V6:
https://github.com/LKomaryanskiy/xen/commits/espi-support-master-upstream-v7-unsquashed/
Github branch with patch series:
https://github.com/LKomaryanskiy/xen/commits/espi-support-master-upstream-v7/
Changes in V7:
- individual changes in patches
Link on V6:
- https://lists.xenproject.org/archives/html/xen-devel/2025-09/msg00296.html
Changes in V6:
- individual changes in patches
Link on V5:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg02086.html
Changes in V5:
- individual changes in patches
Link on V4:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg01767.html
Changes in V4:
- added a patch for documentation
- individual changes in patches
Link on V3:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg01628.html
Changes in V3:
- added a patch to update CHANGELOG.md
- individual changes in patches
Link on V2:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg00372.html
Changes in V2:
- added 2 more patches to implement helper
functions for gic/vgic:
xen/arm: gic: implement helper functions for INTID checks xen/arm: vgic: implement helper functions for virq checks
- removed 2 patches:
xen/arm/irq: allow assignment/releasing of eSPI interrupts xen/arm: gic/irq: permit routing of eSPI interrupts to Xen and domains since their functionality can be moved to appropriate patches after introducing patches with helper functions
- individual changes in patches
Link on V1:
- https://lists.xenproject.org/archives/html/xen-devel/2025-07/msg01809.html
Leonid Komarianskyi (12):
xen/arm: gicv3: refactor obtaining GIC addresses for common operations xen/arm: gic: implement helper functions for INTID checks xen/arm: vgic: implement helper functions for virq checks xen/arm/irq: add handling for IRQs in the eSPI range xen/arm: gicv3: implement handling of GICv3.1 eSPI xen/arm/irq: allow eSPI processing in the gic_interrupt function xen/arm: gicv3: modify ICH_LR_PHYSICAL_MASK to allow eSPI processing xen/arm: vgic: add resource management for extended SPIs xen/arm: domain_build/dom0less-build: adjust domains config to support
eSPIs
xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers doc/man: update description for nr_spis with eSPI CHANGELOG.md: add mention of GICv3.1 eSPI support
CHANGELOG.md | 2 + docs/man/xl.cfg.5.pod.in | 13 +- xen/arch/arm/Kconfig | 8 + xen/arch/arm/dom0less-build.c | 2 +- xen/arch/arm/domain_build.c | 2 +- xen/arch/arm/gic-v3.c | 195 +++++++++++++++++++---- xen/arch/arm/gic.c | 8 +- xen/arch/arm/include/asm/gic.h | 28 ++++ xen/arch/arm/include/asm/gic_v3_defs.h | 40 ++++- xen/arch/arm/include/asm/irq.h | 38 +++++ xen/arch/arm/include/asm/vgic.h | 56 ++++++- xen/arch/arm/irq.c | 62 +++++++- xen/arch/arm/vgic-v3.c | 203 ++++++++++++++++++----- xen/arch/arm/vgic.c | 212 +++++++++++++++++++++++-- xen/arch/arm/vgic/vgic.c | 5 + 15 files changed, 762 insertions(+), 112 deletions(-)
Signature · 1 line
2.34.1
PATCH v7 4/12 xen/arm/irq: add handling for IRQs in the eSPI range
Currently, Xen does not support eSPI interrupts, leading to a data abort when such interrupts are defined in the DTS.
This patch introduces a separate array to initialize up to 1024 interrupt descriptors in the eSPI range and adds the necessary defines and helper function. These changes lay the groundwork for future implementation of full eSPI interrupt support. As this GICv3.1 feature is not required by all vendors, all changes are guarded by ifdefs, depending on the corresponding Kconfig option.
---
Changes in V7:
- fixed the condition in the is_espi assert for non-eSPI builds: the previous condition was mistakenly added with a wrong check and led to triggering asserts for all non-eSPI INTIDs, when it should be triggered in this case in the other way around
- minor: used is_espi() in the espi_intid_to_idx() ASSERT, as is_espi performs the same verification
Changes in V6:
- added an assert in is_espi() when CONFIG_GICV3_ESPI=n to ensure that out-of-range array resources are not accessed, e.g., in __irq_to_desc()
- removed unnecessary parentheses in is_espi()
- converted helper macro to inline functions and added sanity checks with ASSERTs to them
- defined espi_to_desc for non-eSPI builds as a prototype
- updates the comments
- used the IS_ENABLED(CONFIG_GICV3_ESPI) macro to initialize nr_irqs
Changes in V5:
- no functional changes introduced by this version compared with V4, only minor fixes and removal of ifdefs for macroses
- added TODO comment, suggested by Oleksandr Tyshchenko
- changed int to unsigned int for irqs
- removed ifdefs for eSPI-specific defines and macros to reduce the number of ifdefs and code duplication in further changes
- removed reviewed-by as moving defines from ifdefs requires additional confirmation from reviewers
Changes in V4:
- removed redundant line with 'default n' in Kconfig, as it is disabled by default, without explicit specification
- added reviewed-by from Volodymyr Babchuk
Changes in V3:
- introduced a new define NR_ESPI_IRQS to avoid confusion, like in the case of using NR_IRQS for espi_desc array
- implemented helper functions espi_to_desc and init_espi_data to make it possible to add stubs with the same name, and as a result, reduce the number of #ifdefs
- disable CONFIG_GICV3_ESPI default value to n
Changes in V2:
- use (ESPI_MAX_INTID + 1) instead of (ESPI_BASE_INTID + NR_IRQS)
- remove unnecessary comment for nr_irqs initialization
--- xen/arch/arm/Kconfig | 8 +++++ xen/arch/arm/include/asm/irq.h | 37 ++++++++++++++++++++++++ xen/arch/arm/irq.c | 53 ++++++++++++++++++++++++++++++++-- 3 files changed, 96 insertions(+), 2 deletions(-)
xen/arch/arm/Kconfig +8 -0
@@ -135,6 +135,14 @@ config GICV3 Driver for the ARM Generic Interrupt Controller v3. If unsure, use the default setting. +config GICV3_ESPI + bool "Extended SPI range support" + depends on GICV3 && !NEW_VGIC + help + Allow Xen and domains to use interrupt numbers from the extended SPI + range, from 4096 to 5119. This feature is introduced in GICv3.1 + architecture. + config HAS_ITS bool "GICv3 ITS MSI controller support (UNSUPPORTED)" if UNSUPPORTED depends on GICV3 && !NEW_VGIC && !ARM_32
xen/arch/arm/include/asm/irq.h +37 -0
@@ -32,6 +32,10 @@ struct arch_irq_desc {#define SPI_MAX_INTID 1019#define LPI_OFFSET 8192 +#define ESPI_BASE_INTID 4096 +#define ESPI_MAX_INTID 5119 +#define NR_ESPI_IRQS 1024 +/* LPIs are always numbered starting at 8192, so 0 is a good invalid case. */ #define INVALID_LPI 0
@@ -39,7 +43,12 @@ struct arch_irq_desc {#define INVALID_IRQ 1023extern const unsigned int nr_irqs; +#ifdef CONFIG_GICV3_ESPI +/* This will cover the eSPI range, to allow asignmant of eSPIs to domains. */ +#define nr_static_irqs (ESPI_MAX_INTID + 1) +#else #define nr_static_irqs NR_IRQS +#endif struct irq_desc ;struct irqaction ;
@@ -55,6 +64,34 @@ static inline bool is_lpi(unsigned int irq)return irq >=LPI_OFFSET ; } +static inline bool is_espi (unsigned int irq) +{ +#ifdef CONFIG_GICV3_ESPI +return irq >=ESPI_BASE_INTID && irq <=ESPI_MAX_INTID ; +#else +/* +* The function should not be called for eSPIs when CONFIG_GICV3_ESPI is +* disabled. Returning false allows the compiler to optimize the code +* when the config is disabled, while the assert ensures that out-of-range +* array resources are not accessed, e.g., in __irq_to_desc(). +*/ +ASSERT (!(irq >=ESPI_BASE_INTID && irq <=ESPI_MAX_INTID )); +return false; +#endif +} + +static inline unsigned int espi_intid_to_idx (unsigned int intid) +{ +ASSERT (is_espi (intid)); +return intid -ESPI_BASE_INTID ; +} + +static inline unsigned int espi_idx_to_intid (unsigned int idx) +{ +ASSERT (idx <=NR_ESPI_IRQS ); +return idx +ESPI_BASE_INTID ; +} +#define domain_pirq_to_irq (d, pirq) (pirq)bool is_assignable_irq (unsigned int irq);
xen/arch/arm/irq.c +51 -2
77 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v7 1/12 xen/arm: gicv3: refactor obtaining GIC addresses for common operations
In reply to Leonid KomarianskyiCurrently, many common functions perform the same operations to calculate GIC register addresses. This patch consolidates the similar code into a separate helper function to improve maintainability and reduce duplication. This refactoring also simplifies the implementation of eSPI support in future changes.
---
Changes in V7:
- no changes
Changes in V6:
- no functional changes, just fixing minor nit: changed u32 to uint32_t in get_addr_by_offset()
- added reviewed-by from Oleksandr Tyshchenko
Changes in V5:
- fixed a minor nit: changed %d to %u in the warning message because the IRQ number cannot be less than zero
- added acked-by from Julien Grall
Changes in V4:
- no changes
Changes in V3:
- changed panic() in get_addr_by_offset() to printing warning and ASSERT_UNREACHABLE()
- added verification of return pointer from get_addr_by_offset() in the callers
- moved invocation of get_addr_by_offset() from spinlock guards, since it is not necessarry
- added RB from Volodymyr Babchuk
Changes in V2:
- no changes
--- xen/arch/arm/gic-v3.c | 114 +++++++++++++++++++++++---------- xen/arch/arm/include/asm/irq.h | 1 + 2 files changed, 81 insertions(+), 34 deletions(-)
xen/arch/arm/gic-v3.c +80 -34
@@ -445,17 +445,67 @@ static void gicv3_dump_state(const struct vcpu *v) } } +static void __iomem *get_addr_by_offset (struct irq_desc *irqd,uint32_t offset) +{ +switch ( irqd->irq ) + { + case 0 ... (NR_GIC_LOCAL_IRQS - 1): +switch ( offset ) + { +case GICD_ISENABLER : +case GICD_ICENABLER : +case GICD_ISPENDR : +case GICD_ICPENDR : +case GICD_ISACTIVER : +case GICD_ICACTIVER : +return (GICD_RDIST_SGI_BASE + offset); +case GICD_ICFGR : +return (GICD_RDIST_SGI_BASE +GICR_ICFGR1 ); +case GICD_IPRIORITYR : +return (GICD_RDIST_SGI_BASE +GICR_IPRIORITYR0 + irqd->irq); +default : +break ; + } + case NR_GIC_LOCAL_IRQS ... SPI_MAX_INTID: +switch ( offset ) + { +case GICD_ISENABLER : +case GICD_ICENABLER : +case GICD_ISPENDR : +case GICD_ICPENDR : +case GICD_ISACTIVER : +case GICD_ICACTIVER : +return (GICD + offset + (irqd->irq /32 ) *4 ); +case GICD_ICFGR : +return (GICD +GICD_ICFGR + (irqd->irq /16 ) *4 ); +case GICD_IROUTER : +return (GICD +GICD_IROUTER + irqd->irq *8 ); +case GICD_IPRIORITYR : +return (GICD +GICD_IPRIORITYR + irqd->irq); +default : +break ; + } +default : +break ; + } + +/* Something went wrong, we shouldn't be able to reach here */ +printk (XENLOG_WARNING "GICv3: WARNING: Invalid offset 0x%x for IRQ#%u" , + offset, irqd->irq); +ASSERT_UNREACHABLE (); + +return NULL ; +} +static void gicv3_poke_irq (struct irq_desc *irqd,u32 offset,bool wait_for_rwp) {u32 mask =1U << (irqd->irq %32 ); -void __iomem *base; +void __iomem *addr =get_addr_by_offset (irqd, offset); -if ( irqd->irq <NR_GIC_LOCAL_IRQS ) - base =GICD_RDIST_SGI_BASE ; -else - base =GICD ; +if ( addr ==NULL ) +return ; -writel_relaxed (mask, base + offset + (irqd->irq /32 ) *4 ); +writel_relaxed (mask, addr);if ( wait_for_rwp )gicv3_wait_for_rwp (irqd->irq);
@@ -463,15 +513,12 @@ static void gicv3_poke_irq(struct irq_desc *irqd, u32 offset, bool wait_for_rwp)static bool gicv3_peek_irq (struct irq_desc *irqd,u32 offset) { -void __iomem *base; -unsigned int irq = irqd->irq; +void __iomem *addr =get_addr_by_offset (irqd, offset); -if ( irq >=NR_GIC_LOCAL_IRQS ) - base =GICD + (irq /32 ) *4 ; -else - base =GICD_RDIST_SGI_BASE ; +if ( addr ==NULL ) +return false; -return !!(readl (base + offset) & (1U << (irq %32 ))); +return !!(readl (addr) & (1U << (irqd->irq %32 ))); }static void gicv3_unmask_irq (struct irq_desc *irqd)
@@ -558,30 +605,28 @@ static inline uint64_t gicv3_mpidr_to_affinity(int cpu)static void gicv3_set_irq_type (struct irq_desc *desc,unsigned int type) {uint32_t cfg, actual, edgebit; -void __iomem *base; -unsigned int irq = desc->irq; +void __iomem *addr;/* SGI's are always edge-triggered not need to call GICD_ICFGR0 */ -ASSERT (irq >=NR_GIC_SGI ); +ASSERT (desc->irq >=NR_GIC_SGI ); -spin_lock (&gicv3.lock); + addr =get_addr_by_offset (desc,GICD_ICFGR ); +if ( addr ==NULL ) +return ; -if ( irq >=NR_GIC_LOCAL_IRQS ) - base =GICD +GICD_ICFGR + (irq /16 ) *4 ; -else - base =GICD_RDIST_SGI_BASE +GICR_ICFGR1 ; +spin_lock (&gicv3.lock); - cfg =readl_relaxed (base); + cfg =readl_relaxed (addr); - edgebit =2u << (2 * (irq %16 )); + edgebit =2u << (2 * (desc->irq %16 ));if ( type &IRQ_TYPE_LEVEL_MASK ) cfg &= ~edgebit;else if ( type &IRQ_TYPE_EDGE_BOTH ) cfg |= edgebit; -writel_relaxed (cfg, base); +writel_relaxed (cfg, addr); - actual =readl_relaxed (base); + actual =readl_relaxed (addr);if ( ( cfg & edgebit ) ^ ( actual & edgebit ) ) { printk(XENLOG_WARNING "GICv3: WARNING: "
@@ -600,16 +645,13 @@ static void gicv3_set_irq_type(struct irq_desc *desc, unsigned int type)static void gicv3_set_irq_priority (struct irq_desc *desc,unsigned int priority) { -unsigned int irq = desc->irq; +void __iomem *addr =get_addr_by_offset (desc,GICD_IPRIORITYR ); -spin_lock (&gicv3.lock); - -/* Set priority */ -if ( irq <NR_GIC_LOCAL_IRQS ) -writeb_relaxed (priority,GICD_RDIST_SGI_BASE +GICR_IPRIORITYR0 + irq); -else -writeb_relaxed (priority,GICD +GICD_IPRIORITYR + irq); +if ( addr ==NULL ) +return ; +spin_lock (&gicv3.lock); +writeb_relaxed (priority, addr);spin_unlock (&gicv3.lock); }
@@ -1273,6 +1315,10 @@ static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask) {unsigned int cpu;uint64_t affinity; +void __iomem *addr =get_addr_by_offset (desc,GICD_IROUTER ); + +if ( addr ==NULL ) +return ;ASSERT (!cpumask_empty (mask));
@@ -1284,7 +1330,7 @@ static void gicv3_irq_set_affinity(struct irq_desc *desc, const cpumask_t *mask) affinity &= ~GICD_IROUTER_SPI_MODE_ANY ;if ( desc->irq >=NR_GIC_LOCAL_IRQS ) -writeq_relaxed_non_atomic (affinity, (GICD +GICD_IROUTER + desc->irq *8 )); +writeq_relaxed_non_atomic (affinity, addr);spin_unlock (&gicv3.lock); }
xen/arch/arm/include/asm/irq.h +1 -0
@@ -29,6 +29,7 @@ struct arch_irq_desc {*/ #define NR_IRQS 1024 +#define SPI_MAX_INTID 1019#define LPI_OFFSET 8192/* LPIs are always numbered starting at 8192, so 0 is a good invalid case. */
Signature · 1 line
2.34.1
PATCH v7 2/12 xen/arm: gic: implement helper functions for INTID checks
In reply to Leonid KomarianskyiIntroduced two new helper functions: gic_is_valid_line and gic_is_spi. The first function helps determine whether an IRQ number is less than the number of lines supported by hardware. The second function additionally checks if the IRQ number falls within the SPI range. Also, updated the appropriate checks to use these new helper functions.
The current checks for the real GIC are very similar to those for the vGIC but serve a different purpose. For GIC-related code, the interrupt numbers should be validated based on whether the hardware can operate with such interrupts. On the other hand, for the vGIC, the indexes must also be verified to ensure they are available for a specific domain. The first reason for introducing these helper functions is to avoid potential confusion with vGIC-related checks. The second reason is to consolidate similar code into separate functions, which can be more easily extended by additional conditions, e.g., when implementing extended SPI interrupts.
The changes, which replace open-coded checks with the use of the new helper functions, do not introduce any functional changes, as the helper functions follow the current IRQ index verification logic.
---
Changes in V7:
- no changes
Changes in V6:
- no changes
Changes in V5:
- fixed a minor nit: moved the existing comment to the line above to fix formatting that exceeded 80 characters
- added acked-by from Julien Grall
Changes in V4:
- removed redundant parentheses
- added reviewed-by from Volodymyr Babchuk
Changes in V3:
- renamed gic_is_valid_irq to gic_is_valid_line and gic_is_shared_irq to gic_is_spi
- updated commit message
Changes in V2:
- introduced this patch
--- xen/arch/arm/gic.c | 3 ++- xen/arch/arm/include/asm/gic.h | 9 +++++++++ xen/arch/arm/irq.c | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-)
xen/arch/arm/gic.c +2 -1
@@ -111,7 +111,8 @@ static void gic_set_irq_priority(struct irq_desc *desc, unsigned int priority)void gic_route_irq_to_xen (struct irq_desc *desc,unsigned int priority) {ASSERT (priority <=0xff );/* Only 8 bits of priority */ -ASSERT (desc->irq <gic_number_lines ());/* Can't route interrupts that don't exist */ +/* Can't route interrupts that don't exist */ +ASSERT (gic_is_valid_line (desc->irq));ASSERT (test_bit (_IRQ_DISABLED, &desc->status));ASSERT (spin_is_locked (&desc->lock));
xen/arch/arm/include/asm/gic.h +9 -0
@@ -306,6 +306,15 @@ extern void gic_dump_vgic_info(struct vcpu *v);/* Number of interrupt lines */ extern unsigned int gic_number_lines (void ); +static inline bool gic_is_valid_line (unsigned int irq) +{ +return irq <gic_number_lines (); +} + +static inline bool gic_is_spi (unsigned int irq) +{ +return irq >=NR_LOCAL_IRQS &&gic_is_valid_line (irq); +}/* IRQ translation function for the device tree */ int gic_irq_xlate(const u32 *intspec, unsigned int intsize,
xen/arch/arm/irq.c +1 -1
@@ -415,7 +415,7 @@ err:bool is_assignable_irq (unsigned int irq) {/* For now, we can only route SPIs to the guest */ -return (irq >=NR_LOCAL_IRQS ) && (irq <gic_number_lines ()); +return gic_is_spi (irq); }/*
Signature · 1 line
2.34.1
PATCH v7 6/12 xen/arm/irq: allow eSPI processing in the gic_interrupt function
In reply to Leonid KomarianskyiThe gic_interrupt function is the main handler for processing IRQs. Currently, due to restrictive checks, it does not process interrupt numbers greater than 1019. This patch updates the condition to allow the handling of interrupts from the eSPI range.
---
Changes in V7:
- no changes
Changes in V6:
- added acked-by from Julien Grall
Changes in V5:
- no changes
Changes in V4:
- fixed commit message
- added reviewed-by from Volodymyr Babchuk
Changes in V3:
- no changes
Changes in V2:
- no changes
--- xen/arch/arm/gic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/gic.c +1 -1
@@ -342,7 +342,7 @@ void gic_interrupt(struct cpu_user_regs *regs, int is_fiq)/* Reading IRQ will ACK it */ irq = gic_hw_ops->read_irq (); -if (likely (irq >=GIC_SGI_STATIC_MAX && irq <1020 ) ) +if (likely (irq >=GIC_SGI_STATIC_MAX && irq <1020 ) ||is_espi (irq) ) {isb ();do_IRQ (regs, irq, is_fiq);
Signature · 1 line
2.34.1
PATCH v7 5/12 xen/arm: gicv3: implement handling of GICv3.1 eSPI
In reply to Leonid KomarianskyiIntroduced appropriate register definitions, helper macros, and initialization of required GICv3.1 distributor registers to support eSPI. This type of interrupt is handled in the same way as regular SPI interrupts, with the following differences:
1) eSPIs can have up to 1024 interrupts, starting from the beginning of the range, whereas regular SPIs use INTIDs from 32 to 1019, totaling 988 interrupts;
2) eSPIs start at INTID 4096, necessitating additional interrupt index conversion during register operations.
In case if appropriate config is disabled, or GIC HW doesn't support eSPI, the existing functionality will remain the same.
---
Changes in V7:
- no changes
Changes in V6:
- removed unnecessary parentheses in gic_is_valid_espi()
- updated gic_is_valid_line(): it now verifies the condition irq < gic_number_lines() first, as it is more likely that the irq number will be from the non-eSPI range
- minor change: changed the macros ESPI_INTID2IDX and ESPI_IDX2INTID into appropriate inline functions introduced in the previous patch
- added reviewed-by from Oleksandr Tyshchenko
Changes in V5:
- fixed minor nits, no functional changes: changed u32 to uint32_t and added a comment noting that the configuration for eSPIs is the same as for regular SPIs
- removed ifdefs for eSPI-specific offsets to reduce the number of ifdefs and code duplication in further changes
- removed reviewed-by as moving offset from ifdefs requires additional confirmation from reviewers
Changes in V4:
- added offsets for GICD_IGRPMODRnE and GICD_NSACRnE that are required for vGIC emulation
- added a log banner with eSPI information, similar to the one for regular SPI
- added newline after ifdef and before gic_is_valid_line
- added reviewed-by from Volodymyr Babchuk
Changes in V3:
- add __init attribute to gicv3_dist_espi_common_init
- change open-codded eSPI register initialization to the appropriate gen-mask macro
- fixed formatting for lines with more than 80 symbols
- introduced gicv3_dist_espi_init_aff to be able to use stubs in case of CONFIG_GICV3_ESPI disabled
- renamed parameter in the GICD_TYPER_ESPI_RANGE macro to espi_range (name was taken from GIC specification) to avoid confusion
- changed type for i variable to unsigned int since it cannot be negative
Changes in V2:
- move gic_number_espis function from
[PATCH 08/10] xen/arm: vgic: add resource management for extended SPIs to use it in the newly introduced gic_is_valid_espi
- add gic_is_valid_espi which checks if IRQ number is in supported by HW eSPI range
- update gic_is_valid_irq conditions to allow operations with eSPIs
--- xen/arch/arm/gic-v3.c | 83 ++++++++++++++++++++++++++ xen/arch/arm/include/asm/gic.h | 21 ++++++- xen/arch/arm/include/asm/gic_v3_defs.h | 38 ++++++++++++ 3 files changed, 141 insertions(+), 1 deletion(-)
xen/arch/arm/gic-v3.c +83 -0
@@ -485,6 +485,36 @@ static void __iomem *get_addr_by_offset(struct irq_desc *irqd, uint32_t offset)default :break ; } +#ifdef CONFIG_GICV3_ESPI + case ESPI_BASE_INTID ... ESPI_MAX_INTID: + { +uint32_t irq_index =espi_intid_to_idx (irqd->irq); + +switch ( offset ) + { +case GICD_ISENABLER : +return (GICD + GICD_ISENABLERnE + (irq_index /32 ) *4 ); +case GICD_ICENABLER : +return (GICD + GICD_ICENABLERnE + (irq_index /32 ) *4 ); +case GICD_ISPENDR : +return (GICD + GICD_ISPENDRnE + (irq_index /32 ) *4 ); +case GICD_ICPENDR : +return (GICD + GICD_ICPENDRnE + (irq_index /32 ) *4 ); +case GICD_ISACTIVER : +return (GICD + GICD_ISACTIVERnE + (irq_index /32 ) *4 ); +case GICD_ICACTIVER : +return (GICD + GICD_ICACTIVERnE + (irq_index /32 ) *4 ); +case GICD_ICFGR : +return (GICD + GICD_ICFGRnE + (irq_index /16 ) *4 ); +case GICD_IROUTER : +return (GICD + GICD_IROUTERnE + irq_index *8 ); +case GICD_IPRIORITYR : +return (GICD + GICD_IPRIORITYRnE + irq_index); +default : +break ; + } + } +#endif default :break ; }
@@ -655,6 +685,55 @@ static void gicv3_set_irq_priority(struct irq_desc *desc,spin_unlock (&gicv3.lock); } +#ifdef CONFIG_GICV3_ESPI +unsigned int gic_number_espis (void ) +{ +return gic_hw_ops->info->nr_espi; +} + +static void __init gicv3_dist_espi_common_init (uint32_t type) +{ +unsigned int espi_nr, i; + + espi_nr =min (1024U ,GICD_TYPER_ESPIS_NUM (type)); + gicv3_info.nr_espi = espi_nr; +/* The GIC HW doesn't support eSPI, so we can leave from here */ +if ( gicv3_info.nr_espi ==0 ) +return ; + +printk ("GICv3: %d eSPI lines\n" , gicv3_info.nr_espi); + +/* The configuration for eSPIs is similar to that for regular SPIs */ +for ( i =0 ; i < espi_nr; i +=16 ) +writel_relaxed (0 ,GICD + GICD_ICFGRnE + (i /16 ) *4 ); + +for ( i =0 ; i < espi_nr; i +=4 ) +writel_relaxed (GIC_PRI_IRQ_ALL , +GICD + GICD_IPRIORITYRnE + (i /4 ) *4 ); + +for ( i =0 ; i < espi_nr; i +=32 ) + { +writel_relaxed (GENMASK (31 ,0 ),GICD + GICD_ICENABLERnE + (i /32 ) *4 ); +writel_relaxed (GENMASK (31 ,0 ),GICD + GICD_ICACTIVERnE + (i /32 ) *4 ); + } + +for ( i =0 ; i < espi_nr; i +=32 ) +writel_relaxed (GENMASK (31 ,0 ),GICD + GICD_IGROUPRnE + (i /32 ) *4 ); +} + +static void __init gicv3_dist_espi_init_aff (uint64_t affinity) +{ +unsigned int i; + +for ( i =0 ; i < gicv3_info.nr_espi; i++ ) +writeq_relaxed_non_atomic (affinity,GICD + GICD_IROUTERnE + i *8 ); +} +#else +static void __init gicv3_dist_espi_common_init (uint32_t type) { } + +static void __init gicv3_dist_espi_init_aff (uint64_t affinity) { } +#endif +static void __init gicv3_dist_init (void ) {uint32_t type;
@@ -700,6 +779,8 @@ static void __init gicv3_dist_init(void)for ( i =NR_GIC_LOCAL_IRQS ; i < nr_lines; i +=32 )writel_relaxed (GENMASK (31 ,0 ),GICD +GICD_IGROUPR + (i /32 ) *4 ); +gicv3_dist_espi_common_init (type); +gicv3_dist_wait_for_rwp ();/* Turn on the distributor */
@@ -713,6 +794,8 @@ static void __init gicv3_dist_init(void)for ( i =NR_GIC_LOCAL_IRQS ; i < nr_lines; i++ )writeq_relaxed_non_atomic (affinity,GICD +GICD_IROUTER + i *8 ); + +gicv3_dist_espi_init_aff (affinity); }static int gicv3_enable_redist (void )
xen/arch/arm/include/asm/gic.h +20 -1
@@ -306,9 +306,24 @@ extern void gic_dump_vgic_info(struct vcpu *v);/* Number of interrupt lines */ extern unsigned int gic_number_lines (void ); +#ifdef CONFIG_GICV3_ESPI +extern unsigned int gic_number_espis (void ); + +static inline bool gic_is_valid_espi (unsigned int irq) +{ +return irq >=ESPI_BASE_INTID && + irq <espi_idx_to_intid (gic_number_espis ()); +} +#else +static inline bool gic_is_valid_espi (unsigned int irq) +{ +return false; +} +#endif +static inline bool gic_is_valid_line (unsigned int irq) { -return irq <gic_number_lines (); +return irq <gic_number_lines () ||gic_is_valid_espi (irq); }static inline bool gic_is_spi (unsigned int irq)
@@ -325,6 +340,10 @@ struct gic_info {enum gic_version hw_version;/* Number of GIC lines supported */ unsigned int nr_lines; +#ifdef CONFIG_GICV3_ESPI +/* Number of GIC eSPI supported */ +unsigned int nr_espi; +#endif /* Number of LR registers */ uint8_t nr_lrs;/* Maintenance irq number */
xen/arch/arm/include/asm/gic_v3_defs.h +38 -0
@@ -37,6 +37,44 @@#define GICD_IROUTER1019 (0x7FD8)#define GICD_PIDR2 (0xFFE8) +/* Additional registers for GICv3.1 */ +#define GICD_IGROUPRnE (0x1000) +#define GICD_IGROUPRnEN (0x107C) +#define GICD_ISENABLERnE (0x1200) +#define GICD_ISENABLERnEN (0x127C) +#define GICD_ICENABLERnE (0x1400) +#define GICD_ICENABLERnEN (0x147C) +#define GICD_ISPENDRnE (0x1600) +#define GICD_ISPENDRnEN (0x167C) +#define GICD_ICPENDRnE (0x1800) +#define GICD_ICPENDRnEN (0x187C) +#define GICD_ISACTIVERnE (0x1A00) +#define GICD_ISACTIVERnEN (0x1A7C) +#define GICD_ICACTIVERnE (0x1C00) +#define GICD_ICACTIVERnEN (0x1C7C) +#define GICD_IPRIORITYRnE (0x2000) +#define GICD_IPRIORITYRnEN (0x23FC) +#define GICD_ICFGRnE (0x3000) +#define GICD_ICFGRnEN (0x30FC) +#define GICD_IGRPMODRnE (0x3400) +#define GICD_IGRPMODRnEN (0x347C) +#define GICD_NSACRnE (0x3600) +#define GICD_NSACRnEN (0x36FC) +#define GICD_IROUTERnE (0x8000) +#define GICD_IROUTERnEN (0x9FFC) + +#ifdef CONFIG_GICV3_ESPI +#define GICD_TYPER_ESPI_SHIFT 8 +#define GICD_TYPER_ESPI_RANGE_SHIFT 27 +#define GICD_TYPER_ESPI_RANGE_MASK (0x1F) +#define GICD_TYPER_ESPI (1U << GICD_TYPER_ESPI_SHIFT) +#define GICD_TYPER_ESPI_RANGE (espi_range) ((((espi_range) & \ + GICD_TYPER_ESPI_RANGE_MASK) + 1) * 32) +#define GICD_TYPER_ESPIS_NUM (typer) \ + (((typer) & GICD_TYPER_ESPI) ? \ + GICD_TYPER_ESPI_RANGE((typer) >> GICD_TYPER_ESPI_RANGE_SHIFT) : 0) +#endif +/* Common between GICD_PIDR2 and GICR_PIDR2 */ #define GIC_PIDR2_ARCH_MASK (0xf0)#define GIC_PIDR2_ARCH_GICv3 (0x30)
Signature · 1 line
2.34.1
PATCH v7 8/12 xen/arm: vgic: add resource management for extended SPIs
In reply to Leonid KomarianskyiThis change introduces resource management in the VGIC to handle extended SPIs introduced in GICv3.1. The pending_irqs and allocated_irqs arrays are resized to support the required number of eSPIs, based on what is supported by the hardware and requested by the guest. A new field, ext_shared_irqs, is added to the VGIC structure to store information about eSPIs, similar to how shared_irqs is used for regular SPIs.
Since the eSPI range starts at INTID 4096 and INTIDs between 1025 and 4095 are reserved, helper macros are introduced to simplify the transformation of indices and to enable easier access to eSPI-specific resources. These changes prepare the VGIC for processing eSPIs as required by future functionality.
The initialization and deinitialization paths for vgic have been updated to allocate and free these resources appropriately. Additionally, updated handling of INTIDs greater than 1024, passed from the toolstack during domain creation, and verification logic ensures only valid SPI or eSPI INTIDs are used.
The existing SPI behavior remains unaffected when guests do not request eSPIs, GIC hardware does not support them, or the CONFIG_GICV3_ESPI option is disabled.
---
Changes in V7:
- minor: changed hardcoded value of 32 to NR_LOCAL_IRQS
- minor: used local variable idx in spi_to_pending() and vgic_reserve_virq()
- minor: added a comment for allocated_irqs and pending_irqs with index mappings
- added reviewed-by from Oleksandr Tyshchenko
Changes for V6:
- introduced a new function for index to virq conversion, idx_to_virq. This allows the removal of eSPI-specific functions and enables the reuse of existing code for regular SPIs
- fixed the return value of vgic_allocate_virq in the case of eSPI
- updated the error message in route_irq_to_guest(). To simplify it and avoid overcomplicating with INTID ranges, propose removing the information about the max number of IRQs
- fixed eSPI rank initialization to avoid using EXT_RANK_IDX2NUM for converting the eSPI rank to the extended range
- updated the recalculation logic to avoid the nr_spis > 1020 - NR_LOCAL_IRQS check when nr_spis is reassigned in the case of eSPI
- fixed formatting issues for macros
- minor change: changed the macros ESPI_INTID2IDX and ESPI_IDX2INTID into appropriate inline functions introduced in the previous patch
- minor change: changed int to unsigned int for nr_espis
Changes in V5:
- removed the has_espi field because it can be determined by checking whether domain->arch.vgic.nr_espis is zero or not
- since vgic_ext_rank_offset is not used in this patch, it has been moved to the appropriate patch in the patch series, which implements vgic eSPI registers emulation and requires this function
- removed ifdefs for eSPI-specific macros to reduce the number of ifdefs and code duplication in further changes
- fixed minor nit: used %pd for printing domain with its ID
Changes in V4:
- added has_espi field to simplify determining whether a domain is able to operate with eSPI
- fixed formatting issues and misspellings
Changes in V3:
- fixed formatting for lines with more than 80 symbols
- introduced helper functions to be able to use stubs in case of CONFIG_GICV3_ESPI disabled, and as a result, reduce the number of #ifdefs
- fixed checks for nr_spis in domain_vgic_init
- updated comment about nr_spis adjustments with dom0less mention
- moved comment with additional explanations before checks
- used unsigned int for indexes since they cannot be negative
- removed unnecessary parentheses
- move vgic_ext_rank_offset to the below ifdef guard, to reduce the number of ifdefs
Changes in V2:
- change is_espi_rank to is_valid_espi_rank to verify whether the array element ext_shared_irqs exists. The previous version, is_espi_rank, only checked if the rank index was less than the maximum possible eSPI rank index, but this could potentially result in accessing a non-existing array element. To address this, is_valid_espi_rank was introduced, which ensures that the required eSPI rank exists
- move gic_number_espis to
xen/arm: gicv3: implement handling of GICv3.1 eSPI
- update vgic_is_valid_irq checks to allow operating with eSPIs
- remove redundant newline in vgic_allocate_virq
--- xen/arch/arm/include/asm/vgic.h | 26 ++++- xen/arch/arm/irq.c | 3 +- xen/arch/arm/vgic.c | 180 +++++++++++++++++++++++++++++--- 3 files changed, 193 insertions(+), 16 deletions(-)
xen/arch/arm/include/asm/vgic.h +24 -2
@@ -144,11 +144,25 @@ struct vgic_dist {spinlock_t lock;uint32_t ctlr;int nr_spis;/* Number of SPIs */ -unsigned long *allocated_irqs;/* bitmap of IRQs allocated */ +/* +* Bitmap of allocated IRQs with the following index mapping: +* Local IRQs [0..31] +* Regular SPIs [32..nr_spis + 31] +* Optional, if supported: +* Extended SPIs [nr_spis + 32..nr_spis + nr_espis + 31] +*/ +unsigned long *allocated_irqs;struct vgic_irq_rank *shared_irqs; +#ifdef CONFIG_GICV3_ESPI +struct vgic_irq_rank *ext_shared_irqs; +unsigned int nr_espis;/* Number of extended SPIs */ +#endif /* * SPIs are domain global, SGIs and PPIs are per-VCPU and stored in -* struct arch_vcpu. +* struct arch_vcpu. The index mapping is as follows: +* Regular SPIs [0..nr_spis - 1] +* Optional, if supported: +* eSPIs [nr_spis..nr_spis + nr_espis - 1] */ struct pending_irq *pending_irqs;/* Base address for guest GIC */
@@ -243,6 +257,14 @@ struct vgic_ops {/* Number of ranks of interrupt registers for a domain */ #define DOMAIN_NR_RANKS (d) (((d)->arch.vgic.nr_spis+31)/32) +#ifdef CONFIG_GICV3_ESPI +#define DOMAIN_NR_EXT_RANKS (d) (((d)->arch.vgic.nr_espis + 31) / 32) +#endif +#define EXT_RANK_MIN (ESPI_BASE_INTID / 32) +#define EXT_RANK_MAX ((ESPI_MAX_INTID + 31) / 32) +#define EXT_RANK_NUM2IDX (num) ((num) - EXT_RANK_MIN) +#define EXT_RANK_IDX2NUM (idx) ((idx) + EXT_RANK_MIN) +#define vgic_lock (v) spin_lock_irq(&(v)->domain->arch.vgic.lock)#define vgic_unlock (v) spin_unlock_irq(&(v)->domain->arch.vgic.lock)
xen/arch/arm/irq.c +1 -2
@@ -494,8 +494,7 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,if ( !vgic_is_valid_line (d, virq) ) {printk (XENLOG_G_ERR -"the vIRQ number %u is too high for domain %u (max = %u)\n" , - irq, d->domain_id,vgic_num_irqs (d)); +"invalid vIRQ number %u for domain %pd\n" , irq, d);return -EINVAL ; }
xen/arch/arm/vgic.c +168 -12
281 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v7 9/12 xen/arm: domain_build/dom0less-build: adjust domains config to support eSPIs
In reply to Leonid KomarianskyiThe Dom0 and DomUs logic for the dom0less configuration in create_dom0() and arch_create_domUs() should account for extended SPIs when supported by the hardware and enabled with CONFIG_GICV3_ESPI. These changes ensure proper calculation of the maximum number of SPIs and eSPIs available to Dom0 and DomUs in dom0less setups.
When eSPIs are supported by the hardware and CONFIG_GICV3_ESPI is enabled, the maximum number of eSPI interrupts is calculated using the ESPI_BASE_INTID offset (4096) and is limited to 1024, with 32 IRQs subtracted. To ensure compatibility with non-Dom0 domains, this adjustment is applied by the toolstack during domain creation, while for Dom0 or DomUs in Dom0, it is handled directly during VGIC initialization. If eSPIs are not supported, the calculation defaults to using the standard SPI range, with a maximum value of 992 interrupt lines, as it works currently.
---
Changes in V7:
- no changes
Changes in V6:
- minor: updated the commit message
Changes in V5:
- fixed minor nits, no functional changes: updated the comment to make it clearer and corrected a misspelling
- added reviewed-by from Volodymyr Babchuk and from Oleksandr Tyshchenko
Changes in V4:
- consolidated the eSPI and SPI logic into a new inline function, vgic_def_nr_spis. Without eSPI support (either due to config being disabled or hardware not supporting it), it will return the regular SPI range, as it works currently. There are no functional changes compared with the previous patch version
- removed VGIC_DEF_MAX_SPI macro, to reduce the number of ifdefs
Changes in V3:
- renamed macro VGIC_DEF_NR_ESPIS to more appropriate VGIC_DEF_MAX_SPI
- added eSPI initialization for dom0less setups
- fixed comment with mentions about dom0less builds
- fixed formatting for lines with more than 80 symbols
- updated commit message
Changes in V2:
- no changes
--- xen/arch/arm/dom0less-build.c | 2 +- xen/arch/arm/domain_build.c | 2 +- xen/arch/arm/include/asm/vgic.h | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-)
xen/arch/arm/dom0less-build.c +1 -1
@@ -285,7 +285,7 @@ void __init arch_create_domUs(struct dt_device_node *node, {int vpl011_virq =GUEST_VPL011_SPI ; - d_cfg->arch.nr_spis =VGIC_DEF_NR_SPIS ; + 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 -1
@@ -2054,7 +2054,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 ; - dom0_cfg.arch.nr_spis =VGIC_DEF_NR_SPIS ; + 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/include/asm/vgic.h +19 -0
@@ -357,6 +357,25 @@ extern void vgic_check_inflight_irqs_pending(struct vcpu *v,/* 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) +static inline unsigned int vgic_def_nr_spis (void ) +{ +#ifdef CONFIG_GICV3_ESPI +/* +* Check if the hardware supports extended SPIs (even if the appropriate +* config is set). If not, the common SPI range will be used. Otherwise +* return the maximum eSPI INTID, supported by HW GIC, subtracted by 32. +* For Dom0 and started at boot time DomUs we will add back this value +* during VGIC initialization. This ensures consistent handling for Dom0 +* and other domains. For the regular SPI range interrupts in this case, +* the maximum value of VGIC_DEF_NR_SPIS will be used. +*/ +if (gic_number_espis () >0 ) +return ESPI_BASE_INTID +min (gic_number_espis (),1024U ) -32 ; +#endif + +return VGIC_DEF_NR_SPIS ; +} +extern bool vgic_is_valid_line (struct domain *d,unsigned int virq);static inline bool vgic_is_spi (struct domain *d,unsigned int virq)
Signature · 1 line
2.34.1
PATCH v7 12/12 CHANGELOG.md: add mention of GICv3.1 eSPI support
In reply to Leonid KomarianskyiThe GICv3.1 eSPI (Extended Shared Peripheral Interrupts) range is already supported with CONFIG_GICV3_ESPI enabled, so this feature should be mentioned in CHANGELOG.md.
---
Changes in V7:
- no changes
Changes in V6:
- no changes
Changes in V5:
- extended changelog update with a brief explanation of what eSPI is
- added acked-by from Oleksii Kurochko, which was received for V3:
https://lore.kernel.org/xen-devel/[email protected]/
Changes in V4:
- no changes
Changes in V3:
- introduced this patch
--- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+)
CHANGELOG.md +2 -0
@@ -29,6 +29,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - On Arm: - Ability to enable stack protector + - GICv3.1 eSPI (Extended Shared Peripheral Interrupts) support for Xen + and guest domains. ### Removed - On x86:
Signature · 1 line
2.34.1
PATCH v7 10/12 xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers
In reply to Leonid KomarianskyiImplemented support for GICv3.1 extended SPI registers for vGICv3, allowing the emulation of eSPI-specific behavior for guest domains. The implementation includes read and write emulation for eSPI-related registers (e.g., GICD_ISENABLERnE, GICD_IROUTERnE, and others), following a similar approach to the handling of regular SPIs.
The eSPI registers, previously located in reserved address ranges, are now adjusted to support MMIO read and write operations correctly when CONFIG_GICV3_ESPI is enabled.
The availability of eSPIs and the number of emulated extended SPIs for guest domains is reported by setting the appropriate bits in the GICD_TYPER register, based on the number of eSPIs requested by the domain and supported by the hardware. In cases where the configuration option is disabled, the hardware does not support eSPIs, or the domain does not request such interrupts, the functionality remains unchanged.
---
Changes in V7:
- minor: renamed vgic_get_rank to vgic_common_rank_offset
- minor: updated comment for vgic_common_rank_offset
- minor: restored comment for vgic_store_irouter
- minor: added sanity checks with asserts to helper functions
- added reviewed-by from Oleksandr Tyshchenko
Changes in V6:
- introduced helper functions: vgic_get_rank and vgic_get_reg_offset to avoid boilerplate code and simplify changes
- fixed index initialization in the previous patch ([08/12] xen/arm:
vgic: add resource management for extended SPIs) and removed index conversion for vgic_enable_irqs(), vgic_disable_irqs(), vgic_set_irqs_pending(), and vgic_check_inflight_irqs_pending()
- grouped SPI and eSPI registers
- updated the comment for vgic_store_irouter to reflect parameter changes
- minor change: changed the macros ESPI_INTID2IDX and ESPI_IDX2INTID into appropriate inline functions introduced in the previous patch
Changes in V5:
- since eSPI-specific defines and macros are now available even when the appropriate config is disabled, this allows us to remove many #ifdef guards and reuse the existing code for regular SPIs for eSPIs as well, as eSPIs are processed similarly. This improves code readability and consolidates the register ranges for SPIs and eSPIs in a single place, simplifying future changes or fixes for SPIs and their counterparts from the extended range
- moved vgic_ext_rank_offset() from
[08/12] xen/arm: vgic: add resource management for extended SPIs as the function was unused before this patch
- added stub implementation of vgic_ext_rank_offset() when CONFIG_GICV3_ESPI=n
- removed unnecessary defines for reserved ranges, which were introduced in V4 to reduce the number of #ifdefs. The issue is now resolved by allowing the use of SPI-specific offsets and reworking the logic
Changes in V4:
- added missing RAZ and write ignore eSPI-specific registers ranges:
GICD_NSACRnE and GICD_IGRPMODRnE
- changed previously reserved range to cover GICD_NSACRnE and GICD_IGRPMODRnE
- introduced GICD_RESERVED_RANGE<n>_START/END defines to remove hardcoded values and reduce the number of ifdefs
- fixed reserved ranges with eSPI option enabled: added missing range 0x0F30-0x0F7C
- updated the logic for domains that do not support eSPI, but Xen is compiled with the eSPI option. Now, prior to other MMIO checks, we verify whether eSPI is available for the domain or not. If not, it behaves as it does currently - RAZ and WI
- fixed print for GICD_ICACTIVERnE
- fixed new lines formatting for switch-case
Changes in V3:
- changed vgic_store_irouter parameters - instead of offset virq is used, to remove the additional bool espi parameter and simplify checks. Also, adjusted parameters for regular SPI. Since the offset parameter was used only for calculating virq number and then reused for finding rank offset, it will not affect functionality.
- fixed formatting for goto lables - added newlines after condition
- fixed logs for GICD_ISACTIVERnE and GICD_ICACTIVERnE handlers
- removed #ifdefs in 2 places where they were adjacent and could be merged
Changes in V2:
- add missing rank index conversion for pending and inflight irqs
--- xen/arch/arm/include/asm/vgic.h | 4 + xen/arch/arm/vgic-v3.c | 203 +++++++++++++++++++++++++------- xen/arch/arm/vgic.c | 22 ++++ 3 files changed, 185 insertions(+), 44 deletions(-)
xen/arch/arm/include/asm/vgic.h +4 -0
@@ -324,6 +324,10 @@ extern struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v,unsigned int b, unsigned int n, unsigned int s); +extern struct vgic_irq_rank *vgic_ext_rank_offset (struct vcpu *v, +unsigned int b, +unsigned int n, +unsigned int s);extern struct vgic_irq_rank *vgic_rank_irq (struct vcpu *v,unsigned int irq);extern void vgic_disable_irqs (struct vcpu *v,uint32_t r,unsigned int n);extern void vgic_enable_irqs (struct vcpu *v,uint32_t r,unsigned int n);
xen/arch/arm/vgic-v3.c +159 -44
403 lines not on this page · raw message
xen/arch/arm/vgic.c +22 -0
@@ -170,6 +170,18 @@ int domain_vgic_register(struct domain *d, unsigned int *mmio_count) }#ifdef CONFIG_GICV3_ESPI +/* +* The function behavior is the same as for regular SPIs (vgic_rank_offset), +* but it operates with extended SPI ranks. +*/ +struct vgic_irq_rank *vgic_ext_rank_offset (struct vcpu *v,unsigned int b, +unsigned int n,unsigned int s) +{ +unsigned int rank =REG_RANK_NR (b, (n >> s)); + +return vgic_get_rank (v, rank +EXT_RANK_MIN ); +} +static unsigned int vgic_num_spi_lines (struct domain *d) {return d->arch.vgic.nr_spis + d->arch.vgic.nr_espis;
@@ -210,6 +222,16 @@ static unsigned int vgic_num_spi_lines(struct domain *d) return d->arch.vgic.nr_spis; } +/* +* It is expected that, in the case of CONFIG_GICV3_ESPI=n, the function will +* return NULL. In this scenario, mmio_read/mmio_write will be treated as +* RAZ/WI, as expected. +*/ +struct vgic_irq_rank *vgic_ext_rank_offset (struct vcpu *v,unsigned int b, +unsigned int n,unsigned int s) +{ +return NULL ; +}#endif static unsigned int vgic_num_alloc_irqs (struct domain *d)
Signature · 1 line
2.34.1
PATCH v7 7/12 xen/arm: gicv3: modify ICH_LR_PHYSICAL_MASK to allow eSPI processing
In reply to Leonid KomarianskyiTo properly deactivate physical eSPI routed to a domain and allow them to be retriggered after the initial trigger, the LR needs to be updated. The current implementation ignores interrupts outside the range specified by the mask 0x3FF, which only covers IRQ numbers up to 1023. To enable processing of eSPI interrupts, this patch updates the mask to 0x1FFF.
---
Changes in V7:
- added reviewed-by from Volodymyr Babchuk
Changes in V6:
- updated mask to 0x1fff to avoid confusion
- updated commit message
- removed reviewed-by as new changes requires additional confirmation from reviewers
Changes in V5:
- no changes
Changes in V4:
- added reviewed-by from Volodymyr Babchuk
Changes in V3:
- no changes
Changes in V2:
- remove unnecessary CONFIG_GICV3_ESPI ifdef guard
--- xen/arch/arm/include/asm/gic_v3_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/include/asm/gic_v3_defs.h +1 -1
@@ -211,7 +211,7 @@#define ICH_LR_VIRTUAL_SHIFT 0#define ICH_LR_CPUID_MASK 0x7#define ICH_LR_CPUID_SHIFT 10 -#define ICH_LR_PHYSICAL_MASK 0x3ff +#define ICH_LR_PHYSICAL_MASK 0x1fff#define ICH_LR_PHYSICAL_SHIFT 32#define ICH_LR_STATE_MASK 0x3#define ICH_LR_STATE_SHIFT 62
Signature · 1 line
2.34.1
PATCH v7 11/12 doc/man: update description for nr_spis with eSPI
In reply to Leonid KomarianskyiSince eSPI support has been introduced, update the documentation with the appropriate description.
---
The discussion is ongoing and can be addressed in V5. Clarification is needed from the maintainers. Link:
- https://lore.kernel.org/xen-devel/[email protected]/
Changes in V7:
- no changes
Changes in V6:
- no changes
Changes in V5:
- no changes
Changes in V4:
- introduced this patch
--- docs/man/xl.cfg.5.pod.in | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
docs/man/xl.cfg.5.pod.in +8 -5
@@ -3072,11 +3072,14 @@ 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 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. +Peripheral Interrupts) to allocate for the domain. Max is 960 for regular SPIs +or 5088 for eSPIs (Extended SPIs). The eSPIs includes an additional 1024 SPIs +from the eSPI range (4096 to 5119) if the hardware supports extended SPIs +(GICv3.1+) and CONFIG_GICV3_ESPI is enabled. 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. =item B<trap_unmapped_accesses=BOOLEAN>
Signature · 1 line
2.34.1
Re: [PATCH v7 04/12] xen/arm/irq: add handling for IRQs in the eSPI range
In reply to Leonid KomarianskyiHi Leonid,
Quoted 11 lines · Leonid Komarianskyi
Currently, Xen does not support eSPI interrupts, leading to a data abort when such interrupts are defined in the DTS.
This patch introduces a separate array to initialize up to 1024 interrupt descriptors in the eSPI range and adds the necessary defines and helper function. These changes lay the groundwork for future implementation of full eSPI interrupt support. As this GICv3.1 feature is not required by all vendors, all changes are guarded by ifdefs, depending on the corresponding
Kconfigoption.
Quoted 1 line
Signed-off-by Leonid Komarianskyi <[email protected]>
Quoted 219 lines
---
Changes in V7:
- fixed the condition in theis_espiassert for non-eSPI builds: the previous condition was mistakenly added with a wrong check and led to triggering asserts for all non-eSPI INTIDs, when it should be triggered in this case in the other way around
- minor: usedis_espi()in theespi_intid_to_idx()ASSERT, asis_espiperforms the same verificationChanges in V6:
- added an assert inis_espi()whenCONFIG_GICV3_ESPI=nto ensure that out-of-range array resources are not accessed, e.g., in__irq_to_desc()
- removed unnecessary parentheses inis_espi()
- converted helper macro to inline functions and added sanity checks with ASSERTs to them
- definedespi_to_descfor non-eSPI builds as a prototype
- updates the comments
- used theIS_ENABLED(CONFIG_GICV3_ESPI)macro to initializenr_irqsChanges in V5:
- no functional changes introduced by this version compared with V4, only minor fixes and removal of ifdefs for macroses
- added TODO comment, suggested by Oleksandr Tyshchenko
- changed int to unsigned int for irqs
- removed ifdefs for eSPI-specific defines and macros to reduce the number of ifdefs and code duplication in further changes
- removed reviewed-by as moving defines from ifdefs requires additional confirmation from reviewersChanges in V4:
- removed redundant line with 'default n' inKconfig, as it is disabled by default, without explicit specification
- added reviewed-by from Volodymyr BabchukChanges in V3:
- introduced a new defineNR_ESPI_IRQSto avoid confusion, like in the case of usingNR_IRQSforespi_descarray
- implemented helper functionsespi_to_descandinit_espi_datato make it possible to add stubs with the same name, and as a result, reduce the number of #ifdefs
- disableCONFIG_GICV3_ESPIdefault value to nChanges in V2:
- use (ESPI_MAX_INTID+ 1) instead of (ESPI_BASE_INTID+NR_IRQS)
- remove unnecessary comment fornr_irqsinitialization--- xen/arch/arm/Kconfig | 8 +++++ xen/arch/arm/include/asm/irq.h | 37 ++++++++++++++++++++++++ xen/arch/arm/irq.c | 53 ++++++++++++++++++++++++++++++++-- 3 files changed, 96 insertions(+), 2 deletions(-)xen/arch/arm/Kconfig +8
-0@@ -135,6 +135,14 @@ config GICV3 Driver for the ARM Generic Interrupt Controller v3. If unsure, use the default setting. +config GICV3_ESPI + bool "Extended SPI range support" + depends on GICV3 && !NEW_VGIC + help + Allow Xen and domains to use interrupt numbers from the extended SPI + range, from 4096 to 5119. This feature is introduced in GICv3.1 + architecture. + config HAS_ITS bool "GICv3 ITS MSI controller support (UNSUPPORTED)" if UNSUPPORTED depends on GICV3 && !NEW_VGIC && !ARM_32xen/arch/arm/include/asm/irq.h +37
-0@@ -32,6 +32,10 @@ struct arch_irq_desc {#define SPI_MAX_INTID 1019#define LPI_OFFSET 8192 +#define ESPI_BASE_INTID 4096 +#define ESPI_MAX_INTID 5119 +#define NR_ESPI_IRQS 1024 +/* LPIs are always numbered starting at 8192, so 0 is a good invalid case. */ #define INVALID_LPI 0@@ -39,7 +43,12 @@ struct arch_irq_desc {#define INVALID_IRQ 1023extern const unsigned int nr_irqs; +#ifdef CONFIG_GICV3_ESPI +/* This will cover the eSPI range, to allow asignmant of eSPIs to domains. */ +#define nr_static_irqs (ESPI_MAX_INTID + 1) +#else #define nr_static_irqs NR_IRQS +#endif struct irq_desc ;struct irqaction ;@@ -55,6 +64,34 @@ static inline bool is_lpi(unsigned int irq)return irq >=LPI_OFFSET ; } +static inline bool is_espi (unsigned int irq) +{ +#ifdef CONFIG_GICV3_ESPI +return irq >=ESPI_BASE_INTID && irq <=ESPI_MAX_INTID ; +#else +/* +* The function should not be called for eSPIs when CONFIG_GICV3_ESPI is +* disabled. Returning false allows the compiler to optimize the code +* when the config is disabled, while the assert ensures that out-of-range +* array resources are not accessed, e.g., in __irq_to_desc(). +*/ +ASSERT (!(irq >=ESPI_BASE_INTID && irq <=ESPI_MAX_INTID )); +return false; +#endif +} + +static inline unsigned int espi_intid_to_idx (unsigned int intid) +{ +ASSERT (is_espi (intid)); +return intid -ESPI_BASE_INTID ; +} + +static inline unsigned int espi_idx_to_intid (unsigned int idx) +{ +ASSERT (idx <=NR_ESPI_IRQS ); +return idx +ESPI_BASE_INTID ; +} +#define domain_pirq_to_irq (d, pirq) (pirq)bool is_assignable_irq (unsigned int irq);xen/arch/arm/irq.c +51
-2@@ -19,7 +19,9 @@#include <asm/gic.h> #include <asm/vgic.h> -const unsigned int nr_irqs =NR_IRQS ; +const unsigned int nr_irqs =IS_ENABLED (CONFIG_GICV3_ESPI ) ? + (ESPI_MAX_INTID +1 ) : +NR_IRQS ;static unsigned int local_irqs_type[NR_LOCAL_IRQS ];static DEFINE_SPINLOCK (local_irqs_type_lock);@@ -46,6 +48,50 @@ void irq_end_none(struct irq_desc *irq) }static irq_desc_t irq_desc[NR_IRQS -NR_LOCAL_IRQS ]; +#ifdef CONFIG_GICV3_ESPI +/* TODO: Consider allocating an array dynamically */ +static irq_desc_t espi_desc[NR_ESPI_IRQS ]; + +static struct irq_desc *espi_to_desc (unsigned int irq) +{ +return &espi_desc[espi_intid_to_idx (irq)]; +} + +static int __init init_espi_data (void ) +{ +unsigned int irq; + +for ( irq =ESPI_BASE_INTID ; irq <=ESPI_MAX_INTID ; irq++ ) + { +struct irq_desc *desc =irq_to_desc (irq); +int rc =init_one_irq_desc (desc); + +if ( rc ) +return rc; + + desc->irq = irq; + desc->action =NULL ; + } + +return 0 ; +} +#else +/* +* Defined as a prototype as it should not be called if CONFIG_GICV3_ESPI=n. +* Without CONFIG_GICV3_ESPI, the additional 1024 IRQ descriptors will not +* be defined, and thus, they cannot be used. Unless INTIDs from the eSPI +* range are mistakenly defined in Xen DTS when the appropriate config is +* disabled, this function will not be reached because is_espi will return +* false for non-eSPI INTIDs. +*/ +struct irq_desc *espi_to_desc (unsigned int irq); + +static int __init init_espi_data (void ) +{ +return 0 ; +} +#endif + static DEFINE_PER_CPU(irq_desc_t[NR_LOCAL_IRQS], local_irq_desc);struct irq_desc *__irq_to_desc (unsigned int irq)@@ -53,6 +99,9 @@ struct irq_desc *__irq_to_desc(unsigned int irq)if ( irq <NR_LOCAL_IRQS )return &this_cpu (local_irq_desc)[irq]; +if (is_espi (irq) ) +return espi_to_desc (irq); +return &irq_desc[irq-NR_LOCAL_IRQS ]; }@@ -79,7 +128,7 @@ static int __init init_irq_data(void) desc->action =NULL ; } -return 0 ; +return init_espi_data (); }static int init_local_irq_data (unsigned int cpu)
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v7 08/12] xen/arm: vgic: add resource management for extended SPIs
In reply to Leonid KomarianskyiQuoted 20 lines · Leonid Komarianskyi
This change introduces resource management in the VGIC to handle extended SPIs introduced in GICv3.1. The
pending_irqsandallocated_irqsarrays are resized to support the required number of eSPIs, based on what is supported by the hardware and requested by the guest. A new field,ext_shared_irqs, is added to the VGIC structure to store information about eSPIs, similar to howshared_irqsis used for regular SPIs.Since the eSPI range starts at INTID 4096 and INTIDs between 1025 and 4095 are reserved, helper macros are introduced to simplify the transformation of indices and to enable easier access to eSPI-specific resources. These changes prepare the VGIC for processing eSPIs as required by future functionality.
The initialization and deinitialization paths for vgic have been updated to allocate and free these resources appropriately. Additionally, updated handling of INTIDs greater than 1024, passed from the toolstack during domain creation, and verification logic ensures only valid SPI or eSPI INTIDs are used.
Quoted 6 lines
The existing SPI behavior remains unaffected when guests do not request eSPIs, GIC hardware does not support them, or the
CONFIG_GICV3_ESPIoption is disabled.Signed-off-by Leonid Komarianskyi <[email protected]>Reviewed-by Oleksandr Tyshchenko <[email protected]>
Quoted 430 lines
---
Changes in V7:
- minor: changed hardcoded value of 32 toNR_LOCAL_IRQS
- minor: used local variable idx inspi_to_pending()andvgic_reserve_virq()
- minor: added a comment forallocated_irqsandpending_irqswith index mappings
- added reviewed-by from Oleksandr TyshchenkoChanges for V6:
- introduced a new function for index to virq conversion,idx_to_virq. This allows the removal of eSPI-specific functions and enables the reuse of existing code for regular SPIs
- fixed the return value ofvgic_allocate_virqin the case of eSPI
- updated the error message inroute_irq_to_guest(). To simplify it and avoid overcomplicating with INTID ranges, propose removing the information about the max number of IRQs
- fixed eSPI rank initialization to avoid usingEXT_RANK_IDX2NUMfor converting the eSPI rank to the extended range
- updated the recalculation logic to avoid thenr_spis> 1020 -NR_LOCAL_IRQScheck whennr_spisis reassigned in the case of eSPI
- fixed formatting issues for macros
- minor change: changed the macrosESPI_INTID2IDXandESPI_IDX2INTIDinto appropriate inline functions introduced in the previous patch
- minor change: changed int to unsigned int fornr_espisChanges in V5:
- removed thehas_espifield because it can be determined by checking whetherdomain->arch.vgic.nr_espisis zero or not
- sincevgic_ext_rank_offsetis not used in this patch, it has been moved to the appropriate patch in the patch series, which implements vgic eSPI registers emulation and requires this function
- removed ifdefs for eSPI-specific macros to reduce the number of ifdefs and code duplication in further changes
- fixed minor nit: used %pd for printing domain with its IDChanges in V4:
- addedhas_espifield to simplify determining whether a domain is able to operate with eSPI
- fixed formatting issues and misspellingsChanges in V3:
- fixed formatting for lines with more than 80 symbols
- introduced helper functions to be able to use stubs in case ofCONFIG_GICV3_ESPIdisabled, and as a result, reduce the number of #ifdefs
- fixed checks fornr_spisindomain_vgic_init
- updated comment aboutnr_spisadjustments with dom0less mention
- moved comment with additional explanations before checks
- used unsigned int for indexes since they cannot be negative
- removed unnecessary parentheses
- movevgic_ext_rank_offsetto the below ifdef guard, to reduce the number of ifdefsChanges in V2:
- changeis_espi_ranktois_valid_espi_rankto verify whether the array elementext_shared_irqsexists. The previous version,is_espi_rank, only checked if the rank index was less than the maximum possible eSPI rank index, but this could potentially result in accessing a non-existing array element. To address this,is_valid_espi_rankwas introduced, which ensures that the required eSPI rank exists
- movegic_number_espisto
xen/arm: gicv3: implement handling of GICv3.1 eSPI
- updatevgic_is_valid_irqchecks to allow operating with eSPIs
- remove redundant newline invgic_allocate_virq--- xen/arch/arm/include/asm/vgic.h | 26 ++++- xen/arch/arm/irq.c | 3 +- xen/arch/arm/vgic.c | 180 +++++++++++++++++++++++++++++--- 3 files changed, 193 insertions(+), 16 deletions(-)xen/arch/arm/include/asm/vgic.h +24
-2@@ -144,11 +144,25 @@ struct vgic_dist {spinlock_t lock;uint32_t ctlr;int nr_spis;/* Number of SPIs */ -unsigned long *allocated_irqs;/* bitmap of IRQs allocated */ +/* +* Bitmap of allocated IRQs with the following index mapping: +* Local IRQs [0..31] +* Regular SPIs [32..nr_spis + 31] +* Optional, if supported: +* Extended SPIs [nr_spis + 32..nr_spis + nr_espis + 31] +*/ +unsigned long *allocated_irqs;struct vgic_irq_rank *shared_irqs; +#ifdef CONFIG_GICV3_ESPI +struct vgic_irq_rank *ext_shared_irqs; +unsigned int nr_espis;/* Number of extended SPIs */ +#endif /* * SPIs are domain global, SGIs and PPIs are per-VCPU and stored in -* struct arch_vcpu. +* struct arch_vcpu. The index mapping is as follows: +* Regular SPIs [0..nr_spis - 1] +* Optional, if supported: +* eSPIs [nr_spis..nr_spis + nr_espis - 1] */ struct pending_irq *pending_irqs;/* Base address for guest GIC */ @@ -243,6 +257,14 @@ struct vgic_ops {/* Number of ranks of interrupt registers for a domain */ #define DOMAIN_NR_RANKS (d) (((d)->arch.vgic.nr_spis+31)/32) +#ifdef CONFIG_GICV3_ESPI +#define DOMAIN_NR_EXT_RANKS (d) (((d)->arch.vgic.nr_espis + 31) / 32) +#endif +#define EXT_RANK_MIN (ESPI_BASE_INTID / 32) +#define EXT_RANK_MAX ((ESPI_MAX_INTID + 31) / 32) +#define EXT_RANK_NUM2IDX (num) ((num) - EXT_RANK_MIN) +#define EXT_RANK_IDX2NUM (idx) ((idx) + EXT_RANK_MIN) +#define vgic_lock (v) spin_lock_irq(&(v)->domain->arch.vgic.lock)#define vgic_unlock (v) spin_unlock_irq(&(v)->domain->arch.vgic.lock)xen/arch/arm/irq.c +1
-2@@ -494,8 +494,7 @@ int route_irq_to_guest(struct domain *d, unsigned int virq,if ( !vgic_is_valid_line (d, virq) ) {printk (XENLOG_G_ERR -"the vIRQ number %u is too high for domain %u (max = %u)\n" , - irq, d->domain_id,vgic_num_irqs (d)); +"invalid vIRQ number %u for domain %pd\n" , irq, d);return -EINVAL ; }xen/arch/arm/vgic.c +168
-12@@ -25,11 +25,61 @@#include <asm/vgic.h> +static inline unsigned int idx_to_virq (struct domain *d,unsigned int idx) +{ +if ( idx >=vgic_num_irqs (d) ) +return espi_idx_to_intid (idx -vgic_num_irqs (d)); + +return idx; +} +bool vgic_is_valid_line (struct domain *d,unsigned int virq) { +#ifdef CONFIG_GICV3_ESPI +if ( virq >=ESPI_BASE_INTID && + virq <espi_idx_to_intid (d->arch.vgic.nr_espis) ) +return true; +#endif +return virq <vgic_num_irqs (d); } +#ifdef CONFIG_GICV3_ESPI +/* +* Since eSPI indexes start from 4096 and numbers from 1024 to +* 4095 are forbidden, we need to check both lower and upper +* limits for ranks. +*/ +static inline bool is_valid_espi_rank (struct domain *d,unsigned int rank) +{ +return rank >=EXT_RANK_MIN && +EXT_RANK_NUM2IDX (rank) <DOMAIN_NR_EXT_RANKS (d); +} + +static inline struct vgic_irq_rank *vgic_get_espi_rank (struct vcpu *v, +unsigned int rank) +{ +return &v->domain->arch.vgic.ext_shared_irqs[EXT_RANK_NUM2IDX (rank)]; +} + +#else +static inline bool is_valid_espi_rank (struct domain *d,unsigned int rank) +{ +return false; +} + +/* +* This function is stub and will not be called if CONFIG_GICV3_ESPI=n, +* because in this case, is_valid_espi_rank will always return false. +*/ +static inline struct vgic_irq_rank *vgic_get_espi_rank (struct vcpu *v, +unsigned int rank) +{ +ASSERT_UNREACHABLE (); +return NULL ; +} +#endif +static inline struct vgic_irq_rank *vgic_get_rank (struct vcpu *v,unsigned int rank) {@@ -37,6 +87,8 @@ static inline struct vgic_irq_rank *vgic_get_rank(struct vcpu *v,return v->arch.vgic.private_irqs; else if ( rank <= DOMAIN_NR_RANKS(v->domain) ) return &v->domain->arch.vgic.shared_irqs[rank - 1]; + else if ( is_valid_espi_rank(v->domain, rank) ) + return vgic_get_espi_rank(v, rank); else return NULL; }@@ -117,6 +169,54 @@ int domain_vgic_register(struct domain *d, unsigned int *mmio_count)return 0 ; } +#ifdef CONFIG_GICV3_ESPI +static unsigned int vgic_num_spi_lines (struct domain *d) +{ +return d->arch.vgic.nr_spis + d->arch.vgic.nr_espis; +} + +static int init_vgic_espi (struct domain *d) +{ +unsigned int i, idx; + +if ( d->arch.vgic.nr_espis ==0 ) +return 0 ; + + d->arch.vgic.ext_shared_irqs = + xzalloc_array(struct vgic_irq_rank, DOMAIN_NR_EXT_RANKS(d)); +if ( d->arch.vgic.ext_shared_irqs ==NULL ) +return -ENOMEM ; + +for ( i = d->arch.vgic.nr_spis, idx =0 ; + i <vgic_num_spi_lines (d); i++, idx++ ) +vgic_init_pending_irq (&d->arch.vgic.pending_irqs[i], +espi_idx_to_intid (idx)); + +for ( i =0 ; i <DOMAIN_NR_EXT_RANKS (d); i++ ) +vgic_rank_init (&d->arch.vgic.ext_shared_irqs[i], +EXT_RANK_IDX2NUM (i),0 ); + +return 0 ; +} + +#else +static int init_vgic_espi (struct domain *d) +{ +return 0 ; +} + +static unsigned int vgic_num_spi_lines (struct domain *d) +{ +return d->arch.vgic.nr_spis; +} + +#endif + +static unsigned int vgic_num_alloc_irqs (struct domain *d) +{ +return vgic_num_spi_lines (d) +NR_LOCAL_IRQS ; +} +int domain_vgic_init (struct domain *d,unsigned int nr_spis) {int i;@@ -133,7 +233,39 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis)/* Limit the number of virtual SPIs supported to (1020 - 32) = 988 */ if ( nr_spis > (1020 - NR_LOCAL_IRQS) ) +#ifndef CONFIG_GICV3_ESPI return -EINVAL ; +#else + { +/* +* During domain creation, the dom0less DomUs code or toolstack +* specifies the maximum INTID, which is defined in the domain +* config subtracted by 32 to cover the local IRQs (please see +* the comment to VGIC_DEF_NR_SPIS). To compute the actual number +* of eSPI that will be usable for, add back 32 (NR_LOCAL_IRQS). +*/ + nr_spis +=NR_LOCAL_IRQS ; +if ( nr_spis >espi_idx_to_intid (NR_ESPI_IRQS ) ) +return -EINVAL ; + +if ( nr_spis >=ESPI_BASE_INTID ) + { +unsigned int nr_espis =min (nr_spis -ESPI_BASE_INTID ,1024U ); + +/* Verify if GIC HW can handle provided INTID */ +if ( nr_espis >gic_number_espis () ) +return -EINVAL ; + + d->arch.vgic.nr_espis = nr_espis; +/* Set the maximum available number for regular SPIs */ + nr_spis =VGIC_DEF_NR_SPIS ; + } +else + { +return -EINVAL ; + } + } +#endif d->arch.vgic.nr_spis = nr_spis;@@ -145,7 +277,7 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis)return -ENOMEM ; d->arch.vgic.pending_irqs = - xzalloc_array(struct pending_irq, d->arch.vgic.nr_spis); + xzalloc_array(struct pending_irq, vgic_num_spi_lines(d));if ( d->arch.vgic.pending_irqs ==NULL )return -ENOMEM ;@@ -156,12 +288,16 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis)for ( i =0 ; i <DOMAIN_NR_RANKS (d); i++ )vgic_rank_init (&d->arch.vgic.shared_irqs[i], i +1 ,0 ); + ret =init_vgic_espi (d); +if ( ret ) +return ret; + ret = d->arch.vgic.handler->domain_init (d);if ( ret )return ret; d->arch.vgic.allocated_irqs = - xzalloc_array(unsigned long, BITS_TO_LONGS(vgic_num_irqs(d))); + xzalloc_array(unsigned long, BITS_TO_LONGS(vgic_num_alloc_irqs(d)));if ( !d->arch.vgic.allocated_irqs )return -ENOMEM ;@@ -182,9 +318,12 @@ void domain_vgic_free(struct domain *d)int i;int ret; -for ( i =0 ; i < (d->arch.vgic.nr_spis); i++ ) +for ( i =NR_LOCAL_IRQS ; i <vgic_num_alloc_irqs (d); i++ ) { -struct pending_irq *p =spi_to_pending (d, i +32 ); +struct pending_irq *p; +unsigned int virq =idx_to_virq (d, i); + + p =spi_to_pending (d, virq);if ( p->desc ) {@@ -198,6 +337,9 @@ void domain_vgic_free(struct domain *d)if ( d->arch.vgic.handler ) d->arch.vgic.handler->domain_free (d);xfree (d->arch.vgic.shared_irqs); +#ifdef CONFIG_GICV3_ESPI +xfree (d->arch.vgic.ext_shared_irqs); +#endif xfree (d->arch.vgic.pending_irqs);xfree (d->arch.vgic.allocated_irqs); }@@ -323,10 +465,12 @@ void arch_move_irqs(struct vcpu *v)*/ ASSERT (!is_lpi (vgic_num_irqs (d) -1 )); -for ( i =32 ; i <vgic_num_irqs (d); i++ ) +for ( i =NR_LOCAL_IRQS ; i <vgic_num_alloc_irqs (d); i++ ) { - v_target =vgic_get_target_vcpu (v, i); - p =irq_to_pending (v_target, i); +unsigned int virq =idx_to_virq (d, i); + + v_target =vgic_get_target_vcpu (v, virq); + p =irq_to_pending (v_target, virq);if ( v_target == v && !test_bit (GIC_IRQ_GUEST_MIGRATING , &p->status) )irq_set_affinity (p->desc, cpu_mask);@@ -539,15 +683,22 @@ struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq)else if (is_lpi (irq) ) n = v->domain->arch.vgic.handler->lpi_to_pending (v->domain, irq);else - n = &v->domain->arch.vgic.pending_irqs[irq -32 ]; + n =spi_to_pending (v->domain, irq);return n; }struct pending_irq *spi_to_pending (struct domain *d,unsigned int irq) { +unsigned int idx; +ASSERT (irq >=NR_LOCAL_IRQS ); -return &d->arch.vgic.pending_irqs[irq -32 ]; +if (is_espi (irq) ) + idx =espi_intid_to_idx (irq) + d->arch.vgic.nr_spis; +else + idx = irq -NR_LOCAL_IRQS ; + +return &d->arch.vgic.pending_irqs[idx]; }void vgic_clear_pending_irqs (struct vcpu *v)@@ -665,10 +816,15 @@ bool vgic_emulate(struct cpu_user_regs *regs, union hsr hsr)bool vgic_reserve_virq (struct domain *d,unsigned int virq) { +unsigned int idx = virq; +if ( !vgic_is_valid_line (d, virq) )return false; -return !test_and_set_bit (virq, d->arch.vgic.allocated_irqs); +if (is_espi (virq) ) + idx =espi_intid_to_idx (virq) +vgic_num_irqs (d); + +return !test_and_set_bit (idx, d->arch.vgic.allocated_irqs); }int vgic_allocate_virq (struct domain *d,bool spi)@@ -685,7 +841,7 @@ int vgic_allocate_virq(struct domain *d, bool spi)else { first =32 ; - end =vgic_num_irqs (d); + end =vgic_num_alloc_irqs (d); }/* @@ -700,7 +856,7 @@ int vgic_allocate_virq(struct domain *d, bool spi) }while (test_and_set_bit (virq, d->arch.vgic.allocated_irqs) ); -return virq; +return idx_to_virq (d, virq); }void vgic_free_virq (struct domain *d,unsigned int virq)
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v7 04/12] xen/arm/irq: add handling for IRQs in the eSPI range
In reply to Leonid KomarianskyiHi Leonid,
Quoted 16 lines · Leonid Komarianskyi
xen/arch/arm/include/asm/irq.h +4
-0@@ -32,6 +32,10 @@ struct arch_irq_desc {#define SPI_MAX_INTID 1019#define LPI_OFFSET 8192 +#define ESPI_BASE_INTID 4096 +#define ESPI_MAX_INTID 5119 +#define NR_ESPI_IRQS 1024 +/* LPIs are always numbered starting at 8192, so 0 is a good invalid case. */ #define INVALID_LPI 0
xen/arch/arm/include/asm/irq.h struct arch_irq_desc { · line 47
Quoted 5 lines
xen/arch/arm/include/asm/irq.h +2
-0@@ -39,7 +43,12 @@ struct arch_irq_desc {#define INVALID_IRQ 1023extern const unsigned int nr_irqs; +#ifdef CONFIG_GICV3_ESPI +/* This will cover the eSPI range, to allow asignmant of eSPIs to domains. */
Typo: s/asignmant/assignment/
[...]
Quoted 4 lines
Unless INTIDs from the eSPI
+ * range are mistakenly defined in Xen DTS when the appropriate config is
+ * disabled, this function will not be reached becauseis_espiwill return
+ * false for non-eSPI INTIDs.
I am still confused with this paragraph. How is this function can be reached if it is compiled out? Surely, if the DT is misconfigured, we should get an error when trying to route the interrupt. No? If so, can you point me to that code?
Cheers,
Signature · 1 line
aJulien Grall
Re: [PATCH v7 05/12] xen/arm: gicv3: implement handling of GICv3.1 eSPI
In reply to Leonid KomarianskyiHi Leonid,
Quoted 7 lines · Leonid Komarianskyi
xen/arch/arm/gic-v3.c +7
-0+#ifdef CONFIG_GICV3_ESPI +unsigned int gic_number_espis (void ) +{ +return gic_hw_ops->info->nr_espi; +} + +static void __init gicv3_dist_espi_common_init (uint32_t type)
xen/arch/arm/gic-v3.c static void gicv3_set_irq_priority(struct irq_desc *desc, · line 704
Quoted 10 lines
xen/arch/arm/gic-v3.c +10
-0+{ +unsigned int espi_nr, i; + + espi_nr =min (1024U ,GICD_TYPER_ESPIS_NUM (type)); + gicv3_info.nr_espi = espi_nr; +/* The GIC HW doesn't support eSPI, so we can leave from here */ +if ( gicv3_info.nr_espi ==0 ) +return ; + +printk ("GICv3: %d eSPI lines\n" , gicv3_info.nr_espi);
Style: nr_espi is unsigned. So it should be %u. Can be fixed on commit if there is nothing else major to change.
xen/arch/arm/gic-v3.c static void gicv3_set_irq_priority(struct irq_desc *desc, · line 716
Quoted 12 lines
xen/arch/arm/gic-v3.c +12
-0+ +/* The configuration for eSPIs is similar to that for regular SPIs */ +for ( i =0 ; i < espi_nr; i +=16 ) +writel_relaxed (0 ,GICD + GICD_ICFGRnE + (i /16 ) *4 ); + +for ( i =0 ; i < espi_nr; i +=4 ) +writel_relaxed (GIC_PRI_IRQ_ALL , +GICD + GICD_IPRIORITYRnE + (i /4 ) *4 ); + +for ( i =0 ; i < espi_nr; i +=32 ) + { +writel_relaxed (GENMASK (31 ,0 ),GICD + GICD_ICENABLERnE + (i /32 ) *4 );
Sorry I only spotted now.
The goal of gicv3_dist_espi_common_init() is to make sure the GIC is in a sane state for Xen (the previous OS or firmware may have left some state). Now the firmware may decide to use eSPI but not Xen (e.g. because CONFIG_ESPI=n).
This would means we may have eSPI interrupts that may be enabled and pending. So as soon as we re-enable the GIC we may receive interrupts we can't handle. So I think we may need to initialize the eSPI part of the distributor unconditionally. What do you think?
This could be handled as a follow-up but within the timeframe of Xen 4.21. So for this patch:
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v7 07/12] xen/arm: gicv3: modify ICH_LR_PHYSICAL_MASK to allow eSPI processing
In reply to Leonid KomarianskyiHi Leonid,
Quoted 8 lines · Leonid Komarianskyi
To properly deactivate physical eSPI routed to a domain and allow them to be retriggered after the initial trigger, the LR needs to be updated. The current implementation ignores interrupts outside the range specified by the mask
0x3FF, which only covers IRQ numbers up to 1023. To enable processing of eSPI interrupts, this patch updates the mask to0x1FFF.Signed-off-by Leonid Komarianskyi <[email protected]>Reviewed-by Volodymyr Babchuk <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v7 08/12] xen/arm: vgic: add resource management for extended SPIs
In reply to Leonid KomarianskyiHi Leonid,
Quoted 20 lines · Leonid Komarianskyi
This change introduces resource management in the VGIC to handle extended SPIs introduced in GICv3.1. The
pending_irqsandallocated_irqsarrays are resized to support the required number of eSPIs, based on what is supported by the hardware and requested by the guest. A new field,ext_shared_irqs, is added to the VGIC structure to store information about eSPIs, similar to howshared_irqsis used for regular SPIs.Since the eSPI range starts at INTID 4096 and INTIDs between 1025 and 4095 are reserved, helper macros are introduced to simplify the transformation of indices and to enable easier access to eSPI-specific resources. These changes prepare the VGIC for processing eSPIs as required by future functionality.
The initialization and deinitialization paths for vgic have been updated to allocate and free these resources appropriately. Additionally, updated handling of INTIDs greater than 1024, passed from the toolstack during domain creation, and verification logic ensures only valid SPI or eSPI INTIDs are used.
Quoted 6 lines
The existing SPI behavior remains unaffected when guests do not request eSPIs, GIC hardware does not support them, or the
CONFIG_GICV3_ESPIoption is disabled.Signed-off-by Leonid Komarianskyi <[email protected]>Reviewed-by Oleksandr Tyshchenko <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v7 09/12] xen/arm: domain_build/dom0less-build: adjust domains config to support eSPIs
In reply to Leonid KomarianskyiHi Leonid,
Quoted 15 lines · Leonid Komarianskyi
The Dom0 and DomUs logic for the dom0less configuration in
create_dom0()andarch_create_domUs()should account for extended SPIs when supported by the hardware and enabled withCONFIG_GICV3_ESPI. These changes ensure proper calculation of the maximum number of SPIs and eSPIs available to Dom0 and DomUs in dom0less setups.When eSPIs are supported by the hardware and
CONFIG_GICV3_ESPIis enabled, the maximum number of eSPI interrupts is calculated using theESPI_BASE_INTIDoffset (4096) and is limited to 1024, with 32 IRQs subtracted. To ensure compatibility with non-Dom0 domains, this adjustment is applied by the toolstack during domain creation, while for Dom0 or DomUs in Dom0, it is handled directly during VGIC initialization. If eSPIs are not supported, the calculation defaults to using the standard SPI range, with a maximum value of 992 interrupt lines, as it works currently.
Quoted 3 lines
Signed-off-by Leonid Komarianskyi <[email protected]>Reviewed-by Volodymyr Babchuk <[email protected]>Reviewed-by Oleksandr Tyshchenko <[email protected]>
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v7 10/12] xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers
In reply to Leonid KomarianskyiHi Leonid,
Quoted 17 lines · Leonid Komarianskyi
Implemented support for GICv3.1 extended SPI registers for vGICv3, allowing the emulation of eSPI-specific behavior for guest domains. The implementation includes read and write emulation for eSPI-related registers (e.g.,
GICD_ISENABLERnE,GICD_IROUTERnE, and others), following a similar approach to the handling of regular SPIs.The eSPI registers, previously located in reserved address ranges, are now adjusted to support MMIO read and write operations correctly when
CONFIG_GICV3_ESPIis enabled.The availability of eSPIs and the number of emulated extended SPIs for guest domains is reported by setting the appropriate bits in the
GICD_TYPERregister, based on the number of eSPIs requested by the domain and supported by the hardware. In cases where the configuration option is disabled, the hardware does not support eSPIs, or the domain does not request such interrupts, the functionality remains unchanged.
Quoted 2 lines
Signed-off-by Leonid Komarianskyi <[email protected]>Reviewed-by Oleksandr Tyshchenko <[email protected]>
This patch looks definitely better. Thanks for the rework!
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v7 04/12] xen/arm/irq: add handling for IRQs in the eSPI range
In reply to Julien GrallHi Julien,
Thank you for your comment.
Quoted 36 lines · Julien Grall
Hi Leonid,
Quoted 20 lines · Leonid Komarianskyi
xen/arch/arm/include/ renamed from xen/arch/arm/include/asm/irq.h +0
-0
asm/irq.h
index5bc6475eb4..2ff2d07d6d100644xen/arch/arm/include/asm/irq.h +4
-0@@ -32,6 +32,10 @@ struct arch_irq_desc { #define SPI_MAX_INTID 1019 #define LPI_OFFSET 8192 +#define ESPI_BASE_INTID 4096 +#define ESPI_MAX_INTID 5119 +#define NR_ESPI_IRQS 1024 + /* LPIs are always numbered starting at 8192, so 0 is a good invalidcase. */
#define INVALID_LPI 0xen/arch/arm/include/asm/irq.h +2
-0@@ -39,7 +43,12 @@ struct arch_irq_desc { #define INVALID_IRQ 1023 extern const unsigned int nr_irqs; +#ifdef CONFIG_GICV3_ESPI +/* This will cover the eSPI range, to allow asignmant of eSPIs to Quoted 1 line
domains. */
Typo: s/asignmant/assignment/
[...]
Quoted 6 lines
Unless INTIDs from the eSPI
+ * range are mistakenly defined in Xen DTS when the appropriate config is
+ * disabled, this function will not be reached becauseis_espiwill return
+ * false for non-eSPI INTIDs.
Quoted 7 lines
I am still confused with this paragraph. How is this function can be reached if it is compiled out? Surely, if the DT is misconfigured, we should get an error when trying to route the interrupt. No? If so, can you point me to that code?
Cheers,
Oh, sorry, the second part of the comment is redundant with the current implementation. It was correct when the function had an implementation and returned NULL. The correct comment is:
Defined as a prototype as it should not be called if CONFIG_GICV3_ESPI=n. Without CONFIG_GICV3_ESPI, the additional 1024 IRQ descriptors will not be defined, and thus, they cannot be used.
Should I prepare V8 with the comment fix, or can this be corrected on commit?
Best regards,
Leonid
Re: [PATCH v7 04/12] xen/arm/irq: add handling for IRQs in the eSPI range
Quoted 49 lines · Leonid Komarianskyi
Quoted 36 lines · Julien Grall
Hi Leonid,
Quoted 20 lines · Leonid Komarianskyi
xen/arch/arm/include/ renamed from xen/arch/arm/include/asm/irq.h +0
-0
asm/irq.h
index5bc6475eb4..2ff2d07d6d100644xen/arch/arm/include/asm/irq.h +4
-0@@ -32,6 +32,10 @@ struct arch_irq_desc { #define SPI_MAX_INTID 1019 #define LPI_OFFSET 8192 +#define ESPI_BASE_INTID 4096 +#define ESPI_MAX_INTID 5119 +#define NR_ESPI_IRQS 1024 + /* LPIs are always numbered starting at 8192, so 0 is a good invalidcase. */
#define INVALID_LPI 0xen/arch/arm/include/asm/irq.h +2
-0@@ -39,7 +43,12 @@ struct arch_irq_desc { #define INVALID_IRQ 1023 extern const unsigned int nr_irqs; +#ifdef CONFIG_GICV3_ESPI +/* This will cover the eSPI range, to allow asignmant of eSPIs to Quoted 1 line
domains. */
Typo: s/asignmant/assignment/
[...]
Quoted 6 lines
Unless INTIDs from the eSPI
+ * range are mistakenly defined in Xen DTS when the appropriate config is
+ * disabled, this function will not be reached becauseis_espiwill return
+ * false for non-eSPI INTIDs.Quoted 7 lines
I am still confused with this paragraph. How is this function can be reached if it is compiled out? Surely, if the DT is misconfigured, we should get an error when trying to route the interrupt. No? If so, can you point me to that code?
Cheers,
Oh, sorry, the second part of the comment is redundant with the current implementation. It was correct when the function had an implementation and returned NULL. The correct comment is:
Quoted 6 lines
Defined as a prototype as it should not be called if
CONFIG_GICV3_ESPI=n. WithoutCONFIG_GICV3_ESPI, the additional 1024 IRQ descriptors will not be defined, and thus, they cannot be used.Should I prepare V8 with the comment fix, or can this be corrected on commit?
I should be able to update it while committing.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v7 05/12] xen/arm: gicv3: implement handling of GICv3.1 eSPI
In reply to Julien GrallHi Julien,
Thank you for your comments and AB.
Quoted 52 lines · Julien Grall
Hi Leonid,
Quoted 7 lines · Leonid Komarianskyi
xen/arch/arm/gic-v3.c +7
-0+#ifdef CONFIG_GICV3_ESPI +unsigned int gic_number_espis (void ) +{ + return gic_hw_ops->info->nr_espi; +} + +static void __init gicv3_dist_espi_common_init (uint32_t type)xen/arch/arm/gic-v3.c static void gicv3_set_irq_priority(struct irq_desc *desc, · line 704
Quoted 10 lines
xen/arch/arm/gic-v3.c +10
-0+{ + unsigned int espi_nr, i; + + espi_nr = min(1024U, GICD_TYPER_ESPIS_NUM(type)); + gicv3_info.nr_espi = espi_nr; + /* The GIC HW doesn't support eSPI, so we can leave from here */ + if ( gicv3_info.nr_espi == 0 ) + return; + + printk("GICv3: %d eSPI lines\n", gicv3_info.nr_espi);Style:
nr_espiis unsigned. So it should be %u. Can be fixed on commit if there is nothing else major to change.Quoted 13 lines
+
+ /* The configuration for eSPIs is similar to that for regular SPIs */
+ for ( i = 0; i <espi_nr; i += 16 )
+writel_relaxed(0, GICD + GICD_ICFGRnE + (i / 16) * 4);xen/arch/arm/gic-v3.c +8
-0+ + for ( i = 0; i < espi_nr; i += 4 ) + writel_relaxed(GIC_PRI_IRQ_ALL, + GICD + GICD_IPRIORITYRnE + (i / 4) * 4); + + for ( i = 0; i < espi_nr; i += 32 ) + { + writel_relaxed(GENMASK(31, 0), GICD + GICD_ICENABLERnE + (i /Quoted 1 line
32) * 4);
Sorry I only spotted now.
The goal of
gicv3_dist_espi_common_init()is to make sure the GIC is in a sane state for Xen (the previous OS or firmware may have left some state). Now the firmware may decide to use eSPI but not Xen (e.g. becauseCONFIG_ESPI=n).This would means we may have eSPI interrupts that may be enabled and pending. So as soon as we re-enable the GIC we may receive interrupts we can't handle. So I think we may need to initialize the eSPI part of the distributor unconditionally. What do you think?
Quoted 7 lines
This could be handled as a follow-up but within the timeframe of Xen 4.21. So for this patch:
Acked-by Julien Grall <[email protected]>Cheers,
Yes, that's a really good point about firmware initialization - I did not think about that. In that case, we just need to move the nr_espi field out of the ifdef, remove the stubs for gicv3_dist_espi_common_init() and gicv3_dist_espi_init_aff(), and remove the ifdef for these functions. The verifications at the beginning of gicv3_dist_espi_common_init() should work correctly, simply returning 0 on platforms without eSPI.
I will prepare a follow-up patch for this.
Best regards,
Leonid
Re: [PATCH v7 05/12] xen/arm: gicv3: implement handling of GICv3.1 eSPI
Hi Leonid,
Quoted 61 lines · Leonid Komarianskyi
Quoted 52 lines · Julien Grall
Hi Leonid,
Quoted 7 lines · Leonid Komarianskyi
xen/arch/arm/gic-v3.c +7
-0+#ifdef CONFIG_GICV3_ESPI +unsigned int gic_number_espis (void ) +{ + return gic_hw_ops->info->nr_espi; +} + +static void __init gicv3_dist_espi_common_init (uint32_t type)xen/arch/arm/gic-v3.c static void gicv3_set_irq_priority(struct irq_desc *desc, · line 704
Quoted 10 lines
xen/arch/arm/gic-v3.c +10
-0+{ + unsigned int espi_nr, i; + + espi_nr = min(1024U, GICD_TYPER_ESPIS_NUM(type)); + gicv3_info.nr_espi = espi_nr; + /* The GIC HW doesn't support eSPI, so we can leave from here */ + if ( gicv3_info.nr_espi == 0 ) + return; + + printk("GICv3: %d eSPI lines\n", gicv3_info.nr_espi);Style:
nr_espiis unsigned. So it should be %u. Can be fixed on commit if there is nothing else major to change.Quoted 13 lines
+
+ /* The configuration for eSPIs is similar to that for regular SPIs */
+ for ( i = 0; i <espi_nr; i += 16 )
+writel_relaxed(0, GICD + GICD_ICFGRnE + (i / 16) * 4);xen/arch/arm/gic-v3.c +8
-0+ + for ( i = 0; i < espi_nr; i += 4 ) + writel_relaxed(GIC_PRI_IRQ_ALL, + GICD + GICD_IPRIORITYRnE + (i / 4) * 4); + + for ( i = 0; i < espi_nr; i += 32 ) + { + writel_relaxed(GENMASK(31, 0), GICD + GICD_ICENABLERnE + (i /Quoted 1 line
32) * 4);
Sorry I only spotted now.
The goal of
gicv3_dist_espi_common_init()is to make sure the GIC is in a sane state for Xen (the previous OS or firmware may have left some state). Now the firmware may decide to use eSPI but not Xen (e.g. becauseCONFIG_ESPI=n).This would means we may have eSPI interrupts that may be enabled and pending. So as soon as we re-enable the GIC we may receive interrupts we can't handle. So I think we may need to initialize the eSPI part of the distributor unconditionally. What do you think?
Quoted 7 lines
This could be handled as a follow-up but within the timeframe of Xen 4.21. So for this patch:
Acked-by Julien Grall <[email protected]>Cheers,
Quoted 7 lines
Yes, that's a really good point about firmware initialization - I did not think about that. In that case, we just need to move the
nr_espifield out of the ifdef, remove the stubs forgicv3_dist_espi_common_init()andgicv3_dist_espi_init_aff(), and remove the ifdef for these functions. The verifications at the beginning ofgicv3_dist_espi_common_init()should work correctly, simply returning 0 on platforms without eSPI.
I don't think we need all of these. We just need to ensure the interrupts are disabled and deactivated. So no need to reset the affinity or even moving the field moving the field out of the ifdef.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v7 04/12] xen/arm/irq: add handling for IRQs in the eSPI range
In reply to Leonid KomarianskyiOn 04.09.25 23:01, Leonid Komarianskyi wrote:
Hello Leonid
Quoted 11 lines
Currently, Xen does not support eSPI interrupts, leading to a data abort when such interrupts are defined in the DTS.
This patch introduces a separate array to initialize up to 1024 interrupt descriptors in the eSPI range and adds the necessary defines and helper function. These changes lay the groundwork for future implementation of full eSPI interrupt support. As this GICv3.1 feature is not required by all vendors, all changes are guarded by ifdefs, depending on the corresponding
Kconfigoption.
Quoted 1 line
Signed-off-by Leonid Komarianskyi <[email protected]>
Initially I was slightly worried about ...
Quoted 118 lines
---
Changes in V7:
- fixed the condition in theis_espiassert for non-eSPI builds: the previous condition was mistakenly added with a wrong check and led to triggering asserts for all non-eSPI INTIDs, when it should be triggered in this case in the other way around
- minor: usedis_espi()in theespi_intid_to_idx()ASSERT, asis_espiperforms the same verificationChanges in V6:
- added an assert inis_espi()whenCONFIG_GICV3_ESPI=nto ensure that out-of-range array resources are not accessed, e.g., in__irq_to_desc()
- removed unnecessary parentheses inis_espi()
- converted helper macro to inline functions and added sanity checks with ASSERTs to them
- definedespi_to_descfor non-eSPI builds as a prototype
- updates the comments
- used theIS_ENABLED(CONFIG_GICV3_ESPI)macro to initializenr_irqsChanges in V5:
- no functional changes introduced by this version compared with V4, only minor fixes and removal of ifdefs for macroses
- added TODO comment, suggested by Oleksandr Tyshchenko
- changed int to unsigned int for irqs
- removed ifdefs for eSPI-specific defines and macros to reduce the number of ifdefs and code duplication in further changes
- removed reviewed-by as moving defines from ifdefs requires additional confirmation from reviewersChanges in V4:
- removed redundant line with 'default n' inKconfig, as it is disabled by default, without explicit specification
- added reviewed-by from Volodymyr BabchukChanges in V3:
- introduced a new defineNR_ESPI_IRQSto avoid confusion, like in the case of usingNR_IRQSforespi_descarray
- implemented helper functionsespi_to_descandinit_espi_datato make it possible to add stubs with the same name, and as a result, reduce the number of #ifdefs
- disableCONFIG_GICV3_ESPIdefault value to nChanges in V2:
- use (ESPI_MAX_INTID+ 1) instead of (ESPI_BASE_INTID+NR_IRQS)
- remove unnecessary comment fornr_irqsinitialization--- xen/arch/arm/Kconfig | 8 +++++ xen/arch/arm/include/asm/irq.h | 37 ++++++++++++++++++++++++ xen/arch/arm/irq.c | 53 ++++++++++++++++++++++++++++++++-- 3 files changed, 96 insertions(+), 2 deletions(-)xen/arch/arm/Kconfig +8
-0@@ -135,6 +135,14 @@ config GICV3 Driver for the ARM Generic Interrupt Controller v3. If unsure, use the default setting. +config GICV3_ESPI + bool "Extended SPI range support" + depends on GICV3 && !NEW_VGIC + help + Allow Xen and domains to use interrupt numbers from the extended SPI + range, from 4096 to 5119. This feature is introduced in GICv3.1 + architecture. + config HAS_ITS bool "GICv3 ITS MSI controller support (UNSUPPORTED)" if UNSUPPORTED depends on GICV3 && !NEW_VGIC && !ARM_32xen/arch/arm/include/asm/irq.h +24
-0@@ -32,6 +32,10 @@ struct arch_irq_desc {#define SPI_MAX_INTID 1019#define LPI_OFFSET 8192 +#define ESPI_BASE_INTID 4096 +#define ESPI_MAX_INTID 5119 +#define NR_ESPI_IRQS 1024 +/* LPIs are always numbered starting at 8192, so 0 is a good invalid case. */ #define INVALID_LPI 0@@ -39,7 +43,12 @@ struct arch_irq_desc {#define INVALID_IRQ 1023extern const unsigned int nr_irqs; +#ifdef CONFIG_GICV3_ESPI +/* This will cover the eSPI range, to allow asignmant of eSPIs to domains. */ +#define nr_static_irqs (ESPI_MAX_INTID + 1) +#else #define nr_static_irqs NR_IRQS +#endif struct irq_desc ;struct irqaction ;@@ -55,6 +64,34 @@ static inline bool is_lpi(unsigned int irq)return irq >=LPI_OFFSET ; } +static inline bool is_espi (unsigned int irq) +{ +#ifdef CONFIG_GICV3_ESPI +return irq >=ESPI_BASE_INTID && irq <=ESPI_MAX_INTID ; +#else +/* +* The function should not be called for eSPIs when CONFIG_GICV3_ESPI is +* disabled. Returning false allows the compiler to optimize the code +* when the config is disabled, while the assert ensures that out-of-range +* array resources are not accessed, e.g., in __irq_to_desc(). +*/ +ASSERT (!(irq >=ESPI_BASE_INTID && irq <=ESPI_MAX_INTID )); +return false; +#endif +}
xen/arch/arm/include/asm/irq.h static inline bool is_lpi(unsigned int irq) · line 91
Quoted 10 lines
xen/arch/arm/include/asm/irq.h +10
-0+ +static inline unsigned int espi_intid_to_idx (unsigned int intid) +{ +ASSERT (is_espi (intid)); +return intid -ESPI_BASE_INTID ; +} + +static inline unsigned int espi_idx_to_intid (unsigned int idx) +{ +ASSERT (idx <=NR_ESPI_IRQS );
... this assert.
The system defines that there are only 1024 (NR_ESPI_IRQS) eSPIs, which map to indices 0 through 1023. An idx of 1024 is an invalid eSPI index. The assert would allow idx = 1024 to pass, and the helper would then return an invalid interrupt ID of 5120 (1024 + 4096). But, as I understand, you chose "<=" instead of "<" to be able to also pass NR_ESPI_IRQS/gic_number_espis() to calculate a "one-past-the-end" interrupt ID, which can then be used as an exclusive upper bound for range checks in the code.
By looking at how it is used within the series, I did not notice obvious issues.
Quoted 91 lines
xen/arch/arm/include/asm/irq.h +3
-0+return idx +ESPI_BASE_INTID ; +} +#define domain_pirq_to_irq (d, pirq) (pirq)bool is_assignable_irq (unsigned int irq);xen/arch/arm/irq.c +51
-2@@ -19,7 +19,9 @@#include <asm/gic.h> #include <asm/vgic.h> -const unsigned int nr_irqs =NR_IRQS ; +const unsigned int nr_irqs =IS_ENABLED (CONFIG_GICV3_ESPI ) ? + (ESPI_MAX_INTID +1 ) : +NR_IRQS ;static unsigned int local_irqs_type[NR_LOCAL_IRQS ];static DEFINE_SPINLOCK (local_irqs_type_lock);@@ -46,6 +48,50 @@ void irq_end_none(struct irq_desc *irq) }static irq_desc_t irq_desc[NR_IRQS -NR_LOCAL_IRQS ]; +#ifdef CONFIG_GICV3_ESPI +/* TODO: Consider allocating an array dynamically */ +static irq_desc_t espi_desc[NR_ESPI_IRQS ]; + +static struct irq_desc *espi_to_desc (unsigned int irq) +{ +return &espi_desc[espi_intid_to_idx (irq)]; +} + +static int __init init_espi_data (void ) +{ +unsigned int irq; + +for ( irq =ESPI_BASE_INTID ; irq <=ESPI_MAX_INTID ; irq++ ) + { +struct irq_desc *desc =irq_to_desc (irq); +int rc =init_one_irq_desc (desc); + +if ( rc ) +return rc; + + desc->irq = irq; + desc->action =NULL ; + } + +return 0 ; +} +#else +/* +* Defined as a prototype as it should not be called if CONFIG_GICV3_ESPI=n. +* Without CONFIG_GICV3_ESPI, the additional 1024 IRQ descriptors will not +* be defined, and thus, they cannot be used. Unless INTIDs from the eSPI +* range are mistakenly defined in Xen DTS when the appropriate config is +* disabled, this function will not be reached because is_espi will return +* false for non-eSPI INTIDs. +*/ +struct irq_desc *espi_to_desc (unsigned int irq); + +static int __init init_espi_data (void ) +{ +return 0 ; +} +#endif + static DEFINE_PER_CPU(irq_desc_t[NR_LOCAL_IRQS], local_irq_desc);struct irq_desc *__irq_to_desc (unsigned int irq)@@ -53,6 +99,9 @@ struct irq_desc *__irq_to_desc(unsigned int irq)if ( irq <NR_LOCAL_IRQS )return &this_cpu (local_irq_desc)[irq]; +if (is_espi (irq) ) +return espi_to_desc (irq); +return &irq_desc[irq-NR_LOCAL_IRQS ]; }@@ -79,7 +128,7 @@ static int __init init_irq_data(void) desc->action =NULL ; } -return 0 ; +return init_espi_data (); }static int init_local_irq_data (unsigned int cpu)
Hi Leonid,
I was about to commit this but unfortunately it is introducing MISRA regressions. See:
https://gitlab.com/xen-project/people/sstabellini/xen/-/tree/ppp6?ref_type=heads
https://gitlab.com/xen-project/people/sstabellini/xen/-/jobs/11265005118
Against upstream staging:
https://eclair-analysis-logs.xenproject.org/fs/space/XEN.ecdf/xen-project/hardware/xen/ECLAIR_normal/staging/ARM64/11264772605/PROJECT.ecd;/by_service.html#service&kind
It is introducing a couple of easy-to-fix 16.3 issues and also a couple of new 16.4 issues. They should be all easy to fix. It is also introducing three new 13.2 issues and one 18.1 but I haven't looked closely into those. Please address them.
Oleksii,
Technically, the series is fully acked and ready to be committed. From a risk perspective, I would be comfortable committing it now with the outstanding MISRA regressions, leaving Leonid to fix them over the next few days. However, I have not done so because it would make it harder to spot the MISRA regressions due to the way the scanner works (it compares against the previous version).
I suggest we allow this series to be committed in the next couple of days, once Leonid addresses the regressions, even though it would technically be past the feature freeze.
Cheers,
Stefano
P.S.
Leonid, you might want to check my commits because I fixed a couple of things on commit, in addition to adding the various acked-by tags.
Quoted 122 lines · Leonid Komarianskyi
Hello everyone!
V6 contains an issue for debug builds with
CONFIG_GICV3_ESPI=ndue to a mistake in theASSERT()condition in theis_espi()function. This patch series fixes the issue and also includes minor fixes according to the review of V6.Summarized description:
This patch series adds support for the extended shared peripheral interrupt (eSPI) range (INTIDs 4096-5119 [2](ranges of INTIDs)) for Xen and guest domains. The implementation uses a generic approach to handle eSPIs, similar to regular SPIs, while maintaining compatibility with the existing SPI range. Functionality remains unchanged for setups that do not require eSPIs.The series includes:
1) General refactoring of common IRQ operations with GIC registers to improve code readability, simplify further maintenance and prepare the key functions for eSPI implementation.
2) Introducing a newKconfigoption (default n) to enable or disable eSPI support. Disabling this option prevents unnecessary resource allocation for setups that do not require eSPIs.
3) Adding additional resources to store required information and operate with up to 1024 interrupts from eSPI range.
4) Adjusting assertions and checks to pass verification for INTIDs in the eSPI range.
5) Configuration of eSPI-specific registers during GIC initialization for systems with GICv3.1+ hardware.
6) Enables eSPI MMIO emulation for vGIC, allowing guest domains to access and operate within the eSPI's INTIDs.
7) Updating documentation and CHANGELOG to reflect the changes made for eSPI support.Also, to simplify reviewing, please find below link to unsquashed patches, that are on top of every patch, that is changed in the series, compared to V6:
https://github.com/LKomaryanskiy/xen/commits/espi-support-master-upstream-v7-unsquashed/Github branch with patch series:
https://github.com/LKomaryanskiy/xen/commits/espi-support-master-upstream-v7/Changes in V7:
- individual changes in patchesLink on V6:
- https://lists.xenproject.org/archives/html/xen-devel/2025-09/msg00296.htmlChanges in V6:
- individual changes in patchesLink on V5:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg02086.htmlChanges in V5:
- individual changes in patchesLink on V4:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg01767.htmlChanges in V4:
- added a patch for documentation
- individual changes in patchesLink on V3:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg01628.htmlChanges in V3:
- added a patch to update CHANGELOG.md
- individual changes in patchesLink on V2:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg00372.htmlChanges in V2:
- added 2 more patches to implement helper
functions for gic/vgic:
xen/arm: gic: implement helper functions for INTID checks xen/arm: vgic: implement helper functions for virq checks
- removed 2 patches:
xen/arm/irq: allow assignment/releasing of eSPI interrupts xen/arm: gic/irq: permit routing of eSPI interrupts to Xen and domains since their functionality can be moved to appropriate patches after introducing patches with helper functions
- individual changes in patchesLink on V1:
- https://lists.xenproject.org/archives/html/xen-devel/2025-07/msg01809.htmlLeonid Komarianskyi (12):
xen/arm: gicv3: refactor obtaining GIC addresses for common operations xen/arm: gic: implement helper functions for INTID checks xen/arm: vgic: implement helper functions for virq checks xen/arm/irq: add handling for IRQs in the eSPI range xen/arm: gicv3: implement handling of GICv3.1 eSPI xen/arm/irq: allow eSPI processing in thegic_interruptfunction xen/arm: gicv3: modifyICH_LR_PHYSICAL_MASKto allow eSPI processing xen/arm: vgic: add resource management for extended SPIs xen/arm: domain_build/dom0less-build: adjust domains config to support
eSPIs
xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers doc/man: update description fornr_spiswith eSPI CHANGELOG.md: add mention of GICv3.1 eSPI supportCHANGELOG.md | 2 + docs/man/xl.cfg.5.pod.in | 13 +- xen/arch/arm/Kconfig | 8 + xen/arch/arm/dom0less-build.c | 2 +- xen/arch/arm/domain_build.c | 2 +- xen/arch/arm/gic-v3.c | 195 +++++++++++++++++++---- xen/arch/arm/gic.c | 8 +- xen/arch/arm/include/asm/gic.h | 28 ++++ xen/arch/arm/include/asm/gic_v3_defs.h | 40 ++++- xen/arch/arm/include/asm/irq.h | 38 +++++ xen/arch/arm/include/asm/vgic.h | 56 ++++++- xen/arch/arm/irq.c | 62 +++++++- xen/arch/arm/vgic-v3.c | 203 ++++++++++++++++++----- xen/arch/arm/vgic.c | 212 +++++++++++++++++++++++-- xen/arch/arm/vgic/vgic.c | 5 + 15 files changed, 762 insertions(+), 112 deletions(-)Signature · 1 line
2.34.1
Hello Stefano,
Thank you for your comments and for providing the Eclair reports.
Quoted 11 lines · Stefano Stabellini
Hi Leonid,
I was about to commit this but unfortunately it is introducing MISRA regressions. See:
https://gitlab.com/xen-project/people/sstabellini/xen/-/tree/ppp6?ref_type=headshttps://gitlab.com/xen-project/people/sstabellini/xen/-/jobs/11265005118
Quoted 8 lines
Against upstream staging:
https://eclair-analysis-logs.xenproject.org/fs/space/XEN.ecdf/xen-project/hardware/xen/ECLAIR_normal/staging/ARM64/11264772605/PROJECT.ecd;/by_service.html#service&kindIt is introducing a couple of easy-to-fix 16.3 issues and also a couple of new 16.4 issues. They should be all easy to fix. It is also introducing three new 13.2 issues and one 18.1 but I haven't looked closely into those. Please address them.
Regarding the MISRA 16.3/16.4 violations and 13.2 cautions - there are no questions from my side. I have fixed them and will send the updated V8 (with typo fixes, added acked/reviewed-by tags, etc.). However, I would like to clarify regarding the MISRA 18.1 caution regression and review process rules:
MISRA 18.1 caution:
xen/arch/arm/irq.c:105.13-105.39: [8] access of 'irq_desc' at an overflowing index, while it holds only 992 'struct irq_desc' elements
Actually, there is no new real issue here, because the mainline irq_desc() currently does not have upper limit checks for IRQs:
struct irq_desc *__irq_to_desc(unsigned int irq)
{
if ( irq < NR_LOCAL_IRQS )
return &this_cpu(local_irq_desc)[irq];
return &irq_desc[irq-NR_LOCAL_IRQS];
}... as a result Eclair does not spot any issues in this code according to the staging report. As I understand, it triggers on patches with eSPI because I introduced new checks for the eSPI INTID range, which should not be used without CONFIG_GICV3_ESPI=y.
Also, a similar issue with invalid INTIDs was discussed in the thread:
https://lists.xenproject.org/archives/html/xen-devel/2025-09/msg00401.html
Long story short: the mainline Xen currently allows defining invalid INTIDs in the Xen DTS and crashes in __irq_to_desc() when attempting to operate on an invalid interrupt number.
I have prepared a fix for the 18.1 caution, but I am not sure whether it is worth applying just to address the Eclair report (if it is not critical):
https://github.com/LKomaryanskiy/xen/commit/af5d9a483302f7bcfaadbefb85f5e4ee35f6cb3b
So, could you please clarify which option would be better:
1) Leave the code as it is for now, accepting the MISRA caution from Eclair and fix the issue later in the context of addressing Xen crashing with invalid INTIDs and implementing dynamic allocation of irq_desc_t array;
2) Apply the fix now (while also planning to address the invalid INTID issue in the future)
Regarding the review process:
Should I remove the 'reviewed-by' tags from the patches where I added missing breaks (with the corresponding code updates) or introduced variables to fix MISRA issues? I am asking because these are code changes, and I am not sure if I should leave the RB tags in this case.
Quoted 18 lines
Oleksii,
Technically, the series is fully acked and ready to be committed. From a risk perspective, I would be comfortable committing it now with the outstanding MISRA regressions, leaving Leonid to fix them over the next few days. However, I have not done so because it would make it harder to spot the MISRA regressions due to the way the scanner works (it compares against the previous version).
I suggest we allow this series to be committed in the next couple of days, once Leonid addresses the regressions, even though it would technically be past the feature freeze.
Cheers,
Stefano
Quoted 129 lines
P.S.Leonid, you might want to check my commits because I fixed a couple of things on commit, in addition to adding the various acked-by tags.
Quoted 122 lines · Leonid Komarianskyi
Hello everyone!
V6 contains an issue for debug builds with
CONFIG_GICV3_ESPI=ndue to a mistake in theASSERT()condition in theis_espi()function. This patch series fixes the issue and also includes minor fixes according to the review of V6.Summarized description:
This patch series adds support for the extended shared peripheral interrupt (eSPI) range (INTIDs 4096-5119 [2](ranges of INTIDs)) for Xen and guest domains. The implementation uses a generic approach to handle eSPIs, similar to regular SPIs, while maintaining compatibility with the existing SPI range. Functionality remains unchanged for setups that do not require eSPIs.The series includes:
1) General refactoring of common IRQ operations with GIC registers to improve code readability, simplify further maintenance and prepare the key functions for eSPI implementation.
2) Introducing a newKconfigoption (default n) to enable or disable eSPI support. Disabling this option prevents unnecessary resource allocation for setups that do not require eSPIs.
3) Adding additional resources to store required information and operate with up to 1024 interrupts from eSPI range.
4) Adjusting assertions and checks to pass verification for INTIDs in the eSPI range.
5) Configuration of eSPI-specific registers during GIC initialization for systems with GICv3.1+ hardware.
6) Enables eSPI MMIO emulation for vGIC, allowing guest domains to access and operate within the eSPI's INTIDs.
7) Updating documentation and CHANGELOG to reflect the changes made for eSPI support.Also, to simplify reviewing, please find below link to unsquashed patches, that are on top of every patch, that is changed in the series, compared to V6:
https://github.com/LKomaryanskiy/xen/commits/espi-support-master-upstream-v7-unsquashed/Github branch with patch series:
https://github.com/LKomaryanskiy/xen/commits/espi-support-master-upstream-v7/Changes in V7:
- individual changes in patchesLink on V6:
- https://lists.xenproject.org/archives/html/xen-devel/2025-09/msg00296.htmlChanges in V6:
- individual changes in patchesLink on V5:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg02086.htmlChanges in V5:
- individual changes in patchesLink on V4:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg01767.htmlChanges in V4:
- added a patch for documentation
- individual changes in patchesLink on V3:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg01628.htmlChanges in V3:
- added a patch to update CHANGELOG.md
- individual changes in patchesLink on V2:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg00372.htmlChanges in V2:
- added 2 more patches to implement helper
functions for gic/vgic:
xen/arm: gic: implement helper functions for INTID checks xen/arm: vgic: implement helper functions for virq checks
- removed 2 patches:
xen/arm/irq: allow assignment/releasing of eSPI interrupts xen/arm: gic/irq: permit routing of eSPI interrupts to Xen and domains since their functionality can be moved to appropriate patches after introducing patches with helper functions
- individual changes in patchesLink on V1:
- https://lists.xenproject.org/archives/html/xen-devel/2025-07/msg01809.htmlLeonid Komarianskyi (12):
xen/arm: gicv3: refactor obtaining GIC addresses for common operations xen/arm: gic: implement helper functions for INTID checks xen/arm: vgic: implement helper functions for virq checks xen/arm/irq: add handling for IRQs in the eSPI range xen/arm: gicv3: implement handling of GICv3.1 eSPI xen/arm/irq: allow eSPI processing in thegic_interruptfunction xen/arm: gicv3: modifyICH_LR_PHYSICAL_MASKto allow eSPI processing xen/arm: vgic: add resource management for extended SPIs xen/arm: domain_build/dom0less-build: adjust domains config to support
eSPIs
xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers doc/man: update description fornr_spiswith eSPI CHANGELOG.md: add mention of GICv3.1 eSPI supportCHANGELOG.md | 2 + docs/man/xl.cfg.5.pod.in | 13 +- xen/arch/arm/Kconfig | 8 + xen/arch/arm/dom0less-build.c | 2 +- xen/arch/arm/domain_build.c | 2 +- xen/arch/arm/gic-v3.c | 195 +++++++++++++++++++---- xen/arch/arm/gic.c | 8 +- xen/arch/arm/include/asm/gic.h | 28 ++++ xen/arch/arm/include/asm/gic_v3_defs.h | 40 ++++- xen/arch/arm/include/asm/irq.h | 38 +++++ xen/arch/arm/include/asm/vgic.h | 56 ++++++- xen/arch/arm/irq.c | 62 +++++++- xen/arch/arm/vgic-v3.c | 203 ++++++++++++++++++----- xen/arch/arm/vgic.c | 212 +++++++++++++++++++++++-- xen/arch/arm/vgic/vgic.c | 5 + 15 files changed, 762 insertions(+), 112 deletions(-)--
2.34.1
Best regards,
Leonid
Quoted 29 lines · Stefano Stabellini
Hi Leonid,
I was about to commit this but unfortunately it is introducing MISRA regressions. See:
https://gitlab.com/xen-project/people/sstabellini/xen/-/tree/ppp6?ref_type=headshttps://gitlab.com/xen-project/people/sstabellini/xen/-/jobs/11265005118
Against upstream staging:
https://eclair-analysis-logs.xenproject.org/fs/space/XEN.ecdf/xen-project/hardware/xen/ECLAIR_normal/staging/ARM64/11264772605/PROJECT.ecd;/by_service.html#service&kindIt is introducing a couple of easy-to-fix 16.3 issues and also a couple of new 16.4 issues. They should be all easy to fix. It is also introducing three new 13.2 issues and one 18.1 but I haven't looked closely into those. Please address them.
Oleksii,
Technically, the series is fully acked and ready to be committed. From a risk perspective, I would be comfortable committing it now with the outstanding MISRA regressions, leaving Leonid to fix them over the next few days. However, I have not done so because it would make it harder to spot the MISRA regressions due to the way the scanner works (it compares against the previous version).
Quoted 3 lines
I suggest we allow this series to be committed in the next couple of days, once Leonid addresses the regressions, even though it would technically be past the feature freeze.
If there is no any strong objects, it sounds good to me to give couple of days to fix the regressions and then commit this patch series.
~ Oleksii
Quoted 134 lines
Cheers,
Stefano
P.S.Leonid, you might want to check my commits because I fixed a couple of things on commit, in addition to adding the various acked-by tags.
Quoted 122 lines · Leonid Komarianskyi
Hello everyone!
V6 contains an issue for debug builds with
CONFIG_GICV3_ESPI=ndue to a mistake in theASSERT()condition in theis_espi()function. This patch series fixes the issue and also includes minor fixes according to the review of V6.Summarized description:
This patch series adds support for the extended shared peripheral interrupt (eSPI) range (INTIDs 4096-5119 [2](ranges of INTIDs)) for Xen and guest domains. The implementation uses a generic approach to handle eSPIs, similar to regular SPIs, while maintaining compatibility with the existing SPI range. Functionality remains unchanged for setups that do not require eSPIs.The series includes:
1) General refactoring of common IRQ operations with GIC registers to improve code readability, simplify further maintenance and prepare the key functions for eSPI implementation.
2) Introducing a newKconfigoption (default n) to enable or disable eSPI support. Disabling this option prevents unnecessary resource allocation for setups that do not require eSPIs.
3) Adding additional resources to store required information and operate with up to 1024 interrupts from eSPI range.
4) Adjusting assertions and checks to pass verification for INTIDs in the eSPI range.
5) Configuration of eSPI-specific registers during GIC initialization for systems with GICv3.1+ hardware.
6) Enables eSPI MMIO emulation for vGIC, allowing guest domains to access and operate within the eSPI's INTIDs.
7) Updating documentation and CHANGELOG to reflect the changes made for eSPI support.Also, to simplify reviewing, please find below link to unsquashed patches, that are on top of every patch, that is changed in the series, compared to V6:
https://github.com/LKomaryanskiy/xen/commits/espi-support-master-upstream-v7-unsquashed/Github branch with patch series:
https://github.com/LKomaryanskiy/xen/commits/espi-support-master-upstream-v7/Changes in V7:
- individual changes in patchesLink on V6:
-https://lists.xenproject.org/archives/html/xen-devel/2025-09/msg00296.htmlChanges in V6:
- individual changes in patchesLink on V5:
-https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg02086.htmlChanges in V5:
- individual changes in patchesLink on V4:
-https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg01767.htmlChanges in V4:
- added a patch for documentation
- individual changes in patchesLink on V3:
-https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg01628.htmlChanges in V3:
- added a patch to update CHANGELOG.md
- individual changes in patchesLink on V2:
-https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg00372.htmlChanges in V2:
- added 2 more patches to implement helper
functions for gic/vgic:
xen/arm: gic: implement helper functions for INTID checks xen/arm: vgic: implement helper functions for virq checks
- removed 2 patches:
xen/arm/irq: allow assignment/releasing of eSPI interrupts xen/arm: gic/irq: permit routing of eSPI interrupts to Xen and domains since their functionality can be moved to appropriate patches after introducing patches with helper functions
- individual changes in patchesLink on V1:
-https://lists.xenproject.org/archives/html/xen-devel/2025-07/msg01809.htmlLeonid Komarianskyi (12):
xen/arm: gicv3: refactor obtaining GIC addresses for common operations xen/arm: gic: implement helper functions for INTID checks xen/arm: vgic: implement helper functions for virq checks xen/arm/irq: add handling for IRQs in the eSPI range xen/arm: gicv3: implement handling of GICv3.1 eSPI xen/arm/irq: allow eSPI processing in thegic_interruptfunction xen/arm: gicv3: modifyICH_LR_PHYSICAL_MASKto allow eSPI processing xen/arm: vgic: add resource management for extended SPIs xen/arm: domain_build/dom0less-build: adjust domains config to support
eSPIs
xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers doc/man: update description fornr_spiswith eSPI CHANGELOG.md: add mention of GICv3.1 eSPI supportCHANGELOG.md | 2 + docs/man/xl.cfg.5.pod.in | 13 +- xen/arch/arm/Kconfig | 8 + xen/arch/arm/dom0less-build.c | 2 +- xen/arch/arm/domain_build.c | 2 +- xen/arch/arm/gic-v3.c | 195 +++++++++++++++++++---- xen/arch/arm/gic.c | 8 +- xen/arch/arm/include/asm/gic.h | 28 ++++ xen/arch/arm/include/asm/gic_v3_defs.h | 40 ++++- xen/arch/arm/include/asm/irq.h | 38 +++++ xen/arch/arm/include/asm/vgic.h | 56 ++++++- xen/arch/arm/irq.c | 62 +++++++- xen/arch/arm/vgic-v3.c | 203 ++++++++++++++++++----- xen/arch/arm/vgic.c | 212 +++++++++++++++++++++++-- xen/arch/arm/vgic/vgic.c | 5 + 15 files changed, 762 insertions(+), 112 deletions(-)Signature · 1 line
2.34.1
Quoted 25 lines · Leonid Komarianskyi
Hello Stefano,
Thank you for your comments and for providing the Eclair reports.
Quoted 11 lines · Stefano Stabellini
Hi Leonid,
I was about to commit this but unfortunately it is introducing MISRA regressions. See:
https://gitlab.com/xen-project/people/sstabellini/xen/-/tree/ppp6?ref_type=headshttps://gitlab.com/xen-project/people/sstabellini/xen/-/jobs/11265005118
Quoted 8 lines
Against upstream staging:
https://eclair-analysis-logs.xenproject.org/fs/space/XEN.ecdf/xen-project/hardware/xen/ECLAIR_normal/staging/ARM64/11264772605/PROJECT.ecd;/by_service.html#service&kindIt is introducing a couple of easy-to-fix 16.3 issues and also a couple of new 16.4 issues. They should be all easy to fix. It is also introducing three new 13.2 issues and one 18.1 but I haven't looked closely into those. Please address them.
Quoted 3 lines
Regarding the MISRA 16.3/16.4 violations and 13.2 cautions - there are no questions from my side. I have fixed them and will send the updated V8 (with typo fixes, added acked/reviewed-by tags, etc.).
Thanks!
Quoted 37 lines
However, I
would like to clarify regarding the MISRA 18.1 caution regression and review process rules:MISRA 18.1 caution:
xen/arch/arm/irq.c:105.13-105.39: [8] access of '
irq_desc' at an overflowing index, while it holds only 992 'structirq_desc' elementsActually, there is no new real issue here, because the mainline
irq_desc()currently does not have upper limit checks for IRQs:struct
irq_desc*__irq_to_desc(unsigned int irq){ if ( irq < NR_LOCAL_IRQS ) return &this_cpu(local_irq_desc)[irq]; return &irq_desc[irq-NR_LOCAL_IRQS]; }... as a result Eclair does not spot any issues in this code according to the staging report. As I understand, it triggers on patches with eSPI because I introduced new checks for the eSPI INTID range, which should not be used without
CONFIG_GICV3_ESPI=y.Also, a similar issue with invalid INTIDs was discussed in the thread:
https://lists.xenproject.org/archives/html/xen-devel/2025-09/msg00401.html
Long story short: the mainline Xen currently allows defining invalid INTIDs in the Xen DTS and crashes in
__irq_to_desc()when attempting to operate on an invalid interrupt number.I have prepared a fix for the 18.1 caution, but I am not sure whether it is worth applying just to address the Eclair report (if it is not critical):
https://github.com/LKomaryanskiy/xen/commit/af5d9a483302f7bcfaadbefb85f5e4ee35f6cb3b
Quoted 6 lines
So, could you please clarify which option would be better:
1) Leave the code as it is for now, accepting the MISRA caution from Eclair and fix the issue later in the context of addressing Xen crashing with invalid INTIDs and implementing dynamic allocation ofirq_desc_tarray;
2) Apply the fix now (while also planning to address the invalid INTID issue in the future)
I am happy to apply the fix now as part of the series
Quoted 5 lines
Regarding the review process:
Should I remove the 'reviewed-by' tags from the patches where I added missing breaks (with the corresponding code updates) or introduced variables to fix MISRA issues? I am asking because these are code changes, and I am not sure if I should leave the RB tags in this case.
Please keep them
Quoted 151 lines
Quoted 18 lines
Oleksii,
Technically, the series is fully acked and ready to be committed. From a risk perspective, I would be comfortable committing it now with the outstanding MISRA regressions, leaving Leonid to fix them over the next few days. However, I have not done so because it would make it harder to spot the MISRA regressions due to the way the scanner works (it compares against the previous version).
I suggest we allow this series to be committed in the next couple of days, once Leonid addresses the regressions, even though it would technically be past the feature freeze.
Cheers,
Stefano
Quoted 129 lines
P.S.Leonid, you might want to check my commits because I fixed a couple of things on commit, in addition to adding the various acked-by tags.
Quoted 122 lines · Leonid Komarianskyi
Hello everyone!
V6 contains an issue for debug builds with
CONFIG_GICV3_ESPI=ndue to a mistake in theASSERT()condition in theis_espi()function. This patch series fixes the issue and also includes minor fixes according to the review of V6.Summarized description:
This patch series adds support for the extended shared peripheral interrupt (eSPI) range (INTIDs 4096-5119 [2](ranges of INTIDs)) for Xen and guest domains. The implementation uses a generic approach to handle eSPIs, similar to regular SPIs, while maintaining compatibility with the existing SPI range. Functionality remains unchanged for setups that do not require eSPIs.The series includes:
1) General refactoring of common IRQ operations with GIC registers to improve code readability, simplify further maintenance and prepare the key functions for eSPI implementation.
2) Introducing a newKconfigoption (default n) to enable or disable eSPI support. Disabling this option prevents unnecessary resource allocation for setups that do not require eSPIs.
3) Adding additional resources to store required information and operate with up to 1024 interrupts from eSPI range.
4) Adjusting assertions and checks to pass verification for INTIDs in the eSPI range.
5) Configuration of eSPI-specific registers during GIC initialization for systems with GICv3.1+ hardware.
6) Enables eSPI MMIO emulation for vGIC, allowing guest domains to access and operate within the eSPI's INTIDs.
7) Updating documentation and CHANGELOG to reflect the changes made for eSPI support.Also, to simplify reviewing, please find below link to unsquashed patches, that are on top of every patch, that is changed in the series, compared to V6:
https://github.com/LKomaryanskiy/xen/commits/espi-support-master-upstream-v7-unsquashed/Github branch with patch series:
https://github.com/LKomaryanskiy/xen/commits/espi-support-master-upstream-v7/Changes in V7:
- individual changes in patchesLink on V6:
- https://lists.xenproject.org/archives/html/xen-devel/2025-09/msg00296.htmlChanges in V6:
- individual changes in patchesLink on V5:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg02086.htmlChanges in V5:
- individual changes in patchesLink on V4:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg01767.htmlChanges in V4:
- added a patch for documentation
- individual changes in patchesLink on V3:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg01628.htmlChanges in V3:
- added a patch to update CHANGELOG.md
- individual changes in patchesLink on V2:
- https://lists.xenproject.org/archives/html/xen-devel/2025-08/msg00372.htmlChanges in V2:
- added 2 more patches to implement helper
functions for gic/vgic:
xen/arm: gic: implement helper functions for INTID checks xen/arm: vgic: implement helper functions for virq checks
- removed 2 patches:
xen/arm/irq: allow assignment/releasing of eSPI interrupts xen/arm: gic/irq: permit routing of eSPI interrupts to Xen and domains since their functionality can be moved to appropriate patches after introducing patches with helper functions
- individual changes in patchesLink on V1:
- https://lists.xenproject.org/archives/html/xen-devel/2025-07/msg01809.htmlLeonid Komarianskyi (12):
xen/arm: gicv3: refactor obtaining GIC addresses for common operations xen/arm: gic: implement helper functions for INTID checks xen/arm: vgic: implement helper functions for virq checks xen/arm/irq: add handling for IRQs in the eSPI range xen/arm: gicv3: implement handling of GICv3.1 eSPI xen/arm/irq: allow eSPI processing in thegic_interruptfunction xen/arm: gicv3: modifyICH_LR_PHYSICAL_MASKto allow eSPI processing xen/arm: vgic: add resource management for extended SPIs xen/arm: domain_build/dom0less-build: adjust domains config to support
eSPIs
xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers doc/man: update description fornr_spiswith eSPI CHANGELOG.md: add mention of GICv3.1 eSPI supportCHANGELOG.md | 2 + docs/man/xl.cfg.5.pod.in | 13 +- xen/arch/arm/Kconfig | 8 + xen/arch/arm/dom0less-build.c | 2 +- xen/arch/arm/domain_build.c | 2 +- xen/arch/arm/gic-v3.c | 195 +++++++++++++++++++---- xen/arch/arm/gic.c | 8 +- xen/arch/arm/include/asm/gic.h | 28 ++++ xen/arch/arm/include/asm/gic_v3_defs.h | 40 ++++- xen/arch/arm/include/asm/irq.h | 38 +++++ xen/arch/arm/include/asm/vgic.h | 56 ++++++- xen/arch/arm/irq.c | 62 +++++++- xen/arch/arm/vgic-v3.c | 203 ++++++++++++++++++----- xen/arch/arm/vgic.c | 212 +++++++++++++++++++++++-- xen/arch/arm/vgic/vgic.c | 5 + 15 files changed, 762 insertions(+), 112 deletions(-)--
2.34.1Best regards,
Leonid