xen/arm: vgic to ignore GICD ICPENRn registers access
PATCH 1/1 xen/arm: vgic to ignore GICD ICPENRn registers access
Currently, Xen will return IO unhandled when guests access GICD ICPENRn registers. This will raise a data abort inside guest. For Linux Guest, these virtual registers will not be accessed. But for Zephyr, in its GIC initilization code, these virtual registers will be accessed. And zephyr guest will get an IO dataabort in initilization stage and enter fatal error. Emulating ICPENDR is not easy with the existing vGIC, so we currently ignore these virtual registers access and print a message about whether they are already pending instead of returning unhandled. More details can be found at [1].
[1] https://lists.xenproject.org/archives/html/xen-devel/2021-09/
msg00744.html
--- xen/arch/arm/vgic-v2.c | 10 +++++++--- xen/arch/arm/vgic-v3.c | 29 +++++++++++++++++------------ xen/arch/arm/vgic.c | 37 +++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/vgic.h | 2 ++ 4 files changed, 63 insertions(+), 15 deletions(-)
xen/arch/arm/vgic-v2.c +7 -3
@@ -481,10 +481,14 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,case VRANGE32 (GICD_ICPENDR ,GICD_ICPENDRN ):if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_rank_offset (v,1 , gicd_reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; +printk (XENLOG_G_ERR -"%pv: vGICD: unhandled word write %#" PRIregister" to ICPENDR%d\n" , - v, r, gicd_reg -GICD_ICPENDR ); -return 0 ; +"%pv: vGICD: unhandled word write %#" PRIregister" to ICPENDR%d, and current pending state is: %s\n" , + v, r, gicd_reg -GICD_ICPENDR , +vgic_get_irqs_pending (v, r, rank->index) ?"on" :"off" ); + goto write_ignore_32;case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size !=DABT_WORD ) goto bad_width;
xen/arch/arm/vgic-v3.c +17 -12
@@ -817,10 +817,14 @@ static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v,case VRANGE32 (GICD_ICPENDR ,GICD_ICPENDRN ):if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_rank_offset (v,1 , reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; +printk (XENLOG_G_ERR -"%pv: %s: unhandled word write %#" PRIregister" to ICPENDR%d\n" , - v, name, r, reg -GICD_ICPENDR ); -return 0 ; +"%pv: %s: unhandled word write %#" PRIregister" to ICPENDR%d, and current pending state is: %s\n" , + v, name, r, reg -GICD_ICPENDR , +vgic_get_irqs_pending (v, r, rank->index) ?"on" :"off" ); + goto write_ignore_32;case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size !=DABT_WORD ) goto bad_width;
@@ -978,19 +982,20 @@ static int vgic_v3_rdistr_sgi_mmio_write(struct vcpu *v, mmio_info_t *info,case VREG32 (GICR_ICFGR1 ):case VRANGE32 (GICR_IPRIORITYR0 ,GICR_IPRIORITYR7 ):case VREG32 (GICR_ISPENDR0 ): -/* -* Above registers offset are common with GICD. -* So handle common with GICD handling -*/ +/* +* Above registers offset are common with GICD. +* So handle common with GICD handling +*/ return __vgic_v3_distr_common_mmio_write ("vGICR: SGI" , v, info, gicr_reg, r);case VREG32 (GICR_ICPENDR0 ): -if ( dabt.size !=DABT_WORD ) goto bad_width; -printk (XENLOG_G_ERR -"%pv: vGICR: SGI: unhandled word write %#" PRIregister" to ICPENDR0\n" , - v, r); -return 0 ; +/* +* Above registers offset are common with GICD. +* So handle common with GICD handling +*/ +return __vgic_v3_distr_common_mmio_write ("vGICR: SGI" , v, + info, gicr_reg, r);case VREG32 (GICR_IGRPMODR0 ):/* We do not implement security extensions for guests, write ignore */
xen/arch/arm/vgic.c +37 -0
@@ -470,6 +470,43 @@ void vgic_set_irqs_pending(struct vcpu *v, uint32_t r, unsigned int rank) } } +bool vgic_get_irqs_pending (struct vcpu *v,uint32_t r,unsigned int rank) +{ +const unsigned long mask = r; +unsigned int i; +/* The first rank is always per-vCPU */ +bool private = rank ==0 ; +bool is_pending = false; + +/* LPIs status will never be retrieved via this function */ +ASSERT (!is_lpi (32 * rank +31 )); + +for_each_set_bit ( i, &mask,32 ) + { +unsigned int irq = i +32 * rank; + +if ( !private ) + { +struct pending_irq *p =spi_to_pending (v->domain, irq); + +if ( p->desc !=NULL ) + { +unsigned long flags; + +spin_lock_irqsave (&p->desc->lock, flags); + is_pending =gic_read_pending_state (p->desc); +spin_unlock_irqrestore (&p->desc->lock, flags); + } + } + +/* When get pending state, break the loop in time */ +if ( is_pending ) +break ; + } + +return is_pending; +} +bool vgic_to_sgi (struct vcpu *v,register_t sgir,enum gic_sgi_mode irqmode,int virq,const struct sgi_target *target) {
xen/include/asm-arm/vgic.h +2 -0
@@ -290,6 +290,8 @@ extern void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n);extern void vgic_enable_irqs (struct vcpu *v,uint32_t r,int n);extern void vgic_set_irqs_pending (struct vcpu *v,uint32_t r,unsigned int rank); +extern bool vgic_get_irqs_pending (struct vcpu *v,uint32_t r, +unsigned int rank);extern void register_vgic_ops (struct domain *d,const struct vgic_ops *ops);int vgic_v2_init (struct domain *d,int *mmio_count);int vgic_v3_init (struct domain *d,int *mmio_count);
Signature · 1 line
2.17.1
Hi,
Quoted 5 lines · Hongda Deng
Currently, Xen will return IO unhandled when guests access GICD ICPENRn registers. This will raise a data abort inside guest. For Linux Guest, these virtual registers will not be accessed. But for Zephyr, in its GIC initilization code, these virtual registers will be accessed. And zephyr guest will get an IO dataabort in initilization stage and enter
s/dataabort/data abort/
s/initilization/initialization/
Quoted 27 lines
fatal error. Emulating ICPENDR is not easy with the existing vGIC, so we currently ignore these virtual registers access and print a message about whether they are already pending instead of returning unhandled. More details can be found at [1].
[1] https://lists.xenproject.org/archives/html/xen-devel/2021-09/
msg00744.htmlSigned-off-by Hongda Deng <[email protected]>--- xen/arch/arm/vgic-v2.c | 10 +++++++--- xen/arch/arm/vgic-v3.c | 29 +++++++++++++++++------------ xen/arch/arm/vgic.c | 37 +++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/vgic.h | 2 ++ 4 files changed, 63 insertions(+), 15 deletions(-)xen/arch/arm/vgic-v2.c +2
-0@@ -481,10 +481,14 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,case VRANGE32 (GICD_ICPENDR ,GICD_ICPENDRN ):if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_rank_offset (v,1 , gicd_reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore;
xen/arch/arm/vgic-v2.c static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info, · line 493
Quoted 10 lines
xen/arch/arm/vgic-v2.c +4
-3+printk (XENLOG_G_ERR -"%pv: vGICD: unhandled word write %#" PRIregister" to ICPENDR%d\n" , - v, r, gicd_reg -GICD_ICPENDR ); -return 0 ; +"%pv: vGICD: unhandled word write %#" PRIregister" to ICPENDR%d, and current pending state is: %s\n" , + v, r, gicd_reg -GICD_ICPENDR , +vgic_get_irqs_pending (v, r, rank->index) ?"on" :"off" );
Each register contain the information for multiple pending interrupts. So it is a bit confusing to say whether the state is on/off. Instead, it would be better to state which interrupt is pending.
Also, I would rather avoid printing a message if there are no interrupts pending because there are no issues if this is happening.
Quoted 70 lines
xen/arch/arm/vgic-v2.c +1
-0+ goto write_ignore_32;case
VRANGE32(GICD_ISACTIVER, GICD_ISACTIVERN):
if ( dabt.size !=DABT_WORD) gotobad_width;xen/arch/arm/vgic-v3.c +17
-12@@ -817,10 +817,14 @@ static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v,case VRANGE32 (GICD_ICPENDR ,GICD_ICPENDRN ):if ( dabt.size !=DABT_WORD ) goto bad_width; + rank =vgic_rank_offset (v,1 , reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; +printk (XENLOG_G_ERR -"%pv: %s: unhandled word write %#" PRIregister" to ICPENDR%d\n" , - v, name, r, reg -GICD_ICPENDR ); -return 0 ; +"%pv: %s: unhandled word write %#" PRIregister" to ICPENDR%d, and current pending state is: %s\n" , + v, name, r, reg -GICD_ICPENDR , +vgic_get_irqs_pending (v, r, rank->index) ?"on" :"off" ); + goto write_ignore_32;case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size !=DABT_WORD ) goto bad_width;@@ -978,19 +982,20 @@ static int vgic_v3_rdistr_sgi_mmio_write(struct vcpu *v, mmio_info_t *info,case VREG32 (GICR_ICFGR1 ):case VRANGE32 (GICR_IPRIORITYR0 ,GICR_IPRIORITYR7 ):case VREG32 (GICR_ISPENDR0 ): -/* -* Above registers offset are common with GICD. -* So handle common with GICD handling -*/ +/* +* Above registers offset are common with GICD. +* So handle common with GICD handling +*/ return __vgic_v3_distr_common_mmio_write ("vGICR: SGI" , v, info, gicr_reg, r);case VREG32 (GICR_ICPENDR0 ): -if ( dabt.size !=DABT_WORD ) goto bad_width; -printk (XENLOG_G_ERR -"%pv: vGICR: SGI: unhandled word write %#" PRIregister" to ICPENDR0\n" , - v, r); -return 0 ; +/* +* Above registers offset are common with GICD. +* So handle common with GICD handling +*/ +return __vgic_v3_distr_common_mmio_write ("vGICR: SGI" , v, + info, gicr_reg, r);case VREG32 (GICR_IGRPMODR0 ):/* We do not implement security extensions for guests, write ignore */ xen/arch/arm/vgic.c +6
-0@@ -470,6 +470,43 @@ void vgic_set_irqs_pending(struct vcpu *v, uint32_t r, unsigned int rank) } } +bool vgic_get_irqs_pending (struct vcpu *v,uint32_t r,unsigned int rank) +{ +const unsigned long mask = r; +unsigned int i; +/* The first rank is always per-vCPU */ +bool private = rank ==0 ;
xen/arch/arm/vgic.c void vgic_set_irqs_pending(struct vcpu *v, uint32_t r, unsigned int rank) · line 488
Quoted 10 lines
xen/arch/arm/vgic.c +10
-0+bool is_pending = false; + +/* LPIs status will never be retrieved via this function */ +ASSERT (!is_lpi (32 * rank +31 )); + +for_each_set_bit ( i, &mask,32 ) + { +unsigned int irq = i +32 * rank; + +if ( !private )
It is not clear to me why you not handling PPIs/SGIs and ...
xen/arch/arm/vgic.c void vgic_set_irqs_pending(struct vcpu *v, uint32_t r, unsigned int rank) · line 492
Quoted 4 lines
xen/arch/arm/vgic.c +4
-0+ { +struct pending_irq *p =spi_to_pending (v->domain, irq); + +if ( p->desc !=NULL )
... emulated SPIs (e.g. PL011).
xen/arch/arm/vgic.c void vgic_set_irqs_pending(struct vcpu *v, uint32_t r, unsigned int rank) · line 498
Quoted 6 lines
xen/arch/arm/vgic.c +6
-0+ { +unsigned long flags; + +spin_lock_irqsave (&p->desc->lock, flags); + is_pending =gic_read_pending_state (p->desc); +spin_unlock_irqrestore (&p->desc->lock, flags);
What you are reading here is the pending state from the HW. This is not the same as the pending state from the VM PoV. In fact, in the most common case, the interrupt will be pending from the VM PoV, but simply active from the HW PoV (it is deactivated once the interrupt has been handled by the guest).
I think what you want to check is whether the flag GIC_IRQ_GUEST_QUEUED is set in p->status (Stefano ?).
This is technically still a bit racy as Xen may still think the interrupt is pending while the it may be actually active in the guest. AFAIK, the other way around (i.e. not pending in Xen but pending in the guest) cannot happen.
Anyway, this is just a message, so it is still better than crashing :).
Cheers,
Signature · 1 line
Julien Grall
Quoted 157 lines · Julien Grall
Hi,
Quoted 5 lines · Hongda Deng
Currently, Xen will return IO unhandled when guests access GICD ICPENRn registers. This will raise a data abort inside guest. For Linux Guest, these virtual registers will not be accessed. But for Zephyr, in its GIC initilization code, these virtual registers will be accessed. And zephyr guest will get an IO dataabort in initilization stage and enter
s/dataabort/data abort/
s/initilization/initialization/Quoted 37 lines
fatal error. Emulating ICPENDR is not easy with the existing vGIC, so we currently ignore these virtual registers access and print a message about whether they are already pending instead of returning unhandled. More details can be found at [1].
[1] https://lists.xenproject.org/archives/html/xen-devel/2021-09/
msg00744.htmlSigned-off-by Hongda Deng <[email protected]>--- xen/arch/arm/vgic-v2.c | 10 +++++++--- xen/arch/arm/vgic-v3.c | 29 +++++++++++++++++------------ xen/arch/arm/vgic.c | 37 +++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/vgic.h | 2 ++ 4 files changed, 63 insertions(+), 15 deletions(-)xen/arch/arm/vgic-v2.c +4
-3@@ -481,10 +481,14 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v,mmio_info_t *info, case VRANGE32(GICD_ICPENDR, GICD_ICPENDRN): if ( dabt.size != DABT_WORD ) goto bad_width; + rank =vgic_rank_offset (v,1 , gicd_reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + printk(XENLOG_G_ERR - "%pv: vGICD: unhandled word write %#"PRIregister" to ICPENDR%d\n", - v, r, gicd_reg - GICD_ICPENDR); -return 0 ; + "%pv: vGICD: unhandled word write %#"PRIregister" toICPENDR%d, and current pending state is: %s\n",
xen/arch/arm/vgic-v2.c static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info, · line 490
Quoted 2 lines
xen/arch/arm/vgic-v2.c +2
-0+ v, r, gicd_reg -GICD_ICPENDR , + vgic_get_irqs_pending(v, r, rank->index) ? "on" : "off");Each register contain the information for multiple pending interrupts. So it is a bit confusing to say whether the state is on/off. Instead, it would be better to state which interrupt is pending.
Also, I would rather avoid printing a message if there are no interrupts pending because there are no issues if this is happening.
Quoted 71 lines
xen/arch/arm/vgic-v2.c +1
-0+ goto write_ignore_32;case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size !=DABT_WORD ) goto bad_width;xen/arch/arm/vgic-v3.c +7
-3@@ -817,10 +817,14 @@ static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v, case VRANGE32(GICD_ICPENDR, GICD_ICPENDRN): if ( dabt.size != DABT_WORD ) goto bad_width; + rank =vgic_rank_offset (v,1 , reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + printk(XENLOG_G_ERR - "%pv: %s: unhandled word write %#"PRIregister" to ICPENDR%d\n", - v, name, r, reg - GICD_ICPENDR); -return 0 ; + "%pv: %s: unhandled word write %#"PRIregister" to ICPENDR%d, and current pending state is: %s\n", + v, name, r, reg - GICD_ICPENDR, + vgic_get_irqs_pending(v, r, rank->index) ? "on" : "off"); + goto write_ignore_32;case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size != DABT_WORD ) goto bad_width;xen/arch/arm/vgic-v3.c +10
-9@@ -978,19 +982,20 @@ static int vgic_v3_rdistr_sgi_mmio_write(struct vcpu *v, mmio_info_t *info, case VREG32(GICR_ICFGR1):case VRANGE32 (GICR_IPRIORITYR0 ,GICR_IPRIORITYR7 ):case VREG32 (GICR_ISPENDR0 ): -/* -* Above registers offset are common with GICD. -* So handle common with GICD handling -*/ +/* +* Above registers offset are common with GICD. +* So handle common with GICD handling +*/ return __vgic_v3_distr_common_mmio_write ("vGICR: SGI" , v, info, gicr_reg, r);case VREG32 (GICR_ICPENDR0 ): -if ( dabt.size !=DABT_WORD ) goto bad_width; -printk (XENLOG_G_ERR -"%pv: vGICR: SGI: unhandled word write %#" PRIregister" to ICPENDR0\n", - v, r); -return 0 ; +/* +* Above registers offset are common with GICD. +* So handle common with GICD handling +*/ + return __vgic_v3_distr_common_mmio_write("vGICR: SGI", v, +info ,gicr_reg ,r );case VREG32 (GICR_IGRPMODR0 ):/* We do not implement security extensions for guests, write ignore */
xen/arch/arm/vgic.c +5
-0@@ -470,6 +470,43 @@ void vgic_set_irqs_pending(struct vcpu *v, uint32_t r, unsigned int rank) } } +bool vgic_get_irqs_pending(struct vcpu *v, uint32_t r, unsigned int rank) +{ + const unsigned long mask = r; +unsigned int i; +/* The first rank is always per-vCPU */ +bool private = rank ==0 ;xen/arch/arm/vgic.c void vgic_set_irqs_pending(struct vcpu *v, uint32_t r, · line 488
Quoted 10 lines
xen/arch/arm/vgic.c +10
-0+bool is_pending = false; + +/* LPIs status will never be retrieved via this function */ +ASSERT (!is_lpi (32 * rank +31 )); + +for_each_set_bit ( i, &mask,32 ) + { +unsigned int irq = i +32 * rank; + +if ( !private )It is not clear to me why you not handling PPIs/SGIs and ...
xen/arch/arm/vgic.c void vgic_set_irqs_pending(struct vcpu *v, uint32_t r, unsigned int rank) · line 492
Quoted 4 lines
xen/arch/arm/vgic.c +4
-0+ { +struct pending_irq *p =spi_to_pending (v->domain, irq); + +if ( p->desc !=NULL )... emulated SPIs (e.g. PL011).
xen/arch/arm/vgic.c void vgic_set_irqs_pending(struct vcpu *v, uint32_t r, unsigned int rank) · line 498
Quoted 6 lines
xen/arch/arm/vgic.c +6
-0+ { +unsigned long flags; + +spin_lock_irqsave (&p->desc->lock, flags); + is_pending =gic_read_pending_state (p->desc); +spin_unlock_irqrestore (&p->desc->lock, flags);
Quoted 7 lines
What you are reading here is the pending state from the HW. This is not the same as the pending state from the VM PoV. In fact, in the most common case, the interrupt will be pending from the VM PoV, but simply active from the HW PoV (it is deactivated once the interrupt has been handled by the guest).
I think what you want to check is whether the flag
GIC_IRQ_GUEST_QUEUEDis set inp->status(Stefano ?).
Yeah, that's right. In fact, there is no need for checking the hardware registers. You can just go through the inflight_irqs list and print all of them (the list is sync on hyp entry on the cpu you are running on, not the others of course).
Quoted 5 lines
This is technically still a bit racy as Xen may still think the interrupt is pending while the it may be actually active in the guest. AFAIK, the other way around (i.e. not pending in Xen but pending in the guest) cannot happen.
Anyway, this is just a message, so it is still better than crashing :).
+1
Hi,
Thanks for your great and detailed advice, I did some investigations about vgic especially inflight_irqs in the last few days.
Quoted 9 lines
-----Original Message-----
From: Stefano Stabellini <[email protected]>
Sent: 2021年9月24日 4:54
To: Julien Grall <[email protected]>
Cc: Hongda Deng <[email protected]>; [email protected]; [email protected]; Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>
Subject: Re: [PATCH] xen/arm: vgic to ignore GICD ICPENRn registers access
Quoted 13 lines
Quoted 12 lines · Julien Grall
Hi,
Quoted 5 lines · Hongda Deng
Currently, Xen will return IO unhandled when guests access GICD ICPENRn registers. This will raise a data abort inside guest. For Linux Guest, these virtual registers will not be accessed. But for Zephyr, in its GIC initilization code, these virtual registers will be accessed. And zephyr guest will get an IO dataabort in initilization stage and enter
s/dataabort/data abort/
s/initilization/initialization/
Ack.
Quoted 40 lines
Quoted 40 lines
Quoted 39 lines
fatal error. Emulating ICPENDR is not easy with the existing vGIC, so we currently ignore these virtual registers access and print a message about whether they are already pending instead of returning unhandled. More details can be found at [1].
[1] https://lists.xenproject.org/archives/html/xen-devel/2021-09/
msg00744.htmlSigned-off-by Hongda Deng <[email protected]>--- xen/arch/arm/vgic-v2.c | 10 +++++++--- xen/arch/arm/vgic-v3.c | 29 +++++++++++++++++------------ xen/arch/arm/vgic.c | 37 +++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/vgic.h | 2 ++ 4 files changed, 63 insertions(+), 15 deletions(-)xen/arch/arm/vgic-v2.c +4
-3@@ -481,10 +481,14 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v,mmio_info_t *info, case VRANGE32(GICD_ICPENDR, GICD_ICPENDRN): if ( dabt.size != DABT_WORD ) goto bad_width; + rank =vgic_rank_offset (v,1 , gicd_reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + printk(XENLOG_G_ERR - "%pv: vGICD: unhandled word write %#"PRIregister" to ICPENDR%d\n", - v, r, gicd_reg - GICD_ICPENDR); -return 0 ; + "%pv: vGICD: unhandled word write %#"PRIregister" toICPENDR%d, and current pending state is: %s\n",
xen/arch/arm/vgic-v2.c +2
-0+ v, r, gicd_reg -GICD_ICPENDR , + vgic_get_irqs_pending(v, r, rank->index) ? "on" : "off");
Quoted 6 lines
Quoted 6 lines
Each register contain the information for multiple pending interrupts. So it is a bit confusing to say whether the state is on/off. Instead, it would be better to state which interrupt is pending.
Also, I would rather avoid printing a message if there are no interrupts pending because there are no issues if this is happening.
I will fix it in the next version patch.
Quoted 117 lines
Quoted 9 lines
xen/arch/arm/vgic-v3.c static int
Quoted 9 lines
xen/arch/arm/vgic-v2.c +1
-0+ goto write_ignore_32;case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size !=DABT_WORD ) goto bad_width;xen/arch/arm/vgic-v3.c +0
-0@@ -817,10 +817,14 @@ static int__vgic_v3_distr_common_mmio_write(const
Quoted 11 lines
Quoted 11 lines
xen/arch/arm/vgic-v3.c +3
-3char *name, struct vcpu *v, case VRANGE32(GICD_ICPENDR, GICD_ICPENDRN): if ( dabt.size != DABT_WORD ) goto bad_width; + rank =vgic_rank_offset (v,1 , reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + printk(XENLOG_G_ERR - "%pv: %s: unhandled word write %#"PRIregister" to ICPENDR%d\n", - v, name, r, reg - GICD_ICPENDR); -return 0 ;Quoted 8 lines
xen/arch/arm/vgic-v3.c static int vgic_v3_rdistr_sgi_mmio_write(struct
Quoted 8 lines
xen/arch/arm/vgic-v3.c +4
-0+ "%pv: %s: unhandled word write %#"PRIregister" to ICPENDR%d, and current pending state is: %s\n", + v, name, r, reg - GICD_ICPENDR, + vgic_get_irqs_pending(v, r, rank->index) ? "on" : "off"); + goto write_ignore_32;case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size != DABT_WORD ) goto bad_width;xen/arch/arm/vgic-v3.c +0
-0@@ -978,19 +982,20 @@ static int vgic_v3_rdistr_sgi_mmio_write(structvcpu
Quoted 27 lines
Quoted 27 lines
xen/arch/arm/vgic-v3.c +10
-9*v, mmio_info_t *info, case VREG32(GICR_ICFGR1):case VRANGE32 (GICR_IPRIORITYR0 ,GICR_IPRIORITYR7 ):case VREG32 (GICR_ISPENDR0 ): -/* -* Above registers offset are common with GICD. -* So handle common with GICD handling -*/ +/* +* Above registers offset are common with GICD. +* So handle common with GICD handling +*/ return __vgic_v3_distr_common_mmio_write ("vGICR: SGI" , v, info, gicr_reg, r);case VREG32 (GICR_ICPENDR0 ): -if ( dabt.size !=DABT_WORD ) goto bad_width; -printk (XENLOG_G_ERR -"%pv: vGICR: SGI: unhandled word write %#" PRIregister" to ICPENDR0\n", - v, r); -return 0 ; +/* +* Above registers offset are common with GICD. +* So handle common with GICD handling +*/ + return __vgic_v3_distr_common_mmio_write("vGICR: SGI", v, +info ,gicr_reg ,r );Quoted 8 lines
xen/arch/arm/vgic.c void vgic_set_irqs_pending(struct vcpu *v, uint32_t
Quoted 8 lines
xen/arch/arm/vgic-v3.c +0
-0case VREG32 (GICR_IGRPMODR0 ):/* We do not implement security extensions for guests, write ignore */
xen/arch/arm/vgic.c +0
-0@@ -470,6 +470,43 @@ void vgic_set_irqs_pending(struct vcpu *v, uint32_tr,
Quoted 36 lines
Quoted 9 lines
xen/arch/arm/vgic.c +5
-0unsigned int rank) } } +bool vgic_get_irqs_pending(struct vcpu *v, uint32_t r, unsigned int rank) +{ + const unsigned long mask = r; +unsigned int i; +/* The first rank is always per-vCPU */ +bool private = rank ==0 ;xen/arch/arm/vgic.c void vgic_set_irqs_pending(struct vcpu *v, uint32_t r, unsigned int rank) · line 488
Quoted 10 lines
xen/arch/arm/vgic.c +10
-0+bool is_pending = false; + +/* LPIs status will never be retrieved via this function */ +ASSERT (!is_lpi (32 * rank +31 )); + +for_each_set_bit ( i, &mask,32 ) + { +unsigned int irq = i +32 * rank; + +if ( !private )It is not clear to me why you not handling PPIs/SGIs and ...
xen/arch/arm/vgic.c void vgic_set_irqs_pending(struct vcpu *v, uint32_t r, unsigned int rank) · line 492
Quoted 4 lines
xen/arch/arm/vgic.c +4
-0+ { +struct pending_irq *p =spi_to_pending (v->domain, irq); + +if ( p->desc !=NULL )... emulated SPIs (e.g. PL011).
xen/arch/arm/vgic.c void vgic_set_irqs_pending(struct vcpu *v, uint32_t r, unsigned int rank) · line 498
Quoted 6 lines
xen/arch/arm/vgic.c +6
-0+ { +unsigned long flags; + +spin_lock_irqsave (&p->desc->lock, flags); + is_pending =gic_read_pending_state (p->desc); +spin_unlock_irqrestore (&p->desc->lock, flags);Quoted 6 lines
What you are reading here is the pending state from the HW. This is not the same as the pending state from the VM PoV. In fact, in the most common case, the interrupt will be pending from the VM PoV, but simply active from the HW PoV (it is deactivated once the interrupt has been handled by the guest).
I think what you want to check is whether the flag
GIC_IRQ_GUEST_QUEUEDis set
Quoted 1 line
in
p->status(Stefano ?).Yeah, that's right. In fact, there is no need for checking the hardware registers. You can just go through the
inflight_irqslist and print all of them (the list is sync on hyp entry on the cpu you are running on, not the others of course).
Quoted 7 lines
Quoted 5 lines
This is technically still a bit racy as Xen may still think the interrupt is pending while the it may be actually active in the guest. AFAIK, the other way around (i.e. not pending in Xen but pending in the guest) cannot happen.
Anyway, this is just a message, so it is still better than crashing :).
+1
Thanks again for your advice.
Based on that, I wrote a new patch to go through vcpu->arch.vgic.inflight_irqs to check the pending states and print them if there are in the next version patch. I will send it for review later.
Cheers,
Hongda