Skip to content

Commit 0a94b20

Browse files
committed
KVM: x86: Unconditionally handle MSR_IA32_TSC_DEADLINE in fastpath exits
Drop the fastpath VM-Exit requirement that KVM can use the hypervisor timer to emulate the APIC timer in TSC deadline mode. I.e. unconditionally handle MSR_IA32_TSC_DEADLINE WRMSRs in the fastpath. Restricting the fastpath to *maybe* using the VMX preemption timer is ineffective and unnecessary. If the requested deadline can't be programmed into the VMX preemption timer, KVM will fall back to hrtimers, i.e. the restriction is ineffective as far as preventing any kind of worst case scenario. But guarding against a worst case scenario is completely unnecessary as the "slow" path, start_sw_tscdeadline() => hrtimer_start(), explicitly disables IRQs. In fact, the worst case scenario is when KVM thinks it can use the VMX preemption timer, as KVM will eat the overhead of calling into vmx_set_hv_timer() and falling back to hrtimers. Opportunistically limit kvm_can_use_hv_timer() to lapic.c as the fastpath code was the only external user. Stating the obvious, this allows handling MSR_IA32_TSC_DEADLINE writes in the fastpath on AMD CPUs. Link: https://lore.kernel.org/r/20250805190526.1453366-6-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent aeeb4c7 commit 0a94b20

3 files changed

Lines changed: 1 addition & 5 deletions

File tree

arch/x86/kvm/lapic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static bool kvm_can_post_timer_interrupt(struct kvm_vcpu *vcpu)
130130
(kvm_mwait_in_guest(vcpu->kvm) || kvm_hlt_in_guest(vcpu->kvm));
131131
}
132132

133-
bool kvm_can_use_hv_timer(struct kvm_vcpu *vcpu)
133+
static bool kvm_can_use_hv_timer(struct kvm_vcpu *vcpu)
134134
{
135135
return kvm_x86_ops.set_hv_timer
136136
&& !(kvm_mwait_in_guest(vcpu->kvm) ||

arch/x86/kvm/lapic.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ void kvm_lapic_switch_to_hv_timer(struct kvm_vcpu *vcpu);
249249
void kvm_lapic_expired_hv_timer(struct kvm_vcpu *vcpu);
250250
bool kvm_lapic_hv_timer_in_use(struct kvm_vcpu *vcpu);
251251
void kvm_lapic_restart_hv_timer(struct kvm_vcpu *vcpu);
252-
bool kvm_can_use_hv_timer(struct kvm_vcpu *vcpu);
253252

254253
static inline enum lapic_mode kvm_apic_mode(u64 apic_base)
255254
{

arch/x86/kvm/x86.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,9 +2151,6 @@ static int handle_fastpath_set_x2apic_icr_irqoff(struct kvm_vcpu *vcpu, u64 data
21512151

21522152
static int handle_fastpath_set_tscdeadline(struct kvm_vcpu *vcpu, u64 data)
21532153
{
2154-
if (!kvm_can_use_hv_timer(vcpu))
2155-
return 1;
2156-
21572154
kvm_set_lapic_tscdeadline_msr(vcpu, data);
21582155
return 0;
21592156
}

0 commit comments

Comments
 (0)