Commit d9ae449b authored by Christoffer Dall's avatar Christoffer Dall

KVM: arm64: vgic-its: Make updates to propbaser/pendbaser atomic

There are two problems with the current implementation of the MMIO
handlers for the propbaser and pendbaser:

First, the write to the value itself is not guaranteed to be an atomic
64-bit write so two concurrent writes to the structure field could be
intermixed.

Second, because we do a read-modify-update operation without any
synchronization, if we have two 32-bit accesses to separate parts of the
register, we can loose one of them.

By using the atomic cmpxchg64 we should cover both issues above.
Reviewed-by: default avatarAndre Przywara <andre.przywara@arm.com>
Signed-off-by: default avatarChristoffer Dall <christoffer.dall@linaro.org>
parent 2cccbb36
...@@ -306,16 +306,19 @@ static void vgic_mmio_write_propbase(struct kvm_vcpu *vcpu, ...@@ -306,16 +306,19 @@ static void vgic_mmio_write_propbase(struct kvm_vcpu *vcpu,
{ {
struct vgic_dist *dist = &vcpu->kvm->arch.vgic; struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
u64 propbaser = dist->propbaser; u64 old_propbaser, propbaser;
/* Storing a value with LPIs already enabled is undefined */ /* Storing a value with LPIs already enabled is undefined */
if (vgic_cpu->lpis_enabled) if (vgic_cpu->lpis_enabled)
return; return;
propbaser = update_64bit_reg(propbaser, addr & 4, len, val); do {
propbaser = vgic_sanitise_propbaser(propbaser); old_propbaser = dist->propbaser;
propbaser = old_propbaser;
dist->propbaser = propbaser; propbaser = update_64bit_reg(propbaser, addr & 4, len, val);
propbaser = vgic_sanitise_propbaser(propbaser);
} while (cmpxchg64(&dist->propbaser, old_propbaser,
propbaser) != old_propbaser);
} }
static unsigned long vgic_mmio_read_pendbase(struct kvm_vcpu *vcpu, static unsigned long vgic_mmio_read_pendbase(struct kvm_vcpu *vcpu,
...@@ -331,16 +334,19 @@ static void vgic_mmio_write_pendbase(struct kvm_vcpu *vcpu, ...@@ -331,16 +334,19 @@ static void vgic_mmio_write_pendbase(struct kvm_vcpu *vcpu,
unsigned long val) unsigned long val)
{ {
struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
u64 pendbaser = vgic_cpu->pendbaser; u64 old_pendbaser, pendbaser;
/* Storing a value with LPIs already enabled is undefined */ /* Storing a value with LPIs already enabled is undefined */
if (vgic_cpu->lpis_enabled) if (vgic_cpu->lpis_enabled)
return; return;
pendbaser = update_64bit_reg(pendbaser, addr & 4, len, val); do {
pendbaser = vgic_sanitise_pendbaser(pendbaser); old_pendbaser = vgic_cpu->pendbaser;
pendbaser = old_pendbaser;
vgic_cpu->pendbaser = pendbaser; pendbaser = update_64bit_reg(pendbaser, addr & 4, len, val);
pendbaser = vgic_sanitise_pendbaser(pendbaser);
} while (cmpxchg64(&vgic_cpu->pendbaser, old_pendbaser,
pendbaser) != old_pendbaser);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment