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
, code
)
67 __field( __u16
, rep_cnt
)
68 __field( __u16
, rep_idx
)
69 __field( __u64
, ingpa
)
70 __field( __u64
, outgpa
)
76 __entry
->rep_cnt
= rep_cnt
;
77 __entry
->rep_idx
= rep_idx
;
78 __entry
->ingpa
= ingpa
;
79 __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)
182 * Tracepoint for kvm guest exit:
184 TRACE_EVENT(kvm_exit
,
185 TP_PROTO(unsigned int exit_reason
, struct kvm_vcpu
*vcpu
),
186 TP_ARGS(exit_reason
, vcpu
),
189 __field( unsigned int, exit_reason
)
190 __field( unsigned long, guest_rip
)
194 __entry
->exit_reason
= exit_reason
;
195 __entry
->guest_rip
= kvm_rip_read(vcpu
);
198 TP_printk("reason %s rip 0x%lx",
199 ftrace_print_symbols_seq(p
, __entry
->exit_reason
,
200 kvm_x86_ops
->exit_reasons_str
),
205 * Tracepoint for kvm interrupt injection:
207 TRACE_EVENT(kvm_inj_virq
,
208 TP_PROTO(unsigned int irq
),
212 __field( unsigned int, irq
)
219 TP_printk("irq %u", __entry
->irq
)
222 #define EXS(x) { x##_VECTOR, "#" #x }
224 #define kvm_trace_sym_exc \
225 EXS(DE), EXS(DB), EXS(BP), EXS(OF), EXS(BR), EXS(UD), EXS(NM), \
226 EXS(DF), EXS(TS), EXS(NP), EXS(SS), EXS(GP), EXS(PF), \
230 * Tracepoint for kvm interrupt injection:
232 TRACE_EVENT(kvm_inj_exception
,
233 TP_PROTO(unsigned exception
, bool has_error
, unsigned error_code
),
234 TP_ARGS(exception
, has_error
, error_code
),
237 __field( u8
, exception
)
238 __field( u8
, has_error
)
239 __field( u32
, error_code
)
243 __entry
->exception
= exception
;
244 __entry
->has_error
= has_error
;
245 __entry
->error_code
= error_code
;
248 TP_printk("%s (0x%x)",
249 __print_symbolic(__entry
->exception
, kvm_trace_sym_exc
),
250 /* FIXME: don't print error_code if not present */
251 __entry
->has_error
? __entry
->error_code
: 0)
255 * Tracepoint for page fault.
257 TRACE_EVENT(kvm_page_fault
,
258 TP_PROTO(unsigned long fault_address
, unsigned int error_code
),
259 TP_ARGS(fault_address
, error_code
),
262 __field( unsigned long, fault_address
)
263 __field( unsigned int, error_code
)
267 __entry
->fault_address
= fault_address
;
268 __entry
->error_code
= error_code
;
271 TP_printk("address %lx error_code %x",
272 __entry
->fault_address
, __entry
->error_code
)
276 * Tracepoint for guest MSR access.
279 TP_PROTO(unsigned write
, u32 ecx
, u64 data
, bool exception
),
280 TP_ARGS(write
, ecx
, data
, exception
),
283 __field( unsigned, write
)
286 __field( u8
, exception
)
290 __entry
->write
= write
;
292 __entry
->data
= data
;
293 __entry
->exception
= exception
;
296 TP_printk("msr_%s %x = 0x%llx%s",
297 __entry
->write
? "write" : "read",
298 __entry
->ecx
, __entry
->data
,
299 __entry
->exception
? " (#GP)" : "")
302 #define trace_kvm_msr_read(ecx, data) trace_kvm_msr(0, ecx, data, false)
303 #define trace_kvm_msr_write(ecx, data) trace_kvm_msr(1, ecx, data, false)
304 #define trace_kvm_msr_read_ex(ecx) trace_kvm_msr(0, ecx, 0, true)
305 #define trace_kvm_msr_write_ex(ecx, data) trace_kvm_msr(1, ecx, data, true)
308 * Tracepoint for guest CR access.
311 TP_PROTO(unsigned int rw
, unsigned int cr
, unsigned long val
),
312 TP_ARGS(rw
, cr
, val
),
315 __field( unsigned int, rw
)
316 __field( unsigned int, cr
)
317 __field( unsigned long, val
)
326 TP_printk("cr_%s %x = 0x%lx",
327 __entry
->rw
? "write" : "read",
328 __entry
->cr
, __entry
->val
)
331 #define trace_kvm_cr_read(cr, val) trace_kvm_cr(0, cr, val)
332 #define trace_kvm_cr_write(cr, val) trace_kvm_cr(1, cr, val)
334 TRACE_EVENT(kvm_pic_set_irq
,
335 TP_PROTO(__u8 chip
, __u8 pin
, __u8 elcr
, __u8 imr
, bool coalesced
),
336 TP_ARGS(chip
, pin
, elcr
, imr
, coalesced
),
339 __field( __u8
, chip
)
341 __field( __u8
, elcr
)
343 __field( bool, coalesced
)
347 __entry
->chip
= chip
;
349 __entry
->elcr
= elcr
;
351 __entry
->coalesced
= coalesced
;
354 TP_printk("chip %u pin %u (%s%s)%s",
355 __entry
->chip
, __entry
->pin
,
356 (__entry
->elcr
& (1 << __entry
->pin
)) ? "level":"edge",
357 (__entry
->imr
& (1 << __entry
->pin
)) ? "|masked":"",
358 __entry
->coalesced
? " (coalesced)" : "")
361 #define kvm_apic_dst_shorthand \
365 {0x3, "all-but-self"}
367 TRACE_EVENT(kvm_apic_ipi
,
368 TP_PROTO(__u32 icr_low
, __u32 dest_id
),
369 TP_ARGS(icr_low
, dest_id
),
372 __field( __u32
, icr_low
)
373 __field( __u32
, dest_id
)
377 __entry
->icr_low
= icr_low
;
378 __entry
->dest_id
= dest_id
;
381 TP_printk("dst %x vec %u (%s|%s|%s|%s|%s)",
382 __entry
->dest_id
, (u8
)__entry
->icr_low
,
383 __print_symbolic((__entry
->icr_low
>> 8 & 0x7),
385 (__entry
->icr_low
& (1<<11)) ? "logical" : "physical",
386 (__entry
->icr_low
& (1<<14)) ? "assert" : "de-assert",
387 (__entry
->icr_low
& (1<<15)) ? "level" : "edge",
388 __print_symbolic((__entry
->icr_low
>> 18 & 0x3),
389 kvm_apic_dst_shorthand
))
392 TRACE_EVENT(kvm_apic_accept_irq
,
393 TP_PROTO(__u32 apicid
, __u16 dm
, __u8 tm
, __u8 vec
, bool coalesced
),
394 TP_ARGS(apicid
, dm
, tm
, vec
, coalesced
),
397 __field( __u32
, apicid
)
401 __field( bool, coalesced
)
405 __entry
->apicid
= apicid
;
409 __entry
->coalesced
= coalesced
;
412 TP_printk("apicid %x vec %u (%s|%s)%s",
413 __entry
->apicid
, __entry
->vec
,
414 __print_symbolic((__entry
->dm
>> 8 & 0x7), kvm_deliver_mode
),
415 __entry
->tm
? "level" : "edge",
416 __entry
->coalesced
? " (coalesced)" : "")
420 * Tracepoint for nested VMRUN
422 TRACE_EVENT(kvm_nested_vmrun
,
423 TP_PROTO(__u64 rip
, __u64 vmcb
, __u64 nested_rip
, __u32 int_ctl
,
424 __u32 event_inj
, bool npt
),
425 TP_ARGS(rip
, vmcb
, nested_rip
, int_ctl
, event_inj
, npt
),
428 __field( __u64
, rip
)
429 __field( __u64
, vmcb
)
430 __field( __u64
, nested_rip
)
431 __field( __u32
, int_ctl
)
432 __field( __u32
, event_inj
)
438 __entry
->vmcb
= vmcb
;
439 __entry
->nested_rip
= nested_rip
;
440 __entry
->int_ctl
= int_ctl
;
441 __entry
->event_inj
= event_inj
;
445 TP_printk("rip: 0x%016llx vmcb: 0x%016llx nrip: 0x%016llx int_ctl: 0x%08x "
446 "event_inj: 0x%08x npt: %s",
447 __entry
->rip
, __entry
->vmcb
, __entry
->nested_rip
,
448 __entry
->int_ctl
, __entry
->event_inj
,
449 __entry
->npt
? "on" : "off")
452 TRACE_EVENT(kvm_nested_intercepts
,
453 TP_PROTO(__u16 cr_read
, __u16 cr_write
, __u32 exceptions
, __u64 intercept
),
454 TP_ARGS(cr_read
, cr_write
, exceptions
, intercept
),
457 __field( __u16
, cr_read
)
458 __field( __u16
, cr_write
)
459 __field( __u32
, exceptions
)
460 __field( __u64
, intercept
)
464 __entry
->cr_read
= cr_read
;
465 __entry
->cr_write
= cr_write
;
466 __entry
->exceptions
= exceptions
;
467 __entry
->intercept
= intercept
;
470 TP_printk("cr_read: %04x cr_write: %04x excp: %08x intercept: %016llx",
471 __entry
->cr_read
, __entry
->cr_write
, __entry
->exceptions
,
475 * Tracepoint for #VMEXIT while nested
477 TRACE_EVENT(kvm_nested_vmexit
,
478 TP_PROTO(__u64 rip
, __u32 exit_code
,
479 __u64 exit_info1
, __u64 exit_info2
,
480 __u32 exit_int_info
, __u32 exit_int_info_err
),
481 TP_ARGS(rip
, exit_code
, exit_info1
, exit_info2
,
482 exit_int_info
, exit_int_info_err
),
485 __field( __u64
, rip
)
486 __field( __u32
, exit_code
)
487 __field( __u64
, exit_info1
)
488 __field( __u64
, exit_info2
)
489 __field( __u32
, exit_int_info
)
490 __field( __u32
, exit_int_info_err
)
495 __entry
->exit_code
= exit_code
;
496 __entry
->exit_info1
= exit_info1
;
497 __entry
->exit_info2
= exit_info2
;
498 __entry
->exit_int_info
= exit_int_info
;
499 __entry
->exit_int_info_err
= exit_int_info_err
;
501 TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx "
502 "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
504 ftrace_print_symbols_seq(p
, __entry
->exit_code
,
505 kvm_x86_ops
->exit_reasons_str
),
506 __entry
->exit_info1
, __entry
->exit_info2
,
507 __entry
->exit_int_info
, __entry
->exit_int_info_err
)
511 * Tracepoint for #VMEXIT reinjected to the guest
513 TRACE_EVENT(kvm_nested_vmexit_inject
,
514 TP_PROTO(__u32 exit_code
,
515 __u64 exit_info1
, __u64 exit_info2
,
516 __u32 exit_int_info
, __u32 exit_int_info_err
),
517 TP_ARGS(exit_code
, exit_info1
, exit_info2
,
518 exit_int_info
, exit_int_info_err
),
521 __field( __u32
, exit_code
)
522 __field( __u64
, exit_info1
)
523 __field( __u64
, exit_info2
)
524 __field( __u32
, exit_int_info
)
525 __field( __u32
, exit_int_info_err
)
529 __entry
->exit_code
= exit_code
;
530 __entry
->exit_info1
= exit_info1
;
531 __entry
->exit_info2
= exit_info2
;
532 __entry
->exit_int_info
= exit_int_info
;
533 __entry
->exit_int_info_err
= exit_int_info_err
;
536 TP_printk("reason: %s ext_inf1: 0x%016llx "
537 "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
538 ftrace_print_symbols_seq(p
, __entry
->exit_code
,
539 kvm_x86_ops
->exit_reasons_str
),
540 __entry
->exit_info1
, __entry
->exit_info2
,
541 __entry
->exit_int_info
, __entry
->exit_int_info_err
)
545 * Tracepoint for nested #vmexit because of interrupt pending
547 TRACE_EVENT(kvm_nested_intr_vmexit
,
552 __field( __u64
, rip
)
559 TP_printk("rip: 0x%016llx", __entry
->rip
)
563 * Tracepoint for nested #vmexit because of interrupt pending
565 TRACE_EVENT(kvm_invlpga
,
566 TP_PROTO(__u64 rip
, int asid
, u64 address
),
567 TP_ARGS(rip
, asid
, address
),
570 __field( __u64
, rip
)
572 __field( __u64
, address
)
577 __entry
->asid
= asid
;
578 __entry
->address
= address
;
581 TP_printk("rip: 0x%016llx asid: %d address: 0x%016llx",
582 __entry
->rip
, __entry
->asid
, __entry
->address
)
586 * Tracepoint for nested #vmexit because of interrupt pending
588 TRACE_EVENT(kvm_skinit
,
589 TP_PROTO(__u64 rip
, __u32 slb
),
593 __field( __u64
, rip
)
594 __field( __u32
, slb
)
602 TP_printk("rip: 0x%016llx slb: 0x%08x",
603 __entry
->rip
, __entry
->slb
)
606 #define __print_insn(insn, ilen) ({ \
608 const char *ret = p->buffer + p->len; \
610 for (i = 0; i < ilen; ++i) \
611 trace_seq_printf(p, " %02x", insn[i]); \
612 trace_seq_printf(p, "%c", 0); \
616 #define KVM_EMUL_INSN_F_CR0_PE (1 << 0)
617 #define KVM_EMUL_INSN_F_EFL_VM (1 << 1)
618 #define KVM_EMUL_INSN_F_CS_D (1 << 2)
619 #define KVM_EMUL_INSN_F_CS_L (1 << 3)
621 #define kvm_trace_symbol_emul_flags \
623 { KVM_EMUL_INSN_F_CR0_PE \
624 | KVM_EMUL_INSN_F_EFL_VM, "vm16" }, \
625 { KVM_EMUL_INSN_F_CR0_PE, "prot16" }, \
626 { KVM_EMUL_INSN_F_CR0_PE \
627 | KVM_EMUL_INSN_F_CS_D, "prot32" }, \
628 { KVM_EMUL_INSN_F_CR0_PE \
629 | KVM_EMUL_INSN_F_CS_L, "prot64" }
631 #define kei_decode_mode(mode) ({ \
634 case X86EMUL_MODE_REAL: \
637 case X86EMUL_MODE_VM86: \
638 flags = KVM_EMUL_INSN_F_EFL_VM; \
640 case X86EMUL_MODE_PROT16: \
641 flags = KVM_EMUL_INSN_F_CR0_PE; \
643 case X86EMUL_MODE_PROT32: \
644 flags = KVM_EMUL_INSN_F_CR0_PE \
645 | KVM_EMUL_INSN_F_CS_D; \
647 case X86EMUL_MODE_PROT64: \
648 flags = KVM_EMUL_INSN_F_CR0_PE \
649 | KVM_EMUL_INSN_F_CS_L; \
655 TRACE_EVENT(kvm_emulate_insn
,
656 TP_PROTO(struct kvm_vcpu
*vcpu
, __u8 failed
),
657 TP_ARGS(vcpu
, failed
),
660 __field( __u64
, rip
)
661 __field( __u32
, csbase
)
663 __array( __u8
, insn
, 15 )
664 __field( __u8
, flags
)
665 __field( __u8
, failed
)
669 __entry
->rip
= vcpu
->arch
.emulate_ctxt
.decode
.fetch
.start
;
670 __entry
->csbase
= kvm_x86_ops
->get_segment_base(vcpu
, VCPU_SREG_CS
);
671 __entry
->len
= vcpu
->arch
.emulate_ctxt
.decode
.eip
672 - vcpu
->arch
.emulate_ctxt
.decode
.fetch
.start
;
673 memcpy(__entry
->insn
,
674 vcpu
->arch
.emulate_ctxt
.decode
.fetch
.data
,
676 __entry
->flags
= kei_decode_mode(vcpu
->arch
.emulate_ctxt
.mode
);
677 __entry
->failed
= failed
;
680 TP_printk("%x:%llx:%s (%s)%s",
681 __entry
->csbase
, __entry
->rip
,
682 __print_insn(__entry
->insn
, __entry
->len
),
683 __print_symbolic(__entry
->flags
,
684 kvm_trace_symbol_emul_flags
),
685 __entry
->failed
? " failed" : ""
689 #define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0)
690 #define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1)
692 #endif /* _TRACE_KVM_H */
694 #undef TRACE_INCLUDE_PATH
695 #define TRACE_INCLUDE_PATH arch/x86/kvm
696 #undef TRACE_INCLUDE_FILE
697 #define TRACE_INCLUDE_FILE trace
699 /* This part must be outside protection */
700 #include <trace/define_trace.h>