Introduce eSPI support
PATCH v2 1/10 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 V2:
- no changes
--- xen/arch/arm/gic-v3.c | 99 ++++++++++++++++++++++------------ xen/arch/arm/include/asm/irq.h | 1 + 2 files changed, 67 insertions(+), 33 deletions(-)
xen/arch/arm/gic-v3.c +66 -33
@@ -445,17 +445,62 @@ static void gicv3_dump_state(const struct vcpu *v) } } +static void __iomem *get_addr_by_offset (struct irq_desc *irqd,u32 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 */ +panic ("Invalid offset 0x%x for IRQ#%d" , offset, irqd->irq); + +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; - -if ( irqd->irq <NR_GIC_LOCAL_IRQS ) - base =GICD_RDIST_SGI_BASE ; -else - base =GICD ; +void __iomem *addr =get_addr_by_offset (irqd, offset); -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 +508,9 @@ 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; - -if ( irq >=NR_GIC_LOCAL_IRQS ) - base =GICD + (irq /32 ) *4 ; -else - base =GICD_RDIST_SGI_BASE ; +void __iomem *addr =get_addr_by_offset (irqd, offset); -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 +597,26 @@ 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); -if ( irq >=NR_GIC_LOCAL_IRQS ) - base =GICD +GICD_ICFGR + (irq /16 ) *4 ; -else - base =GICD_RDIST_SGI_BASE +GICR_ICFGR1 ; + addr =get_addr_by_offset (desc,GICD_ICFGR ); - 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,15 +635,12 @@ 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;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); + addr =get_addr_by_offset (desc,GICD_IPRIORITYR ); +writeb_relaxed (priority, addr);spin_unlock (&gicv3.lock); }
@@ -1273,6 +1305,7 @@ 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 );ASSERT (!cpumask_empty (mask));
@@ -1284,7 +1317,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 v2 2/10 xen/arm: gic: implement helper functions for INTID checks
Introduced two new helper functions: gic_is_valid_irq and gic_is_shared_irq. 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 V2:
- introduced this patch
--- xen/arch/arm/gic.c | 2 +- xen/arch/arm/include/asm/gic.h | 9 +++++++++ xen/arch/arm/irq.c | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-)
xen/arch/arm/gic.c +1 -1
@@ -111,7 +111,7 @@ 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 */ +ASSERT (gic_is_valid_irq (desc->irq));/* Can't route interrupts that don't exist */ 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_irq (unsigned int irq) +{ +return irq <gic_number_lines (); +} + +static inline bool gic_is_shared_irq (unsigned int irq) +{ +return (irq >=NR_LOCAL_IRQS &&gic_is_valid_irq (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_shared_irq (irq); }/*
Signature · 1 line
2.34.1
v2 cover Introduce eSPI support
Hello everyone!
### Background
Unlike the Linux kernel, which has supported extended shared peripheral interrupts (eSPIs) since 2019 [1], Xen currently lacks support for this interrupt range. For SoCs with GICv3.1+, this feature may be essential because critical devices, such as consoles required for booting Xen itself, may rely on eSPIs. Additionally, these platforms require eSPI support for fully functional domains, as any device using eSPIs cannot currently be used with Xen setups. Without eSPI support, Xen cannot run properly on these platforms, significantly limiting its usability on modern ARM hardware.
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 y) 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.
[1] https://github.com/torvalds/linux/commit/211bddd210a6746e4fdfa9b6cdfbdb15026530a7
[2] https://developer.arm.com/documentation/198123/0302/Arm-GIC-fundamentals?lang=en
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 (10):
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 do_IRQ 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: adjust Dom0 IRQ handling to support eSPIs xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers
xen/arch/arm/Kconfig | 9 + xen/arch/arm/domain_build.c | 10 + xen/arch/arm/gic-v3.c | 172 +++++++++++++---- xen/arch/arm/gic.c | 7 +- xen/arch/arm/include/asm/gic.h | 26 +++ xen/arch/arm/include/asm/gic_v3_defs.h | 35 +++- xen/arch/arm/include/asm/irq.h | 26 +++ xen/arch/arm/include/asm/vgic.h | 36 ++++ xen/arch/arm/irq.c | 34 +++- xen/arch/arm/vgic-v3.c | 248 ++++++++++++++++++++++++- xen/arch/arm/vgic.c | 155 +++++++++++++++- 11 files changed, 711 insertions(+), 47 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 4/10 xen/arm/irq: add handling for IRQs in the eSPI range
In reply to Leonid KomarianskyiCurrently, 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 V2:
- use (ESPI_MAX_INTID + 1) instead of (ESPI_BASE_INTID + NR_IRQS)
- remove unnecessary comment for nr_irqs initialization
--- xen/arch/arm/Kconfig | 9 +++++++++ xen/arch/arm/include/asm/irq.h | 25 +++++++++++++++++++++++++ xen/arch/arm/irq.c | 26 ++++++++++++++++++++++++++ 3 files changed, 60 insertions(+)
xen/arch/arm/Kconfig +9 -0
@@ -135,6 +135,15 @@ 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 + default y + 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 +25 -0
@@ -32,6 +32,14 @@ struct arch_irq_desc {#define SPI_MAX_INTID 1019#define LPI_OFFSET 8192 +#ifdef CONFIG_GICV3_ESPI +#define ESPI_BASE_INTID 4096 +#define ESPI_MAX_INTID 5119 + +#define ESPI_INTID2IDX (intid) ((intid) - ESPI_BASE_INTID) +#define ESPI_IDX2INTID (idx) ((idx) + ESPI_BASE_INTID) +#endif +/* LPIs are always numbered starting at 8192, so 0 is a good invalid case. */ #define INVALID_LPI 0
@@ -39,7 +47,15 @@ struct arch_irq_desc {#define INVALID_IRQ 1023extern const unsigned int nr_irqs; +#ifdef CONFIG_GICV3_ESPI +/* +* This will also cover the eSPI range, as some critical devices +* for booting Xen (e.g., serial) may use this type of interrupts. +*/ +#define nr_static_irqs (ESPI_MAX_INTID + 1) +#else #define nr_static_irqs NR_IRQS +#endif struct irq_desc ;struct irqaction ;
@@ -55,6 +71,15 @@ 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 +return false; +#endif +} +#define domain_pirq_to_irq (d, pirq) (pirq)bool is_assignable_irq (unsigned int irq);
xen/arch/arm/irq.c +26 -0
@@ -19,7 +19,11 @@#include <asm/gic.h> #include <asm/vgic.h> +#ifdef CONFIG_GICV3_ESPI +const unsigned int nr_irqs =ESPI_MAX_INTID +1 ; +#else const unsigned int nr_irqs =NR_IRQS ; +#endif static unsigned int local_irqs_type[NR_LOCAL_IRQS ];static DEFINE_SPINLOCK (local_irqs_type_lock);
@@ -46,6 +50,9 @@ void irq_end_none(struct irq_desc *irq) }static irq_desc_t irq_desc[NR_IRQS -NR_LOCAL_IRQS ]; +#ifdef CONFIG_GICV3_ESPI +static irq_desc_t espi_desc[NR_IRQS ]; +#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 +60,11 @@ struct irq_desc *__irq_to_desc(unsigned int irq)if ( irq <NR_LOCAL_IRQS )return &this_cpu (local_irq_desc)[irq]; +#ifdef CONFIG_GICV3_ESPI +if (is_espi (irq) ) +return &espi_desc[ESPI_INTID2IDX (irq)]; +#endif +return &irq_desc[irq-NR_LOCAL_IRQS ]; }
@@ -79,6 +91,20 @@ static int __init init_irq_data(void) desc->action =NULL ; } +#ifdef CONFIG_GICV3_ESPI +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 ; + } +#endif +return 0 ; }
Signature · 1 line
2.34.1
PATCH v2 6/10 xen/arm/irq: allow eSPI processing in the do_IRQ function
In reply to Leonid KomarianskyiThe do_IRQ() function is the main handler for processing IRQs. Currently, due to restrictive checks, it does not process interrupt numbers greater than 1024. This patch updates the condition to allow the handling of interrupts from the eSPI range.
---
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
@@ -341,7 +341,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 v2 3/10 xen/arm: vgic: implement helper functions for virq checks
In reply to Leonid KomarianskyiIntroduced two new helper functions for vGIC: vgic_is_valid_irq and vgic_is_shared_irq. The functions are similar to the newly introduced gic_is_valid_irq and gic_is_shared_irq, 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 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 ++++++++-- 4 files changed, 18 insertions(+), 6 deletions(-)
xen/arch/arm/gic.c +1 -2
@@ -133,8 +133,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_shared_irq (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_irq (struct domain *d,unsigned int virq); + +static inline bool vgic_is_shared_irq (struct domain *d,unsigned int virq) +{ +return (virq >=NR_LOCAL_IRQS &&vgic_is_valid_irq (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_irq (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_shared_irq (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_irq (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_shared_irq (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_irq (d, virq) )return false;return !test_and_set_bit (virq, d->arch.vgic.allocated_irqs);
Signature · 1 line
2.34.1
PATCH v2 5/10 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 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 | 73 ++++++++++++++++++++++++++ xen/arch/arm/include/asm/gic.h | 17 ++++++ xen/arch/arm/include/asm/gic_v3_defs.h | 33 ++++++++++++ 3 files changed, 123 insertions(+)
xen/arch/arm/gic-v3.c +73 -0
@@ -485,6 +485,36 @@ static void __iomem *get_addr_by_offset(struct irq_desc *irqd, u32 offset)default :break ; } +#ifdef CONFIG_GICV3_ESPI + case ESPI_BASE_INTID ... ESPI_MAX_INTID: + { +u32 irq_index =ESPI_INTID2IDX (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 ; }
@@ -645,6 +675,40 @@ 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 gicv3_dist_espi_common_init (uint32_t type) +{ +unsigned int espi_nr; +int 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 ; + +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 (0xffffffffU ,GICD + GICD_ICENABLERnE + (i /32 ) *4 ); +writel_relaxed (0xffffffffU ,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 ); +} +#endif +static void __init gicv3_dist_init (void ) {uint32_t type;
@@ -690,6 +754,10 @@ 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 ); +#ifdef CONFIG_GICV3_ESPI +gicv3_dist_espi_common_init (type); +#endif +gicv3_dist_wait_for_rwp ();/* Turn on the distributor */
@@ -703,6 +771,11 @@ 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 ); + +#ifdef CONFIG_GICV3_ESPI +for ( i =0 ; i < gicv3_info.nr_espi; i++ ) +writeq_relaxed_non_atomic (affinity,GICD + GICD_IROUTERnE + i *8 ); +#endif }static int gicv3_enable_redist (void )
xen/arch/arm/include/asm/gic.h +17 -0
@@ -306,8 +306,21 @@ 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_IDX2INTID (gic_number_espis ())); +} +#endif +static inline bool gic_is_valid_irq (unsigned int irq) { +#ifdef CONFIG_GICV3_ESPI +if (gic_is_valid_espi (irq) ) +return true; +#endif return irq <gic_number_lines (); }
@@ -325,6 +338,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 +33 -0
@@ -37,6 +37,39 @@#define GICD_IROUTER1019 (0x7FD8)#define GICD_PIDR2 (0xFFE8) +#ifdef CONFIG_GICV3_ESPI +/* 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_IROUTERnE (0x8000) +#define GICD_IROUTERnEN (0x9FFC) + +#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 (typer) ((((typer) & 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 v2 7/10 xen/arm: gicv3: modify ICH_LR_PHYSICAL_MASK to allow eSPI processing
In reply to Leonid KomarianskyiTo properly deactivate guest interrupts 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 0x13FF.
---
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
@@ -206,7 +206,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 0x13ff#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 v2 9/10 xen/arm: domain_build: adjust Dom0 IRQ handling to support eSPIs
In reply to Leonid KomarianskyiThe Dom0 configuration logic in create_dom0() has been updated to account for extended SPIs when supported by the hardware and enabled with CONFIG_GICV3_ESPI. These changes ensure the proper calculation of the maximum number of SPIs and eSPIs available for Dom0.
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 limited at 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 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 now.
---
Changes in V2:
- no changes
--- xen/arch/arm/domain_build.c | 10 ++++++++++ xen/arch/arm/include/asm/vgic.h | 11 +++++++++++ 2 files changed, 21 insertions(+)
xen/arch/arm/domain_build.c +10 -0
@@ -2055,6 +2055,16 @@ 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 ; +#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 overwrite the nr_spis with the +* maximum available INTID from eSPI range. In that case, the number of regular SPIs will +* be adjusted to the maximum value during vGIC initialization. +*/ +if (gic_number_espis () >0 ) + dom0_cfg.arch.nr_spis =VGIC_DEF_NR_ESPIS ; +#endif dom0_cfg.arch.tee_type =tee_get_type (); dom0_cfg.max_vcpus =dom0_max_vcpus ();
xen/arch/arm/include/asm/vgic.h +11 -0
@@ -353,6 +353,17 @@ 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) +#ifdef CONFIG_GICV3_ESPI +/* +* Returns the maximum eSPI INTID subtracted by 32. For non-Dom0 domains, the +* toolstack applies the same adjustment to cover local IRQs. 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. +*/ +#define VGIC_DEF_NR_ESPIS (ESPI_BASE_INTID + min(gic_number_espis(), 1024U) - 32) +#endif +extern bool vgic_is_valid_irq (struct domain *d,unsigned int virq);static inline bool vgic_is_shared_irq (struct domain *d,unsigned int virq)
Signature · 1 line
2.34.1
PATCH v2 10/10 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 V2:
- add missing rank index conversion for pending and inflight irqs
--- xen/arch/arm/vgic-v3.c | 248 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 245 insertions(+), 3 deletions(-)
xen/arch/arm/vgic-v3.c +245 -3
@@ -111,7 +111,7 @@ static uint64_t vgic_fetch_irouter(struct vgic_irq_rank *rank,* Note the offset will be aligned to the appropriate boundary. */ static void vgic_store_irouter (struct domain *d,struct vgic_irq_rank *rank, -unsigned int offset,uint64_t irouter) +unsigned int offset,uint64_t irouter,bool espi) {struct vcpu *new_vcpu, *old_vcpu;unsigned int virq;
@@ -123,7 +123,8 @@ static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank,* The IROUTER0-31, used for SGIs/PPIs, are reserved and should * never call this function. */ -ASSERT (virq >=32 ); +if ( !espi ) +ASSERT (virq >=32 );/* Get the index in the rank */ offset = virq &INTERRUPT_RANK_MASK ;
@@ -146,6 +147,11 @@ static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank,/* Only migrate the IRQ if the target vCPU has changed */ if ( new_vcpu != old_vcpu ) { +#ifdef CONFIG_GICV3_ESPI +/* Convert virq index to eSPI range */ +if ( espi ) + virq =ESPI_IDX2INTID (virq); +#endif if (vgic_migrate_irq (old_vcpu, new_vcpu, virq) )write_atomic (&rank->vcpu[offset], new_vcpu->vcpu_id); }
@@ -685,6 +691,9 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, {case VRANGE32 (GICD_IGROUPR ,GICD_IGROUPRN ):case VRANGE32 (GICD_IGRPMODR ,GICD_IGRPMODRN ): +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_IGROUPRnE, GICD_IGROUPRnEN): +#endif /* We do not implement security extensions for guests, read zero */ if ( dabt.size !=DABT_WORD ) goto bad_width; goto read_as_zero;
@@ -710,11 +719,19 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v,/* Read the pending status of an IRQ via GICD/GICR is not supported */ case VRANGE32 (GICD_ISPENDR ,GICD_ISPENDRN ):case VRANGE32 (GICD_ICPENDR ,GICD_ICPENDRN ): +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_ISPENDRnE, GICD_ISPENDRnEN): +case VRANGE32 (GICD_ICPENDRnE, GICD_ICPENDRnEN): +#endif goto read_as_zero;/* Read the active status of an IRQ via GICD/GICR is not supported */ case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):case VRANGE32 (GICD_ICACTIVER ,GICD_ICACTIVERN ): +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_ISACTIVERnE, GICD_ISACTIVERnEN): +case VRANGE32 (GICD_ICACTIVERnE, GICD_ICACTIVERnEN): +#endif goto read_as_zero;case VRANGE32 (GICD_IPRIORITYR ,GICD_IPRIORITYRN ):
@@ -752,6 +769,61 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v,return 1 ; } +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_ISENABLERnE, GICD_ISENABLERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ISENABLERnE,DABT_WORD ); +if ( rank ==NULL ) goto read_as_zero; +vgic_lock_rank (v, rank, flags); + *r =vreg_reg32_extract (rank->ienable, info); +vgic_unlock_rank (v, rank, flags); +return 1 ; + +case VRANGE32 (GICD_ICENABLERnE, GICD_ICENABLERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ICENABLERnE,DABT_WORD ); +if ( rank ==NULL ) goto read_as_zero; +vgic_lock_rank (v, rank, flags); + *r =vreg_reg32_extract (rank->ienable, info); +vgic_unlock_rank (v, rank, flags); +return 1 ; + +case VRANGE32 (GICD_IPRIORITYRnE, GICD_IPRIORITYRnEN): + { +uint32_t ipriorityr; +uint8_t rank_index; + +if ( dabt.size !=DABT_BYTE && dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,8 , reg - GICD_IPRIORITYRnE,DABT_WORD ); +if ( rank ==NULL ) goto read_as_zero; + rank_index =REG_RANK_INDEX (8 , reg - GICD_IPRIORITYRnE,DABT_WORD ); + +vgic_lock_rank (v, rank, flags); + ipriorityr =ACCESS_ONCE (rank->ipriorityr[rank_index]); +vgic_unlock_rank (v, rank, flags); + + *r =vreg_reg32_extract (ipriorityr, info); + +return 1 ; + } + +case VRANGE32 (GICD_ICFGRnE, GICD_ICFGRnEN): + { +uint32_t icfgr; + +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,2 , reg - GICD_ICFGRnE,DABT_WORD ); +if ( rank ==NULL ) goto read_as_zero; +vgic_lock_rank (v, rank, flags); + icfgr = rank->icfg[REG_RANK_INDEX (2 , reg - GICD_ICFGRnE,DABT_WORD )]; +vgic_unlock_rank (v, rank, flags); + + *r =vreg_reg32_extract (icfgr, info); + +return 1 ; + } +#endif +default : printk(XENLOG_G_ERR "%pv: %s: unhandled read r%d offset %#08x\n",
@@ -782,6 +854,9 @@ static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v, {case VRANGE32 (GICD_IGROUPR ,GICD_IGROUPRN ):case VRANGE32 (GICD_IGRPMODR ,GICD_IGRPMODRN ): +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_IGROUPRnE, GICD_IGROUPRnEN): +#endif /* We do not implement security extensions for guests, write ignore */ goto write_ignore_32;
@@ -871,6 +946,87 @@ static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v,vgic_unlock_rank (v, rank, flags);return 1 ; +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_ISENABLERnE, GICD_ISENABLERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ISENABLERnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; +vgic_lock_rank (v, rank, flags); + tr = rank->ienable; +vreg_reg32_setbits (&rank->ienable, r, info); +vgic_enable_irqs (v, (rank->ienable) & (~tr),EXT_RANK_IDX2NUM (rank->index)); +vgic_unlock_rank (v, rank, flags); +return 1 ; + +case VRANGE32 (GICD_ICENABLERnE, GICD_ICENABLERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ICENABLERnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; +vgic_lock_rank (v, rank, flags); + tr = rank->ienable; +vreg_reg32_clearbits (&rank->ienable, r, info); +vgic_disable_irqs (v, (~rank->ienable) & tr,EXT_RANK_IDX2NUM (rank->index)); +vgic_unlock_rank (v, rank, flags); +return 1 ; + +case VRANGE32 (GICD_ISPENDRnE, GICD_ISPENDRnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ISPENDRnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + +vgic_set_irqs_pending (v, r,EXT_RANK_IDX2NUM (rank->index)); + +return 1 ; + +case VRANGE32 (GICD_ICPENDRnE, GICD_ICPENDRnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ICPENDRnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + +vgic_check_inflight_irqs_pending (v,EXT_RANK_IDX2NUM (rank->index), r); + + goto write_ignore; +case VRANGE32 (GICD_ISACTIVERnE, GICD_ISACTIVERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; +printk (XENLOG_G_ERR +"%pv: %s: unhandled word write %#" PRIregister" to ISACTIVER%d\n" , + v, name, r, reg - GICD_ISACTIVERnE); +return 0 ; + +case VRANGE32 (GICD_ICACTIVERnE, GICD_ICACTIVERnEN): +printk (XENLOG_G_ERR +"%pv: %s: unhandled word write %#" PRIregister" to ICACTIVER%d\n" , + v, name, r, reg -GICD_ICACTIVER ); + goto write_ignore_32; + +case VRANGE32 (GICD_IPRIORITYRnE, GICD_IPRIORITYRnEN): + { +uint32_t *ipriorityr, priority; + +if ( dabt.size !=DABT_BYTE && dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,8 , reg - GICD_IPRIORITYRnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; +vgic_lock_rank (v, rank, flags); + ipriorityr = &rank->ipriorityr[REG_RANK_INDEX (8 , reg - GICD_IPRIORITYRnE, +DABT_WORD )]; + priority =ACCESS_ONCE (*ipriorityr); +vreg_reg32_update (&priority, r, info); +ACCESS_ONCE (*ipriorityr) = priority; +vgic_unlock_rank (v, rank, flags); +return 1 ; + } +case VRANGE32 (GICD_ICFGRnE, GICD_ICFGRnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,2 , reg - GICD_ICFGRnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; +vgic_lock_rank (v, rank, flags); +vreg_reg32_update (&rank->icfg[REG_RANK_INDEX (2 , reg - GICD_ICFGRnE, +DABT_WORD )], + r, info); +vgic_unlock_rank (v, rank, flags); +return 1 ; +#endif +default : printk(XENLOG_G_ERR "%pv: %s: unhandled write r%d=%"PRIregister" offset %#08x\n",
@@ -1129,6 +1285,16 @@ static int vgic_v3_distr_mmio_read(struct vcpu *v, mmio_info_t *info, typer |=GICD_TYPE_LPIS ; typer |= (v->domain->arch.vgic.intid_bits -1 ) <<GICD_TYPE_ID_BITS_SHIFT ; +#ifdef CONFIG_GICV3_ESPI +if ( v->domain->arch.vgic.nr_espis >0 ) + { +/* Set eSPI support bit for the domain */ + typer |=GICD_TYPER_ESPI ; +/* Set ESPI range bits */ + typer |= (DIV_ROUND_UP (v->domain->arch.vgic.nr_espis,32 ) -1 ) + <<GICD_TYPER_ESPI_RANGE_SHIFT ; + } +#endif *r =vreg_reg32_extract (typer, info);
@@ -1194,6 +1360,18 @@ static int vgic_v3_distr_mmio_read(struct vcpu *v, mmio_info_t *info,case VRANGE32 (GICD_IPRIORITYR ,GICD_IPRIORITYRN ):case VRANGE32 (GICD_ICFGR ,GICD_ICFGRN ):case VRANGE32 (GICD_IGRPMODR ,GICD_IGRPMODRN ): + +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_IGROUPRnE, GICD_IGROUPRnEN): +case VRANGE32 (GICD_ISENABLERnE, GICD_ISENABLERnEN): +case VRANGE32 (GICD_ICENABLERnE, GICD_ICENABLERnEN): +case VRANGE32 (GICD_ISPENDRnE, GICD_ISPENDRnEN): +case VRANGE32 (GICD_ICPENDRnE, GICD_ICPENDRnEN): +case VRANGE32 (GICD_ISACTIVERnE, GICD_ISACTIVERnEN): +case VRANGE32 (GICD_ICACTIVERnE, GICD_ICACTIVERnEN): +case VRANGE32 (GICD_IPRIORITYRnE, GICD_IPRIORITYRnEN): +case VRANGE32 (GICD_ICFGRnE, GICD_ICFGRnEN): +#endif /* * Above all register are common with GICR and GICD * Manage in common
@@ -1216,7 +1394,11 @@ static int vgic_v3_distr_mmio_read(struct vcpu *v, mmio_info_t *info,/* Replaced with GICR_ISPENDR0. So ignore write */ goto read_as_zero_32; +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (0x3100 ,0x60FC ): +#else case VRANGE32 (0x0F30 ,0x60FC ): +#endif goto read_reserved;case VRANGE64 (GICD_IROUTER32 ,GICD_IROUTER1019 ):
@@ -1235,8 +1417,30 @@ static int vgic_v3_distr_mmio_read(struct vcpu *v, mmio_info_t *info,return 1 ; } +#ifdef CONFIG_GICV3_ESPI +case VRANGE64 (GICD_IROUTERnE, GICD_IROUTERnEN): + { +uint64_t irouter; + +if ( !vgic_reg64_check_access (dabt) ) goto bad_width; + rank =vgic_ext_rank_offset (v,64 , gicd_reg - GICD_IROUTERnE, +DABT_DOUBLE_WORD ); +if ( rank ==NULL ) goto read_as_zero; +vgic_lock_rank (v, rank, flags); + irouter =vgic_fetch_irouter (rank, gicd_reg - GICD_IROUTERnE); +vgic_unlock_rank (v, rank, flags); + + *r =vreg_reg64_extract (irouter, info); + +return 1 ; + } +#endif +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (0xA004 ,0xBFFC ): +#else case VRANGE32 (0x7FE0 ,0xBFFC ): +#endif goto read_reserved;case VRANGE32 (0xC000 ,0xFFCC ):
@@ -1382,6 +1586,18 @@ static int vgic_v3_distr_mmio_write(struct vcpu *v, mmio_info_t *info,case VRANGE32 (GICD_IPRIORITYR ,GICD_IPRIORITYRN ):case VRANGE32 (GICD_ICFGR ,GICD_ICFGRN ):case VRANGE32 (GICD_IGRPMODR ,GICD_IGRPMODRN ): + +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_IGROUPRnE, GICD_IGROUPRnEN): +case VRANGE32 (GICD_ISENABLERnE, GICD_ISENABLERnEN): +case VRANGE32 (GICD_ICENABLERnE, GICD_ICENABLERnEN): +case VRANGE32 (GICD_ISPENDRnE, GICD_ISPENDRnEN): +case VRANGE32 (GICD_ICPENDRnE, GICD_ICPENDRnEN): +case VRANGE32 (GICD_ISACTIVERnE, GICD_ISACTIVERnEN): +case VRANGE32 (GICD_ICACTIVERnE, GICD_ICACTIVERnEN): +case VRANGE32 (GICD_IPRIORITYRnE, GICD_IPRIORITYRnEN): +case VRANGE32 (GICD_ICFGRnE, GICD_ICFGRnEN): +#endif /* Above registers are common with GICR and GICD * Manage in common */ return __vgic_v3_distr_common_mmio_write("vGICD", v, info,
@@ -1405,7 +1621,11 @@ static int vgic_v3_distr_mmio_write(struct vcpu *v, mmio_info_t *info,if ( dabt.size !=DABT_WORD ) goto bad_width;return 0 ; +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (0x3100 ,0x60FC ): +#else case VRANGE32 (0x0F30 ,0x60FC ): +#endif goto write_reserved;case VRANGE64 (GICD_IROUTER32 ,GICD_IROUTER1019 ):
@@ -1419,12 +1639,34 @@ static int vgic_v3_distr_mmio_write(struct vcpu *v, mmio_info_t *info,vgic_lock_rank (v, rank, flags); irouter =vgic_fetch_irouter (rank, gicd_reg -GICD_IROUTER );vreg_reg64_update (&irouter, r, info); -vgic_store_irouter (v->domain, rank, gicd_reg -GICD_IROUTER , irouter); +vgic_store_irouter (v->domain, rank, gicd_reg -GICD_IROUTER , irouter, false); +vgic_unlock_rank (v, rank, flags); +return 1 ; + } + +#ifdef CONFIG_GICV3_ESPI +case VRANGE64 (GICD_IROUTERnE, GICD_IROUTERnEN): + { +uint64_t irouter; + +if ( !vgic_reg64_check_access (dabt) ) goto bad_width; + rank =vgic_ext_rank_offset (v,64 , gicd_reg - GICD_IROUTERnE, +DABT_DOUBLE_WORD ); +if ( rank ==NULL ) goto write_ignore; +vgic_lock_rank (v, rank, flags); + irouter =vgic_fetch_irouter (rank, gicd_reg - GICD_IROUTERnE); +vreg_reg64_update (&irouter, r, info); +vgic_store_irouter (v->domain, rank, gicd_reg - GICD_IROUTERnE, irouter, true);vgic_unlock_rank (v, rank, flags);return 1 ; } +#endif +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (0xA004 ,0xBFFC ): +#else case VRANGE32 (0x7FE0 ,0xBFFC ): +#endif goto write_reserved;case VRANGE32 (0xC000 ,0xFFCC ):
Signature · 1 line
2.34.1
PATCH v2 8/10 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 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 | 18 ++++ xen/arch/arm/vgic.c | 145 ++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+)
xen/arch/arm/include/asm/vgic.h +18 -0
@@ -146,6 +146,10 @@ struct vgic_dist {int nr_spis;/* Number of SPIs */ unsigned long *allocated_irqs;/* bitmap of IRQs allocated */ struct vgic_irq_rank *shared_irqs; +#ifdef CONFIG_GICV3_ESPI +struct vgic_irq_rank *ext_shared_irqs; +int nr_espis;/* Number of extended SPIs */ +#endif /* * SPIs are domain global, SGIs and PPIs are per-VCPU and stored in * struct arch_vcpu.
@@ -243,6 +247,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) +#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) +#endif +#define vgic_lock (v) spin_lock_irq(&(v)->domain->arch.vgic.lock)#define vgic_unlock (v) spin_unlock_irq(&(v)->domain->arch.vgic.lock)
@@ -302,6 +314,12 @@ extern struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v,unsigned int b, unsigned int n, unsigned int s); +#ifdef CONFIG_GICV3_ESPI +extern struct vgic_irq_rank *vgic_ext_rank_offset (struct vcpu *v, +unsigned int b, +unsigned int n, +unsigned int s); +#endif 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.c +145 -0
236 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 02/10] xen/arm: gic: implement helper functions for INTID checks
In reply to Leonid KomarianskyiHi Leonid,
Quoted 51 lines · Leonid Komarianskyi
Introduced two new helper functions:
gic_is_valid_irqandgic_is_shared_irq. 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.
Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- introduced this patch--- xen/arch/arm/gic.c | 2 +- xen/arch/arm/include/asm/gic.h | 9 +++++++++ xen/arch/arm/irq.c | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-)xen/arch/arm/gic.c +1
-1@@ -111,7 +111,7 @@ 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 */ +ASSERT (gic_is_valid_irq (desc->irq));/* Can't route interrupts that don't exist */ ASSERT (test_bit (_IRQ_DISABLED, &desc->status));ASSERT (spin_is_locked (&desc->lock));xen/arch/arm/include/asm/gic.h +0
-0
xen/arch/arm/include/asm/gic.h extern void gic_dump_vgic_info(struct vcpu *v); · line 309
Quoted 4 lines
xen/arch/arm/include/asm/gic.h +1
-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_irq (unsigned int irq)
We need to do something about naming, because this function completely ignores presence of LPIs. What I mean, that it will return "false" for any LPI, while you can't argue that LPI is a valid interrupt :) I understand that this is expected behavior by current callers, but the function name is misleading.
Name like "gic_is_valid_non_lpi()" seems to mouthful, but it is the best I can come up with.
xen/arch/arm/include/asm/gic.h extern void gic_dump_vgic_info(struct vcpu *v); · line 316
Quoted 7 lines
xen/arch/arm/include/asm/gic.h +7
-0+{ +return irq <gic_number_lines (); +} + +static inline bool gic_is_shared_irq (unsigned int irq) +{ +return (irq >=NR_LOCAL_IRQS &&gic_is_valid_irq (irq));
Again, because of misleading name of gic_is_valid_irq() it may seem that this function will return "true" for LPIs as well...
Quoted 17 lines
xen/arch/arm/include/asm/gic.h +1
-0+}/* 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_shared_irq (irq); }/*
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v2 03/10] xen/arm: vgic: implement helper functions for virq checks
In reply to Leonid KomarianskyiQuoted 98 lines · Leonid Komarianskyi
Introduced two new helper functions for vGIC:
vgic_is_valid_irqandvgic_is_shared_irq. The functions are similar to the newly introducedgic_is_valid_irqandgic_is_shared_irq, 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_irqmay affect existing functionality, as it currently checks whether the vIRQ is less than or equal tovgic_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 thanvgic_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.Signed-off-by Leonid Komarianskyi <[email protected]>---
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 ++++++++-- 4 files changed, 18 insertions(+), 6 deletions(-)xen/arch/arm/gic.c +1
-2@@ -133,8 +133,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_shared_irq (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_irq (struct domain *d,unsigned int virq); + +static inline bool vgic_is_shared_irq (struct domain *d,unsigned int virq) +{ +return (virq >=NR_LOCAL_IRQS &&vgic_is_valid_irq (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_irq (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_shared_irq (d, virq) )return -EINVAL ; desc =vgic_get_hw_irq_desc (d,NULL , virq);xen/arch/arm/vgic.c +0
-0
xen/arch/arm/vgic.c line 28
Quoted 5 lines
xen/arch/arm/vgic.c +2
-0@@ -24,6 +24,12 @@#include <asm/gic.h> #include <asm/vgic.h> + +bool vgic_is_valid_irq (struct domain *d,unsigned int virq)
I have the same comment as for the previous patch. This function completely ignores LPIs presence, while you can't argue that LPIs as valid. Again, function callers are expecting this behavior, so this is fine, but function name should better reflect its behavior.
[...]
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v2 04/10] xen/arm/irq: add handling for IRQs in the eSPI range
In reply to Leonid KomarianskyiQuoted 10 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.
I don't think that it is a good idea to hide this feature under Kconfig option, as this will increase number of different build variants. I believe that runtime check for GICD_TYPER.ESPI should be sufficient, but maintainers can correct me there.
Quoted 55 lines
Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- use (ESPI_MAX_INTID+ 1) instead of (ESPI_BASE_INTID+NR_IRQS)
- remove unnecessary comment fornr_irqsinitialization--- xen/arch/arm/Kconfig | 9 +++++++++ xen/arch/arm/include/asm/irq.h | 25 +++++++++++++++++++++++++ xen/arch/arm/irq.c | 26 ++++++++++++++++++++++++++ 3 files changed, 60 insertions(+)xen/arch/arm/Kconfig +9
-0@@ -135,6 +135,15 @@ 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 + default y + 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 +8
-0@@ -32,6 +32,14 @@ struct arch_irq_desc {#define SPI_MAX_INTID 1019#define LPI_OFFSET 8192 +#ifdef CONFIG_GICV3_ESPI +#define ESPI_BASE_INTID 4096 +#define ESPI_MAX_INTID 5119 + +#define ESPI_INTID2IDX (intid) ((intid) - ESPI_BASE_INTID) +#define ESPI_IDX2INTID (idx) ((idx) + ESPI_BASE_INTID) +#endif +/* LPIs are always numbered starting at 8192, so 0 is a good invalid case. */ #define INVALID_LPI 0@@ -39,7 +47,15 @@ struct arch_irq_desc {#define INVALID_IRQ 1023
xen/arch/arm/include/asm/irq.h struct arch_irq_desc { · line 58
Quoted 10 lines
xen/arch/arm/include/asm/irq.h +8
-0extern const unsigned int nr_irqs; +#ifdef CONFIG_GICV3_ESPI +/* +* This will also cover the eSPI range, as some critical devices +* for booting Xen (e.g., serial) may use this type of interrupts. +*/ +#define nr_static_irqs (ESPI_MAX_INTID + 1) +#else #define nr_static_irqs NR_IRQS +#endif
Don't introduce defines that look like variables. I am sure that MISRA team will be unhappy about that. But what you can really do is to introduce variable nr_static_irqs, which value will depend on GICD_TYPER.ESPI and GICD_TYPER.ESPI_range
Quoted 36 lines
xen/arch/arm/include/asm/irq.h +9
-0struct irq_desc ;struct irqaction ;@@ -55,6 +71,15 @@ 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 +return false; +#endif +} +#define domain_pirq_to_irq (d, pirq) (pirq)bool is_assignable_irq (unsigned int irq);xen/arch/arm/irq.c +4
-0@@ -19,7 +19,11 @@#include <asm/gic.h> #include <asm/vgic.h> +#ifdef CONFIG_GICV3_ESPI +const unsigned int nr_irqs =ESPI_MAX_INTID +1 ; +#else const unsigned int nr_irqs =NR_IRQS ; +#endif static unsigned int local_irqs_type[NR_LOCAL_IRQS ];static DEFINE_SPINLOCK (local_irqs_type_lock);
xen/arch/arm/irq.c void irq_end_none(struct irq_desc *irq) · line 54
Quoted 5 lines
xen/arch/arm/irq.c +2
-0@@ -46,6 +50,9 @@ void irq_end_none(struct irq_desc *irq) }static irq_desc_t irq_desc[NR_IRQS -NR_LOCAL_IRQS ]; +#ifdef CONFIG_GICV3_ESPI +static irq_desc_t espi_desc[NR_IRQS ];
This is really confusing. Should it be something like espi_desc[NR_ESPI_IRQS]?
Quoted 37 lines
xen/arch/arm/irq.c +1
-0+#endif static DEFINE_PER_CPU(irq_desc_t[NR_LOCAL_IRQS], local_irq_desc);struct
irq_desc*__irq_to_desc(unsigned int irq)xen/arch/arm/irq.c +19
-0@@ -53,6 +60,11 @@ struct irq_desc *__irq_to_desc(unsigned int irq)if ( irq <NR_LOCAL_IRQS )return &this_cpu (local_irq_desc)[irq]; +#ifdef CONFIG_GICV3_ESPI +if (is_espi (irq) ) +return &espi_desc[ESPI_INTID2IDX (irq)]; +#endif +return &irq_desc[irq-NR_LOCAL_IRQS ]; }@@ -79,6 +91,20 @@ static int __init init_irq_data(void) desc->action =NULL ; } +#ifdef CONFIG_GICV3_ESPI +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 ; + } +#endif +return 0 ; }
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v2 01/10] xen/arm: gicv3: refactor obtaining GIC addresses for common operations
In reply to Leonid KomarianskyiHi,
Quoted 7 lines · Leonid Komarianskyi
Currently, 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.
Signed-off-by Leonid Komarianskyi <[email protected]>
Quoted 187 lines
---
Changes in V2:
- no changes--- xen/arch/arm/gic-v3.c | 99 ++++++++++++++++++++++------------ xen/arch/arm/include/asm/irq.h | 1 + 2 files changed, 67 insertions(+), 33 deletions(-)xen/arch/arm/gic-v3.c +66
-33@@ -445,17 +445,62 @@ static void gicv3_dump_state(const struct vcpu *v) } } +static void __iomem *get_addr_by_offset (struct irq_desc *irqd,u32 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 */ +panic ("Invalid offset 0x%x for IRQ#%d" , offset, irqd->irq); + +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; - -if ( irqd->irq <NR_GIC_LOCAL_IRQS ) - base =GICD_RDIST_SGI_BASE ; -else - base =GICD ; +void __iomem *addr =get_addr_by_offset (irqd, offset); -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 +508,9 @@ 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; - -if ( irq >=NR_GIC_LOCAL_IRQS ) - base =GICD + (irq /32 ) *4 ; -else - base =GICD_RDIST_SGI_BASE ; +void __iomem *addr =get_addr_by_offset (irqd, offset); -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 +597,26 @@ 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); -if ( irq >=NR_GIC_LOCAL_IRQS ) - base =GICD +GICD_ICFGR + (irq /16 ) *4 ; -else - base =GICD_RDIST_SGI_BASE +GICR_ICFGR1 ; + addr =get_addr_by_offset (desc,GICD_ICFGR ); - 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,15 +635,12 @@ 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;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); + addr =get_addr_by_offset (desc,GICD_IPRIORITYR ); +writeb_relaxed (priority, addr);spin_unlock (&gicv3.lock); }@@ -1273,6 +1305,7 @@ 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 );ASSERT (!cpumask_empty (mask));@@ -1284,7 +1317,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
WBR, Volodymyr
Re: [PATCH v2 01/10] xen/arm: gicv3: refactor obtaining GIC addresses for common operations
In reply to Leonid KomarianskyiHi Leonid,
Quoted 11 lines · Leonid Komarianskyi
Currently, 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.
Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- no changes
I am a bit surprised this is just saying no changes given the discussion in v1. I feel you should have pinged on the v1 to close off the discussion before sending v2.
While I understand your point and could accept we consolidate the code...
Quoted 49 lines
--- xen/arch/arm/gic-v3.c | 99 ++++++++++++++++++++++------------ xen/arch/arm/include/asm/irq.h | 1 + 2 files changed, 67 insertions(+), 33 deletions(-)xen/arch/arm/gic-v3.c +36
-0@@ -445,17 +445,62 @@ static void gicv3_dump_state(const struct vcpu *v) } } +static void __iomem *get_addr_by_offset (struct irq_desc *irqd,u32 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 :
xen/arch/arm/gic-v3.c static void gicv3_dump_state(const struct vcpu *v) · line 493
Quoted 10 lines
xen/arch/arm/gic-v3.c +10
-0+return (GICD +GICD_IPRIORITYR + irqd->irq); +default : +break ; + } +default : +break ; + } + +/* Something went wrong, we shouldn't be able to reach here */ +panic ("Invalid offset 0x%x for IRQ#%d" , offset, irqd->irq);
... I still quite concerned about using panic here. We need to try to handle the error more gracefully in production.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 05/10] xen/arm: gicv3: implement handling of GICv3.1 eSPI
In reply to Leonid KomarianskyiHi,
Quoted 92 lines · Leonid Komarianskyi
Introduced 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.
Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- movegic_number_espisfunction from
[PATCH 08/10] xen/arm: vgic: add resource management for extended SPIs to use it in the newly introducedgic_is_valid_espi
- addgic_is_valid_espiwhich checks if IRQ number is in supported by HW eSPI range
- updategic_is_valid_irqconditions to allow operations with eSPIs--- xen/arch/arm/gic-v3.c | 73 ++++++++++++++++++++++++++ xen/arch/arm/include/asm/gic.h | 17 ++++++ xen/arch/arm/include/asm/gic_v3_defs.h | 33 ++++++++++++ 3 files changed, 123 insertions(+)xen/arch/arm/gic-v3.c +46
-0@@ -485,6 +485,36 @@ static void __iomem *get_addr_by_offset(struct irq_desc *irqd, u32 offset)default :break ; } +#ifdef CONFIG_GICV3_ESPI + case ESPI_BASE_INTID ... ESPI_MAX_INTID: + { +u32 irq_index =ESPI_INTID2IDX (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 ; }@@ -645,6 +675,40 @@ 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 gicv3_dist_espi_common_init (uint32_t type) +{ +unsigned int espi_nr; +int 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 ;
xen/arch/arm/gic-v3.c static void gicv3_set_irq_priority(struct irq_desc *desc, · line 703
Quoted 10 lines
xen/arch/arm/gic-v3.c +10
-0+ +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 (0xffffffffU ,GICD + GICD_ICENABLERnE + (i /32 ) *4 );
Is there are particular reason why you use GENMASK(31,0) below, but open-coded 0xffffffff here?
xen/arch/arm/gic-v3.c static void gicv3_set_irq_priority(struct irq_desc *desc, · line 704
Quoted 1 line
xen/arch/arm/gic-v3.c +1
-0+writel_relaxed (0xffffffffU ,GICD + GICD_ICACTIVERnE + (i /32 ) *4 );
... and here?
Quoted 96 lines
xen/arch/arm/gic-v3.c +16
-0+ } + +for ( i =0 ; i < espi_nr; i +=32 ) +writel_relaxed (GENMASK (31 ,0 ),GICD + GICD_IGROUPRnE + (i /32 ) *4 ); +} +#endif +static void __init gicv3_dist_init (void ) {uint32_t type;@@ -690,6 +754,10 @@ 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 ); +#ifdef CONFIG_GICV3_ESPI +gicv3_dist_espi_common_init (type); +#endif +gicv3_dist_wait_for_rwp ();/* Turn on the distributor */ @@ -703,6 +771,11 @@ 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 ); + +#ifdef CONFIG_GICV3_ESPI +for ( i =0 ; i < gicv3_info.nr_espi; i++ ) +writeq_relaxed_non_atomic (affinity,GICD + GICD_IROUTERnE + i *8 ); +#endif }static int gicv3_enable_redist (void )xen/arch/arm/include/asm/gic.h +17
-0@@ -306,8 +306,21 @@ 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_IDX2INTID (gic_number_espis ())); +} +#endif +static inline bool gic_is_valid_irq (unsigned int irq) { +#ifdef CONFIG_GICV3_ESPI +if (gic_is_valid_espi (irq) ) +return true; +#endif return irq <gic_number_lines (); }@@ -325,6 +338,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 +18
-0@@ -37,6 +37,39 @@#define GICD_IROUTER1019 (0x7FD8)#define GICD_PIDR2 (0xFFE8) +#ifdef CONFIG_GICV3_ESPI +/* 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)
xen/arch/arm/include/asm/gic_v3_defs.h line 67
Quoted 10 lines
xen/arch/arm/include/asm/gic_v3_defs.h +10
-0+#define GICD_ICFGRnE (0x3000) +#define GICD_ICFGRnEN (0x30FC) +#define GICD_IROUTERnE (0x8000) +#define GICD_IROUTERnEN (0x9FFC) + +#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 (typer) ((((typer) & GICD_TYPER_ESPI_RANGE_MASK) + 1) * 32)
Isn't this line a bit long?
xen/arch/arm/include/asm/gic_v3_defs.h line 70
Quoted 3 lines
xen/arch/arm/include/asm/gic_v3_defs.h +3
-0+#define GICD_TYPER_ESPIS_NUM (typer) \ + (((typer) & GICD_TYPER_ESPI) ? \ + GICD_TYPER_ESPI_RANGE((typer) >> GICD_TYPER_ESPI_RANGE_SHIFT) : 0)
I am not sure that this is correct.
Probably you wanted to write
+ GICD_TYPER_ESPI_RANGE((typer >> GICD_TYPER_ESPI_RANGE_SHIFT)) : 0)
Quoted 5 lines
xen/arch/arm/include/asm/gic_v3_defs.h +2
-0+#endif +/* Common between GICD_PIDR2 and GICR_PIDR2 */ #define GIC_PIDR2_ARCH_MASK (0xf0)#define GIC_PIDR2_ARCH_GICv3 (0x30)
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v2 10/10] xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers
In reply to Leonid KomarianskyiOn 07.08.25 15:33, Leonid Komarianskyi wrote:
Hello Leonid
Quoted 92 lines
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.Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- add missing rank index conversion for pending and inflight irqs--- xen/arch/arm/vgic-v3.c | 248 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 245 insertions(+), 3 deletions(-)xen/arch/arm/vgic-v3.c +19
-2@@ -111,7 +111,7 @@ static uint64_t vgic_fetch_irouter(struct vgic_irq_rank *rank,* Note the offset will be aligned to the appropriate boundary. */ static void vgic_store_irouter (struct domain *d,struct vgic_irq_rank *rank, -unsigned int offset,uint64_t irouter) +unsigned int offset,uint64_t irouter,bool espi) {struct vcpu *new_vcpu, *old_vcpu;unsigned int virq;@@ -123,7 +123,8 @@ static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank,* The IROUTER0-31, used for SGIs/PPIs, are reserved and should * never call this function. */ -ASSERT (virq >=32 ); +if ( !espi ) +ASSERT (virq >=32 );/* Get the index in the rank */ offset = virq &INTERRUPT_RANK_MASK ;@@ -146,6 +147,11 @@ static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank,/* Only migrate the IRQ if the target vCPU has changed */ if ( new_vcpu != old_vcpu ) { +#ifdef CONFIG_GICV3_ESPI +/* Convert virq index to eSPI range */ +if ( espi ) + virq =ESPI_IDX2INTID (virq); +#endif if (vgic_migrate_irq (old_vcpu, new_vcpu, virq) )write_atomic (&rank->vcpu[offset], new_vcpu->vcpu_id); }@@ -685,6 +691,9 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, {case VRANGE32 (GICD_IGROUPR ,GICD_IGROUPRN ):case VRANGE32 (GICD_IGRPMODR ,GICD_IGRPMODRN ): +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_IGROUPRnE, GICD_IGROUPRnEN): +#endif /* We do not implement security extensions for guests, read zero */ if ( dabt.size !=DABT_WORD ) goto bad_width; goto read_as_zero;@@ -710,11 +719,19 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v,/* Read the pending status of an IRQ via GICD/GICR is not supported */ case VRANGE32 (GICD_ISPENDR ,GICD_ISPENDRN ):case VRANGE32 (GICD_ICPENDR ,GICD_ICPENDRN ): +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_ISPENDRnE, GICD_ISPENDRnEN): +case VRANGE32 (GICD_ICPENDRnE, GICD_ICPENDRnEN): +#endif goto read_as_zero;/* Read the active status of an IRQ via GICD/GICR is not supported */ case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):case VRANGE32 (GICD_ICACTIVER ,GICD_ICACTIVERN ): +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_ISACTIVERnE, GICD_ISACTIVERnEN): +case VRANGE32 (GICD_ICACTIVERnE, GICD_ICACTIVERnEN): +#endif goto read_as_zero;case VRANGE32 (GICD_IPRIORITYR ,GICD_IPRIORITYRN ):
xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, · line 774
Quoted 6 lines
xen/arch/arm/vgic-v3.c +3
-0@@ -752,6 +769,61 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v,return 1 ; } +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_ISENABLERnE, GICD_ISENABLERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width;
NIT: If I am not mistaken, the goto should be on the next line (here and in similar places throughout the added code).
Quoted 103 lines
xen/arch/arm/vgic-v3.c +89
-0+ rank =vgic_ext_rank_offset (v,1 , reg - GICD_ISENABLERnE,DABT_WORD ); +if ( rank ==NULL ) goto read_as_zero; +vgic_lock_rank (v, rank, flags); + *r =vreg_reg32_extract (rank->ienable, info); +vgic_unlock_rank (v, rank, flags); +return 1 ; + +case VRANGE32 (GICD_ICENABLERnE, GICD_ICENABLERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ICENABLERnE,DABT_WORD ); +if ( rank ==NULL ) goto read_as_zero; +vgic_lock_rank (v, rank, flags); + *r =vreg_reg32_extract (rank->ienable, info); +vgic_unlock_rank (v, rank, flags); +return 1 ; + +case VRANGE32 (GICD_IPRIORITYRnE, GICD_IPRIORITYRnEN): + { +uint32_t ipriorityr; +uint8_t rank_index; + +if ( dabt.size !=DABT_BYTE && dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,8 , reg - GICD_IPRIORITYRnE,DABT_WORD ); +if ( rank ==NULL ) goto read_as_zero; + rank_index =REG_RANK_INDEX (8 , reg - GICD_IPRIORITYRnE,DABT_WORD ); + +vgic_lock_rank (v, rank, flags); + ipriorityr =ACCESS_ONCE (rank->ipriorityr[rank_index]); +vgic_unlock_rank (v, rank, flags); + + *r =vreg_reg32_extract (ipriorityr, info); + +return 1 ; + } + +case VRANGE32 (GICD_ICFGRnE, GICD_ICFGRnEN): + { +uint32_t icfgr; + +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,2 , reg - GICD_ICFGRnE,DABT_WORD ); +if ( rank ==NULL ) goto read_as_zero; +vgic_lock_rank (v, rank, flags); + icfgr = rank->icfg[REG_RANK_INDEX (2 , reg - GICD_ICFGRnE,DABT_WORD )]; +vgic_unlock_rank (v, rank, flags); + + *r =vreg_reg32_extract (icfgr, info); + +return 1 ; + } +#endif +default : printk(XENLOG_G_ERR "%pv: %s: unhandled read r%d offset %#08x\n",@@ -782,6 +854,9 @@ static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v, {case VRANGE32 (GICD_IGROUPR ,GICD_IGROUPRN ):case VRANGE32 (GICD_IGRPMODR ,GICD_IGRPMODRN ): +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_IGROUPRnE, GICD_IGROUPRnEN): +#endif /* We do not implement security extensions for guests, write ignore */ goto write_ignore_32;@@ -871,6 +946,87 @@ static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v,vgic_unlock_rank (v, rank, flags);return 1 ; +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_ISENABLERnE, GICD_ISENABLERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ISENABLERnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; +vgic_lock_rank (v, rank, flags); + tr = rank->ienable; +vreg_reg32_setbits (&rank->ienable, r, info); +vgic_enable_irqs (v, (rank->ienable) & (~tr),EXT_RANK_IDX2NUM (rank->index)); +vgic_unlock_rank (v, rank, flags); +return 1 ; + +case VRANGE32 (GICD_ICENABLERnE, GICD_ICENABLERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ICENABLERnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; +vgic_lock_rank (v, rank, flags); + tr = rank->ienable; +vreg_reg32_clearbits (&rank->ienable, r, info); +vgic_disable_irqs (v, (~rank->ienable) & tr,EXT_RANK_IDX2NUM (rank->index)); +vgic_unlock_rank (v, rank, flags); +return 1 ; + +case VRANGE32 (GICD_ISPENDRnE, GICD_ISPENDRnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ISPENDRnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + +vgic_set_irqs_pending (v, r,EXT_RANK_IDX2NUM (rank->index)); + +return 1 ; + +case VRANGE32 (GICD_ICPENDRnE, GICD_ICPENDRnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width;
xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v, · line 992
Quoted 10 lines
xen/arch/arm/vgic-v3.c +10
-0+ rank =vgic_ext_rank_offset (v,1 , reg - GICD_ICPENDRnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + +vgic_check_inflight_irqs_pending (v,EXT_RANK_IDX2NUM (rank->index), r); + + goto write_ignore; +case VRANGE32 (GICD_ISACTIVERnE, GICD_ISACTIVERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + printk(XENLOG_G_ERR + "%pv: %s: unhandled word write %#"PRIregister" to ISACTIVER%d\n",
I would use ISACTIVER%dE in the printed message to distinguish between normal and "extended" registers (here and in similar places throughout the added code).
xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v, · line 999
Quoted 7 lines
xen/arch/arm/vgic-v3.c +7
-0+ v, name, r, reg - GICD_ISACTIVERnE); +return 0 ; + +case VRANGE32 (GICD_ICACTIVERnE, GICD_ICACTIVERnEN): +printk (XENLOG_G_ERR +"%pv: %s: unhandled word write %#" PRIregister" to ICACTIVER%d\n" , + v, name, r, reg -GICD_ICACTIVER );
s/GICD_ICACTIVER/GICD_ICACTIVERnE
[snip]
Re: [PATCH v2 02/10] xen/arm: gic: implement helper functions for INTID checks
In reply to Volodymyr BabchukHi,
Quoted 64 lines · Volodymyr Babchuk
Quoted 51 lines · Leonid Komarianskyi
Introduced two new helper functions:
gic_is_valid_irqandgic_is_shared_irq. 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.
Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- introduced this patch--- xen/arch/arm/gic.c | 2 +- xen/arch/arm/include/asm/gic.h | 9 +++++++++ xen/arch/arm/irq.c | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-)xen/arch/arm/gic.c +1
-1@@ -111,7 +111,7 @@ 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 */ +ASSERT (gic_is_valid_irq (desc->irq));/* Can't route interrupts that don't exist */ ASSERT (test_bit (_IRQ_DISABLED, &desc->status));ASSERT (spin_is_locked (&desc->lock));xen/arch/arm/include/asm/gic.h +0
-0xen/arch/arm/include/asm/gic.h extern void gic_dump_vgic_info(struct vcpu *v); · line 309
Quoted 4 lines
xen/arch/arm/include/asm/gic.h +1
-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_irq (unsigned int irq)We need to do something about naming, because this function completely ignores presence of LPIs. What I mean, that it will return "false" for any LPI, while you can't argue that LPI is a valid interrupt :) I understand that this is expected behavior by current callers, but the function name is misleading.
Quoted 2 lines
Name like "
gic_is_valid_non_lpi()" seems to mouthful, but it is the best I can come up with.
AFAIU, there is no interrupt lines for LPIs. So what about gic_is_valid_line()?
Quoted 11 lines
xen/arch/arm/include/asm/gic.h extern void gic_dump_vgic_info(struct vcpu *v); · line 316
Quoted 8 lines
xen/arch/arm/include/asm/gic.h +7
-0+{ +return irq <gic_number_lines (); +} + +static inline bool gic_is_shared_irq (unsigned int irq) +{ +return (irq >=NR_LOCAL_IRQS &&gic_is_valid_irq (irq));Again, because of misleading name of
gic_is_valid_irq()it may seem that this function will return "true" for LPIs as well...
Even if we rename gic_is_valid_irq(), the function name would be misleading because LPIs are shared. I think it would be better named gic_is_spi(...);
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 07/10] xen/arm: gicv3: modify ICH_LR_PHYSICAL_MASK to allow eSPI processing
In reply to Leonid KomarianskyiHi Leonid,
Quoted 5 lines · Leonid Komarianskyi
To properly deactivate guest interrupts 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 to0x13FF.
I am not sure how this supposed to work. According to the arch specification, pINTID field in ICH_LR<n>_EL2 is only 12 bits wide.
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v2 08/10] xen/arm: vgic: add resource management for extended SPIs
In reply to Leonid KomarianskyiQuoted 101 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.
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]>---
Changes 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 | 18 ++++ xen/arch/arm/vgic.c | 145 ++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+)xen/arch/arm/include/asm/vgic.h +18
-0@@ -146,6 +146,10 @@ struct vgic_dist {int nr_spis;/* Number of SPIs */ unsigned long *allocated_irqs;/* bitmap of IRQs allocated */ struct vgic_irq_rank *shared_irqs; +#ifdef CONFIG_GICV3_ESPI +struct vgic_irq_rank *ext_shared_irqs; +int nr_espis;/* Number of extended SPIs */ +#endif /* * SPIs are domain global, SGIs and PPIs are per-VCPU and stored in * struct arch_vcpu. @@ -243,6 +247,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) +#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) +#endif +#define vgic_lock (v) spin_lock_irq(&(v)->domain->arch.vgic.lock)#define vgic_unlock (v) spin_unlock_irq(&(v)->domain->arch.vgic.lock)@@ -302,6 +314,12 @@ extern struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v,unsigned int b, unsigned int n, unsigned int s); +#ifdef CONFIG_GICV3_ESPI +extern struct vgic_irq_rank *vgic_ext_rank_offset (struct vcpu *v, +unsigned int b, +unsigned int n, +unsigned int s); +#endif 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.c +5
-0@@ -27,9 +27,26 @@bool vgic_is_valid_irq (struct domain *d,unsigned int virq) { +#ifdef CONFIG_GICV3_ESPI +if ( virq >=ESPI_BASE_INTID && virq <ESPI_IDX2INTID (d->arch.vgic.nr_espis) ) +return true; +#endif +return virq <vgic_num_irqs (d); }
xen/arch/arm/vgic.c line 46
Quoted 10 lines
xen/arch/arm/vgic.c +9
-0+#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) );
I am pretty sure that max line length in 80 symbols, and here you have more. As well in couple of other places below.
Quoted 68 lines
xen/arch/arm/vgic.c +40
-0+} +#endif +static inline struct vgic_irq_rank *vgic_get_rank (struct vcpu *v,unsigned int rank) {@@ -37,6 +54,10 @@ 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]; +#ifdef CONFIG_GICV3_ESPI + else if ( is_valid_espi_rank(v->domain, rank) ) + return &v->domain->arch.vgic.ext_shared_irqs[EXT_RANK_NUM2IDX(rank)]; +#endif else return NULL; }@@ -53,6 +74,16 @@ struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, unsigned int b,return vgic_get_rank (v, rank); } +#ifdef CONFIG_GICV3_ESPI +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 ); +} +#endif +struct vgic_irq_rank *vgic_rank_irq (struct vcpu *v,unsigned int irq) {unsigned int rank = irq /32 ;@@ -117,6 +148,29 @@ int domain_vgic_register(struct domain *d, unsigned int *mmio_count)return 0 ; } +#ifdef CONFIG_GICV3_ESPI +static int init_vgic_espi (struct domain *d) +{ +int i; + +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 =0 ; i < d->arch.vgic.nr_espis; i++ ) +vgic_init_pending_irq (&d->arch.vgic.pending_irqs[i + d->arch.vgic.nr_spis],ESPI_IDX2INTID (i)); + +for ( i =0 ; i <DOMAIN_NR_EXT_RANKS (d); i++ ) +vgic_rank_init (&d->arch.vgic.ext_shared_irqs[i], i,0 ); + +return 0 ; +} +#endif +int domain_vgic_init (struct domain *d,unsigned int nr_spis) {int i;@@ -131,6 +185,30 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis)*/ nr_spis =ROUNDUP (nr_spis,32 );
xen/arch/arm/vgic.c int domain_vgic_init(struct domain *d, unsigned int nr_spis) · line 197
Quoted 10 lines
xen/arch/arm/vgic.c +10
-0+#ifdef CONFIG_GICV3_ESPI +if ( nr_spis >ESPI_MAX_INTID ) +return -EINVAL ; + +if (is_espi (nr_spis) ) + { +/* +* During domain creation, the toolstack specifies the maximum INTID, +* which is defined in the domain config subtracted by 32. To compute the +* actual number of eSPI that will be usable for, add back 32.
I think, according to this, your if ( is_espi() ) check is wrong. Should you add 32 here as well?
Quoted 150 lines
xen/arch/arm/vgic.c +81
-0+*/ + d->arch.vgic.nr_espis =min (nr_spis -ESPI_BASE_INTID +32 ,1024U ); +/* Verify if GIC HW can handle provided INTID */ +if ( d->arch.vgic.nr_espis >gic_number_espis () ) +return -EINVAL ; +/* Set the maximum available number for defult SPI to pass the next check */ + nr_spis = VGIC_DEF_NR_SPIS; + }else + { +/* Domain will use the regular SPI range */ + d->arch.vgic.nr_espis =0 ; + } +#endif +/* Limit the number of virtual SPIs supported to (1020 - 32) = 988 */ if ( nr_spis > (1020 -NR_LOCAL_IRQS ) )return -EINVAL ;@@ -145,7 +223,12 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis)return -ENOMEM ; d->arch.vgic.pending_irqs = +#ifdef CONFIG_GICV3_ESPI + xzalloc_array(struct pending_irq, d->arch.vgic.nr_spis + + d->arch.vgic.nr_espis); +#else xzalloc_array(struct pending_irq, d->arch.vgic.nr_spis); +#endif if ( d->arch.vgic.pending_irqs ==NULL )return -ENOMEM ;@@ -156,12 +239,23 @@ 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 ); +#ifdef CONFIG_GICV3_ESPI + ret =init_vgic_espi (d); +if ( ret ) +return ret; +#endif + ret = d->arch.vgic.handler->domain_init (d);if ( ret )return ret; d->arch.vgic.allocated_irqs = +#ifdef CONFIG_GICV3_ESPI + xzalloc_array(unsigned long, BITS_TO_LONGS(vgic_num_irqs(d) + + d->arch.vgic.nr_espis)); +#else xzalloc_array(unsigned long, BITS_TO_LONGS(vgic_num_irqs(d))); +#endif if ( !d->arch.vgic.allocated_irqs )return -ENOMEM ;@@ -195,9 +289,27 @@ void domain_vgic_free(struct domain *d) } } +#ifdef CONFIG_GICV3_ESPI +for ( i =0 ; i < (d->arch.vgic.nr_espis); i++ ) + { +struct pending_irq *p =spi_to_pending (d,ESPI_IDX2INTID (i)); + +if ( p->desc ) + { + ret =release_guest_irq (d, p->irq); +if ( ret ) +dprintk (XENLOG_G_WARNING ,"d%u: Failed to release virq %u ret = %d\n" , + d->domain_id, p->irq, ret); + } + } +#endif +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); }@@ -331,6 +443,17 @@ void arch_move_irqs(struct vcpu *v)if ( v_target == v && !test_bit (GIC_IRQ_GUEST_MIGRATING , &p->status) )irq_set_affinity (p->desc, cpu_mask); } + +#ifdef CONFIG_GICV3_ESPI +for ( i =ESPI_BASE_INTID ; i < (d)->arch.vgic.nr_espis; i++ ) + { + v_target =vgic_get_target_vcpu (v, i); + p =irq_to_pending (v_target, i); + +if ( v_target == v && !test_bit (GIC_IRQ_GUEST_MIGRATING , &p->status) ) +irq_set_affinity (p->desc, cpu_mask); + } +#endif }void vgic_disable_irqs (struct vcpu *v,uint32_t r,unsigned int n)@@ -538,6 +661,10 @@ struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq) n = &v->arch.vgic.pending_irqs[irq]; else if ( is_lpi(irq) ) n = v->domain->arch.vgic.handler->lpi_to_pending (v->domain, irq); +#ifdef CONFIG_GICV3_ESPI + else if ( is_espi(irq) ) + n = &v->domain->arch.vgic.pending_irqs[ESPI_INTID2IDX (irq) + v->domain->arch.vgic.nr_spis]; +#endif else n = &v->domain->arch.vgic.pending_irqs[irq -32 ];return n;@@ -547,6 +674,14 @@ struct pending_irq *spi_to_pending(struct domain *d, unsigned int irq) {ASSERT (irq >=NR_LOCAL_IRQS ); +#ifdef CONFIG_GICV3_ESPI +if (is_espi (irq) ) + { + irq =ESPI_INTID2IDX (irq) + d->arch.vgic.nr_spis; +return &d->arch.vgic.pending_irqs[irq]; + } +#endif +return &d->arch.vgic.pending_irqs[irq -32 ]; }@@ -668,6 +803,11 @@ bool vgic_reserve_virq(struct domain *d, unsigned int virq)if ( !vgic_is_valid_irq (d, virq) )return false; +#ifdef CONFIG_GICV3_ESPI +if (is_espi (virq) ) +return !test_and_set_bit (ESPI_INTID2IDX (virq) +vgic_num_irqs (d), d->arch.vgic.allocated_irqs); +#endif +return !test_and_set_bit (virq, d->arch.vgic.allocated_irqs); }@@ -686,6 +826,11 @@ int vgic_allocate_virq(struct domain *d, bool spi) { first =32 ; end =vgic_num_irqs (d); +#ifdef CONFIG_GICV3_ESPI +/* Take into account extended SPI range */ + end += d->arch.vgic.nr_espis; +#endif + }/*
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v2 04/10] xen/arm/irq: add handling for IRQs in the eSPI range
In reply to Volodymyr BabchukHi,
Quoted 13 lines · Volodymyr Babchuk
Quoted 10 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 3 lines
I don't think that it is a good idea to hide this feature under
Kconfig
option, as this will increase number of different build variants.
I believe that runtime check for GICD_TYPER.ESPI should be sufficient,> but maintainers can correct me there.
I haven't seen many board with ESPI available. So I think it would be better if this is under a Kconfig because not everyone may want to have the code.
[...]
Quoted 32 lines
Quoted 32 lines
struct
irq_desc;
struct irqaction;xen/arch/arm/include/asm/irq.h +9
-0@@ -55,6 +71,15 @@ 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 +return false; +#endif +} +#define domain_pirq_to_irq (d, pirq) (pirq)bool is_assignable_irq (unsigned int irq);xen/arch/arm/irq.c +4
-0@@ -19,7 +19,11 @@#include <asm/gic.h> #include <asm/vgic.h> +#ifdef CONFIG_GICV3_ESPI +const unsigned int nr_irqs =ESPI_MAX_INTID +1 ; +#else const unsigned int nr_irqs =NR_IRQS ; +#endif
Quoted 8 lines
xen/arch/arm/irq.c void irq_end_none(struct irq_desc *irq) · line 54
Quoted 8 lines
xen/arch/arm/irq.c +2
-0static unsigned int local_irqs_type[NR_LOCAL_IRQS ];static DEFINE_SPINLOCK (local_irqs_type_lock);@@ -46,6 +50,9 @@ void irq_end_none(struct irq_desc *irq) }static irq_desc_t irq_desc[NR_IRQS -NR_LOCAL_IRQS ]; +#ifdef CONFIG_GICV3_ESPI +static irq_desc_t espi_desc[NR_IRQS ];
By how much will this increase the Xen binary?
Quoted 2 lines
This is really confusing. Should it be something like espi_desc[NR_ESPI_IRQS]?
+1.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 09/10] xen/arm: domain_build: adjust Dom0 IRQ handling to support eSPIs
In reply to Leonid KomarianskyiQuoted 52 lines · Leonid Komarianskyi
The Dom0 configuration logic in
create_dom0()has been updated to account for extended SPIs when supported by the hardware and enabled withCONFIG_GICV3_ESPI. These changes ensure the proper calculation of the maximum number of SPIs and eSPIs available for Dom0.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 limited at 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 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 now.Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- no changes--- xen/arch/arm/domain_build.c | 10 ++++++++++ xen/arch/arm/include/asm/vgic.h | 11 +++++++++++ 2 files changed, 21 insertions(+)xen/arch/arm/domain_build.c +10
-0@@ -2055,6 +2055,16 @@ 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 ; +#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 overwrite the nr_spis with the +* maximum available INTID from eSPI range. In that case, the number of regular SPIs will +* be adjusted to the maximum value during vGIC initialization. +*/ +if (gic_number_espis () >0 ) + dom0_cfg.arch.nr_spis =VGIC_DEF_NR_ESPIS ; +#endif dom0_cfg.arch.tee_type =tee_get_type (); dom0_cfg.max_vcpus =dom0_max_vcpus ();xen/arch/arm/include/asm/vgic.h +0
-0@@ -353,6 +353,17 @@ 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)
xen/arch/arm/include/asm/vgic.h extern void vgic_check_inflight_irqs_pending(struct vcpu *v, · line 364
Quoted 10 lines
xen/arch/arm/include/asm/vgic.h +9
-0+#ifdef CONFIG_GICV3_ESPI +/* +* Returns the maximum eSPI INTID subtracted by 32. For non-Dom0 domains, the +* toolstack applies the same adjustment to cover local IRQs. 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. +*/ +#define VGIC_DEF_NR_ESPIS (ESPI_BASE_INTID + min(gic_number_espis(), 1024U) - 32)
Name of the define is wrong, as it is not number of eSPIs. Actually, this is maximum SPI (including eSPIs) number.
Quoted 5 lines
xen/arch/arm/include/asm/vgic.h +2
-0+#endif +extern bool vgic_is_valid_irq (struct domain *d,unsigned int virq);static inline bool vgic_is_shared_irq (struct domain *d,unsigned int virq)
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v2 04/10] xen/arm/irq: add handling for IRQs in the eSPI range
In reply to Julien GrallHi Julien,
Quoted 19 lines · Julien Grall
Hi,
Quoted 12 lines · Volodymyr Babchuk
Quoted 10 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 4 lines
I don't think that it is a good idea to hide this feature under
Kconfig
option, as this will increase number of different build variants. I believe that runtime check for GICD_TYPER.ESPI should be
Quoted 5 lines
sufficient,> but maintainers can correct me there.
I haven't seen many board with ESPI available. So I think it would be better if this is under a
Kconfigbecause not everyone may want to have the code.
Probably, we can expect more in the future... Anyways, after reviewing all patches in the series, I can see that code will be littered with #ifdef CONFIG_GICV3_ESPI, which, probably, not a good thing.
Quoted 32 lines
[...]
Quoted 29 lines
Quoted 29 lines
struct
irq_desc;
struct irqaction;xen/arch/arm/include/asm/irq.h +8
-0@@ -55,6 +71,15 @@ 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 +return false; +#endif +} +#define domain_pirq_to_irq (d, pirq) (pirq)bool is_assignable_irq (unsigned int irq);xen/arch/arm/irq.c +3
-0@@ -19,7 +19,11 @@#include <asm/gic.h> #include <asm/vgic.h> +#ifdef CONFIG_GICV3_ESPI +const unsigned int nr_irqs =ESPI_MAX_INTID +1 ; +#else const unsigned int nr_irqs =NR_IRQS ; +#endif static unsigned int local_irqs_type[NR_LOCAL_IRQS ];
Quoted 8 lines
Quoted 6 lines
xen/arch/arm/irq.c void irq_end_none(struct irq_desc *irq) · line 53
Quoted 6 lines
xen/arch/arm/irq.c +2
-0static DEFINE_SPINLOCK (local_irqs_type_lock);@@ -46,6 +50,9 @@ void irq_end_none(struct irq_desc *irq) }static irq_desc_t irq_desc[NR_IRQS -NR_LOCAL_IRQS ]; +#ifdef CONFIG_GICV3_ESPI +static irq_desc_t espi_desc[NR_IRQS ];By how much will this increase the Xen binary?
I am wondering this also. The struct is cache aligned, so it will take at least 128 bytes. The whole array will take at least 128kb. Not great, not terrible. As this should go to .bss, it should not increase the binary itself.
Maybe it is better to allocate this dynamically? I do understand that we want to get rid of as many dynamic allocs as possible, but maybe in this case it will be okay. As a bonus point, we can't leave this pointer present even if CONFIG_GICV3_ESPI=n, which will simplify some code in latter patches.
[...]
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v2 04/10] xen/arm/irq: add handling for IRQs in the eSPI range
Quoted 21 lines · Volodymyr Babchuk
Quoted 19 lines · Julien Grall
Hi,
Quoted 16 lines · Volodymyr Babchuk
Quoted 10 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.I don't think that it is a good idea to hide this feature under
Kconfig
option, as this will increase number of different build variants. I believe that runtime check for GICD_TYPER.ESPI should be
Quoted 7 lines
Quoted 5 lines
sufficient,> but maintainers can correct me there.
I haven't seen many board with ESPI available. So I think it would be better if this is under a
Kconfigbecause not everyone may want to have the code.Probably, we can expect more in the future...
Well yes. But I was under the impression this the preferred approach. See the discussion about disabling 32-bit support on 64-bit:
Anyways, after reviewing
Quoted 2 lines
all patches in the series, I can see that code will be littered with #ifdef
CONFIG_GICV3_ESPI, which, probably, not a good thing.
The solution is to provide wrappers to reduce the number of #ifdef. I haven't checked all the places.
Quoted 42 lines
Quoted 33 lines
[...]
Quoted 29 lines
Quoted 29 lines
struct irq_desc; struct irqaction;xen/arch/arm/include/asm/irq.h +8
-0@@ -55,6 +71,15 @@ 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 +return false; +#endif +} +#define domain_pirq_to_irq (d, pirq) (pirq)bool is_assignable_irq (unsigned int irq);xen/arch/arm/irq.c +3
-0@@ -19,7 +19,11 @@#include <asm/gic.h> #include <asm/vgic.h> +#ifdef CONFIG_GICV3_ESPI +const unsigned int nr_irqs =ESPI_MAX_INTID +1 ; +#else const unsigned int nr_irqs =NR_IRQS ; +#endif static unsigned int local_irqs_type[NR_LOCAL_IRQS ];Quoted 8 lines
Quoted 6 lines
xen/arch/arm/irq.c void irq_end_none(struct irq_desc *irq) · line 53
Quoted 6 lines
xen/arch/arm/irq.c +2
-0static DEFINE_SPINLOCK (local_irqs_type_lock);@@ -46,6 +50,9 @@ void irq_end_none(struct irq_desc *irq) }static irq_desc_t irq_desc[NR_IRQS -NR_LOCAL_IRQS ]; +#ifdef CONFIG_GICV3_ESPI +static irq_desc_t espi_desc[NR_IRQS ];By how much will this increase the Xen binary?
Quoted 4 lines
I am wondering this also. The struct is cache aligned, so it will take at least 128 bytes. The whole array will take at least 128kb. Not great, not terrible. As this should go to .bss, it should not increase the binary itself.
I guess "binary" was the wrong word. I was referring to the size of the Xen in memory. On my setup Xen is 1448kb. Here you would increase ~9% of resident size. This seems quite steep for a feature that is not often used.
Quoted 4 lines
Maybe it is better to allocate this dynamically? I do understand that we want to get rid of as many dynamic allocs as possible, but maybe in this case it will be okay.
This is up to Leonid. I don't think this is strictly necessary in order to get the eSPI support. However, until this is solved CONFIG_GICV3_EPSI *must not* be on by default as this is done in this patch.
Quoted 3 lines
As a bonus point, we can't leave this pointer
present even ifCONFIG_GICV3_ESPI=n, which will simplify some code in latter patches.
Did you intend to say "We can leave" rather than "we can't leave"?
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 10/10] xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers
In reply to Leonid KomarianskyiHi Leonid,
Quoted 31 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.Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- add missing rank index conversion for pending and inflight irqs--- xen/arch/arm/vgic-v3.c | 248 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 245 insertions(+), 3 deletions(-)xen/arch/arm/vgic-v3.c +0
-0
xen/arch/arm/vgic-v3.c static uint64_t vgic_fetch_irouter(struct vgic_irq_rank *rank, · line 114
Quoted 5 lines
xen/arch/arm/vgic-v3.c +1
-1@@ -111,7 +111,7 @@ static uint64_t vgic_fetch_irouter(struct vgic_irq_rank *rank,* Note the offset will be aligned to the appropriate boundary. */ static void vgic_store_irouter (struct domain *d,struct vgic_irq_rank *rank, -unsigned int offset,uint64_t irouter) +unsigned int offset,uint64_t irouter,bool espi)
I am wondering: maybe it is better to pass virq instead of offset into this function? In that case you can get rid of espi parameter.
xen/arch/arm/vgic-v3.c static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank, · line 127
Quoted 10 lines
xen/arch/arm/vgic-v3.c +2
-1{struct vcpu *new_vcpu, *old_vcpu;unsigned int virq;@@ -123,7 +123,8 @@ static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank,* The IROUTER0-31, used for SGIs/PPIs, are reserved and should * never call this function. */ -ASSERT (virq >=32 ); +if ( !espi ) +ASSERT (virq >=32 );
better to write
ASSERT (!espi & (virq>=32))
and probably you need symmetrical ASSERT for espi == true
xen/arch/arm/vgic-v3.c static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank, · line 154
Quoted 11 lines
xen/arch/arm/vgic-v3.c +5
-0/* Get the index in the rank */ offset = virq &INTERRUPT_RANK_MASK ;@@ -146,6 +147,11 @@ static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank,/* Only migrate the IRQ if the target vCPU has changed */ if ( new_vcpu != old_vcpu ) { +#ifdef CONFIG_GICV3_ESPI +/* Convert virq index to eSPI range */ +if ( espi ) + virq =ESPI_IDX2INTID (virq); +#endif
If you define ESPI_IDX2INTID() uncoditionally, you can get rid of #ifdef CONFIG_GICV3_ESPI here
xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, · line 694
Quoted 8 lines
xen/arch/arm/vgic-v3.c +1
-0if (vgic_migrate_irq (old_vcpu, new_vcpu, virq) )write_atomic (&rank->vcpu[offset], new_vcpu->vcpu_id); }@@ -685,6 +691,9 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, {case VRANGE32 (GICD_IGROUPR ,GICD_IGROUPRN ):case VRANGE32 (GICD_IGRPMODR ,GICD_IGRPMODRN ): +#ifdef CONFIG_GICV3_ESPI
Do you really need ifdef here?
xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, · line 722
Quoted 12 lines
xen/arch/arm/vgic-v3.c +2
-0+case VRANGE32 (GICD_IGROUPRnE, GICD_IGROUPRnEN): +#endif /* We do not implement security extensions for guests, read zero */ if ( dabt.size != DABT_WORD ) goto bad_width; goto read_as_zero;xen/arch/arm/vgic-v3.c +1
-0@@ -710,11 +719,19 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v,/* Read the pending status of an IRQ via GICD/GICR is not supported */ case VRANGE32 (GICD_ISPENDR ,GICD_ISPENDRN ):case VRANGE32 (GICD_ICPENDR ,GICD_ICPENDRN ): +#ifdef CONFIG_GICV3_ESPI
Same as here
xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, · line 731
Quoted 9 lines
xen/arch/arm/vgic-v3.c +4
-0+case VRANGE32 (GICD_ISPENDRnE, GICD_ISPENDRnEN): +case VRANGE32 (GICD_ICPENDRnE, GICD_ICPENDRnEN): +#endif goto read_as_zero;/* Read the active status of an IRQ via GICD/GICR is not supported */ case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):case VRANGE32 (GICD_ICACTIVER ,GICD_ICACTIVERN ): +#ifdef CONFIG_GICV3_ESPI
... and here and in all other places
Quoted 312 lines
xen/arch/arm/vgic-v3.c +229
-1+case VRANGE32 (GICD_ISACTIVERnE, GICD_ISACTIVERnEN): +case VRANGE32 (GICD_ICACTIVERnE, GICD_ICACTIVERnEN): +#endif goto read_as_zero;case VRANGE32 (GICD_IPRIORITYR ,GICD_IPRIORITYRN ):@@ -752,6 +769,61 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v,return 1 ; } +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_ISENABLERnE, GICD_ISENABLERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ISENABLERnE,DABT_WORD ); +if ( rank ==NULL ) goto read_as_zero; +vgic_lock_rank (v, rank, flags); + *r =vreg_reg32_extract (rank->ienable, info); +vgic_unlock_rank (v, rank, flags); +return 1 ; + +case VRANGE32 (GICD_ICENABLERnE, GICD_ICENABLERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ICENABLERnE,DABT_WORD ); +if ( rank ==NULL ) goto read_as_zero; +vgic_lock_rank (v, rank, flags); + *r =vreg_reg32_extract (rank->ienable, info); +vgic_unlock_rank (v, rank, flags); +return 1 ; + +case VRANGE32 (GICD_IPRIORITYRnE, GICD_IPRIORITYRnEN): + { +uint32_t ipriorityr; +uint8_t rank_index; + +if ( dabt.size !=DABT_BYTE && dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,8 , reg - GICD_IPRIORITYRnE,DABT_WORD ); +if ( rank ==NULL ) goto read_as_zero; + rank_index =REG_RANK_INDEX (8 , reg - GICD_IPRIORITYRnE,DABT_WORD ); + +vgic_lock_rank (v, rank, flags); + ipriorityr =ACCESS_ONCE (rank->ipriorityr[rank_index]); +vgic_unlock_rank (v, rank, flags); + + *r =vreg_reg32_extract (ipriorityr, info); + +return 1 ; + } + +case VRANGE32 (GICD_ICFGRnE, GICD_ICFGRnEN): + { +uint32_t icfgr; + +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,2 , reg - GICD_ICFGRnE,DABT_WORD ); +if ( rank ==NULL ) goto read_as_zero; +vgic_lock_rank (v, rank, flags); + icfgr = rank->icfg[REG_RANK_INDEX (2 , reg - GICD_ICFGRnE,DABT_WORD )]; +vgic_unlock_rank (v, rank, flags); + + *r =vreg_reg32_extract (icfgr, info); + +return 1 ; + } +#endif +default : printk(XENLOG_G_ERR "%pv: %s: unhandled read r%d offset %#08x\n",@@ -782,6 +854,9 @@ static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v, {case VRANGE32 (GICD_IGROUPR ,GICD_IGROUPRN ):case VRANGE32 (GICD_IGRPMODR ,GICD_IGRPMODRN ): +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_IGROUPRnE, GICD_IGROUPRnEN): +#endif /* We do not implement security extensions for guests, write ignore */ goto write_ignore_32;@@ -871,6 +946,87 @@ static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v,vgic_unlock_rank (v, rank, flags);return 1 ; +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_ISENABLERnE, GICD_ISENABLERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ISENABLERnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; +vgic_lock_rank (v, rank, flags); + tr = rank->ienable; +vreg_reg32_setbits (&rank->ienable, r, info); +vgic_enable_irqs (v, (rank->ienable) & (~tr),EXT_RANK_IDX2NUM (rank->index)); +vgic_unlock_rank (v, rank, flags); +return 1 ; + +case VRANGE32 (GICD_ICENABLERnE, GICD_ICENABLERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ICENABLERnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; +vgic_lock_rank (v, rank, flags); + tr = rank->ienable; +vreg_reg32_clearbits (&rank->ienable, r, info); +vgic_disable_irqs (v, (~rank->ienable) & tr,EXT_RANK_IDX2NUM (rank->index)); +vgic_unlock_rank (v, rank, flags); +return 1 ; + +case VRANGE32 (GICD_ISPENDRnE, GICD_ISPENDRnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ISPENDRnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + +vgic_set_irqs_pending (v, r,EXT_RANK_IDX2NUM (rank->index)); + +return 1 ; + +case VRANGE32 (GICD_ICPENDRnE, GICD_ICPENDRnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,1 , reg - GICD_ICPENDRnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + +vgic_check_inflight_irqs_pending (v,EXT_RANK_IDX2NUM (rank->index), r); + + goto write_ignore; +case VRANGE32 (GICD_ISACTIVERnE, GICD_ISACTIVERnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; +printk (XENLOG_G_ERR +"%pv: %s: unhandled word write %#" PRIregister" to ISACTIVER%d\n" , + v, name, r, reg - GICD_ISACTIVERnE); +return 0 ; + +case VRANGE32 (GICD_ICACTIVERnE, GICD_ICACTIVERnEN): +printk (XENLOG_G_ERR +"%pv: %s: unhandled word write %#" PRIregister" to ICACTIVER%d\n" , + v, name, r, reg -GICD_ICACTIVER ); + goto write_ignore_32; + +case VRANGE32 (GICD_IPRIORITYRnE, GICD_IPRIORITYRnEN): + { +uint32_t *ipriorityr, priority; + +if ( dabt.size !=DABT_BYTE && dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,8 , reg - GICD_IPRIORITYRnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; +vgic_lock_rank (v, rank, flags); + ipriorityr = &rank->ipriorityr[REG_RANK_INDEX (8 , reg - GICD_IPRIORITYRnE, +DABT_WORD )]; + priority =ACCESS_ONCE (*ipriorityr); +vreg_reg32_update (&priority, r, info); +ACCESS_ONCE (*ipriorityr) = priority; +vgic_unlock_rank (v, rank, flags); +return 1 ; + } +case VRANGE32 (GICD_ICFGRnE, GICD_ICFGRnEN): +if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_ext_rank_offset (v,2 , reg - GICD_ICFGRnE,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; +vgic_lock_rank (v, rank, flags); +vreg_reg32_update (&rank->icfg[REG_RANK_INDEX (2 , reg - GICD_ICFGRnE, +DABT_WORD )], + r, info); +vgic_unlock_rank (v, rank, flags); +return 1 ; +#endif +default : printk(XENLOG_G_ERR "%pv: %s: unhandled write r%d=%"PRIregister" offset %#08x\n",@@ -1129,6 +1285,16 @@ static int vgic_v3_distr_mmio_read(struct vcpu *v, mmio_info_t *info, typer |=GICD_TYPE_LPIS ; typer |= (v->domain->arch.vgic.intid_bits -1 ) <<GICD_TYPE_ID_BITS_SHIFT ; +#ifdef CONFIG_GICV3_ESPI +if ( v->domain->arch.vgic.nr_espis >0 ) + { +/* Set eSPI support bit for the domain */ + typer |=GICD_TYPER_ESPI ; +/* Set ESPI range bits */ + typer |= (DIV_ROUND_UP (v->domain->arch.vgic.nr_espis,32 ) -1 ) + <<GICD_TYPER_ESPI_RANGE_SHIFT ; + } +#endif *r =vreg_reg32_extract (typer, info);@@ -1194,6 +1360,18 @@ static int vgic_v3_distr_mmio_read(struct vcpu *v, mmio_info_t *info,case VRANGE32 (GICD_IPRIORITYR ,GICD_IPRIORITYRN ):case VRANGE32 (GICD_ICFGR ,GICD_ICFGRN ):case VRANGE32 (GICD_IGRPMODR ,GICD_IGRPMODRN ): + +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_IGROUPRnE, GICD_IGROUPRnEN): +case VRANGE32 (GICD_ISENABLERnE, GICD_ISENABLERnEN): +case VRANGE32 (GICD_ICENABLERnE, GICD_ICENABLERnEN): +case VRANGE32 (GICD_ISPENDRnE, GICD_ISPENDRnEN): +case VRANGE32 (GICD_ICPENDRnE, GICD_ICPENDRnEN): +case VRANGE32 (GICD_ISACTIVERnE, GICD_ISACTIVERnEN): +case VRANGE32 (GICD_ICACTIVERnE, GICD_ICACTIVERnEN): +case VRANGE32 (GICD_IPRIORITYRnE, GICD_IPRIORITYRnEN): +case VRANGE32 (GICD_ICFGRnE, GICD_ICFGRnEN): +#endif /* * Above all register are common with GICR and GICD * Manage in common @@ -1216,7 +1394,11 @@ static int vgic_v3_distr_mmio_read(struct vcpu *v, mmio_info_t *info,/* Replaced with GICR_ISPENDR0. So ignore write */ goto read_as_zero_32; +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (0x3100 ,0x60FC ): +#else case VRANGE32 (0x0F30 ,0x60FC ): +#endif goto read_reserved;case VRANGE64 (GICD_IROUTER32 ,GICD_IROUTER1019 ):@@ -1235,8 +1417,30 @@ static int vgic_v3_distr_mmio_read(struct vcpu *v, mmio_info_t *info,return 1 ; } +#ifdef CONFIG_GICV3_ESPI +case VRANGE64 (GICD_IROUTERnE, GICD_IROUTERnEN): + { +uint64_t irouter; + +if ( !vgic_reg64_check_access (dabt) ) goto bad_width; + rank =vgic_ext_rank_offset (v,64 , gicd_reg - GICD_IROUTERnE, +DABT_DOUBLE_WORD ); +if ( rank ==NULL ) goto read_as_zero; +vgic_lock_rank (v, rank, flags); + irouter =vgic_fetch_irouter (rank, gicd_reg - GICD_IROUTERnE); +vgic_unlock_rank (v, rank, flags); + + *r =vreg_reg64_extract (irouter, info); + +return 1 ; + } +#endif +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (0xA004 ,0xBFFC ): +#else case VRANGE32 (0x7FE0 ,0xBFFC ): +#endif goto read_reserved;case VRANGE32 (0xC000 ,0xFFCC ):@@ -1382,6 +1586,18 @@ static int vgic_v3_distr_mmio_write(struct vcpu *v, mmio_info_t *info,case VRANGE32 (GICD_IPRIORITYR ,GICD_IPRIORITYRN ):case VRANGE32 (GICD_ICFGR ,GICD_ICFGRN ):case VRANGE32 (GICD_IGRPMODR ,GICD_IGRPMODRN ): + +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (GICD_IGROUPRnE, GICD_IGROUPRnEN): +case VRANGE32 (GICD_ISENABLERnE, GICD_ISENABLERnEN): +case VRANGE32 (GICD_ICENABLERnE, GICD_ICENABLERnEN): +case VRANGE32 (GICD_ISPENDRnE, GICD_ISPENDRnEN): +case VRANGE32 (GICD_ICPENDRnE, GICD_ICPENDRnEN): +case VRANGE32 (GICD_ISACTIVERnE, GICD_ISACTIVERnEN): +case VRANGE32 (GICD_ICACTIVERnE, GICD_ICACTIVERnEN): +case VRANGE32 (GICD_IPRIORITYRnE, GICD_IPRIORITYRnEN): +case VRANGE32 (GICD_ICFGRnE, GICD_ICFGRnEN): +#endif /* Above registers are common with GICR and GICD * Manage in common */ return __vgic_v3_distr_common_mmio_write("vGICD", v, info,@@ -1405,7 +1621,11 @@ static int vgic_v3_distr_mmio_write(struct vcpu *v, mmio_info_t *info,if ( dabt.size !=DABT_WORD ) goto bad_width;return 0 ; +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (0x3100 ,0x60FC ): +#else case VRANGE32 (0x0F30 ,0x60FC ): +#endif goto write_reserved;case VRANGE64 (GICD_IROUTER32 ,GICD_IROUTER1019 ):@@ -1419,12 +1639,34 @@ static int vgic_v3_distr_mmio_write(struct vcpu *v, mmio_info_t *info,vgic_lock_rank (v, rank, flags); irouter =vgic_fetch_irouter (rank, gicd_reg -GICD_IROUTER );vreg_reg64_update (&irouter, r, info); -vgic_store_irouter (v->domain, rank, gicd_reg -GICD_IROUTER , irouter); +vgic_store_irouter (v->domain, rank, gicd_reg -GICD_IROUTER , irouter, false); +vgic_unlock_rank (v, rank, flags); +return 1 ; + } + +#ifdef CONFIG_GICV3_ESPI +case VRANGE64 (GICD_IROUTERnE, GICD_IROUTERnEN): + { +uint64_t irouter; + +if ( !vgic_reg64_check_access (dabt) ) goto bad_width; + rank =vgic_ext_rank_offset (v,64 , gicd_reg - GICD_IROUTERnE, +DABT_DOUBLE_WORD ); +if ( rank ==NULL ) goto write_ignore; +vgic_lock_rank (v, rank, flags); + irouter =vgic_fetch_irouter (rank, gicd_reg - GICD_IROUTERnE); +vreg_reg64_update (&irouter, r, info); +vgic_store_irouter (v->domain, rank, gicd_reg - GICD_IROUTERnE, irouter, true);vgic_unlock_rank (v, rank, flags);return 1 ; } +#endif +#ifdef CONFIG_GICV3_ESPI +case VRANGE32 (0xA004 ,0xBFFC ): +#else case VRANGE32 (0x7FE0 ,0xBFFC ): +#endif goto write_reserved;case VRANGE32 (0xC000 ,0xFFCC ):
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v2 04/10] xen/arm/irq: add handling for IRQs in the eSPI range
In reply to Julien GrallQuoted 27 lines · Julien Grall
Quoted 26 lines · Volodymyr Babchuk
Quoted 24 lines · Julien Grall
Hi,
Quoted 12 lines · Volodymyr Babchuk
Quoted 10 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 4 lines
I don't think that it is a good idea to hide this feature under
Kconfig
option, as this will increase number of different build variants. I believe that runtime check for GICD_TYPER.ESPI should besufficient,> but maintainers can correct me there.
I haven't seen many board with ESPI available. So I think it would be better if this is under a
Kconfigbecause not everyone may want to have the code.
Quoted 6 lines
Quoted 1 line
Probably, we can expect more in the future...
Well yes. But I was under the impression this the preferred approach. See the discussion about disabling 32-bit support on 64-bit:
Ah yes, safety certification. Welp, can't argue with that.
Quoted 7 lines
Quoted 4 lines
Anyways, after reviewing
all patches in the series, I can see that code will be littered with #ifdefCONFIG_GICV3_ESPI, which, probably, not a good thing.The solution is to provide wrappers to reduce the number of #ifdef. I haven't checked all the places.
Yes, I was also thinking about that, but I got an impression, that in many cases it will be hard to provide such wrappers. Anyways, something is needs to be done here.
[...]
Quoted 6 lines
Quoted 4 lines
As a bonus point, we can't leave this pointer
present even ifCONFIG_GICV3_ESPI=n, which will simplify some code in latter patches.Did you intend to say "We can leave" rather than "we can't leave"?
Correct
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v2 07/10] xen/arm: gicv3: modify ICH_LR_PHYSICAL_MASK to allow eSPI processing
In reply to Volodymyr BabchukHi Volodymyr,
Quoted 5 lines · Volodymyr Babchuk
Hi Leonid,
Leonid Komarianskyi <[email protected]> writes:
Quoted 10 lines
Quoted 5 lines
To properly deactivate guest interrupts 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 to0x13FF.I am not sure how this supposed to work. According to the arch specification, pINTID field in ICH_LR<n>_EL2 is only 12 bits wide.
Thank you for your review.
According to the specification, the pINTID field in ICH_LR<n>_EL2 is 13 bits wide ([44:32] bits):
Quoted 4 lines
A hardware physical identifier is only required in List Registers for interrupts that require deactivation. This means only 13 bits of Physical INTID are required, regardless of the number specified by ICC_CTLR_EL1.IDbits.
0x13FF is a 13-bit number that fits into the corresponding register field and covers the maximum eSPI INTID value - 5119.
Best regards,
Leonid
Re: [PATCH v2 09/10] xen/arm: domain_build: adjust Dom0 IRQ handling to support eSPIs
In reply to Volodymyr BabchukHi Volodymyr,
Quoted 58 lines · Volodymyr Babchuk
Quoted 53 lines · Leonid Komarianskyi
The Dom0 configuration logic in
create_dom0()has been updated to account for extended SPIs when supported by the hardware and enabled withCONFIG_GICV3_ESPI. These changes ensure the proper calculation of the maximum number of SPIs and eSPIs available for Dom0.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 limited at 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 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 now.Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- no changes--- xen/arch/arm/domain_build.c | 10 ++++++++++ xen/arch/arm/include/asm/vgic.h | 11 +++++++++++ 2 files changed, 21 insertions(+)xen/arch/arm/domain_build.c +10
-0@@ -2055,6 +2055,16 @@ 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 ; +#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 overwrite the nr_spis with the +* maximum available INTID from eSPI range. In that case, the number of regular SPIs will +* be adjusted to the maximum value during vGIC initialization. +*/ +if (gic_number_espis () >0 ) + dom0_cfg.arch.nr_spis =VGIC_DEF_NR_ESPIS ; +#endif dom0_cfg.arch.tee_type =tee_get_type (); dom0_cfg.max_vcpus =dom0_max_vcpus ();xen/arch/arm/include/asm/vgic.h +0
-0@@ -353,6 +353,17 @@ 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)
Quoted 11 lines
xen/arch/arm/include/asm/vgic.h extern void vgic_check_inflight_irqs_pending(struct vcpu *v, · line 364
Quoted 9 lines
xen/arch/arm/include/asm/vgic.h +9
-0+#ifdef CONFIG_GICV3_ESPI +/* +* Returns the maximum eSPI INTID subtracted by 32. For non-Dom0 domains, the +* toolstack applies the same adjustment to cover local IRQs. 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. +*/ +#define VGIC_DEF_NR_ESPIS (ESPI_BASE_INTID + min(gic_number_espis(), 1024U) - 32)Name of the define is wrong, as it is not number of eSPIs. Actually, this is maximum SPI (including eSPIs) number.
Thank you for your review.
Would it be okay if I rename this macro to VGIC_DEF_MAX_SPI?
Quoted 7 lines
xen/arch/arm/include/asm/vgic.h extern void vgic_check_inflight_irqs_pending(struct vcpu *v, · line 369
Quoted 6 lines
xen/arch/arm/include/asm/vgic.h +2
-0+#endif +extern bool vgic_is_valid_irq (struct domain *d,unsigned int virq);static inline bool vgic_is_shared_irq (struct domain *d,unsigned int virq)
Best regards,
Leonid
Re: [PATCH v2 02/10] xen/arm: gic: implement helper functions for INTID checks
In reply to Julien GrallHi Volodymyr and Julien,
Thank you for your comments and for your time.
Quoted 70 lines · Julien Grall
Hi,
Quoted 67 lines · Volodymyr Babchuk
Quoted 55 lines · Leonid Komarianskyi
Introduced two new helper functions:
gic_is_valid_irqandgic_is_shared_irq. 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.
Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- introduced this patch
---
xen/arch/arm/gic.c | 2 +-
xen/arch/arm/include/asm/gic.h| 9 +++++++++
xen/arch/arm/irq.c | 2 +-3 files changed, 11 insertions(+), 2 deletions(-)xen/arch/arm/gic.c +0
-0@@ -111,7 +111,7 @@ 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 */
+ ASSERT(gic_is_valid_irq(desc->irq));/* Can't route interrupts that don't exist */
ASSERT(test_bit(_IRQ_DISABLED, &desc->status)); ASSERT(spin_is_locked(&desc->lock));xen/arch/arm/include/ renamed from xen/arch/arm/include/asm/gic.h +0
-0
asm/gic.h
index541f0eeb80..ac0b7b783e100644xen/arch/arm/include/asm/gic.h extern void gic_dump_vgic_info(struct vcpu *v); · line 308
Quoted 3 lines
xen/arch/arm/include/asm/gic.h +1
-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_irq (unsigned int irq)We need to do something about naming, because this function completely ignores presence of LPIs. What I mean, that it will return "false" for any LPI, while you can't argue that LPI is a valid interrupt :) I understand that this is expected behavior by current callers, but the function name is misleading.
Quoted 5 lines
Quoted 2 lines
Name like "
gic_is_valid_non_lpi()" seems to mouthful, but it is the best I can come up with.AFAIU, there is no interrupt lines for LPIs. So what about
gic_is_valid_line()?
Oh, thank you. It would be much better to name the function gic_is_valid_line(), so I will rename it in V3.
Quoted 12 lines
Quoted 11 lines
xen/arch/arm/include/asm/gic.h extern void gic_dump_vgic_info(struct vcpu *v); · line 316
Quoted 8 lines
xen/arch/arm/include/asm/gic.h +7
-0+{ + return irq < gic_number_lines(); +} + +static inline bool gic_is_shared_irq (unsigned int irq) +{ + return (irq >= NR_LOCAL_IRQS && gic_is_valid_irq(irq));Again, because of misleading name of
gic_is_valid_irq()it may seem that this function will return "true" for LPIs as well...
Quoted 6 lines
Even if we rename
gic_is_valid_irq(), the function name would be misleading because LPIs are shared. I think it would be better namedgic_is_spi(...);Cheers,
Okay, I will rename gic_is_shared_irq to gic_is_spi in V3.
Best regards,
Leonid
Re: [PATCH v2 03/10] xen/arm: vgic: implement helper functions for virq checks
In reply to Volodymyr BabchukHi Volodymyr,
Thank you for you comment.
Quoted 112 lines · Volodymyr Babchuk
Quoted 98 lines · Leonid Komarianskyi
Introduced two new helper functions for vGIC:
vgic_is_valid_irqandvgic_is_shared_irq. The functions are similar to the newly introducedgic_is_valid_irqandgic_is_shared_irq, 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_irqmay affect existing functionality, as it currently checks whether the vIRQ is less than or equal tovgic_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 thanvgic_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.Signed-off-by Leonid Komarianskyi <[email protected]>---
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 ++++++++-- 4 files changed, 18 insertions(+), 6 deletions(-)xen/arch/arm/gic.c +1
-2@@ -133,8 +133,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_shared_irq (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_irq (struct domain *d,unsigned int virq); + +static inline bool vgic_is_shared_irq (struct domain *d,unsigned int virq) +{ +return (virq >=NR_LOCAL_IRQS &&vgic_is_valid_irq (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_irq (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_shared_irq (d, virq) )return -EINVAL ; desc =vgic_get_hw_irq_desc (d,NULL , virq);xen/arch/arm/vgic.c +0
-0xen/arch/arm/vgic.c line 28
Quoted 5 lines
xen/arch/arm/vgic.c +2
-0@@ -24,6 +24,12 @@#include <asm/gic.h> #include <asm/vgic.h> + +bool vgic_is_valid_irq (struct domain *d,unsigned int virq)I have the same comment as for the previous patch. This function completely ignores LPIs presence, while you can't argue that LPIs as valid. Again, function callers are expecting this behavior, so this is fine, but function name should better reflect its behavior.
Quoted 2 lines
[...]
Would it be okay to rename these functions as proposed in the previous patch discussion:vgic_is_valid_irq -> vgic_is_valid_linevgic_is_shared_irq -> vgic_is_spi?
Or, in the case of vgic, is it not a good idea to use the "line" suffix because vgic does not have physical interrupt lines? Would it be better to rename it to vgic_is_valid_non_lpi instead?
Best regards,
Leonid
Re: [PATCH v2 08/10] xen/arm: vgic: add resource management for extended SPIs
In reply to Volodymyr BabchukHi Volodymyr,
Thank you for your review comments.
Quoted 105 lines · Volodymyr Babchuk
Quoted 102 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.
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]>---
Changes 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 | 18 ++++ xen/arch/arm/vgic.c | 145 ++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+)xen/arch/arm/include/asm/vgic.h +18
-0@@ -146,6 +146,10 @@ struct vgic_dist {int nr_spis;/* Number of SPIs */ unsigned long *allocated_irqs;/* bitmap of IRQs allocated */ struct vgic_irq_rank *shared_irqs; +#ifdef CONFIG_GICV3_ESPI +struct vgic_irq_rank *ext_shared_irqs; +int nr_espis;/* Number of extended SPIs */ +#endif /* * SPIs are domain global, SGIs and PPIs are per-VCPU and stored in * struct arch_vcpu. @@ -243,6 +247,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) +#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) +#endif +#define vgic_lock (v) spin_lock_irq(&(v)->domain->arch.vgic.lock)#define vgic_unlock (v) spin_unlock_irq(&(v)->domain->arch.vgic.lock)@@ -302,6 +314,12 @@ extern struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v,unsigned int b, unsigned int n, unsigned int s); +#ifdef CONFIG_GICV3_ESPI +extern struct vgic_irq_rank *vgic_ext_rank_offset (struct vcpu *v, +unsigned int b, +unsigned int n, +unsigned int s); +#endif 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.c +5
-0@@ -27,9 +27,26 @@bool vgic_is_valid_irq (struct domain *d,unsigned int virq) { +#ifdef CONFIG_GICV3_ESPI +if ( virq >=ESPI_BASE_INTID && virq <ESPI_IDX2INTID (d->arch.vgic.nr_espis) ) +return true; +#endif +return virq <vgic_num_irqs (d); }
Quoted 13 lines
xen/arch/arm/vgic.c line 46
Quoted 9 lines
xen/arch/arm/vgic.c +9
-0+#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) );I am pretty sure that max line length in 80 symbols, and here you have more. As well in couple of other places below.
Previously, I had seen code in the mainline with lines longer than 80 characters, so I thought the maximum length was 100.. However, I rechecked the CODING_STYLE file in Xen and it indeed contains the following:
Quoted 2 lines
Lines should be less than 80 characters in length. Long lines should be split at sensible places and the trailing portions indented.
So, yes, my mistake. I will revise the code in the patch series and fix the places where the line length exceeds 80 characters.
Quoted 68 lines
Quoted 68 lines
xen/arch/arm/vgic.c +40
-0+} +#endif +static inline struct vgic_irq_rank *vgic_get_rank (struct vcpu *v,unsigned int rank) {@@ -37,6 +54,10 @@ 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]; +#ifdef CONFIG_GICV3_ESPI + else if ( is_valid_espi_rank(v->domain, rank) ) + return &v->domain->arch.vgic.ext_shared_irqs[EXT_RANK_NUM2IDX(rank)]; +#endif else return NULL; }@@ -53,6 +74,16 @@ struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, unsigned int b,return vgic_get_rank (v, rank); } +#ifdef CONFIG_GICV3_ESPI +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 ); +} +#endif +struct vgic_irq_rank *vgic_rank_irq (struct vcpu *v,unsigned int irq) {unsigned int rank = irq /32 ;@@ -117,6 +148,29 @@ int domain_vgic_register(struct domain *d, unsigned int *mmio_count)return 0 ; } +#ifdef CONFIG_GICV3_ESPI +static int init_vgic_espi (struct domain *d) +{ +int i; + +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 =0 ; i < d->arch.vgic.nr_espis; i++ ) +vgic_init_pending_irq (&d->arch.vgic.pending_irqs[i + d->arch.vgic.nr_spis],ESPI_IDX2INTID (i)); + +for ( i =0 ; i <DOMAIN_NR_EXT_RANKS (d); i++ ) +vgic_rank_init (&d->arch.vgic.ext_shared_irqs[i], i,0 ); + +return 0 ; +} +#endif +int domain_vgic_init (struct domain *d,unsigned int nr_spis) {int i;@@ -131,6 +185,30 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis)*/ nr_spis =ROUNDUP (nr_spis,32 );
Quoted 13 lines
xen/arch/arm/vgic.c int domain_vgic_init(struct domain *d, unsigned int nr_spis) · line 197
Quoted 10 lines
xen/arch/arm/vgic.c +10
-0+#ifdef CONFIG_GICV3_ESPI +if ( nr_spis >ESPI_MAX_INTID ) +return -EINVAL ; + +if (is_espi (nr_spis) ) + { +/* +* During domain creation, the toolstack specifies the maximum INTID, +* which is defined in the domain config subtracted by 32. To compute the +* actual number of eSPI that will be usable for, add back 32. I think, according to this, your if (
is_espi()) check is wrong. Should you add 32 here as well?
Oh, yes, the verifications above do not take into account this subtraction of 32, so they will fail for the first 32 eSPI INTIDs and mistakenly allow processing INTIDs greater than 5119. I will fix that in V3 by adding 32 to nr_spis if checks and moving this comment above the if checks.
Quoted 150 lines
Quoted 150 lines
xen/arch/arm/vgic.c +81
-0+*/ + d->arch.vgic.nr_espis =min (nr_spis -ESPI_BASE_INTID +32 ,1024U ); +/* Verify if GIC HW can handle provided INTID */ +if ( d->arch.vgic.nr_espis >gic_number_espis () ) +return -EINVAL ; +/* Set the maximum available number for defult SPI to pass the next check */ + nr_spis = VGIC_DEF_NR_SPIS; + }else + { +/* Domain will use the regular SPI range */ + d->arch.vgic.nr_espis =0 ; + } +#endif +/* Limit the number of virtual SPIs supported to (1020 - 32) = 988 */ if ( nr_spis > (1020 -NR_LOCAL_IRQS ) )return -EINVAL ;@@ -145,7 +223,12 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis)return -ENOMEM ; d->arch.vgic.pending_irqs = +#ifdef CONFIG_GICV3_ESPI + xzalloc_array(struct pending_irq, d->arch.vgic.nr_spis + + d->arch.vgic.nr_espis); +#else xzalloc_array(struct pending_irq, d->arch.vgic.nr_spis); +#endif if ( d->arch.vgic.pending_irqs ==NULL )return -ENOMEM ;@@ -156,12 +239,23 @@ 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 ); +#ifdef CONFIG_GICV3_ESPI + ret =init_vgic_espi (d); +if ( ret ) +return ret; +#endif + ret = d->arch.vgic.handler->domain_init (d);if ( ret )return ret; d->arch.vgic.allocated_irqs = +#ifdef CONFIG_GICV3_ESPI + xzalloc_array(unsigned long, BITS_TO_LONGS(vgic_num_irqs(d) + + d->arch.vgic.nr_espis)); +#else xzalloc_array(unsigned long, BITS_TO_LONGS(vgic_num_irqs(d))); +#endif if ( !d->arch.vgic.allocated_irqs )return -ENOMEM ;@@ -195,9 +289,27 @@ void domain_vgic_free(struct domain *d) } } +#ifdef CONFIG_GICV3_ESPI +for ( i =0 ; i < (d->arch.vgic.nr_espis); i++ ) + { +struct pending_irq *p =spi_to_pending (d,ESPI_IDX2INTID (i)); + +if ( p->desc ) + { + ret =release_guest_irq (d, p->irq); +if ( ret ) +dprintk (XENLOG_G_WARNING ,"d%u: Failed to release virq %u ret = %d\n" , + d->domain_id, p->irq, ret); + } + } +#endif +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); }@@ -331,6 +443,17 @@ void arch_move_irqs(struct vcpu *v)if ( v_target == v && !test_bit (GIC_IRQ_GUEST_MIGRATING , &p->status) )irq_set_affinity (p->desc, cpu_mask); } + +#ifdef CONFIG_GICV3_ESPI +for ( i =ESPI_BASE_INTID ; i < (d)->arch.vgic.nr_espis; i++ ) + { + v_target =vgic_get_target_vcpu (v, i); + p =irq_to_pending (v_target, i); + +if ( v_target == v && !test_bit (GIC_IRQ_GUEST_MIGRATING , &p->status) ) +irq_set_affinity (p->desc, cpu_mask); + } +#endif }void vgic_disable_irqs (struct vcpu *v,uint32_t r,unsigned int n)@@ -538,6 +661,10 @@ struct pending_irq *irq_to_pending(struct vcpu *v, unsigned int irq) n = &v->arch.vgic.pending_irqs[irq]; else if ( is_lpi(irq) ) n = v->domain->arch.vgic.handler->lpi_to_pending (v->domain, irq); +#ifdef CONFIG_GICV3_ESPI + else if ( is_espi(irq) ) + n = &v->domain->arch.vgic.pending_irqs[ESPI_INTID2IDX (irq) + v->domain->arch.vgic.nr_spis]; +#endif else n = &v->domain->arch.vgic.pending_irqs[irq -32 ];return n;@@ -547,6 +674,14 @@ struct pending_irq *spi_to_pending(struct domain *d, unsigned int irq) {ASSERT (irq >=NR_LOCAL_IRQS ); +#ifdef CONFIG_GICV3_ESPI +if (is_espi (irq) ) + { + irq =ESPI_INTID2IDX (irq) + d->arch.vgic.nr_spis; +return &d->arch.vgic.pending_irqs[irq]; + } +#endif +return &d->arch.vgic.pending_irqs[irq -32 ]; }@@ -668,6 +803,11 @@ bool vgic_reserve_virq(struct domain *d, unsigned int virq)if ( !vgic_is_valid_irq (d, virq) )return false; +#ifdef CONFIG_GICV3_ESPI +if (is_espi (virq) ) +return !test_and_set_bit (ESPI_INTID2IDX (virq) +vgic_num_irqs (d), d->arch.vgic.allocated_irqs); +#endif +return !test_and_set_bit (virq, d->arch.vgic.allocated_irqs); }@@ -686,6 +826,11 @@ int vgic_allocate_virq(struct domain *d, bool spi) { first =32 ; end =vgic_num_irqs (d); +#ifdef CONFIG_GICV3_ESPI +/* Take into account extended SPI range */ + end += d->arch.vgic.nr_espis; +#endif + }
Quoted 2 lines
xen/arch/arm/vgic.c int vgic_allocate_virq(struct domain *d, bool spi) · line 836
Quoted 1 line
xen/arch/arm/vgic.c +0
-0/*
Best regards,
Leonid
Re: [PATCH v2 01/10] xen/arm: gicv3: refactor obtaining GIC addresses for common operations
In reply to Julien GrallHi Julien,
Thank you for your close review.
Quoted 13 lines · Julien Grall
Hi Leonid,
Quoted 10 lines · Leonid Komarianskyi
Currently, 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.Signed-off-by Leonid Komarianskyi <[email protected]>
Quoted 8 lines
Quoted 3 lines
---
Changes in V2:
- no changesI am a bit surprised this is just saying no changes given the discussion in v1. I feel you should have pinged on the v1 to close off the discussion before sending v2.
Sorry, my bad. I should have reached out to you and clarified the unfinished discussion in V1. I just wanted to publish the changes in V2 that were agreed upon in V1. But yes, I understand - it was a bad idea to push V2 without completing the discussion in V1. I apologize for that.
Quoted 3 lines
While I understand your point and could accept we consolidate the code...
Thank you for your understanding and acceptance :) It really simplifies the changes in the next patches.
Quoted 63 lines
Quoted 49 lines
---
xen/arch/arm/gic-v3.c | 99 ++++++++++++++++++++++------------xen/arch/arm/include/asm/irq.h| 1 +2 files changed, 67 insertions(+), 33 deletions(-)xen/arch/arm/gic-v3.c +36
-0@@ -445,17 +445,62 @@ static void gicv3_dump_state(const struct vcpu *v) } } +static void __iomem *get_addr_by_offset (struct irq_desc *irqd,u32 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:xen/arch/arm/gic-v3.c static void gicv3_dump_state(const struct vcpu *v) · line 493
Quoted 10 lines
xen/arch/arm/gic-v3.c +10
-0+ return (GICD + GICD_IPRIORITYR + irqd->irq); + default: + break; + } + default: + break; + } + + /* Something went wrong, we shouldn't be able to reach here */ + panic("Invalid offset 0x%x for IRQ#%d", offset, irqd->irq);... I still quite concerned about using panic here. We need to try to handle the error more gracefully in production.
Quoted 2 lines
Cheers,
I was thinking about this again, and maybe it would be better to change the panic into simply printing an error using printk(XENLOG_G_ERR ...) and adding proper checks to ensure the return value is not NULL in the callers.
Also, in the case of gicv3_peek_irq, which must return a boolean value (due to the generic API for gicv3_read_pending_state), we could return false with an additional warning message that we are unable to read the actual value due to incorrect parameters; therefore, we return false. What do you think about this approach?
Best regards,
Leonid
Re: [PATCH v2 01/10] xen/arm: gicv3: refactor obtaining GIC addresses for common operations
Hi Leonid,
Quoted 63 lines · Leonid Komarianskyi
Thank you for your close review.>>> ---
Quoted 62 lines
Quoted 48 lines
xen/arch/arm/gic-v3.c | 99 ++++++++++++++++++++++------------ xen/arch/arm/include/asm/irq.h | 1 + 2 files changed, 67 insertions(+), 33 deletions(-)xen/arch/arm/gic-v3.c +36
-0@@ -445,17 +445,62 @@ static void gicv3_dump_state(const struct vcpu *v) } } +static void __iomem *get_addr_by_offset (struct irq_desc *irqd,u32 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:xen/arch/arm/gic-v3.c static void gicv3_dump_state(const struct vcpu *v) · line 493
Quoted 10 lines
xen/arch/arm/gic-v3.c +10
-0+ return (GICD + GICD_IPRIORITYR + irqd->irq); + default: + break; + } + default: + break; + } + + /* Something went wrong, we shouldn't be able to reach here */ + panic("Invalid offset 0x%x for IRQ#%d", offset, irqd->irq);... I still quite concerned about using panic here. We need to try to handle the error more gracefully in production.
Quoted 7 lines
Quoted 2 lines
Cheers,
I was thinking about this again, and maybe it would be better to change the panic into simply printing an error using
printk(XENLOG_G_ERR ...)and adding proper checks to ensure the return value is not NULL in the callers.
Given the error is not meant to happen, after the printk() I would add an ASSERT_UNREACHABLE() so we can catch issue in DEBUG build more easily.
Quoted 5 lines
Also, in the case of
gicv3_peek_irq, which must return a boolean value (due to the generic API forgicv3_read_pending_state), we could return false with an additional warning message that we are unable to read the actual value due to incorrect parameters; therefore, we return false. What do you think about this approach?
It makes sense to read false as the interrupt technically doesn't exist. But I don't think we should add an extra warning. The one in get_addr_by_offset() should be sufficient.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 10/10] xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers
In reply to Volodymyr BabchukHi Volodymyr,
Thank you for your close review.
Quoted 31 lines · Volodymyr Babchuk
Hi Leonid,
Quoted 26 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.Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- add missing rank index conversion for pending and inflight irqs--- xen/arch/arm/vgic-v3.c | 248 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 245 insertions(+), 3 deletions(-)
Quoted 14 lines
xen/arch/arm/vgic-v3.c static uint64_t vgic_fetch_irouter(struct vgic_irq_rank *rank, · line 114
Quoted 10 lines
xen/arch/arm/vgic-v3.c +1
-1@@ -111,7 +111,7 @@ static uint64_t vgic_fetch_irouter(struct vgic_irq_rank *rank,* Note the offset will be aligned to the appropriate boundary. */ static void vgic_store_irouter (struct domain *d,struct vgic_irq_rank *rank, -unsigned int offset,uint64_t irouter) +unsigned int offset,uint64_t irouter,bool espi)I am wondering: maybe it is better to pass virq instead of offset into this function? In that case you can get rid of espi parameter.
Yes, it makes sense, because in any case we recalculate the offset later, after getting the virq:
Quoted 2 lines
/* Get the index in the rank */ offset = virq & INTERRUPT_RANK_MASK;
And as a bonus, I can get rid of the espi parameter. However, it requires the caller to calculate the virq by itself.
If applicable, I can add one more preparation patch in V3 before actually implementing eSPI with such changes. Would that be better?
Quoted 5 lines
Quoted 5 lines
xen/arch/arm/vgic-v3.c +0
-0{struct vcpu *new_vcpu, *old_vcpu;unsigned int virq;@@ -123,7 +123,8 @@ static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank,* The IROUTER0-31, used for SGIs/PPIs, are reserved and should
Quoted 9 lines
xen/arch/arm/vgic-v3.c static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank, · line 127
Quoted 5 lines
xen/arch/arm/vgic-v3.c +2
-1* never call this function. */ -ASSERT (virq >=32 ); +if ( !espi ) +ASSERT (virq >=32 );better to write
ASSERT (!espi & (virq>=32))
I agree with that, it looks much better. I will change it in V3 or drop at all if it would be okay to use virq as a parameter.
Quoted 1 line
and probably you need symmetrical ASSERT for espi == true
This is not needed for eSPI because, unlike regular SPIs that have indexes starting from 32, eSPI INTIDs start from 4096 and cover all 1024 IRQ lines.
Quoted 16 lines
xen/arch/arm/vgic-v3.c static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank, · line 154
Quoted 12 lines
xen/arch/arm/vgic-v3.c +5
-0/* Get the index in the rank */ offset = virq &INTERRUPT_RANK_MASK ;@@ -146,6 +147,11 @@ static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank,/* Only migrate the IRQ if the target vCPU has changed */ if ( new_vcpu != old_vcpu ) { +#ifdef CONFIG_GICV3_ESPI +/* Convert virq index to eSPI range */ +if ( espi ) + virq =ESPI_IDX2INTID (virq); +#endif If you define
ESPI_IDX2INTID()uncoditionally, you can get rid of #ifdefCONFIG_GICV3_ESPIhere
Actually, ESPI_IDX2INTID is defined under ifdef condition:
Quoted 7 lines
#ifdef
CONFIG_GICV3_ESPI
#defineESPI_BASE_INTID4096
#defineESPI_MAX_INTID5119#define
ESPI_INTID2IDX(intid)((intid) -ESPI_BASE_INTID)
#defineESPI_IDX2INTID(idx)((idx) +ESPI_BASE_INTID)
#endif
So it should be used under CONFIG_GICV3_ESPI, like in other places.
Quoted 11 lines
xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, · line 694
Quoted 8 lines
xen/arch/arm/vgic-v3.c +1
-0if (vgic_migrate_irq (old_vcpu, new_vcpu, virq) )write_atomic (&rank->vcpu[offset], new_vcpu->vcpu_id); }@@ -685,6 +691,9 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, {case VRANGE32 (GICD_IGROUPR ,GICD_IGROUPRN ):case VRANGE32 (GICD_IGRPMODR ,GICD_IGRPMODRN ): +#ifdef CONFIG_GICV3_ESPI Do you really need ifdef here?
Oh, yes, this ifdef is redundant because, without CONFIG_GICV3_ESPI enabled, we cannot reach this function with eSPI-specific offsets from the caller.
So, yes, I will remove this ifdef in V3.
Quoted 4 lines
Quoted 2 lines
xen/arch/arm/vgic-v3.c +2
-0+case VRANGE32 (GICD_IGROUPRnE, GICD_IGROUPRnEN): +#endif
Quoted 10 lines
xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, · line 722
Quoted 8 lines
xen/arch/arm/vgic-v3.c +1
-0/* We do not implement security extensions for guests, read zero */ if ( dabt.size !=DABT_WORD ) goto bad_width; goto read_as_zero;@@ -710,11 +719,19 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v,/* Read the pending status of an IRQ via GICD/GICR is not supported */ case VRANGE32 (GICD_ISPENDR ,GICD_ISPENDRN ):case VRANGE32 (GICD_ICPENDR ,GICD_ICPENDRN ): +#ifdef CONFIG_GICV3_ESPI Same as here
I will remove it in V3.
Quoted 6 lines
Quoted 6 lines
xen/arch/arm/vgic-v3.c +3
-0+case VRANGE32 (GICD_ISPENDRnE, GICD_ISPENDRnEN): +case VRANGE32 (GICD_ICPENDRnE, GICD_ICPENDRnEN): +#endif goto read_as_zero;
Quoted 7 lines
xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, · line 731
Quoted 4 lines
xen/arch/arm/vgic-v3.c +1
-0/* Read the active status of an IRQ via GICD/GICR is not supported */ case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):case VRANGE32 (GICD_ICACTIVER ,GICD_ICACTIVERN ): +#ifdef CONFIG_GICV3_ESPI ... and here and in all other places
Thank you, that's a really good point. I will revise all the places with ifdefs in this patch and fix them in V3.
Best regards,
Leonid
Re: [PATCH v2 01/10] xen/arm: gicv3: refactor obtaining GIC addresses for common operations
In reply to Julien GrallHi Julien,
Quoted 72 lines · Julien Grall
Hi Leonid,
Quoted 69 lines · Leonid Komarianskyi
Thank you for your close review.>>> ---
Quoted 67 lines
Quoted 50 lines
xen/arch/arm/gic-v3.c | 99 +++++++++++++++++++++
+------------ xen/arch/arm/include/asm/irq.h | 1 + 2 files changed, 67 insertions(+), 33 deletions(-)xen/arch/arm/gic-v3.c +35
-0@@ -445,17 +445,62 @@ static void gicv3_dump_state(const struct vcpu *v) } } +static void __iomem *get_addr_by_offset (struct irq_desc *irqd,u32 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);xen/arch/arm/gic-v3.c static void gicv3_dump_state(const struct vcpu · line 494
Quoted 10 lines
xen/arch/arm/gic-v3.c +10
-0+ case GICD_IPRIORITYR: + return (GICD + GICD_IPRIORITYR + irqd->irq); + default: + break; + } + default: + break; + } + + /* Something went wrong, we shouldn't be able to reach here */> +
panic("Invalid offset 0x%x for IRQ#%d", offset, irqd->irq);... I still quite concerned about using panic here. We need to try to handle the error more gracefully in production.
Cheers,
Quoted 8 lines
Quoted 4 lines
I was thinking about this again, and maybe it would be better to change the panic into simply printing an error using
printk(XENLOG_G_ERR ...)and adding proper checks to ensure the return value is not NULL in the callers.Given the error is not meant to happen, after the
printk()I would add anASSERT_UNREACHABLE()so we can catch issue in DEBUG build more easily.
Okay, so I will change the panic to printk + ASSERT_UNREACHABLE() in V3. Thank you.
Quoted 6 lines
Quoted 5 lines
Also, in the case of
gicv3_peek_irq, which must return a boolean value (due to the generic API forgicv3_read_pending_state), we could return false with an additional warning message that we are unable to read the actual value due to incorrect parameters; therefore, we return false. What do you think about this approach?
Quoted 6 lines
It makes sense to read false as the interrupt technically doesn't exist. But I don't think we should add an extra warning. The one in
get_addr_by_offset()should be sufficient.Cheers,
Understood, thank you again.
Best regards,
Leonid
Re: [PATCH v2 10/10] xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers
In reply to Oleksandr TyshchenkoHello Oleksandr,
Thank you for your review comments.
Quoted 108 lines · Oleksandr Tyshchenko
On 07.08.25 15:33, Leonid Komarianskyi wrote:
Hello Leonid
Quoted 101 lines
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.Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- add missing rank index conversion for pending and inflight irqs
---
xen/arch/arm/vgic-v3.c| 248 ++++++++++++++++++++++++++++++++++++++++-1 file changed, 245 insertions(+), 3 deletions(-)xen/arch/arm/vgic-v3.c +0
-0@@ -111,7 +111,7 @@ static uint64_t vgic_fetch_irouter(structvgic_irq_rank *rank, * Note the offset will be aligned to the appropriate boundary. */ static void vgic_store_irouter(struct domain *d, struct
vgic_irq_rank*rank,
- unsigned int offset,uint64_tirouter) + unsigned int offset,uint64_tirouter, bool espi)
{
struct vcpu*new_vcpu,*old_vcpu;
unsigned int virq;xen/arch/arm/vgic-v3.c +7
-1@@ -123,7 +123,8 @@ static void vgic_store_irouter(struct domain *d,struct vgic_irq_rank *rank, * The IROUTER0-31, used for SGIs/PPIs, are reserved and should * never call this function. */ - ASSERT(virq >= 32); + if ( !espi ) + ASSERT(virq >= 32); /* Get the index in the rank */ offset = virq & INTERRUPT_RANK_MASK;@@ -146,6 +147,11 @@ static void vgic_store_irouter(struct domain *d,struct vgic_irq_rank *rank, /* Only migrate the IRQ if the target vCPU has changed */ if ( new_vcpu != old_vcpu ) { +#ifdef CONFIG_GICV3_ESPI + /* Convert virq index to eSPI range */ + if ( espi ) + virq = ESPI_IDX2INTID(virq); +#endif if ( vgic_migrate_irq(old_vcpu, new_vcpu, virq) ) write_atomic(&rank->vcpu[offset], new_vcpu->vcpu_id);}
xen/arch/arm/vgic-v3.c +0
-0@@ -685,6 +691,9 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, {case
VRANGE32(GICD_IGROUPR, GICD_IGROUPRN):
caseVRANGE32(GICD_IGRPMODR, GICD_IGRPMODRN):xen/arch/arm/vgic-v3.c +3
-0+#ifdef CONFIG_GICV3_ESPI + case VRANGE32(GICD_IGROUPRnE, GICD_IGROUPRnEN): +#endif /* We do not implement security extensions for guests, read zero */
if ( dabt.size !=DABT_WORD) gotobad_width; gotoread_as_zero;xen/arch/arm/vgic-v3.c +0
-0@@ -710,11 +719,19 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, /* Read the pending status of an IRQ via GICD/GICR is notsupported */
caseVRANGE32(GICD_ISPENDR, GICD_ISPENDRN):
caseVRANGE32(GICD_ICPENDR, GICD_ICPENDRN):xen/arch/arm/vgic-v3.c +4
-0+#ifdef CONFIG_GICV3_ESPI + case VRANGE32(GICD_ISPENDRnE, GICD_ISPENDRnEN): + case VRANGE32(GICD_ICPENDRnE, GICD_ICPENDRnEN): +#endif goto
read_as_zero;
/* Read the active status of an IRQ via GICD/GICR is not supported */
caseVRANGE32(GICD_ISACTIVER, GICD_ISACTIVERN):
caseVRANGE32(GICD_ICACTIVER, GICD_ICACTIVERN):xen/arch/arm/vgic-v3.c +4
-0+#ifdef CONFIG_GICV3_ESPI + case VRANGE32(GICD_ISACTIVERnE, GICD_ISACTIVERnEN): + case VRANGE32(GICD_ICACTIVERnE, GICD_ICACTIVERnEN): +#endif goto
read_as_zero;
caseVRANGE32(GICD_IPRIORITYR, GICD_IPRIORITYRN):xen/arch/arm/vgic-v3.c +0
-0@@ -752,6 +769,61 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, return 1;
Quoted 9 lines
xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, · line 774
Quoted 4 lines
xen/arch/arm/vgic-v3.c +3
-0} +#ifdef CONFIG_GICV3_ESPI + case VRANGE32(GICD_ISENABLERnE, GICD_ISENABLERnEN): + if ( dabt.size != DABT_WORD ) goto bad_width;NIT: If I am not mistaken, the goto should be on the next line (here and in similar places throughout the added code).
I just replicated some existing code with formatting for regular SPIs in eSPI. According to CODING_STYLE, there is no explicit rule against putting such code on one line (or I missed this point). However, in examples for a single-statement block after an if:
Quoted 5 lines
Braces should be omitted for blocks with a single statement. e.g.,
if ( condition )
single_statement();
The single statement is placed on a new line. So, I would prefer to address your nit and add newlines here and in similar places in V3.
Quoted 143 lines
Quoted 121 lines
xen/arch/arm/vgic-v3.c +23
-0+ rank = vgic_ext_rank_offset(v, 1, reg - GICD_ISENABLERnE,DABT_WORD ); + if ( rank == NULL ) goto read_as_zero; + vgic_lock_rank(v, rank, flags); + *r = vreg_reg32_extract(rank->ienable, info); + vgic_unlock_rank(v, rank, flags); + return 1; + + case VRANGE32(GICD_ICENABLERnE, GICD_ICENABLERnEN): + if ( dabt.size != DABT_WORD ) goto bad_width; + rank = vgic_ext_rank_offset(v, 1, reg - GICD_ICENABLERnE,DABT_WORD ); + if ( rank == NULL ) goto read_as_zero; + vgic_lock_rank(v, rank, flags); + *r = vreg_reg32_extract(rank->ienable, info); + vgic_unlock_rank(v, rank, flags); + return 1; + + case VRANGE32(GICD_IPRIORITYRnE, GICD_IPRIORITYRnEN): + { + uint32_t ipriorityr; + uint8_t rank_index; + + if ( dabt.size != DABT_BYTE && dabt.size != DABT_WORD ) goto bad_width; + rank = vgic_ext_rank_offset(v, 8, reg - GICD_IPRIORITYRnE,
DABT_WORD);
+ if ( rank == NULL ) gotoread_as_zero;
+rank_index=REG_RANK_INDEX(8, reg - GICD_IPRIORITYRnE, DABT_WORD);xen/arch/arm/vgic-v3.c +16
-0+ + vgic_lock_rank(v, rank, flags); + ipriorityr = ACCESS_ONCE(rank->ipriorityr[rank_index]); + vgic_unlock_rank(v, rank, flags); + + *r = vreg_reg32_extract(ipriorityr, info); + + return 1; + } + + case VRANGE32(GICD_ICFGRnE, GICD_ICFGRnEN): + { + uint32_t icfgr; + + if ( dabt.size != DABT_WORD ) goto bad_width; + rank = vgic_ext_rank_offset(v, 2, reg - GICD_ICFGRnE,
DABT_WORD);
+ if ( rank == NULL ) gotoread_as_zero;
+vgic_lock_rank(v, rank, flags);
+ icfgr = rank->icfg[REG_RANK_INDEX(2, reg -GICD_ICFGRnE,DABT_WORD)];
+vgic_unlock_rank(v, rank, flags);xen/arch/arm/vgic-v3.c +7
-0+ + *r = vreg_reg32_extract(icfgr, info); + + return 1; + } +#endif +default:
printk(XENLOG_G_ERR
"%pv: %s: unhandled read r%d offset %#08x\n",xen/arch/arm/vgic-v3.c +0
-0@@ -782,6 +854,9 @@ static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v, {case
VRANGE32(GICD_IGROUPR, GICD_IGROUPRN):
caseVRANGE32(GICD_IGRPMODR, GICD_IGRPMODRN):xen/arch/arm/vgic-v3.c +3
-0+#ifdef CONFIG_GICV3_ESPI + case VRANGE32(GICD_IGROUPRnE, GICD_IGROUPRnEN): +#endif /* We do not implement security extensions for guests, write ignore */
gotowrite_ignore_32;xen/arch/arm/vgic-v3.c +20
-0@@ -871,6 +946,87 @@ static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v, vgic_unlock_rank(v, rank, flags); return 1; +#ifdef CONFIG_GICV3_ESPI + case VRANGE32(GICD_ISENABLERnE, GICD_ISENABLERnEN): + if ( dabt.size != DABT_WORD ) goto bad_width; + rank = vgic_ext_rank_offset(v, 1, reg - GICD_ISENABLERnE,DABT_WORD ); + if ( rank == NULL ) goto write_ignore; + vgic_lock_rank(v, rank, flags); + tr = rank->ienable; + vreg_reg32_setbits(&rank->ienable, r, info); + vgic_enable_irqs(v, (rank->ienable) & (~tr),EXT_RANK_IDX2NUM (rank->index)); + vgic_unlock_rank(v, rank, flags); + return 1; + + case VRANGE32(GICD_ICENABLERnE, GICD_ICENABLERnEN): + if ( dabt.size != DABT_WORD ) goto bad_width; + rank = vgic_ext_rank_offset(v, 1, reg - GICD_ICENABLERnE,DABT_WORD ); + if ( rank == NULL ) goto write_ignore; + vgic_lock_rank(v, rank, flags); + tr = rank->ienable; + vreg_reg32_clearbits(&rank->ienable, r, info); + vgic_disable_irqs(v, (~rank->ienable) & tr,
EXT_RANK_IDX2NUM(rank->index));
+vgic_unlock_rank(v, rank, flags);
+ return 1;
+
+ caseVRANGE32(GICD_ISPENDRnE, GICD_ISPENDRnEN):
+ if ( dabt.size !=DABT_WORD) gotobad_width; + rank =vgic_ext_rank_offset(v, 1, reg - GICD_ISPENDRnE, DABT_WORD);
+ if ( rank == NULL ) gotowrite_ignore;xen/arch/arm/vgic-v3.c +8
-0+ + vgic_set_irqs_pending(v, r, EXT_RANK_IDX2NUM(rank->index)); + + return 1; + + case VRANGE32(GICD_ICPENDRnE, GICD_ICPENDRnEN): + if ( dabt.size != DABT_WORD ) goto bad_width; + rank = vgic_ext_rank_offset(v, 1, reg - GICD_ICPENDRnE,
DABT_WORD);
+ if ( rank == NULL ) gotowrite_ignore;
+
+ vgic_check_inflight_irqs_pending(v, EXT_RANK_IDX2NUM(rank-Quoted 8 lines
Quoted 1 line
index), r);
+
+ gotowrite_ignore;
+ caseVRANGE32(GICD_ISACTIVERnE, GICD_ISACTIVERnEN):
+ if ( dabt.size !=DABT_WORD) gotobad_width; + printk(XENLOG_G_ERR
+ "%pv: %s: unhandled word write %#"PRIregister" to ISACTIVER%d\n",I would use ISACTIVER%dE in the printed message to distinguish between normal and "extended" registers (here and in similar places throughout the added code).
Quoted 8 lines
+ v, name, r, reg -
GICD_ISACTIVERnE);
+ return 0;
+
+ caseVRANGE32(GICD_ICACTIVERnE, GICD_ICACTIVERnEN):
+ printk(XENLOG_G_ERR
+ "%pv: %s: unhandled word write %#"PRIregister" to ICACTIVER%d\n",
+ v, name, r, reg -GICD_ICACTIVER);
Quoted 4 lines
s/GICD_ICACTIVER/GICD_ICACTIVERnE
[snip]
Oh, I missed this. I will fix it in V3. Thank you.
Best regards,
Leonid
Re: [PATCH v2 09/10] xen/arm: domain_build: adjust Dom0 IRQ handling to support eSPIs
In reply to Leonid KomarianskyiHi Leonid,
Quoted 74 lines · Leonid Komarianskyi
Hi Volodymyr,
Quoted 58 lines · Volodymyr Babchuk
Quoted 53 lines · Leonid Komarianskyi
The Dom0 configuration logic in
create_dom0()has been updated to account for extended SPIs when supported by the hardware and enabled withCONFIG_GICV3_ESPI. These changes ensure the proper calculation of the maximum number of SPIs and eSPIs available for Dom0.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 limited at 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 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 now.Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- no changes--- xen/arch/arm/domain_build.c | 10 ++++++++++ xen/arch/arm/include/asm/vgic.h | 11 +++++++++++ 2 files changed, 21 insertions(+)xen/arch/arm/domain_build.c +10
-0@@ -2055,6 +2055,16 @@ 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 ; +#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 overwrite the nr_spis with the +* maximum available INTID from eSPI range. In that case, the number of regular SPIs will +* be adjusted to the maximum value during vGIC initialization. +*/ +if (gic_number_espis () >0 ) + dom0_cfg.arch.nr_spis =VGIC_DEF_NR_ESPIS ; +#endif dom0_cfg.arch.tee_type =tee_get_type (); dom0_cfg.max_vcpus =dom0_max_vcpus ();xen/arch/arm/include/asm/vgic.h +0
-0@@ -353,6 +353,17 @@ 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)Quoted 11 lines
xen/arch/arm/include/asm/vgic.h extern void vgic_check_inflight_irqs_pending(struct vcpu *v, · line 364
Quoted 9 lines
xen/arch/arm/include/asm/vgic.h +9
-0+#ifdef CONFIG_GICV3_ESPI +/* +* Returns the maximum eSPI INTID subtracted by 32. For non-Dom0 domains, the +* toolstack applies the same adjustment to cover local IRQs. 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. +*/ +#define VGIC_DEF_NR_ESPIS (ESPI_BASE_INTID + min(gic_number_espis(), 1024U) - 32)Name of the define is wrong, as it is not number of eSPIs. Actually, this is maximum SPI (including eSPIs) number.
Quoted 2 lines
Thank you for your review.
Would it be okay if I rename this macro toVGIC_DEF_MAX_SPI?
Yes, I think this is better name.
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v2 03/10] xen/arm: vgic: implement helper functions for virq checks
In reply to Leonid KomarianskyiLeonid,
Quoted 120 lines · Leonid Komarianskyi
Hi Volodymyr,
Thank you for you comment.
Quoted 112 lines · Volodymyr Babchuk
Quoted 98 lines · Leonid Komarianskyi
Introduced two new helper functions for vGIC:
vgic_is_valid_irqandvgic_is_shared_irq. The functions are similar to the newly introducedgic_is_valid_irqandgic_is_shared_irq, 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_irqmay affect existing functionality, as it currently checks whether the vIRQ is less than or equal tovgic_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 thanvgic_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.Signed-off-by Leonid Komarianskyi <[email protected]>---
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 ++++++++-- 4 files changed, 18 insertions(+), 6 deletions(-)xen/arch/arm/gic.c +1
-2@@ -133,8 +133,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_shared_irq (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_irq (struct domain *d,unsigned int virq); + +static inline bool vgic_is_shared_irq (struct domain *d,unsigned int virq) +{ +return (virq >=NR_LOCAL_IRQS &&vgic_is_valid_irq (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_irq (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_shared_irq (d, virq) )return -EINVAL ; desc =vgic_get_hw_irq_desc (d,NULL , virq);xen/arch/arm/vgic.c +0
-0xen/arch/arm/vgic.c line 28
Quoted 5 lines
xen/arch/arm/vgic.c +2
-0@@ -24,6 +24,12 @@#include <asm/gic.h> #include <asm/vgic.h> + +bool vgic_is_valid_irq (struct domain *d,unsigned int virq)I have the same comment as for the previous patch. This function completely ignores LPIs presence, while you can't argue that LPIs as valid. Again, function callers are expecting this behavior, so this is fine, but function name should better reflect its behavior.
Quoted 2 lines
[...]
Quoted 8 lines
Would it be okay to rename these functions as proposed in the previous patch discussion:
vgic_is_valid_irq->vgic_is_valid_linevgic_is_shared_irq->vgic_is_spi?Or, in the case of vgic, is it not a good idea to use the "line" suffix because vgic does not have physical interrupt lines? Would it be better to rename it to
vgic_is_valid_non_lpiinstead?
I think it is better to follow the pGIC naming convention. While there is no physical IRQ lines in vGIC, it emulates real GIC anyways.
Signature · 1 line
WBR, Volodymyr
Re: [PATCH v2 04/10] xen/arm/irq: add handling for IRQs in the eSPI range
In reply to Julien GrallHi Volodymyr and Julien,
Thank you for your review comments and for raising an important discussion regarding memory usage and wrappers.
Quoted 35 lines · Julien Grall
Quoted 21 lines · Volodymyr Babchuk
Quoted 19 lines · Julien Grall
Hi,
Quoted 16 lines · Volodymyr Babchuk
Quoted 10 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.I don't think that it is a good idea to hide this feature under
Kconfig
option, as this will increase number of different build variants. I believe that runtime check for GICD_TYPER.ESPI should beQuoted 7 lines
Quoted 5 lines
sufficient,> but maintainers can correct me there.
I haven't seen many board with ESPI available. So I think it would be better if this is under a
Kconfigbecause not everyone may want to have the code.Probably, we can expect more in the future...
Well yes. But I was under the impression this the preferred approach. See the discussion about disabling 32-bit support on 64-bit:
Quoted 8 lines
Anyways, after reviewing
Quoted 2 lines
all patches in the series, I can see that code will be littered with #ifdef
CONFIG_GICV3_ESPI, which, probably, not a good thing.The solution is to provide wrappers to reduce the number of #ifdef. I haven't checked all the places.
I agree with you, it's a good point to use wrappers where possible. I will revise all patches in the series and try to use wrappers where possible to reduce #ifdefs.
Quoted 52 lines
Quoted 42 lines
Quoted 33 lines
[...]
Quoted 29 lines
Quoted 29 lines
struct
irq_desc;
struct irqaction;xen/arch/arm/include/asm/irq.h +8
-0@@ -55,6 +71,15 @@ 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 + return false; +#endif +} + #define domain_pirq_to_irq(d, pirq) (pirq) bool is_assignable_irq(unsigned int irq);xen/arch/arm/irq.c +0
-0@@ -19,7 +19,11 @@ #include <asm/gic.h> #include <asm/vgic.h>+#ifdef
CONFIG_GICV3_ESPIxen/arch/arm/irq.c +2
-0+const unsigned int nr_irqs =ESPI_MAX_INTID +1 ; +#else const unsigned int
nr_irqs=NR_IRQS; +#endif
static unsigned int local_irqs_type[NR_LOCAL_IRQS];Quoted 8 lines
Quoted 6 lines
xen/arch/arm/irq.c void irq_end_none(struct irq_desc *irq) · line 53
Quoted 6 lines
static
DEFINE_SPINLOCK(local_irqs_type_lock);xen/arch/arm/irq.c +2
-0@@ -46,6 +50,9 @@ void irq_end_none(struct irq_desc *irq) } static irq_desc_t irq_desc[NR_IRQS - NR_LOCAL_IRQS]; +#ifdef CONFIG_GICV3_ESPI +static irq_desc_t espi_desc[NR_IRQS ];By how much will this increase the Xen binary?
Quoted 4 lines
I am wondering this also. The struct is cache aligned, so it will take at least 128 bytes. The whole array will take at least 128kb. Not great, not terrible. As this should go to .bss, it should not increase the binary itself.
I guess "binary" was the wrong word. I was referring to the size of the Xen in memory. On my setup Xen is 1448kb. Here you would increase ~9% of resident size. This seems quite steep for a feature that is not often used.
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
Maybe it is better to allocate this dynamically? I do understand that we want to get rid of as many dynamic allocs as possible, but maybe in this case it will be okay.
This is up to Leonid. I don't think this is strictly necessary in order to get the eSPI support. However, until this is solved
CONFIG_GICV3_EPSI*must not* be on by default as this is done in this patch.
I will check how much time and effort are required to switch to dynamic allocation. If it does not take much time and does not require many changes, I will prepare an additional preparation patch in V3. Otherwise, I will disable the config by default in V3.
Quoted 8 lines
Quoted 3 lines
As a bonus point, we can't leave this pointer
present even ifCONFIG_GICV3_ESPI=n, which will simplify some code in latter patches.Did you intend to say "We can leave" rather than "we can't leave"?
Cheers,
Best regards,
Leonid
Re: [PATCH v2 04/10] xen/arm/irq: add handling for IRQs in the eSPI range
In reply to Volodymyr BabchukHi Volodymyr,
Thank you for your review.
Quoted 73 lines · Volodymyr Babchuk
Quoted 10 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.I don't think that it is a good idea to hide this feature under
Kconfigoption, as this will increase number of different build variants. I believe that runtime check for GICD_TYPER.ESPI should be sufficient, but maintainers can correct me there.Quoted 55 lines
Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- use (ESPI_MAX_INTID+ 1) instead of (ESPI_BASE_INTID+NR_IRQS)
- remove unnecessary comment fornr_irqsinitialization--- xen/arch/arm/Kconfig | 9 +++++++++ xen/arch/arm/include/asm/irq.h | 25 +++++++++++++++++++++++++ xen/arch/arm/irq.c | 26 ++++++++++++++++++++++++++ 3 files changed, 60 insertions(+)xen/arch/arm/Kconfig +9
-0@@ -135,6 +135,15 @@ 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 + default y + 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 +8
-0@@ -32,6 +32,14 @@ struct arch_irq_desc {#define SPI_MAX_INTID 1019#define LPI_OFFSET 8192 +#ifdef CONFIG_GICV3_ESPI +#define ESPI_BASE_INTID 4096 +#define ESPI_MAX_INTID 5119 + +#define ESPI_INTID2IDX (intid) ((intid) - ESPI_BASE_INTID) +#define ESPI_IDX2INTID (idx) ((idx) + ESPI_BASE_INTID) +#endif +/* LPIs are always numbered starting at 8192, so 0 is a good invalid case. */ #define INVALID_LPI 0@@ -39,7 +47,15 @@ struct arch_irq_desc {#define INVALID_IRQ 1023
Quoted 16 lines
xen/arch/arm/include/asm/irq.h struct arch_irq_desc { · line 58
Quoted 10 lines
xen/arch/arm/include/asm/irq.h +8
-0extern const unsigned int nr_irqs; +#ifdef CONFIG_GICV3_ESPI +/* +* This will also cover the eSPI range, as some critical devices +* for booting Xen (e.g., serial) may use this type of interrupts. +*/ +#define nr_static_irqs (ESPI_MAX_INTID + 1) +#else #define nr_static_irqs NR_IRQS +#endif Don't introduce defines that look like variables. I am sure that MISRA team will be unhappy about that. But what you can really do is to introduce variable
nr_static_irqs, which value will depend on GICD_TYPER.ESPI and GICD_TYPER.ESPI_range
This is a generic define, which is present in all arch-specific irq headers (x86, PPC, RISC-V, ARM). I think it is not a good idea to make this a const variable only when CONFIG_GICV3_ESPI is enabled, while in other places it is a define. Moreover, I clarified with one of our teammates, who is engaged in MISRA fixes for Xen, and he confirmed that there is no violation of the MISRA rule here. To summarize all of that, would it be okay to leave this place unchanged?
Quoted 38 lines
Quoted 38 lines
xen/arch/arm/include/asm/irq.h +9
-0struct irq_desc ;struct irqaction ;@@ -55,6 +71,15 @@ 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 +return false; +#endif +} +#define domain_pirq_to_irq (d, pirq) (pirq)bool is_assignable_irq (unsigned int irq);xen/arch/arm/irq.c +4
-0@@ -19,7 +19,11 @@#include <asm/gic.h> #include <asm/vgic.h> +#ifdef CONFIG_GICV3_ESPI +const unsigned int nr_irqs =ESPI_MAX_INTID +1 ; +#else const unsigned int nr_irqs =NR_IRQS ; +#endif static unsigned int local_irqs_type[NR_LOCAL_IRQS ];static DEFINE_SPINLOCK (local_irqs_type_lock);@@ -46,6 +50,9 @@ void irq_end_none(struct irq_desc *irq) }
Quoted 6 lines
xen/arch/arm/irq.c void irq_end_none(struct irq_desc *irq) · line 54
Quoted 3 lines
xen/arch/arm/irq.c +2
-0static irq_desc_t irq_desc[NR_IRQS -NR_LOCAL_IRQS ]; +#ifdef CONFIG_GICV3_ESPI +static irq_desc_t espi_desc[NR_IRQS ];This is really confusing. Should it be something like espi_desc[NR_ESPI_IRQS]?
Sure, that would be better. So, I will add the NR_ESPI_IRQS define in V3. Of course, if I am not able to make a dynamic allocation, which is being discussed in the sub-thread for this patch. :)
Quoted 21 lines
Quoted 21 lines
xen/arch/arm/irq.c +1
-0+#endif static DEFINE_PER_CPU(irq_desc_t[NR_LOCAL_IRQS], local_irq_desc);struct
irq_desc*__irq_to_desc(unsigned int irq)xen/arch/arm/irq.c +5
-0@@ -53,6 +60,11 @@ struct irq_desc *__irq_to_desc(unsigned int irq)if ( irq <NR_LOCAL_IRQS )return &this_cpu (local_irq_desc)[irq]; +#ifdef CONFIG_GICV3_ESPI +if (is_espi (irq) ) +return &espi_desc[ESPI_INTID2IDX (irq)]; +#endif +return &irq_desc[irq-NR_LOCAL_IRQS ]; }@@ -79,6 +91,20 @@ static int __init init_irq_data(void) desc->action =NULL ; }
Quoted 17 lines
Quoted 6 lines
xen/arch/arm/irq.c +6
-0+#ifdef CONFIG_GICV3_ESPI +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); +xen/arch/arm/irq.c static int __init init_irq_data(void) · line 109
Quoted 10 lines
xen/arch/arm/irq.c +8
-0+if ( rc ) +return rc; + + desc->irq = irq; + desc->action = NULL; + } +#endif +return 0 ; }
Best regards,
Leonid
Re: [PATCH v2 05/10] xen/arm: gicv3: implement handling of GICv3.1 eSPI
In reply to Volodymyr BabchukHi Volodymyr,
Thank you for your close review.
Quoted 111 lines · Volodymyr Babchuk
Hi,
Quoted 92 lines · Leonid Komarianskyi
Introduced 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.
Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- movegic_number_espisfunction from
[PATCH 08/10] xen/arm: vgic: add resource management for extended SPIs to use it in the newly introducedgic_is_valid_espi
- addgic_is_valid_espiwhich checks if IRQ number is in supported by HW eSPI range
- updategic_is_valid_irqconditions to allow operations with eSPIs--- xen/arch/arm/gic-v3.c | 73 ++++++++++++++++++++++++++ xen/arch/arm/include/asm/gic.h | 17 ++++++ xen/arch/arm/include/asm/gic_v3_defs.h | 33 ++++++++++++ 3 files changed, 123 insertions(+)xen/arch/arm/gic-v3.c +46
-0@@ -485,6 +485,36 @@ static void __iomem *get_addr_by_offset(struct irq_desc *irqd, u32 offset)default :break ; } +#ifdef CONFIG_GICV3_ESPI + case ESPI_BASE_INTID ... ESPI_MAX_INTID: + { +u32 irq_index =ESPI_INTID2IDX (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 ; }@@ -645,6 +675,40 @@ 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 gicv3_dist_espi_common_init (uint32_t type) +{ +unsigned int espi_nr; +int 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 ;xen/arch/arm/gic-v3.c static void gicv3_set_irq_priority(struct irq_desc *desc, · line 703
Quoted 10 lines
xen/arch/arm/gic-v3.c +10
-0+ +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 (0xffffffffU ,GICD + GICD_ICENABLERnE + (i /32 ) *4 );Is there are particular reason why you use
GENMASK(31,0)below, but open-coded0xffffffffhere?
Quoted 4 lines
xen/arch/arm/gic-v3.c static void gicv3_set_irq_priority(struct irq_desc *desc, · line 704
Quoted 1 line
xen/arch/arm/gic-v3.c +1
-0+writel_relaxed (0xffffffffU ,GICD + GICD_ICACTIVERnE + (i /32 ) *4 );... and here?
No, there is no particular reason to use open-code here. It is just a copy-paste from the code for regular SPI initialization. Thus, I agree it is much better to use GENMASK(31, 0). I will change this in V3.
Quoted 100 lines
Quoted 100 lines
xen/arch/arm/gic-v3.c +16
-0+ } + +for ( i =0 ; i < espi_nr; i +=32 ) +writel_relaxed (GENMASK (31 ,0 ),GICD + GICD_IGROUPRnE + (i /32 ) *4 ); +} +#endif +static void __init gicv3_dist_init (void ) {uint32_t type;@@ -690,6 +754,10 @@ 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 ); +#ifdef CONFIG_GICV3_ESPI +gicv3_dist_espi_common_init (type); +#endif +gicv3_dist_wait_for_rwp ();/* Turn on the distributor */ @@ -703,6 +771,11 @@ 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 ); + +#ifdef CONFIG_GICV3_ESPI +for ( i =0 ; i < gicv3_info.nr_espi; i++ ) +writeq_relaxed_non_atomic (affinity,GICD + GICD_IROUTERnE + i *8 ); +#endif }static int gicv3_enable_redist (void )xen/arch/arm/include/asm/gic.h +17
-0@@ -306,8 +306,21 @@ 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_IDX2INTID (gic_number_espis ())); +} +#endif +static inline bool gic_is_valid_irq (unsigned int irq) { +#ifdef CONFIG_GICV3_ESPI +if (gic_is_valid_espi (irq) ) +return true; +#endif return irq <gic_number_lines (); }@@ -325,6 +338,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 +22
-0@@ -37,6 +37,39 @@#define GICD_IROUTER1019 (0x7FD8)#define GICD_PIDR2 (0xFFE8) +#ifdef CONFIG_GICV3_ESPI +/* 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_IROUTERnE (0x8000) +#define GICD_IROUTERnEN (0x9FFC)
Quoted 9 lines
xen/arch/arm/include/asm/gic_v3_defs.h line 67
Quoted 6 lines
xen/arch/arm/include/asm/gic_v3_defs.h +6
-0+ +#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 (typer) ((((typer) & GICD_TYPER_ESPI_RANGE_MASK) + 1) * 32)Isn't this line a bit long?
Yes, I will revise all patches in the series with such long lines and fix them in V3.
Quoted 10 lines
xen/arch/arm/include/asm/gic_v3_defs.h line 70
Quoted 3 lines
xen/arch/arm/include/asm/gic_v3_defs.h +3
-0+#define GICD_TYPER_ESPIS_NUM (typer) \ + (((typer) & GICD_TYPER_ESPI) ? \ + GICD_TYPER_ESPI_RANGE((typer) >> GICD_TYPER_ESPI_RANGE_SHIFT) : 0)I am not sure that this is correct.
Probably you wanted to write
+GICD_TYPER_ESPI_RANGE((typer >> GICD_TYPER_ESPI_RANGE_SHIFT)): 0)
I double checked - it seems like everything is correct - the typer parameter should be surrounded by parentheses, and GICD_TYPER_ESPI_RANGE should operate with the already shifted value. However, I wrote a slightly confusing macro. At the very least, it would be better to rename in V3 the typer parameter in GICD_TYPER_ESPI_RANGE, because it takes the value of GICD_TYPER that is already shifted by 27, instead of the raw register value. Would that be acceptable?
Quoted 6 lines
xen/arch/arm/include/asm/gic_v3_defs.h line 75
Quoted 5 lines
xen/arch/arm/include/asm/gic_v3_defs.h +2
-0+#endif +/* Common between GICD_PIDR2 and GICR_PIDR2 */ #define GIC_PIDR2_ARCH_MASK (0xf0)#define GIC_PIDR2_ARCH_GICv3 (0x30)
Best regards,
Leonid
Re: [PATCH v2 09/10] xen/arm: domain_build: adjust Dom0 IRQ handling to support eSPIs
In reply to Volodymyr BabchukHi Volodymyr,
Quoted 79 lines · Volodymyr Babchuk
Hi Leonid,
Quoted 74 lines · Leonid Komarianskyi
Hi Volodymyr,
Quoted 69 lines · Volodymyr Babchuk
Quoted 52 lines · Leonid Komarianskyi
The Dom0 configuration logic in
create_dom0()has been updated to account for extended SPIs when supported by the hardware and enabled withCONFIG_GICV3_ESPI. These changes ensure the proper calculation of the maximum number of SPIs and eSPIs available for Dom0.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 limited at 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 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 now.Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- no changes--- xen/arch/arm/domain_build.c | 10 ++++++++++ xen/arch/arm/include/asm/vgic.h | 11 +++++++++++ 2 files changed, 21 insertions(+)xen/arch/arm/domain_build.c +10
-0@@ -2055,6 +2055,16 @@ 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 ; +#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 overwrite the nr_spis with the +* maximum available INTID from eSPI range. In that case, the number of regular SPIs will +* be adjusted to the maximum value during vGIC initialization. +*/ +if (gic_number_espis () >0 ) + dom0_cfg.arch.nr_spis =VGIC_DEF_NR_ESPIS ; +#endif dom0_cfg.arch.tee_type =tee_get_type (); dom0_cfg.max_vcpus =dom0_max_vcpus ();xen/arch/arm/include/asm/vgic.h +0
-0@@ -353,6 +353,17 @@ 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)xen/arch/arm/include/asm/vgic.h extern void vgic_check_inflight_irqs_pending(struct vcpu *v, · line 364
Quoted 10 lines
xen/arch/arm/include/asm/vgic.h +9
-0+#ifdef CONFIG_GICV3_ESPI +/* +* Returns the maximum eSPI INTID subtracted by 32. For non-Dom0 domains, the +* toolstack applies the same adjustment to cover local IRQs. 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. +*/ +#define VGIC_DEF_NR_ESPIS (ESPI_BASE_INTID + min(gic_number_espis(), 1024U) - 32)Name of the define is wrong, as it is not number of eSPIs. Actually, this is maximum SPI (including eSPIs) number.
Quoted 5 lines
Quoted 2 lines
Thank you for your review.
Would it be okay if I rename this macro toVGIC_DEF_MAX_SPI?Yes, I think this is better name.
Thank you for your confirmation. I will rename this macro to VGIC_DEF_MAX_SPI in V3.
Best regards,
Leonid
Re: [PATCH v2 03/10] xen/arm: vgic: implement helper functions for virq checks
In reply to Volodymyr BabchukHi Volodymyr,
Quoted 130 lines · Volodymyr Babchuk
Leonid,
Quoted 125 lines · Leonid Komarianskyi
Hi Volodymyr,
Thank you for you comment.
Quoted 112 lines · Volodymyr Babchuk
Quoted 98 lines · Leonid Komarianskyi
Introduced two new helper functions for vGIC:
vgic_is_valid_irqandvgic_is_shared_irq. The functions are similar to the newly introducedgic_is_valid_irqandgic_is_shared_irq, 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_irqmay affect existing functionality, as it currently checks whether the vIRQ is less than or equal tovgic_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 thanvgic_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.Signed-off-by Leonid Komarianskyi <[email protected]>---
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 ++++++++-- 4 files changed, 18 insertions(+), 6 deletions(-)xen/arch/arm/gic.c +1
-2@@ -133,8 +133,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_shared_irq (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_irq (struct domain *d,unsigned int virq); + +static inline bool vgic_is_shared_irq (struct domain *d,unsigned int virq) +{ +return (virq >=NR_LOCAL_IRQS &&vgic_is_valid_irq (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_irq (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_shared_irq (d, virq) )return -EINVAL ; desc =vgic_get_hw_irq_desc (d,NULL , virq);xen/arch/arm/vgic.c +0
-0xen/arch/arm/vgic.c line 28
Quoted 5 lines
xen/arch/arm/vgic.c +2
-0@@ -24,6 +24,12 @@#include <asm/gic.h> #include <asm/vgic.h> + +bool vgic_is_valid_irq (struct domain *d,unsigned int virq)I have the same comment as for the previous patch. This function completely ignores LPIs presence, while you can't argue that LPIs as valid. Again, function callers are expecting this behavior, so this is fine, but function name should better reflect its behavior.
Quoted 2 lines
[...]
Would it be okay to rename these functions as proposed in the previous patch discussion:
vgic_is_valid_irq->vgic_is_valid_linevgic_is_shared_irq->vgic_is_spi?
Quoted 7 lines
Quoted 3 lines
Or, in the case of vgic, is it not a good idea to use the "line" suffix because vgic does not have physical interrupt lines? Would it be better to rename it to
vgic_is_valid_non_lpiinstead?I think it is better to follow the pGIC naming convention. While there is no physical IRQ lines in vGIC, it emulates real GIC anyways.
Okay, good point. I will rename the vGIC-related functions in the pGIC manner in V3.
Best regards,
Leonid
Re: [PATCH v2 03/10] xen/arm: vgic: implement helper functions for virq checks
In reply to Leonid KomarianskyiOn 07.08.25 15:33, Leonid Komarianskyi wrote:
Hello Leonid
Quoted 76 lines
Introduced two new helper functions for vGIC:
vgic_is_valid_irqandvgic_is_shared_irq. The functions are similar to the newly introducedgic_is_valid_irqandgic_is_shared_irq, 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_irqmay affect existing functionality, as it currently checks whether the vIRQ is less than or equal tovgic_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 thanvgic_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.Signed-off-by Leonid Komarianskyi <[email protected]>---
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 ++++++++-- 4 files changed, 18 insertions(+), 6 deletions(-)xen/arch/arm/gic.c +1
-2@@ -133,8 +133,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_shared_irq (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_irq (struct domain *d,unsigned int virq); + +static inline bool vgic_is_shared_irq (struct domain *d,unsigned int virq) +{ +return (virq >=NR_LOCAL_IRQS &&vgic_is_valid_irq (d, virq)); +} +/* * Allocate a guest VIRQ * - spi == 0 => allocate a PPI. It will be the same on every vCPU xen/arch/arm/irq.c +0
-0
xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned int virq, · line 445
Quoted 5 lines
xen/arch/arm/irq.c +1
-1@@ -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_irq (d, virq) )
This file is common for all VGIC implementations, so route_irq_to_guest() is used with CONFIG_NEW_VGIC=y as well.
If your series is built with CONFIG_NEW_VGIC=y (I know, that NEW_VGIC does not support GICV3 HW) I have got the following error:
aarch64-poky-linux-ld: prelink.o: in function `route_irq_to_guest':/usr/src/debug/xen/4.18.0+gitAUTOINC+ce58f56108-r0/git/xen/arch/arm/irq.c:445: undefined reference to vgic_is_valid_irq' /usr/src/debug/xen/4.18.0+gitAUTOINC+ce58f56108-r0/git/xen/arch/arm/irq.c:445:(.text+0x5e2f8): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol vgic_is_valid_irq'
...
From the quick look, vgic_is_valid_irq() needs a stub (or NEW_VGIC's counterpart).
[snip]
Re: [PATCH v2 09/10] xen/arm: domain_build: adjust Dom0 IRQ handling to support eSPIs
In reply to Leonid KomarianskyiOn 07.08.25 15:33, Leonid Komarianskyi wrote:
Hello Leonid
Quoted 32 lines
The Dom0 configuration logic in
create_dom0()has been updated to account for extended SPIs when supported by the hardware and enabled withCONFIG_GICV3_ESPI. These changes ensure the proper calculation of the maximum number of SPIs and eSPIs available for Dom0.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 limited at 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 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 now.Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- no changes--- xen/arch/arm/domain_build.c | 10 ++++++++++ xen/arch/arm/include/asm/vgic.h | 11 +++++++++++ 2 files changed, 21 insertions(+)xen/arch/arm/domain_build.c +0
-0@@ -2055,6 +2055,16 @@ 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 ;
xen/arch/arm/domain_build.c void __init create_dom0(void) · line 2067
Quoted 10 lines
xen/arch/arm/domain_build.c +10
-0+#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 overwrite the nr_spis with the +* maximum available INTID from eSPI range. In that case, the number of regular SPIs will +* be adjusted to the maximum value during vGIC initialization. +*/ +if (gic_number_espis () >0 ) + dom0_cfg.arch.nr_spis =VGIC_DEF_NR_ESPIS ; +#endif
I might miss something, but within the whole series, you seem not to update "nr_spis" field for dom0less DomUs (in dom0less-build.c). Please clarify the reason?
Quoted 3 lines
xen/arch/arm/domain_build.c +0
-0dom0_cfg.arch.tee_type =tee_get_type (); dom0_cfg.max_vcpus =dom0_max_vcpus ();
[snip]
Re: [PATCH v2 05/10] xen/arm: gicv3: implement handling of GICv3.1 eSPI
In reply to Leonid KomarianskyiOn 07.08.25 15:33, Leonid Komarianskyi wrote:
Hello Leonid
Quoted 73 lines
Introduced 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.
Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- movegic_number_espisfunction from
[PATCH 08/10] xen/arm: vgic: add resource management for extended SPIs to use it in the newly introducedgic_is_valid_espi
- addgic_is_valid_espiwhich checks if IRQ number is in supported by HW eSPI range
- updategic_is_valid_irqconditions to allow operations with eSPIs--- xen/arch/arm/gic-v3.c | 73 ++++++++++++++++++++++++++ xen/arch/arm/include/asm/gic.h | 17 ++++++ xen/arch/arm/include/asm/gic_v3_defs.h | 33 ++++++++++++ 3 files changed, 123 insertions(+)xen/arch/arm/gic-v3.c +30
-0@@ -485,6 +485,36 @@ static void __iomem *get_addr_by_offset(struct irq_desc *irqd, u32 offset)default :break ; } +#ifdef CONFIG_GICV3_ESPI + case ESPI_BASE_INTID ... ESPI_MAX_INTID: + { +u32 irq_index =ESPI_INTID2IDX (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 ; }
xen/arch/arm/gic-v3.c static void gicv3_set_irq_priority(struct irq_desc *desc, · line 684
Quoted 10 lines
xen/arch/arm/gic-v3.c +7
-0@@ -645,6 +675,40 @@ 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 gicv3_dist_espi_common_init (uint32_t type)
missing __init ?
xen/arch/arm/gic-v3.c static void gicv3_set_irq_priority(struct irq_desc *desc, · line 687
Quoted 3 lines
xen/arch/arm/gic-v3.c +3
-0+{ +unsigned int espi_nr; +int i;
please use unsigned int if "i" cannot be negative
Quoted 50 lines
xen/arch/arm/gic-v3.c +33
-0+ + 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 ; + +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 (0xffffffffU ,GICD + GICD_ICENABLERnE + (i /32 ) *4 ); +writel_relaxed (0xffffffffU ,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); +} +#endif +static void __init gicv3_dist_init (void ) {uint32_t type;@@ -690,6 +754,10 @@ 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 ); +#ifdef CONFIG_GICV3_ESPI +gicv3_dist_espi_common_init (type); +#endif +gicv3_dist_wait_for_rwp ();/* Turn on the distributor */ @@ -703,6 +771,11 @@ 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 ); + +#ifdef CONFIG_GICV3_ESPI +for ( i =0 ; i < gicv3_info.nr_espi; i++ ) +writeq_relaxed_non_atomic (affinity,GICD + GICD_IROUTERnE + i *8 ); +#endif }static int gicv3_enable_redist (void )
[snip]
Re: [PATCH v2 08/10] xen/arm: vgic: add resource management for extended SPIs
In reply to Leonid KomarianskyiOn 07.08.25 15:33, Leonid Komarianskyi wrote:
Hello Leonid
Quoted 146 lines
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.
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]>---
Changes 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 | 18 ++++ xen/arch/arm/vgic.c | 145 ++++++++++++++++++++++++++++++++ 2 files changed, 163 insertions(+)xen/arch/arm/include/asm/vgic.h +18
-0@@ -146,6 +146,10 @@ struct vgic_dist {int nr_spis;/* Number of SPIs */ unsigned long *allocated_irqs;/* bitmap of IRQs allocated */ struct vgic_irq_rank *shared_irqs; +#ifdef CONFIG_GICV3_ESPI +struct vgic_irq_rank *ext_shared_irqs; +int nr_espis;/* Number of extended SPIs */ +#endif /* * SPIs are domain global, SGIs and PPIs are per-VCPU and stored in * struct arch_vcpu. @@ -243,6 +247,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) +#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) +#endif +#define vgic_lock (v) spin_lock_irq(&(v)->domain->arch.vgic.lock)#define vgic_unlock (v) spin_unlock_irq(&(v)->domain->arch.vgic.lock)@@ -302,6 +314,12 @@ extern struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v,unsigned int b, unsigned int n, unsigned int s); +#ifdef CONFIG_GICV3_ESPI +extern struct vgic_irq_rank *vgic_ext_rank_offset (struct vcpu *v, +unsigned int b, +unsigned int n, +unsigned int s); +#endif 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.c +31
-0@@ -27,9 +27,26 @@bool vgic_is_valid_irq (struct domain *d,unsigned int virq) { +#ifdef CONFIG_GICV3_ESPI +if ( virq >=ESPI_BASE_INTID && virq <ESPI_IDX2INTID (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) ); +} +#endif +static inline struct vgic_irq_rank *vgic_get_rank (struct vcpu *v,unsigned int rank) {@@ -37,6 +54,10 @@ 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]; +#ifdef CONFIG_GICV3_ESPI + else if ( is_valid_espi_rank(v->domain, rank) ) + return &v->domain->arch.vgic.ext_shared_irqs[EXT_RANK_NUM2IDX(rank)]; +#endif else return NULL; }@@ -53,6 +74,16 @@ struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, unsigned int b,return vgic_get_rank (v, rank); } +#ifdef CONFIG_GICV3_ESPI +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 ); +} +#endif +struct vgic_irq_rank *vgic_rank_irq (struct vcpu *v,unsigned int irq) {unsigned int rank = irq /32 ;
xen/arch/arm/vgic.c int domain_vgic_register(struct domain *d, unsigned int *mmio_count) · line 154
Quoted 7 lines
xen/arch/arm/vgic.c +4
-0@@ -117,6 +148,29 @@ int domain_vgic_register(struct domain *d, unsigned int *mmio_count)return 0 ; } +#ifdef CONFIG_GICV3_ESPI +static int init_vgic_espi (struct domain *d) +{ +int i;
please use unsigned int if "i" cannot be negative
Quoted 24 lines
xen/arch/arm/vgic.c +19
-0+ +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 =0 ; i < d->arch.vgic.nr_espis; i++ ) +vgic_init_pending_irq (&d->arch.vgic.pending_irqs[i + d->arch.vgic.nr_spis],ESPI_IDX2INTID (i)); + +for ( i =0 ; i <DOMAIN_NR_EXT_RANKS (d); i++ ) +vgic_rank_init (&d->arch.vgic.ext_shared_irqs[i], i,0 ); + + return 0; +} +#endif +int domain_vgic_init (struct domain *d,unsigned int nr_spis) {int i;@@ -131,6 +185,30 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis)*/
xen/arch/arm/vgic.c int domain_vgic_init(struct domain *d, unsigned int nr_spis) · line 195
Quoted 10 lines
xen/arch/arm/vgic.c +8
-0nr_spis =ROUNDUP (nr_spis,32 ); +#ifdef CONFIG_GICV3_ESPI +if ( nr_spis >ESPI_MAX_INTID ) +return -EINVAL ; + +if (is_espi (nr_spis) ) + { +/* +* During domain creation, the toolstack specifies the maximum INTID,
domain_vgic_init() is also called for dom0less DomUs (if present), which are created at Xen boot. So the toolstack might even be absent on the target system.
Quoted 57 lines
xen/arch/arm/vgic.c +32
-0+* which is defined in the domain config subtracted by 32. To compute the +* actual number of eSPI that will be usable for, add back 32. +*/ + d->arch.vgic.nr_espis =min (nr_spis -ESPI_BASE_INTID +32 ,1024U ); +/* Verify if GIC HW can handle provided INTID */ +if ( d->arch.vgic.nr_espis >gic_number_espis () ) +return -EINVAL ; +/* Set the maximum available number for defult SPI to pass the next check */ + nr_spis = VGIC_DEF_NR_SPIS; + }else + { +/* Domain will use the regular SPI range */ + d->arch.vgic.nr_espis =0 ; + } +#endif +/* Limit the number of virtual SPIs supported to (1020 - 32) = 988 */ if ( nr_spis > (1020 -NR_LOCAL_IRQS ) )return -EINVAL ;@@ -145,7 +223,12 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis)return -ENOMEM ; d->arch.vgic.pending_irqs = +#ifdef CONFIG_GICV3_ESPI + xzalloc_array(struct pending_irq, d->arch.vgic.nr_spis + + d->arch.vgic.nr_espis); +#else xzalloc_array(struct pending_irq, d->arch.vgic.nr_spis); +#endif if ( d->arch.vgic.pending_irqs ==NULL )return -ENOMEM ;@@ -156,12 +239,23 @@ 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 ); +#ifdef CONFIG_GICV3_ESPI + ret =init_vgic_espi (d); +if ( ret ) +return ret; +#endif + ret = d->arch.vgic.handler->domain_init (d);if ( ret )return ret; d->arch.vgic.allocated_irqs = +#ifdef CONFIG_GICV3_ESPI + xzalloc_array(unsigned long, BITS_TO_LONGS(vgic_num_irqs(d) + + d->arch.vgic.nr_espis)); +#else xzalloc_array(unsigned long, BITS_TO_LONGS(vgic_num_irqs(d))); +#endif if ( !d->arch.vgic.allocated_irqs )return -ENOMEM ;
xen/arch/arm/vgic.c void domain_vgic_free(struct domain *d) · line 293
Quoted 5 lines
xen/arch/arm/vgic.c +2
-0@@ -195,9 +289,27 @@ void domain_vgic_free(struct domain *d) } } +#ifdef CONFIG_GICV3_ESPI +for ( i =0 ; i < (d->arch.vgic.nr_espis); i++ )
NIT: no need for () around d->arch.vgic.nr_espis
Quoted 23 lines
xen/arch/arm/vgic.c +16
-0+ { +struct pending_irq *p =spi_to_pending (d,ESPI_IDX2INTID (i)); + +if ( p->desc ) + { + ret =release_guest_irq (d, p->irq); +if ( ret ) +dprintk (XENLOG_G_WARNING ,"d%u: Failed to release virq %u ret = %d\n" , + d->domain_id, p->irq, ret); + } + } +#endif +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); }
xen/arch/arm/vgic.c void arch_move_irqs(struct vcpu *v) · line 448
Quoted 6 lines
xen/arch/arm/vgic.c +3
-0@@ -331,6 +443,17 @@ void arch_move_irqs(struct vcpu *v)if ( v_target == v && !test_bit (GIC_IRQ_GUEST_MIGRATING , &p->status) )irq_set_affinity (p->desc, cpu_mask); } + +#ifdef CONFIG_GICV3_ESPI +for ( i =ESPI_BASE_INTID ; i < (d)->arch.vgic.nr_espis; i++ )
NIT: no need for () around d
[snip]
Quoted 1 line · Leonid Komarianskyi
Hello everyone!
Hello Leonid,
Quoted 12 lines
### Background
Unlike the Linux kernel, which has supported extended shared peripheral interrupts (eSPIs) since 2019 [1], Xen currently lacks support for this interrupt range. For SoCs with GICv3.1+, this feature may be essential because critical devices, such as consoles required for booting Xen itself, may rely on eSPIs. Additionally, these platforms require eSPI support for fully functional domains, as any device using eSPIs cannot currently be used with Xen setups. Without eSPI support, Xen cannot run properly on these platforms, significantly limiting its usability on modern ARM hardware.
Quoted 6 lines
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.
I have lightly re-checked the simple Arm64 Xen environment (dom0less DomU under QEMU) with your series applied. To be clear, I did not really test the eSPI support (the underlying GICv3 HW does support it); I just wanted to ensure that your series would not break anything. So, in both cases (CONFIG_GICV3_ESPI=y and CONFIG_GICV3_ESPI=n), I did not notice any issues (at least obvious) related to GICv3 emulation and SPI injection for the passed-through device.
Also, I think you want to describe the eSPI feature in the CHANGELOG.md.
[snip]
Re: [PATCH v2 03/10] xen/arm: vgic: implement helper functions for virq checks
In reply to Oleksandr TyshchenkoHello Oleksandr,
Quoted 114 lines · Oleksandr Tyshchenko
[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
On 07.08.25 15:33, Leonid Komarianskyi wrote:
Hello Leonid
Quoted 81 lines
Introduced two new helper functions for vGIC:
vgic_is_valid_irqandvgic_is_shared_irq. The functions are similar to the newly introducedgic_is_valid_irqandgic_is_shared_irq, 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_irqmay affect existing functionality, as it currently checks whether the vIRQ is less than or equal tovgic_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 thanvgic_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.Signed-off-by Leonid Komarianskyi <[email protected]>---
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 ++++++++--4 files changed, 18 insertions(+), 6 deletions(-)xen/arch/arm/gic.c +1
-2@@ -133,8 +133,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_shared_irq(d, virq)); ASSERT(!is_lpi(virq));ret =
vgic_connect_hw_irq(d, NULL, virq, desc, true);xen/arch/arm/include/ renamed from xen/arch/arm/include/asm/vgic.h +0
-0
asm/vgic.h
index35c0c6a8b0..45201f4ca5100644xen/arch/arm/include/asm/vgic.h +0
-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 localIRQs. */
#defineVGIC_DEF_NR_SPIS(min(gic_number_lines(), VGIC_MAX_IRQS)- 32)xen/arch/arm/include/asm/vgic.h +3
-0+extern bool vgic_is_valid_irq (struct domain *d,unsigned int virq); + +static inline bool vgic_is_shared_irq(struct domain *d, unsigned intvirq)
xen/arch/arm/include/asm/vgic.h +4
-0+{ + return (virq >= NR_LOCAL_IRQS && vgic_is_valid_irq(d, virq)); +} +/*
* Allocate a guest VIRQ
* - spi == 0 => allocate a PPI. It will be the same on every vCPUxen/arch/arm/irq.c +0
-0xen/arch/arm/irq.c int route_irq_to_guest(struct domain *d, unsigned · line 446
Quoted 6 lines
xen/arch/arm/irq.c +1
-1@@ -442,7 +442,7 @@ int route_irq_to_guest(struct domain *d, unsignedint virq, unsigned long flags; int retval = 0; - if ( virq >= vgic_num_irqs(d) ) + if ( !vgic_is_valid_irq(d, virq) )This file is common for all VGIC implementations, so
route_irq_to_guest()is used withCONFIG_NEW_VGIC=yas well.If your series is built with
CONFIG_NEW_VGIC=y(I know, thatNEW_VGICdoes not support GICV3 HW) I have got the following error:aarch64-poky-linux-ld: prelink.o: in function `route_irq_to_guest':
/usr/src/debug/xen/4.18.0+gitAUTOINC+ce58f56108-r0/git/xen/arch/arm/irq.c:445:
undefined reference to `vgic_is_valid_irq'/usr/src/debug/xen/4.18.0+gitAUTOINC+ce58f56108-r0/git/xen/arch/arm/irq.c:445:(.text+0x5e2f8):
relocation truncated to fit:R_AARCH64_CALL26against undefined symbol `vgic_is_valid_irq'
...
Quoted 4 lines
From the quick look,
vgic_is_valid_irq()needs a stub (or NEW_VGIC's
counterpart).[snip]
Thank you for your review and for testing the patch series with different config options. I will add the vgic_is_valid_irq counterpart (after discussion, we decided to rename the function to vgic_is_valid_line) for NEW_VGIC and recheck the build with NEW_VGIC config.
Best regards,
Leonid.
Re: [PATCH v2 05/10] xen/arm: gicv3: implement handling of GICv3.1 eSPI
In reply to Oleksandr TyshchenkoHi Oleksandr,
Thank you for your review comments.
Quoted 86 lines · Oleksandr Tyshchenko
[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
On 07.08.25 15:33, Leonid Komarianskyi wrote:
Hello Leonid
Quoted 78 lines
Introduced 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.
Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- movegic_number_espisfunction from
[PATCH 08/10] xen/arm: vgic: add resource management for extended SPIs to use it in the newly introducedgic_is_valid_espi
- addgic_is_valid_espiwhich checks if IRQ number is in supported by HW eSPI range
- updategic_is_valid_irqconditions to allow operations with eSPIs
---
xen/arch/arm/gic-v3.c | 73 ++++++++++++++++++++++++++ xen/arch/arm/include/asm/gic.h | 17 ++++++xen/arch/arm/include/asm/gic_v3_defs.h| 33 ++++++++++++3 files changed, 123 insertions(+)xen/arch/arm/gic-v3.c +0
-0@@ -485,6 +485,36 @@ static void __iomem *get_addr_by_offset(struct irq_desc *irqd, u32 offset)default:
break;
}xen/arch/arm/gic-v3.c +30
-0+#ifdef CONFIG_GICV3_ESPI + case ESPI_BASE_INTID ... ESPI_MAX_INTID: + { + u32 irq_index = ESPI_INTID2IDX(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;
}xen/arch/arm/gic-v3.c +0
-0@@ -645,6 +675,40 @@ static void gicv3_set_irq_priority(structirq_desc *desc, spin_unlock(&gicv3.lock); }
Quoted 10 lines
xen/arch/arm/gic-v3.c static void gicv3_set_irq_priority(struct irq_desc *desc, · line 684
Quoted 7 lines
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 gicv3_dist_espi_common_init (uint32_t type)missing
__init?
Yes, I missed this. I will add it in V3.
Quoted 6 lines
xen/arch/arm/gic-v3.c static void gicv3_set_irq_priority(struct irq_desc *desc, · line 687
Quoted 3 lines
xen/arch/arm/gic-v3.c +3
-0+{ + unsigned int espi_nr; + int i;please use unsigned int if "i" cannot be negative
Sure, I will change int to unsigned int, because it really cannot be negative.
Quoted 56 lines
Quoted 56 lines
xen/arch/arm/gic-v3.c +17
-0+ + 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; + + 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(0xffffffffU, GICD + GICD_ICENABLERnE + (i /32 ) *4 ); + writel_relaxed(0xffffffffU, 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);xen/arch/arm/gic-v3.c +3
-0+} +#endif +static void
__initgicv3_dist_init(void)
{
uint32_ttype;xen/arch/arm/gic-v3.c +0
-0@@ -690,6 +754,10 @@ 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);xen/arch/arm/gic-v3.c +4
-0+#ifdef CONFIG_GICV3_ESPI + gicv3_dist_espi_common_init(type); +#endif +
gicv3_dist_wait_for_rwp();/* Turn on the distributor */
xen/arch/arm/gic-v3.c +0
-0@@ -703,6 +771,11 @@ 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);xen/arch/arm/gic-v3.c +4
-0+ +#ifdef CONFIG_GICV3_ESPI + for ( i = 0; i < gicv3_info.nr_espi; i++ ) + writeq_relaxed_non_atomic(affinity, GICD + GICD_IROUTERnE + i* 8);
+#endif
}
Quoted 5 lines
Quoted 1 line
static int
gicv3_enable_redist(void)[snip]
Best regards,
Leonid
Re: [PATCH v2 08/10] xen/arm: vgic: add resource management for extended SPIs
In reply to Oleksandr TyshchenkoHello Oleksandr,
Thank you for your close review.
Quoted 162 lines · Oleksandr Tyshchenko
On 07.08.25 15:33, Leonid Komarianskyi wrote:
Hello Leonid
Quoted 155 lines
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.
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]>---
Changes 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| 18 ++++ xen/arch/arm/vgic.c | 145 ++++++++++++++++++++++++++++++++2 files changed, 163 insertions(+)xen/arch/arm/include/ renamed from xen/arch/arm/include/asm/vgic.h +0
-0
asm/vgic.h
index45201f4ca5..9fa4523018100644xen/arch/arm/include/asm/vgic.h +0
-0@@ -146,6 +146,10 @@ struct vgic_dist {int
nr_spis; /* Number of SPIs */
unsigned long*allocated_irqs; /* bitmap of IRQs allocated */ structvgic_irq_rank*shared_irqs;xen/arch/arm/include/asm/vgic.h +4
-0+#ifdef CONFIG_GICV3_ESPI + struct vgic_irq_rank *ext_shared_irqs; + int nr_espis; /* Number of extended SPIs */ +#endif /*
* SPIs are domain global, SGIs and PPIs are per-VCPU and stored in
* structarch_vcpu.xen/arch/arm/include/asm/vgic.h +14
-0@@ -243,6 +247,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) +#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) +#endif + #define vgic_lock(v) spin_lock_irq(&(v)->domain->arch.vgic.lock) #define vgic_unlock(v) spin_unlock_irq(&(v)->domain->arch.vgic.lock)@@ -302,6 +314,12 @@ extern struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, unsigned int b, unsigned int n, unsigned int s); +#ifdef CONFIG_GICV3_ESPI +extern struct vgic_irq_rank *vgic_ext_rank_offset (struct vcpu *v, + unsigned int b, + unsigned int n, + unsigned int s); +#endif extern struct
vgic_irq_rank*vgic_rank_irq(struct vcpu *v, unsigned int irq);
extern voidvgic_disable_irqs(struct vcpu *v, uint32_t r, unsigned int n);
extern voidvgic_enable_irqs(struct vcpu *v, uint32_t r, unsigned int n);xen/arch/arm/vgic.c +17
-0@@ -27,9 +27,26 @@ bool vgic_is_valid_irq(struct domain *d, unsigned int virq) { +#ifdef CONFIG_GICV3_ESPI + if ( virq >= ESPI_BASE_INTID && virq < ESPI_IDX2INTID(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) ); +} +#endif + static inline struct vgic_irq_rank *vgic_get_rank(struct vcpu *v, unsigned int rank){
xen/arch/arm/vgic.c +4
-0@@ -37,6 +54,10 @@ 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]; +#ifdef CONFIG_GICV3_ESPI + else if ( is_valid_espi_rank(v->domain, rank) ) + return &v->domain- >arch.vgic.ext_shared_irqs[EXT_RANK_NUM2IDX(rank)]; +#endif else
return NULL;
}xen/arch/arm/vgic.c +10
-0@@ -53,6 +74,16 @@ struct vgic_irq_rank *vgic_rank_offset(struct vcpu *v, unsigned int b, return vgic_get_rank(v, rank); } +#ifdef CONFIG_GICV3_ESPI +struct vgic_irq_rank *vgic_ext_rank_offset (struct vcpu *v,unsigned int b, + unsigned int n, unsignedint s) +{ + unsigned int rank = REG_RANK_NR(b, (n >> s)); + + return vgic_get_rank(v, rank + EXT_RANK_MIN); +} +#endif + struct vgic_irq_rank *vgic_rank_irq(struct vcpu *v, unsigned int irq){
unsigned int rank = irq / 32;xen/arch/arm/vgic.c +0
-0@@ -117,6 +148,29 @@ int domain_vgic_register(struct domain *d, unsigned int *mmio_count)
Quoted 9 lines
xen/arch/arm/vgic.c int domain_vgic_register(struct domain *d, unsigned int *mmio_count) · line 154
Quoted 6 lines
xen/arch/arm/vgic.c +4
-0return 0; } +#ifdef CONFIG_GICV3_ESPI +static int init_vgic_espi (struct domain *d) +{ + int i;please use unsigned int if "i" cannot be negative
Sure, I will change the type to unsigned int in V3.
Quoted 32 lines
Quoted 32 lines
xen/arch/arm/vgic.c +19
-0+ + 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 = 0; i < d->arch.vgic.nr_espis; i++ ) + vgic_init_pending_irq(&d->arch.vgic.pending_irqs[i + d- >arch.vgic.nr_spis], ESPI_IDX2INTID(i)); + + for ( i = 0; i < DOMAIN_NR_EXT_RANKS(d); i++ ) + vgic_rank_init(&d->arch.vgic.ext_shared_irqs[i], i, 0); + + return 0; +} +#endif + int domain_vgic_init(struct domain *d, unsigned int nr_spis) {int i;
xen/arch/arm/vgic.c +5
-0@@ -131,6 +185,30 @@ int domain_vgic_init(struct domain *d, unsignedint nr_spis) */ nr_spis = ROUNDUP(nr_spis, 32); +#ifdef CONFIG_GICV3_ESPI + if ( nr_spis > ESPI_MAX_INTID ) + return -EINVAL; + + if ( is_espi(nr_spis) )
Quoted 9 lines
xen/arch/arm/vgic.c int domain_vgic_init(struct domain *d, unsigned int nr_spis)
Quoted 4 lines
xen/arch/arm/vgic.c +3
-0+ { + /* +* During domain creation, the toolstack specifies the maximum INTID,
domain_vgic_init()is also called for dom0less DomUs (if present), which are created at Xen boot. So the toolstack might even be absent on the target system.
Thank you for pointing this out. I revised the patch series and found that I did not change the behavior for dom0less builds. I will fix it in V3 and update the comment.
Quoted 56 lines
Quoted 56 lines
xen/arch/arm/vgic.c +1
-0+ * which is defined in the domain config subtracted by 32. Tocompute the
+ * actual number of eSPI that will be usable for, add back 32. + */
+d->arch.vgic.nr_espis=min(nr_spis - ESPI_BASE_INTID + 32, 1024U);
+ /* Verify if GIC HW can handle provided INTID */
+ if (d->arch.vgic.nr_espis>gic_number_espis())
+ return-EINVAL;
+ /* Set the maximum available number for defult SPI to pass the next check */
+nr_spis=VGIC_DEF_NR_SPIS;
+ } else
+ {
+ /* Domain will use the regular SPI range */
+d->arch.vgic.nr_espis= 0;
+ }xen/arch/arm/vgic.c +2
-0+#endif +/* Limit the number of virtual SPIs supported to (1020 - 32) = 988 */
if (nr_spis> (1020 -NR_LOCAL_IRQS) )
return-EINVAL;xen/arch/arm/vgic.c +0
-0@@ -145,7 +223,12 @@ int domain_vgic_init(struct domain *d, unsigned int nr_spis) return -ENOMEM;
d->arch.vgic.pending_irqs=xen/arch/arm/vgic.c +4
-0+#ifdef CONFIG_GICV3_ESPI + xzalloc_array(struct pending_irq, d->arch.vgic.nr_spis + + d->arch.vgic.nr_espis); +#else
xzalloc_array(struct pending_irq, d->arch.vgic.nr_spis); +#endif
if (d->arch.vgic.pending_irqs== NULL )
return-ENOMEM;xen/arch/arm/vgic.c +6
-0@@ -156,12 +239,23 @@ 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); +#ifdef CONFIG_GICV3_ESPI + ret = init_vgic_espi(d); + if ( ret ) + return ret; +#endif + ret = d->arch.vgic.handler->domain_init(d); if ( ret ) return ret;
d->arch.vgic.allocated_irqs=xen/arch/arm/vgic.c +4
-0+#ifdef CONFIG_GICV3_ESPI + xzalloc_array(unsigned long, BITS_TO_LONGS(vgic_num_irqs(d) + + d->arch.vgic.nr_espis)); +#else
xzalloc_array(unsigned long, BITS_TO_LONGS(vgic_num_irqs(d))); +#endif
if ( !d->arch.vgic.allocated_irqs )
Quoted 9 lines
xen/arch/arm/vgic.c void domain_vgic_free(struct domain *d) · line 292
Quoted 6 lines
return
-ENOMEM;xen/arch/arm/vgic.c +2
-0@@ -195,9 +289,27 @@ void domain_vgic_free(struct domain *d) } } +#ifdef CONFIG_GICV3_ESPI + for ( i = 0; i < (d->arch.vgic.nr_espis); i++ )NIT: no need for () around
d->arch.vgic.nr_espis
I will remove them in V3.
Quoted 25 lines
Quoted 25 lines
xen/arch/arm/vgic.c +16
-0+ { + struct pending_irq *p = spi_to_pending(d, ESPI_IDX2INTID(i)); + + if ( p->desc ) + { + ret = release_guest_irq(d, p->irq); + if ( ret ) + dprintk(XENLOG_G_WARNING, "d%u: Failed to release virq %u ret = %d\n", + d->domain_id, p->irq, ret); + } + } +#endif + 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); }@@ -331,6 +443,17 @@ void arch_move_irqs(struct vcpu *v)if (
v_target== v && !test_bit(GIC_IRQ_GUEST_MIGRATING, &p-
Quoted 8 lines
xen/arch/arm/vgic.c void arch_move_irqs(struct vcpu *v) · line 448
Quoted 6 lines
Quoted 1 line
status) )
irq_set_affinity(p->desc, cpu_mask); }xen/arch/arm/vgic.c +3
-0+ +#ifdef CONFIG_GICV3_ESPI + for ( i = ESPI_BASE_INTID; i < (d)->arch.vgic.nr_espis; i++ )NIT: no need for () around d
I will remove them in V3.
Quoted 2 lines
[snip]
Best regards,
Leonid
Re: [PATCH v2 09/10] xen/arm: domain_build: adjust Dom0 IRQ handling to support eSPIs
In reply to Oleksandr TyshchenkoHello Oleksandr,
Thank you for your question.
Quoted 48 lines · Oleksandr Tyshchenko
[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
On 07.08.25 15:33, Leonid Komarianskyi wrote:
Hello Leonid
Quoted 41 lines
The Dom0 configuration logic in
create_dom0()has been updated to account for extended SPIs when supported by the hardware and enabled withCONFIG_GICV3_ESPI. These changes ensure the proper calculation of the maximum number of SPIs and eSPIs available for Dom0.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 limited at 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 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 now.Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- no changes
---
xen/arch/arm/domain_build.c | 10 ++++++++++xen/arch/arm/include/asm/vgic.h| 11 +++++++++++2 files changed, 21 insertions(+)xen/arch/arm/domain_build.c +3
-0@@ -2055,6 +2055,16 @@ 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; +#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 overwrite thenr_spiswith the
+ * maximum available INTID from eSPI range. In that case, the number of regular SPIs will
+ * be adjusted to the maximum value during vGIC initialization.
Quoted 9 lines
Quoted 4 lines
+ */
+ if (gic_number_espis()> 0 )
+ dom0_cfg.arch.nr_spis =VGIC_DEF_NR_ESPIS; +#endifI might miss something, but within the whole series, you seem not to update "
nr_spis" field for dom0less DomUs (indom0less-build.c). Please clarify the reason?
Yes, I missed this because I was mostly focused on the build (with Dom0) that I currently have on the platform with eSPI. I rechecked the code, and the dom0less code has the same behavior, so I believe it should work similarly with the same changes in arch_create_domUs. I will update it in V3.
Quoted 5 lines
Quoted 3 lines
dom0_cfg.arch.tee_type =
tee_get_type();
dom0_cfg.max_vcpus =dom0_max_vcpus();[snip]
Best regards,
Leonid
Hello Oleksandr,
Quoted 27 lines · Oleksandr Tyshchenko
Quoted 1 line · Leonid Komarianskyi
Hello everyone!
Hello Leonid,
Quoted 12 lines
### Background
Unlike the Linux kernel, which has supported extended shared peripheral interrupts (eSPIs) since 2019 [1], Xen currently lacks support for this interrupt range. For SoCs with GICv3.1+, this feature may be essential because critical devices, such as consoles required for booting Xen itself, may rely on eSPIs. Additionally, these platforms require eSPI support for fully functional domains, as any device using eSPIs cannot currently be used with Xen setups. Without eSPI support, Xen cannot run properly on these platforms, significantly limiting its usability on modern ARM hardware.Quoted 6 lines
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.
Quoted 8 lines
I have lightly re-checked the simple Arm64 Xen environment (dom0less DomU under QEMU) with your series applied. To be clear, I did not really test the eSPI support (the underlying GICv3 HW does support it); I just wanted to ensure that your series would not break anything. So, in both cases (
CONFIG_GICV3_ESPI=yandCONFIG_GICV3_ESPI=n), I did not notice any issues (at least obvious) related to GICv3 emulation and SPI injection for the passed-through device.
Thank you for your verification and proving that all works as expected on setup without HW eSPI support:)
Quoted 4 lines
Also, I think you want to describe the eSPI feature in the CHANGELOG.md.
[snip]
Okay, I will add one more patch in V3 to update the CHANGELOG.md file.
Best regards,
Leonid
Re: [PATCH v2 10/10] xen/arm: vgic-v3: add emulation of GICv3.1 eSPI registers
In reply to Volodymyr BabchukHello Volodymyr,
Quoted 107 lines · Volodymyr Babchuk
Hi Leonid,
Quoted 31 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.Signed-off-by Leonid Komarianskyi <[email protected]>---
Changes in V2:
- add missing rank index conversion for pending and inflight irqs--- xen/arch/arm/vgic-v3.c | 248 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 245 insertions(+), 3 deletions(-)xen/arch/arm/vgic-v3.c +0
-0xen/arch/arm/vgic-v3.c static uint64_t vgic_fetch_irouter(struct vgic_irq_rank *rank, · line 114
Quoted 5 lines
xen/arch/arm/vgic-v3.c +1
-1@@ -111,7 +111,7 @@ static uint64_t vgic_fetch_irouter(struct vgic_irq_rank *rank,* Note the offset will be aligned to the appropriate boundary. */ static void vgic_store_irouter (struct domain *d,struct vgic_irq_rank *rank, -unsigned int offset,uint64_t irouter) +unsigned int offset,uint64_t irouter,bool espi)I am wondering: maybe it is better to pass virq instead of offset into this function? In that case you can get rid of espi parameter.
xen/arch/arm/vgic-v3.c static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank, · line 127
Quoted 10 lines
xen/arch/arm/vgic-v3.c +2
-1{struct vcpu *new_vcpu, *old_vcpu;unsigned int virq;@@ -123,7 +123,8 @@ static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank,* The IROUTER0-31, used for SGIs/PPIs, are reserved and should * never call this function. */ -ASSERT (virq >=32 ); +if ( !espi ) +ASSERT (virq >=32 );better to write
ASSERT (!espi & (virq>=32))and probably you need symmetrical ASSERT for espi == true
xen/arch/arm/vgic-v3.c static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank, · line 154
Quoted 11 lines
xen/arch/arm/vgic-v3.c +5
-0/* Get the index in the rank */ offset = virq &INTERRUPT_RANK_MASK ;@@ -146,6 +147,11 @@ static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank,/* Only migrate the IRQ if the target vCPU has changed */ if ( new_vcpu != old_vcpu ) { +#ifdef CONFIG_GICV3_ESPI +/* Convert virq index to eSPI range */ +if ( espi ) + virq =ESPI_IDX2INTID (virq); +#endif If you define
ESPI_IDX2INTID()uncoditionally, you can get rid of #ifdefCONFIG_GICV3_ESPIherexen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, · line 694
Quoted 8 lines
xen/arch/arm/vgic-v3.c +1
-0if (vgic_migrate_irq (old_vcpu, new_vcpu, virq) )write_atomic (&rank->vcpu[offset], new_vcpu->vcpu_id); }@@ -685,6 +691,9 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, {case VRANGE32 (GICD_IGROUPR ,GICD_IGROUPRN ):case VRANGE32 (GICD_IGRPMODR ,GICD_IGRPMODRN ): +#ifdef CONFIG_GICV3_ESPI Do you really need ifdef here?
xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, · line 722
Quoted 12 lines
xen/arch/arm/vgic-v3.c +2
-0+case VRANGE32 (GICD_IGROUPRnE, GICD_IGROUPRnEN): +#endif /* We do not implement security extensions for guests, read zero */ if ( dabt.size != DABT_WORD ) goto bad_width; goto read_as_zero;xen/arch/arm/vgic-v3.c +1
-0@@ -710,11 +719,19 @@ static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v,/* Read the pending status of an IRQ via GICD/GICR is not supported */ case VRANGE32 (GICD_ISPENDR ,GICD_ISPENDRN ):case VRANGE32 (GICD_ICPENDR ,GICD_ICPENDRN ): +#ifdef CONFIG_GICV3_ESPI Same as here
Quoted 5 lines
xen/arch/arm/vgic-v3.c +3
-0+case VRANGE32 (GICD_ISPENDRnE, GICD_ISPENDRnEN): +case VRANGE32 (GICD_ICPENDRnE, GICD_ICPENDRnEN): +#endif goto read_as_zero;
Quoted 7 lines
xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_read(const char *name, struct vcpu *v, · line 731
Quoted 4 lines
xen/arch/arm/vgic-v3.c +1
-0/* Read the active status of an IRQ via GICD/GICR is not supported */ case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):case VRANGE32 (GICD_ICACTIVER ,GICD_ICACTIVERN ): +#ifdef CONFIG_GICV3_ESPI ... and here and in all other places
I have rechecked the idea of removing some of the #ifdefs, and unfortunately, I cannot simply do this as is here, because in this case, I would need to move the register offsets out of the CONFIG_GICV3_ESPI guard in the previous patch in the series. Please see:
[PATCH v2 05/10] xen/arm: gicv3: implement handling of GICv3.1 eSPI
As a result, with CONFIG_GICV3_ESPI disabled, we would have many unused defines and also unreachable code in __vgic_v3_distr_common_mmio_read and __vgic_v3_distr_common_mmio_write (I think the MISRA team will not be happy about this..). Thus, I prefer to leave the #ifdefs as they are. However, if you think it is better to remove the #ifdefs, I will update the appropriate patch to make these changes compilable with fewer #ifdefs and CONFIG_GICV3_ESPI disabled.
Best regards,
Leonid