1 #if !defined(LTTNG_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
2 #define LTTNG_TRACE_KVM_H
4 #include "../../../../../../probes/lttng-tracepoint-event.h"
7 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
8 #include <asm/clocksource.h>
10 #include <linux/version.h>
11 #include <../arch/x86/kvm/lapic.h>
12 #include <../arch/x86/kvm/kvm_cache_regs.h>
15 #define TRACE_SYSTEM kvm
18 * Tracepoint for guest mode entry.
20 LTTNG_TRACEPOINT_EVENT(kvm_entry
,
21 TP_PROTO(unsigned int vcpu_id
),
25 ctf_integer(unsigned int, vcpu_id
, vcpu_id
)
30 * Tracepoint for hypercall.
32 LTTNG_TRACEPOINT_EVENT(kvm_hypercall
,
33 TP_PROTO(unsigned long nr
, unsigned long a0
, unsigned long a1
,
34 unsigned long a2
, unsigned long a3
),
35 TP_ARGS(nr
, a0
, a1
, a2
, a3
),
38 ctf_integer(unsigned long, nr
, nr
)
39 ctf_integer(unsigned long, a0
, a0
)
40 ctf_integer(unsigned long, a1
, a1
)
41 ctf_integer(unsigned long, a2
, a2
)
42 ctf_integer(unsigned long, a3
, a3
)
47 * Tracepoint for hypercall.
49 LTTNG_TRACEPOINT_EVENT(kvm_hv_hypercall
,
50 TP_PROTO(__u16 code
, bool fast
, __u16 rep_cnt
, __u16 rep_idx
,
51 __u64 ingpa
, __u64 outgpa
),
52 TP_ARGS(code
, fast
, rep_cnt
, rep_idx
, ingpa
, outgpa
),
55 ctf_integer(__u16
, rep_cnt
, rep_cnt
)
56 ctf_integer(__u16
, rep_idx
, rep_idx
)
57 ctf_integer(__u64
, ingpa
, ingpa
)
58 ctf_integer(__u64
, outgpa
, outgpa
)
59 ctf_integer(__u16
, code
, code
)
60 ctf_integer(bool, fast
, fast
)
67 LTTNG_TRACEPOINT_EVENT(kvm_pio
,
68 TP_PROTO(unsigned int rw
, unsigned int port
, unsigned int size
,
70 TP_ARGS(rw
, port
, size
, count
),
73 ctf_integer(unsigned int, rw
, rw
)
74 ctf_integer(unsigned int, port
, port
)
75 ctf_integer(unsigned int, size
, size
)
76 ctf_integer(unsigned int, count
, count
)
81 * Tracepoint for cpuid.
83 LTTNG_TRACEPOINT_EVENT(kvm_cpuid
,
84 TP_PROTO(unsigned int function
, unsigned long rax
, unsigned long rbx
,
85 unsigned long rcx
, unsigned long rdx
),
86 TP_ARGS(function
, rax
, rbx
, rcx
, rdx
),
89 ctf_integer(unsigned int, function
, function
)
90 ctf_integer(unsigned long, rax
, rax
)
91 ctf_integer(unsigned long, rbx
, rbx
)
92 ctf_integer(unsigned long, rcx
, rcx
)
93 ctf_integer(unsigned long, rdx
, rdx
)
98 * Tracepoint for apic access.
100 LTTNG_TRACEPOINT_EVENT(kvm_apic
,
101 TP_PROTO(unsigned int rw
, unsigned int reg
, unsigned int val
),
102 TP_ARGS(rw
, reg
, val
),
105 ctf_integer(unsigned int, rw
, rw
)
106 ctf_integer(unsigned int, reg
, reg
)
107 ctf_integer(unsigned int, val
, val
)
111 #define trace_kvm_apic_read(reg, val) trace_kvm_apic(0, reg, val)
112 #define trace_kvm_apic_write(reg, val) trace_kvm_apic(1, reg, val)
115 * Tracepoint for kvm guest exit:
117 LTTNG_TRACEPOINT_EVENT_CODE(kvm_exit
,
118 TP_PROTO(unsigned int exit_reason
, struct kvm_vcpu
*vcpu
, u32 isa
),
119 TP_ARGS(exit_reason
, vcpu
, isa
),
126 kvm_x86_ops
->get_exit_info(vcpu
, &tp_locvar
->info1
,
131 ctf_integer(unsigned int, exit_reason
, exit_reason
)
132 ctf_integer(unsigned long, guest_rip
, kvm_rip_read(vcpu
))
133 ctf_integer(u32
, isa
, isa
)
134 ctf_integer(u64
, info1
, tp_locvar
->info1
)
135 ctf_integer(u64
, info2
, tp_locvar
->info2
)
140 * Tracepoint for kvm interrupt injection:
142 LTTNG_TRACEPOINT_EVENT(kvm_inj_virq
,
143 TP_PROTO(unsigned int irq
),
147 ctf_integer(unsigned int, irq
, irq
)
152 * Tracepoint for kvm interrupt injection:
154 LTTNG_TRACEPOINT_EVENT(kvm_inj_exception
,
155 TP_PROTO(unsigned exception
, bool has_error
, unsigned error_code
),
156 TP_ARGS(exception
, has_error
, error_code
),
159 ctf_integer(u8
, exception
, exception
)
160 ctf_integer(u8
, has_error
, has_error
)
161 ctf_integer(u32
, error_code
, error_code
)
166 * Tracepoint for page fault.
168 LTTNG_TRACEPOINT_EVENT(kvm_page_fault
,
169 TP_PROTO(unsigned long fault_address
, unsigned int error_code
),
170 TP_ARGS(fault_address
, error_code
),
173 ctf_integer(unsigned long, fault_address
, fault_address
)
174 ctf_integer(unsigned int, error_code
, error_code
)
179 * Tracepoint for guest MSR access.
181 LTTNG_TRACEPOINT_EVENT(kvm_msr
,
182 TP_PROTO(unsigned write
, u32 ecx
, u64 data
, bool exception
),
183 TP_ARGS(write
, ecx
, data
, exception
),
186 ctf_integer(unsigned, write
, write
)
187 ctf_integer(u32
, ecx
, ecx
)
188 ctf_integer(u64
, data
, data
)
189 ctf_integer(u8
, exception
, exception
)
193 #define trace_kvm_msr_read(ecx, data) trace_kvm_msr(0, ecx, data, false)
194 #define trace_kvm_msr_write(ecx, data) trace_kvm_msr(1, ecx, data, false)
195 #define trace_kvm_msr_read_ex(ecx) trace_kvm_msr(0, ecx, 0, true)
196 #define trace_kvm_msr_write_ex(ecx, data) trace_kvm_msr(1, ecx, data, true)
199 * Tracepoint for guest CR access.
201 LTTNG_TRACEPOINT_EVENT(kvm_cr
,
202 TP_PROTO(unsigned int rw
, unsigned int cr
, unsigned long val
),
203 TP_ARGS(rw
, cr
, val
),
206 ctf_integer(unsigned int, rw
, rw
)
207 ctf_integer(unsigned int, cr
, cr
)
208 ctf_integer(unsigned long, val
, val
)
212 #define trace_kvm_cr_read(cr, val) trace_kvm_cr(0, cr, val)
213 #define trace_kvm_cr_write(cr, val) trace_kvm_cr(1, cr, val)
215 LTTNG_TRACEPOINT_EVENT(kvm_pic_set_irq
,
216 TP_PROTO(__u8 chip
, __u8 pin
, __u8 elcr
, __u8 imr
, bool coalesced
),
217 TP_ARGS(chip
, pin
, elcr
, imr
, coalesced
),
220 ctf_integer(__u8
, chip
, chip
)
221 ctf_integer(__u8
, pin
, pin
)
222 ctf_integer(__u8
, elcr
, elcr
)
223 ctf_integer(__u8
, imr
, imr
)
224 ctf_integer(bool, coalesced
, coalesced
)
228 LTTNG_TRACEPOINT_EVENT(kvm_apic_ipi
,
229 TP_PROTO(__u32 icr_low
, __u32 dest_id
),
230 TP_ARGS(icr_low
, dest_id
),
233 ctf_integer(__u32
, icr_low
, icr_low
)
234 ctf_integer(__u32
, dest_id
, dest_id
)
238 LTTNG_TRACEPOINT_EVENT(kvm_apic_accept_irq
,
239 TP_PROTO(__u32 apicid
, __u16 dm
, __u8 tm
, __u8 vec
, bool coalesced
),
240 TP_ARGS(apicid
, dm
, tm
, vec
, coalesced
),
243 ctf_integer(__u32
, apicid
, apicid
)
244 ctf_integer(__u16
, dm
, dm
)
245 ctf_integer(__u8
, tm
, tm
)
246 ctf_integer(__u8
, vec
, vec
)
247 ctf_integer(bool, coalesced
, coalesced
)
251 LTTNG_TRACEPOINT_EVENT(kvm_eoi
,
252 TP_PROTO(struct kvm_lapic
*apic
, int vector
),
253 TP_ARGS(apic
, vector
),
256 ctf_integer(__u32
, apicid
, apic
->vcpu
->vcpu_id
)
257 ctf_integer(int, vector
, vector
)
261 LTTNG_TRACEPOINT_EVENT(kvm_pv_eoi
,
262 TP_PROTO(struct kvm_lapic
*apic
, int vector
),
263 TP_ARGS(apic
, vector
),
266 ctf_integer(__u32
, apicid
, apic
->vcpu
->vcpu_id
)
267 ctf_integer(int, vector
, vector
)
272 * Tracepoint for nested VMRUN
274 LTTNG_TRACEPOINT_EVENT(kvm_nested_vmrun
,
275 TP_PROTO(__u64 rip
, __u64 vmcb
, __u64 nested_rip
, __u32 int_ctl
,
276 __u32 event_inj
, bool npt
),
277 TP_ARGS(rip
, vmcb
, nested_rip
, int_ctl
, event_inj
, npt
),
280 ctf_integer(__u64
, rip
, rip
)
281 ctf_integer(__u64
, vmcb
, vmcb
)
282 ctf_integer(__u64
, nested_rip
, nested_rip
)
283 ctf_integer(__u32
, int_ctl
, int_ctl
)
284 ctf_integer(__u32
, event_inj
, event_inj
)
285 ctf_integer(bool, npt
, npt
)
289 LTTNG_TRACEPOINT_EVENT(kvm_nested_intercepts
,
290 TP_PROTO(__u16 cr_read
, __u16 cr_write
, __u32 exceptions
, __u64 intercept
),
291 TP_ARGS(cr_read
, cr_write
, exceptions
, intercept
),
294 ctf_integer(__u16
, cr_read
, cr_read
)
295 ctf_integer(__u16
, cr_write
, cr_write
)
296 ctf_integer(__u32
, exceptions
, exceptions
)
297 ctf_integer(__u64
, intercept
, intercept
)
301 * Tracepoint for #VMEXIT while nested
303 LTTNG_TRACEPOINT_EVENT(kvm_nested_vmexit
,
304 TP_PROTO(__u64 rip
, __u32 exit_code
,
305 __u64 exit_info1
, __u64 exit_info2
,
306 __u32 exit_int_info
, __u32 exit_int_info_err
, __u32 isa
),
307 TP_ARGS(rip
, exit_code
, exit_info1
, exit_info2
,
308 exit_int_info
, exit_int_info_err
, isa
),
311 ctf_integer(__u64
, rip
, rip
)
312 ctf_integer(__u32
, exit_code
, exit_code
)
313 ctf_integer(__u64
, exit_info1
, exit_info1
)
314 ctf_integer(__u64
, exit_info2
, exit_info2
)
315 ctf_integer(__u32
, exit_int_info
, exit_int_info
)
316 ctf_integer(__u32
, exit_int_info_err
, exit_int_info_err
)
317 ctf_integer(__u32
, isa
, isa
)
322 * Tracepoint for #VMEXIT reinjected to the guest
324 LTTNG_TRACEPOINT_EVENT(kvm_nested_vmexit_inject
,
325 TP_PROTO(__u32 exit_code
,
326 __u64 exit_info1
, __u64 exit_info2
,
327 __u32 exit_int_info
, __u32 exit_int_info_err
, __u32 isa
),
328 TP_ARGS(exit_code
, exit_info1
, exit_info2
,
329 exit_int_info
, exit_int_info_err
, isa
),
332 ctf_integer(__u32
, exit_code
, exit_code
)
333 ctf_integer(__u64
, exit_info1
, exit_info1
)
334 ctf_integer(__u64
, exit_info2
, exit_info2
)
335 ctf_integer(__u32
, exit_int_info
, exit_int_info
)
336 ctf_integer(__u32
, exit_int_info_err
, exit_int_info_err
)
337 ctf_integer(__u32
, isa
, isa
)
342 * Tracepoint for nested #vmexit because of interrupt pending
344 LTTNG_TRACEPOINT_EVENT(kvm_nested_intr_vmexit
,
349 ctf_integer(__u64
, rip
, rip
)
354 * Tracepoint for nested #vmexit because of interrupt pending
356 LTTNG_TRACEPOINT_EVENT(kvm_invlpga
,
357 TP_PROTO(__u64 rip
, int asid
, u64 address
),
358 TP_ARGS(rip
, asid
, address
),
361 ctf_integer(__u64
, rip
, rip
)
362 ctf_integer(int, asid
, asid
)
363 ctf_integer(__u64
, address
, address
)
368 * Tracepoint for nested #vmexit because of interrupt pending
370 LTTNG_TRACEPOINT_EVENT(kvm_skinit
,
371 TP_PROTO(__u64 rip
, __u32 slb
),
375 ctf_integer(__u64
, rip
, rip
)
376 ctf_integer(__u32
, slb
, slb
)
380 #define KVM_EMUL_INSN_F_CR0_PE (1 << 0)
381 #define KVM_EMUL_INSN_F_EFL_VM (1 << 1)
382 #define KVM_EMUL_INSN_F_CS_D (1 << 2)
383 #define KVM_EMUL_INSN_F_CS_L (1 << 3)
385 #define kvm_trace_symbol_emul_flags \
387 { KVM_EMUL_INSN_F_CR0_PE \
388 | KVM_EMUL_INSN_F_EFL_VM, "vm16" }, \
389 { KVM_EMUL_INSN_F_CR0_PE, "prot16" }, \
390 { KVM_EMUL_INSN_F_CR0_PE \
391 | KVM_EMUL_INSN_F_CS_D, "prot32" }, \
392 { KVM_EMUL_INSN_F_CR0_PE \
393 | KVM_EMUL_INSN_F_CS_L, "prot64" }
395 #define kei_decode_mode(mode) ({ \
398 case X86EMUL_MODE_REAL: \
401 case X86EMUL_MODE_VM86: \
402 flags = KVM_EMUL_INSN_F_EFL_VM; \
404 case X86EMUL_MODE_PROT16: \
405 flags = KVM_EMUL_INSN_F_CR0_PE; \
407 case X86EMUL_MODE_PROT32: \
408 flags = KVM_EMUL_INSN_F_CR0_PE \
409 | KVM_EMUL_INSN_F_CS_D; \
411 case X86EMUL_MODE_PROT64: \
412 flags = KVM_EMUL_INSN_F_CR0_PE \
413 | KVM_EMUL_INSN_F_CS_L; \
419 LTTNG_TRACEPOINT_EVENT(kvm_emulate_insn
,
420 TP_PROTO(struct kvm_vcpu
*vcpu
, __u8 failed
),
421 TP_ARGS(vcpu
, failed
),
424 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0))
425 ctf_integer(__u64
, rip
, vcpu
->arch
.emulate_ctxt
.decode
.fetch
.start
)
426 ctf_integer(__u32
, csbase
, kvm_x86_ops
->get_segment_base(vcpu
, VCPU_SREG_CS
))
427 ctf_integer(__u8
, len
, vcpu
->arch
.emulate_ctxt
.decode
.eip
428 - vcpu
->arch
.emulate_ctxt
.decode
.fetch
.start
)
429 ctf_array(__u8
, insn
, vcpu
->arch
.emulate_ctxt
.decode
.fetch
.data
, 15)
430 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(3,17,0))
431 ctf_integer(__u64
, rip
, vcpu
->arch
.emulate_ctxt
.fetch
.start
)
432 ctf_integer(__u32
, csbase
, kvm_x86_ops
->get_segment_base(vcpu
, VCPU_SREG_CS
))
433 ctf_integer(__u8
, len
, vcpu
->arch
.emulate_ctxt
._eip
434 - vcpu
->arch
.emulate_ctxt
.fetch
.start
)
435 ctf_array(__u8
, insn
, vcpu
->arch
.emulate_ctxt
.fetch
.data
, 15)
437 ctf_integer(__u64
, rip
, vcpu
->arch
.emulate_ctxt
._eip
-
438 (vcpu
->arch
.emulate_ctxt
.fetch
.ptr
-
439 vcpu
->arch
.emulate_ctxt
.fetch
.data
))
440 ctf_integer(__u32
, csbase
, kvm_x86_ops
->get_segment_base(vcpu
, VCPU_SREG_CS
))
441 ctf_integer(__u8
, len
, vcpu
->arch
.emulate_ctxt
.fetch
.ptr
-
442 vcpu
->arch
.emulate_ctxt
.fetch
.data
)
443 ctf_array(__u8
, insn
, vcpu
->arch
.emulate_ctxt
.fetch
.data
, 15)
445 ctf_integer(__u8
, flags
, kei_decode_mode(vcpu
->arch
.emulate_ctxt
.mode
))
446 ctf_integer(__u8
, failed
, failed
)
450 #define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0)
451 #define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1)
453 LTTNG_TRACEPOINT_EVENT(
455 TP_PROTO(gva_t gva
, gpa_t gpa
, bool write
, bool gpa_match
),
456 TP_ARGS(gva
, gpa
, write
, gpa_match
),
459 ctf_integer(gva_t
, gva
, gva
)
460 ctf_integer(gpa_t
, gpa
, gpa
)
461 ctf_integer(bool, write
, write
)
462 ctf_integer(bool, gpa_match
, gpa_match
)
466 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0))
467 LTTNG_TRACEPOINT_EVENT(kvm_write_tsc_offset
,
468 TP_PROTO(unsigned int vcpu_id
, __u64 previous_tsc_offset
,
469 __u64 next_tsc_offset
),
470 TP_ARGS(vcpu_id
, previous_tsc_offset
, next_tsc_offset
),
473 ctf_integer(unsigned int, vcpu_id
, vcpu_id
)
474 ctf_integer(__u64
, previous_tsc_offset
, previous_tsc_offset
)
475 ctf_integer(__u64
, next_tsc_offset
, next_tsc_offset
)
480 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
483 LTTNG_TRACEPOINT_EVENT(kvm_update_master_clock
,
484 TP_PROTO(bool use_master_clock
, unsigned int host_clock
, bool offset_matched
),
485 TP_ARGS(use_master_clock
, host_clock
, offset_matched
),
488 ctf_integer(bool, use_master_clock
, use_master_clock
)
489 ctf_integer(unsigned int, host_clock
, host_clock
)
490 ctf_integer(bool, offset_matched
, offset_matched
)
494 LTTNG_TRACEPOINT_EVENT(kvm_track_tsc
,
495 TP_PROTO(unsigned int vcpu_id
, unsigned int nr_matched
,
496 unsigned int online_vcpus
, bool use_master_clock
,
497 unsigned int host_clock
),
498 TP_ARGS(vcpu_id
, nr_matched
, online_vcpus
, use_master_clock
,
502 ctf_integer(unsigned int, vcpu_id
, vcpu_id
)
503 ctf_integer(unsigned int, nr_vcpus_matched_tsc
, nr_matched
)
504 ctf_integer(unsigned int, online_vcpus
, online_vcpus
)
505 ctf_integer(bool, use_master_clock
, use_master_clock
)
506 ctf_integer(unsigned int, host_clock
, host_clock
)
510 #endif /* CONFIG_X86_64 */
511 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0) */
513 #endif /* LTTNG_TRACE_KVM_H */
515 #undef TRACE_INCLUDE_PATH
516 #define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module/arch/x86/kvm
517 #undef TRACE_INCLUDE_FILE
518 #define TRACE_INCLUDE_FILE trace
520 /* This part must be outside protection */
521 #include "../../../../../../probes/define_trace.h"