1 #if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
4 #include <linux/tracepoint.h>
7 #define TRACE_SYSTEM kvm
10 * Tracepoint for guest mode entry.
12 TRACE_EVENT(kvm_entry
,
13 TP_PROTO(unsigned int vcpu_id
),
17 __field( unsigned int, vcpu_id
)
21 __entry
->vcpu_id
= vcpu_id
;
24 TP_printk("vcpu %u", __entry
->vcpu_id
)
28 * Tracepoint for hypercall.
30 TRACE_EVENT(kvm_hypercall
,
31 TP_PROTO(unsigned long nr
, unsigned long a0
, unsigned long a1
,
32 unsigned long a2
, unsigned long a3
),
33 TP_ARGS(nr
, a0
, a1
, a2
, a3
),
36 __field( unsigned long, nr
)
37 __field( unsigned long, a0
)
38 __field( unsigned long, a1
)
39 __field( unsigned long, a2
)
40 __field( unsigned long, a3
)
51 TP_printk("nr 0x%lx a0 0x%lx a1 0x%lx a2 0x%lx a3 0x%lx",
52 __entry
->nr
, __entry
->a0
, __entry
->a1
, __entry
->a2
,
57 * Tracepoint for hypercall.
59 TRACE_EVENT(kvm_hv_hypercall
,
60 TP_PROTO(__u16 code
, bool fast
, __u16 rep_cnt
, __u16 rep_idx
,
61 __u64 ingpa
, __u64 outgpa
),
62 TP_ARGS(code
, fast
, rep_cnt
, rep_idx
, ingpa
, outgpa
),
65 __field( __u16
, rep_cnt
)
66 __field( __u16
, rep_idx
)
67 __field( __u64
, ingpa
)
68 __field( __u64
, outgpa
)
69 __field( __u16
, code
)
74 __entry
->rep_cnt
= rep_cnt
;
75 __entry
->rep_idx
= rep_idx
;
76 __entry
->ingpa
= ingpa
;
77 __entry
->outgpa
= outgpa
;
82 TP_printk("code 0x%x %s cnt 0x%x idx 0x%x in 0x%llx out 0x%llx",
83 __entry
->code
, __entry
->fast
? "fast" : "slow",
84 __entry
->rep_cnt
, __entry
->rep_idx
, __entry
->ingpa
,
92 TP_PROTO(unsigned int rw
, unsigned int port
, unsigned int size
,
94 TP_ARGS(rw
, port
, size
, count
),
97 __field( unsigned int, rw
)
98 __field( unsigned int, port
)
99 __field( unsigned int, size
)
100 __field( unsigned int, count
)
105 __entry
->port
= port
;
106 __entry
->size
= size
;
107 __entry
->count
= count
;
110 TP_printk("pio_%s at 0x%x size %d count %d",
111 __entry
->rw
? "write" : "read",
112 __entry
->port
, __entry
->size
, __entry
->count
)
116 * Tracepoint for cpuid.
118 TRACE_EVENT(kvm_cpuid
,
119 TP_PROTO(unsigned int function
, unsigned long rax
, unsigned long rbx
,
120 unsigned long rcx
, unsigned long rdx
),
121 TP_ARGS(function
, rax
, rbx
, rcx
, rdx
),
124 __field( unsigned int, function
)
125 __field( unsigned long, rax
)
126 __field( unsigned long, rbx
)
127 __field( unsigned long, rcx
)
128 __field( unsigned long, rdx
)
132 __entry
->function
= function
;
139 TP_printk("func %x rax %lx rbx %lx rcx %lx rdx %lx",
140 __entry
->function
, __entry
->rax
,
141 __entry
->rbx
, __entry
->rcx
, __entry
->rdx
)
144 #define AREG(x) { APIC_##x, "APIC_" #x }
146 #define kvm_trace_symbol_apic \
147 AREG(ID), AREG(LVR), AREG(TASKPRI), AREG(ARBPRI), AREG(PROCPRI), \
148 AREG(EOI), AREG(RRR), AREG(LDR), AREG(DFR), AREG(SPIV), AREG(ISR), \
149 AREG(TMR), AREG(IRR), AREG(ESR), AREG(ICR), AREG(ICR2), AREG(LVTT), \
150 AREG(LVTTHMR), AREG(LVTPC), AREG(LVT0), AREG(LVT1), AREG(LVTERR), \
151 AREG(TMICT), AREG(TMCCT), AREG(TDCR), AREG(SELF_IPI), AREG(EFEAT), \
154 * Tracepoint for apic access.
156 TRACE_EVENT(kvm_apic
,
157 TP_PROTO(unsigned int rw
, unsigned int reg
, unsigned int val
),
158 TP_ARGS(rw
, reg
, val
),
161 __field( unsigned int, rw
)
162 __field( unsigned int, reg
)
163 __field( unsigned int, val
)
172 TP_printk("apic_%s %s = 0x%x",
173 __entry
->rw
? "write" : "read",
174 __print_symbolic(__entry
->reg
, kvm_trace_symbol_apic
),
178 #define trace_kvm_apic_read(reg, val) trace_kvm_apic(0, reg, val)
179 #define trace_kvm_apic_write(reg, val) trace_kvm_apic(1, reg, val)
181 #define KVM_ISA_VMX 1
182 #define KVM_ISA_SVM 2
185 * Tracepoint for kvm guest exit:
187 TRACE_EVENT(kvm_exit
,
188 TP_PROTO(unsigned int exit_reason
, struct kvm_vcpu
*vcpu
, u32 isa
),
189 TP_ARGS(exit_reason
, vcpu
, isa
),
192 __field( unsigned int, exit_reason
)
193 __field( unsigned long, guest_rip
)
195 __field( u64
, info1
)
196 __field( u64
, info2
)
200 __entry
->exit_reason
= exit_reason
;
201 __entry
->guest_rip
= kvm_rip_read(vcpu
);
203 kvm_x86_ops
->get_exit_info(vcpu
, &__entry
->info1
,
207 TP_printk("reason %s rip 0x%lx info %llx %llx",
208 ftrace_print_symbols_seq(p
, __entry
->exit_reason
,
209 kvm_x86_ops
->exit_reasons_str
),
210 __entry
->guest_rip
, __entry
->info1
, __entry
->info2
)
214 * Tracepoint for kvm interrupt injection:
216 TRACE_EVENT(kvm_inj_virq
,
217 TP_PROTO(unsigned int irq
),
221 __field( unsigned int, irq
)
228 TP_printk("irq %u", __entry
->irq
)
231 #define EXS(x) { x##_VECTOR, "#" #x }
233 #define kvm_trace_sym_exc \
234 EXS(DE), EXS(DB), EXS(BP), EXS(OF), EXS(BR), EXS(UD), EXS(NM), \
235 EXS(DF), EXS(TS), EXS(NP), EXS(SS), EXS(GP), EXS(PF), \
239 * Tracepoint for kvm interrupt injection:
241 TRACE_EVENT(kvm_inj_exception
,
242 TP_PROTO(unsigned exception
, bool has_error
, unsigned error_code
),
243 TP_ARGS(exception
, has_error
, error_code
),
246 __field( u8
, exception
)
247 __field( u8
, has_error
)
248 __field( u32
, error_code
)
252 __entry
->exception
= exception
;
253 __entry
->has_error
= has_error
;
254 __entry
->error_code
= error_code
;
257 TP_printk("%s (0x%x)",
258 __print_symbolic(__entry
->exception
, kvm_trace_sym_exc
),
259 /* FIXME: don't print error_code if not present */
260 __entry
->has_error
? __entry
->error_code
: 0)
264 * Tracepoint for page fault.
266 TRACE_EVENT(kvm_page_fault
,
267 TP_PROTO(unsigned long fault_address
, unsigned int error_code
),
268 TP_ARGS(fault_address
, error_code
),
271 __field( unsigned long, fault_address
)
272 __field( unsigned int, error_code
)
276 __entry
->fault_address
= fault_address
;
277 __entry
->error_code
= error_code
;
280 TP_printk("address %lx error_code %x",
281 __entry
->fault_address
, __entry
->error_code
)
285 * Tracepoint for guest MSR access.
288 TP_PROTO(unsigned write
, u32 ecx
, u64 data
, bool exception
),
289 TP_ARGS(write
, ecx
, data
, exception
),
292 __field( unsigned, write
)
295 __field( u8
, exception
)
299 __entry
->write
= write
;
301 __entry
->data
= data
;
302 __entry
->exception
= exception
;
305 TP_printk("msr_%s %x = 0x%llx%s",
306 __entry
->write
? "write" : "read",
307 __entry
->ecx
, __entry
->data
,
308 __entry
->exception
? " (#GP)" : "")
311 #define trace_kvm_msr_read(ecx, data) trace_kvm_msr(0, ecx, data, false)
312 #define trace_kvm_msr_write(ecx, data) trace_kvm_msr(1, ecx, data, false)
313 #define trace_kvm_msr_read_ex(ecx) trace_kvm_msr(0, ecx, 0, true)
314 #define trace_kvm_msr_write_ex(ecx, data) trace_kvm_msr(1, ecx, data, true)
317 * Tracepoint for guest CR access.
320 TP_PROTO(unsigned int rw
, unsigned int cr
, unsigned long val
),
321 TP_ARGS(rw
, cr
, val
),
324 __field( unsigned int, rw
)
325 __field( unsigned int, cr
)
326 __field( unsigned long, val
)
335 TP_printk("cr_%s %x = 0x%lx",
336 __entry
->rw
? "write" : "read",
337 __entry
->cr
, __entry
->val
)
340 #define trace_kvm_cr_read(cr, val) trace_kvm_cr(0, cr, val)
341 #define trace_kvm_cr_write(cr, val) trace_kvm_cr(1, cr, val)
343 TRACE_EVENT(kvm_pic_set_irq
,
344 TP_PROTO(__u8 chip
, __u8 pin
, __u8 elcr
, __u8 imr
, bool coalesced
),
345 TP_ARGS(chip
, pin
, elcr
, imr
, coalesced
),
348 __field( __u8
, chip
)
350 __field( __u8
, elcr
)
352 __field( bool, coalesced
)
356 __entry
->chip
= chip
;
358 __entry
->elcr
= elcr
;
360 __entry
->coalesced
= coalesced
;
363 TP_printk("chip %u pin %u (%s%s)%s",
364 __entry
->chip
, __entry
->pin
,
365 (__entry
->elcr
& (1 << __entry
->pin
)) ? "level":"edge",
366 (__entry
->imr
& (1 << __entry
->pin
)) ? "|masked":"",
367 __entry
->coalesced
? " (coalesced)" : "")
370 #define kvm_apic_dst_shorthand \
374 {0x3, "all-but-self"}
376 TRACE_EVENT(kvm_apic_ipi
,
377 TP_PROTO(__u32 icr_low
, __u32 dest_id
),
378 TP_ARGS(icr_low
, dest_id
),
381 __field( __u32
, icr_low
)
382 __field( __u32
, dest_id
)
386 __entry
->icr_low
= icr_low
;
387 __entry
->dest_id
= dest_id
;
390 TP_printk("dst %x vec %u (%s|%s|%s|%s|%s)",
391 __entry
->dest_id
, (u8
)__entry
->icr_low
,
392 __print_symbolic((__entry
->icr_low
>> 8 & 0x7),
394 (__entry
->icr_low
& (1<<11)) ? "logical" : "physical",
395 (__entry
->icr_low
& (1<<14)) ? "assert" : "de-assert",
396 (__entry
->icr_low
& (1<<15)) ? "level" : "edge",
397 __print_symbolic((__entry
->icr_low
>> 18 & 0x3),
398 kvm_apic_dst_shorthand
))
401 TRACE_EVENT(kvm_apic_accept_irq
,
402 TP_PROTO(__u32 apicid
, __u16 dm
, __u8 tm
, __u8 vec
, bool coalesced
),
403 TP_ARGS(apicid
, dm
, tm
, vec
, coalesced
),
406 __field( __u32
, apicid
)
410 __field( bool, coalesced
)
414 __entry
->apicid
= apicid
;
418 __entry
->coalesced
= coalesced
;
421 TP_printk("apicid %x vec %u (%s|%s)%s",
422 __entry
->apicid
, __entry
->vec
,
423 __print_symbolic((__entry
->dm
>> 8 & 0x7), kvm_deliver_mode
),
424 __entry
->tm
? "level" : "edge",
425 __entry
->coalesced
? " (coalesced)" : "")
429 * Tracepoint for nested VMRUN
431 TRACE_EVENT(kvm_nested_vmrun
,
432 TP_PROTO(__u64 rip
, __u64 vmcb
, __u64 nested_rip
, __u32 int_ctl
,
433 __u32 event_inj
, bool npt
),
434 TP_ARGS(rip
, vmcb
, nested_rip
, int_ctl
, event_inj
, npt
),
437 __field( __u64
, rip
)
438 __field( __u64
, vmcb
)
439 __field( __u64
, nested_rip
)
440 __field( __u32
, int_ctl
)
441 __field( __u32
, event_inj
)
447 __entry
->vmcb
= vmcb
;
448 __entry
->nested_rip
= nested_rip
;
449 __entry
->int_ctl
= int_ctl
;
450 __entry
->event_inj
= event_inj
;
454 TP_printk("rip: 0x%016llx vmcb: 0x%016llx nrip: 0x%016llx int_ctl: 0x%08x "
455 "event_inj: 0x%08x npt: %s",
456 __entry
->rip
, __entry
->vmcb
, __entry
->nested_rip
,
457 __entry
->int_ctl
, __entry
->event_inj
,
458 __entry
->npt
? "on" : "off")
461 TRACE_EVENT(kvm_nested_intercepts
,
462 TP_PROTO(__u16 cr_read
, __u16 cr_write
, __u32 exceptions
, __u64 intercept
),
463 TP_ARGS(cr_read
, cr_write
, exceptions
, intercept
),
466 __field( __u16
, cr_read
)
467 __field( __u16
, cr_write
)
468 __field( __u32
, exceptions
)
469 __field( __u64
, intercept
)
473 __entry
->cr_read
= cr_read
;
474 __entry
->cr_write
= cr_write
;
475 __entry
->exceptions
= exceptions
;
476 __entry
->intercept
= intercept
;
479 TP_printk("cr_read: %04x cr_write: %04x excp: %08x intercept: %016llx",
480 __entry
->cr_read
, __entry
->cr_write
, __entry
->exceptions
,
484 * Tracepoint for #VMEXIT while nested
486 TRACE_EVENT(kvm_nested_vmexit
,
487 TP_PROTO(__u64 rip
, __u32 exit_code
,
488 __u64 exit_info1
, __u64 exit_info2
,
489 __u32 exit_int_info
, __u32 exit_int_info_err
),
490 TP_ARGS(rip
, exit_code
, exit_info1
, exit_info2
,
491 exit_int_info
, exit_int_info_err
),
494 __field( __u64
, rip
)
495 __field( __u32
, exit_code
)
496 __field( __u64
, exit_info1
)
497 __field( __u64
, exit_info2
)
498 __field( __u32
, exit_int_info
)
499 __field( __u32
, exit_int_info_err
)
504 __entry
->exit_code
= exit_code
;
505 __entry
->exit_info1
= exit_info1
;
506 __entry
->exit_info2
= exit_info2
;
507 __entry
->exit_int_info
= exit_int_info
;
508 __entry
->exit_int_info_err
= exit_int_info_err
;
510 TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx "
511 "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
513 ftrace_print_symbols_seq(p
, __entry
->exit_code
,
514 kvm_x86_ops
->exit_reasons_str
),
515 __entry
->exit_info1
, __entry
->exit_info2
,
516 __entry
->exit_int_info
, __entry
->exit_int_info_err
)
520 * Tracepoint for #VMEXIT reinjected to the guest
522 TRACE_EVENT(kvm_nested_vmexit_inject
,
523 TP_PROTO(__u32 exit_code
,
524 __u64 exit_info1
, __u64 exit_info2
,
525 __u32 exit_int_info
, __u32 exit_int_info_err
),
526 TP_ARGS(exit_code
, exit_info1
, exit_info2
,
527 exit_int_info
, exit_int_info_err
),
530 __field( __u32
, exit_code
)
531 __field( __u64
, exit_info1
)
532 __field( __u64
, exit_info2
)
533 __field( __u32
, exit_int_info
)
534 __field( __u32
, exit_int_info_err
)
538 __entry
->exit_code
= exit_code
;
539 __entry
->exit_info1
= exit_info1
;
540 __entry
->exit_info2
= exit_info2
;
541 __entry
->exit_int_info
= exit_int_info
;
542 __entry
->exit_int_info_err
= exit_int_info_err
;
545 TP_printk("reason: %s ext_inf1: 0x%016llx "
546 "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
547 ftrace_print_symbols_seq(p
, __entry
->exit_code
,
548 kvm_x86_ops
->exit_reasons_str
),
549 __entry
->exit_info1
, __entry
->exit_info2
,
550 __entry
->exit_int_info
, __entry
->exit_int_info_err
)
554 * Tracepoint for nested #vmexit because of interrupt pending
556 TRACE_EVENT(kvm_nested_intr_vmexit
,
561 __field( __u64
, rip
)
568 TP_printk("rip: 0x%016llx", __entry
->rip
)
572 * Tracepoint for nested #vmexit because of interrupt pending
574 TRACE_EVENT(kvm_invlpga
,
575 TP_PROTO(__u64 rip
, int asid
, u64 address
),
576 TP_ARGS(rip
, asid
, address
),
579 __field( __u64
, rip
)
581 __field( __u64
, address
)
586 __entry
->asid
= asid
;
587 __entry
->address
= address
;
590 TP_printk("rip: 0x%016llx asid: %d address: 0x%016llx",
591 __entry
->rip
, __entry
->asid
, __entry
->address
)
595 * Tracepoint for nested #vmexit because of interrupt pending
597 TRACE_EVENT(kvm_skinit
,
598 TP_PROTO(__u64 rip
, __u32 slb
),
602 __field( __u64
, rip
)
603 __field( __u32
, slb
)
611 TP_printk("rip: 0x%016llx slb: 0x%08x",
612 __entry
->rip
, __entry
->slb
)
615 #define __print_insn(insn, ilen) ({ \
617 const char *ret = p->buffer + p->len; \
619 for (i = 0; i < ilen; ++i) \
620 trace_seq_printf(p, " %02x", insn[i]); \
621 trace_seq_printf(p, "%c", 0); \
625 #define KVM_EMUL_INSN_F_CR0_PE (1 << 0)
626 #define KVM_EMUL_INSN_F_EFL_VM (1 << 1)
627 #define KVM_EMUL_INSN_F_CS_D (1 << 2)
628 #define KVM_EMUL_INSN_F_CS_L (1 << 3)
630 #define kvm_trace_symbol_emul_flags \
632 { KVM_EMUL_INSN_F_CR0_PE \
633 | KVM_EMUL_INSN_F_EFL_VM, "vm16" }, \
634 { KVM_EMUL_INSN_F_CR0_PE, "prot16" }, \
635 { KVM_EMUL_INSN_F_CR0_PE \
636 | KVM_EMUL_INSN_F_CS_D, "prot32" }, \
637 { KVM_EMUL_INSN_F_CR0_PE \
638 | KVM_EMUL_INSN_F_CS_L, "prot64" }
640 #define kei_decode_mode(mode) ({ \
643 case X86EMUL_MODE_REAL: \
646 case X86EMUL_MODE_VM86: \
647 flags = KVM_EMUL_INSN_F_EFL_VM; \
649 case X86EMUL_MODE_PROT16: \
650 flags = KVM_EMUL_INSN_F_CR0_PE; \
652 case X86EMUL_MODE_PROT32: \
653 flags = KVM_EMUL_INSN_F_CR0_PE \
654 | KVM_EMUL_INSN_F_CS_D; \
656 case X86EMUL_MODE_PROT64: \
657 flags = KVM_EMUL_INSN_F_CR0_PE \
658 | KVM_EMUL_INSN_F_CS_L; \
664 TRACE_EVENT(kvm_emulate_insn
,
665 TP_PROTO(struct kvm_vcpu
*vcpu
, __u8 failed
),
666 TP_ARGS(vcpu
, failed
),
669 __field( __u64
, rip
)
670 __field( __u32
, csbase
)
672 __array( __u8
, insn
, 15 )
673 __field( __u8
, flags
)
674 __field( __u8
, failed
)
678 __entry
->rip
= vcpu
->arch
.emulate_ctxt
.fetch
.start
;
679 __entry
->csbase
= kvm_x86_ops
->get_segment_base(vcpu
, VCPU_SREG_CS
);
680 __entry
->len
= vcpu
->arch
.emulate_ctxt
._eip
681 - vcpu
->arch
.emulate_ctxt
.fetch
.start
;
682 memcpy(__entry
->insn
,
683 vcpu
->arch
.emulate_ctxt
.fetch
.data
,
685 __entry
->flags
= kei_decode_mode(vcpu
->arch
.emulate_ctxt
.mode
);
686 __entry
->failed
= failed
;
689 TP_printk("%x:%llx:%s (%s)%s",
690 __entry
->csbase
, __entry
->rip
,
691 __print_insn(__entry
->insn
, __entry
->len
),
692 __print_symbolic(__entry
->flags
,
693 kvm_trace_symbol_emul_flags
),
694 __entry
->failed
? " failed" : ""
698 #define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0)
699 #define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1)
703 TP_PROTO(gva_t gva
, gpa_t gpa
, bool write
, bool gpa_match
),
704 TP_ARGS(gva
, gpa
, write
, gpa_match
),
710 __field(bool, gpa_match
)
716 __entry
->write
= write
;
717 __entry
->gpa_match
= gpa_match
720 TP_printk("gva %#lx gpa %#llx %s %s", __entry
->gva
, __entry
->gpa
,
721 __entry
->write
? "Write" : "Read",
722 __entry
->gpa_match
? "GPA" : "GVA")
724 #endif /* _TRACE_KVM_H */
726 #undef TRACE_INCLUDE_PATH
727 #define TRACE_INCLUDE_PATH arch/x86/kvm
728 #undef TRACE_INCLUDE_FILE
729 #define TRACE_INCLUDE_FILE trace
731 /* This part must be outside protection */
732 #include <trace/define_trace.h>