Skip to content

Commit 5f3b30b

Browse files
yamahatabonzini
authored andcommitted
KVM: x86: Push down setting vcpu.arch.user_set_tsc
Push down setting vcpu.arch.user_set_tsc to true from kvm_synchronize_tsc() to __kvm_synchronize_tsc() so that the two callers don't have to modify user_set_tsc directly as preparation. Later, prohibit changing TSC synchronization for TDX guests to modify __kvm_synchornize_tsc() change. We don't want to touch caller sites not to change user_set_tsc. Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com> Message-ID: <62b1a7a35d6961844786b6e47e8ecb774af7a228.1728719037.git.isaku.yamahata@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 46c4937 commit 5f3b30b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

arch/x86/kvm/x86.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,12 +2626,15 @@ static inline bool kvm_check_tsc_unstable(void)
26262626
* participates in.
26272627
*/
26282628
static void __kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 offset, u64 tsc,
2629-
u64 ns, bool matched)
2629+
u64 ns, bool matched, bool user_set_tsc)
26302630
{
26312631
struct kvm *kvm = vcpu->kvm;
26322632

26332633
lockdep_assert_held(&kvm->arch.tsc_write_lock);
26342634

2635+
if (user_set_tsc)
2636+
vcpu->kvm->arch.user_set_tsc = true;
2637+
26352638
/*
26362639
* We also track th most recent recorded KHZ, write and time to
26372640
* allow the matching interval to be extended at each write.
@@ -2717,8 +2720,6 @@ static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 *user_value)
27172720
}
27182721
}
27192722

2720-
if (user_value)
2721-
kvm->arch.user_set_tsc = true;
27222723

27232724
/*
27242725
* For a reliable TSC, we can match TSC offsets, and for an unstable
@@ -2738,7 +2739,7 @@ static void kvm_synchronize_tsc(struct kvm_vcpu *vcpu, u64 *user_value)
27382739
matched = true;
27392740
}
27402741

2741-
__kvm_synchronize_tsc(vcpu, offset, data, ns, matched);
2742+
__kvm_synchronize_tsc(vcpu, offset, data, ns, matched, !!user_value);
27422743
raw_spin_unlock_irqrestore(&kvm->arch.tsc_write_lock, flags);
27432744
}
27442745

@@ -5725,8 +5726,7 @@ static int kvm_arch_tsc_set_attr(struct kvm_vcpu *vcpu,
57255726
tsc = kvm_scale_tsc(rdtsc(), vcpu->arch.l1_tsc_scaling_ratio) + offset;
57265727
ns = get_kvmclock_base_ns();
57275728

5728-
kvm->arch.user_set_tsc = true;
5729-
__kvm_synchronize_tsc(vcpu, offset, tsc, ns, matched);
5729+
__kvm_synchronize_tsc(vcpu, offset, tsc, ns, matched, true);
57305730
raw_spin_unlock_irqrestore(&kvm->arch.tsc_write_lock, flags);
57315731

57325732
r = 0;

0 commit comments

Comments
 (0)