arm/vgic-v3: fix virq offset in the rank when storing irouter
PATCH v2 1/1 arm/vgic-v3: fix virq offset in the rank when storing irouter
When vGIC performs irouter registers emulation, to get the target vCPU via virq conveniently, Xen doesn't store the irouter value directly, instead it will use the value (affinities) in irouter to calculate the target vCPU, and then save the target vCPU in irq rank->vcpu[offset].
When vGIC tries to get the target vCPU, it first calculates the target vCPU index via
int target = read_atomic(&rank->vcpu[virq & INTERRUPT_RANK_MASK]);
and then it gets the target vCPU via
v->domain->vcpu[target];
When vGIC tries to store irouter for one virq, the target vCPU index in the rank is computed as
offset &= virq & INTERRUPT_RANK_MASK;
finally it gets the target vCPU via
d->vcpu[read_atomic(&rank->vcpu[offset])];
There is a difference between them while getting the target vCPU index in the rank. Actually (virq & INTERRUPT_RANK_MASK) would already get the target vCPU index in the rank, it's wrong to add '&' before '=' when calculate the offset.
For example, the target vCPU index in the rank should be 6 for virq 38, but vGIC will get offset=0 when vGIC stores the irouter for this virq, and finally vGIC will access the wrong target vCPU index in the rank when updating the irouter.
--- xen/arch/arm/vgic-v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/vgic-v3.c +1 -1
@@ -135,7 +135,7 @@ static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank,ASSERT (virq >=32 );/* Get the index in the rank */ - offset &= virq &INTERRUPT_RANK_MASK ; + offset = virq &INTERRUPT_RANK_MASK ; new_vcpu =vgic_v3_irouter_to_vcpu (d, irouter); old_vcpu = d->vcpu[read_atomic (&rank->vcpu[offset])];
Signature · 1 line
2.25.1
Hi Hongda,
Quoted 22 lines · Hongda Deng
When vGIC performs irouter registers emulation, to get the target vCPU via virq conveniently, Xen doesn't store the irouter value directly, instead it will use the value (affinities) in irouter to calculate the target vCPU, and then save the target vCPU in irq rank->vcpu[offset].
When vGIC tries to get the target vCPU, it first calculates the target vCPU index via
int target =read_atomic(&rank->vcpu[virq & INTERRUPT_RANK_MASK]);
and then it gets the target vCPU via
v->domain->vcpu[target];When vGIC tries to store irouter for one virq, the target vCPU index in the rank is computed as
offset &= virq &INTERRUPT_RANK_MASK;
finally it gets the target vCPU via
d->vcpu[read_atomic(&rank->vcpu[offset])];There is a difference between them while getting the target vCPU index in the rank. Actually (virq &
INTERRUPT_RANK_MASK) would already get the target vCPU index in the rank, it's wrong to add '&' before '=' when calculate the offset.
Quoted 7 lines
For example, the target vCPU index in the rank should be 6 for virq 38, but vGIC will get offset=0 when vGIC stores the irouter for this virq, and finally vGIC will access the wrong target vCPU index in the rank when updating the irouter.
Fixes 5d495f4349b5 ("xen/arm: vgic: Optimize the way to store the target vCPU in the rank")Signed-off-by Hongda Deng <[email protected]>
This will also want to be backported. I will add it in my queue.
Quoted 1 line
---
For future series, please provide a changelog for every version.
Quoted 8 lines
xen/arch/arm/vgic-v3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/arch/arm/vgic-v3.c +0
-0
xen/arch/arm/vgic-v3.c static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank, · line 141
Quoted 8 lines
xen/arch/arm/vgic-v3.c +1
-1@@ -135,7 +135,7 @@ static void vgic_store_irouter(struct domain *d, struct vgic_irq_rank *rank,ASSERT (virq >=32 );/* Get the index in the rank */ - offset &= virq &INTERRUPT_RANK_MASK ; + offset = virq &INTERRUPT_RANK_MASK ; new_vcpu =vgic_v3_irouter_to_vcpu (d, irouter); old_vcpu = d->vcpu[read_atomic (&rank->vcpu[offset])];
Cheers,
Signature · 1 line
Julien Grall
Quoted 30 lines · Julien Grall
Hi Hongda,
Quoted 27 lines · Hongda Deng
When vGIC performs irouter registers emulation, to get the target vCPU via virq conveniently, Xen doesn't store the irouter value directly, instead it will use the value (affinities) in irouter to calculate the target vCPU, and then save the target vCPU in irq rank->vcpu[offset].
When vGIC tries to get the target vCPU, it first calculates the target vCPU index via
int target =read_atomic(&rank->vcpu[virq & INTERRUPT_RANK_MASK]); and then it gets the target vCPU via v->domain->vcpu[target];When vGIC tries to store irouter for one virq, the target vCPU index in the rank is computed as
offset &= virq &INTERRUPT_RANK_MASK;
finally it gets the target vCPU via d->vcpu[read_atomic(&rank->vcpu[offset])];There is a difference between them while getting the target vCPU index in the rank. Actually (virq &
INTERRUPT_RANK_MASK) would already get the target vCPU index in the rank, it's wrong to add '&' before '=' when calculate the offset.For example, the target vCPU index in the rank should be 6 for virq 38, but vGIC will get offset=0 when vGIC stores the irouter for this virq, and finally vGIC will access the wrong target vCPU index in the rank when updating the irouter.
Quoted 4 lines
Quoted 2 lines
Fixes 5d495f4349b5 ("xen/arm: vgic: Optimize the way to store the target vCPU in the rank")Signed-off-by Hongda Deng <[email protected]>Reviewed-by Julien Grall <[email protected]>
Committed.
Cheers,
Signature · 1 line
Julien Grall