Skip to content

Commit 7f18792

Browse files
matosattibonzini
authored andcommitted
KVM: x86: update masterclock values on TSC writes
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 <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent b2c9d43 commit 7f18792

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

arch/x86/kvm/x86.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,21 +1235,22 @@ void kvm_track_tsc_matching(struct kvm_vcpu *vcpu)
12351235
{
12361236
#ifdef CONFIG_X86_64
12371237
bool vcpus_matched;
1238-
bool do_request = false;
12391238
struct kvm_arch *ka = &vcpu->kvm->arch;
12401239
struct pvclock_gtod_data *gtod = &pvclock_gtod_data;
12411240

12421241
vcpus_matched = (ka->nr_vcpus_matched_tsc + 1 ==
12431242
atomic_read(&vcpu->kvm->online_vcpus));
12441243

1245-
if (vcpus_matched && gtod->clock.vclock_mode == VCLOCK_TSC)
1246-
if (!ka->use_master_clock)
1247-
do_request = 1;
1248-
1249-
if (!vcpus_matched && ka->use_master_clock)
1250-
do_request = 1;
1251-
1252-
if (do_request)
1244+
/*
1245+
* Once the masterclock is enabled, always perform request in
1246+
* order to update it.
1247+
*
1248+
* In order to enable masterclock, the host clocksource must be TSC
1249+
* and the vcpus need to have matched TSCs. When that happens,
1250+
* perform request to enable masterclock.
1251+
*/
1252+
if (ka->use_master_clock ||
1253+
(gtod->clock.vclock_mode == VCLOCK_TSC && vcpus_matched))
12531254
kvm_make_request(KVM_REQ_MASTERCLOCK_UPDATE, vcpu);
12541255

12551256
trace_kvm_track_tsc(vcpu->vcpu_id, ka->nr_vcpus_matched_tsc,

0 commit comments

Comments
 (0)