Skip to content

Commit 229725a

Browse files
committed
KVM: SVM: Clean up preemption toggling related to MSR_AMD64_TSC_RATIO
Explicitly disable preemption when writing MSR_AMD64_TSC_RATIO only in the "outer" helper, as all direct callers of the "inner" helper now run with preemption already disabled. And that isn't a coincidence, as the outer helper requires a vCPU and is intended to be used when modifying guest state and/or emulating guest instructions, which are typically done with preemption enabled. Direct use of the inner helper should be extremely limited, as the only time KVM should modify MSR_AMD64_TSC_RATIO without a vCPU is when sanitizing the MSR for a specific pCPU (currently done when {en,dis}abling disabling SVM). The other direct caller is svm_prepare_switch_to_guest(), which does have a vCPU, but is a one-off special case: KVM is about to enter the guest on a specific pCPU and thus must have preemption disabled. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent c0dc39b commit 229725a

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

arch/x86/kvm/svm/svm.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -569,15 +569,11 @@ static int svm_check_processor_compat(void)
569569

570570
static void __svm_write_tsc_multiplier(u64 multiplier)
571571
{
572-
preempt_disable();
573-
574572
if (multiplier == __this_cpu_read(current_tsc_ratio))
575-
goto out;
573+
return;
576574

577575
wrmsrl(MSR_AMD64_TSC_RATIO, multiplier);
578576
__this_cpu_write(current_tsc_ratio, multiplier);
579-
out:
580-
preempt_enable();
581577
}
582578

583579
static inline void kvm_cpu_svm_disable(void)
@@ -1152,7 +1148,9 @@ static void svm_write_tsc_offset(struct kvm_vcpu *vcpu, u64 offset)
11521148

11531149
void svm_write_tsc_multiplier(struct kvm_vcpu *vcpu, u64 multiplier)
11541150
{
1151+
preempt_disable();
11551152
__svm_write_tsc_multiplier(multiplier);
1153+
preempt_enable();
11561154
}
11571155

11581156
/* Evaluate instruction intercepts that depend on guest CPUID features. */

0 commit comments

Comments
 (0)