Skip to content

Commit 266068e

Browse files
Andre-ARMMarc Zyngier
authored andcommitted
KVM: arm/arm64: vgic-v2: Limit ITARGETSR bits to number of VCPUs
The GICv2 spec says in section 4.3.12 that a "CPU targets field bit that corresponds to an unimplemented CPU interface is RAZ/WI." Currently we allow the guest to write any value in there and it can read that back. Mask the written value with the proper CPU mask to be spec compliant. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent fd5ebf9 commit 266068e

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

virt/kvm/arm/vgic/vgic-mmio-v2.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ static void vgic_mmio_write_target(struct kvm_vcpu *vcpu,
129129
unsigned long val)
130130
{
131131
u32 intid = VGIC_ADDR_TO_INTID(addr, 8);
132+
u8 cpu_mask = GENMASK(atomic_read(&vcpu->kvm->online_vcpus) - 1, 0);
132133
int i;
133134

134135
/* GICD_ITARGETSR[0-7] are read-only */
@@ -141,7 +142,7 @@ static void vgic_mmio_write_target(struct kvm_vcpu *vcpu,
141142

142143
spin_lock(&irq->irq_lock);
143144

144-
irq->targets = (val >> (i * 8)) & 0xff;
145+
irq->targets = (val >> (i * 8)) & cpu_mask;
145146
target = irq->targets ? __ffs(irq->targets) : 0;
146147
irq->target_vcpu = kvm_get_vcpu(vcpu->kvm, target);
147148

0 commit comments

Comments
 (0)