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

Commit 03ba32ca authored by Marcelo Tosatti's avatar Marcelo Tosatti Committed by Gleb Natapov
Browse files

VMX: x86: handle host TSC calibration failure

If the host TSC calibration fails, tsc_khz is zero (see tsc_init.c).
Handle such case properly in KVM (instead of dividing by zero).

https://bugzilla.redhat.com/show_bug.cgi?id=859282



Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: default avatarGleb Natapov <gleb@redhat.com>
parent 0fa24ce3
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -1079,6 +1079,10 @@ static void kvm_set_tsc_khz(struct kvm_vcpu *vcpu, u32 this_tsc_khz)
	u32 thresh_lo, thresh_hi;
	int use_scaling = 0;

	/* tsc_khz can be zero if TSC calibration fails */
	if (this_tsc_khz == 0)
		return;

	/* Compute a scale to convert nanoseconds in TSC cycles */
	kvm_get_time_scale(this_tsc_khz, NSEC_PER_SEC / 1000,
			   &vcpu->arch.virtual_tsc_shift,
@@ -1156,6 +1160,7 @@ void kvm_write_tsc(struct kvm_vcpu *vcpu, struct msr_data *msr)
	ns = get_kernel_ns();
	elapsed = ns - kvm->arch.last_tsc_nsec;

	if (vcpu->arch.virtual_tsc_khz) {
		/* n.b - signed multiplication and division required */
		usdiff = data - kvm->arch.last_tsc_write;
#ifdef CONFIG_X86_64
@@ -1170,6 +1175,8 @@ void kvm_write_tsc(struct kvm_vcpu *vcpu, struct msr_data *msr)
		usdiff -= elapsed;
		if (usdiff < 0)
			usdiff = -usdiff;
	} else
		usdiff = USEC_PER_SEC; /* disable TSC match window below */

	/*
	 * Special case: TSC write with a small delta (1 second) of virtual