Skip to content

Commit 9c9025e

Browse files
committed
KVM: x86: Plumb "force_immediate_exit" into kvm_entry() tracepoint
Annotate the kvm_entry() tracepoint with "immediate exit" when KVM is forcing a VM-Exit immediately after VM-Enter, e.g. when KVM wants to inject an event but needs to first complete some other operation. Knowing that KVM is (or isn't) forcing an exit is useful information when debugging issues related to event injection. Suggested-by: Maxim Levitsky <mlevitsk@redhat.com> Link: https://lore.kernel.org/r/20240110012705.506918-2-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 2a5f091 commit 9c9025e

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,8 @@ struct kvm_x86_ops {
16631663
void (*flush_tlb_guest)(struct kvm_vcpu *vcpu);
16641664

16651665
int (*vcpu_pre_run)(struct kvm_vcpu *vcpu);
1666-
enum exit_fastpath_completion (*vcpu_run)(struct kvm_vcpu *vcpu);
1666+
enum exit_fastpath_completion (*vcpu_run)(struct kvm_vcpu *vcpu,
1667+
bool force_immediate_exit);
16671668
int (*handle_exit)(struct kvm_vcpu *vcpu,
16681669
enum exit_fastpath_completion exit_fastpath);
16691670
int (*skip_emulated_instruction)(struct kvm_vcpu *vcpu);

arch/x86/kvm/svm/svm.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4112,12 +4112,13 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu, bool spec_ctrl_in
41124112
guest_state_exit_irqoff();
41134113
}
41144114

4115-
static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu)
4115+
static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu,
4116+
bool force_immediate_exit)
41164117
{
41174118
struct vcpu_svm *svm = to_svm(vcpu);
41184119
bool spec_ctrl_intercepted = msr_write_intercepted(vcpu, MSR_IA32_SPEC_CTRL);
41194120

4120-
trace_kvm_entry(vcpu);
4121+
trace_kvm_entry(vcpu, force_immediate_exit);
41214122

41224123
svm->vmcb->save.rax = vcpu->arch.regs[VCPU_REGS_RAX];
41234124
svm->vmcb->save.rsp = vcpu->arch.regs[VCPU_REGS_RSP];

arch/x86/kvm/trace.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@
1515
* Tracepoint for guest mode entry.
1616
*/
1717
TRACE_EVENT(kvm_entry,
18-
TP_PROTO(struct kvm_vcpu *vcpu),
19-
TP_ARGS(vcpu),
18+
TP_PROTO(struct kvm_vcpu *vcpu, bool force_immediate_exit),
19+
TP_ARGS(vcpu, force_immediate_exit),
2020

2121
TP_STRUCT__entry(
2222
__field( unsigned int, vcpu_id )
2323
__field( unsigned long, rip )
24+
__field( bool, immediate_exit )
2425
),
2526

2627
TP_fast_assign(
2728
__entry->vcpu_id = vcpu->vcpu_id;
2829
__entry->rip = kvm_rip_read(vcpu);
30+
__entry->immediate_exit = force_immediate_exit;
2931
),
3032

31-
TP_printk("vcpu %u, rip 0x%lx", __entry->vcpu_id, __entry->rip)
33+
TP_printk("vcpu %u, rip 0x%lx%s", __entry->vcpu_id, __entry->rip,
34+
__entry->immediate_exit ? "[immediate exit]" : "")
3235
);
3336

3437
/*

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7265,7 +7265,7 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vcpu *vcpu,
72657265
guest_state_exit_irqoff();
72667266
}
72677267

7268-
static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu)
7268+
static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate_exit)
72697269
{
72707270
struct vcpu_vmx *vmx = to_vmx(vcpu);
72717271
unsigned long cr3, cr4;
@@ -7292,7 +7292,7 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu)
72927292
return EXIT_FASTPATH_NONE;
72937293
}
72947294

7295-
trace_kvm_entry(vcpu);
7295+
trace_kvm_entry(vcpu, force_immediate_exit);
72967296

72977297
if (vmx->ple_window_dirty) {
72987298
vmx->ple_window_dirty = false;

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10956,7 +10956,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
1095610956
WARN_ON_ONCE((kvm_vcpu_apicv_activated(vcpu) != kvm_vcpu_apicv_active(vcpu)) &&
1095710957
(kvm_get_apic_mode(vcpu) != LAPIC_MODE_DISABLED));
1095810958

10959-
exit_fastpath = static_call(kvm_x86_vcpu_run)(vcpu);
10959+
exit_fastpath = static_call(kvm_x86_vcpu_run)(vcpu, req_immediate_exit);
1096010960
if (likely(exit_fastpath != EXIT_FASTPATH_REENTER_GUEST))
1096110961
break;
1096210962

0 commit comments

Comments
 (0)