diff options
author | Christoffer Dall <christoffer.dall@linaro.org> | 2016-08-03 12:03:44 -0400 |
---|---|---|
committer | Christoffer Dall <christoffer.dall@linaro.org> | 2016-08-15 17:00:20 -0400 |
commit | d9ae449b3d14d7c55f69af329972f175d180e68d (patch) | |
tree | c9b04b65130b96654d275cb550568748a4087f08 /virt | |
parent | 2cccbb368a2bf27d98cf36bb424fbbf5572c0fab (diff) |
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: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
Diffstat (limited to 'virt')
-rw-r--r-- | virt/kvm/arm/vgic/vgic-mmio-v3.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/virt/kvm/arm/vgic/vgic-mmio-v3.c b/virt/kvm/arm/vgic/vgic-mmio-v3.c index ff668e0dd586..90d81811fdda 100644 --- a/virt/kvm/arm/vgic/vgic-mmio-v3.c +++ b/virt/kvm/arm/vgic/vgic-mmio-v3.c | |||
@@ -306,16 +306,19 @@ static void vgic_mmio_write_propbase(struct kvm_vcpu *vcpu, | |||
306 | { | 306 | { |
307 | struct vgic_dist *dist = &vcpu->kvm->arch.vgic; | 307 | struct vgic_dist *dist = &vcpu->kvm->arch.vgic; |
308 | struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; | 308 | struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; |
309 | u64 propbaser = dist->propbaser; | 309 | u64 old_propbaser, propbaser; |
310 | 310 | ||
311 | /* Storing a value with LPIs already enabled is undefined */ | 311 | /* Storing a value with LPIs already enabled is undefined */ |
312 | if (vgic_cpu->lpis_enabled) | 312 | if (vgic_cpu->lpis_enabled) |
313 | return; | 313 | return; |
314 | 314 | ||
315 | propbaser = update_64bit_reg(propbaser, addr & 4, len, val); | 315 | do { |
316 | propbaser = vgic_sanitise_propbaser(propbaser); | 316 | old_propbaser = dist->propbaser; |
317 | 317 | propbaser = old_propbaser; | |
318 | dist->propbaser = propbaser; | 318 | propbaser = update_64bit_reg(propbaser, addr & 4, len, val); |
319 | propbaser = vgic_sanitise_propbaser(propbaser); | ||
320 | } while (cmpxchg64(&dist->propbaser, old_propbaser, | ||
321 | propbaser) != old_propbaser); | ||
319 | } | 322 | } |
320 | 323 | ||
321 | static unsigned long vgic_mmio_read_pendbase(struct kvm_vcpu *vcpu, | 324 | 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 | unsigned long val) | 334 | unsigned long val) |
332 | { | 335 | { |
333 | struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; | 336 | struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu; |
334 | u64 pendbaser = vgic_cpu->pendbaser; | 337 | u64 old_pendbaser, pendbaser; |
335 | 338 | ||
336 | /* Storing a value with LPIs already enabled is undefined */ | 339 | /* Storing a value with LPIs already enabled is undefined */ |
337 | if (vgic_cpu->lpis_enabled) | 340 | if (vgic_cpu->lpis_enabled) |
338 | return; | 341 | return; |
339 | 342 | ||
340 | pendbaser = update_64bit_reg(pendbaser, addr & 4, len, val); | 343 | do { |
341 | pendbaser = vgic_sanitise_pendbaser(pendbaser); | 344 | old_pendbaser = vgic_cpu->pendbaser; |
342 | 345 | pendbaser = old_pendbaser; | |
343 | vgic_cpu->pendbaser = pendbaser; | 346 | pendbaser = update_64bit_reg(pendbaser, addr & 4, len, val); |
347 | pendbaser = vgic_sanitise_pendbaser(pendbaser); | ||
348 | } while (cmpxchg64(&vgic_cpu->pendbaser, old_pendbaser, | ||
349 | pendbaser) != old_pendbaser); | ||
344 | } | 350 | } |
345 | 351 | ||
346 | /* | 352 | /* |