4d8e76316780aad4080dee76a166ec868a421949
[lttng-modules.git] / instrumentation / events / lttng-module / arch / x86 / kvm / trace.h
1 #if !defined(LTTNG_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
2 #define LTTNG_TRACE_KVM_H
3
4 #include <probes/lttng-tracepoint-event.h>
5 #include <asm/vmx.h>
6 #include <asm/svm.h>
7 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
8 #include <asm/clocksource.h>
9 #endif
10 #include <linux/version.h>
11 #include <../arch/x86/kvm/lapic.h>
12 #include <../arch/x86/kvm/kvm_cache_regs.h>
13
14 #undef TRACE_SYSTEM
15 #define TRACE_SYSTEM kvm_x86
16
17 /*
18 * Tracepoint for guest mode entry.
19 */
20 LTTNG_TRACEPOINT_EVENT_MAP(kvm_entry, kvm_x86_entry,
21 TP_PROTO(unsigned int vcpu_id),
22 TP_ARGS(vcpu_id),
23
24 TP_FIELDS(
25 ctf_integer(unsigned int, vcpu_id, vcpu_id)
26 )
27 )
28
29 /*
30 * Tracepoint for hypercall.
31 */
32 LTTNG_TRACEPOINT_EVENT_MAP(kvm_hypercall, kvm_x86_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),
36
37 TP_FIELDS(
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)
43 )
44 )
45
46 /*
47 * Tracepoint for hypercall.
48 */
49 LTTNG_TRACEPOINT_EVENT_MAP(kvm_hv_hypercall, kvm_x86_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),
53
54 TP_FIELDS(
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)
61 )
62 )
63
64 /*
65 * Tracepoint for PIO.
66 */
67 LTTNG_TRACEPOINT_EVENT_MAP(kvm_pio, kvm_x86_pio,
68 TP_PROTO(unsigned int rw, unsigned int port, unsigned int size,
69 unsigned int count),
70 TP_ARGS(rw, port, size, count),
71
72 TP_FIELDS(
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)
77 )
78 )
79
80 /*
81 * Tracepoint for cpuid.
82 */
83 LTTNG_TRACEPOINT_EVENT_MAP(kvm_cpuid, kvm_x86_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),
87
88 TP_FIELDS(
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)
94 )
95 )
96
97 /*
98 * Tracepoint for apic access.
99 */
100 LTTNG_TRACEPOINT_EVENT_MAP(kvm_apic, kvm_x86_apic,
101 TP_PROTO(unsigned int rw, unsigned int reg, unsigned int val),
102 TP_ARGS(rw, reg, val),
103
104 TP_FIELDS(
105 ctf_integer(unsigned int, rw, rw)
106 ctf_integer(unsigned int, reg, reg)
107 ctf_integer(unsigned int, val, val)
108 )
109 )
110
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)
113
114 /*
115 * Tracepoint for kvm guest exit:
116 */
117 LTTNG_TRACEPOINT_EVENT_CODE_MAP(kvm_exit, kvm_x86_exit,
118 TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa),
119 TP_ARGS(exit_reason, vcpu, isa),
120
121 TP_locvar(
122 u64 info1, info2;
123 ),
124
125 TP_code_pre(
126 kvm_x86_ops->get_exit_info(vcpu, &tp_locvar->info1,
127 &tp_locvar->info2);
128 ),
129
130 TP_FIELDS(
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)
136 ),
137
138 TP_code_post()
139 )
140
141 /*
142 * Tracepoint for kvm interrupt injection:
143 */
144 LTTNG_TRACEPOINT_EVENT_MAP(kvm_inj_virq, kvm_x86_inj_virq,
145 TP_PROTO(unsigned int irq),
146 TP_ARGS(irq),
147
148 TP_FIELDS(
149 ctf_integer(unsigned int, irq, irq)
150 )
151 )
152
153 /*
154 * Tracepoint for kvm interrupt injection:
155 */
156 LTTNG_TRACEPOINT_EVENT_MAP(kvm_inj_exception, kvm_x86_inj_exception,
157 TP_PROTO(unsigned exception, bool has_error, unsigned error_code),
158 TP_ARGS(exception, has_error, error_code),
159
160 TP_FIELDS(
161 ctf_integer(u8, exception, exception)
162 ctf_integer(u8, has_error, has_error)
163 ctf_integer(u32, error_code, error_code)
164 )
165 )
166
167 /*
168 * Tracepoint for page fault.
169 */
170 LTTNG_TRACEPOINT_EVENT_MAP(kvm_page_fault, kvm_x86_page_fault,
171 TP_PROTO(unsigned long fault_address, unsigned int error_code),
172 TP_ARGS(fault_address, error_code),
173
174 TP_FIELDS(
175 ctf_integer(unsigned long, fault_address, fault_address)
176 ctf_integer(unsigned int, error_code, error_code)
177 )
178 )
179
180 /*
181 * Tracepoint for guest MSR access.
182 */
183 LTTNG_TRACEPOINT_EVENT_MAP(kvm_msr, kvm_x86_msr,
184 TP_PROTO(unsigned write, u32 ecx, u64 data, bool exception),
185 TP_ARGS(write, ecx, data, exception),
186
187 TP_FIELDS(
188 ctf_integer(unsigned, write, write)
189 ctf_integer(u32, ecx, ecx)
190 ctf_integer(u64, data, data)
191 ctf_integer(u8, exception, exception)
192 )
193 )
194
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)
199
200 /*
201 * Tracepoint for guest CR access.
202 */
203 LTTNG_TRACEPOINT_EVENT_MAP(kvm_cr, kvm_x86_cr,
204 TP_PROTO(unsigned int rw, unsigned int cr, unsigned long val),
205 TP_ARGS(rw, cr, val),
206
207 TP_FIELDS(
208 ctf_integer(unsigned int, rw, rw)
209 ctf_integer(unsigned int, cr, cr)
210 ctf_integer(unsigned long, val, val)
211 )
212 )
213
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)
216
217 LTTNG_TRACEPOINT_EVENT_MAP(kvm_pic_set_irq, kvm_x86_pic_set_irq,
218 TP_PROTO(__u8 chip, __u8 pin, __u8 elcr, __u8 imr, bool coalesced),
219 TP_ARGS(chip, pin, elcr, imr, coalesced),
220
221 TP_FIELDS(
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)
227 )
228 )
229
230 LTTNG_TRACEPOINT_EVENT_MAP(kvm_apic_ipi, kvm_x86_apic_ipi,
231 TP_PROTO(__u32 icr_low, __u32 dest_id),
232 TP_ARGS(icr_low, dest_id),
233
234 TP_FIELDS(
235 ctf_integer(__u32, icr_low, icr_low)
236 ctf_integer(__u32, dest_id, dest_id)
237 )
238 )
239
240 LTTNG_TRACEPOINT_EVENT_MAP(kvm_apic_accept_irq, kvm_x86_apic_accept_irq,
241 TP_PROTO(__u32 apicid, __u16 dm, __u8 tm, __u8 vec, bool coalesced),
242 TP_ARGS(apicid, dm, tm, vec, coalesced),
243
244 TP_FIELDS(
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)
250 )
251 )
252
253 LTTNG_TRACEPOINT_EVENT_MAP(kvm_eoi, kvm_x86_eoi,
254 TP_PROTO(struct kvm_lapic *apic, int vector),
255 TP_ARGS(apic, vector),
256
257 TP_FIELDS(
258 ctf_integer(__u32, apicid, apic->vcpu->vcpu_id)
259 ctf_integer(int, vector, vector)
260 )
261 )
262
263 LTTNG_TRACEPOINT_EVENT_MAP(kvm_pv_eoi, kvm_x86_pv_eoi,
264 TP_PROTO(struct kvm_lapic *apic, int vector),
265 TP_ARGS(apic, vector),
266
267 TP_FIELDS(
268 ctf_integer(__u32, apicid, apic->vcpu->vcpu_id)
269 ctf_integer(int, vector, vector)
270 )
271 )
272
273 /*
274 * Tracepoint for nested VMRUN
275 */
276 LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_vmrun, kvm_x86_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),
280
281 TP_FIELDS(
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)
288 )
289 )
290
291 LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_intercepts, kvm_x86_nested_intercepts,
292 TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u64 intercept),
293 TP_ARGS(cr_read, cr_write, exceptions, intercept),
294
295 TP_FIELDS(
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)
300 )
301 )
302 /*
303 * Tracepoint for #VMEXIT while nested
304 */
305 LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_vmexit, kvm_x86_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),
311
312 TP_FIELDS(
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)
320 )
321 )
322
323 /*
324 * Tracepoint for #VMEXIT reinjected to the guest
325 */
326 LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_vmexit_inject, kvm_x86_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),
332
333 TP_FIELDS(
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)
340 )
341 )
342
343 /*
344 * Tracepoint for nested #vmexit because of interrupt pending
345 */
346 LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_intr_vmexit, kvm_x86_nested_intr_vmexit,
347 TP_PROTO(__u64 rip),
348 TP_ARGS(rip),
349
350 TP_FIELDS(
351 ctf_integer(__u64, rip, rip)
352 )
353 )
354
355 /*
356 * Tracepoint for nested #vmexit because of interrupt pending
357 */
358 LTTNG_TRACEPOINT_EVENT_MAP(kvm_invlpga, kvm_x86_invlpga,
359 TP_PROTO(__u64 rip, int asid, u64 address),
360 TP_ARGS(rip, asid, address),
361
362 TP_FIELDS(
363 ctf_integer(__u64, rip, rip)
364 ctf_integer(int, asid, asid)
365 ctf_integer(__u64, address, address)
366 )
367 )
368
369 /*
370 * Tracepoint for nested #vmexit because of interrupt pending
371 */
372 LTTNG_TRACEPOINT_EVENT_MAP(kvm_skinit, kvm_x86_skinit,
373 TP_PROTO(__u64 rip, __u32 slb),
374 TP_ARGS(rip, slb),
375
376 TP_FIELDS(
377 ctf_integer(__u64, rip, rip)
378 ctf_integer(__u32, slb, slb)
379 )
380 )
381
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)
386
387 #define kvm_trace_symbol_emul_flags \
388 { 0, "real" }, \
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" }
396
397 #define kei_decode_mode(mode) ({ \
398 u8 flags = 0xff; \
399 switch (mode) { \
400 case X86EMUL_MODE_REAL: \
401 flags = 0; \
402 break; \
403 case X86EMUL_MODE_VM86: \
404 flags = KVM_EMUL_INSN_F_EFL_VM; \
405 break; \
406 case X86EMUL_MODE_PROT16: \
407 flags = KVM_EMUL_INSN_F_CR0_PE; \
408 break; \
409 case X86EMUL_MODE_PROT32: \
410 flags = KVM_EMUL_INSN_F_CR0_PE \
411 | KVM_EMUL_INSN_F_CS_D; \
412 break; \
413 case X86EMUL_MODE_PROT64: \
414 flags = KVM_EMUL_INSN_F_CR0_PE \
415 | KVM_EMUL_INSN_F_CS_L; \
416 break; \
417 } \
418 flags; \
419 })
420
421 LTTNG_TRACEPOINT_EVENT_MAP(kvm_emulate_insn, kvm_x86_emulate_insn,
422 TP_PROTO(struct kvm_vcpu *vcpu, __u8 failed),
423 TP_ARGS(vcpu, failed),
424
425 TP_FIELDS(
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)
438 #else
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)
446 #endif
447 ctf_integer(__u8, flags, kei_decode_mode(vcpu->arch.emulate_ctxt.mode))
448 ctf_integer(__u8, failed, failed)
449 )
450 )
451
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)
454
455 LTTNG_TRACEPOINT_EVENT_MAP(
456 vcpu_match_mmio, kvm_x86_vcpu_match_mmio,
457 TP_PROTO(gva_t gva, gpa_t gpa, bool write, bool gpa_match),
458 TP_ARGS(gva, gpa, write, gpa_match),
459
460 TP_FIELDS(
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)
465 )
466 )
467
468 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0))
469 LTTNG_TRACEPOINT_EVENT_MAP(kvm_write_tsc_offset, kvm_x86_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),
473
474 TP_FIELDS(
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)
478 )
479 )
480 #endif
481
482 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0))
483 #ifdef CONFIG_X86_64
484
485 LTTNG_TRACEPOINT_EVENT_MAP(kvm_update_master_clock, kvm_x86_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),
488
489 TP_FIELDS(
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)
493 )
494 )
495
496 LTTNG_TRACEPOINT_EVENT_MAP(kvm_track_tsc, kvm_x86_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,
501 host_clock),
502
503 TP_FIELDS(
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)
509 )
510 )
511
512 #endif /* CONFIG_X86_64 */
513 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0) */
514
515 #endif /* LTTNG_TRACE_KVM_H */
516
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
521
522 /* This part must be outside protection */
523 #include <probes/define_trace.h>
This page took 0.038333 seconds and 3 git commands to generate.