Fix: build kvm probe on EL 8.4+
[lttng-modules.git] / include / instrumentation / events / arch / x86 / kvm / trace.h
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: GPL-2.0-only */
3bc29f0a
MD
2#if !defined(LTTNG_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
3#define LTTNG_TRACE_KVM_H
b3c40230 4
3b4aafcb 5#include <lttng/tracepoint-event.h>
b3c40230
MG
6#include <asm/vmx.h>
7#include <asm/svm.h>
5f4c791e 8#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
b3c40230 9#include <asm/clocksource.h>
8170580a 10#endif
5f4c791e 11#include <lttng/kernel-version.h>
cbd56a97 12#include <wrapper/kvm-x86.h>
b3c40230
MG
13#include <../arch/x86/kvm/lapic.h>
14#include <../arch/x86/kvm/kvm_cache_regs.h>
15
16#undef TRACE_SYSTEM
b36bb1a8 17#define TRACE_SYSTEM kvm_x86
b3c40230
MG
18
19/*
20 * Tracepoint for guest mode entry.
21 */
b36bb1a8 22LTTNG_TRACEPOINT_EVENT_MAP(kvm_entry, kvm_x86_entry,
b3c40230
MG
23 TP_PROTO(unsigned int vcpu_id),
24 TP_ARGS(vcpu_id),
25
f127e61e
MD
26 TP_FIELDS(
27 ctf_integer(unsigned int, vcpu_id, vcpu_id)
28 )
b3c40230
MG
29)
30
31/*
32 * Tracepoint for hypercall.
33 */
b36bb1a8 34LTTNG_TRACEPOINT_EVENT_MAP(kvm_hypercall, kvm_x86_hypercall,
b3c40230
MG
35 TP_PROTO(unsigned long nr, unsigned long a0, unsigned long a1,
36 unsigned long a2, unsigned long a3),
37 TP_ARGS(nr, a0, a1, a2, a3),
38
f127e61e
MD
39 TP_FIELDS(
40 ctf_integer(unsigned long, nr, nr)
41 ctf_integer(unsigned long, a0, a0)
42 ctf_integer(unsigned long, a1, a1)
43 ctf_integer(unsigned long, a2, a2)
44 ctf_integer(unsigned long, a3, a3)
45 )
b3c40230
MG
46)
47
48/*
49 * Tracepoint for hypercall.
50 */
b36bb1a8 51LTTNG_TRACEPOINT_EVENT_MAP(kvm_hv_hypercall, kvm_x86_hv_hypercall,
b3c40230
MG
52 TP_PROTO(__u16 code, bool fast, __u16 rep_cnt, __u16 rep_idx,
53 __u64 ingpa, __u64 outgpa),
54 TP_ARGS(code, fast, rep_cnt, rep_idx, ingpa, outgpa),
55
f127e61e
MD
56 TP_FIELDS(
57 ctf_integer(__u16, rep_cnt, rep_cnt)
58 ctf_integer(__u16, rep_idx, rep_idx)
59 ctf_integer(__u64, ingpa, ingpa)
60 ctf_integer(__u64, outgpa, outgpa)
61 ctf_integer(__u16, code, code)
62 ctf_integer(bool, fast, fast)
63 )
b3c40230
MG
64)
65
66/*
67 * Tracepoint for PIO.
68 */
b36bb1a8 69LTTNG_TRACEPOINT_EVENT_MAP(kvm_pio, kvm_x86_pio,
b3c40230
MG
70 TP_PROTO(unsigned int rw, unsigned int port, unsigned int size,
71 unsigned int count),
72 TP_ARGS(rw, port, size, count),
73
f127e61e
MD
74 TP_FIELDS(
75 ctf_integer(unsigned int, rw, rw)
76 ctf_integer(unsigned int, port, port)
77 ctf_integer(unsigned int, size, size)
78 ctf_integer(unsigned int, count, count)
79 )
b3c40230
MG
80)
81
82/*
83 * Tracepoint for cpuid.
84 */
b36bb1a8 85LTTNG_TRACEPOINT_EVENT_MAP(kvm_cpuid, kvm_x86_cpuid,
b3c40230
MG
86 TP_PROTO(unsigned int function, unsigned long rax, unsigned long rbx,
87 unsigned long rcx, unsigned long rdx),
88 TP_ARGS(function, rax, rbx, rcx, rdx),
89
f127e61e
MD
90 TP_FIELDS(
91 ctf_integer(unsigned int, function, function)
92 ctf_integer(unsigned long, rax, rax)
93 ctf_integer(unsigned long, rbx, rbx)
94 ctf_integer(unsigned long, rcx, rcx)
95 ctf_integer(unsigned long, rdx, rdx)
96 )
b3c40230
MG
97)
98
b3c40230
MG
99/*
100 * Tracepoint for apic access.
101 */
b36bb1a8 102LTTNG_TRACEPOINT_EVENT_MAP(kvm_apic, kvm_x86_apic,
b3c40230
MG
103 TP_PROTO(unsigned int rw, unsigned int reg, unsigned int val),
104 TP_ARGS(rw, reg, val),
105
f127e61e
MD
106 TP_FIELDS(
107 ctf_integer(unsigned int, rw, rw)
108 ctf_integer(unsigned int, reg, reg)
109 ctf_integer(unsigned int, val, val)
110 )
b3c40230
MG
111)
112
113#define trace_kvm_apic_read(reg, val) trace_kvm_apic(0, reg, val)
114#define trace_kvm_apic_write(reg, val) trace_kvm_apic(1, reg, val)
115
b3c40230
MG
116/*
117 * Tracepoint for kvm guest exit:
118 */
cbd56a97
MJ
119#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,18,0))
120LTTNG_TRACEPOINT_EVENT_CODE_MAP(kvm_exit, kvm_x86_exit,
121 TP_PROTO(struct kvm_vcpu *vcpu, u32 isa),
122 TP_ARGS(vcpu, isa),
123
124 TP_locvar(
125 u32 exit_reason;
126 u64 info1, info2;
127 u32 intr_info, error_code;
128 ),
129
130 TP_code_pre(
131 lttng_kvm_x86_get_exit_info(vcpu,
132 &tp_locvar->exit_reason,
133 &tp_locvar->info1,
134 &tp_locvar->info2,
135 &tp_locvar->intr_info,
136 &tp_locvar->error_code);
137 ),
138
139 TP_FIELDS(
140 ctf_integer(unsigned int, exit_reason, tp_locvar->exit_reason)
141 ctf_integer(unsigned long, guest_rip, kvm_rip_read(vcpu))
142 ctf_integer(u32, isa, isa)
143 ctf_integer(u64, info1, tp_locvar->info1)
144 ctf_integer(u64, info2, tp_locvar->info2)
145 ctf_integer(u32, intr_info, tp_locvar->intr_info)
146 ctf_integer(u32, error_code, tp_locvar->error_code)
147 ctf_integer(unsigned int, vcpu_id, vcpu->vcpu_id)
148 ),
149
150 TP_code_post()
151)
152#elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,16,0))
036297af
MJ
153LTTNG_TRACEPOINT_EVENT_CODE_MAP(kvm_exit, kvm_x86_exit,
154 TP_PROTO(struct kvm_vcpu *vcpu, u32 isa),
155 TP_ARGS(vcpu, isa),
156
157 TP_locvar(
158 u32 reason;
159 u64 info1, info2;
160 u32 intr_info, error_code;
161 ),
162
163 TP_code_pre(
164 kvm_x86_ops.get_exit_info(vcpu, &tp_locvar->reason,
165 &tp_locvar->info1,
166 &tp_locvar->info2,
167 &tp_locvar->intr_info,
168 &tp_locvar->error_code);
169 ),
170
171 TP_FIELDS(
172 ctf_integer(u32, exit_reason, tp_locvar->reason)
173 ctf_integer(unsigned long, guest_rip, kvm_rip_read(vcpu))
174 ctf_integer(u32, isa, isa)
175 ctf_integer(u64, info1, tp_locvar->info1)
176 ctf_integer(u64, info2, tp_locvar->info2)
177 ctf_integer(u32, intr_info, tp_locvar->intr_info)
178 ctf_integer(u32, error_code, tp_locvar->error_code)
179 ctf_integer(unsigned int, vcpu_id, vcpu->vcpu_id)
180 ),
181
182 TP_code_post()
183)
578ab207
KS
184#elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,10,0) || \
185 LTTNG_RHEL_KERNEL_RANGE(4,18,0,240,0,0, 4,19,0,0,0,0))
0e0ee108
MJ
186LTTNG_TRACEPOINT_EVENT_CODE_MAP(kvm_exit, kvm_x86_exit,
187 TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa),
188 TP_ARGS(exit_reason, vcpu, isa),
189
190 TP_locvar(
191 u64 info1, info2;
192 u32 intr_info, error_code;
193 ),
194
195 TP_code_pre(
196 kvm_x86_ops.get_exit_info(vcpu, &tp_locvar->info1,
197 &tp_locvar->info2,
198 &tp_locvar->intr_info,
199 &tp_locvar->error_code);
200 ),
201
202 TP_FIELDS(
203 ctf_integer(unsigned int, exit_reason, exit_reason)
204 ctf_integer(unsigned long, guest_rip, kvm_rip_read(vcpu))
205 ctf_integer(u32, isa, isa)
206 ctf_integer(u64, info1, tp_locvar->info1)
207 ctf_integer(u64, info2, tp_locvar->info2)
208 ctf_integer(u32, intr_info, tp_locvar->intr_info)
209 ctf_integer(u32, error_code, tp_locvar->error_code)
210 ctf_integer(unsigned int, vcpu_id, vcpu->vcpu_id)
211 ),
212
213 TP_code_post()
214)
5f4c791e 215#elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,7,0))
b36bb1a8 216LTTNG_TRACEPOINT_EVENT_CODE_MAP(kvm_exit, kvm_x86_exit,
f127e61e
MD
217 TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa),
218 TP_ARGS(exit_reason, vcpu, isa),
219
220 TP_locvar(
221 u64 info1, info2;
b3c40230
MG
222 ),
223
265822ae 224 TP_code_pre(
9cc9518e
MD
225 kvm_x86_ops.get_exit_info(vcpu, &tp_locvar->info1,
226 &tp_locvar->info2);
0e0ee108
MJ
227 ),
228
229 TP_FIELDS(
230 ctf_integer(unsigned int, exit_reason, exit_reason)
231 ctf_integer(unsigned long, guest_rip, kvm_rip_read(vcpu))
232 ctf_integer(u32, isa, isa)
233 ctf_integer(u64, info1, tp_locvar->info1)
234 ctf_integer(u64, info2, tp_locvar->info2)
235 ),
236
237 TP_code_post()
238)
9cc9518e 239#else
0e0ee108
MJ
240LTTNG_TRACEPOINT_EVENT_CODE_MAP(kvm_exit, kvm_x86_exit,
241 TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa),
242 TP_ARGS(exit_reason, vcpu, isa),
243
244 TP_locvar(
245 u64 info1, info2;
246 ),
247
248 TP_code_pre(
f127e61e
MD
249 kvm_x86_ops->get_exit_info(vcpu, &tp_locvar->info1,
250 &tp_locvar->info2);
b3c40230
MG
251 ),
252
f127e61e
MD
253 TP_FIELDS(
254 ctf_integer(unsigned int, exit_reason, exit_reason)
255 ctf_integer(unsigned long, guest_rip, kvm_rip_read(vcpu))
256 ctf_integer(u32, isa, isa)
257 ctf_integer(u64, info1, tp_locvar->info1)
258 ctf_integer(u64, info2, tp_locvar->info2)
265822ae
MD
259 ),
260
261 TP_code_post()
b3c40230 262)
0e0ee108 263#endif
b3c40230
MG
264
265/*
266 * Tracepoint for kvm interrupt injection:
267 */
b36bb1a8 268LTTNG_TRACEPOINT_EVENT_MAP(kvm_inj_virq, kvm_x86_inj_virq,
b3c40230
MG
269 TP_PROTO(unsigned int irq),
270 TP_ARGS(irq),
271
f127e61e
MD
272 TP_FIELDS(
273 ctf_integer(unsigned int, irq, irq)
274 )
b3c40230
MG
275)
276
b3c40230
MG
277/*
278 * Tracepoint for kvm interrupt injection:
279 */
b36bb1a8 280LTTNG_TRACEPOINT_EVENT_MAP(kvm_inj_exception, kvm_x86_inj_exception,
b3c40230
MG
281 TP_PROTO(unsigned exception, bool has_error, unsigned error_code),
282 TP_ARGS(exception, has_error, error_code),
283
f127e61e
MD
284 TP_FIELDS(
285 ctf_integer(u8, exception, exception)
286 ctf_integer(u8, has_error, has_error)
287 ctf_integer(u32, error_code, error_code)
288 )
b3c40230
MG
289)
290
291/*
292 * Tracepoint for page fault.
293 */
b36bb1a8 294LTTNG_TRACEPOINT_EVENT_MAP(kvm_page_fault, kvm_x86_page_fault,
b3c40230
MG
295 TP_PROTO(unsigned long fault_address, unsigned int error_code),
296 TP_ARGS(fault_address, error_code),
297
f127e61e 298 TP_FIELDS(
2c054599 299 ctf_integer_hex(unsigned long, fault_address, fault_address)
f127e61e
MD
300 ctf_integer(unsigned int, error_code, error_code)
301 )
b3c40230
MG
302)
303
304/*
305 * Tracepoint for guest MSR access.
306 */
b36bb1a8 307LTTNG_TRACEPOINT_EVENT_MAP(kvm_msr, kvm_x86_msr,
b3c40230
MG
308 TP_PROTO(unsigned write, u32 ecx, u64 data, bool exception),
309 TP_ARGS(write, ecx, data, exception),
310
f127e61e
MD
311 TP_FIELDS(
312 ctf_integer(unsigned, write, write)
313 ctf_integer(u32, ecx, ecx)
314 ctf_integer(u64, data, data)
315 ctf_integer(u8, exception, exception)
316 )
b3c40230
MG
317)
318
319#define trace_kvm_msr_read(ecx, data) trace_kvm_msr(0, ecx, data, false)
320#define trace_kvm_msr_write(ecx, data) trace_kvm_msr(1, ecx, data, false)
321#define trace_kvm_msr_read_ex(ecx) trace_kvm_msr(0, ecx, 0, true)
322#define trace_kvm_msr_write_ex(ecx, data) trace_kvm_msr(1, ecx, data, true)
323
324/*
325 * Tracepoint for guest CR access.
326 */
b36bb1a8 327LTTNG_TRACEPOINT_EVENT_MAP(kvm_cr, kvm_x86_cr,
b3c40230
MG
328 TP_PROTO(unsigned int rw, unsigned int cr, unsigned long val),
329 TP_ARGS(rw, cr, val),
330
f127e61e
MD
331 TP_FIELDS(
332 ctf_integer(unsigned int, rw, rw)
333 ctf_integer(unsigned int, cr, cr)
334 ctf_integer(unsigned long, val, val)
335 )
b3c40230
MG
336)
337
338#define trace_kvm_cr_read(cr, val) trace_kvm_cr(0, cr, val)
339#define trace_kvm_cr_write(cr, val) trace_kvm_cr(1, cr, val)
340
b36bb1a8 341LTTNG_TRACEPOINT_EVENT_MAP(kvm_pic_set_irq, kvm_x86_pic_set_irq,
b3c40230
MG
342 TP_PROTO(__u8 chip, __u8 pin, __u8 elcr, __u8 imr, bool coalesced),
343 TP_ARGS(chip, pin, elcr, imr, coalesced),
344
f127e61e
MD
345 TP_FIELDS(
346 ctf_integer(__u8, chip, chip)
347 ctf_integer(__u8, pin, pin)
348 ctf_integer(__u8, elcr, elcr)
349 ctf_integer(__u8, imr, imr)
350 ctf_integer(bool, coalesced, coalesced)
351 )
b3c40230
MG
352)
353
b36bb1a8 354LTTNG_TRACEPOINT_EVENT_MAP(kvm_apic_ipi, kvm_x86_apic_ipi,
b3c40230
MG
355 TP_PROTO(__u32 icr_low, __u32 dest_id),
356 TP_ARGS(icr_low, dest_id),
357
f127e61e
MD
358 TP_FIELDS(
359 ctf_integer(__u32, icr_low, icr_low)
360 ctf_integer(__u32, dest_id, dest_id)
361 )
b3c40230
MG
362)
363
b36bb1a8 364LTTNG_TRACEPOINT_EVENT_MAP(kvm_apic_accept_irq, kvm_x86_apic_accept_irq,
b3c40230
MG
365 TP_PROTO(__u32 apicid, __u16 dm, __u8 tm, __u8 vec, bool coalesced),
366 TP_ARGS(apicid, dm, tm, vec, coalesced),
367
f127e61e
MD
368 TP_FIELDS(
369 ctf_integer(__u32, apicid, apicid)
370 ctf_integer(__u16, dm, dm)
371 ctf_integer(__u8, tm, tm)
372 ctf_integer(__u8, vec, vec)
373 ctf_integer(bool, coalesced, coalesced)
374 )
b3c40230
MG
375)
376
b36bb1a8 377LTTNG_TRACEPOINT_EVENT_MAP(kvm_eoi, kvm_x86_eoi,
b3c40230
MG
378 TP_PROTO(struct kvm_lapic *apic, int vector),
379 TP_ARGS(apic, vector),
380
f127e61e
MD
381 TP_FIELDS(
382 ctf_integer(__u32, apicid, apic->vcpu->vcpu_id)
383 ctf_integer(int, vector, vector)
384 )
b3c40230
MG
385)
386
b36bb1a8 387LTTNG_TRACEPOINT_EVENT_MAP(kvm_pv_eoi, kvm_x86_pv_eoi,
b3c40230
MG
388 TP_PROTO(struct kvm_lapic *apic, int vector),
389 TP_ARGS(apic, vector),
390
f127e61e
MD
391 TP_FIELDS(
392 ctf_integer(__u32, apicid, apic->vcpu->vcpu_id)
393 ctf_integer(int, vector, vector)
394 )
b3c40230
MG
395)
396
397/*
398 * Tracepoint for nested VMRUN
399 */
b36bb1a8 400LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_vmrun, kvm_x86_nested_vmrun,
b3c40230
MG
401 TP_PROTO(__u64 rip, __u64 vmcb, __u64 nested_rip, __u32 int_ctl,
402 __u32 event_inj, bool npt),
403 TP_ARGS(rip, vmcb, nested_rip, int_ctl, event_inj, npt),
404
f127e61e
MD
405 TP_FIELDS(
406 ctf_integer(__u64, rip, rip)
407 ctf_integer(__u64, vmcb, vmcb)
408 ctf_integer(__u64, nested_rip, nested_rip)
409 ctf_integer(__u32, int_ctl, int_ctl)
410 ctf_integer(__u32, event_inj, event_inj)
411 ctf_integer(bool, npt, npt)
412 )
b3c40230
MG
413)
414
b36bb1a8 415LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_intercepts, kvm_x86_nested_intercepts,
b3c40230
MG
416 TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u64 intercept),
417 TP_ARGS(cr_read, cr_write, exceptions, intercept),
418
f127e61e
MD
419 TP_FIELDS(
420 ctf_integer(__u16, cr_read, cr_read)
421 ctf_integer(__u16, cr_write, cr_write)
422 ctf_integer(__u32, exceptions, exceptions)
423 ctf_integer(__u64, intercept, intercept)
424 )
b3c40230
MG
425)
426/*
427 * Tracepoint for #VMEXIT while nested
428 */
b36bb1a8 429LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_vmexit, kvm_x86_nested_vmexit,
b3c40230
MG
430 TP_PROTO(__u64 rip, __u32 exit_code,
431 __u64 exit_info1, __u64 exit_info2,
432 __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
433 TP_ARGS(rip, exit_code, exit_info1, exit_info2,
434 exit_int_info, exit_int_info_err, isa),
435
f127e61e
MD
436 TP_FIELDS(
437 ctf_integer(__u64, rip, rip)
438 ctf_integer(__u32, exit_code, exit_code)
439 ctf_integer(__u64, exit_info1, exit_info1)
440 ctf_integer(__u64, exit_info2, exit_info2)
441 ctf_integer(__u32, exit_int_info, exit_int_info)
442 ctf_integer(__u32, exit_int_info_err, exit_int_info_err)
443 ctf_integer(__u32, isa, isa)
444 )
b3c40230
MG
445)
446
447/*
448 * Tracepoint for #VMEXIT reinjected to the guest
449 */
b36bb1a8 450LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_vmexit_inject, kvm_x86_nested_vmexit_inject,
b3c40230
MG
451 TP_PROTO(__u32 exit_code,
452 __u64 exit_info1, __u64 exit_info2,
453 __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
454 TP_ARGS(exit_code, exit_info1, exit_info2,
455 exit_int_info, exit_int_info_err, isa),
456
f127e61e
MD
457 TP_FIELDS(
458 ctf_integer(__u32, exit_code, exit_code)
459 ctf_integer(__u64, exit_info1, exit_info1)
460 ctf_integer(__u64, exit_info2, exit_info2)
461 ctf_integer(__u32, exit_int_info, exit_int_info)
462 ctf_integer(__u32, exit_int_info_err, exit_int_info_err)
463 ctf_integer(__u32, isa, isa)
464 )
b3c40230
MG
465)
466
467/*
468 * Tracepoint for nested #vmexit because of interrupt pending
469 */
b36bb1a8 470LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_intr_vmexit, kvm_x86_nested_intr_vmexit,
b3c40230
MG
471 TP_PROTO(__u64 rip),
472 TP_ARGS(rip),
473
f127e61e
MD
474 TP_FIELDS(
475 ctf_integer(__u64, rip, rip)
476 )
b3c40230
MG
477)
478
479/*
480 * Tracepoint for nested #vmexit because of interrupt pending
481 */
b36bb1a8 482LTTNG_TRACEPOINT_EVENT_MAP(kvm_invlpga, kvm_x86_invlpga,
b3c40230
MG
483 TP_PROTO(__u64 rip, int asid, u64 address),
484 TP_ARGS(rip, asid, address),
485
f127e61e
MD
486 TP_FIELDS(
487 ctf_integer(__u64, rip, rip)
488 ctf_integer(int, asid, asid)
2c054599 489 ctf_integer_hex(__u64, address, address)
f127e61e 490 )
b3c40230
MG
491)
492
493/*
494 * Tracepoint for nested #vmexit because of interrupt pending
495 */
b36bb1a8 496LTTNG_TRACEPOINT_EVENT_MAP(kvm_skinit, kvm_x86_skinit,
b3c40230
MG
497 TP_PROTO(__u64 rip, __u32 slb),
498 TP_ARGS(rip, slb),
499
f127e61e
MD
500 TP_FIELDS(
501 ctf_integer(__u64, rip, rip)
502 ctf_integer(__u32, slb, slb)
503 )
b3c40230
MG
504)
505
506#define KVM_EMUL_INSN_F_CR0_PE (1 << 0)
507#define KVM_EMUL_INSN_F_EFL_VM (1 << 1)
508#define KVM_EMUL_INSN_F_CS_D (1 << 2)
509#define KVM_EMUL_INSN_F_CS_L (1 << 3)
510
511#define kvm_trace_symbol_emul_flags \
512 { 0, "real" }, \
513 { KVM_EMUL_INSN_F_CR0_PE \
514 | KVM_EMUL_INSN_F_EFL_VM, "vm16" }, \
515 { KVM_EMUL_INSN_F_CR0_PE, "prot16" }, \
516 { KVM_EMUL_INSN_F_CR0_PE \
517 | KVM_EMUL_INSN_F_CS_D, "prot32" }, \
518 { KVM_EMUL_INSN_F_CR0_PE \
519 | KVM_EMUL_INSN_F_CS_L, "prot64" }
520
521#define kei_decode_mode(mode) ({ \
522 u8 flags = 0xff; \
523 switch (mode) { \
524 case X86EMUL_MODE_REAL: \
525 flags = 0; \
526 break; \
527 case X86EMUL_MODE_VM86: \
528 flags = KVM_EMUL_INSN_F_EFL_VM; \
529 break; \
530 case X86EMUL_MODE_PROT16: \
531 flags = KVM_EMUL_INSN_F_CR0_PE; \
532 break; \
533 case X86EMUL_MODE_PROT32: \
534 flags = KVM_EMUL_INSN_F_CR0_PE \
535 | KVM_EMUL_INSN_F_CS_D; \
536 break; \
537 case X86EMUL_MODE_PROT64: \
538 flags = KVM_EMUL_INSN_F_CR0_PE \
539 | KVM_EMUL_INSN_F_CS_L; \
540 break; \
541 } \
542 flags; \
543 })
544
b36bb1a8 545LTTNG_TRACEPOINT_EVENT_MAP(kvm_emulate_insn, kvm_x86_emulate_insn,
b3c40230
MG
546 TP_PROTO(struct kvm_vcpu *vcpu, __u8 failed),
547 TP_ARGS(vcpu, failed),
548
f127e61e 549 TP_FIELDS(
5f4c791e 550#if (LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(3,1,0))
f127e61e
MD
551 ctf_integer(__u64, rip, vcpu->arch.emulate_ctxt.decode.fetch.start)
552 ctf_integer(__u32, csbase, kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS))
553 ctf_integer(__u8, len, vcpu->arch.emulate_ctxt.decode.eip
554 - vcpu->arch.emulate_ctxt.decode.fetch.start)
555 ctf_array(__u8, insn, vcpu->arch.emulate_ctxt.decode.fetch.data, 15)
9cc9518e 556 ctf_integer(__u8, flags, kei_decode_mode(vcpu->arch.emulate_ctxt.mode))
5f4c791e 557#elif (LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(3,17,0))
f127e61e
MD
558 ctf_integer(__u64, rip, vcpu->arch.emulate_ctxt.fetch.start)
559 ctf_integer(__u32, csbase, kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS))
560 ctf_integer(__u8, len, vcpu->arch.emulate_ctxt._eip
561 - vcpu->arch.emulate_ctxt.fetch.start)
562 ctf_array(__u8, insn, vcpu->arch.emulate_ctxt.fetch.data, 15)
9cc9518e 563 ctf_integer(__u8, flags, kei_decode_mode(vcpu->arch.emulate_ctxt.mode))
578ab207
KS
564#elif (LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(5,7,0) && \
565 !LTTNG_RHEL_KERNEL_RANGE(4,18,0,305,0,0, 4,19,0,0,0,0))
f127e61e
MD
566 ctf_integer(__u64, rip, vcpu->arch.emulate_ctxt._eip -
567 (vcpu->arch.emulate_ctxt.fetch.ptr -
568 vcpu->arch.emulate_ctxt.fetch.data))
569 ctf_integer(__u32, csbase, kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS))
570 ctf_integer(__u8, len, vcpu->arch.emulate_ctxt.fetch.ptr -
571 vcpu->arch.emulate_ctxt.fetch.data)
572 ctf_array(__u8, insn, vcpu->arch.emulate_ctxt.fetch.data, 15)
f127e61e 573 ctf_integer(__u8, flags, kei_decode_mode(vcpu->arch.emulate_ctxt.mode))
578ab207
KS
574#elif (LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(5,18,0) || \
575 LTTNG_RHEL_KERNEL_RANGE(4,18,0,305,0,0, 4,19,0,0,0,0))
9cc9518e
MD
576 ctf_integer(__u64, rip, vcpu->arch.emulate_ctxt->_eip -
577 (vcpu->arch.emulate_ctxt->fetch.ptr -
578 vcpu->arch.emulate_ctxt->fetch.data))
579 ctf_integer(__u32, csbase, kvm_x86_ops.get_segment_base(vcpu, VCPU_SREG_CS))
580 ctf_integer(__u8, len, vcpu->arch.emulate_ctxt->fetch.ptr -
581 vcpu->arch.emulate_ctxt->fetch.data)
582 ctf_array(__u8, insn, vcpu->arch.emulate_ctxt->fetch.data, 15)
583 ctf_integer(__u8, flags, kei_decode_mode(vcpu->arch.emulate_ctxt->mode))
cbd56a97
MJ
584#else
585 ctf_integer(__u64, rip, vcpu->arch.emulate_ctxt->_eip -
586 (vcpu->arch.emulate_ctxt->fetch.ptr -
587 vcpu->arch.emulate_ctxt->fetch.data))
588 ctf_integer(__u32, csbase, lttng_kvm_x86_get_segment_base(vcpu, VCPU_SREG_CS))
589 ctf_integer(__u8, len, vcpu->arch.emulate_ctxt->fetch.ptr -
590 vcpu->arch.emulate_ctxt->fetch.data)
591 ctf_array(__u8, insn, vcpu->arch.emulate_ctxt->fetch.data, 15)
592 ctf_integer(__u8, flags, kei_decode_mode(vcpu->arch.emulate_ctxt->mode))
9cc9518e 593#endif
f127e61e 594 ctf_integer(__u8, failed, failed)
b3c40230 595 )
f127e61e 596)
b3c40230
MG
597
598#define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0)
599#define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1)
600
b36bb1a8
MD
601LTTNG_TRACEPOINT_EVENT_MAP(
602 vcpu_match_mmio, kvm_x86_vcpu_match_mmio,
b3c40230
MG
603 TP_PROTO(gva_t gva, gpa_t gpa, bool write, bool gpa_match),
604 TP_ARGS(gva, gpa, write, gpa_match),
605
f127e61e
MD
606 TP_FIELDS(
607 ctf_integer(gva_t, gva, gva)
608 ctf_integer(gpa_t, gpa, gpa)
609 ctf_integer(bool, write, write)
610 ctf_integer(bool, gpa_match, gpa_match)
611 )
b3c40230
MG
612)
613
5f4c791e 614#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,11,0))
b36bb1a8 615LTTNG_TRACEPOINT_EVENT_MAP(kvm_write_tsc_offset, kvm_x86_write_tsc_offset,
026e6902
MG
616 TP_PROTO(unsigned int vcpu_id, __u64 previous_tsc_offset,
617 __u64 next_tsc_offset),
618 TP_ARGS(vcpu_id, previous_tsc_offset, next_tsc_offset),
619
f127e61e
MD
620 TP_FIELDS(
621 ctf_integer(unsigned int, vcpu_id, vcpu_id)
622 ctf_integer(__u64, previous_tsc_offset, previous_tsc_offset)
623 ctf_integer(__u64, next_tsc_offset, next_tsc_offset)
624 )
026e6902
MG
625)
626#endif
627
5f4c791e 628#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0))
b3c40230
MG
629#ifdef CONFIG_X86_64
630
b36bb1a8 631LTTNG_TRACEPOINT_EVENT_MAP(kvm_update_master_clock, kvm_x86_update_master_clock,
b3c40230
MG
632 TP_PROTO(bool use_master_clock, unsigned int host_clock, bool offset_matched),
633 TP_ARGS(use_master_clock, host_clock, offset_matched),
634
f127e61e
MD
635 TP_FIELDS(
636 ctf_integer(bool, use_master_clock, use_master_clock)
637 ctf_integer(unsigned int, host_clock, host_clock)
638 ctf_integer(bool, offset_matched, offset_matched)
639 )
b3c40230
MG
640)
641
b36bb1a8 642LTTNG_TRACEPOINT_EVENT_MAP(kvm_track_tsc, kvm_x86_track_tsc,
b3c40230
MG
643 TP_PROTO(unsigned int vcpu_id, unsigned int nr_matched,
644 unsigned int online_vcpus, bool use_master_clock,
645 unsigned int host_clock),
646 TP_ARGS(vcpu_id, nr_matched, online_vcpus, use_master_clock,
647 host_clock),
648
f127e61e
MD
649 TP_FIELDS(
650 ctf_integer(unsigned int, vcpu_id, vcpu_id)
651 ctf_integer(unsigned int, nr_vcpus_matched_tsc, nr_matched)
652 ctf_integer(unsigned int, online_vcpus, online_vcpus)
653 ctf_integer(bool, use_master_clock, use_master_clock)
654 ctf_integer(unsigned int, host_clock, host_clock)
655 )
b3c40230
MG
656)
657
658#endif /* CONFIG_X86_64 */
5f4c791e 659#endif /* LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,8,0) */
b3c40230 660
3bc29f0a 661#endif /* LTTNG_TRACE_KVM_H */
b3c40230
MG
662
663#undef TRACE_INCLUDE_PATH
4f47ccf0 664#define TRACE_INCLUDE_PATH instrumentation/events/arch/x86/kvm
b3c40230
MG
665#undef TRACE_INCLUDE_FILE
666#define TRACE_INCLUDE_FILE trace
667
668/* This part must be outside protection */
3b4aafcb 669#include <lttng/define_trace.h>
This page took 0.088713 seconds and 4 git commands to generate.