Update README.md for supported kernel
[lttng-modules.git] / instrumentation / events / lttng-module / arch / x86 / kvm / trace.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #if !defined(LTTNG_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
3 #define LTTNG_TRACE_KVM_H
4
5 #include <probes/lttng-tracepoint-event.h>
6 #include <asm/vmx.h>
7 #include <asm/svm.h>
8 #include <asm/clocksource.h>
9 #include <../arch/x86/kvm/lapic.h>
10 #include <../arch/x86/kvm/kvm_cache_regs.h>
11
12 #undef TRACE_SYSTEM
13 #define TRACE_SYSTEM kvm_x86
14
15 /*
16 * Tracepoint for guest mode entry.
17 */
18 LTTNG_TRACEPOINT_EVENT_MAP(kvm_entry, kvm_x86_entry,
19 TP_PROTO(unsigned int vcpu_id),
20 TP_ARGS(vcpu_id),
21
22 TP_FIELDS(
23 ctf_integer(unsigned int, vcpu_id, vcpu_id)
24 )
25 )
26
27 /*
28 * Tracepoint for hypercall.
29 */
30 LTTNG_TRACEPOINT_EVENT_MAP(kvm_hypercall, kvm_x86_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),
34
35 TP_FIELDS(
36 ctf_integer(unsigned long, nr, nr)
37 ctf_integer(unsigned long, a0, a0)
38 ctf_integer(unsigned long, a1, a1)
39 ctf_integer(unsigned long, a2, a2)
40 ctf_integer(unsigned long, a3, a3)
41 )
42 )
43
44 /*
45 * Tracepoint for hypercall.
46 */
47 LTTNG_TRACEPOINT_EVENT_MAP(kvm_hv_hypercall, kvm_x86_hv_hypercall,
48 TP_PROTO(__u16 code, bool fast, __u16 rep_cnt, __u16 rep_idx,
49 __u64 ingpa, __u64 outgpa),
50 TP_ARGS(code, fast, rep_cnt, rep_idx, ingpa, outgpa),
51
52 TP_FIELDS(
53 ctf_integer(__u16, rep_cnt, rep_cnt)
54 ctf_integer(__u16, rep_idx, rep_idx)
55 ctf_integer(__u64, ingpa, ingpa)
56 ctf_integer(__u64, outgpa, outgpa)
57 ctf_integer(__u16, code, code)
58 ctf_integer(bool, fast, fast)
59 )
60 )
61
62 /*
63 * Tracepoint for PIO.
64 */
65 LTTNG_TRACEPOINT_EVENT_MAP(kvm_pio, kvm_x86_pio,
66 TP_PROTO(unsigned int rw, unsigned int port, unsigned int size,
67 unsigned int count),
68 TP_ARGS(rw, port, size, count),
69
70 TP_FIELDS(
71 ctf_integer(unsigned int, rw, rw)
72 ctf_integer(unsigned int, port, port)
73 ctf_integer(unsigned int, size, size)
74 ctf_integer(unsigned int, count, count)
75 )
76 )
77
78 /*
79 * Tracepoint for cpuid.
80 */
81 LTTNG_TRACEPOINT_EVENT_MAP(kvm_cpuid, kvm_x86_cpuid,
82 TP_PROTO(unsigned int function, unsigned long rax, unsigned long rbx,
83 unsigned long rcx, unsigned long rdx),
84 TP_ARGS(function, rax, rbx, rcx, rdx),
85
86 TP_FIELDS(
87 ctf_integer(unsigned int, function, function)
88 ctf_integer(unsigned long, rax, rax)
89 ctf_integer(unsigned long, rbx, rbx)
90 ctf_integer(unsigned long, rcx, rcx)
91 ctf_integer(unsigned long, rdx, rdx)
92 )
93 )
94
95 /*
96 * Tracepoint for apic access.
97 */
98 LTTNG_TRACEPOINT_EVENT_MAP(kvm_apic, kvm_x86_apic,
99 TP_PROTO(unsigned int rw, unsigned int reg, unsigned int val),
100 TP_ARGS(rw, reg, val),
101
102 TP_FIELDS(
103 ctf_integer(unsigned int, rw, rw)
104 ctf_integer(unsigned int, reg, reg)
105 ctf_integer(unsigned int, val, val)
106 )
107 )
108
109 #define trace_kvm_apic_read(reg, val) trace_kvm_apic(0, reg, val)
110 #define trace_kvm_apic_write(reg, val) trace_kvm_apic(1, reg, val)
111
112 /*
113 * Tracepoint for kvm guest exit:
114 */
115 LTTNG_TRACEPOINT_EVENT_CODE_MAP(kvm_exit, kvm_x86_exit,
116 TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa),
117 TP_ARGS(exit_reason, vcpu, isa),
118
119 TP_locvar(
120 u64 info1, info2;
121 ),
122
123 TP_code_pre(
124 kvm_x86_ops.get_exit_info(vcpu, &tp_locvar->info1,
125 &tp_locvar->info2);
126 ),
127
128 TP_FIELDS(
129 ctf_integer(unsigned int, exit_reason, exit_reason)
130 ctf_integer(unsigned long, guest_rip, kvm_rip_read(vcpu))
131 ctf_integer(u32, isa, isa)
132 ctf_integer(u64, info1, tp_locvar->info1)
133 ctf_integer(u64, info2, tp_locvar->info2)
134 ),
135
136 TP_code_post()
137 )
138
139 /*
140 * Tracepoint for kvm interrupt injection:
141 */
142 LTTNG_TRACEPOINT_EVENT_MAP(kvm_inj_virq, kvm_x86_inj_virq,
143 TP_PROTO(unsigned int irq),
144 TP_ARGS(irq),
145
146 TP_FIELDS(
147 ctf_integer(unsigned int, irq, irq)
148 )
149 )
150
151 /*
152 * Tracepoint for kvm interrupt injection:
153 */
154 LTTNG_TRACEPOINT_EVENT_MAP(kvm_inj_exception, kvm_x86_inj_exception,
155 TP_PROTO(unsigned exception, bool has_error, unsigned error_code),
156 TP_ARGS(exception, has_error, error_code),
157
158 TP_FIELDS(
159 ctf_integer(u8, exception, exception)
160 ctf_integer(u8, has_error, has_error)
161 ctf_integer(u32, error_code, error_code)
162 )
163 )
164
165 /*
166 * Tracepoint for page fault.
167 */
168 LTTNG_TRACEPOINT_EVENT_MAP(kvm_page_fault, kvm_x86_page_fault,
169 TP_PROTO(unsigned long fault_address, unsigned int error_code),
170 TP_ARGS(fault_address, error_code),
171
172 TP_FIELDS(
173 ctf_integer_hex(unsigned long, fault_address, fault_address)
174 ctf_integer(unsigned int, error_code, error_code)
175 )
176 )
177
178 /*
179 * Tracepoint for guest MSR access.
180 */
181 LTTNG_TRACEPOINT_EVENT_MAP(kvm_msr, kvm_x86_msr,
182 TP_PROTO(unsigned write, u32 ecx, u64 data, bool exception),
183 TP_ARGS(write, ecx, data, exception),
184
185 TP_FIELDS(
186 ctf_integer(unsigned, write, write)
187 ctf_integer(u32, ecx, ecx)
188 ctf_integer(u64, data, data)
189 ctf_integer(u8, exception, exception)
190 )
191 )
192
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)
197
198 /*
199 * Tracepoint for guest CR access.
200 */
201 LTTNG_TRACEPOINT_EVENT_MAP(kvm_cr, kvm_x86_cr,
202 TP_PROTO(unsigned int rw, unsigned int cr, unsigned long val),
203 TP_ARGS(rw, cr, val),
204
205 TP_FIELDS(
206 ctf_integer(unsigned int, rw, rw)
207 ctf_integer(unsigned int, cr, cr)
208 ctf_integer(unsigned long, val, val)
209 )
210 )
211
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)
214
215 LTTNG_TRACEPOINT_EVENT_MAP(kvm_pic_set_irq, kvm_x86_pic_set_irq,
216 TP_PROTO(__u8 chip, __u8 pin, __u8 elcr, __u8 imr, bool coalesced),
217 TP_ARGS(chip, pin, elcr, imr, coalesced),
218
219 TP_FIELDS(
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)
225 )
226 )
227
228 LTTNG_TRACEPOINT_EVENT_MAP(kvm_apic_ipi, kvm_x86_apic_ipi,
229 TP_PROTO(__u32 icr_low, __u32 dest_id),
230 TP_ARGS(icr_low, dest_id),
231
232 TP_FIELDS(
233 ctf_integer(__u32, icr_low, icr_low)
234 ctf_integer(__u32, dest_id, dest_id)
235 )
236 )
237
238 LTTNG_TRACEPOINT_EVENT_MAP(kvm_apic_accept_irq, kvm_x86_apic_accept_irq,
239 TP_PROTO(__u32 apicid, __u16 dm, __u8 tm, __u8 vec, bool coalesced),
240 TP_ARGS(apicid, dm, tm, vec, coalesced),
241
242 TP_FIELDS(
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)
248 )
249 )
250
251 LTTNG_TRACEPOINT_EVENT_MAP(kvm_eoi, kvm_x86_eoi,
252 TP_PROTO(struct kvm_lapic *apic, int vector),
253 TP_ARGS(apic, vector),
254
255 TP_FIELDS(
256 ctf_integer(__u32, apicid, apic->vcpu->vcpu_id)
257 ctf_integer(int, vector, vector)
258 )
259 )
260
261 LTTNG_TRACEPOINT_EVENT_MAP(kvm_pv_eoi, kvm_x86_pv_eoi,
262 TP_PROTO(struct kvm_lapic *apic, int vector),
263 TP_ARGS(apic, vector),
264
265 TP_FIELDS(
266 ctf_integer(__u32, apicid, apic->vcpu->vcpu_id)
267 ctf_integer(int, vector, vector)
268 )
269 )
270
271 /*
272 * Tracepoint for nested VMRUN
273 */
274 LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_vmrun, kvm_x86_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),
278
279 TP_FIELDS(
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)
286 )
287 )
288
289 LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_intercepts, kvm_x86_nested_intercepts,
290 TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u64 intercept),
291 TP_ARGS(cr_read, cr_write, exceptions, intercept),
292
293 TP_FIELDS(
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)
298 )
299 )
300 /*
301 * Tracepoint for #VMEXIT while nested
302 */
303 LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_vmexit, kvm_x86_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),
309
310 TP_FIELDS(
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)
318 )
319 )
320
321 /*
322 * Tracepoint for #VMEXIT reinjected to the guest
323 */
324 LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_vmexit_inject, kvm_x86_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),
330
331 TP_FIELDS(
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)
338 )
339 )
340
341 /*
342 * Tracepoint for nested #vmexit because of interrupt pending
343 */
344 LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_intr_vmexit, kvm_x86_nested_intr_vmexit,
345 TP_PROTO(__u64 rip),
346 TP_ARGS(rip),
347
348 TP_FIELDS(
349 ctf_integer(__u64, rip, rip)
350 )
351 )
352
353 /*
354 * Tracepoint for nested #vmexit because of interrupt pending
355 */
356 LTTNG_TRACEPOINT_EVENT_MAP(kvm_invlpga, kvm_x86_invlpga,
357 TP_PROTO(__u64 rip, int asid, u64 address),
358 TP_ARGS(rip, asid, address),
359
360 TP_FIELDS(
361 ctf_integer(__u64, rip, rip)
362 ctf_integer(int, asid, asid)
363 ctf_integer_hex(__u64, address, address)
364 )
365 )
366
367 /*
368 * Tracepoint for nested #vmexit because of interrupt pending
369 */
370 LTTNG_TRACEPOINT_EVENT_MAP(kvm_skinit, kvm_x86_skinit,
371 TP_PROTO(__u64 rip, __u32 slb),
372 TP_ARGS(rip, slb),
373
374 TP_FIELDS(
375 ctf_integer(__u64, rip, rip)
376 ctf_integer(__u32, slb, slb)
377 )
378 )
379
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)
384
385 #define kvm_trace_symbol_emul_flags \
386 { 0, "real" }, \
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" }
394
395 #define kei_decode_mode(mode) ({ \
396 u8 flags = 0xff; \
397 switch (mode) { \
398 case X86EMUL_MODE_REAL: \
399 flags = 0; \
400 break; \
401 case X86EMUL_MODE_VM86: \
402 flags = KVM_EMUL_INSN_F_EFL_VM; \
403 break; \
404 case X86EMUL_MODE_PROT16: \
405 flags = KVM_EMUL_INSN_F_CR0_PE; \
406 break; \
407 case X86EMUL_MODE_PROT32: \
408 flags = KVM_EMUL_INSN_F_CR0_PE \
409 | KVM_EMUL_INSN_F_CS_D; \
410 break; \
411 case X86EMUL_MODE_PROT64: \
412 flags = KVM_EMUL_INSN_F_CR0_PE \
413 | KVM_EMUL_INSN_F_CS_L; \
414 break; \
415 } \
416 flags; \
417 })
418
419 LTTNG_TRACEPOINT_EVENT_MAP(kvm_emulate_insn, kvm_x86_emulate_insn,
420 TP_PROTO(struct kvm_vcpu *vcpu, __u8 failed),
421 TP_ARGS(vcpu, failed),
422
423 TP_FIELDS(
424 ctf_integer(__u64, rip, vcpu->arch.emulate_ctxt->_eip -
425 (vcpu->arch.emulate_ctxt->fetch.ptr -
426 vcpu->arch.emulate_ctxt->fetch.data))
427 ctf_integer(__u32, csbase, kvm_x86_ops.get_segment_base(vcpu, VCPU_SREG_CS))
428 ctf_integer(__u8, len, vcpu->arch.emulate_ctxt->fetch.ptr -
429 vcpu->arch.emulate_ctxt->fetch.data)
430 ctf_array(__u8, insn, vcpu->arch.emulate_ctxt->fetch.data, 15)
431 ctf_integer(__u8, flags, kei_decode_mode(vcpu->arch.emulate_ctxt->mode))
432 ctf_integer(__u8, failed, failed)
433 )
434 )
435
436 #define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0)
437 #define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1)
438
439 LTTNG_TRACEPOINT_EVENT_MAP(
440 vcpu_match_mmio, kvm_x86_vcpu_match_mmio,
441 TP_PROTO(gva_t gva, gpa_t gpa, bool write, bool gpa_match),
442 TP_ARGS(gva, gpa, write, gpa_match),
443
444 TP_FIELDS(
445 ctf_integer(gva_t, gva, gva)
446 ctf_integer(gpa_t, gpa, gpa)
447 ctf_integer(bool, write, write)
448 ctf_integer(bool, gpa_match, gpa_match)
449 )
450 )
451
452 LTTNG_TRACEPOINT_EVENT_MAP(kvm_write_tsc_offset, kvm_x86_write_tsc_offset,
453 TP_PROTO(unsigned int vcpu_id, __u64 previous_tsc_offset,
454 __u64 next_tsc_offset),
455 TP_ARGS(vcpu_id, previous_tsc_offset, next_tsc_offset),
456
457 TP_FIELDS(
458 ctf_integer(unsigned int, vcpu_id, vcpu_id)
459 ctf_integer(__u64, previous_tsc_offset, previous_tsc_offset)
460 ctf_integer(__u64, next_tsc_offset, next_tsc_offset)
461 )
462 )
463
464 #ifdef CONFIG_X86_64
465
466 LTTNG_TRACEPOINT_EVENT_MAP(kvm_update_master_clock, kvm_x86_update_master_clock,
467 TP_PROTO(bool use_master_clock, unsigned int host_clock, bool offset_matched),
468 TP_ARGS(use_master_clock, host_clock, offset_matched),
469
470 TP_FIELDS(
471 ctf_integer(bool, use_master_clock, use_master_clock)
472 ctf_integer(unsigned int, host_clock, host_clock)
473 ctf_integer(bool, offset_matched, offset_matched)
474 )
475 )
476
477 LTTNG_TRACEPOINT_EVENT_MAP(kvm_track_tsc, kvm_x86_track_tsc,
478 TP_PROTO(unsigned int vcpu_id, unsigned int nr_matched,
479 unsigned int online_vcpus, bool use_master_clock,
480 unsigned int host_clock),
481 TP_ARGS(vcpu_id, nr_matched, online_vcpus, use_master_clock,
482 host_clock),
483
484 TP_FIELDS(
485 ctf_integer(unsigned int, vcpu_id, vcpu_id)
486 ctf_integer(unsigned int, nr_vcpus_matched_tsc, nr_matched)
487 ctf_integer(unsigned int, online_vcpus, online_vcpus)
488 ctf_integer(bool, use_master_clock, use_master_clock)
489 ctf_integer(unsigned int, host_clock, host_clock)
490 )
491 )
492
493 #endif /* CONFIG_X86_64 */
494
495 #endif /* LTTNG_TRACE_KVM_H */
496
497 #undef TRACE_INCLUDE_PATH
498 #define TRACE_INCLUDE_PATH instrumentation/events/lttng-module/arch/x86/kvm
499 #undef TRACE_INCLUDE_FILE
500 #define TRACE_INCLUDE_FILE trace
501
502 /* This part must be outside protection */
503 #include <probes/define_trace.h>
This page took 0.039712 seconds and 4 git commands to generate.