lkml.org 
[lkml]   [2020]   [Dec]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE
Date
On Thu, Dec 03 2020 at 19:11, Maxim Levitsky wrote:
> + case KVM_SET_TSC_STATE: {
> + struct kvm_tsc_state __user *user_tsc_state = argp;
> + struct kvm_tsc_state tsc_state;
> + u64 host_tsc, wall_nsec;
> +
> + u64 new_guest_tsc, new_guest_tsc_offset;
> +
> + r = -EFAULT;
> + if (copy_from_user(&tsc_state, user_tsc_state, sizeof(tsc_state)))
> + goto out;
> +
> + kvm_get_walltime(&wall_nsec, &host_tsc);
> + new_guest_tsc = tsc_state.tsc;
> +
> + if (tsc_state.flags & KVM_TSC_STATE_TIMESTAMP_VALID) {
> + s64 diff = wall_nsec - tsc_state.nsec;
> + if (diff >= 0)
> + new_guest_tsc += nsec_to_cycles(vcpu, diff);
> + else
> + new_guest_tsc -= nsec_to_cycles(vcpu, -diff);
> + }
> +
> + new_guest_tsc_offset = new_guest_tsc - kvm_scale_tsc(vcpu, host_tsc);
> + kvm_vcpu_write_tsc_offset(vcpu, new_guest_tsc_offset);

From a timekeeping POV and the guests expectation of TSC this is
fundamentally wrong:

tscguest = scaled(hosttsc) + offset

The TSC has to be viewed systemwide and not per CPU. It's systemwide
used for timekeeping and for that to work it has to be synchronized.

Why would this be different on virt? Just because it's virt or what?

Migration is a guest wide thing and you're not migrating single vCPUs.

This hackery just papers over he underlying design fail that KVM looks
at the TSC per vCPU which is the root cause and that needs to be fixed.

Thanks,

tglx

\
 
 \ /
  Last update: 2020-12-06 17:21    [W:0.220 / U:2.956 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site