Skip to contentSkip to conversation

vgic emulation and GICD_ITARGETSR

PATCH Superseded Stefano Stabellini 3 participants 13 messages May 25, 2014 – Jun 3, 2014

v1 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

cover vgic emulation and GICD_ITARGETSR

Hi all,
this small patch series improves vgic emulation in relation to GICD_ITARGETSR and irq delivery.

At the moment we don't support irq delivery to vcpu != 0, so prevent the guest from setting itarget to something != 0. vgic_enable_irqs and vgic_disable_irqs currently ignore the itarget settings and just enable/disable irqs on the current vcpu. Fix their behaviour to enable/disable irqs on the vcpu set by itarget, that is always vcpu0 for irq >= 32.

Stefano Stabellini (2):
xen/arm: add a warning if the guest asks for SPI delivery to vcpu != 0. xen/arm: observe itarget setting in vgic_enable_irqs and vgic_disable_irqs

 xen/arch/arm/vgic.c |   47 +++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 39 insertions(+), 8 deletions(-)
#1 lore raw

PATCH 1/2 xen/arm: add a warning if the guest asks for SPI delivery to vcpu != 0.

---
 xen/arch/arm/vgic.c |    5 +++++
 1 file changed, 5 insertions(+)
xen/arch/arm/vgic.c +5 -0
index 4869b87..e4f38a0 100644
@@ -581,6 +581,11 @@ static int vgic_distr_mmio_write(struct vcpu *v, mmio_info_t *info)
         if ( dabt.size != 0 && dabt.size != 2 ) goto bad_width;
         rank = vgic_irq_rank(v, 8, gicd_reg - GICD_ITARGETSR);
         if ( rank == NULL) goto write_ignore;
+        if ( *r )
+        {
+            gdprintk(XENLOG_DEBUG, "SPI delivery to seconday cpus is unimplemented\n");
+            return 1;
+        }
         vgic_lock_rank(v, rank);
         if ( dabt.size == 2 )
             rank->itargets[REG_RANK_INDEX(8, gicd_reg - GICD_ITARGETSR)] = *r;
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH 1/2] xen/arm: add a warning if the guest asks for SPI delivery to vcpu != 0.

Hi Stefano,

Quoted 10 lines · Stefano Stabellini
---
  xen/arch/arm/vgic.c |    5 +++++
  1 file changed, 5 insertions(+)
xen/arch/arm/vgic.c +0 -0
index 4869b87..e4f38a0 100644

xen/arch/arm/vgic.c static int vgic_distr_mmio_write(struct vcpu *v, mmio_info_t *info) · line 584

Quoted 4 lines
xen/arch/arm/vgic.c +1 -0
@@ -581,6 +581,11 @@ static int vgic_distr_mmio_write(struct vcpu *v, mmio_info_t *info)
          if ( dabt.size != 0 && dabt.size != 2 ) goto bad_width;
          rank = vgic_irq_rank(v, 8, gicd_reg - GICD_ITARGETSR);
          if ( rank == NULL) goto write_ignore;
+        if ( *r )

This is wrong, ITARGETSR store a 4 bitmask of CPUs, one per interrupt. Each bit of the mask correspond to a CPU (see Table 4-17 in the GICv2 manual).

Furthermore, I think it's safe to just ignore write. The manual says:
"It is IMPLEMENTATION DEFINED which, if any, SPIs are statically configured in hardware. The CPU targets field for such an SPI is read-only, and returns a value that indicates the CPU targets for the interrupt."

With the former comment, your patch #2 is also wrong.

xen/arch/arm/vgic.c static int vgic_distr_mmio_write(struct vcpu *v, mmio_info_t *info) · line 586

