KVM: SVM: count all irq windows exit
[linux-3.10.git] / arch / x86 / kvm / trace.h
index db93276..911d264 100644 (file)
@@ -2,6 +2,8 @@
 #define _TRACE_KVM_H
 
 #include <linux/tracepoint.h>
+#include <asm/vmx.h>
+#include <asm/svm.h>
 
 #undef TRACE_SYSTEM
 #define TRACE_SYSTEM kvm
@@ -181,6 +183,95 @@ TRACE_EVENT(kvm_apic,
 #define KVM_ISA_VMX   1
 #define KVM_ISA_SVM   2
 
+#define VMX_EXIT_REASONS \
+       { EXIT_REASON_EXCEPTION_NMI,            "EXCEPTION_NMI" }, \
+       { EXIT_REASON_EXTERNAL_INTERRUPT,       "EXTERNAL_INTERRUPT" }, \
+       { EXIT_REASON_TRIPLE_FAULT,             "TRIPLE_FAULT" }, \
+       { EXIT_REASON_PENDING_INTERRUPT,        "PENDING_INTERRUPT" }, \
+       { EXIT_REASON_NMI_WINDOW,               "NMI_WINDOW" }, \
+       { EXIT_REASON_TASK_SWITCH,              "TASK_SWITCH" }, \
+       { EXIT_REASON_CPUID,                    "CPUID" }, \
+       { EXIT_REASON_HLT,                      "HLT" }, \
+       { EXIT_REASON_INVLPG,                   "INVLPG" }, \
+       { EXIT_REASON_RDPMC,                    "RDPMC" }, \
+       { EXIT_REASON_RDTSC,                    "RDTSC" }, \
+       { EXIT_REASON_VMCALL,                   "VMCALL" }, \
+       { EXIT_REASON_VMCLEAR,                  "VMCLEAR" }, \
+       { EXIT_REASON_VMLAUNCH,                 "VMLAUNCH" }, \
+       { EXIT_REASON_VMPTRLD,                  "VMPTRLD" }, \
+       { EXIT_REASON_VMPTRST,                  "VMPTRST" }, \
+       { EXIT_REASON_VMREAD,                   "VMREAD" }, \
+       { EXIT_REASON_VMRESUME,                 "VMRESUME" }, \
+       { EXIT_REASON_VMWRITE,                  "VMWRITE" }, \
+       { EXIT_REASON_VMOFF,                    "VMOFF" }, \
+       { EXIT_REASON_VMON,                     "VMON" }, \
+       { EXIT_REASON_CR_ACCESS,                "CR_ACCESS" }, \
+       { EXIT_REASON_DR_ACCESS,                "DR_ACCESS" }, \
+       { EXIT_REASON_IO_INSTRUCTION,           "IO_INSTRUCTION" }, \
+       { EXIT_REASON_MSR_READ,                 "MSR_READ" }, \
+       { EXIT_REASON_MSR_WRITE,                "MSR_WRITE" }, \
+       { EXIT_REASON_MWAIT_INSTRUCTION,        "MWAIT_INSTRUCTION" }, \
+       { EXIT_REASON_MONITOR_INSTRUCTION,      "MONITOR_INSTRUCTION" }, \
+       { EXIT_REASON_PAUSE_INSTRUCTION,        "PAUSE_INSTRUCTION" }, \
+       { EXIT_REASON_MCE_DURING_VMENTRY,       "MCE_DURING_VMENTRY" }, \
+       { EXIT_REASON_TPR_BELOW_THRESHOLD,      "TPR_BELOW_THRESHOLD" },        \
+       { EXIT_REASON_APIC_ACCESS,              "APIC_ACCESS" }, \
+       { EXIT_REASON_EPT_VIOLATION,            "EPT_VIOLATION" }, \
+       { EXIT_REASON_EPT_MISCONFIG,            "EPT_MISCONFIG" }, \
+       { EXIT_REASON_WBINVD,                   "WBINVD" }
+
+#define SVM_EXIT_REASONS \
+       { SVM_EXIT_READ_CR0,                    "read_cr0" }, \
+       { SVM_EXIT_READ_CR3,                    "read_cr3" }, \
+       { SVM_EXIT_READ_CR4,                    "read_cr4" }, \
+       { SVM_EXIT_READ_CR8,                    "read_cr8" }, \
+       { SVM_EXIT_WRITE_CR0,                   "write_cr0" }, \
+       { SVM_EXIT_WRITE_CR3,                   "write_cr3" }, \
+       { SVM_EXIT_WRITE_CR4,                   "write_cr4" }, \
+       { SVM_EXIT_WRITE_CR8,                   "write_cr8" }, \
+       { SVM_EXIT_READ_DR0,                    "read_dr0" }, \
+       { SVM_EXIT_READ_DR1,                    "read_dr1" }, \
+       { SVM_EXIT_READ_DR2,                    "read_dr2" }, \
+       { SVM_EXIT_READ_DR3,                    "read_dr3" }, \
+       { SVM_EXIT_WRITE_DR0,                   "write_dr0" }, \
+       { SVM_EXIT_WRITE_DR1,                   "write_dr1" }, \
+       { SVM_EXIT_WRITE_DR2,                   "write_dr2" }, \
+       { SVM_EXIT_WRITE_DR3,                   "write_dr3" }, \
+       { SVM_EXIT_WRITE_DR5,                   "write_dr5" }, \
+       { SVM_EXIT_WRITE_DR7,                   "write_dr7" }, \
+       { SVM_EXIT_EXCP_BASE + DB_VECTOR,       "DB excp" }, \
+       { SVM_EXIT_EXCP_BASE + BP_VECTOR,       "BP excp" }, \
+       { SVM_EXIT_EXCP_BASE + UD_VECTOR,       "UD excp" }, \
+       { SVM_EXIT_EXCP_BASE + PF_VECTOR,       "PF excp" }, \
+       { SVM_EXIT_EXCP_BASE + NM_VECTOR,       "NM excp" }, \
+       { SVM_EXIT_EXCP_BASE + MC_VECTOR,       "MC excp" }, \
+       { SVM_EXIT_INTR,                        "interrupt" }, \
+       { SVM_EXIT_NMI,                         "nmi" }, \
+       { SVM_EXIT_SMI,                         "smi" }, \
+       { SVM_EXIT_INIT,                        "init" }, \
+       { SVM_EXIT_VINTR,                       "vintr" }, \
+       { SVM_EXIT_CPUID,                       "cpuid" }, \
+       { SVM_EXIT_INVD,                        "invd" }, \
+       { SVM_EXIT_HLT,                         "hlt" }, \
+       { SVM_EXIT_INVLPG,                      "invlpg" }, \
+       { SVM_EXIT_INVLPGA,                     "invlpga" }, \
+       { SVM_EXIT_IOIO,                        "io" }, \
+       { SVM_EXIT_MSR,                         "msr" }, \
+       { SVM_EXIT_TASK_SWITCH,                 "task_switch" }, \
+       { SVM_EXIT_SHUTDOWN,                    "shutdown" }, \
+       { SVM_EXIT_VMRUN,                       "vmrun" }, \
+       { SVM_EXIT_VMMCALL,                     "hypercall" }, \
+       { SVM_EXIT_VMLOAD,                      "vmload" }, \
+       { SVM_EXIT_VMSAVE,                      "vmsave" }, \
+       { SVM_EXIT_STGI,                        "stgi" }, \
+       { SVM_EXIT_CLGI,                        "clgi" }, \
+       { SVM_EXIT_SKINIT,                      "skinit" }, \
+       { SVM_EXIT_WBINVD,                      "wbinvd" }, \
+       { SVM_EXIT_MONITOR,                     "monitor" }, \
+       { SVM_EXIT_MWAIT,                       "mwait" }, \
+       { SVM_EXIT_XSETBV,                      "xsetbv" }, \
+       { SVM_EXIT_NPF,                         "npf" }
+
 /*
  * Tracepoint for kvm guest exit:
  */
@@ -205,8 +296,9 @@ TRACE_EVENT(kvm_exit,
        ),
 
        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->isa == KVM_ISA_VMX) ?
