• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
3 #define _TRACE_KVM_H
4 
5 #include <linux/tracepoint.h>
6 #include <asm/vmx.h>
7 #include <asm/svm.h>
8 #include <asm/clocksource.h>
9 #include <asm/pvclock-abi.h>
10 
11 #undef TRACE_SYSTEM
12 #define TRACE_SYSTEM kvm
13 
14 /*
15  * Tracepoint for guest mode entry.
16  */
17 TRACE_EVENT(kvm_entry,
18 	TP_PROTO(struct kvm_vcpu *vcpu),
19 	TP_ARGS(vcpu),
20 
21 	TP_STRUCT__entry(
22 		__field(	unsigned int,	vcpu_id		)
23 		__field(	unsigned long,	rip		)
24 	),
25 
26 	TP_fast_assign(
27 		__entry->vcpu_id        = vcpu->vcpu_id;
28 		__entry->rip		= kvm_rip_read(vcpu);
29 	),
30 
31 	TP_printk("vcpu %u, rip 0x%lx", __entry->vcpu_id, __entry->rip)
32 );
33 
34 /*
35  * Tracepoint for hypercall.
36  */
37 TRACE_EVENT(kvm_hypercall,
38 	TP_PROTO(unsigned long nr, unsigned long a0, unsigned long a1,
39 		 unsigned long a2, unsigned long a3),
40 	TP_ARGS(nr, a0, a1, a2, a3),
41 
42 	TP_STRUCT__entry(
43 		__field(	unsigned long, 	nr		)
44 		__field(	unsigned long,	a0		)
45 		__field(	unsigned long,	a1		)
46 		__field(	unsigned long,	a2		)
47 		__field(	unsigned long,	a3		)
48 	),
49 
50 	TP_fast_assign(
51 		__entry->nr		= nr;
52 		__entry->a0		= a0;
53 		__entry->a1		= a1;
54 		__entry->a2		= a2;
55 		__entry->a3		= a3;
56 	),
57 
58 	TP_printk("nr 0x%lx a0 0x%lx a1 0x%lx a2 0x%lx a3 0x%lx",
59 		 __entry->nr, __entry->a0, __entry->a1,  __entry->a2,
60 		 __entry->a3)
61 );
62 
63 /*
64  * Tracepoint for hypercall.
65  */
66 TRACE_EVENT(kvm_hv_hypercall,
67 	TP_PROTO(__u16 code, bool fast, __u16 rep_cnt, __u16 rep_idx,
68 		 __u64 ingpa, __u64 outgpa),
69 	TP_ARGS(code, fast, rep_cnt, rep_idx, ingpa, outgpa),
70 
71 	TP_STRUCT__entry(
72 		__field(	__u16,		rep_cnt		)
73 		__field(	__u16,		rep_idx		)
74 		__field(	__u64,		ingpa		)
75 		__field(	__u64,		outgpa		)
76 		__field(	__u16, 		code		)
77 		__field(	bool,		fast		)
78 	),
79 
80 	TP_fast_assign(
81 		__entry->rep_cnt	= rep_cnt;
82 		__entry->rep_idx	= rep_idx;
83 		__entry->ingpa		= ingpa;
84 		__entry->outgpa		= outgpa;
85 		__entry->code		= code;
86 		__entry->fast		= fast;
87 	),
88 
89 	TP_printk("code 0x%x %s cnt 0x%x idx 0x%x in 0x%llx out 0x%llx",
90 		  __entry->code, __entry->fast ? "fast" : "slow",
91 		  __entry->rep_cnt, __entry->rep_idx,  __entry->ingpa,
92 		  __entry->outgpa)
93 );
94 
95 TRACE_EVENT(kvm_hv_hypercall_done,
96 	TP_PROTO(u64 result),
97 	TP_ARGS(result),
98 
99 	TP_STRUCT__entry(
100 		__field(__u64, result)
101 	),
102 
103 	TP_fast_assign(
104 		__entry->result	= result;
105 	),
106 
107 	TP_printk("result 0x%llx", __entry->result)
108 );
109 
110 /*
111  * Tracepoint for Xen hypercall.
112  */
113 TRACE_EVENT(kvm_xen_hypercall,
114 	TP_PROTO(unsigned long nr, unsigned long a0, unsigned long a1,
115 		 unsigned long a2, unsigned long a3, unsigned long a4,
116 		 unsigned long a5),
117 	    TP_ARGS(nr, a0, a1, a2, a3, a4, a5),
118 
119 	TP_STRUCT__entry(
120 		__field(unsigned long, nr)
121 		__field(unsigned long, a0)
122 		__field(unsigned long, a1)
123 		__field(unsigned long, a2)
124 		__field(unsigned long, a3)
125 		__field(unsigned long, a4)
126 		__field(unsigned long, a5)
127 	),
128 
129 	TP_fast_assign(
130 		__entry->nr = nr;
131 		__entry->a0 = a0;
132 		__entry->a1 = a1;
133 		__entry->a2 = a2;
134 		__entry->a3 = a3;
135 		__entry->a4 = a4;
136 		__entry->a4 = a5;
137 	),
138 
139 	TP_printk("nr 0x%lx a0 0x%lx a1 0x%lx a2 0x%lx a3 0x%lx a4 0x%lx a5 %lx",
140 		  __entry->nr, __entry->a0, __entry->a1,  __entry->a2,
141 		  __entry->a3, __entry->a4, __entry->a5)
142 );
143 
144 
145 
146 /*
147  * Tracepoint for PIO.
148  */
149 
150 #define KVM_PIO_IN   0
151 #define KVM_PIO_OUT  1
152 
153 TRACE_EVENT(kvm_pio,
154 	TP_PROTO(unsigned int rw, unsigned int port, unsigned int size,
155 		 unsigned int count, void *data),
156 	TP_ARGS(rw, port, size, count, data),
157 
158 	TP_STRUCT__entry(
159 		__field(	unsigned int, 	rw		)
160 		__field(	unsigned int, 	port		)
161 		__field(	unsigned int, 	size		)
162 		__field(	unsigned int,	count		)
163 		__field(	unsigned int,	val		)
164 	),
165 
166 	TP_fast_assign(
167 		__entry->rw		= rw;
168 		__entry->port		= port;
169 		__entry->size		= size;
170 		__entry->count		= count;
171 		if (size == 1)
172 			__entry->val	= *(unsigned char *)data;
173 		else if (size == 2)
174 			__entry->val	= *(unsigned short *)data;
175 		else
176 			__entry->val	= *(unsigned int *)data;
177 	),
178 
179 	TP_printk("pio_%s at 0x%x size %d count %d val 0x%x %s",
180 		  __entry->rw ? "write" : "read",
181 		  __entry->port, __entry->size, __entry->count, __entry->val,
182 		  __entry->count > 1 ? "(...)" : "")
183 );
184 
185 /*
186  * Tracepoint for fast mmio.
187  */
188 TRACE_EVENT(kvm_fast_mmio,
189 	TP_PROTO(u64 gpa),
190 	TP_ARGS(gpa),
191 
192 	TP_STRUCT__entry(
193 		__field(u64,	gpa)
194 	),
195 
196 	TP_fast_assign(
197 		__entry->gpa		= gpa;
198 	),
199 
200 	TP_printk("fast mmio at gpa 0x%llx", __entry->gpa)
201 );
202 
203 /*
204  * Tracepoint for cpuid.
205  */
206 TRACE_EVENT(kvm_cpuid,
207 	TP_PROTO(unsigned int function, unsigned int index, unsigned long rax,
208 		 unsigned long rbx, unsigned long rcx, unsigned long rdx,
209 		 bool found, bool used_max_basic),
210 	TP_ARGS(function, index, rax, rbx, rcx, rdx, found, used_max_basic),
211 
212 	TP_STRUCT__entry(
213 		__field(	unsigned int,	function	)
214 		__field(	unsigned int,	index		)
215 		__field(	unsigned long,	rax		)
216 		__field(	unsigned long,	rbx		)
217 		__field(	unsigned long,	rcx		)
218 		__field(	unsigned long,	rdx		)
219 		__field(	bool,		found		)
220 		__field(	bool,		used_max_basic	)
221 	),
222 
223 	TP_fast_assign(
224 		__entry->function	= function;
225 		__entry->index		= index;
226 		__entry->rax		= rax;
227 		__entry->rbx		= rbx;
228 		__entry->rcx		= rcx;
229 		__entry->rdx		= rdx;
230 		__entry->found		= found;
231 		__entry->used_max_basic	= used_max_basic;
232 	),
233 
234 	TP_printk("func %x idx %x rax %lx rbx %lx rcx %lx rdx %lx, cpuid entry %s%s",
235 		  __entry->function, __entry->index, __entry->rax,
236 		  __entry->rbx, __entry->rcx, __entry->rdx,
237 		  __entry->found ? "found" : "not found",
238 		  __entry->used_max_basic ? ", used max basic" : "")
239 );
240 
241 #define AREG(x) { APIC_##x, "APIC_" #x }
242 
243 #define kvm_trace_symbol_apic						    \
244 	AREG(ID), AREG(LVR), AREG(TASKPRI), AREG(ARBPRI), AREG(PROCPRI),    \
245 	AREG(EOI), AREG(RRR), AREG(LDR), AREG(DFR), AREG(SPIV), AREG(ISR),  \
246 	AREG(TMR), AREG(IRR), AREG(ESR), AREG(ICR), AREG(ICR2), AREG(LVTT), \
247 	AREG(LVTTHMR), AREG(LVTPC), AREG(LVT0), AREG(LVT1), AREG(LVTERR),   \
248 	AREG(TMICT), AREG(TMCCT), AREG(TDCR), AREG(SELF_IPI), AREG(EFEAT),  \
249 	AREG(ECTRL)
250 /*
251  * Tracepoint for apic access.
252  */
253 TRACE_EVENT(kvm_apic,
254 	TP_PROTO(unsigned int rw, unsigned int reg, unsigned int val),
255 	TP_ARGS(rw, reg, val),
256 
257 	TP_STRUCT__entry(
258 		__field(	unsigned int,	rw		)
259 		__field(	unsigned int,	reg		)
260 		__field(	unsigned int,	val		)
261 	),
262 
263 	TP_fast_assign(
264 		__entry->rw		= rw;
265 		__entry->reg		= reg;
266 		__entry->val		= val;
267 	),
268 
269 	TP_printk("apic_%s %s = 0x%x",
270 		  __entry->rw ? "write" : "read",
271 		  __print_symbolic(__entry->reg, kvm_trace_symbol_apic),
272 		  __entry->val)
273 );
274 
275 #define trace_kvm_apic_read(reg, val)		trace_kvm_apic(0, reg, val)
276 #define trace_kvm_apic_write(reg, val)		trace_kvm_apic(1, reg, val)
277 
278 #define KVM_ISA_VMX   1
279 #define KVM_ISA_SVM   2
280 
281 #define kvm_print_exit_reason(exit_reason, isa)				\
282 	(isa == KVM_ISA_VMX) ?						\
283 	__print_symbolic(exit_reason & 0xffff, VMX_EXIT_REASONS) :	\
284 	__print_symbolic(exit_reason, SVM_EXIT_REASONS),		\
285 	(isa == KVM_ISA_VMX && exit_reason & ~0xffff) ? " " : "",	\
286 	(isa == KVM_ISA_VMX) ?						\
287 	__print_flags(exit_reason & ~0xffff, " ", VMX_EXIT_REASON_FLAGS) : ""
288 
289 #define TRACE_EVENT_KVM_EXIT(name)					     \
290 TRACE_EVENT(name,							     \
291 	TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa),  \
292 	TP_ARGS(exit_reason, vcpu, isa),				     \
293 									     \
294 	TP_STRUCT__entry(						     \
295 		__field(	unsigned int,	exit_reason	)	     \
296 		__field(	unsigned long,	guest_rip	)	     \
297 		__field(	u32,	        isa             )	     \
298 		__field(	u64,	        info1           )	     \
299 		__field(	u64,	        info2           )	     \
300 		__field(	u32,	        intr_info	)	     \
301 		__field(	u32,	        error_code	)	     \
302 		__field(	unsigned int,	vcpu_id         )	     \
303 	),								     \
304 									     \
305 	TP_fast_assign(							     \
306 		__entry->exit_reason	= exit_reason;			     \
307 		__entry->guest_rip	= kvm_rip_read(vcpu);		     \
308 		__entry->isa            = isa;				     \
309 		__entry->vcpu_id        = vcpu->vcpu_id;		     \
310 		static_call(kvm_x86_get_exit_info)(vcpu, &__entry->info1,    \
311 					  &__entry->info2,		     \
312 					  &__entry->intr_info,		     \
313 					  &__entry->error_code);	     \
314 	),								     \
315 									     \
316 	TP_printk("vcpu %u reason %s%s%s rip 0x%lx info1 0x%016llx "	     \
317 		  "info2 0x%016llx intr_info 0x%08x error_code 0x%08x",	     \
318 		  __entry->vcpu_id,					     \
319 		  kvm_print_exit_reason(__entry->exit_reason, __entry->isa), \
320 		  __entry->guest_rip, __entry->info1, __entry->info2,	     \
321 		  __entry->intr_info, __entry->error_code)		     \
322 )
323 
324 /*
325  * Tracepoint for kvm guest exit:
326  */
327 TRACE_EVENT_KVM_EXIT(kvm_exit);
328 
329 /*
330  * Tracepoint for kvm interrupt injection:
331  */
332 TRACE_EVENT(kvm_inj_virq,
333 	TP_PROTO(unsigned int irq),
334 	TP_ARGS(irq),
335 
336 	TP_STRUCT__entry(
337 		__field(	unsigned int,	irq		)
338 	),
339 
340 	TP_fast_assign(
341 		__entry->irq		= irq;
342 	),
343 
344 	TP_printk("irq %u", __entry->irq)
345 );
346 
347 #define EXS(x) { x##_VECTOR, "#" #x }
348 
349 #define kvm_trace_sym_exc						\
350 	EXS(DE), EXS(DB), EXS(BP), EXS(OF), EXS(BR), EXS(UD), EXS(NM),	\
351 	EXS(DF), EXS(TS), EXS(NP), EXS(SS), EXS(GP), EXS(PF),		\
352 	EXS(MF), EXS(AC), EXS(MC)
353 
354 /*
355  * Tracepoint for kvm interrupt injection:
356  */
357 TRACE_EVENT(kvm_inj_exception,
358 	TP_PROTO(unsigned exception, bool has_error, unsigned error_code,
359 		 bool reinjected),
360 	TP_ARGS(exception, has_error, error_code, reinjected),
361 
362 	TP_STRUCT__entry(
363 		__field(	u8,	exception	)
364 		__field(	u8,	has_error	)
365 		__field(	u32,	error_code	)
366 		__field(	bool,	reinjected	)
367 	),
368 
369 	TP_fast_assign(
370 		__entry->exception	= exception;
371 		__entry->has_error	= has_error;
372 		__entry->error_code	= error_code;
373 		__entry->reinjected	= reinjected;
374 	),
375 
376 	TP_printk("%s (0x%x)%s",
377 		  __print_symbolic(__entry->exception, kvm_trace_sym_exc),
378 		  /* FIXME: don't print error_code if not present */
379 		  __entry->has_error ? __entry->error_code : 0,
380 		  __entry->reinjected ? " [reinjected]" : "")
381 );
382 
383 /*
384  * Tracepoint for page fault.
385  */
386 TRACE_EVENT(kvm_page_fault,
387 	TP_PROTO(unsigned long fault_address, unsigned int error_code),
388 	TP_ARGS(fault_address, error_code),
389 
390 	TP_STRUCT__entry(
391 		__field(	unsigned long,	fault_address	)
392 		__field(	unsigned int,	error_code	)
393 	),
394 
395 	TP_fast_assign(
396 		__entry->fault_address	= fault_address;
397 		__entry->error_code	= error_code;
398 	),
399 
400 	TP_printk("address %lx error_code %x",
401 		  __entry->fault_address, __entry->error_code)
402 );
403 
404 /*
405  * Tracepoint for guest MSR access.
406  */
407 TRACE_EVENT(kvm_msr,
408 	TP_PROTO(unsigned write, u32 ecx, u64 data, bool exception),
409 	TP_ARGS(write, ecx, data, exception),
410 
411 	TP_STRUCT__entry(
412 		__field(	unsigned,	write		)
413 		__field(	u32,		ecx		)
414 		__field(	u64,		data		)
415 		__field(	u8,		exception	)
416 	),
417 
418 	TP_fast_assign(
419 		__entry->write		= write;
420 		__entry->ecx		= ecx;
421 		__entry->data		= data;
422 		__entry->exception	= exception;
423 	),
424 
425 	TP_printk("msr_%s %x = 0x%llx%s",
426 		  __entry->write ? "write" : "read",
427 		  __entry->ecx, __entry->data,
428 		  __entry->exception ? " (#GP)" : "")
429 );
430 
431 #define trace_kvm_msr_read(ecx, data)      trace_kvm_msr(0, ecx, data, false)
432 #define trace_kvm_msr_write(ecx, data)     trace_kvm_msr(1, ecx, data, false)
433 #define trace_kvm_msr_read_ex(ecx)         trace_kvm_msr(0, ecx, 0, true)
434 #define trace_kvm_msr_write_ex(ecx, data)  trace_kvm_msr(1, ecx, data, true)
435 
436 /*
437  * Tracepoint for guest CR access.
438  */
439 TRACE_EVENT(kvm_cr,
440 	TP_PROTO(unsigned int rw, unsigned int cr, unsigned long val),
441 	TP_ARGS(rw, cr, val),
442 
443 	TP_STRUCT__entry(
444 		__field(	unsigned int,	rw		)
445 		__field(	unsigned int,	cr		)
446 		__field(	unsigned long,	val		)
447 	),
448 
449 	TP_fast_assign(
450 		__entry->rw		= rw;
451 		__entry->cr		= cr;
452 		__entry->val		= val;
453 	),
454 
455 	TP_printk("cr_%s %x = 0x%lx",
456 		  __entry->rw ? "write" : "read",
457 		  __entry->cr, __entry->val)
458 );
459 
460 #define trace_kvm_cr_read(cr, val)		trace_kvm_cr(0, cr, val)
461 #define trace_kvm_cr_write(cr, val)		trace_kvm_cr(1, cr, val)
462 
463 TRACE_EVENT(kvm_pic_set_irq,
464 	    TP_PROTO(__u8 chip, __u8 pin, __u8 elcr, __u8 imr, bool coalesced),
465 	    TP_ARGS(chip, pin, elcr, imr, coalesced),
466 
467 	TP_STRUCT__entry(
468 		__field(	__u8,		chip		)
469 		__field(	__u8,		pin		)
470 		__field(	__u8,		elcr		)
471 		__field(	__u8,		imr		)
472 		__field(	bool,		coalesced	)
473 	),
474 
475 	TP_fast_assign(
476 		__entry->chip		= chip;
477 		__entry->pin		= pin;
478 		__entry->elcr		= elcr;
479 		__entry->imr		= imr;
480 		__entry->coalesced	= coalesced;
481 	),
482 
483 	TP_printk("chip %u pin %u (%s%s)%s",
484 		  __entry->chip, __entry->pin,
485 		  (__entry->elcr & (1 << __entry->pin)) ? "level":"edge",
486 		  (__entry->imr & (1 << __entry->pin)) ? "|masked":"",
487 		  __entry->coalesced ? " (coalesced)" : "")
488 );
489 
490 #define kvm_apic_dst_shorthand		\
491 	{0x0, "dst"},			\
492 	{0x1, "self"},			\
493 	{0x2, "all"},			\
494 	{0x3, "all-but-self"}
495 
496 TRACE_EVENT(kvm_apic_ipi,
497 	    TP_PROTO(__u32 icr_low, __u32 dest_id),
498 	    TP_ARGS(icr_low, dest_id),
499 
500 	TP_STRUCT__entry(
501 		__field(	__u32,		icr_low		)
502 		__field(	__u32,		dest_id		)
503 	),
504 
505 	TP_fast_assign(
506 		__entry->icr_low	= icr_low;
507 		__entry->dest_id	= dest_id;
508 	),
509 
510 	TP_printk("dst %x vec %u (%s|%s|%s|%s|%s)",
511 		  __entry->dest_id, (u8)__entry->icr_low,
512 		  __print_symbolic((__entry->icr_low >> 8 & 0x7),
513 				   kvm_deliver_mode),
514 		  (__entry->icr_low & (1<<11)) ? "logical" : "physical",
515 		  (__entry->icr_low & (1<<14)) ? "assert" : "de-assert",
516 		  (__entry->icr_low & (1<<15)) ? "level" : "edge",
517 		  __print_symbolic((__entry->icr_low >> 18 & 0x3),
518 				   kvm_apic_dst_shorthand))
519 );
520 
521 TRACE_EVENT(kvm_apic_accept_irq,
522 	    TP_PROTO(__u32 apicid, __u16 dm, __u16 tm, __u8 vec),
523 	    TP_ARGS(apicid, dm, tm, vec),
524 
525 	TP_STRUCT__entry(
526 		__field(	__u32,		apicid		)
527 		__field(	__u16,		dm		)
528 		__field(	__u16,		tm		)
529 		__field(	__u8,		vec		)
530 	),
531 
532 	TP_fast_assign(
533 		__entry->apicid		= apicid;
534 		__entry->dm		= dm;
535 		__entry->tm		= tm;
536 		__entry->vec		= vec;
537 	),
538 
539 	TP_printk("apicid %x vec %u (%s|%s)",
540 		  __entry->apicid, __entry->vec,
541 		  __print_symbolic((__entry->dm >> 8 & 0x7), kvm_deliver_mode),
542 		  __entry->tm ? "level" : "edge")
543 );
544 
545 TRACE_EVENT(kvm_eoi,
546 	    TP_PROTO(struct kvm_lapic *apic, int vector),
547 	    TP_ARGS(apic, vector),
548 
549 	TP_STRUCT__entry(
550 		__field(	__u32,		apicid		)
551 		__field(	int,		vector		)
552 	),
553 
554 	TP_fast_assign(
555 		__entry->apicid		= apic->vcpu->vcpu_id;
556 		__entry->vector		= vector;
557 	),
558 
559 	TP_printk("apicid %x vector %d", __entry->apicid, __entry->vector)
560 );
561 
562 TRACE_EVENT(kvm_pv_eoi,
563 	    TP_PROTO(struct kvm_lapic *apic, int vector),
564 	    TP_ARGS(apic, vector),
565 
566 	TP_STRUCT__entry(
567 		__field(	__u32,		apicid		)
568 		__field(	int,		vector		)
569 	),
570 
571 	TP_fast_assign(
572 		__entry->apicid		= apic->vcpu->vcpu_id;
573 		__entry->vector		= vector;
574 	),
575 
576 	TP_printk("apicid %x vector %d", __entry->apicid, __entry->vector)
577 );
578 
579 /*
580  * Tracepoint for nested VMRUN
581  */
582 TRACE_EVENT(kvm_nested_vmrun,
583 	    TP_PROTO(__u64 rip, __u64 vmcb, __u64 nested_rip, __u32 int_ctl,
584 		     __u32 event_inj, bool npt),
585 	    TP_ARGS(rip, vmcb, nested_rip, int_ctl, event_inj, npt),
586 
587 	TP_STRUCT__entry(
588 		__field(	__u64,		rip		)
589 		__field(	__u64,		vmcb		)
590 		__field(	__u64,		nested_rip	)
591 		__field(	__u32,		int_ctl		)
592 		__field(	__u32,		event_inj	)
593 		__field(	bool,		npt		)
594 	),
595 
596 	TP_fast_assign(
597 		__entry->rip		= rip;
598 		__entry->vmcb		= vmcb;
599 		__entry->nested_rip	= nested_rip;
600 		__entry->int_ctl	= int_ctl;
601 		__entry->event_inj	= event_inj;
602 		__entry->npt		= npt;
603 	),
604 
605 	TP_printk("rip: 0x%016llx vmcb: 0x%016llx nrip: 0x%016llx int_ctl: 0x%08x "
606 		  "event_inj: 0x%08x npt: %s",
607 		__entry->rip, __entry->vmcb, __entry->nested_rip,
608 		__entry->int_ctl, __entry->event_inj,
609 		__entry->npt ? "on" : "off")
610 );
611 
612 TRACE_EVENT(kvm_nested_intercepts,
613 	    TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions,
614 		     __u32 intercept1, __u32 intercept2, __u32 intercept3),
615 	    TP_ARGS(cr_read, cr_write, exceptions, intercept1,
616 		    intercept2, intercept3),
617 
618 	TP_STRUCT__entry(
619 		__field(	__u16,		cr_read		)
620 		__field(	__u16,		cr_write	)
621 		__field(	__u32,		exceptions	)
622 		__field(	__u32,		intercept1	)
623 		__field(	__u32,		intercept2	)
624 		__field(	__u32,		intercept3	)
625 	),
626 
627 	TP_fast_assign(
628 		__entry->cr_read	= cr_read;
629 		__entry->cr_write	= cr_write;
630 		__entry->exceptions	= exceptions;
631 		__entry->intercept1	= intercept1;
632 		__entry->intercept2	= intercept2;
633 		__entry->intercept3	= intercept3;
634 	),
635 
636 	TP_printk("cr_read: %04x cr_write: %04x excp: %08x "
637 		  "intercepts: %08x %08x %08x",
638 		  __entry->cr_read, __entry->cr_write, __entry->exceptions,
639 		  __entry->intercept1, __entry->intercept2, __entry->intercept3)
640 );
641 /*
642  * Tracepoint for #VMEXIT while nested
643  */
644 TRACE_EVENT_KVM_EXIT(kvm_nested_vmexit);
645 
646 /*
647  * Tracepoint for #VMEXIT reinjected to the guest
648  */
649 TRACE_EVENT(kvm_nested_vmexit_inject,
650 	    TP_PROTO(__u32 exit_code,
651 		     __u64 exit_info1, __u64 exit_info2,
652 		     __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
653 	    TP_ARGS(exit_code, exit_info1, exit_info2,
654 		    exit_int_info, exit_int_info_err, isa),
655 
656 	TP_STRUCT__entry(
657 		__field(	__u32,		exit_code		)
658 		__field(	__u64,		exit_info1		)
659 		__field(	__u64,		exit_info2		)
660 		__field(	__u32,		exit_int_info		)
661 		__field(	__u32,		exit_int_info_err	)
662 		__field(	__u32,		isa			)
663 	),
664 
665 	TP_fast_assign(
666 		__entry->exit_code		= exit_code;
667 		__entry->exit_info1		= exit_info1;
668 		__entry->exit_info2		= exit_info2;
669 		__entry->exit_int_info		= exit_int_info;
670 		__entry->exit_int_info_err	= exit_int_info_err;
671 		__entry->isa			= isa;
672 	),
673 
674 	TP_printk("reason: %s%s%s ext_inf1: 0x%016llx "
675 		  "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
676 		  kvm_print_exit_reason(__entry->exit_code, __entry->isa),
677 		  __entry->exit_info1, __entry->exit_info2,
678 		  __entry->exit_int_info, __entry->exit_int_info_err)
679 );
680 
681 /*
682  * Tracepoint for nested #vmexit because of interrupt pending
683  */
684 TRACE_EVENT(kvm_nested_intr_vmexit,
685 	    TP_PROTO(__u64 rip),
686 	    TP_ARGS(rip),
687 
688 	TP_STRUCT__entry(
689 		__field(	__u64,	rip	)
690 	),
691 
692 	TP_fast_assign(
693 		__entry->rip	=	rip
694 	),
695 
696 	TP_printk("rip: 0x%016llx", __entry->rip)
697 );
698 
699 /*
700  * Tracepoint for nested #vmexit because of interrupt pending
701  */
702 TRACE_EVENT(kvm_invlpga,
703 	    TP_PROTO(__u64 rip, int asid, u64 address),
704 	    TP_ARGS(rip, asid, address),
705 
706 	TP_STRUCT__entry(
707 		__field(	__u64,	rip	)
708 		__field(	int,	asid	)
709 		__field(	__u64,	address	)
710 	),
711 
712 	TP_fast_assign(
713 		__entry->rip		=	rip;
714 		__entry->asid		=	asid;
715 		__entry->address	=	address;
716 	),
717 
718 	TP_printk("rip: 0x%016llx asid: %d address: 0x%016llx",
719 		  __entry->rip, __entry->asid, __entry->address)
720 );
721 
722 /*
723  * Tracepoint for nested #vmexit because of interrupt pending
724  */
725 TRACE_EVENT(kvm_skinit,
726 	    TP_PROTO(__u64 rip, __u32 slb),
727 	    TP_ARGS(rip, slb),
728 
729 	TP_STRUCT__entry(
730 		__field(	__u64,	rip	)
731 		__field(	__u32,	slb	)
732 	),
733 
734 	TP_fast_assign(
735 		__entry->rip		=	rip;
736 		__entry->slb		=	slb;
737 	),
738 
739 	TP_printk("rip: 0x%016llx slb: 0x%08x",
740 		  __entry->rip, __entry->slb)
741 );
742 
743 #define KVM_EMUL_INSN_F_CR0_PE (1 << 0)
744 #define KVM_EMUL_INSN_F_EFL_VM (1 << 1)
745 #define KVM_EMUL_INSN_F_CS_D   (1 << 2)
746 #define KVM_EMUL_INSN_F_CS_L   (1 << 3)
747 
748 #define kvm_trace_symbol_emul_flags	                  \
749 	{ 0,   			    "real" },		  \
750 	{ KVM_EMUL_INSN_F_CR0_PE			  \
751 	  | KVM_EMUL_INSN_F_EFL_VM, "vm16" },		  \
752 	{ KVM_EMUL_INSN_F_CR0_PE,   "prot16" },		  \
753 	{ KVM_EMUL_INSN_F_CR0_PE			  \
754 	  | KVM_EMUL_INSN_F_CS_D,   "prot32" },		  \
755 	{ KVM_EMUL_INSN_F_CR0_PE			  \
756 	  | KVM_EMUL_INSN_F_CS_L,   "prot64" }
757 
758 #define kei_decode_mode(mode) ({			\
759 	u8 flags = 0xff;				\
760 	switch (mode) {					\
761 	case X86EMUL_MODE_REAL:				\
762 		flags = 0;				\
763 		break;					\
764 	case X86EMUL_MODE_VM86:				\
765 		flags = KVM_EMUL_INSN_F_EFL_VM;		\
766 		break;					\
767 	case X86EMUL_MODE_PROT16:			\
768 		flags = KVM_EMUL_INSN_F_CR0_PE;		\
769 		break;					\
770 	case X86EMUL_MODE_PROT32:			\
771 		flags = KVM_EMUL_INSN_F_CR0_PE		\
772 			| KVM_EMUL_INSN_F_CS_D;		\
773 		break;					\
774 	case X86EMUL_MODE_PROT64:			\
775 		flags = KVM_EMUL_INSN_F_CR0_PE		\
776 			| KVM_EMUL_INSN_F_CS_L;		\
777 		break;					\
778 	}						\
779 	flags;						\
780 	})
781 
782 TRACE_EVENT(kvm_emulate_insn,
783 	TP_PROTO(struct kvm_vcpu *vcpu, __u8 failed),
784 	TP_ARGS(vcpu, failed),
785 
786 	TP_STRUCT__entry(
787 		__field(    __u64, rip                       )
788 		__field(    __u32, csbase                    )
789 		__field(    __u8,  len                       )
790 		__array(    __u8,  insn,    15	             )
791 		__field(    __u8,  flags       	   	     )
792 		__field(    __u8,  failed                    )
793 		),
794 
795 	TP_fast_assign(
796 		__entry->csbase = static_call(kvm_x86_get_segment_base)(vcpu, VCPU_SREG_CS);
797 		__entry->len = vcpu->arch.emulate_ctxt->fetch.ptr
798 			       - vcpu->arch.emulate_ctxt->fetch.data;
799 		__entry->rip = vcpu->arch.emulate_ctxt->_eip - __entry->len;
800 		memcpy(__entry->insn,
801 		       vcpu->arch.emulate_ctxt->fetch.data,
802 		       15);
803 		__entry->flags = kei_decode_mode(vcpu->arch.emulate_ctxt->mode);
804 		__entry->failed = failed;
805 		),
806 
807 	TP_printk("%x:%llx:%s (%s)%s",
808 		  __entry->csbase, __entry->rip,
809 		  __print_hex(__entry->insn, __entry->len),
810 		  __print_symbolic(__entry->flags,
811 				   kvm_trace_symbol_emul_flags),
812 		  __entry->failed ? " failed" : ""
813 		)
814 	);
815 
816 #define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0)
817 #define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1)
818 
819 TRACE_EVENT(
820 	vcpu_match_mmio,
821 	TP_PROTO(gva_t gva, gpa_t gpa, bool write, bool gpa_match),
822 	TP_ARGS(gva, gpa, write, gpa_match),
823 
824 	TP_STRUCT__entry(
825 		__field(gva_t, gva)
826 		__field(gpa_t, gpa)
827 		__field(bool, write)
828 		__field(bool, gpa_match)
829 		),
830 
831 	TP_fast_assign(
832 		__entry->gva = gva;
833 		__entry->gpa = gpa;
834 		__entry->write = write;
835 		__entry->gpa_match = gpa_match
836 		),
837 
838 	TP_printk("gva %#lx gpa %#llx %s %s", __entry->gva, __entry->gpa,
839 		  __entry->write ? "Write" : "Read",
840 		  __entry->gpa_match ? "GPA" : "GVA")
841 );
842 
843 TRACE_EVENT(kvm_write_tsc_offset,
844 	TP_PROTO(unsigned int vcpu_id, __u64 previous_tsc_offset,
845 		 __u64 next_tsc_offset),
846 	TP_ARGS(vcpu_id, previous_tsc_offset, next_tsc_offset),
847 
848 	TP_STRUCT__entry(
849 		__field( unsigned int,	vcpu_id				)
850 		__field(	__u64,	previous_tsc_offset		)
851 		__field(	__u64,	next_tsc_offset			)
852 	),
853 
854 	TP_fast_assign(
855 		__entry->vcpu_id		= vcpu_id;
856 		__entry->previous_tsc_offset	= previous_tsc_offset;
857 		__entry->next_tsc_offset	= next_tsc_offset;
858 	),
859 
860 	TP_printk("vcpu=%u prev=%llu next=%llu", __entry->vcpu_id,
861 		  __entry->previous_tsc_offset, __entry->next_tsc_offset)
862 );
863 
864 #ifdef CONFIG_X86_64
865 
866 #define host_clocks					\
867 	{VDSO_CLOCKMODE_NONE, "none"},			\
868 	{VDSO_CLOCKMODE_TSC,  "tsc"}			\
869 
870 TRACE_EVENT(kvm_update_master_clock,
871 	TP_PROTO(bool use_master_clock, unsigned int host_clock, bool offset_matched),
872 	TP_ARGS(use_master_clock, host_clock, offset_matched),
873 
874 	TP_STRUCT__entry(
875 		__field(		bool,	use_master_clock	)
876 		__field(	unsigned int,	host_clock		)
877 		__field(		bool,	offset_matched		)
878 	),
879 
880 	TP_fast_assign(
881 		__entry->use_master_clock	= use_master_clock;
882 		__entry->host_clock		= host_clock;
883 		__entry->offset_matched		= offset_matched;
884 	),
885 
886 	TP_printk("masterclock %d hostclock %s offsetmatched %u",
887 		  __entry->use_master_clock,
888 		  __print_symbolic(__entry->host_clock, host_clocks),
889 		  __entry->offset_matched)
890 );
891 
892 TRACE_EVENT(kvm_track_tsc,
893 	TP_PROTO(unsigned int vcpu_id, unsigned int nr_matched,
894 		 unsigned int online_vcpus, bool use_master_clock,
895 		 unsigned int host_clock),
896 	TP_ARGS(vcpu_id, nr_matched, online_vcpus, use_master_clock,
897 		host_clock),
898 
899 	TP_STRUCT__entry(
900 		__field(	unsigned int,	vcpu_id			)
901 		__field(	unsigned int,	nr_vcpus_matched_tsc	)
902 		__field(	unsigned int,	online_vcpus		)
903 		__field(	bool,		use_master_clock	)
904 		__field(	unsigned int,	host_clock		)
905 	),
906 
907 	TP_fast_assign(
908 		__entry->vcpu_id		= vcpu_id;
909 		__entry->nr_vcpus_matched_tsc	= nr_matched;
910 		__entry->online_vcpus		= online_vcpus;
911 		__entry->use_master_clock	= use_master_clock;
912 		__entry->host_clock		= host_clock;
913 	),
914 
915 	TP_printk("vcpu_id %u masterclock %u offsetmatched %u nr_online %u"
916 		  " hostclock %s",
917 		  __entry->vcpu_id, __entry->use_master_clock,
918 		  __entry->nr_vcpus_matched_tsc, __entry->online_vcpus,
919 		  __print_symbolic(__entry->host_clock, host_clocks))
920 );
921 
922 #endif /* CONFIG_X86_64 */
923 
924 /*
925  * Tracepoint for PML full VMEXIT.
926  */
927 TRACE_EVENT(kvm_pml_full,
928 	TP_PROTO(unsigned int vcpu_id),
929 	TP_ARGS(vcpu_id),
930 
931 	TP_STRUCT__entry(
932 		__field(	unsigned int,	vcpu_id			)
933 	),
934 
935 	TP_fast_assign(
936 		__entry->vcpu_id		= vcpu_id;
937 	),
938 
939 	TP_printk("vcpu %d: PML full", __entry->vcpu_id)
940 );
941 
942 TRACE_EVENT(kvm_ple_window_update,
943 	TP_PROTO(unsigned int vcpu_id, unsigned int new, unsigned int old),
944 	TP_ARGS(vcpu_id, new, old),
945 
946 	TP_STRUCT__entry(
947 		__field(        unsigned int,   vcpu_id         )
948 		__field(        unsigned int,       new         )
949 		__field(        unsigned int,       old         )
950 	),
951 
952 	TP_fast_assign(
953 		__entry->vcpu_id        = vcpu_id;
954 		__entry->new            = new;
955 		__entry->old            = old;
956 	),
957 
958 	TP_printk("vcpu %u old %u new %u (%s)",
959 	          __entry->vcpu_id, __entry->old, __entry->new,
960 		  __entry->old < __entry->new ? "growed" : "shrinked")
961 );
962 
963 TRACE_EVENT(kvm_pvclock_update,
964 	TP_PROTO(unsigned int vcpu_id, struct pvclock_vcpu_time_info *pvclock),
965 	TP_ARGS(vcpu_id, pvclock),
966 
967 	TP_STRUCT__entry(
968 		__field(	unsigned int,	vcpu_id			)
969 		__field(	__u32,		version			)
970 		__field(	__u64,		tsc_timestamp		)
971 		__field(	__u64,		system_time		)
972 		__field(	__u32,		tsc_to_system_mul	)
973 		__field(	__s8,		tsc_shift		)
974 		__field(	__u8,		flags			)
975 	),
976 
977 	TP_fast_assign(
978 		__entry->vcpu_id	   = vcpu_id;
979 		__entry->version	   = pvclock->version;
980 		__entry->tsc_timestamp	   = pvclock->tsc_timestamp;
981 		__entry->system_time	   = pvclock->system_time;
982 		__entry->tsc_to_system_mul = pvclock->tsc_to_system_mul;
983 		__entry->tsc_shift	   = pvclock->tsc_shift;
984 		__entry->flags		   = pvclock->flags;
985 	),
986 
987 	TP_printk("vcpu_id %u, pvclock { version %u, tsc_timestamp 0x%llx, "
988 		  "system_time 0x%llx, tsc_to_system_mul 0x%x, tsc_shift %d, "
989 		  "flags 0x%x }",
990 		  __entry->vcpu_id,
991 		  __entry->version,
992 		  __entry->tsc_timestamp,
993 		  __entry->system_time,
994 		  __entry->tsc_to_system_mul,
995 		  __entry->tsc_shift,
996 		  __entry->flags)
997 );
998 
999 TRACE_EVENT(kvm_wait_lapic_expire,
1000 	TP_PROTO(unsigned int vcpu_id, s64 delta),
1001 	TP_ARGS(vcpu_id, delta),
1002 
1003 	TP_STRUCT__entry(
1004 		__field(	unsigned int,	vcpu_id		)
1005 		__field(	s64,		delta		)
1006 	),
1007 
1008 	TP_fast_assign(
1009 		__entry->vcpu_id	   = vcpu_id;
1010 		__entry->delta             = delta;
1011 	),
1012 
1013 	TP_printk("vcpu %u: delta %lld (%s)",
1014 		  __entry->vcpu_id,
1015 		  __entry->delta,
1016 		  __entry->delta < 0 ? "early" : "late")
1017 );
1018 
1019 TRACE_EVENT(kvm_smm_transition,
1020 	TP_PROTO(unsigned int vcpu_id, u64 smbase, bool entering),
1021 	TP_ARGS(vcpu_id, smbase, entering),
1022 
1023 	TP_STRUCT__entry(
1024 		__field(	unsigned int,	vcpu_id		)
1025 		__field(	u64,		smbase		)
1026 		__field(	bool,		entering	)
1027 	),
1028 
1029 	TP_fast_assign(
1030 		__entry->vcpu_id	= vcpu_id;
1031 		__entry->smbase		= smbase;
1032 		__entry->entering	= entering;
1033 	),
1034 
1035 	TP_printk("vcpu %u: %s SMM, smbase 0x%llx",
1036 		  __entry->vcpu_id,
1037 		  __entry->entering ? "entering" : "leaving",
1038 		  __entry->smbase)
1039 );
1040 
1041 /*
1042  * Tracepoint for VT-d posted-interrupts.
1043  */
1044 TRACE_EVENT(kvm_pi_irte_update,
1045 	TP_PROTO(unsigned int host_irq, unsigned int vcpu_id,
1046 		 unsigned int gsi, unsigned int gvec,
1047 		 u64 pi_desc_addr, bool set),
1048 	TP_ARGS(host_irq, vcpu_id, gsi, gvec, pi_desc_addr, set),
1049 
1050 	TP_STRUCT__entry(
1051 		__field(	unsigned int,	host_irq	)
1052 		__field(	unsigned int,	vcpu_id		)
1053 		__field(	unsigned int,	gsi		)
1054 		__field(	unsigned int,	gvec		)
1055 		__field(	u64,		pi_desc_addr	)
1056 		__field(	bool,		set		)
1057 	),
1058 
1059 	TP_fast_assign(
1060 		__entry->host_irq	= host_irq;
1061 		__entry->vcpu_id	= vcpu_id;
1062 		__entry->gsi		= gsi;
1063 		__entry->gvec		= gvec;
1064 		__entry->pi_desc_addr	= pi_desc_addr;
1065 		__entry->set		= set;
1066 	),
1067 
1068 	TP_printk("VT-d PI is %s for irq %u, vcpu %u, gsi: 0x%x, "
1069 		  "gvec: 0x%x, pi_desc_addr: 0x%llx",
1070 		  __entry->set ? "enabled and being updated" : "disabled",
1071 		  __entry->host_irq,
1072 		  __entry->vcpu_id,
1073 		  __entry->gsi,
1074 		  __entry->gvec,
1075 		  __entry->pi_desc_addr)
1076 );
1077 
1078 /*
1079  * Tracepoint for kvm_hv_notify_acked_sint.
1080  */
1081 TRACE_EVENT(kvm_hv_notify_acked_sint,
1082 	TP_PROTO(int vcpu_id, u32 sint),
1083 	TP_ARGS(vcpu_id, sint),
1084 
1085 	TP_STRUCT__entry(
1086 		__field(int, vcpu_id)
1087 		__field(u32, sint)
1088 	),
1089 
1090 	TP_fast_assign(
1091 		__entry->vcpu_id = vcpu_id;
1092 		__entry->sint = sint;
1093 	),
1094 
1095 	TP_printk("vcpu_id %d sint %u", __entry->vcpu_id, __entry->sint)
1096 );
1097 
1098 /*
1099  * Tracepoint for synic_set_irq.
1100  */
1101 TRACE_EVENT(kvm_hv_synic_set_irq,
1102 	TP_PROTO(int vcpu_id, u32 sint, int vector, int ret),
1103 	TP_ARGS(vcpu_id, sint, vector, ret),
1104 
1105 	TP_STRUCT__entry(
1106 		__field(int, vcpu_id)
1107 		__field(u32, sint)
1108 		__field(int, vector)
1109 		__field(int, ret)
1110 	),
1111 
1112 	TP_fast_assign(
1113 		__entry->vcpu_id = vcpu_id;
1114 		__entry->sint = sint;
1115 		__entry->vector = vector;
1116 		__entry->ret = ret;
1117 	),
1118 
1119 	TP_printk("vcpu_id %d sint %u vector %d ret %d",
1120 		  __entry->vcpu_id, __entry->sint, __entry->vector,
1121 		  __entry->ret)
1122 );
1123 
1124 /*
1125  * Tracepoint for kvm_hv_synic_send_eoi.
1126  */
1127 TRACE_EVENT(kvm_hv_synic_send_eoi,
1128 	TP_PROTO(int vcpu_id, int vector),
1129 	TP_ARGS(vcpu_id, vector),
1130 
1131 	TP_STRUCT__entry(
1132 		__field(int, vcpu_id)
1133 		__field(u32, sint)
1134 		__field(int, vector)
1135 		__field(int, ret)
1136 	),
1137 
1138 	TP_fast_assign(
1139 		__entry->vcpu_id = vcpu_id;
1140 		__entry->vector	= vector;
1141 	),
1142 
1143 	TP_printk("vcpu_id %d vector %d", __entry->vcpu_id, __entry->vector)
1144 );
1145 
1146 /*
1147  * Tracepoint for synic_set_msr.
1148  */
1149 TRACE_EVENT(kvm_hv_synic_set_msr,
1150 	TP_PROTO(int vcpu_id, u32 msr, u64 data, bool host),
1151 	TP_ARGS(vcpu_id, msr, data, host),
1152 
1153 	TP_STRUCT__entry(
1154 		__field(int, vcpu_id)
1155 		__field(u32, msr)
1156 		__field(u64, data)
1157 		__field(bool, host)
1158 	),
1159 
1160 	TP_fast_assign(
1161 		__entry->vcpu_id = vcpu_id;
1162 		__entry->msr = msr;
1163 		__entry->data = data;
1164 		__entry->host = host
1165 	),
1166 
1167 	TP_printk("vcpu_id %d msr 0x%x data 0x%llx host %d",
1168 		  __entry->vcpu_id, __entry->msr, __entry->data, __entry->host)
1169 );
1170 
1171 /*
1172  * Tracepoint for stimer_set_config.
1173  */
1174 TRACE_EVENT(kvm_hv_stimer_set_config,
1175 	TP_PROTO(int vcpu_id, int timer_index, u64 config, bool host),
1176 	TP_ARGS(vcpu_id, timer_index, config, host),
1177 
1178 	TP_STRUCT__entry(
1179 		__field(int, vcpu_id)
1180 		__field(int, timer_index)
1181 		__field(u64, config)
1182 		__field(bool, host)
1183 	),
1184 
1185 	TP_fast_assign(
1186 		__entry->vcpu_id = vcpu_id;
1187 		__entry->timer_index = timer_index;
1188 		__entry->config = config;
1189 		__entry->host = host;
1190 	),
1191 
1192 	TP_printk("vcpu_id %d timer %d config 0x%llx host %d",
1193 		  __entry->vcpu_id, __entry->timer_index, __entry->config,
1194 		  __entry->host)
1195 );
1196 
1197 /*
1198  * Tracepoint for stimer_set_count.
1199  */
1200 TRACE_EVENT(kvm_hv_stimer_set_count,
1201 	TP_PROTO(int vcpu_id, int timer_index, u64 count, bool host),
1202 	TP_ARGS(vcpu_id, timer_index, count, host),
1203 
1204 	TP_STRUCT__entry(
1205 		__field(int, vcpu_id)
1206 		__field(int, timer_index)
1207 		__field(u64, count)
1208 		__field(bool, host)
1209 	),
1210 
1211 	TP_fast_assign(
1212 		__entry->vcpu_id = vcpu_id;
1213 		__entry->timer_index = timer_index;
1214 		__entry->count = count;
1215 		__entry->host = host;
1216 	),
1217 
1218 	TP_printk("vcpu_id %d timer %d count %llu host %d",
1219 		  __entry->vcpu_id, __entry->timer_index, __entry->count,
1220 		  __entry->host)
1221 );
1222 
1223 /*
1224  * Tracepoint for stimer_start(periodic timer case).
1225  */
1226 TRACE_EVENT(kvm_hv_stimer_start_periodic,
1227 	TP_PROTO(int vcpu_id, int timer_index, u64 time_now, u64 exp_time),
1228 	TP_ARGS(vcpu_id, timer_index, time_now, exp_time),
1229 
1230 	TP_STRUCT__entry(
1231 		__field(int, vcpu_id)
1232 		__field(int, timer_index)
1233 		__field(u64, time_now)
1234 		__field(u64, exp_time)
1235 	),
1236 
1237 	TP_fast_assign(
1238 		__entry->vcpu_id = vcpu_id;
1239 		__entry->timer_index = timer_index;
1240 		__entry->time_now = time_now;
1241 		__entry->exp_time = exp_time;
1242 	),
1243 
1244 	TP_printk("vcpu_id %d timer %d time_now %llu exp_time %llu",
1245 		  __entry->vcpu_id, __entry->timer_index, __entry->time_now,
1246 		  __entry->exp_time)
1247 );
1248 
1249 /*
1250  * Tracepoint for stimer_start(one-shot timer case).
1251  */
1252 TRACE_EVENT(kvm_hv_stimer_start_one_shot,
1253 	TP_PROTO(int vcpu_id, int timer_index, u64 time_now, u64 count),
1254 	TP_ARGS(vcpu_id, timer_index, time_now, count),
1255 
1256 	TP_STRUCT__entry(
1257 		__field(int, vcpu_id)
1258 		__field(int, timer_index)
1259 		__field(u64, time_now)
1260 		__field(u64, count)
1261 	),
1262 
1263 	TP_fast_assign(
1264 		__entry->vcpu_id = vcpu_id;
1265 		__entry->timer_index = timer_index;
1266 		__entry->time_now = time_now;
1267 		__entry->count = count;
1268 	),
1269 
1270 	TP_printk("vcpu_id %d timer %d time_now %llu count %llu",
1271 		  __entry->vcpu_id, __entry->timer_index, __entry->time_now,
1272 		  __entry->count)
1273 );
1274 
1275 /*
1276  * Tracepoint for stimer_timer_callback.
1277  */
1278 TRACE_EVENT(kvm_hv_stimer_callback,
1279 	TP_PROTO(int vcpu_id, int timer_index),
1280 	TP_ARGS(vcpu_id, timer_index),
1281 
1282 	TP_STRUCT__entry(
1283 		__field(int, vcpu_id)
1284 		__field(int, timer_index)
1285 	),
1286 
1287 	TP_fast_assign(
1288 		__entry->vcpu_id = vcpu_id;
1289 		__entry->timer_index = timer_index;
1290 	),
1291 
1292 	TP_printk("vcpu_id %d timer %d",
1293 		  __entry->vcpu_id, __entry->timer_index)
1294 );
1295 
1296 /*
1297  * Tracepoint for stimer_expiration.
1298  */
1299 TRACE_EVENT(kvm_hv_stimer_expiration,
1300 	TP_PROTO(int vcpu_id, int timer_index, int direct, int msg_send_result),
1301 	TP_ARGS(vcpu_id, timer_index, direct, msg_send_result),
1302 
1303 	TP_STRUCT__entry(
1304 		__field(int, vcpu_id)
1305 		__field(int, timer_index)
1306 		__field(int, direct)
1307 		__field(int, msg_send_result)
1308 	),
1309 
1310 	TP_fast_assign(
1311 		__entry->vcpu_id = vcpu_id;
1312 		__entry->timer_index = timer_index;
1313 		__entry->direct = direct;
1314 		__entry->msg_send_result = msg_send_result;
1315 	),
1316 
1317 	TP_printk("vcpu_id %d timer %d direct %d send result %d",
1318 		  __entry->vcpu_id, __entry->timer_index,
1319 		  __entry->direct, __entry->msg_send_result)
1320 );
1321 
1322 /*
1323  * Tracepoint for stimer_cleanup.
1324  */
1325 TRACE_EVENT(kvm_hv_stimer_cleanup,
1326 	TP_PROTO(int vcpu_id, int timer_index),
1327 	TP_ARGS(vcpu_id, timer_index),
1328 
1329 	TP_STRUCT__entry(
1330 		__field(int, vcpu_id)
1331 		__field(int, timer_index)
1332 	),
1333 
1334 	TP_fast_assign(
1335 		__entry->vcpu_id = vcpu_id;
1336 		__entry->timer_index = timer_index;
1337 	),
1338 
1339 	TP_printk("vcpu_id %d timer %d",
1340 		  __entry->vcpu_id, __entry->timer_index)
1341 );
1342 
1343 TRACE_EVENT(kvm_apicv_update_request,
1344 	    TP_PROTO(bool activate, unsigned long bit),
1345 	    TP_ARGS(activate, bit),
1346 
1347 	TP_STRUCT__entry(
1348 		__field(bool, activate)
1349 		__field(unsigned long, bit)
1350 	),
1351 
1352 	TP_fast_assign(
1353 		__entry->activate = activate;
1354 		__entry->bit = bit;
1355 	),
1356 
1357 	TP_printk("%s bit=%lu",
1358 		  __entry->activate ? "activate" : "deactivate",
1359 		  __entry->bit)
1360 );
1361 
1362 /*
1363  * Tracepoint for AMD AVIC
1364  */
1365 TRACE_EVENT(kvm_avic_incomplete_ipi,
1366 	    TP_PROTO(u32 vcpu, u32 icrh, u32 icrl, u32 id, u32 index),
1367 	    TP_ARGS(vcpu, icrh, icrl, id, index),
1368 
1369 	TP_STRUCT__entry(
1370 		__field(u32, vcpu)
1371 		__field(u32, icrh)
1372 		__field(u32, icrl)
1373 		__field(u32, id)
1374 		__field(u32, index)
1375 	),
1376 
1377 	TP_fast_assign(
1378 		__entry->vcpu = vcpu;
1379 		__entry->icrh = icrh;
1380 		__entry->icrl = icrl;
1381 		__entry->id = id;
1382 		__entry->index = index;
1383 	),
1384 
1385 	TP_printk("vcpu=%u, icrh:icrl=%#010x:%08x, id=%u, index=%u",
1386 		  __entry->vcpu, __entry->icrh, __entry->icrl,
1387 		  __entry->id, __entry->index)
1388 );
1389 
1390 TRACE_EVENT(kvm_avic_unaccelerated_access,
1391 	    TP_PROTO(u32 vcpu, u32 offset, bool ft, bool rw, u32 vec),
1392 	    TP_ARGS(vcpu, offset, ft, rw, vec),
1393 
1394 	TP_STRUCT__entry(
1395 		__field(u32, vcpu)
1396 		__field(u32, offset)
1397 		__field(bool, ft)
1398 		__field(bool, rw)
1399 		__field(u32, vec)
1400 	),
1401 
1402 	TP_fast_assign(
1403 		__entry->vcpu = vcpu;
1404 		__entry->offset = offset;
1405 		__entry->ft = ft;
1406 		__entry->rw = rw;
1407 		__entry->vec = vec;
1408 	),
1409 
1410 	TP_printk("vcpu=%u, offset=%#x(%s), %s, %s, vec=%#x",
1411 		  __entry->vcpu,
1412 		  __entry->offset,
1413 		  __print_symbolic(__entry->offset, kvm_trace_symbol_apic),
1414 		  __entry->ft ? "trap" : "fault",
1415 		  __entry->rw ? "write" : "read",
1416 		  __entry->vec)
1417 );
1418 
1419 TRACE_EVENT(kvm_avic_ga_log,
1420 	    TP_PROTO(u32 vmid, u32 vcpuid),
1421 	    TP_ARGS(vmid, vcpuid),
1422 
1423 	TP_STRUCT__entry(
1424 		__field(u32, vmid)
1425 		__field(u32, vcpuid)
1426 	),
1427 
1428 	TP_fast_assign(
1429 		__entry->vmid = vmid;
1430 		__entry->vcpuid = vcpuid;
1431 	),
1432 
1433 	TP_printk("vmid=%u, vcpuid=%u",
1434 		  __entry->vmid, __entry->vcpuid)
1435 );
1436 
1437 TRACE_EVENT(kvm_hv_timer_state,
1438 		TP_PROTO(unsigned int vcpu_id, unsigned int hv_timer_in_use),
1439 		TP_ARGS(vcpu_id, hv_timer_in_use),
1440 		TP_STRUCT__entry(
1441 			__field(unsigned int, vcpu_id)
1442 			__field(unsigned int, hv_timer_in_use)
1443 			),
1444 		TP_fast_assign(
1445 			__entry->vcpu_id = vcpu_id;
1446 			__entry->hv_timer_in_use = hv_timer_in_use;
1447 			),
1448 		TP_printk("vcpu_id %x hv_timer %x",
1449 			__entry->vcpu_id,
1450 			__entry->hv_timer_in_use)
1451 );
1452 
1453 /*
1454  * Tracepoint for kvm_hv_flush_tlb.
1455  */
1456 TRACE_EVENT(kvm_hv_flush_tlb,
1457 	TP_PROTO(u64 processor_mask, u64 address_space, u64 flags),
1458 	TP_ARGS(processor_mask, address_space, flags),
1459 
1460 	TP_STRUCT__entry(
1461 		__field(u64, processor_mask)
1462 		__field(u64, address_space)
1463 		__field(u64, flags)
1464 	),
1465 
1466 	TP_fast_assign(
1467 		__entry->processor_mask = processor_mask;
1468 		__entry->address_space = address_space;
1469 		__entry->flags = flags;
1470 	),
1471 
1472 	TP_printk("processor_mask 0x%llx address_space 0x%llx flags 0x%llx",
1473 		  __entry->processor_mask, __entry->address_space,
1474 		  __entry->flags)
1475 );
1476 
1477 /*
1478  * Tracepoint for kvm_hv_flush_tlb_ex.
1479  */
1480 TRACE_EVENT(kvm_hv_flush_tlb_ex,
1481 	TP_PROTO(u64 valid_bank_mask, u64 format, u64 address_space, u64 flags),
1482 	TP_ARGS(valid_bank_mask, format, address_space, flags),
1483 
1484 	TP_STRUCT__entry(
1485 		__field(u64, valid_bank_mask)
1486 		__field(u64, format)
1487 		__field(u64, address_space)
1488 		__field(u64, flags)
1489 	),
1490 
1491 	TP_fast_assign(
1492 		__entry->valid_bank_mask = valid_bank_mask;
1493 		__entry->format = format;
1494 		__entry->address_space = address_space;
1495 		__entry->flags = flags;
1496 	),
1497 
1498 	TP_printk("valid_bank_mask 0x%llx format 0x%llx "
1499 		  "address_space 0x%llx flags 0x%llx",
1500 		  __entry->valid_bank_mask, __entry->format,
1501 		  __entry->address_space, __entry->flags)
1502 );
1503 
1504 /*
1505  * Tracepoints for kvm_hv_send_ipi.
1506  */
1507 TRACE_EVENT(kvm_hv_send_ipi,
1508 	TP_PROTO(u32 vector, u64 processor_mask),
1509 	TP_ARGS(vector, processor_mask),
1510 
1511 	TP_STRUCT__entry(
1512 		__field(u32, vector)
1513 		__field(u64, processor_mask)
1514 	),
1515 
1516 	TP_fast_assign(
1517 		__entry->vector = vector;
1518 		__entry->processor_mask = processor_mask;
1519 	),
1520 
1521 	TP_printk("vector %x processor_mask 0x%llx",
1522 		  __entry->vector, __entry->processor_mask)
1523 );
1524 
1525 TRACE_EVENT(kvm_hv_send_ipi_ex,
1526 	TP_PROTO(u32 vector, u64 format, u64 valid_bank_mask),
1527 	TP_ARGS(vector, format, valid_bank_mask),
1528 
1529 	TP_STRUCT__entry(
1530 		__field(u32, vector)
1531 		__field(u64, format)
1532 		__field(u64, valid_bank_mask)
1533 	),
1534 
1535 	TP_fast_assign(
1536 		__entry->vector = vector;
1537 		__entry->format = format;
1538 		__entry->valid_bank_mask = valid_bank_mask;
1539 	),
1540 
1541 	TP_printk("vector %x format %llx valid_bank_mask 0x%llx",
1542 		  __entry->vector, __entry->format,
1543 		  __entry->valid_bank_mask)
1544 );
1545 
1546 TRACE_EVENT(kvm_pv_tlb_flush,
1547 	TP_PROTO(unsigned int vcpu_id, bool need_flush_tlb),
1548 	TP_ARGS(vcpu_id, need_flush_tlb),
1549 
1550 	TP_STRUCT__entry(
1551 		__field(	unsigned int,	vcpu_id		)
1552 		__field(	bool,	need_flush_tlb		)
1553 	),
1554 
1555 	TP_fast_assign(
1556 		__entry->vcpu_id	= vcpu_id;
1557 		__entry->need_flush_tlb = need_flush_tlb;
1558 	),
1559 
1560 	TP_printk("vcpu %u need_flush_tlb %s", __entry->vcpu_id,
1561 		__entry->need_flush_tlb ? "true" : "false")
1562 );
1563 
1564 /*
1565  * Tracepoint for failed nested VMX VM-Enter.
1566  */
1567 TRACE_EVENT(kvm_nested_vmenter_failed,
1568 	TP_PROTO(const char *msg, u32 err),
1569 	TP_ARGS(msg, err),
1570 
1571 	TP_STRUCT__entry(
1572 		__string(msg, msg)
1573 		__field(u32, err)
1574 	),
1575 
1576 	TP_fast_assign(
1577 		__assign_str(msg, msg);
1578 		__entry->err = err;
1579 	),
1580 
1581 	TP_printk("%s%s", __get_str(msg), !__entry->err ? "" :
1582 		__print_symbolic(__entry->err, VMX_VMENTER_INSTRUCTION_ERRORS))
1583 );
1584 
1585 /*
1586  * Tracepoint for syndbg_set_msr.
1587  */
1588 TRACE_EVENT(kvm_hv_syndbg_set_msr,
1589 	TP_PROTO(int vcpu_id, u32 vp_index, u32 msr, u64 data),
1590 	TP_ARGS(vcpu_id, vp_index, msr, data),
1591 
1592 	TP_STRUCT__entry(
1593 		__field(int, vcpu_id)
1594 		__field(u32, vp_index)
1595 		__field(u32, msr)
1596 		__field(u64, data)
1597 	),
1598 
1599 	TP_fast_assign(
1600 		__entry->vcpu_id = vcpu_id;
1601 		__entry->vp_index = vp_index;
1602 		__entry->msr = msr;
1603 		__entry->data = data;
1604 	),
1605 
1606 	TP_printk("vcpu_id %d vp_index %u msr 0x%x data 0x%llx",
1607 		  __entry->vcpu_id, __entry->vp_index, __entry->msr,
1608 		  __entry->data)
1609 );
1610 
1611 /*
1612  * Tracepoint for syndbg_get_msr.
1613  */
1614 TRACE_EVENT(kvm_hv_syndbg_get_msr,
1615 	TP_PROTO(int vcpu_id, u32 vp_index, u32 msr, u64 data),
1616 	TP_ARGS(vcpu_id, vp_index, msr, data),
1617 
1618 	TP_STRUCT__entry(
1619 		__field(int, vcpu_id)
1620 		__field(u32, vp_index)
1621 		__field(u32, msr)
1622 		__field(u64, data)
1623 	),
1624 
1625 	TP_fast_assign(
1626 		__entry->vcpu_id = vcpu_id;
1627 		__entry->vp_index = vp_index;
1628 		__entry->msr = msr;
1629 		__entry->data = data;
1630 	),
1631 
1632 	TP_printk("vcpu_id %d vp_index %u msr 0x%x data 0x%llx",
1633 		  __entry->vcpu_id, __entry->vp_index, __entry->msr,
1634 		  __entry->data)
1635 );
1636 
1637 /*
1638  * Tracepoint for the start of VMGEXIT processing
1639  */
1640 TRACE_EVENT(kvm_vmgexit_enter,
1641 	TP_PROTO(unsigned int vcpu_id, struct ghcb *ghcb),
1642 	TP_ARGS(vcpu_id, ghcb),
1643 
1644 	TP_STRUCT__entry(
1645 		__field(unsigned int, vcpu_id)
1646 		__field(u64, exit_reason)
1647 		__field(u64, info1)
1648 		__field(u64, info2)
1649 	),
1650 
1651 	TP_fast_assign(
1652 		__entry->vcpu_id     = vcpu_id;
1653 		__entry->exit_reason = ghcb->save.sw_exit_code;
1654 		__entry->info1       = ghcb->save.sw_exit_info_1;
1655 		__entry->info2       = ghcb->save.sw_exit_info_2;
1656 	),
1657 
1658 	TP_printk("vcpu %u, exit_reason %llx, exit_info1 %llx, exit_info2 %llx",
1659 		  __entry->vcpu_id, __entry->exit_reason,
1660 		  __entry->info1, __entry->info2)
1661 );
1662 
1663 /*
1664  * Tracepoint for the end of VMGEXIT processing
1665  */
1666 TRACE_EVENT(kvm_vmgexit_exit,
1667 	TP_PROTO(unsigned int vcpu_id, struct ghcb *ghcb),
1668 	TP_ARGS(vcpu_id, ghcb),
1669 
1670 	TP_STRUCT__entry(
1671 		__field(unsigned int, vcpu_id)
1672 		__field(u64, exit_reason)
1673 		__field(u64, info1)
1674 		__field(u64, info2)
1675 	),
1676 
1677 	TP_fast_assign(
1678 		__entry->vcpu_id     = vcpu_id;
1679 		__entry->exit_reason = ghcb->save.sw_exit_code;
1680 		__entry->info1       = ghcb->save.sw_exit_info_1;
1681 		__entry->info2       = ghcb->save.sw_exit_info_2;
1682 	),
1683 
1684 	TP_printk("vcpu %u, exit_reason %llx, exit_info1 %llx, exit_info2 %llx",
1685 		  __entry->vcpu_id, __entry->exit_reason,
1686 		  __entry->info1, __entry->info2)
1687 );
1688 
1689 /*
1690  * Tracepoint for the start of VMGEXIT MSR procotol processing
1691  */
1692 TRACE_EVENT(kvm_vmgexit_msr_protocol_enter,
1693 	TP_PROTO(unsigned int vcpu_id, u64 ghcb_gpa),
1694 	TP_ARGS(vcpu_id, ghcb_gpa),
1695 
1696 	TP_STRUCT__entry(
1697 		__field(unsigned int, vcpu_id)
1698 		__field(u64, ghcb_gpa)
1699 	),
1700 
1701 	TP_fast_assign(
1702 		__entry->vcpu_id  = vcpu_id;
1703 		__entry->ghcb_gpa = ghcb_gpa;
1704 	),
1705 
1706 	TP_printk("vcpu %u, ghcb_gpa %016llx",
1707 		  __entry->vcpu_id, __entry->ghcb_gpa)
1708 );
1709 
1710 /*
1711  * Tracepoint for the end of VMGEXIT MSR procotol processing
1712  */
1713 TRACE_EVENT(kvm_vmgexit_msr_protocol_exit,
1714 	TP_PROTO(unsigned int vcpu_id, u64 ghcb_gpa, int result),
1715 	TP_ARGS(vcpu_id, ghcb_gpa, result),
1716 
1717 	TP_STRUCT__entry(
1718 		__field(unsigned int, vcpu_id)
1719 		__field(u64, ghcb_gpa)
1720 		__field(int, result)
1721 	),
1722 
1723 	TP_fast_assign(
1724 		__entry->vcpu_id  = vcpu_id;
1725 		__entry->ghcb_gpa = ghcb_gpa;
1726 		__entry->result   = result;
1727 	),
1728 
1729 	TP_printk("vcpu %u, ghcb_gpa %016llx, result %d",
1730 		  __entry->vcpu_id, __entry->ghcb_gpa, __entry->result)
1731 );
1732 
1733 #endif /* _TRACE_KVM_H */
1734 
1735 #undef TRACE_INCLUDE_PATH
1736 #define TRACE_INCLUDE_PATH ../../arch/x86/kvm
1737 #undef TRACE_INCLUDE_FILE
1738 #define TRACE_INCLUDE_FILE trace
1739 
1740 /* This part must be outside protection */
1741 #include <trace/define_trace.h>
1742