Commit d204feb2946a5b9f9a73c1d20c25a3930dc56fcd
Committed by
Greg Kroah-Hartman
1 parent
f21d9d4448
KVM: x86: update masterclock values on TSC writes
commit 7f187922ddf6b67f2999a76dcb71663097b75497 upstream. When the guest writes to the TSC, the masterclock TSC copy must be updated as well along with the TSC_OFFSET update, otherwise a negative tsc_timestamp is calculated at kvm_guest_time_update. Once "if (!vcpus_matched && ka->use_master_clock)" is simplified to "if (ka->use_master_clock)", the corresponding "if (!ka->use_master_clock)" becomes redundant, so remove the do_request boolean and collapse everything into a single condition. Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Showing 1 changed file with 10 additions and 9 deletions Side-by-side Diff
arch/x86/kvm/x86.c
... | ... | @@ -1237,21 +1237,22 @@ |
1237 | 1237 | { |
1238 | 1238 | #ifdef CONFIG_X86_64 |
1239 | 1239 | bool vcpus_matched; |
1240 | - bool do_request = false; | |
1241 | 1240 | struct kvm_arch *ka = &vcpu->kvm->arch; |
1242 | 1241 | struct pvclock_gtod_data *gtod = &pvclock_gtod_data; |
1243 | 1242 | |
1244 | 1243 | vcpus_matched = (ka->nr_vcpus_matched_tsc + 1 == |
1245 | 1244 | atomic_read(&vcpu->kvm->online_vcpus)); |
1246 | 1245 | |
1247 | - if (vcpus_matched && gtod->clock.vclock_mode == VCLOCK_TSC) | |
1248 | - if (!ka->use_master_clock) | |
1249 | - do_request = 1; | |
1250 | - | |
1251 | - if (!vcpus_matched && ka->use_master_clock) | |
1252 | - do_request = 1; | |
1253 | - | |
1254 | - if (do_request) | |
1246 | + /* | |
1247 | + * Once the masterclock is enabled, always perform request in | |
1248 | + * order to update it. | |
1249 | + * | |
1250 | + * In order to enable masterclock, the host clocksource must be TSC | |
1251 | + * and the vcpus need to have matched TSCs. When that happens, | |
1252 | + * perform request to enable masterclock. | |
1253 | + */ | |
1254 | + if (ka->use_master_clock || | |
1255 | + (gtod->clock.vclock_mode == VCLOCK_TSC && vcpus_matched)) | |
1255 | 1256 | kvm_make_request(KVM_REQ_MASTERCLOCK_UPDATE, vcpu); |
1256 | 1257 | |
1257 | 1258 | trace_kvm_track_tsc(vcpu->vcpu_id, ka->nr_vcpus_matched_tsc, |