+                __print_symbolic(__entry->exit_reason, VMX_EXIT_REASONS) :
+                __print_symbolic(__entry->exit_reason, SVM_EXIT_REASONS),
                 __entry->guest_rip, __entry->info1, __entry->info2)
 );
 
@@ -486,9 +578,9 @@ TRACE_EVENT(kvm_nested_intercepts,
 TRACE_EVENT(kvm_nested_vmexit,
            TP_PROTO(__u64 rip, __u32 exit_code,
                     __u64 exit_info1, __u64 exit_info2,
-                    __u32 exit_int_info, __u32 exit_int_info_err),
+                    __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
            TP_ARGS(rip, exit_code, exit_info1, exit_info2,
-                   exit_int_info, exit_int_info_err),
+                   exit_int_info, exit_int_info_err, isa),
 
        TP_STRUCT__entry(
                __field(        __u64,          rip                     )
@@ -497,6 +589,7 @@ TRACE_EVENT(kvm_nested_vmexit,
                __field(        __u64,          exit_info2              )
                __field(        __u32,          exit_int_info           )
                __field(        __u32,          exit_int_info_err       )
+               __field(        __u32,          isa                     )
        ),
 
        TP_fast_assign(
@@ -506,12 +599,14 @@ TRACE_EVENT(kvm_nested_vmexit,
                __entry->exit_info2             = exit_info2;
                __entry->exit_int_info          = exit_int_info;
                __entry->exit_int_info_err      = exit_int_info_err;
+               __entry->isa                    = isa;
        ),
        TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx "
                  "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
                  __entry->rip,
-                 ftrace_print_symbols_seq(p, __entry->exit_code,
-                                          kvm_x86_ops->exit_reasons_str),
+                (__entry->isa == KVM_ISA_VMX) ?
+                __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
+                __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
                  __entry->exit_info1, __entry->exit_info2,
                  __entry->exit_int_info, __entry->exit_int_info_err)
 );
@@ -522,9 +617,9 @@ TRACE_EVENT(kvm_nested_vmexit,
 TRACE_EVENT(kvm_nested_vmexit_inject,
            TP_PROTO(__u32 exit_code,
                     __u64 exit_info1, __u64 exit_info2,
-                    __u32 exit_int_info, __u32 exit_int_info_err),
+                    __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
            TP_ARGS(exit_code, exit_info1, exit_info2,
-                   exit_int_info, exit_int_info_err),
+                   exit_int_info, exit_int_info_err, isa),
 
        TP_STRUCT__entry(
                __field(        __u32,          exit_code               )
@@ -532,6 +627,7 @@ TRACE_EVENT(kvm_nested_vmexit_inject,
                __field(        __u64,          exit_info2              )
                __field(        __u32,          exit_int_info           )
                __field(        __u32,          exit_int_info_err       )
+               __field(        __u32,          isa                     )
        ),
 
        TP_fast_assign(
@@ -540,12 +636,14 @@ TRACE_EVENT(kvm_nested_vmexit_inject,
                __entry->exit_info2             = exit_info2;
                __entry->exit_int_info          = exit_int_info;
                __entry->exit_int_info_err      = exit_int_info_err;
+               __entry->isa                    = isa;
        ),
 
        TP_printk("reason: %s ext_inf1: 0x%016llx "
                  "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
-                 ftrace_print_symbols_seq(p, __entry->exit_code,
-                                          kvm_x86_ops->exit_reasons_str),
+                (__entry->isa == KVM_ISA_VMX) ?
+                __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
+                __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
                __entry->exit_info1, __entry->exit_info2,
                __entry->exit_int_info, __entry->exit_int_info_err)
 );
@@ -675,12 +773,12 @@ TRACE_EVENT(kvm_emulate_insn,
                ),
 
        TP_fast_assign(
-               __entry->rip = vcpu->arch.emulate_ctxt.decode.fetch.start;
+               __entry->rip = vcpu->arch.emulate_ctxt.fetch.start;
                __entry->csbase = kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS);
-               __entry->len = vcpu->arch.emulate_ctxt.decode.eip
-                              - vcpu->arch.emulate_ctxt.decode.fetch.start;
+               __entry->len = vcpu->arch.emulate_ctxt._eip
+                              - vcpu->arch.emulate_ctxt.fetch.start;
                memcpy(__entry->insn,
-                      vcpu->arch.emulate_ctxt.decode.fetch.data,
+                      vcpu->arch.emulate_ctxt.fetch.data,
                       15);
                __entry->flags = kei_decode_mode(vcpu->arch.emulate_ctxt.mode);
                __entry->failed = failed;
@@ -698,6 +796,29 @@ TRACE_EVENT(kvm_emulate_insn,
 #define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0)
 #define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1)
 
+TRACE_EVENT(
+       vcpu_match_mmio,
+       TP_PROTO(gva_t gva, gpa_t gpa, bool write, bool gpa_match),
+       TP_ARGS(gva, gpa, write, gpa_match),
+
+       TP_STRUCT__entry(
+               __field(gva_t, gva)
+               __field(gpa_t, gpa)
+               __field(bool, write)
+               __field(bool, gpa_match)
+               ),
+
+       TP_fast_assign(
+               __entry->gva = gva;
+               __entry->gpa = gpa;
+               __entry->write = write;
+               __entry->gpa_match = gpa_match
+               ),
+
+       TP_printk("gva %#lx gpa %#llx %s %s", __entry->gva, __entry->gpa,
+                 __entry->write ? "Write" : "Read",
+                 __entry->gpa_match ? "GPA" : "GVA")
+);
 #endif /* _TRACE_KVM_H */
 
 #undef TRACE_INCLUDE_PATH