Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d9ae449b authored by Christoffer Dall's avatar Christoffer Dall
Browse files

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
Loading
Loading
Loading
Loading
+16 −10
Original line number Original line Diff line number Diff line
@@ -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;


	do {
		old_propbaser = dist->propbaser;
		propbaser = old_propbaser;
		propbaser = update_64bit_reg(propbaser, addr & 4, len, val);
		propbaser = update_64bit_reg(propbaser, addr & 4, len, val);
		propbaser = vgic_sanitise_propbaser(propbaser);
		propbaser = vgic_sanitise_propbaser(propbaser);

	} while (cmpxchg64(&dist->propbaser, old_propbaser,
	dist->propbaser = 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,
				     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;


	do {
		old_pendbaser = vgic_cpu->pendbaser;
		pendbaser = old_pendbaser;
		pendbaser = update_64bit_reg(pendbaser, addr & 4, len, val);
		pendbaser = update_64bit_reg(pendbaser, addr & 4, len, val);
		pendbaser = vgic_sanitise_pendbaser(pendbaser);
		pendbaser = vgic_sanitise_pendbaser(pendbaser);

	} while (cmpxchg64(&vgic_cpu->pendbaser, old_pendbaser,
	vgic_cpu->pendbaser = pendbaser;
			   pendbaser) != old_pendbaser);
}
}


/*
/*