Skip to content

Commit

Permalink
KVM: arm/arm64: vgic: Don't rely on the wrong pending table
Browse files Browse the repository at this point in the history
commit ca185b2 upstream.

It's possible that two LPIs locate in the same "byte_offset" but target
two different vcpus, where their pending status are indicated by two
different pending tables.  In such a scenario, using last_byte_offset
optimization will lead KVM relying on the wrong pending table entry.
Let us use last_ptr instead, which can be treated as a byte index into
a pending table and also, can be vcpu specific.

Fixes: 2807712 ("KVM: arm64: vgic-v3: KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES")
Cc: [email protected]
Signed-off-by: Zenghui Yu <[email protected]>
Signed-off-by: Marc Zyngier <[email protected]>
Acked-by: Eric Auger <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Zenghui Yu authored and gregkh committed Dec 13, 2019
1 parent e8d9825 commit 66f8ca5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions virt/kvm/arm/vgic/vgic-v3.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ int vgic_v3_lpi_sync_pending_status(struct kvm *kvm, struct vgic_irq *irq)
int vgic_v3_save_pending_tables(struct kvm *kvm)
{
struct vgic_dist *dist = &kvm->arch.vgic;
int last_byte_offset = -1;
struct vgic_irq *irq;
gpa_t last_ptr = ~(gpa_t)0;
int ret;
u8 val;

Expand All @@ -396,11 +396,11 @@ int vgic_v3_save_pending_tables(struct kvm *kvm)
bit_nr = irq->intid % BITS_PER_BYTE;
ptr = pendbase + byte_offset;

if (byte_offset != last_byte_offset) {
if (ptr != last_ptr) {
ret = kvm_read_guest_lock(kvm, ptr, &val, 1);
if (ret)
return ret;
last_byte_offset = byte_offset;
last_ptr = ptr;
}

stored = val & (1U << bit_nr);
Expand Down

0 comments on commit 66f8ca5

Please sign in to comment.