2020-07-18 06:41:35

by Sean Christopherson

[permalink] [raw]
Subject: [PATCH 0/7] KVM: x86: Tracepoint improvements and fixes

Various improvements and fixes for the kvm_entry, kvm_exit and
kvm_nested_vmexit tracepoints.

1. Capture the guest's RIP during kvm_entry for obvious reasons.

2. Extend kvm_exit to report the same info as kvm_nested_vmexit, and
macrofy its definition to reuse it verbatim for nested exits.

3. Stop passing in params to kvm_nested_vmexit, and instead use the
same approach (and now code) as kvm_exit where the tracepoint uses a
dedicated kvm_x86_ops hook to retrieve the info.

4. Stop reading GUEST_RIP, EXIT_QUAL, INTR_INFO, and ERROR_CODE on
every VM-Exit from L2 (some of this comes in #3). This saves ~100
cycles (150+ with retpolines) on VM-Exits from L2 that are handled
by L0, e.g. hardware interrupts.

Sean Christopherson (7):
KVM: x86: Add RIP to the kvm_entry, i.e. VM-Enter, tracepoint
KVM: x86: Read guest RIP from within the kvm_nested_vmexit tracepoint
KVM: VMX: Add a helper to test for a valid error code given an intr
info
KVM: x86: Add intr/vectoring info and error code to kvm_exit
tracepoint
KVM: x86: Add macro wrapper for defining kvm_exit tracepoint
KVM: x86: Use common definition for kvm_nested_vmexit tracepoint
KVM: nVMX: Read EXIT_QUAL and INTR_INFO only when needed for nested
exit

arch/x86/include/asm/kvm_host.h | 7 ++-
arch/x86/kvm/svm/svm.c | 16 ++---
arch/x86/kvm/trace.h | 107 +++++++++++++-------------------
arch/x86/kvm/vmx/nested.c | 14 ++---
arch/x86/kvm/vmx/vmcs.h | 7 +++
arch/x86/kvm/vmx/vmx.c | 18 +++++-
arch/x86/kvm/x86.c | 2 +-
7 files changed, 86 insertions(+), 85 deletions(-)

--
2.26.0


2020-07-18 06:41:37

by Sean Christopherson

[permalink] [raw]
Subject: [PATCH 1/7] KVM: x86: Add RIP to the kvm_entry, i.e. VM-Enter, tracepoint

Add RIP to the kvm_entry tracepoint to help debug if the kvm_exit
tracepoint is disable or if VM-Enter fails, in which case the kvm_exit
tracepoint won't be hit.

Read RIP from within the tracepoint itself to avoid a potential VMREAD
and retpoline if the guest's RIP isn't available.

Signed-off-by: Sean Christopherson <[email protected]>
---
arch/x86/kvm/trace.h | 10 ++++++----
arch/x86/kvm/x86.c | 2 +-
2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
index b66432b015d2e..9899ff0fa2534 100644
--- a/arch/x86/kvm/trace.h
+++ b/arch/x86/kvm/trace.h
@@ -15,18 +15,20 @@
* Tracepoint for guest mode entry.
*/
TRACE_EVENT(kvm_entry,
- TP_PROTO(unsigned int vcpu_id),
- TP_ARGS(vcpu_id),
+ TP_PROTO(struct kvm_vcpu *vcpu),
+ TP_ARGS(vcpu),

TP_STRUCT__entry(
__field( unsigned int, vcpu_id )
+ __field( unsigned long, rip )
),

TP_fast_assign(
- __entry->vcpu_id = vcpu_id;
+ __entry->vcpu_id = vcpu->vcpu_id;
+ __entry->rip = kvm_rip_read(vcpu);
),

- TP_printk("vcpu %u", __entry->vcpu_id)
+ TP_printk("vcpu %u, rip 0x%lx", __entry->vcpu_id, __entry->rip)
);

/*
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 5f526d94c33f3..3563359316d64 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8547,7 +8547,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
kvm_x86_ops.request_immediate_exit(vcpu);
}

- trace_kvm_entry(vcpu->vcpu_id);
+ trace_kvm_entry(vcpu);

fpregs_assert_state_consistent();
if (test_thread_flag(TIF_NEED_FPU_LOAD))
--
2.26.0