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
)
142 * Tracepoint for kvm interrupt injection:
144 LTTNG_TRACEPOINT_EVENT(kvm_inj_virq
,
145 TP_PROTO(unsigned int irq
),
149 ctf_integer(unsigned int, irq
, irq
)
154 * Tracepoint for kvm interrupt injection:
156 LTTNG_TRACEPOINT_EVENT(kvm_inj_exception
,
157 TP_PROTO(unsigned exception
, bool has_error
, unsigned error_code
),
158 TP_ARGS(exception
, has_error
, error_code
),
161 ctf_integer(u8
, exception
, exception
)
162 ctf_integer(u8
, has_error
, has_error
)
163 ctf_integer(u32
, error_code
, error_code
)
168 * Tracepoint for page fault.
170 LTTNG_TRACEPOINT_EVENT(kvm_page_fault
,
171 TP_PROTO(unsigned long fault_address
, unsigned int error_code
),
172 TP_ARGS(fault_address
, error_code
),
175 ctf_integer(unsigned long, fault_address
, fault_address
)
176 ctf_integer(unsigned int, error_code
, error_code
)
181 * Tracepoint for guest MSR access.
183 LTTNG_TRACEPOINT_EVENT(kvm_msr
,
184 TP_PROTO(unsigned write
, u32 ecx
, u64 data
, bool exception
),
185 TP_ARGS(write
, ecx
, data
, exception
),
188 ctf_integer(unsigned, write
, write
)
189 ctf_integer(u32
, ecx
, ecx
)
190 ctf_integer(u64
, data
, data
)
191 ctf_integer(u8
, exception
, exception
)
195 #define trace_kvm_msr_read(ecx, data) trace_kvm_msr(0, ecx, data, false)
196 #define trace_kvm_msr_write(ecx, data) trace_kvm_msr(1, ecx, data, false)
197 #define trace_kvm_msr_read_ex(ecx) trace_kvm_msr(0, ecx, 0, true)
198 #define trace_kvm_msr_write_ex(ecx, data) trace_kvm_msr(1, ecx, data, true)
201 * Tracepoint for guest CR access.
203 LTTNG_TRACEPOINT_EVENT(kvm_cr
,
204 TP_PROTO(unsigned int rw
, unsigned int cr
, unsigned long val
),
205 TP_ARGS(rw
, cr
, val
),
208 ctf_integer(unsigned int, rw
, rw
)
209 ctf_integer(unsigned int, cr
, cr
)
210 ctf_integer(unsigned long, val
, val
)
214 #define trace_kvm_cr_read(cr, val) trace_kvm_cr(0, cr, val)
215 #define trace_kvm_cr_write(cr, val) trace_kvm_cr(1, cr, val)
217 LTTNG_TRACEPOINT_EVENT(kvm_pic_set_irq
,
218 TP_PROTO(__u8 chip
, __u8 pin
, __u8 elcr
, __u8 imr
, bool coalesced
),
219 TP_ARGS(chip
, pin
, elcr
, imr
, coalesced
),
222 ctf_integer(__u8
, chip
, chip
)
223 ctf_integer(__u8
, pin
, pin
)
224 ctf_integer(__u8
, elcr
, elcr
)
225 ctf_integer(__u8
, imr
, imr
)
226 ctf_integer(bool, coalesced
, coalesced
)
230 LTTNG_TRACEPOINT_EVENT(kvm_apic_ipi
,
231 TP_PROTO(__u32 icr_low
, __u32 dest_id
),
232 TP_ARGS(icr_low
, dest_id
),
235 ctf_integer(__u32
, icr_low
, icr_low
)
236 ctf_integer(__u32
, dest_id
, dest_id
)
240 LTTNG_TRACEPOINT_EVENT(kvm_apic_accept_irq
,
241 TP_PROTO(__u32 apicid
, __u16 dm
, __u8 tm
, __u8 vec
, bool coalesced
),
242 TP_ARGS(apicid
, dm
, tm
, vec
, coalesced
),
245 ctf_integer(__u32
, apicid
, apicid
)
246 ctf_integer(__u16
, dm
, dm
)
247 ctf_integer(__u8
, tm
, tm
)
248 ctf_integer(__u8
, vec
, vec
)
249 ctf_integer(bool, coalesced
, coalesced
)
253 LTTNG_TRACEPOINT_EVENT(kvm_eoi
,
254 TP_PROTO(struct kvm_lapic
*apic
, int vector
),
255 TP_ARGS(apic
, vector
),
258 ctf_integer(__u32
, apicid
, apic
->vcpu
->vcpu_id
)
259 ctf_integer(int, vector
, vector
)
263 LTTNG_TRACEPOINT_EVENT(kvm_pv_eoi
,
264 TP_PROTO(struct kvm_lapic
*apic
, int vector
),
265 TP_ARGS(apic
, vector
),
268 ctf_integer(__u32
, apicid
, apic
->vcpu
->vcpu_id
)
269 ctf_integer(int, vector
, vector
)
274 * Tracepoint for nested VMRUN
276 LTTNG_TRACEPOINT_EVENT(kvm_nested_vmrun
,
277 TP_PROTO(__u64 rip
, __u64 vmcb
, __u64 nested_rip
, __u32 int_ctl
,
278 __u32 event_inj
, bool npt
),
279 TP_ARGS(rip
, vmcb
, nested_rip
, int_ctl
, event_inj
, npt
),
282 ctf_integer(__u64
, rip
, rip
)
283 ctf_integer(__u64
, vmcb
, vmcb
)
284 ctf_integer(__u64
, nested_rip
, nested_rip
)
285 ctf_integer(__u32
, int_ctl
, int_ctl
)
286 ctf_integer(__u32
, event_inj
, event_inj
)
287 ctf_integer(bool, npt
, npt
)
291 LTTNG_TRACEPOINT_EVENT(kvm_nested_intercepts
,
292 TP_PROTO(__u16 cr_read
, __u16 cr_write
, __u32 exceptions
, __u64 intercept
),
293 TP_ARGS(cr_read
, cr_write
, exceptions
, intercept
),
296 ctf_integer(__u16
, cr_read
, cr_read
)
297 ctf_integer(__u16
, cr_write
, cr_write
)
298 ctf_integer(__u32
, exceptions
, exceptions
)
299 ctf_integer(__u64
, intercept
, intercept
)
303 * Tracepoint for #VMEXIT while nested
305 LTTNG_TRACEPOINT_EVENT(kvm_nested_vmexit
,
306 TP_PROTO(__u64 rip
, __u32 exit_code
,
307 __u64 exit_info1
, __u64 exit_info2
,
308 __u32 exit_int_info
, __u32 exit_int_info_err
, __u32 isa
),
309 TP_ARGS(rip
, exit_code
, exit_info1
, exit_info2
,
310 exit_int_info
, exit_int_info_err
, isa
),
313 ctf_integer(__u64
, rip
, rip
)
314 ctf_integer(__u32
, exit_code
, exit_code
)
315 ctf_integer(__u64
, exit_info1
, exit_info1
)
316 ctf_integer(__u64
, exit_info2
, exit_info2
)
317 ctf_integer(__u32
, exit_int_info
, exit_int_info
)
318 ctf_integer(__u32
, exit_int_info_err
, exit_int_info_err
)
319 ctf_integer(__u32
, isa
, isa
)
324 * Tracepoint for #VMEXIT reinjected to the guest
326 LTTNG_TRACEPOINT_EVENT(kvm_nested_vmexit_inject
,
327 TP_PROTO(__u32 exit_code
,
328 __u64 exit_info1
, __u64 exit_info2
,
329 __u32 exit_int_info
, __u32 exit_int_info_err
, __u32 isa
),
330 TP_ARGS(exit_code
, exit_info1
, exit_info2
,
331 exit_int_info
, exit_int_info_err
, isa
),
334 ctf_integer(__u32
, exit_code
, exit_code
)
335 ctf_integer(__u64
, exit_info1
, exit_info1
)
336 ctf_integer(__u64
, exit_info2
, exit_info2
)
337 ctf_integer(__u32
, exit_int_info
, exit_int_info
)
338 ctf_integer(__u32
, exit_int_info_err
, exit_int_info_err
)
339 ctf_integer(__u32
, isa
, isa
)
344 * Tracepoint for nested #vmexit because of interrupt pending
346 LTTNG_TRACEPOINT_EVENT(kvm_nested_intr_vmexit
,
351 ctf_integer(__u64
, rip
, rip
)
356 * Tracepoint for nested #vmexit because of interrupt pending
358 LTTNG_TRACEPOINT_EVENT(kvm_invlpga
,
359 TP_PROTO(__u64 rip
, int asid
, u64 address
),
360 TP_ARGS(rip
, asid
, address
),
363 ctf_integer(__u64
, rip
, rip
)
364 ctf_integer(int, asid
, asid
)
365 ctf_integer(__u64
, address
, address
)
370 * Tracepoint for nested #vmexit because of interrupt pending
372 LTTNG_TRACEPOINT_EVENT(kvm_skinit
,
373 TP_PROTO(__u64 rip
, __u32 slb
),
377 ctf_integer(__u64
, rip
, rip
)
378 ctf_integer(__u32
, slb
, slb
)
382 #define KVM_EMUL_INSN_F_CR0_PE (1 << 0)
383 #define KVM_EMUL_INSN_F_EFL_VM (1 << 1)
384 #define KVM_EMUL_INSN_F_CS_D (1 << 2)
385 #define KVM_EMUL_INSN_F_CS_L (1 << 3)
387 #define kvm_trace_symbol_emul_flags \
389 { KVM_EMUL_INSN_F_CR0_PE \
390 | KVM_EMUL_INSN_F_EFL_VM, "vm16" }, \
391 { KVM_EMUL_INSN_F_CR0_PE, "prot16" }, \
392 { KVM_EMUL_INSN_F_CR0_PE \
393 | KVM_EMUL_INSN_F_CS_D, "prot32" }, \
394 { KVM_EMUL_INSN_F_CR0_PE \
395 | KVM_EMUL_INSN_F_CS_L, "prot64" }
397 #define kei_decode_mode(mode) ({ \
400 case X86EMUL_MODE_REAL: \
403 case X86EMUL_MODE_VM86: \
404 flags = KVM_EMUL_INSN_F_EFL_VM; \
406 case X86EMUL_MODE_PROT16: \
407 flags = KVM_EMUL_INSN_F_CR0_PE; \
409 case X86EMUL_MODE_PROT32: \
410 flags = KVM_EMUL_INSN_F_CR0_PE \
411 | KVM_EMUL_INSN_F_CS_D; \
413 case X86EMUL_MODE_PROT64: \
414 flags = KVM_EMUL_INSN_F_CR0_PE \
415 | KVM_EMUL_INSN_F_CS_L; \
421 LTTNG_TRACEPOINT_EVENT(kvm_emulate_insn
,
422 TP_PROTO(struct kvm_vcpu
*vcpu
, __u8 failed
),
423 TP_ARGS(vcpu
, failed
),
426 #if (LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0))
427 ctf_integer(__u64
, rip
, vcpu
->arch
.emulate_ctxt
.decode
.fetch
.start
)
428 ctf_integer(__u32
, csbase
, kvm_x86_ops
->get_segment_base(vcpu
, VCPU_SREG_CS
))
429 ctf_integer(__u8
, len
, vcpu
->arch
.emulate_ctxt
.decode
.eip
430 - vcpu
->arch
.emulate_ctxt
.decode
.fetch
.start
)
431 ctf_array(__u8
, insn
, vcpu
->arch
.emulate_ctxt
.decode
.fetch
.data
, 15)
432 #elif (LINUX_VERSION_CODE < KERNEL_VERSION(3,17,0))
433 ctf_integer(__u64
, rip
, vcpu
->arch
.emulate_ctxt
.fetch
.start
)
434 ctf_integer(__u32
, csbase
, kvm_x86_ops
->get_segment_base(vcpu
, VCPU_SREG_CS
))
435 ctf_integer(__u8
, len
, vcpu
->arch
.emulate_ctxt
._eip
436 - vcpu
->arch
.emulate_ctxt
.fetch
.start
)
437 ctf_array(__u8
, insn
, vcpu
->arch
.emulate_ctxt
.fetch
.data
, 15)
439 ctf_integer(__u64
, rip
, vcpu
->arch
.emulate_ctxt
._eip
-
440 (vcpu
->arch
.emulate_ctxt
.fetch
.ptr
-
441 vcpu
->arch
.emulate_ctxt
.fetch
.data
))
442 ctf_integer(__u32
, csbase
, kvm_x86_ops
->get_segment_base(vcpu
, VCPU_SREG_CS
))
443 ctf_integer(__u8
, len
, vcpu
->arch
.emulate_ctxt
.fetch
.ptr
-
444 vcpu
->arch
.emulate_ctxt
.fetch
.data
)
445 ctf_array(__u8
, insn
, vcpu
->arch
.emulate_ctxt
.fetch
.data
, 15)
447 ctf_integer(__u8
, flags
, kei_decode_mode(vcpu
->arch
.emulate_ctxt
.mode
))
448 ctf_integer(__u8
, failed
, failed
)
452 #define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0)
453 #define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1)
455 LTTNG_TRACEPOINT_EVENT(
457 TP_PROTO(gva_t gva
, gpa_t gpa
, bool write
, bool gpa_match
),
458 TP_ARGS(gva
, gpa
, write
, gpa_match
),
461 ctf_integer(gva_t
, gva
, gva
)
462 ctf_integer(gpa_t
, gpa
, gpa
)
463 ctf_integer(bool, write
, write
)
464 ctf_integer(bool, gpa_match
, gpa_match
)
468 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0))
469 LTTNG_TRACEPOINT_EVENT(kvm_write_tsc_offset
,
470 TP_PROTO(unsigned int vcpu_id
, __u64 previous_tsc_offset
,
471 __u64 next_tsc_offset
),
472 TP_ARGS(vcpu_id
, previous_tsc_offset
, next_tsc_offset
),
475 ctf_integer(unsigned int, vcpu_id
, vcpu_id
)
476 ctf_integer(__u64
, previous_tsc_offset
, previous_tsc_offset
)
477 ctf_integer(__u64
, next_tsc_offset
, next_tsc_offset
)
482 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
485 LTTNG_TRACEPOINT_EVENT(kvm_update_master_clock
,
486 TP_PROTO(bool use_master_clock
, unsigned int host_clock
, bool offset_matched
),
487 TP_ARGS(use_master_clock
, host_clock
, offset_matched
),
490 ctf_integer(bool, use_master_clock
, use_master_clock
)
491 ctf_integer(unsigned int, host_clock
, host_clock
)
492 ctf_integer(bool, offset_matched
, offset_matched
)
496 LTTNG_TRACEPOINT_EVENT(kvm_track_tsc
,
497 TP_PROTO(unsigned int vcpu_id
, unsigned int nr_matched
,
498 unsigned int online_vcpus
, bool use_master_clock
,
499 unsigned int host_clock
),
500 TP_ARGS(vcpu_id
, nr_matched
, online_vcpus
, use_master_clock
,
504 ctf_integer(unsigned int, vcpu_id
, vcpu_id
)
505 ctf_integer(unsigned int, nr_vcpus_matched_tsc
, nr_matched
)
506 ctf_integer(unsigned int, online_vcpus
, online_vcpus
)
507 ctf_integer(bool, use_master_clock
, use_master_clock
)
508 ctf_integer(unsigned int, host_clock
, host_clock
)
512 #endif /* CONFIG_X86_64 */
513 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0) */
515 #endif /* LTTNG_TRACE_KVM_H */
517 #undef TRACE_INCLUDE_PATH
518 #define TRACE_INCLUDE_PATH ../instrumentation/events/lttng-module/arch/x86/kvm
519 #undef TRACE_INCLUDE_FILE
520 #define TRACE_INCLUDE_FILE trace
522 /* This part must be outside protection */
523 #include "../../../../../../probes/define_trace.h"