A little trace_kvm_exit improvement
cover A little trace_kvm_exit improvement
Record the ISA (vmx or svm) and the exit qualification in trace_kvm_exit.
Avi Kivity (2):
KVM: Record instruction set in kvm_exit tracepoint
KVM: Add instruction-set-specific exit qualifications to kvm_exit
trace
arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm.c | 12 +++++++++++- arch/x86/kvm/trace.h | 17 +++++++++++++---- arch/x86/kvm/vmx.c | 10 +++++++++- 4 files changed, 34 insertions(+), 6 deletions(-)
PATCH 1/2 KVM: Record instruction set in kvm_exit tracepoint
exit_reason's meaning depend on the instruction set; record it so a trace taken on one machine can be interpreted on another.
--- arch/x86/kvm/svm.c | 2 +- arch/x86/kvm/trace.h | 9 +++++++-- arch/x86/kvm/vmx.c | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-)
arch/x86/kvm/svm.c +1 -1
@@ -2980,7 +2980,7 @@ static int handle_exit(struct kvm_vcpu *vcpu)struct kvm_run *kvm_run = vcpu->run;u32 exit_code = svm->vmcb->control.exit_code; -trace_kvm_exit (exit_code, vcpu); +trace_kvm_exit (exit_code, vcpu,KVM_ISA_SVM );if (!(svm->vmcb->control.intercept_cr_write &INTERCEPT_CR0_MASK )) vcpu->arch.cr0 = svm->vmcb->save.cr0;
arch/x86/kvm/trace.h +7 -2
@@ -178,21 +178,26 @@ TRACE_EVENT(kvm_apic,#define trace_kvm_apic_read (reg, val) trace_kvm_apic(0, reg, val)#define trace_kvm_apic_write (reg, val) trace_kvm_apic(1, reg, val) +#define KVM_ISA_VMX 1 +#define KVM_ISA_SVM 2 +/* * Tracepoint for kvm guest exit: */ TRACE_EVENT(kvm_exit, - TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu), - TP_ARGS(exit_reason, vcpu), + TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa), + TP_ARGS(exit_reason, vcpu, isa), TP_STRUCT__entry( __field( unsigned int, exit_reason ) __field( unsigned long, guest_rip ) + __field( u32, isa ) ), TP_fast_assign( __entry->exit_reason = exit_reason; __entry->guest_rip = kvm_rip_read(vcpu); + __entry->isa = isa; ), TP_printk("reason %s rip 0x%lx",
arch/x86/kvm/vmx.c +1 -1
@@ -3700,7 +3700,7 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)u32 exit_reason = vmx->exit_reason;u32 vectoring_info = vmx->idt_vectoring_info; -trace_kvm_exit (exit_reason, vcpu); +trace_kvm_exit (exit_reason, vcpu,KVM_ISA_VMX );/* If guest state is invalid, start emulating */ if (vmx->emulation_required && emulate_invalid_guest_state)
Signature · 1 line
1.7.1
PATCH 2/2 KVM: Add instruction-set-specific exit qualifications to kvm_exit trace
In reply to Avi KivityThe exit reason alone is insufficient to understand exactly why an exit occured; add ISA-specific trace parameters for additional information.
Because fetching these parameters is expensive on vmx, and because these parameters are fetched even if tracing is disabled, we fetch the parameters via a callback instead of as traditional trace arguments.
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/svm.c | 10 ++++++++++ arch/x86/kvm/trace.h | 8 ++++++-- arch/x86/kvm/vmx.c | 8 ++++++++ 4 files changed, 25 insertions(+), 2 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -594,6 +594,7 @@ struct kvm_x86_ops {void (*write_tsc_offset)(struct kvm_vcpu *vcpu,u64 offset); +void (*get_exit_info)(struct kvm_vcpu *vcpu,u64 * info1,u64 * info2);const struct trace_print_flags *exit_reasons_str; };
arch/x86/kvm/svm.c +10 -0
@@ -2974,6 +2974,14 @@ void dump_vmcb(struct kvm_vcpu *vcpu) } +static void svm_get_exit_info (struct kvm_vcpu *vcpu,u64 *info1,u64 *info2) +{ +struct vmcb_control_area *control = &to_svm (vcpu)->vmcb->control; + + *info1 = control->exit_info_1; + *info2 = control->exit_info_2; +} +static int handle_exit (struct kvm_vcpu *vcpu) {struct vcpu_svm *svm =to_svm (vcpu);
@@ -3678,7 +3686,9 @@ static struct kvm_x86_ops svm_x86_ops = { .get_tdp_level = get_npt_level, .get_mt_mask = svm_get_mt_mask, + .get_exit_info = svm_get_exit_info, .exit_reasons_str = svm_exit_reasons_str, + .get_lpage_level = svm_get_lpage_level, .cpuid_update = svm_cpuid_update,
arch/x86/kvm/trace.h +6 -2
@@ -192,18 +192,22 @@ TRACE_EVENT(kvm_exit, __field( unsigned int, exit_reason ) __field( unsigned long, guest_rip ) __field( u32, isa ) + __field( u64, info1 ) + __field( u64, info2 ) ),TP_fast_assign ( __entry->exit_reason = exit_reason; __entry->guest_rip =kvm_rip_read (vcpu); __entry->isa = isa; + kvm_x86_ops->get_exit_info (vcpu, &__entry->info1, + &__entry->info2); ), -TP_printk ("reason %s rip 0x%lx" , +TP_printk ("reason %s rip 0x%lx info %llx %llx" ,ftrace_print_symbols_seq (p, __entry->exit_reason, kvm_x86_ops->exit_reasons_str), - __entry->guest_rip) + __entry->guest_rip, __entry->info1, __entry->info2) );/*
arch/x86/kvm/vmx.c +8 -0
@@ -3690,6 +3690,12 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {static const int kvm_vmx_max_exit_handlers =ARRAY_SIZE (kvm_vmx_exit_handlers); +static void vmx_get_exit_info (struct kvm_vcpu *vcpu,u64 *info1,u64 *info2) +{ + *info1 =vmcs_readl (EXIT_QUALIFICATION ); + *info2 =vmcs_read32 (VM_EXIT_INTR_INFO ); +} +/* * The guest has exited. See if we can fix it or if we need userspace * assistance.
@@ -4352,7 +4358,9 @@ static struct kvm_x86_ops vmx_x86_ops = { .get_tdp_level = get_ept_level, .get_mt_mask = vmx_get_mt_mask, + .get_exit_info = vmx_get_exit_info, .exit_reasons_str = vmx_exit_reasons_str, + .get_lpage_level = vmx_get_lpage_level, .cpuid_update = vmx_cpuid_update,
Signature · 1 line
1.7.1