On Sun, Mar 27, 2011 at 12:57:03PM +0200, Avi Kivity wrote: > On 03/25/2011 10:44 AM, Joerg Roedel wrote: >> The calculation of the tsc_delta value to ensure a >> forward-going tsc for the guest is a function of the >> host-tsc. This works as long as the guests tsc_khz is equal >> to the hosts tsc_khz. With tsc-scaling hardware support this >> is not longer true and the tsc_delta needs to be calculated >> >> --- a/arch/x86/kvm/x86.c >> +++ b/arch/x86/kvm/x86.c >> @@ -2126,8 +2126,13 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) >> kvm_x86_ops->vcpu_load(vcpu, cpu); >> if (unlikely(vcpu->cpu != cpu) || check_tsc_unstable()) { >> /* Make sure TSC doesn't go backwards */ >> - s64 tsc_delta = !vcpu->arch.last_host_tsc ? 0 : >> - native_read_tsc() - vcpu->arch.last_host_tsc; >> + s64 tsc_delta; >> + u64 tsc; >> + >> + kvm_get_msr(vcpu, MSR_IA32_TSC,&tsc); >> + tsc_delta = !vcpu->arch.last_guest_tsc ? 0 : >> + tsc - vcpu->arch.last_guest_tsc; >> + >> if (tsc_delta< 0) >> mark_tsc_unstable("KVM discovered backwards TSC"); >> if (check_tsc_unstable()) { > > > Patch is correct, but can this really happen? Won't all machines with > scaled tsc also be stable? > > Perhaps not multi-board machines. Yes, all machines with tsc-scaling should also have a stable tsc, so this patch is not strictly required. I added this patch as a response to Zachary's thoughts about the values that need to be passed to adjust_tsc_offset. Zachary mentioned that with this patch-series the adjust_tsc_offset function will either take the adjustment in guest-tsc or host-tsc units (which is not problematic if guest and host tsc have the same frequency). But with tsc-scaling (and Zachary's upcoming patches) this might become a problem. So I changed the semantic of adjust_tsc_offset to always take the adjustment in guest-tsc units. This patch-set converts the one and only call-site of adjust_tsc_offset where the unit is calculated as a function of the host-tsc. Joerg -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html