Skip to content

Commit d95df95

Browse files
Lorenzo Bresciabonzini
authored andcommitted
kvm: tracing: Fix unmatched kvm_entry and kvm_exit events
On VMX, if we exit and then re-enter immediately without leaving the vmx_vcpu_run() function, the kvm_entry event is not logged. That means we will see one (or more) kvm_exit, without its (their) corresponding kvm_entry, as shown here: CPU-1979 [002] 89.871187: kvm_entry: vcpu 1 CPU-1979 [002] 89.871218: kvm_exit: reason MSR_WRITE CPU-1979 [002] 89.871259: kvm_exit: reason MSR_WRITE It also seems possible for a kvm_entry event to be logged, but then we leave vmx_vcpu_run() right away (if vmx->emulation_required is true). In this case, we will have a spurious kvm_entry event in the trace. Fix these situations by moving trace_kvm_entry() inside vmx_vcpu_run() (where trace_kvm_exit() already is). A trace obtained with this patch applied looks like this: CPU-14295 [000] 8388.395387: kvm_entry: vcpu 0 CPU-14295 [000] 8388.395392: kvm_exit: reason MSR_WRITE CPU-14295 [000] 8388.395393: kvm_entry: vcpu 0 CPU-14295 [000] 8388.395503: kvm_exit: reason EXTERNAL_INTERRUPT Of course, not calling trace_kvm_entry() in common x86 code any longer means that we need to adjust the SVM side of things too. Signed-off-by: Lorenzo Brescia <lorenzo.brescia@edu.unito.it> Signed-off-by: Dario Faggioli <dfaggioli@suse.com> Message-Id: <160873470698.11652.13483635328769030605.stgit@Wayrath> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 01ead84 commit d95df95

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

arch/x86/kvm/svm/svm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3739,6 +3739,8 @@ static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu)
37393739
{
37403740
struct vcpu_svm *svm = to_svm(vcpu);
37413741

3742+
trace_kvm_entry(vcpu);
3743+
37423744
svm->vmcb->save.rax = vcpu->arch.regs[VCPU_REGS_RAX];
37433745
svm->vmcb->save.rsp = vcpu->arch.regs[VCPU_REGS_RSP];
37443746
svm->vmcb->save.rip = vcpu->arch.regs[VCPU_REGS_RIP];

arch/x86/kvm/vmx/vmx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6653,6 +6653,8 @@ static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu)
66536653
if (vmx->emulation_required)
66546654
return EXIT_FASTPATH_NONE;
66556655

6656+
trace_kvm_entry(vcpu);
6657+
66566658
if (vmx->ple_window_dirty) {
66576659
vmx->ple_window_dirty = false;
66586660
vmcs_write32(PLE_WINDOW, vmx->ple_window);

arch/x86/kvm/x86.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8992,8 +8992,6 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
89928992
kvm_x86_ops.request_immediate_exit(vcpu);
89938993
}
89948994

8995-
trace_kvm_entry(vcpu);
8996-
89978995
fpregs_assert_state_consistent();
89988996
if (test_thread_flag(TIF_NEED_FPU_LOAD))
89998997
switch_fpu_return();
@@ -11560,6 +11558,7 @@ int kvm_sev_es_string_io(struct kvm_vcpu *vcpu, unsigned int size,
1156011558
}
1156111559
EXPORT_SYMBOL_GPL(kvm_sev_es_string_io);
1156211560

11561+
EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_entry);
1156311562
EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_exit);
1156411563
EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_fast_mmio);
1156511564
EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_inj_virq);

0 commit comments

Comments
 (0)