Introduce eSPI support
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
Leonid Komarianskyi (10):
xen/arm: gicv3: refactor obtaining GIC addresses for common operations xen/arm/irq: add handling for IRQs in the eSPI range xen/arm: gicv3: implement handling of GICv3.1 eSPI xen/arm/irq: allow assignment/releasing of eSPI interrupts xen/arm: gic/irq: permit routing of eSPI interrupts to Xen and domains 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 | 6 +- xen/arch/arm/include/asm/gic.h | 7 + xen/arch/arm/include/asm/gic_v3_defs.h | 37 ++++ xen/arch/arm/include/asm/irq.h | 26 +++ xen/arch/arm/include/asm/vgic.h | 39 ++++ xen/arch/arm/irq.c | 42 ++++- xen/arch/arm/vgic-v3.c | 248 ++++++++++++++++++++++++- xen/arch/arm/vgic.c | 133 ++++++++++++- 11 files changed, 682 insertions(+), 47 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/10 xen/arm: gicv3: refactor obtaining GIC addresses for common operations
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.
--- 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
Re: [PATCH 01/10] xen/arm: gicv3: refactor obtaining GIC addresses for common operations
Hi Leonid,
Quoted 55 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.
Quoted 1 line
Signed-off-by Leonid Komarianskyi <[email protected]>--- 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);
This panic is worrying me because we have multiple switch above and it is difficult to figure out whether everything was covered. Looking at the code, it seems the main advantage would be for ISENABLER/ICENABLER & co because they are using the same logic.
Therefore if you want to consolidate some code, then I would prefer if we introduce an helper just to deal with that logic. The rest (i.e. ICFGR, IROUTER, IPRIORITY) should stay inlined.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 01/10] xen/arm: gicv3: refactor obtaining GIC addresses for common operations
Hello Julien,
Thank you for your close review and comments.
Quoted 65 lines · Julien Grall
Hi Leonid,
Quoted 62 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.Quoted 1 line
Signed-off-by Leonid Komarianskyi <[email protected]>---
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 +41
-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: + return (GICD + GICD_IPRIORITYR + irqd->irq); + default: + break; + } + default:
Quoted 8 lines
xen/arch/arm/gic-v3.c static void gicv3_dump_state(const struct vcpu *v) · line 493
Quoted 5 lines
xen/arch/arm/gic-v3.c +5
-0+ break; + } + + /* Something went wrong, we shouldn't be able to reach here */ + panic("Invalid offset 0x%x for IRQ#%d", offset, irqd->irq);This panic is worrying me because we have multiple switch above and it is difficult to figure out whether everything was covered. ...
Initially, I was thinking about handling the errors more gently when dealing with invalid INTIDs or offsets. It looked like this:
addr = get_addr_by_offset(desc, GICD_ICFGR);
if ( !addr ) {
pr_err("GICv3: cannot perform GIC operation invalid offset 0x%x
for IRQ#%d\n", offset, irq);
return;
}However, there is an issue with the gicv3_peek_irq function. Since it returns a bool, we cannot simply return either true or false from the function, as it will be interpreted as a valid value by the caller, even with an error message. For this reason, I decided to cover all valid INTIDs and offsets and trigger a panic only in an exceptionally rare case where we cannot obtain the correct address due to unexpected parameters.
Regarding your concerns about the panic:
After your comments, I rechecked the code and found that there is only one combination of INTID and offset where an invalid offset would trigger a panic compared with the mainline implementation:gicv3_irq_set_affinity is invoked for INTIDs < NR_GIC_LOCAL_IRQS. Currently, in mainline implementation it does nothing in this particular case:
if ( desc->irq >= NR_GIC_LOCAL_IRQS )
writeq_relaxed_non_atomic(affinity, (GICD + GICD_IROUTER +desc->irq * 8));
This is not a valid situation because, according to the GICv3
specification: GICD_IROUTER<n>, where n in range from 32 to 1019. Nevertheless, I will update the code to maintain the existing behavior unchanged without potential panic in this case.
Also, here are details, why panic will not be happened in real-life scenario:
The function is invoked from 5 places, and its behavior depends on two input parameters - the interrupt number and the offset. The main switch-case covers all valid INTIDs from 0 to 1019 (and will also cover the additional eSPI range from 4096 to 5119 with further changes). The current implementation prevents calling this function with different INTIDs, meaning that passing an invalid INTID represents a truly critical issue that could potentially result only from improper code changes or unpredictable errors (e.g., memory corruption). Moreover, compared to the current mainline implementation, passing an invalid IRQ would silently write to an unknown address, which is at least harder to debug. On the other hand, triggering a panic makes it much easier to identify, debug, and resolve this potential issue.
The second part is nested switch-case that handles all of possible defined values that can be passed to the function such as:GICD_ISENABLER, GICD_ICENABLER, GICD_ISPENDR, GICD_ICPENDR, GICD_ISACTIVER, GICD_ICACTIVER, GICD_ICFGR, GICD_IROUTER and GICD_IPRIORITYR.
Even with the current mainline implementation, there are no ways to invoke e.g. gicv3_poke/peek_irq, gicv3_set_irq_type, gicv3_set_irq_priority or gicv3_irq_set_affinity with some differ offset values as mentioned previously.
To summarize, a panic would occur only in two cases: improper future code modifications or unpredictable errors (e.g., memory corruption). In my opinion, it would require a major issue to trigger the panic.
What do you think? Is it acceptable to leave the panic here after the clarifications described above, or would it be better to handle it in a different way?
Quoted 3 lines
... Therefore if you want to consolidate some code, then I would prefer if we introduce an helper just to deal with that logic. The rest (i.e. ICFGR, IROUTER, IPRIORITY) should stay inlined.
The changes in this patch not only refactor existing logic but also simplify the implementation of eSPI handling in the third patch of this series:
https://patchew.org/Xen/[email protected]/790b1d3876206c8236986d7237173dacae99cac2.1753367178.git.leonid._5Fkomarianskyi@epam.com/
If this function were to handle only some of the required GIC registers, it would necessitate many additional #ifdefs and if conditions in the remaining functions. For example, if get_addr_by_offset did not handle GICD_IROUTER, GICD_ICFGR, and GICD_IPRIORITYR offsets, adding eSPI-related code would look like this:
gicv3_set_irq_type:
...
if ( irq >= NR_GIC_LOCAL_IRQS)
base = GICD + GICD_ICFGR + (irq / 16) * 4;
else
base = GICD_RDIST_SGI_BASE + GICR_ICFGR1;
#ifdef CONFIG_GICV3_ESPI
if (is_espi(irq))
base = (GICD + GICD_ICFGRnE + (ESPI_INTID2IDX(irq) / 16) * 4);#endif
gicv3_irq_set_affinity:
...
#ifdef CONFIG_GICV3_ESPI
if (is_espi(desc->irq))
writeq_relaxed_non_atomic(affinity, (GICD + GICD_IROUTERnE +ESPI_INTID2IDX(desc->irq) * 8));
else
#endif
if ( desc->irq >= NR_GIC_LOCAL_IRQS )
writeq_relaxed_non_atomic(affinity, (GICD + GICD_IROUTER +desc->irq * 8));
gicv3_set_irq_priority:
...
/* Set priority */
if ( irq < NR_GIC_LOCAL_IRQS )
writeb_relaxed(priority, GICD_RDIST_SGI_BASE + GICR_IPRIORITYR0
+ irq);
else
#ifdef CONFIG_GICV3_ESPI
if (is_espi(irq))
writeb_relaxed(priority, GICD + GICD_IPRIORITYRnE +ESPI_INTID2IDX(irq));
else
#endif
writeb_relaxed(priority, GICD + GICD_IPRIORITYR + irq);This code seems less readable, so I opted to refactor all relevant locations and prepare a single function that can be easily modified and maintained. By the way, I was inspired by a Linux kernel patch that was introduced in the same series as the eSPI support implementation for Linux. That patch refactored the code prior to implementing eSPI:
https://github.com/torvalds/linux/commit/e91b036e1c20d80419164ddfc32125052df3fb39
So I decided to make the changes in a similar way - on the first step, refactoring the existing functionality to make implementing eSPI support smoother. And then introduce the eSPI implementation.
I would really like to hear your thoughts after my comments, on whether keeping the current handling of the entire register group makes sense, or not.
Cheers,
Leonid
PATCH 2/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.
--- xen/arch/arm/Kconfig | 9 +++++++++ xen/arch/arm/include/asm/irq.h | 25 +++++++++++++++++++++++++ xen/arch/arm/irq.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 64 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_BASE_INTID + NR_IRQS) +#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 +30 -0
@@ -19,7 +19,15 @@#include <asm/gic.h> #include <asm/vgic.h> +#ifdef CONFIG_GICV3_ESPI +/* +* To operate with IRQs in the eSPI range (4096-5119), +* we need to add the eSPI base interrupt ID. +*/ +const unsigned int nr_irqs =ESPI_BASE_INTID +NR_IRQS ; +#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 +54,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 +64,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 +95,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
Re: [PATCH 02/10] xen/arm/irq: add handling for IRQs in the eSPI range
Hi Leonid,
Quoted 60 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.Signed-off-by Leonid Komarianskyi <[email protected]>--- xen/arch/arm/Kconfig | 9 +++++++++ xen/arch/arm/include/asm/irq.h | 25 +++++++++++++++++++++++++ xen/arch/arm/irq.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 64 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_BASE_INTID + NR_IRQS) +#else #define nr_static_irqs NR_IRQS +#endif
This seems a bit odd. NR_IRQS is supposed to indicate the last SPIs ID. This sort of works because in both case we have 1024. But this is really fragile. So I thin nr_irqs needs to be set to ESPI_MAX_INTID.
Same ...
Quoted 24 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 +0
-0
xen/arch/arm/irq.c line 27
Quoted 9 lines
xen/arch/arm/irq.c +6
-0@@ -19,7 +19,15 @@#include <asm/gic.h> #include <asm/vgic.h> +#ifdef CONFIG_GICV3_ESPI +/* +* To operate with IRQs in the eSPI range (4096-5119), +* we need to add the eSPI base interrupt ID. +*/ +const unsigned int nr_irqs =ESPI_BASE_INTID +NR_IRQS ;
... here.
xen/arch/arm/irq.c void irq_end_none(struct irq_desc *irq) · line 59
Quoted 12 lines
xen/arch/arm/irq.c +5
-0+#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 +54,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
Why do we have to introduce a new array? Can't we use irq_desc?
Quoted 26 lines
xen/arch/arm/irq.c +12
-0static DEFINE_PER_CPU(irq_desc_t[NR_LOCAL_IRQS], local_irq_desc);struct irq_desc *__irq_to_desc (unsigned int irq)@@ -53,6 +64,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 +95,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 )
xen/arch/arm/irq.c static int __init init_irq_data(void) · line 114
Quoted 10 lines
xen/arch/arm/irq.c +7
-0+return rc; + + desc->irq = irq; + desc->action = NULL; + } +#endif +return 0 ; }
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 02/10] xen/arm/irq: add handling for IRQs in the eSPI range
Hi Julien,
Thank you for your close review and comments.
Quoted 69 lines · Julien Grall
Hi Leonid,
Quoted 66 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.Signed-off-by Leonid Komarianskyi <[email protected]>---
xen/arch/arm/Kconfig | 9 +++++++++xen/arch/arm/include/asm/irq.h| 25 +++++++++++++++++++++++++ xen/arch/arm/irq.c | 30 ++++++++++++++++++++++++++++++3 files changed, 64 insertions(+)xen/arch/arm/Kconfig +0
-0@@ -135,6 +135,15 @@ config GICV3Driver for the ARM Generic Interrupt Controller v3. If unsure, use the default setting.
+configGICV3_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.
+
configHAS_ITS
bool "GICv3 ITS MSI controller support (UNSUPPORTED)" if UNSUPPORTED
depends on GICV3 && !NEW_VGIC && !ARM_32xen/arch/arm/include/ renamed from xen/arch/arm/include/asm/irq.h +0
-0
asm/irq.h
index5bc6475eb4..d621f17f10100644xen/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 invalidcase. */
#define INVALID_LPI 0xen/arch/arm/include/asm/irq.h +5
-0@@ -39,7 +47,15 @@ struct arch_irq_desc { #define INVALID_IRQ 1023 extern 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. +*/
Quoted 8 lines
xen/arch/arm/include/asm/irq.h struct arch_irq_desc { · line 58
Quoted 4 lines
xen/arch/arm/include/asm/irq.h +3
-0+#define nr_static_irqs (ESPI_BASE_INTID + NR_IRQS) +#else #define nr_static_irqs NR_IRQS +#endif This seems a bit odd.
NR_IRQSis supposed to indicate the last SPIs ID. This sort of works because in both case we have 1024. But this is really fragile. So I thinnr_irqsneeds to be set toESPI_MAX_INTID. ...
Yes, you're right, I will update it to (ESPI_MAX_INTID + 1). The +1 is needed to cover IRQ number 5119, as this define is used in flask/hooks.c and expects that IRQ number will be less than nr_static_irqs:
static int get_irq_sid(int irq, uint32_t *sid, struct avc_audit_data *ad)
{
if ( irq >= nr_irqs || irq < 0 )
return -EINVAL;
if ( irq < nr_static_irqs ) {
if (ad) {
AVC_AUDIT_DATA_INIT(ad, IRQ);
ad->irq = irq;
}
return security_irq_sid(irq, sid);
}....
or:
static int cf_check flask_map_domain_irq(
struct domain *d, int irq, const void *data)
{
uint32_t sid, dsid;
int rc = -EPERM;
struct avc_audit_data ad;
uint32_t dperm = flask_iommu_resource_use_perm(d);
if ( irq >= nr_static_irqs && data )
rc = flask_map_domain_msi(d, irq, data, &sid, &ad);....
Quoted 34 lines
Same ...
Quoted 21 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 +0
-0xen/arch/arm/irq.c line 26
Quoted 8 lines
xen/arch/arm/irq.c +6
-0@@ -19,7 +19,15 @@ #include <asm/gic.h> #include <asm/vgic.h> +#ifdef CONFIG_GICV3_ESPI +/* +* To operate with IRQs in the eSPI range (4096-5119), +* we need to add the eSPI base interrupt ID. +*/ +const unsigned int nr_irqs =ESPI_BASE_INTID +NR_IRQS ;... here.
Quoted 12 lines
xen/arch/arm/irq.c void irq_end_none(struct irq_desc *irq) · line 58
Quoted 10 lines
xen/arch/arm/irq.c +5
-0+#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 +54,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 Why do we have to introduce a new array? Can't we use
irq_desc?...
I added the new array because reusing the existing array would leave us with two options:
1) Extending the existing array to ESPI_MAX_INTID: It is a bad idea, because vGIC3.1 has reserved range for INTIDs. This is not obvious when working with regular SPIs, as their INTIDs range from 32 to 1019. But for eSPIs, INTIDs start at 4096, while the range from 1024 to 4095 is reserved. Extending the existing array to ESPI_MAX_INTID would unnecessarily add over 3000 irq_desc_t entries that would never be used.
2) Extend the existing array to exact 1024 more elements: This avoids unused entries but complicates accessing irq_desc. In this case we would require in __irq_to_desc to make additional calculation for index. In the current version:
return &espi_desc[ESPI_INTID2IDX(irq)];
Here, it the macro simply subtracts ESPI_BASE_INTID from the given IRQ INTID. But while reusing the same array would look like this:
return &irq_desc[ESPI_INTID2IDX(irq) + NR_IRQS - NR_LOCAL_IRQS];
Since irq_to_desc (which means __irq_to_desc), is called from many places, I decided to introduce a second array to minimize runtime calculations when accessing irq_desc_t elements.
This is purely an optimization, though. If you think option 2 would be better, I will update the code in the v2.
Cheers,
Leonid
PATCH 3/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.
--- xen/arch/arm/gic-v3.c | 68 ++++++++++++++++++++++++++ xen/arch/arm/include/asm/gic.h | 4 ++ xen/arch/arm/include/asm/gic_v3_defs.h | 33 +++++++++++++ 3 files changed, 105 insertions(+)
xen/arch/arm/gic-v3.c +68 -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,35 @@ static void gicv3_set_irq_priority(struct irq_desc *desc,spin_unlock (&gicv3.lock); } +#ifdef CONFIG_GICV3_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 +749,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 +766,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 +4 -0
@@ -316,6 +316,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 4/10 xen/arm/irq: allow assignment/releasing of eSPI interrupts
In reply to Leonid KomarianskyiThe current checks don't allow us to assign or release interrupts with INTID greater than 1024. This patch adds an additional condition to check whether the IRQ number is in the eSPI range and allows it to be assigned to Xen and domains if it is.
--- xen/arch/arm/irq.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
xen/arch/arm/irq.c +4 -4
@@ -444,8 +444,8 @@ 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 ()); +/* For now, we can only route SPIs and eSPIs to the guest */ +return (((irq >=NR_LOCAL_IRQS ) && (irq <gic_number_lines ())) ||is_espi (irq)); }/*
@@ -589,8 +589,8 @@ int release_guest_irq(struct domain *d, unsigned int virq)unsigned long flags;int ret; -/* Only SPIs are supported */ -if ( virq <NR_LOCAL_IRQS || virq >=vgic_num_irqs (d) ) +/* Only SPIs and eSPIs are supported */ +if ( (virq <NR_LOCAL_IRQS || virq >=vgic_num_irqs (d)) && !is_espi (virq) )return -EINVAL ; desc =vgic_get_hw_irq_desc (d,NULL , virq);
Signature · 1 line
2.34.1
Re: [PATCH 04/10] xen/arm/irq: allow assignment/releasing of eSPI interrupts
Hi,
Quoted 14 lines · Leonid Komarianskyi
The current checks don't allow us to assign or release interrupts with INTID greater than 1024. This patch adds an additional condition to check whether the IRQ number is in the eSPI range and allows it to be assigned to Xen and domains if it is.
Quoted 1 line
Signed-off-by Leonid Komarianskyi <[email protected]>--- xen/arch/arm/irq.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)xen/arch/arm/irq.c +0
-0
xen/arch/arm/irq.c err: · line 449
Quoted 8 lines
xen/arch/arm/irq.c +2
-2@@ -444,8 +444,8 @@ 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 ()); +/* For now, we can only route SPIs and eSPIs to the guest */ +return (((irq >=NR_LOCAL_IRQS ) && (irq <gic_number_lines ())) ||is_espi (irq)); }
is_assignable_irq() is called by route_irq_to_guest() which first check 'virq >= vgic_num_irqs()'. AFAICT, if we apply only up to this patch, 'virq' would still require to < 1024. So ...
xen/arch/arm/irq.c int release_guest_irq(struct domain *d, unsigned int virq) · line 593
Quoted 10 lines
xen/arch/arm/irq.c +2
-2be/* @@ -589,8 +589,8 @@ int release_guest_irq(struct domain *d, unsigned int virq)unsigned long flags;int ret; -/* Only SPIs are supported */ -if ( virq <NR_LOCAL_IRQS || virq >=vgic_num_irqs (d) ) +/* Only SPIs and eSPIs are supported */ +if ( (virq <NR_LOCAL_IRQS || virq >=vgic_num_irqs (d)) && !is_espi (virq) )
... I don't quite understand why this (yet?) need a change. Can you clarify?
xen/arch/arm/irq.c int release_guest_irq(struct domain *d, unsigned int virq) · line 596
Quoted 3 lines
xen/arch/arm/irq.c +0
-0return -EINVAL ; desc =vgic_get_hw_irq_desc (d,NULL , virq);
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 04/10] xen/arm/irq: allow assignment/releasing of eSPI interrupts
Hi Julien,
Quoted 21 lines · Julien Grall
Hi,
Quoted 18 lines · Leonid Komarianskyi
The current checks don't allow us to assign or release interrupts with INTID greater than 1024. This patch adds an additional condition to check whether the IRQ number is in the eSPI range and allows it to be assigned to Xen and domains if it is.
Quoted 1 line
Signed-off-by Leonid Komarianskyi <[email protected]>---
xen/arch/arm/irq.c| 8 ++++----1 file changed, 4 insertions(+), 4 deletions(-)xen/arch/arm/irq.c +0
-2@@ -444,8 +444,8 @@ 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());
Quoted 8 lines
xen/arch/arm/irq.c err: · line 449
Quoted 4 lines
xen/arch/arm/irq.c +2
-0+ /* For now, we can only route SPIs and eSPIs to the guest */ + return (((irq >= NR_LOCAL_IRQS) && (irq < gic_number_lines())) ||is_espi (irq)); }
is_assignable_irq()is called byroute_irq_to_guest()which first check 'virq >=vgic_num_irqs()'. AFAICT, if we apply only up to this patch, 'virq' would still require to < 1024. So ...
That is my mistake when splitting the changes into separate patches. I will at least reorder the patches to make the changes more logical, or, based on your comments for the 6th patch in the series, I will try to refactor it with a helper function instead.
Quoted 6 lines
Quoted 6 lines
be
/*xen/arch/arm/irq.c +0
-0@@ -589,8 +589,8 @@ int release_guest_irq(struct domain *d, unsigned int virq) unsigned long flags; int ret;
Quoted 8 lines
xen/arch/arm/irq.c int release_guest_irq(struct domain *d, unsigned int virq)
Quoted 5 lines
xen/arch/arm/irq.c +2
-2- /* Only SPIs are supported */ - if ( virq < NR_LOCAL_IRQS || virq >= vgic_num_irqs(d) ) + /* Only SPIs and eSPIs are supported */ + if ( (virq < NR_LOCAL_IRQS || virq >= vgic_num_irqs(d)) && !is_espi (virq) )... I don't quite understand why this (yet?) need a change. Can you clarify? ...
This is necessary to allow releasing eSPI IRQs when destroying the domain. And yes, this is the same mistake on my part - the patches are in the wrong order, and I will refactor them to fix that and make changes more logical and straightforward.
Thank you for your comments.
Cheers,
Leonid
PATCH 5/10 xen/arm: gic/irq: permit routing of eSPI interrupts to Xen and domains
In reply to Leonid KomarianskyiCurrent checks prevent routing of interrupts from the eSPI range to Xen or guest domains. The addition of the is_espi condition allows verification of whether a given index falls within the eSPI range, enabling routing of such interrupts.
Existing behavior remains unchanged for configurations where eSPI support is disabled, as in this case, is_espi always returns false.
--- xen/arch/arm/gic.c | 4 ++-- xen/arch/arm/irq.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
xen/arch/arm/gic.c +2 -2
@@ -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 (desc->irq <gic_number_lines () ||is_espi (desc->irq));/* Can't route interrupts that don't exist */ ASSERT (test_bit (_IRQ_DISABLED, &desc->status));ASSERT (spin_is_locked (&desc->lock));
@@ -134,7 +134,7 @@ int gic_route_irq_to_guest(struct domain *d, unsigned int virq,ASSERT (spin_is_locked (&desc->lock));/* Caller has already checked that the IRQ is an SPI */ ASSERT (virq >=32 ); -ASSERT (virq <vgic_num_irqs (d)); +ASSERT (virq <vgic_num_irqs (d) ||is_espi (virq));ASSERT (!is_lpi (virq)); ret =vgic_connect_hw_irq (d,NULL , virq, desc, true);
xen/arch/arm/irq.c +2 -2
@@ -461,7 +461,7 @@ bool irq_type_set_by_domain(const struct domain *d)/* * Route an IRQ to a specific guest. -* For now only SPIs are assignable to the guest. +* For now only SPIs and eSPIs are assignable to the guest. */ int route_irq_to_guest (struct domain *d,unsigned int virq,unsigned int irq,const char * devname)
@@ -472,7 +472,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 ( virq >=vgic_num_irqs (d) && !is_espi (virq)) { printk(XENLOG_G_ERR "the vIRQ number %u is too high for domain %u (max = %u)\n",
Signature · 1 line
2.34.1
PATCH 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.
--- xen/arch/arm/gic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/gic.c +1 -1
@@ -342,7 +342,7 @@ void gic_interrupt(struct cpu_user_regs *regs, int is_fiq)/* Reading IRQ will ACK it */ irq = gic_hw_ops->read_irq (); -if (likely (irq >=GIC_SGI_STATIC_MAX && irq <1020 ) ) +if (likely (irq >=GIC_SGI_STATIC_MAX && irq <1020 ) ||is_espi (irq) ) {isb ();do_IRQ (regs, irq, is_fiq);
Signature · 1 line
2.34.1
Re: [PATCH 06/10] xen/arm/irq: allow eSPI processing in the do_IRQ function
Hi,
Quoted 15 lines · Leonid Komarianskyi
The
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.Signed-off-by Leonid Komarianskyi <[email protected]>--- xen/arch/arm/gic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/arch/arm/gic.c +0
-0
xen/arch/arm/gic.c void gic_interrupt(struct cpu_user_regs *regs, int is_fiq) · line 345
Quoted 5 lines
xen/arch/arm/gic.c +1
-1@@ -342,7 +342,7 @@ void gic_interrupt(struct cpu_user_regs *regs, int is_fiq)/* Reading IRQ will ACK it */ irq = gic_hw_ops->read_irq (); -if (likely (irq >=GIC_SGI_STATIC_MAX && irq <1020 ) ) +if (likely (irq >=GIC_SGI_STATIC_MAX && irq <1020 ) ||is_espi (irq) )
Looking at the series, we seem to have a common pattern which is "check if an SPI or an eSPI". AFAIU, pretty much everywhere we use an SPI, we want to be able to use an eSPI.
So rather than open-coding everywhere, can we create a new helper to check whether we have an (e)SPI? This would make easier to read the code.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 06/10] xen/arm/irq: allow eSPI processing in the do_IRQ function
Hi Julien,
Quoted 29 lines · Julien Grall
Hi,
Quoted 15 lines · Leonid Komarianskyi
The
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.Signed-off-by Leonid Komarianskyi <[email protected]>---
xen/arch/arm/gic.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)xen/arch/arm/gic.c +0
-0xen/arch/arm/gic.c void gic_interrupt(struct cpu_user_regs *regs, int · line 346
Quoted 6 lines
xen/arch/arm/gic.c +1
-1@@ -342,7 +342,7 @@ void gic_interrupt(struct cpu_user_regs *regs, int is_fiq) /* Reading IRQ will ACK it */ irq = gic_hw_ops->read_irq(); - if ( likely(irq >= GIC_SGI_STATIC_MAX && irq < 1020) ) + if ( likely(irq >= GIC_SGI_STATIC_MAX && irq < 1020) ||is_espi (irq) )Looking at the series, we seem to have a common pattern which is "check if an SPI or an eSPI". AFAIU, pretty much everywhere we use an SPI, we want to be able to use an eSPI.
Quoted 3 lines
So rather than open-coding everywhere, can we create a new helper to check whether we have an (e)SPI? This would make easier to read the code.
Oh, thank you for your comment - it helped me identify mistakes in the previous patches :)
Basically, in some parts of the code like this, we only need to verify whether the INTID is valid. However, in other cases (e.g., vGIC-specific code), we also need to check whether the domain can utilize the IRQ or if the HW GIC actually supports that INTID. For instance, the HW might support only 512 eSPIs, and simply using the is_espi check would pass incorrectly because it only verifies if the INTID falls in the eSPI range but doesn't check if the hardware supports that INTID or if the domain can use that IRQ.
I will revise the code based on these findings, introduce helper functions, and address the potential issues in v2.
Cheers,
Leonid
PATCH 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.
--- xen/arch/arm/include/asm/gic_v3_defs.h | 4 ++++ 1 file changed, 4 insertions(+)
xen/arch/arm/include/asm/gic_v3_defs.h +4 -0
@@ -206,7 +206,11 @@#define ICH_LR_VIRTUAL_SHIFT 0#define ICH_LR_CPUID_MASK 0x7#define ICH_LR_CPUID_SHIFT 10 +#ifndef CONFIG_GICV3_ESPI #define ICH_LR_PHYSICAL_MASK 0x3ff +#else +#define ICH_LR_PHYSICAL_MASK 0x13ff +#endif #define ICH_LR_PHYSICAL_SHIFT 32#define ICH_LR_STATE_MASK 0x3#define ICH_LR_STATE_SHIFT 62
Signature · 1 line
2.34.1
Re: [PATCH 07/10] xen/arm: gicv3: modify ICH_LR_PHYSICAL_MASK to allow eSPI processing
Hi,
Quoted 16 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.Signed-off-by Leonid Komarianskyi <[email protected]>--- xen/arch/arm/include/asm/gic_v3_defs.h | 4 ++++ 1 file changed, 4 insertions(+)xen/arch/arm/include/asm/gic_v3_defs.h +0
-0
xen/arch/arm/include/asm/gic_v3_defs.h line 213
Quoted 8 lines
xen/arch/arm/include/asm/gic_v3_defs.h +4
-0@@ -206,7 +206,11 @@#define ICH_LR_VIRTUAL_SHIFT 0#define ICH_LR_CPUID_MASK 0x7#define ICH_LR_CPUID_SHIFT 10 +#ifndef CONFIG_GICV3_ESPI #define ICH_LR_PHYSICAL_MASK 0x3ff +#else +#define ICH_LR_PHYSICAL_MASK 0x13ff +#endif
Can't we use 0x13ff unconditionally? If not, then why is it fine to use it on a system where GICv3 doesn't support? (I assume distros will want to have it enabled).
xen/arch/arm/include/asm/gic_v3_defs.h line 216
Quoted 3 lines
xen/arch/arm/include/asm/gic_v3_defs.h +0
-0#define ICH_LR_PHYSICAL_SHIFT 32#define ICH_LR_STATE_MASK 0x3#define ICH_LR_STATE_SHIFT 62
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH 07/10] xen/arm: gicv3: modify ICH_LR_PHYSICAL_MASK to allow eSPI processing
Hi Julien,
Quoted 32 lines · Julien Grall
Hi,
Quoted 17 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.Signed-off-by Leonid Komarianskyi <[email protected]>---
xen/arch/arm/include/asm/gic_v3_defs.h| 4 ++++1 file changed, 4 insertions(+)xen/arch/arm/ renamed from xen/arch/arm/include/asm/gic_v3_defs.h +0
-0
include/asm/gic_v3_defs.h
index7f769b38e3..2c02ddd287100644xen/arch/arm/include/asm/gic_v3_defs.h line 213
Quoted 8 lines
xen/arch/arm/include/asm/gic_v3_defs.h +4
-0@@ -206,7 +206,11 @@ #define ICH_LR_VIRTUAL_SHIFT 0 #define ICH_LR_CPUID_MASK 0x7 #define ICH_LR_CPUID_SHIFT 10 +#ifndef CONFIG_GICV3_ESPI #define ICH_LR_PHYSICAL_MASK 0x3ff +#else +#define ICH_LR_PHYSICAL_MASK 0x13ff +#endif Can't we use
0x13ffunconditionally? If not, then why is it fine to use it on a system where GICv3 doesn't support? (I assume distros will want to have it enabled).
Quoted 6 lines
xen/arch/arm/include/asm/gic_v3_defs.h line 216
Quoted 3 lines
xen/arch/arm/include/asm/gic_v3_defs.h +0
-0#define ICH_LR_PHYSICAL_SHIFT 32 #define ICH_LR_STATE_MASK 0x3 #define ICH_LR_STATE_SHIFT 62Cheers,
You are absolutely right - we can use it unconditionally. So, I will remove the unnecessary #ifdef in v2.
Thanks for pointing that out.
Cheers,
Leonid
PATCH 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.
--- xen/arch/arm/gic-v3.c | 5 ++ xen/arch/arm/include/asm/gic.h | 3 + xen/arch/arm/include/asm/vgic.h | 28 +++++++ xen/arch/arm/vgic.c | 133 +++++++++++++++++++++++++++++++- 4 files changed, 167 insertions(+), 2 deletions(-)
xen/arch/arm/gic-v3.c +5 -0
@@ -676,6 +676,11 @@ static void gicv3_set_irq_priority(struct irq_desc *desc, }#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;
xen/arch/arm/include/asm/gic.h +3 -0
@@ -306,6 +306,9 @@ 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 ); +#endif /* IRQ translation function for the device tree */ int gic_irq_xlate(const u32 *intspec, unsigned int intsize,
xen/arch/arm/include/asm/vgic.h +28 -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,24 @@ 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) + +/* +* 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_espi_rank (unsigned int rank) +{ +return ( rank >=EXT_RANK_MIN && rank <EXT_RANK_MAX ); +} +#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 +324,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 +131 -2
224 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 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.
--- 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
@@ -363,6 +363,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 +/* * Allocate a guest VIRQ * - spi == 0 => allocate a PPI. It will be the same on every vCPU
Signature · 1 line
2.34.1
PATCH 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.
--- 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, 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, 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