xen/arm: vgic to ignore GICD ICPENDRn registers access
PATCH v3 1/1 xen/arm: vgic to ignore GICD ICPENDRn 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 initialization code, these virtual registers will be accessed. And zephyr guest will get an IO data abort 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://github.com/zephyrproject-rtos/zephyr/blob/eaf6cf745df3807e6e
cc941c3a30de6c179ae359/drivers/interrupt_controller/intc_gicv3.c#L274
---
Changes since v2:
* Avoid to print messages when there is no pending interrupt
* Add helper vgic_check_inflight_irqs_pending to check pending status
* Print a message for each interrupt separately
Changes since v1:
* Check pending states by going through vcpu->arch.vgic.inflight_irqs
instead of checking hardware registers
---
xen/arch/arm/vgic-v2.c | 10 ++++++----
xen/arch/arm/vgic-v3.c | 16 ++++++++--------
xen/arch/arm/vgic.c | 36 ++++++++++++++++++++++++++++++++++++
xen/include/asm-arm/vgic.h | 3 ++-
4 files changed, 52 insertions(+), 13 deletions(-)xen/arch/arm/vgic-v2.c +6 -4
@@ -481,10 +481,12 @@ 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; -printk (XENLOG_G_ERR -"%pv: vGICD: unhandled word write %#" PRIregister" to ICPENDR%d\n" , - v, r, gicd_reg -GICD_ICPENDR ); -return 0 ; + rank =vgic_rank_offset (v,1 , gicd_reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + +vgic_check_inflight_irqs_pending (v->domain, v, rank->index, r); + + goto write_ignore_32;case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size !=DABT_WORD ) goto bad_width;
xen/arch/arm/vgic-v3.c +8 -8
@@ -817,10 +817,12 @@ 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; -printk (XENLOG_G_ERR -"%pv: %s: unhandled word write %#" PRIregister" to ICPENDR%d\n" , - v, name, r, reg -GICD_ICPENDR ); -return 0 ; + rank =vgic_rank_offset (v,1 , reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + +vgic_check_inflight_irqs_pending (v->domain, v, rank->index, r); + + goto write_ignore_32;case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size !=DABT_WORD ) goto bad_width;
@@ -987,10 +989,8 @@ static int vgic_v3_rdistr_sgi_mmio_write(struct vcpu *v, mmio_info_t *info,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 ; +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 +36 -0
@@ -726,6 +726,42 @@ unsigned int vgic_max_vcpus(unsigned int domctl_vgic_version) } } +void vgic_check_inflight_irqs_pending (struct domain *d,struct vcpu *v, +unsigned int rank,uint32_t r) +{ +const unsigned long mask = r; +unsigned int i; +unsigned long flags; +struct pending_irq *p; +bool private = rank ==0 ; +struct vcpu *v_target; + +for_each_set_bit ( i, &mask,32 ) + { +unsigned int irq = i +32 * rank; + +if ( private ) + v_target =vgic_get_target_vcpu (v, irq); +else + v_target =vgic_get_target_vcpu (d->vcpu[0 ], irq); + +spin_lock_irqsave (&v_target->arch.vgic.lock, flags); + + p =irq_to_pending (v_target, irq); + +if (unlikely (!p) ) + { +spin_unlock_irqrestore (&v_target->arch.vgic.lock, flags); +continue ; + } + +if ( !list_empty (&p->inflight) ) +printk ("%pv trying to clear pending interrupt %u.\n" , v, irq); + +spin_unlock_irqrestore (&v_target->arch.vgic.lock, flags); + } +} +/* * Local variables: * mode: C
xen/include/asm-arm/vgic.h +2 -1
@@ -298,7 +298,8 @@ extern bool vgic_to_sgi(struct vcpu *v, register_t sgir, enum gic_sgi_mode irqmode, int virq, const struct sgi_target *target);extern bool vgic_migrate_irq (struct vcpu *old,struct vcpu *new,unsigned int irq); - +extern void vgic_check_inflight_irqs_pending (struct domain *d,struct vcpu *v, +unsigned int rank,uint32_t r);#endif /* !CONFIG_NEW_VGIC */ /*** Common VGIC functions used by Xen arch code ****/
Signature · 1 line
2.17.1
Hi Hongda,
[+Ian]
Quoted 12 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 initialization code, these virtual registers will be accessed. And zephyr guest will get an IO data abort 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].
Quoted 4 lines
[1] https://github.com/zephyrproject-rtos/zephyr/blob/eaf6cf745df3807e6e
cc941c3a30de6c179ae359/drivers/interrupt_controller/intc_gicv3.c#L274Signed-off-by Hongda Deng <[email protected]>
Ian this is fixing a bug in the vgic implementation which is preventing to run Zephyr as a guest on top of Xen. Xen support has now been merged in Zephyr so this is required to use it.
Could we consider adding this patch into the 4.16 release ?
Thanks
Bertrand
Quoted 134 lines
---
Changes since v2:* Avoid to print messages when there is no pending interrupt * Add helper vgic_check_inflight_irqs_pending to check pending status * Print a message for each interrupt separatelyChanges since v1:
* Check pending states by going throughvcpu->arch.vgic.inflight_irqsinstead of checking hardware registers
---xen/arch/arm/vgic-v2.c | 10 ++++++---- xen/arch/arm/vgic-v3.c | 16 ++++++++-------- xen/arch/arm/vgic.c | 36 ++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/vgic.h | 3 ++- 4 files changed, 52 insertions(+), 13 deletions(-)xen/arch/arm/vgic-v2.c +6
-4@@ -481,10 +481,12 @@ 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; -printk (XENLOG_G_ERR -"%pv: vGICD: unhandled word write %#" PRIregister" to ICPENDR%d\n" , - v, r, gicd_reg -GICD_ICPENDR ); -return 0 ; + rank =vgic_rank_offset (v,1 , gicd_reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + +vgic_check_inflight_irqs_pending (v->domain, v, rank->index, r); + + goto write_ignore_32;case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size !=DABT_WORD ) goto bad_width;xen/arch/arm/vgic-v3.c +8
-8@@ -817,10 +817,12 @@ 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; -printk (XENLOG_G_ERR -"%pv: %s: unhandled word write %#" PRIregister" to ICPENDR%d\n" , - v, name, r, reg -GICD_ICPENDR ); -return 0 ; + rank =vgic_rank_offset (v,1 , reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + +vgic_check_inflight_irqs_pending (v->domain, v, rank->index, r); + + goto write_ignore_32;case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size !=DABT_WORD ) goto bad_width;@@ -987,10 +989,8 @@ static int vgic_v3_rdistr_sgi_mmio_write(struct vcpu *v, mmio_info_t *info,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 ; +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 +36
-0@@ -726,6 +726,42 @@ unsigned int vgic_max_vcpus(unsigned int domctl_vgic_version) } } +void vgic_check_inflight_irqs_pending (struct domain *d,struct vcpu *v, +unsigned int rank,uint32_t r) +{ +const unsigned long mask = r; +unsigned int i; +unsigned long flags; +struct pending_irq *p; +bool private = rank ==0 ; +struct vcpu *v_target; + +for_each_set_bit ( i, &mask,32 ) + { +unsigned int irq = i +32 * rank; + +if ( private ) + v_target =vgic_get_target_vcpu (v, irq); +else + v_target =vgic_get_target_vcpu (d->vcpu[0 ], irq); + +spin_lock_irqsave (&v_target->arch.vgic.lock, flags); + + p =irq_to_pending (v_target, irq); + +if (unlikely (!p) ) + { +spin_unlock_irqrestore (&v_target->arch.vgic.lock, flags); +continue ; + } + +if ( !list_empty (&p->inflight) ) +printk ("%pv trying to clear pending interrupt %u.\n" , v, irq); + +spin_unlock_irqrestore (&v_target->arch.vgic.lock, flags); + } +} +/* * Local variables: * mode: C xen/include/asm-arm/vgic.h +2
-1@@ -298,7 +298,8 @@ extern bool vgic_to_sgi(struct vcpu *v, register_t sgir, enum gic_sgi_mode irqmode, int virq, const struct sgi_target *target);extern bool vgic_migrate_irq (struct vcpu *old,struct vcpu *new,unsigned int irq); - +extern void vgic_check_inflight_irqs_pending (struct domain *d,struct vcpu *v, +unsigned int rank,uint32_t r);#endif /* !CONFIG_NEW_VGIC */ /*** Common VGIC functions used by Xen arch code ****/ Signature · 1 line
2.17.1
~Bertrand Marquis writes ("Re: [PATCH v3] xen/arm: vgic to ignore GICD ICPENDRn registers access"):
Quoted 16 lines
[+Ian]
Quoted 15 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 initialization code, these virtual registers will be accessed. And zephyr guest will get an IO data abort 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://github.com/zephyrproject-rtos/zephyr/blob/eaf6cf745df3807e6e
cc941c3a30de6c179ae359/drivers/interrupt_controller/intc_gicv3.c#L274
Quoted 8 lines
Quoted 1 line
Signed-off-by Hongda Deng <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>Ian this is fixing a bug in the vgic implementation which is preventing to run Zephyr as a guest on top of Xen. Xen support has now been merged in Zephyr so this is required to use it.
Could we consider adding this patch into the 4.16 release ?
Hi. I'm definitely open to the idea, especially if it goes in soon.
I think this needs an ARM maintainer review, still ?
It doesn't seem entirely straightforward. I'd like to hear from the maintainer, to confirm that they agree it's a bugfix, and to get an idea of the risks vs benefits of this patch.
Thanks,
Ian.
Hi Ian,
Quoted 24 lines · Ian Jackson
~Bertrand Marquis writes ("Re: [PATCH v3] xen/arm: vgic to ignore GICD ICPENDRn registers access"):
Quoted 23 lines
[+Ian]
Quoted 12 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 initialization code, these virtual registers will be accessed. And zephyr guest will get an IO data abort 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].
Quoted 4 lines
[1] https://github.com/zephyrproject-rtos/zephyr/blob/eaf6cf745df3807e6e
cc941c3a30de6c179ae359/drivers/interrupt_controller/intc_gicv3.c#L274Signed-off-by Hongda Deng <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>Ian this is fixing a bug in the vgic implementation which is preventing to run Zephyr as a guest on top of Xen. Xen support has now been merged in Zephyr so this is required to use it.
Quoted 5 lines
Quoted 1 line
Could we consider adding this patch into the 4.16 release ?
Hi. I'm definitely open to the idea, especially if it goes in soon.
I think this needs an ARM maintainer review, still ?
Yes. I am planning to review it later today.
Quoted 4 lines
It doesn't seem entirely straightforward. I'd like to hear from the maintainer, to confirm that they agree it's a bugfix, and to get an idea of the risks vs benefits of this patch.
TL;DR: This is a bug fix and I agree that this should be included in 4.16.
ICPENDRn are a mandatory registers of the GIC implementation. But it is not trivial to emulate properly with our existing vGIC. So for the past years, we chose the lazy approach and inject a data abort when the vCPU access it.
IOW, this is not a new bug fix. We haven't seen any problem before because most of our users were using Linux based guests. Now this is starting to change and therefore we are exercising paths that Linux never used it. In this case, we would not be able to boot Zephyr on Xen.
During boot, Zephyr will write to ICPENDR to clear all the pending interrupts. I am not entirely convinced that from Zephyr PoV this is a useful things to do because, unless you quiesced the devices, interrupts can become pending again right away after clearing.
I would suggest to chat with the Zephyr folks to understand why they need to write to ICPENDR during boot.
In any case, I am assuming there are already Zephyr OS out there. So we need to solve the issue in Xen.
This patch doesn't fully emulate ICPENDR. The new appropach will ignore access and print a message when the OS is trying to clear a pending interrupt.
The code itself is only walking the internal structure. So as long as the correct locks are held, there is no change in the emulated state.
The only difference will happen at the domain level. Now, the domain will be able to continue booting. We will not clear pending interrupts but I think this is an acceptable approach as the worst that can happen is the guest may receive a "spurious" interrupt.
In both cases, I think the risks are limited and I would support the inclusion of this patch (pending appropriate acks) in 4.16.
Cheers,
Signature · 1 line
Julien Grall
Julien Grall writes ("Re: [PATCH v3] xen/arm: vgic to ignore GICD ICPENDRn registers access"):
Quoted 1 line
TL;DR: This is a bug fix and I agree that this should be included in 4.16.
Thank you very much for the detailed and helpful reply.
Hi Hongda,
Title: I would suggest the following title:
xen/arm: vgic: Ignore write access to ICPENDR*
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 initialization code, these virtual registers will be accessed. And zephyr guest will get an IO data abort in initilization stage and enter
Typo: s/initilization/initialization/
I would also s/in/during the/
Quoted 1 line
fatal error. Emulating ICPENDR is not easy with the existing vGIC, so
How about s/enter fatal error/crash/?
Quoted 1 line
we currently ignore these virtual registers access and print a message
To me 'currently' refers to the existing code base (i.e. without your patch). In fact, this seems to be how you use 'currently' in the first paragraph. So how about replace "so we currently" with "rework the emulation to ignore...".
This seems to suggest the patch will modify both read and write access. However, AFAICT, only the write emulation is modified. Can this be clarified in the commit message?
Quoted 29 lines
about whether they are already pending instead of returning unhandled. More details can be found at [1].
[1] https://github.com/zephyrproject-rtos/zephyr/blob/eaf6cf745df3807e6e
cc941c3a30de6c179ae359/drivers/interrupt_controller/intc_gicv3.c#L274Signed-off-by Hongda Deng <[email protected]>---
Changes since v2:* Avoid to print messages when there is no pending interrupt * Add helper vgic_check_inflight_irqs_pending to check pending status * Print a message for each interrupt separately Changes since v1: * Check pending states by going through vcpu->arch.vgic.inflight_irqs instead of checking hardware registers --- xen/arch/arm/vgic-v2.c | 10 ++++++---- xen/arch/arm/vgic-v3.c | 16 ++++++++-------- xen/arch/arm/vgic.c | 36 ++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/vgic.h | 3 ++- 4 files changed, 52 insertions(+), 13 deletions(-)xen/arch/arm/vgic-v2.c +0
-0@@ -481,10 +481,12 @@ static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,case VRANGE32 (GICD_ICPENDR ,GICD_ICPENDRN ):
xen/arch/arm/vgic-v2.c static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info, · line 488
Quoted 10 lines
xen/arch/arm/vgic-v2.c +5
-4if ( dabt.size !=DABT_WORD ) goto bad_width; -printk (XENLOG_G_ERR -"%pv: vGICD: unhandled word write %#" PRIregister" to ICPENDR%d\n" , - v, r, gicd_reg -GICD_ICPENDR ); -return 0 ; + rank =vgic_rank_offset (v,1 , gicd_reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + + vgic_check_inflight_irqs_pending(v->domain, v, rank->index, r); > + + goto write_ignore_32;
NIT: We already check the access above. So I would simply use "write_ignore" here.
Quoted 11 lines
xen/arch/arm/vgic-v2.c +0
-0case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size !=DABT_WORD ) goto bad_width;xen/arch/arm/vgic-v3.c +0
-0@@ -817,10 +817,12 @@ 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;
xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v, · line 825
Quoted 10 lines
xen/arch/arm/vgic-v3.c +6
-4-printk (XENLOG_G_ERR -"%pv: %s: unhandled word write %#" PRIregister" to ICPENDR%d\n" , - v, name, r, reg -GICD_ICPENDR ); -return 0 ; + rank =vgic_rank_offset (v,1 , reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + +vgic_check_inflight_irqs_pending (v->domain, v, rank->index, r); + + goto write_ignore_32;
NIT: Same remark as the previous write_ignore_32.
Quoted 23 lines
xen/arch/arm/vgic-v3.c +2
-4case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size !=DABT_WORD ) goto bad_width;@@ -987,10 +989,8 @@ static int vgic_v3_rdistr_sgi_mmio_write(struct vcpu *v, mmio_info_t *info,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 ; +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 +0
-0@@ -726,6 +726,42 @@ unsigned int vgic_max_vcpus(unsigned int domctl_vgic_version) } }
xen/arch/arm/vgic.c unsigned int vgic_max_vcpus(unsigned int domctl_vgic_version) · line 737
Quoted 10 lines
xen/arch/arm/vgic.c +9
-0+void vgic_check_inflight_irqs_pending (struct domain *d,struct vcpu *v, +unsigned int rank,uint32_t r) +{ +const unsigned long mask = r; +unsigned int i; +unsigned long flags; +struct pending_irq *p; +bool private = rank ==0 ; +struct vcpu *v_target;
AFAIC, flags, p, v_target are only used within the loop. So please reduce the scope and only declare them in for_each_set_bit().
xen/arch/arm/vgic.c unsigned int vgic_max_vcpus(unsigned int domctl_vgic_version) · line 746
Quoted 9 lines
xen/arch/arm/vgic.c +9
-0+ +for_each_set_bit ( i, &mask,32 ) + { +unsigned int irq = i +32 * rank; + +if ( private ) + v_target =vgic_get_target_vcpu (v, irq); +else + v_target =vgic_get_target_vcpu (d->vcpu[0 ], irq);
Shared interrupts can be accessed from any vCPU. So you can replace the 4 lines with:
v_target = vgic_get_target_vcpu(v, irq);
xen/arch/arm/vgic.c unsigned int vgic_max_vcpus(unsigned int domctl_vgic_version) · line 756
Quoted 10 lines
xen/arch/arm/vgic.c +10
-0+ +spin_lock_irqsave (&v_target->arch.vgic.lock, flags); + + p =irq_to_pending (v_target, irq); + +if (unlikely (!p) ) + { +spin_unlock_irqrestore (&v_target->arch.vgic.lock, flags); +continue ; + }
irq_to_pending() cannot return NULL for non-LPI interrupts. But if you still want to check it, then the two if can be combined to something like:
if ( p && !list_empty(&p->inflight) )
printk(...)
spin_unlock_irqrestore(...);
xen/arch/arm/vgic.c unsigned int vgic_max_vcpus(unsigned int domctl_vgic_version) · line 759
Quoted 3 lines
xen/arch/arm/vgic.c +3
-0+ +if ( !list_empty (&p->inflight) ) +printk ("%pv trying to clear pending interrupt %u.\n" , v, irq);
This wants to be a printk(XENLOG_G_WARNING ...) so the message will be appropriately rate-limited.
Quoted 13 lines
xen/arch/arm/vgic.c +5
-0+ +spin_unlock_irqrestore (&v_target->arch.vgic.lock, flags); + } +} +/* * Local variables: * mode: C xen/include/asm-arm/vgic.h +0
-0
xen/include/asm-arm/vgic.h extern bool vgic_to_sgi(struct vcpu *v, register_t sgir, · line 302
Quoted 6 lines
xen/include/asm-arm/vgic.h +2
-1@@ -298,7 +298,8 @@ extern bool vgic_to_sgi(struct vcpu *v, register_t sgir, enum gic_sgi_mode irqmode, int virq, const struct sgi_target *target);extern bool vgic_migrate_irq (struct vcpu *old,struct vcpu *new,unsigned int irq); - +extern void vgic_check_inflight_irqs_pending (struct domain *d,struct vcpu *v, +unsigned int rank,uint32_t r);
Please keep the newline before the #endif.
xen/include/asm-arm/vgic.h extern bool vgic_to_sgi(struct vcpu *v, register_t sgir, · line 305
Quoted 4 lines
xen/include/asm-arm/vgic.h +0
-0#endif /* !CONFIG_NEW_VGIC */ /*** Common VGIC functions used by Xen arch code ****/
Cheers,
Signature · 1 line
Julien Grall
Quoted 12 lines
-----Original Message-----
From: Julien Grall <[email protected]>
Sent: 2021年10月21日 1:45
To: Hongda Deng <[email protected]>; xen- [email protected]; [email protected]
Cc: Bertrand Marquis <[email protected]>; Wei Chen <[email protected]>
Subject: Re: [PATCH v3] xen/arm: vgic to ignore GICD ICPENDRn registers access
Quoted 6 lines
Hi Hongda,
Title: I would suggest the following title:
xen/arm: vgic: Ignore write access to ICPENDR*
Agreed.
Quoted 6 lines · Hongda Deng
Quoted 5 lines
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 initialization code, these virtual registers will be accessed. And zephyr guest will get an IO data abort in initilization stage and enter
Quoted 8 lines
Typo: s/initilization/initialization/
I would also s/in/during the/
Quoted 1 line
fatal error. Emulating ICPENDR is not easy with the existing vGIC, so
How about s/enter fatal error/crash/?
Agreed.
Quoted 11 lines
Quoted 1 line
we currently ignore these virtual registers access and print a message
To me 'currently' refers to the existing code base (i.e. without your patch). In fact, this seems to be how you use 'currently' in the first paragraph. So how about replace "so we currently" with "rework the emulation to ignore...".
This seems to suggest the patch will modify both read and write access. However, AFAICT, only the write emulation is modified. Can this be clarified in the commit message?
Ack.
Quoted 44 lines
Quoted 4 lines
about whether they are already pending instead of returning unhandled. More details can be found at [1].
rtos/zephyr/blob/eaf6cf745df3807e6e
Quoted 5 lines
cc941c3a30de6c179ae359/drivers/interrupt_controller/intc_gicv3.c#L274
Signed-off-by Hongda Deng <[email protected]>---
Changes since v2:Quoted 10 lines
* Avoid to print messages when there is no pending interrupt * Add helper vgic_check_inflight_irqs_pending to check pending status * Print a message for each interrupt separately Changes since v1: * Check pending states by going through vcpu->arch.vgic.inflight_irqs instead of checking hardware registers --- xen/arch/arm/vgic-v2.c | 10 ++++++---- xen/arch/arm/vgic-v3.c | 16 ++++++++-------- xen/arch/arm/vgic.c | 36++++++++++++++++++++++++++++++++++++
xen/arch/arm/vgic-v2.c static int vgic_v2_distr_mmio_write(struct vcpu
Quoted 8 lines
xen/include/asm-arm/vgic.h | 3 ++- 4 files changed, 52 insertions(+), 13 deletions(-)xen/arch/arm/vgic-v2.c +0
-0@@ -481,10 +481,12 @@ static int vgic_v2_distr_mmio_write(struct vcpu*v,
mmio_info_t*info,xen/arch/arm/vgic-v2.c static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info,
Quoted 5 lines
xen/arch/arm/vgic-v2.c +0
-2case VRANGE32 (GICD_ICPENDR ,GICD_ICPENDRN ):if ( dabt.size !=DABT_WORD ) goto bad_width; -printk (XENLOG_G_ERR - "%pv: vGICD: unhandled word write %#"PRIregister" toICPENDR%d\n",
xen/arch/arm/vgic-v2.c static int vgic_v2_distr_mmio_write(struct vcpu *v, mmio_info_t *info, · line 489
Quoted 7 lines
xen/arch/arm/vgic-v2.c +5
-2- v, r, gicd_reg - GICD_ICPENDR); -return 0 ; + rank =vgic_rank_offset (v,1 , gicd_reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + + vgic_check_inflight_irqs_pending(v->domain, v, rank->index, r); > + + goto write_ignore_32;
Quoted 3 lines
NIT: We already check the access above. So I would simply use "
write_ignore" here.
Ack.
Quoted 15 lines
xen/arch/arm/vgic-v3.c static int
Quoted 8 lines
xen/arch/arm/vgic-v2.c +0
-0case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size !=DABT_WORD ) goto bad_width;xen/arch/arm/vgic-v3.c +0
-0@@ -817,10 +817,12 @@ static int__vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v,
xen/arch/arm/vgic-v3.c static int · line 820
Quoted 5 lines
xen/arch/arm/vgic-v3.c +0
-2case VRANGE32 (GICD_ICPENDR ,GICD_ICPENDRN ):if ( dabt.size !=DABT_WORD ) goto bad_width; -printk (XENLOG_G_ERR - "%pv: %s: unhandled word write %#"PRIregister" toICPENDR%d\n",
Quoted 11 lines
xen/arch/arm/vgic-v3.c static int __vgic_v3_distr_common_mmio_write(const char *name, struct vcpu *v, · line 825
Quoted 8 lines
xen/arch/arm/vgic-v3.c +6
-2- v, name, r, reg - GICD_ICPENDR); -return 0 ; + rank =vgic_rank_offset (v,1 , reg -GICD_ICPENDR ,DABT_WORD ); +if ( rank ==NULL ) goto write_ignore; + +vgic_check_inflight_irqs_pending (v->domain, v, rank->index, r); + + goto write_ignore_32;NIT: Same remark as the previous
write_ignore_32.
Ack.
Quoted 28 lines
xen/arch/arm/vgic-v3.c static int vgic_v3_rdistr_sgi_mmio_write(struct
Quoted 4 lines
xen/arch/arm/vgic-v3.c +0
-0case VRANGE32 (GICD_ISACTIVER ,GICD_ISACTIVERN ):if ( dabt.size !=DABT_WORD ) goto bad_width;@@ -987,10 +989,8 @@ static int vgic_v3_rdistr_sgi_mmio_write(structvcpu *v,
mmio_info_t*info,xen/arch/arm/vgic-v3.c static int vgic_v3_rdistr_sgi_mmio_write(struct vcpu *v, mmio_info_t *info,
Quoted 5 lines
xen/arch/arm/vgic-v3.c +0
-2case VREG32 (GICR_ICPENDR0 ):if ( dabt.size !=DABT_WORD ) goto bad_width; -printk (XENLOG_G_ERR - "%pv: vGICR: SGI: unhandled word write %#"PRIregister" toICPENDR0\n",
xen/arch/arm/vgic-v3.c static int vgic_v3_rdistr_sgi_mmio_write(struct vcpu *v, mmio_info_t *info,
Quoted 7 lines
xen/arch/arm/vgic-v3.c +2
-2- v, r); -return 0 ; +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 unsigned int vgic_max_vcpus(unsigned int
Quoted 5 lines
xen/arch/arm/vgic.c +0
-0@@ -726,6 +726,42 @@ unsigned int vgic_max_vcpus(unsigned int
domctl_vgic_version)Quoted 3 lines
xen/arch/arm/vgic.c +0
-0} }
Quoted 13 lines
xen/arch/arm/vgic.c unsigned int vgic_max_vcpus(unsigned int domctl_vgic_version) · line 737
Quoted 9 lines
xen/arch/arm/vgic.c +9
-0+void vgic_check_inflight_irqs_pending (struct domain *d,struct vcpu *v, +unsigned int rank,uint32_t r) +{ +const unsigned long mask = r; +unsigned int i; +unsigned long flags; +struct pending_irq *p; +bool private = rank ==0 ; +struct vcpu *v_target;AFAIC, flags, p,
v_targetare only used within the loop. So please reduce the scope and only declare them infor_each_set_bit().
Ack.
Quoted 12 lines
xen/arch/arm/vgic.c unsigned int vgic_max_vcpus(unsigned int domctl_vgic_version) · line 746
Quoted 9 lines
xen/arch/arm/vgic.c +9
-0+ +for_each_set_bit ( i, &mask,32 ) + { +unsigned int irq = i +32 * rank; + +if ( private ) + v_target =vgic_get_target_vcpu (v, irq); +else + v_target =vgic_get_target_vcpu (d->vcpu[0 ], irq);Shared interrupts can be accessed from any vCPU. So you can replace the 4 lines with:
Quoted 2 lines
v_target = vgic_get_target_vcpu(v, irq);
Ack.
I thought that v may be NULL, obviously I was overthinking about it.
Quoted 14 lines
xen/arch/arm/vgic.c unsigned int vgic_max_vcpus(unsigned int domctl_vgic_version) · line 756
Quoted 10 lines
xen/arch/arm/vgic.c +10
-0+ +spin_lock_irqsave (&v_target->arch.vgic.lock, flags); + + p =irq_to_pending (v_target, irq); + +if (unlikely (!p) ) + { +spin_unlock_irqrestore (&v_target->arch.vgic.lock, flags); +continue ; + }
irq_to_pending()cannot return NULL for non-LPI interrupts. But if you still want to check it, then the two if can be combined to something like:
Quoted 5 lines
if ( p && !list_empty(&p->inflight) )
printk(...)
spin_unlock_irqrestore(...);
Ack.
Quoted 7 lines
xen/arch/arm/vgic.c unsigned int vgic_max_vcpus(unsigned int domctl_vgic_version) · line 759
Quoted 3 lines
xen/arch/arm/vgic.c +3
-0+ +if ( !list_empty (&p->inflight) ) +printk ("%pv trying to clear pending interrupt %u.\n" , v, irq);This wants to be a
printk(XENLOG_G_WARNING ...)so the message will be appropriately rate-limited.
Ack.
Quoted 17 lines
xen/include/asm-arm/vgic.h extern bool vgic_to_sgi(struct vcpu *v, register_t
Quoted 13 lines
xen/arch/arm/vgic.c +5
-0+ +spin_unlock_irqrestore (&v_target->arch.vgic.lock, flags); + } +} +/* * Local variables: * mode: C xen/include/asm-arm/vgic.h +0
-0@@ -298,7 +298,8 @@ extern bool vgic_to_sgi(struct vcpu *v, register_tsgir,
xen/include/asm-arm/vgic.h extern bool vgic_to_sgi(struct vcpu *v, register_t sgir,
Quoted 3 lines
xen/include/asm-arm/vgic.h +0
-0enum gic_sgi_mode irqmode, int virq, const struct sgi_target *target); extern bool vgic_migrate_irq(struct vcpu *old, struct vcpu *new, unsigned
Quoted 8 lines
int irq);
xen/include/asm-arm/vgic.h extern bool vgic_to_sgi(struct vcpu *v, register_t · line 301
Quoted 2 lines
xen/include/asm-arm/vgic.h +1
-1- +extern void vgic_check_inflight_irqs_pending(struct domain *d, structvcpu *v,
xen/include/asm-arm/vgic.h extern bool vgic_to_sgi(struct vcpu *v, register_t sgir, · line 302
Quoted 1 line
xen/include/asm-arm/vgic.h +1
-0+ unsigned int rank, uint32_t r);Please keep the newline before the #endif.
Ack.
Quoted 9 lines
xen/include/asm-arm/vgic.h extern bool vgic_to_sgi(struct vcpu *v, register_t sgir, · line 305
Quoted 4 lines
xen/include/asm-arm/vgic.h +0
-0#endif /* !CONFIG_NEW_VGIC */ /*** Common VGIC functions used by Xen arch code ****/ Cheers,
--
Julien Grall
Thanks for your detailed suggestion ! I will keep these code principles in mind. I will send patch version4 ASAP.
Cheers,
---
Hongda