Quoted 2 lines
xen/arch/arm/vgic.c +2 -0
+        {
+            gdprintk(XENLOG_DEBUG, "SPI delivery to seconday cpus is unimplemented\n");

s/seconday/secondary/

Regards,

Signature · 1 line
Julien Grall
#3 lore raw

Re: [PATCH 1/2] xen/arm: add a warning if the guest asks for SPI delivery to vcpu != 0.

Quoted 8 lines · Julien Grall

Hi Stefano,

Quoted 5 lines · Stefano Stabellini
---
  xen/arch/arm/vgic.c |    5 +++++
  1 file changed, 5 insertions(+)
Quoted 13 lines

xen/arch/arm/vgic.c static int vgic_distr_mmio_write(struct vcpu *v, · line 585

Quoted 10 lines
xen/arch/arm/vgic.c +1 -0
index 4869b87..e4f38a0 100644
@@ -581,6 +581,11 @@ static int vgic_distr_mmio_write(struct vcpu *v,
 mmio_info_t *info)
          if ( dabt.size != 0 && dabt.size != 2 ) goto bad_width;
          rank = vgic_irq_rank(v, 8, gicd_reg - GICD_ITARGETSR);
          if ( rank == NULL) goto write_ignore;
+        if ( *r )

This is wrong, ITARGETSR store a 4 bitmask of CPUs, one per interrupt. Each bit of the mask correspond to a CPU (see Table 4-17 in the GICv2 manual).

you are right

Quoted 4 lines

Furthermore, I think it's safe to just ignore write. The manual says:
"It is IMPLEMENTATION DEFINED which, if any, SPIs are statically configured in hardware. The CPU targets field for such an SPI is read-only, and returns a value that indicates the CPU targets for the interrupt."

Good point

Quoted 1 line

With the former comment, your patch #2 is also wrong.

Patch #2 is valid regardless of the specific itarget setting

Quoted 11 lines

xen/arch/arm/vgic.c static int vgic_distr_mmio_write(struct vcpu *v, · line 588

Quoted 3 lines
xen/arch/arm/vgic.c +2 -0
+        {
+            gdprintk(XENLOG_DEBUG, "SPI delivery to seconday cpus is
 unimplemented\n");

s/seconday/secondary/

Regards,

Signature · 1 line
Julien Grall
#4 lore raw

PATCH 2/2 xen/arm: observe itarget setting in vgic_enable_irqs and vgic_disable_irqs

In reply to Stefano Stabellini

vgic_enable_irqs should enable irq delivery to the vcpu specified by GICD_ITARGETSR, rather than the vcpu that wrote to GICD_ISENABLER. Similarly vgic_disable_irqs should use the target vcpu specified by itarget to disable irqs.

---
 xen/arch/arm/vgic.c |   42 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 34 insertions(+), 8 deletions(-)
xen/arch/arm/vgic.c +34 -8
index e4f38a0..0f0ba1d 100644
@@ -376,12 +376,25 @@ static void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
     unsigned int irq;
     unsigned long flags;
     int i = 0;
+    int target;
+    struct vcpu *v_target;
+    struct vgic_irq_rank *rank;
 
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
-        p = irq_to_pending(v, irq);
+        rank = vgic_irq_rank(v, 1, irq/32);
+        vgic_lock_rank(v, rank);
+        if ( irq >= 32 )
+        {
+            target = rank->itargets[(irq%32)/4] >> (8*(irq % 4));
+            target &= 0xff;
+            v_target = v->domain->vcpu[target];
+        } else
+            v_target = v;
+        vgic_unlock_rank(v, rank);
+        p = irq_to_pending(v_target, irq);
         clear_bit(GIC_IRQ_GUEST_ENABLED, &p->status);
-        gic_remove_from_queues(v, irq);
+        gic_remove_from_queues(v_target, irq);
         if ( p->desc != NULL )
         {
             spin_lock_irqsave(&p->desc->lock, flags);
@@ -399,21 +412,34 @@ static void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n)
     unsigned int irq;
     unsigned long flags;
     int i = 0;
+    int target;
+    struct vcpu *v_target;
+    struct vgic_irq_rank *rank;
 
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
-        p = irq_to_pending(v, irq);
+        rank = vgic_irq_rank(v, 1, irq/32);
+        vgic_lock_rank(v, rank);
+        if ( irq >= 32 )
+        {
+            target = rank->itargets[(irq%32)/4] >> (8*(irq % 4));
+            target &= 0xff;
+            v_target = v->domain->vcpu[target];
+        } else
+            v_target = v;
+        vgic_unlock_rank(v, rank);
+        p = irq_to_pending(v_target, irq);
         set_bit(GIC_IRQ_GUEST_ENABLED, &p->status);
-        if ( irq == v->domain->arch.evtchn_irq &&
+        if ( irq == v_target->domain->arch.evtchn_irq &&
              vcpu_info(current, evtchn_upcall_pending) &&
              list_empty(&p->inflight) )
-            vgic_vcpu_inject_irq(v, irq);
+            vgic_vcpu_inject_irq(v_target, irq);
         else {
             unsigned long flags;
-            spin_lock_irqsave(&v->arch.vgic.lock, flags);
+            spin_lock_irqsave(&v_target->arch.vgic.lock, flags);
             if ( !list_empty(&p->inflight) && !test_bit(GIC_IRQ_GUEST_VISIBLE, &p->status) )
-                gic_raise_guest_irq(v, irq, p->priority);
-            spin_unlock_irqrestore(&v->arch.vgic.lock, flags);
+                gic_raise_guest_irq(v_target, irq, p->priority);
+            spin_unlock_irqrestore(&v_target->arch.vgic.lock, flags);
         }
         if ( p->desc != NULL )
         {
Signature · 1 line
1.7.10.4
#5 lore raw

Re: [PATCH 2/2] xen/arm: observe itarget setting in vgic_enable_irqs and vgic_disable_irqs

Hi Stefano,

xen/arch/arm/vgic.c static void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n) · line 391

Quoted 10 lines · Stefano Stabellini
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
xen/arch/arm/vgic.c +7 -1
-        p = irq_to_pending(v, irq);
+        rank = vgic_irq_rank(v, 1, irq/32);
+        vgic_lock_rank(v, rank);
+        if ( irq >= 32 )
+        {
+            target = rank->itargets[(irq%32)/4] >> (8*(irq % 4));
+            target &= 0xff;
+            v_target = v->domain->vcpu[target];

Without looking to the target stuff (see comment on patch #1), I don't need to do a specific case for SPIs.

It will avoid diverging following the IRQ type.

Regards,

Signature · 1 line
Julien Grall
#6 lore raw

Re: [PATCH 2/2] xen/arm: observe itarget setting in vgic_enable_irqs and vgic_disable_irqs

Quoted 14 lines · Julien Grall

Hi Stefano,

xen/arch/arm/vgic.c static void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n) · line 391

Quoted 10 lines · Stefano Stabellini
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
xen/arch/arm/vgic.c +7 -1
-        p = irq_to_pending(v, irq);
+        rank = vgic_irq_rank(v, 1, irq/32);
+        vgic_lock_rank(v, rank);
+        if ( irq >= 32 )
+        {
+            target = rank->itargets[(irq%32)/4] >> (8*(irq % 4));
+            target &= 0xff;
+            v_target = v->domain->vcpu[target];
Quoted 4 lines

Without looking to the target stuff (see comment on patch #1), I don't need to do a specific case for SPIs.

It will avoid diverging following the IRQ type.

Sooner or later we'll implement SPI delivery to vcpu != 0. When we do we'll actually need this patch, that is correct even without SPI delivery to vcpu != 0.

#7 lore raw

Re: [PATCH 2/2] xen/arm: observe itarget setting in vgic_enable_irqs and vgic_disable_irqs

Quoted 13 lines · Stefano Stabellini
Quoted 12 lines · Julien Grall
Quoted 10 lines · Stefano Stabellini
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
xen/arch/arm/vgic.c +7 -1
-        p = irq_to_pending(v, irq);
+        rank = vgic_irq_rank(v, 1, irq/32);
+        vgic_lock_rank(v, rank);
+        if ( irq >= 32 )
+        {
+            target = rank->itargets[(irq%32)/4] >> (8*(irq % 4));
+            target &= 0xff;
+            v_target = v->domain->vcpu[target];
Quoted 9 lines
Quoted 4 lines

Without looking to the target stuff (see comment on patch #1), I don't need to do a specific case for SPIs.

It will avoid diverging following the IRQ type.

Sooner or later we'll implement SPI delivery to vcpu != 0. When we do we'll actually need this patch, that is correct even without SPI delivery to vcpu != 0.

Hrrrm .... right I forgot this case. If so, the vgic_irq_rank_lock doesn't need to be taken for non-SPIs.

Regards,

Signature · 1 line
Julien Grall
#8 lore raw

Re: [PATCH 2/2] xen/arm: observe itarget setting in vgic_enable_irqs and vgic_disable_irqs

In reply to Stefano Stabellini
Quoted 15 lines · Stefano Stabellini
Quoted 14 lines · Julien Grall

Hi Stefano,

Quoted 10 lines · Stefano Stabellini
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
xen/arch/arm/vgic.c +7 -1
-        p = irq_to_pending(v, irq);
+        rank = vgic_irq_rank(v, 1, irq/32);
+        vgic_lock_rank(v, rank);
+        if ( irq >= 32 )
+        {
+            target = rank->itargets[(irq%32)/4] >> (8*(irq % 4));
+            target &= 0xff;
+            v_target = v->domain->vcpu[target];
Quoted 9 lines
Quoted 4 lines

Without looking to the target stuff (see comment on patch #1), I don't need to do a specific case for SPIs.

It will avoid diverging following the IRQ type.

Sooner or later we'll implement SPI delivery to vcpu != 0. When we do we'll actually need this patch, that is correct even without SPI delivery to vcpu != 0.

To be clear, I didn't say this patch was not useful. I just say we can merge the code and do use the same path for non-SPIs.

Regards,

Signature · 1 line
Julien Grall
#9 lore raw

Re: [PATCH 2/2] xen/arm: observe itarget setting in vgic_enable_irqs and vgic_disable_irqs

Quoted 21 lines · Julien Grall
Quoted 20 lines · Stefano Stabellini
Quoted 18 lines · Julien Grall

Hi Stefano,

xen/arch/arm/vgic.c static void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n) · line 391

Quoted 10 lines · Stefano Stabellini
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
xen/arch/arm/vgic.c +7 -1
-        p = irq_to_pending(v, irq);
+        rank = vgic_irq_rank(v, 1, irq/32);
+        vgic_lock_rank(v, rank);
+        if ( irq >= 32 )
+        {
+            target = rank->itargets[(irq%32)/4] >> (8*(irq % 4));
+            target &= 0xff;
+            v_target = v->domain->vcpu[target];

Without looking to the target stuff (see comment on patch #1), I don't need to do a specific case for SPIs.

It will avoid diverging following the IRQ type.

Quoted 7 lines
Quoted 4 lines

Sooner or later we'll implement SPI delivery to vcpu != 0. When we do we'll actually need this patch, that is correct even without SPI delivery to vcpu != 0.

To be clear, I didn't say this patch was not useful. I just say we can merge the code and do use the same path for non-SPIs.

Ah OK

#10 lore raw

Re: [PATCH 2/2] xen/arm: observe itarget setting in vgic_enable_irqs and vgic_disable_irqs

In reply to Stefano Stabellini
Quoted 21 lines · Stefano Stabellini

vgic_enable_irqs should enable irq delivery to the vcpu specified by GICD_ITARGETSR, rather than the vcpu that wrote to GICD_ISENABLER. Similarly vgic_disable_irqs should use the target vcpu specified by itarget to disable irqs.

---
 xen/arch/arm/vgic.c |   42 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 34 insertions(+), 8 deletions(-)
xen/arch/arm/vgic.c +3 -0
index e4f38a0..0f0ba1d 100644
@@ -376,12 +376,25 @@ static void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
     unsigned int irq;
     unsigned long flags;
     int i = 0;
+    int target;
+    struct vcpu *v_target;
+    struct vgic_irq_rank *rank;

xen/arch/arm/vgic.c static void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n) · line 390

Quoted 10 lines
xen/arch/arm/vgic.c +6 -1
 
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
-        p = irq_to_pending(v, irq);
+        rank = vgic_irq_rank(v, 1, irq/32);
+        vgic_lock_rank(v, rank);
+        if ( irq >= 32 )
+        {
+            target = rank->itargets[(irq%32)/4] >> (8*(irq % 4));
+            target &= 0xff;

This is byte_read(), isn't it?

xen/arch/arm/vgic.c static void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n) · line 391

Quoted 1 line
xen/arch/arm/vgic.c +1 -0
+            v_target = v->domain->vcpu[target];

There needs to be some sort of range check here I think. Else you are setting a trap for whoever implements itargets properly.

Quoted 20 lines
xen/arch/arm/vgic.c +8 -1
+        } else
+            v_target = v;
+        vgic_unlock_rank(v, rank);
+        p = irq_to_pending(v_target, irq);
         clear_bit(GIC_IRQ_GUEST_ENABLED, &p->status);
-        gic_remove_from_queues(v, irq);
+        gic_remove_from_queues(v_target, irq);
         if ( p->desc != NULL )
         {
             spin_lock_irqsave(&p->desc->lock, flags);
@@ -399,21 +412,34 @@ static void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n)
     unsigned int irq;
     unsigned long flags;
     int i = 0;
+    int target;
+    struct vcpu *v_target;
+    struct vgic_irq_rank *rank;
 
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);

xen/arch/arm/vgic.c static void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n) · line 429

Quoted 10 lines
xen/arch/arm/vgic.c +9 -1
-        p = irq_to_pending(v, irq);
+        rank = vgic_irq_rank(v, 1, irq/32);
+        vgic_lock_rank(v, rank);
+        if ( irq >= 32 )
+        {
+            target = rank->itargets[(irq%32)/4] >> (8*(irq % 4));
+            target &= 0xff;
+            v_target = v->domain->vcpu[target];
+        } else
+            v_target = v;

This is the same code as above -- there should be a helper (get_target_vcpu or some such).

Quoted 21 lines
xen/arch/arm/vgic.c +7 -5
+        vgic_unlock_rank(v, rank);
+        p = irq_to_pending(v_target, irq);
         set_bit(GIC_IRQ_GUEST_ENABLED, &p->status);
-        if ( irq == v->domain->arch.evtchn_irq &&
+        if ( irq == v_target->domain->arch.evtchn_irq &&
              vcpu_info(current, evtchn_upcall_pending) &&
              list_empty(&p->inflight) )
-            vgic_vcpu_inject_irq(v, irq);
+            vgic_vcpu_inject_irq(v_target, irq);
         else {
             unsigned long flags;
-            spin_lock_irqsave(&v->arch.vgic.lock, flags);
+            spin_lock_irqsave(&v_target->arch.vgic.lock, flags);
             if ( !list_empty(&p->inflight) && !test_bit(GIC_IRQ_GUEST_VISIBLE, &p->status) )
-                gic_raise_guest_irq(v, irq, p->priority);
-            spin_unlock_irqrestore(&v->arch.vgic.lock, flags);
+                gic_raise_guest_irq(v_target, irq, p->priority);
+            spin_unlock_irqrestore(&v_target->arch.vgic.lock, flags);
         }
         if ( p->desc != NULL )
         {
#11 lore raw

Re: [PATCH 2/2] xen/arm: observe itarget setting in vgic_enable_irqs and vgic_disable_irqs

Quoted 23 lines · Ian Campbell
Quoted 22 lines · Stefano Stabellini

vgic_enable_irqs should enable irq delivery to the vcpu specified by GICD_ITARGETSR, rather than the vcpu that wrote to GICD_ISENABLER. Similarly vgic_disable_irqs should use the target vcpu specified by itarget to disable irqs.

---
 xen/arch/arm/vgic.c |   42 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 34 insertions(+), 8 deletions(-)
xen/arch/arm/vgic.c +3 -0
index e4f38a0..0f0ba1d 100644
@@ -376,12 +376,25 @@ static void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n)
     unsigned int irq;
     unsigned long flags;
     int i = 0;
+    int target;
+    struct vcpu *v_target;
+    struct vgic_irq_rank *rank;
 
Quoted 11 lines

xen/arch/arm/vgic.c static void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n) · line 390

Quoted 9 lines
xen/arch/arm/vgic.c +6 -1
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
-        p = irq_to_pending(v, irq);
+        rank = vgic_irq_rank(v, 1, irq/32);
+        vgic_lock_rank(v, rank);
+        if ( irq >= 32 )
+        {
+            target = rank->itargets[(irq%32)/4] >> (8*(irq % 4));
+            target &= 0xff;

This is byte_read(), isn't it?

yes, I'll use it

Quoted 4 lines

xen/arch/arm/vgic.c static void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n) · line 391

Quoted 1 line
xen/arch/arm/vgic.c +1 -0
+            v_target = v->domain->vcpu[target];

There needs to be some sort of range check here I think. Else you are setting a trap for whoever implements itargets properly.

The check should be at the point where we write itargets, not here. The previous patch already introduces a check for itargets to always be zero.

Quoted 18 lines
Quoted 18 lines
xen/arch/arm/vgic.c +8 -1
+        } else
+            v_target = v;
+        vgic_unlock_rank(v, rank);
+        p = irq_to_pending(v_target, irq);
         clear_bit(GIC_IRQ_GUEST_ENABLED, &p->status);
-        gic_remove_from_queues(v, irq);
+        gic_remove_from_queues(v_target, irq);
         if ( p->desc != NULL )
         {
             spin_lock_irqsave(&p->desc->lock, flags);
@@ -399,21 +412,34 @@ static void vgic_enable_irqs(struct vcpu *v, uint32_t r, int n)
     unsigned int irq;
     unsigned long flags;
     int i = 0;
+    int target;
+    struct vcpu *v_target;
+    struct vgic_irq_rank *rank;
 
Quoted 15 lines

xen/arch/arm/vgic.c static void vgic_disable_irqs(struct vcpu *v, uint32_t r, int n) · line 393

Quoted 12 lines
xen/arch/arm/vgic.c +9 -1
     while ( (i = find_next_bit(&mask, 32, i)) < 32 ) {
         irq = i + (32 * n);
-        p = irq_to_pending(v, irq);
+        rank = vgic_irq_rank(v, 1, irq/32);
+        vgic_lock_rank(v, rank);
+        if ( irq >= 32 )
+        {
+            target = rank->itargets[(irq%32)/4] >> (8*(irq % 4));
+            target &= 0xff;
+            v_target = v->domain->vcpu[target];
+        } else
+            v_target = v;

This is the same code as above -- there should be a helper (get_target_vcpu or some such).

Good idea

Quoted 23 lines
Quoted 21 lines
xen/arch/arm/vgic.c +7 -5
+        vgic_unlock_rank(v, rank);
+        p = irq_to_pending(v_target, irq);
         set_bit(GIC_IRQ_GUEST_ENABLED, &p->status);
-        if ( irq == v->domain->arch.evtchn_irq &&
+        if ( irq == v_target->domain->arch.evtchn_irq &&
              vcpu_info(current, evtchn_upcall_pending) &&
              list_empty(&p->inflight) )
-            vgic_vcpu_inject_irq(v, irq);
+            vgic_vcpu_inject_irq(v_target, irq);
         else {
             unsigned long flags;
-            spin_lock_irqsave(&v->arch.vgic.lock, flags);
+            spin_lock_irqsave(&v_target->arch.vgic.lock, flags);
             if ( !list_empty(&p->inflight) && !test_bit(GIC_IRQ_GUEST_VISIBLE, &p->status) )
-                gic_raise_guest_irq(v, irq, p->priority);
-            spin_unlock_irqrestore(&v->arch.vgic.lock, flags);
+                gic_raise_guest_irq(v_target, irq, p->priority);
+            spin_unlock_irqrestore(&v_target->arch.vgic.lock, flags);
         }
         if ( p->desc != NULL )
         {
#12 lore raw
In reply to Stefano Stabellini
Quoted 6 lines · Stefano Stabellini

Hi all,
this small patch series improves vgic emulation in relation to GICD_ITARGETSR and irq delivery.

At the moment we don't support irq delivery to vcpu != 0, so prevent the guest from setting itarget to something != 0.

How hard would this be to support? I think all interrupts already all arrive at pCPU==0, so we must be capable of forwarding them to whichever pCPU might be running vCPU==0? Is extending that to select wihch vcpu to send to hard?

Quoted 12 lines

vgic_enable_irqs and vgic_disable_irqs currently ignore the itarget settings and just enable/disable irqs on the current vcpu. Fix their behaviour to enable/disable irqs on the vcpu set by itarget, that is always vcpu0 for irq >= 32.

Stefano Stabellini (2):
xen/arm: add a warning if the guest asks for SPI delivery to vcpu != 0. xen/arm: observe itarget setting in vgic_enable_irqs and vgic_disable_irqs

 xen/arch/arm/vgic.c |   47 +++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 39 insertions(+), 8 deletions(-)