KVM: x86: improve the usability of the 'kvm_pio' tracepoint
[sfrench/cifs-2.6.git] / arch / x86 / kvm / trace.h
1 #if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
2 #define _TRACE_KVM_H
3
4 #include <linux/tracepoint.h>
5 #include <asm/vmx.h>
6 #include <asm/svm.h>
7 #include <asm/clocksource.h>
8
9 #undef TRACE_SYSTEM
10 #define TRACE_SYSTEM kvm
11
12 /*
13  * Tracepoint for guest mode entry.
14  */
15 TRACE_EVENT(kvm_entry,
16         TP_PROTO(unsigned int vcpu_id),
17         TP_ARGS(vcpu_id),
18
19         TP_STRUCT__entry(
20                 __field(        unsigned int,   vcpu_id         )
21         ),
22
23         TP_fast_assign(
24                 __entry->vcpu_id        = vcpu_id;
25         ),
26
27         TP_printk("vcpu %u", __entry->vcpu_id)
28 );
29
30 /*
31  * Tracepoint for hypercall.
32  */
33 TRACE_EVENT(kvm_hypercall,
34         TP_PROTO(unsigned long nr, unsigned long a0, unsigned long a1,
35                  unsigned long a2, unsigned long a3),
36         TP_ARGS(nr, a0, a1, a2, a3),
37
38         TP_STRUCT__entry(
39                 __field(        unsigned long,  nr              )
40                 __field(        unsigned long,  a0              )
41                 __field(        unsigned long,  a1              )
42                 __field(        unsigned long,  a2              )
43                 __field(        unsigned long,  a3              )
44         ),
45
46         TP_fast_assign(
47                 __entry->nr             = nr;
48                 __entry->a0             = a0;
49                 __entry->a1             = a1;
50                 __entry->a2             = a2;
51                 __entry->a3             = a3;
52         ),
53
54         TP_printk("nr 0x%lx a0 0x%lx a1 0x%lx a2 0x%lx a3 0x%lx",
55                  __entry->nr, __entry->a0, __entry->a1,  __entry->a2,
56                  __entry->a3)
57 );
58
59 /*
60  * Tracepoint for hypercall.
61  */
62 TRACE_EVENT(kvm_hv_hypercall,
63         TP_PROTO(__u16 code, bool fast, __u16 rep_cnt, __u16 rep_idx,
64                  __u64 ingpa, __u64 outgpa),
65         TP_ARGS(code, fast, rep_cnt, rep_idx, ingpa, outgpa),
66
67         TP_STRUCT__entry(
68                 __field(        __u16,          rep_cnt         )
69                 __field(        __u16,          rep_idx         )
70                 __field(        __u64,          ingpa           )
71                 __field(        __u64,          outgpa          )
72                 __field(        __u16,          code            )
73                 __field(        bool,           fast            )
74         ),
75
76         TP_fast_assign(
77                 __entry->rep_cnt        = rep_cnt;
78                 __entry->rep_idx        = rep_idx;
79                 __entry->ingpa          = ingpa;
80                 __entry->outgpa         = outgpa;
81                 __entry->code           = code;
82                 __entry->fast           = fast;
83         ),
84
85         TP_printk("code 0x%x %s cnt 0x%x idx 0x%x in 0x%llx out 0x%llx",
86                   __entry->code, __entry->fast ? "fast" : "slow",
87                   __entry->rep_cnt, __entry->rep_idx,  __entry->ingpa,
88                   __entry->outgpa)
89 );
90
91 /*
92  * Tracepoint for PIO.
93  */
94
95 #define KVM_PIO_IN   0
96 #define KVM_PIO_OUT  1
97
98 TRACE_EVENT(kvm_pio,
99         TP_PROTO(unsigned int rw, unsigned int port, unsigned int size,
100                  unsigned int count, void *data),
101         TP_ARGS(rw, port, size, count, data),
102
103         TP_STRUCT__entry(
104                 __field(        unsigned int,   rw              )
105                 __field(        unsigned int,   port            )
106                 __field(        unsigned int,   size            )
107                 __field(        unsigned int,   count           )
108                 __field(        unsigned int,   val             )
109         ),
110
111         TP_fast_assign(
112                 __entry->rw             = rw;
113                 __entry->port           = port;
114                 __entry->size           = size;
115                 __entry->count          = count;
116                 if (size == 1)
117                         __entry->val    = *(unsigned char *)data;
118                 else if (size == 2)
119                         __entry->val    = *(unsigned short *)data;
120                 else
121                         __entry->val    = *(unsigned int *)data;
122         ),
123
124         TP_printk("pio_%s at 0x%x size %d count %d val 0x%x %s",
125                   __entry->rw ? "write" : "read",
126                   __entry->port, __entry->size, __entry->count, __entry->val,
127                   __entry->count > 1 ? "(...)" : "")
128 );
129
130 /*
131  * Tracepoint for cpuid.
132  */
133 TRACE_EVENT(kvm_cpuid,
134         TP_PROTO(unsigned int function, unsigned long rax, unsigned long rbx,
135                  unsigned long rcx, unsigned long rdx),
136         TP_ARGS(function, rax, rbx, rcx, rdx),
137
138         TP_STRUCT__entry(
139                 __field(        unsigned int,   function        )
140                 __field(        unsigned long,  rax             )
141                 __field(        unsigned long,  rbx             )
142                 __field(        unsigned long,  rcx             )
143                 __field(        unsigned long,  rdx             )
144         ),
145
146         TP_fast_assign(
147                 __entry->function       = function;
148                 __entry->rax            = rax;
149                 __entry->rbx            = rbx;
150                 __entry->rcx            = rcx;
151                 __entry->rdx            = rdx;
152         ),
153
154         TP_printk("func %x rax %lx rbx %lx rcx %lx rdx %lx",
155                   __entry->function, __entry->rax,
156                   __entry->rbx, __entry->rcx, __entry->rdx)
157 );
158
159 #define AREG(x) { APIC_##x, "APIC_" #x }
160
161 #define kvm_trace_symbol_apic                                               \
162         AREG(ID), AREG(LVR), AREG(TASKPRI), AREG(ARBPRI), AREG(PROCPRI),    \
163         AREG(EOI), AREG(RRR), AREG(LDR), AREG(DFR), AREG(SPIV), AREG(ISR),  \
164         AREG(TMR), AREG(IRR), AREG(ESR), AREG(ICR), AREG(ICR2), AREG(LVTT), \
165         AREG(LVTTHMR), AREG(LVTPC), AREG(LVT0), AREG(LVT1), AREG(LVTERR),   \
166         AREG(TMICT), AREG(TMCCT), AREG(TDCR), AREG(SELF_IPI), AREG(EFEAT),  \
167         AREG(ECTRL)
168 /*
169  * Tracepoint for apic access.
170  */
171 TRACE_EVENT(kvm_apic,
172         TP_PROTO(unsigned int rw, unsigned int reg, unsigned int val),
173         TP_ARGS(rw, reg, val),
174
175         TP_STRUCT__entry(
176                 __field(        unsigned int,   rw              )
177                 __field(        unsigned int,   reg             )
178                 __field(        unsigned int,   val             )
179         ),
180
181         TP_fast_assign(
182                 __entry->rw             = rw;
183                 __entry->reg            = reg;
184                 __entry->val            = val;
185         ),
186
187         TP_printk("apic_%s %s = 0x%x",
188                   __entry->rw ? "write" : "read",
189                   __print_symbolic(__entry->reg, kvm_trace_symbol_apic),
190                   __entry->val)
191 );
192
193 #define trace_kvm_apic_read(reg, val)           trace_kvm_apic(0, reg, val)
194 #define trace_kvm_apic_write(reg, val)          trace_kvm_apic(1, reg, val)
195
196 #define KVM_ISA_VMX   1
197 #define KVM_ISA_SVM   2
198
199 /*
200  * Tracepoint for kvm guest exit:
201  */
202 TRACE_EVENT(kvm_exit,
203         TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa),
204         TP_ARGS(exit_reason, vcpu, isa),
205
206         TP_STRUCT__entry(
207                 __field(        unsigned int,   exit_reason     )
208                 __field(        unsigned long,  guest_rip       )
209                 __field(        u32,            isa             )
210                 __field(        u64,            info1           )
211                 __field(        u64,            info2           )
212         ),
213
214         TP_fast_assign(
215                 __entry->exit_reason    = exit_reason;
216                 __entry->guest_rip      = kvm_rip_read(vcpu);
217                 __entry->isa            = isa;
218                 kvm_x86_ops->get_exit_info(vcpu, &__entry->info1,
219                                            &__entry->info2);
220         ),
221
222         TP_printk("reason %s rip 0x%lx info %llx %llx",
223                  (__entry->isa == KVM_ISA_VMX) ?
224                  __print_symbolic(__entry->exit_reason, VMX_EXIT_REASONS) :
225                  __print_symbolic(__entry->exit_reason, SVM_EXIT_REASONS),
226                  __entry->guest_rip, __entry->info1, __entry->info2)
227 );
228
229 /*
230  * Tracepoint for kvm interrupt injection:
231  */
232 TRACE_EVENT(kvm_inj_virq,
233         TP_PROTO(unsigned int irq),
234         TP_ARGS(irq),
235
236         TP_STRUCT__entry(
237                 __field(        unsigned int,   irq             )
238         ),
239
240         TP_fast_assign(
241                 __entry->irq            = irq;
242         ),
243
244         TP_printk("irq %u", __entry->irq)
245 );
246
247 #define EXS(x) { x##_VECTOR, "#" #x }
248
249 #define kvm_trace_sym_exc                                               \
250         EXS(DE), EXS(DB), EXS(BP), EXS(OF), EXS(BR), EXS(UD), EXS(NM),  \
251         EXS(DF), EXS(TS), EXS(NP), EXS(SS), EXS(GP), EXS(PF),           \
252         EXS(MF), EXS(MC)
253
254 /*
255  * Tracepoint for kvm interrupt injection:
256  */
257 TRACE_EVENT(kvm_inj_exception,
258         TP_PROTO(unsigned exception, bool has_error, unsigned error_code),
259         TP_ARGS(exception, has_error, error_code),
260
261         TP_STRUCT__entry(
262                 __field(        u8,     exception       )
263                 __field(        u8,     has_error       )
264                 __field(        u32,    error_code      )
265         ),
266
267         TP_fast_assign(
268                 __entry->exception      = exception;
269                 __entry->has_error      = has_error;
270                 __entry->error_code     = error_code;
271         ),
272
273         TP_printk("%s (0x%x)",
274                   __print_symbolic(__entry->exception, kvm_trace_sym_exc),
275                   /* FIXME: don't print error_code if not present */
276                   __entry->has_error ? __entry->error_code : 0)
277 );
278
279 /*
280  * Tracepoint for page fault.
281  */
282 TRACE_EVENT(kvm_page_fault,
283         TP_PROTO(unsigned long fault_address, unsigned int error_code),
284         TP_ARGS(fault_address, error_code),
285
286         TP_STRUCT__entry(
287                 __field(        unsigned long,  fault_address   )
288                 __field(        unsigned int,   error_code      )
289         ),
290
291         TP_fast_assign(
292                 __entry->fault_address  = fault_address;
293                 __entry->error_code     = error_code;
294         ),
295
296         TP_printk("address %lx error_code %x",
297                   __entry->fault_address, __entry->error_code)
298 );
299
300 /*
301  * Tracepoint for guest MSR access.
302  */
303 TRACE_EVENT(kvm_msr,
304         TP_PROTO(unsigned write, u32 ecx, u64 data, bool exception),
305         TP_ARGS(write, ecx, data, exception),
306
307         TP_STRUCT__entry(
308                 __field(        unsigned,       write           )
309                 __field(        u32,            ecx             )
310                 __field(        u64,            data            )
311                 __field(        u8,             exception       )
312         ),
313
314         TP_fast_assign(
315                 __entry->write          = write;
316                 __entry->ecx            = ecx;
317                 __entry->data           = data;
318                 __entry->exception      = exception;
319         ),
320
321         TP_printk("msr_%s %x = 0x%llx%s",
322                   __entry->write ? "write" : "read",
323                   __entry->ecx, __entry->data,
324                   __entry->exception ? " (#GP)" : "")
325 );
326
327 #define trace_kvm_msr_read(ecx, data)      trace_kvm_msr(0, ecx, data, false)
328 #define trace_kvm_msr_write(ecx, data)     trace_kvm_msr(1, ecx, data, false)
329 #define trace_kvm_msr_read_ex(ecx)         trace_kvm_msr(0, ecx, 0, true)
330 #define trace_kvm_msr_write_ex(ecx, data)  trace_kvm_msr(1, ecx, data, true)
331
332 /*
333  * Tracepoint for guest CR access.
334  */
335 TRACE_EVENT(kvm_cr,
336         TP_PROTO(unsigned int rw, unsigned int cr, unsigned long val),
337         TP_ARGS(rw, cr, val),
338
339         TP_STRUCT__entry(
340                 __field(        unsigned int,   rw              )
341                 __field(        unsigned int,   cr              )
342                 __field(        unsigned long,  val             )
343         ),
344
345         TP_fast_assign(
346                 __entry->rw             = rw;
347                 __entry->cr             = cr;
348                 __entry->val            = val;
349         ),
350
351         TP_printk("cr_%s %x = 0x%lx",
352                   __entry->rw ? "write" : "read",
353                   __entry->cr, __entry->val)
354 );
355
356 #define trace_kvm_cr_read(cr, val)              trace_kvm_cr(0, cr, val)
357 #define trace_kvm_cr_write(cr, val)             trace_kvm_cr(1, cr, val)
358
359 TRACE_EVENT(kvm_pic_set_irq,
360             TP_PROTO(__u8 chip, __u8 pin, __u8 elcr, __u8 imr, bool coalesced),
361             TP_ARGS(chip, pin, elcr, imr, coalesced),
362
363         TP_STRUCT__entry(
364                 __field(        __u8,           chip            )
365                 __field(        __u8,           pin             )
366                 __field(        __u8,           elcr            )
367                 __field(        __u8,           imr             )
368                 __field(        bool,           coalesced       )
369         ),
370
371         TP_fast_assign(
372                 __entry->chip           = chip;
373                 __entry->pin            = pin;
374                 __entry->elcr           = elcr;
375                 __entry->imr            = imr;
376                 __entry->coalesced      = coalesced;
377         ),
378
379         TP_printk("chip %u pin %u (%s%s)%s",
380                   __entry->chip, __entry->pin,
381                   (__entry->elcr & (1 << __entry->pin)) ? "level":"edge",
382                   (__entry->imr & (1 << __entry->pin)) ? "|masked":"",
383                   __entry->coalesced ? " (coalesced)" : "")
384 );
385
386 #define kvm_apic_dst_shorthand          \
387         {0x0, "dst"},                   \
388         {0x1, "self"},                  \
389         {0x2, "all"},                   \
390         {0x3, "all-but-self"}
391
392 TRACE_EVENT(kvm_apic_ipi,
393             TP_PROTO(__u32 icr_low, __u32 dest_id),
394             TP_ARGS(icr_low, dest_id),
395
396         TP_STRUCT__entry(
397                 __field(        __u32,          icr_low         )
398                 __field(        __u32,          dest_id         )
399         ),
400
401         TP_fast_assign(
402                 __entry->icr_low        = icr_low;
403                 __entry->dest_id        = dest_id;
404         ),
405
406         TP_printk("dst %x vec %u (%s|%s|%s|%s|%s)",
407                   __entry->dest_id, (u8)__entry->icr_low,
408                   __print_symbolic((__entry->icr_low >> 8 & 0x7),
409                                    kvm_deliver_mode),
410                   (__entry->icr_low & (1<<11)) ? "logical" : "physical",
411                   (__entry->icr_low & (1<<14)) ? "assert" : "de-assert",
412                   (__entry->icr_low & (1<<15)) ? "level" : "edge",
413                   __print_symbolic((__entry->icr_low >> 18 & 0x3),
414                                    kvm_apic_dst_shorthand))
415 );
416
417 TRACE_EVENT(kvm_apic_accept_irq,
418             TP_PROTO(__u32 apicid, __u16 dm, __u8 tm, __u8 vec, bool coalesced),
419             TP_ARGS(apicid, dm, tm, vec, coalesced),
420
421         TP_STRUCT__entry(
422                 __field(        __u32,          apicid          )
423                 __field(        __u16,          dm              )
424                 __field(        __u8,           tm              )
425                 __field(        __u8,           vec             )
426                 __field(        bool,           coalesced       )
427         ),
428
429         TP_fast_assign(
430                 __entry->apicid         = apicid;
431                 __entry->dm             = dm;
432                 __entry->tm             = tm;
433                 __entry->vec            = vec;
434                 __entry->coalesced      = coalesced;
435         ),
436
437         TP_printk("apicid %x vec %u (%s|%s)%s",
438                   __entry->apicid, __entry->vec,
439                   __print_symbolic((__entry->dm >> 8 & 0x7), kvm_deliver_mode),
440                   __entry->tm ? "level" : "edge",
441                   __entry->coalesced ? " (coalesced)" : "")
442 );
443
444 TRACE_EVENT(kvm_eoi,
445             TP_PROTO(struct kvm_lapic *apic, int vector),
446             TP_ARGS(apic, vector),
447
448         TP_STRUCT__entry(
449                 __field(        __u32,          apicid          )
450                 __field(        int,            vector          )
451         ),
452
453         TP_fast_assign(
454                 __entry->apicid         = apic->vcpu->vcpu_id;
455                 __entry->vector         = vector;
456         ),
457
458         TP_printk("apicid %x vector %d", __entry->apicid, __entry->vector)
459 );
460
461 TRACE_EVENT(kvm_pv_eoi,
462             TP_PROTO(struct kvm_lapic *apic, int vector),
463             TP_ARGS(apic, vector),
464
465         TP_STRUCT__entry(
466                 __field(        __u32,          apicid          )
467                 __field(        int,            vector          )
468         ),
469
470         TP_fast_assign(
471                 __entry->apicid         = apic->vcpu->vcpu_id;
472                 __entry->vector         = vector;
473         ),
474
475         TP_printk("apicid %x vector %d", __entry->apicid, __entry->vector)
476 );
477
478 /*
479  * Tracepoint for nested VMRUN
480  */
481 TRACE_EVENT(kvm_nested_vmrun,
482             TP_PROTO(__u64 rip, __u64 vmcb, __u64 nested_rip, __u32 int_ctl,
483                      __u32 event_inj, bool npt),
484             TP_ARGS(rip, vmcb, nested_rip, int_ctl, event_inj, npt),
485
486         TP_STRUCT__entry(
487                 __field(        __u64,          rip             )
488                 __field(        __u64,          vmcb            )
489                 __field(        __u64,          nested_rip      )
490                 __field(        __u32,          int_ctl         )
491                 __field(        __u32,          event_inj       )
492                 __field(        bool,           npt             )
493         ),
494
495         TP_fast_assign(
496                 __entry->rip            = rip;
497                 __entry->vmcb           = vmcb;
498                 __entry->nested_rip     = nested_rip;
499                 __entry->int_ctl        = int_ctl;
500                 __entry->event_inj      = event_inj;
501                 __entry->npt            = npt;
502         ),
503
504         TP_printk("rip: 0x%016llx vmcb: 0x%016llx nrip: 0x%016llx int_ctl: 0x%08x "
505                   "event_inj: 0x%08x npt: %s",
506                 __entry->rip, __entry->vmcb, __entry->nested_rip,
507                 __entry->int_ctl, __entry->event_inj,
508                 __entry->npt ? "on" : "off")
509 );
510
511 TRACE_EVENT(kvm_nested_intercepts,
512             TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u64 intercept),
513             TP_ARGS(cr_read, cr_write, exceptions, intercept),
514
515         TP_STRUCT__entry(
516                 __field(        __u16,          cr_read         )
517                 __field(        __u16,          cr_write        )
518                 __field(        __u32,          exceptions      )
519                 __field(        __u64,          intercept       )
520         ),
521
522         TP_fast_assign(
523                 __entry->cr_read        = cr_read;
524                 __entry->cr_write       = cr_write;
525                 __entry->exceptions     = exceptions;
526                 __entry->intercept      = intercept;
527         ),
528
529         TP_printk("cr_read: %04x cr_write: %04x excp: %08x intercept: %016llx",
530                 __entry->cr_read, __entry->cr_write, __entry->exceptions,
531                 __entry->intercept)
532 );
533 /*
534  * Tracepoint for #VMEXIT while nested
535  */
536 TRACE_EVENT(kvm_nested_vmexit,
537             TP_PROTO(__u64 rip, __u32 exit_code,
538                      __u64 exit_info1, __u64 exit_info2,
539                      __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
540             TP_ARGS(rip, exit_code, exit_info1, exit_info2,
541                     exit_int_info, exit_int_info_err, isa),
542
543         TP_STRUCT__entry(
544                 __field(        __u64,          rip                     )
545                 __field(        __u32,          exit_code               )
546                 __field(        __u64,          exit_info1              )
547                 __field(        __u64,          exit_info2              )
548                 __field(        __u32,          exit_int_info           )
549                 __field(        __u32,          exit_int_info_err       )
550                 __field(        __u32,          isa                     )
551         ),
552
553         TP_fast_assign(
554                 __entry->rip                    = rip;
555                 __entry->exit_code              = exit_code;
556                 __entry->exit_info1             = exit_info1;
557                 __entry->exit_info2             = exit_info2;
558                 __entry->exit_int_info          = exit_int_info;
559                 __entry->exit_int_info_err      = exit_int_info_err;
560                 __entry->isa                    = isa;
561         ),
562         TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx "
563                   "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
564                   __entry->rip,
565                  (__entry->isa == KVM_ISA_VMX) ?
566                  __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
567                  __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
568                   __entry->exit_info1, __entry->exit_info2,
569                   __entry->exit_int_info, __entry->exit_int_info_err)
570 );
571
572 /*
573  * Tracepoint for #VMEXIT reinjected to the guest
574  */
575 TRACE_EVENT(kvm_nested_vmexit_inject,
576             TP_PROTO(__u32 exit_code,
577                      __u64 exit_info1, __u64 exit_info2,
578                      __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
579             TP_ARGS(exit_code, exit_info1, exit_info2,
580                     exit_int_info, exit_int_info_err, isa),
581
582         TP_STRUCT__entry(
583                 __field(        __u32,          exit_code               )
584                 __field(        __u64,          exit_info1              )
585                 __field(        __u64,          exit_info2              )
586                 __field(        __u32,          exit_int_info           )
587                 __field(        __u32,          exit_int_info_err       )
588                 __field(        __u32,          isa                     )
589         ),
590
591         TP_fast_assign(
592                 __entry->exit_code              = exit_code;
593                 __entry->exit_info1             = exit_info1;
594                 __entry->exit_info2             = exit_info2;
595                 __entry->exit_int_info          = exit_int_info;
596                 __entry->exit_int_info_err      = exit_int_info_err;
597                 __entry->isa                    = isa;
598         ),
599
600         TP_printk("reason: %s ext_inf1: 0x%016llx "
601                   "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
602                  (__entry->isa == KVM_ISA_VMX) ?
603                  __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
604                  __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
605                 __entry->exit_info1, __entry->exit_info2,
606                 __entry->exit_int_info, __entry->exit_int_info_err)
607 );
608
609 /*
610  * Tracepoint for nested #vmexit because of interrupt pending
611  */
612 TRACE_EVENT(kvm_nested_intr_vmexit,
613             TP_PROTO(__u64 rip),
614             TP_ARGS(rip),
615
616         TP_STRUCT__entry(
617                 __field(        __u64,  rip     )
618         ),
619
620         TP_fast_assign(
621                 __entry->rip    =       rip
622         ),
623
624         TP_printk("rip: 0x%016llx", __entry->rip)
625 );
626
627 /*
628  * Tracepoint for nested #vmexit because of interrupt pending
629  */
630 TRACE_EVENT(kvm_invlpga,
631             TP_PROTO(__u64 rip, int asid, u64 address),
632             TP_ARGS(rip, asid, address),
633
634         TP_STRUCT__entry(
635                 __field(        __u64,  rip     )
636                 __field(        int,    asid    )
637                 __field(        __u64,  address )
638         ),
639
640         TP_fast_assign(
641                 __entry->rip            =       rip;
642                 __entry->asid           =       asid;
643                 __entry->address        =       address;
644         ),
645
646         TP_printk("rip: 0x%016llx asid: %d address: 0x%016llx",
647                   __entry->rip, __entry->asid, __entry->address)
648 );
649
650 /*
651  * Tracepoint for nested #vmexit because of interrupt pending
652  */
653 TRACE_EVENT(kvm_skinit,
654             TP_PROTO(__u64 rip, __u32 slb),
655             TP_ARGS(rip, slb),
656
657         TP_STRUCT__entry(
658                 __field(        __u64,  rip     )
659                 __field(        __u32,  slb     )
660         ),
661
662         TP_fast_assign(
663                 __entry->rip            =       rip;
664                 __entry->slb            =       slb;
665         ),
666
667         TP_printk("rip: 0x%016llx slb: 0x%08x",
668                   __entry->rip, __entry->slb)
669 );
670
671 #define KVM_EMUL_INSN_F_CR0_PE (1 << 0)
672 #define KVM_EMUL_INSN_F_EFL_VM (1 << 1)
673 #define KVM_EMUL_INSN_F_CS_D   (1 << 2)
674 #define KVM_EMUL_INSN_F_CS_L   (1 << 3)
675
676 #define kvm_trace_symbol_emul_flags                       \
677         { 0,                        "real" },             \
678         { KVM_EMUL_INSN_F_CR0_PE                          \
679           | KVM_EMUL_INSN_F_EFL_VM, "vm16" },             \
680         { KVM_EMUL_INSN_F_CR0_PE,   "prot16" },           \
681         { KVM_EMUL_INSN_F_CR0_PE                          \
682           | KVM_EMUL_INSN_F_CS_D,   "prot32" },           \
683         { KVM_EMUL_INSN_F_CR0_PE                          \
684           | KVM_EMUL_INSN_F_CS_L,   "prot64" }
685
686 #define kei_decode_mode(mode) ({                        \
687         u8 flags = 0xff;                                \
688         switch (mode) {                                 \
689         case X86EMUL_MODE_REAL:                         \
690                 flags = 0;                              \
691                 break;                                  \
692         case X86EMUL_MODE_VM86:                         \
693                 flags = KVM_EMUL_INSN_F_EFL_VM;         \
694                 break;                                  \
695         case X86EMUL_MODE_PROT16:                       \
696                 flags = KVM_EMUL_INSN_F_CR0_PE;         \
697                 break;                                  \
698         case X86EMUL_MODE_PROT32:                       \
699                 flags = KVM_EMUL_INSN_F_CR0_PE          \
700                         | KVM_EMUL_INSN_F_CS_D;         \
701                 break;                                  \
702         case X86EMUL_MODE_PROT64:                       \
703                 flags = KVM_EMUL_INSN_F_CR0_PE          \
704                         | KVM_EMUL_INSN_F_CS_L;         \
705                 break;                                  \
706         }                                               \
707         flags;                                          \
708         })
709
710 TRACE_EVENT(kvm_emulate_insn,
711         TP_PROTO(struct kvm_vcpu *vcpu, __u8 failed),
712         TP_ARGS(vcpu, failed),
713
714         TP_STRUCT__entry(
715                 __field(    __u64, rip                       )
716                 __field(    __u32, csbase                    )
717                 __field(    __u8,  len                       )
718                 __array(    __u8,  insn,    15               )
719                 __field(    __u8,  flags                     )
720                 __field(    __u8,  failed                    )
721                 ),
722
723         TP_fast_assign(
724                 __entry->rip = vcpu->arch.emulate_ctxt.fetch.start;
725                 __entry->csbase = kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS);
726                 __entry->len = vcpu->arch.emulate_ctxt._eip
727                                - vcpu->arch.emulate_ctxt.fetch.start;
728                 memcpy(__entry->insn,
729                        vcpu->arch.emulate_ctxt.fetch.data,
730                        15);
731                 __entry->flags = kei_decode_mode(vcpu->arch.emulate_ctxt.mode);
732                 __entry->failed = failed;
733                 ),
734
735         TP_printk("%x:%llx:%s (%s)%s",
736                   __entry->csbase, __entry->rip,
737                   __print_hex(__entry->insn, __entry->len),
738                   __print_symbolic(__entry->flags,
739                                    kvm_trace_symbol_emul_flags),
740                   __entry->failed ? " failed" : ""
741                 )
742         );
743
744 #define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0)
745 #define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1)
746
747 TRACE_EVENT(
748         vcpu_match_mmio,
749         TP_PROTO(gva_t gva, gpa_t gpa, bool write, bool gpa_match),
750         TP_ARGS(gva, gpa, write, gpa_match),
751
752         TP_STRUCT__entry(
753                 __field(gva_t, gva)
754                 __field(gpa_t, gpa)
755                 __field(bool, write)
756                 __field(bool, gpa_match)
757                 ),
758
759         TP_fast_assign(
760                 __entry->gva = gva;
761                 __entry->gpa = gpa;
762                 __entry->write = write;
763                 __entry->gpa_match = gpa_match
764                 ),
765
766         TP_printk("gva %#lx gpa %#llx %s %s", __entry->gva, __entry->gpa,
767                   __entry->write ? "Write" : "Read",
768                   __entry->gpa_match ? "GPA" : "GVA")
769 );
770
771 TRACE_EVENT(kvm_write_tsc_offset,
772         TP_PROTO(unsigned int vcpu_id, __u64 previous_tsc_offset,
773                  __u64 next_tsc_offset),
774         TP_ARGS(vcpu_id, previous_tsc_offset, next_tsc_offset),
775
776         TP_STRUCT__entry(
777                 __field( unsigned int,  vcpu_id                         )
778                 __field(        __u64,  previous_tsc_offset             )
779                 __field(        __u64,  next_tsc_offset                 )
780         ),
781
782         TP_fast_assign(
783                 __entry->vcpu_id                = vcpu_id;
784                 __entry->previous_tsc_offset    = previous_tsc_offset;
785                 __entry->next_tsc_offset        = next_tsc_offset;
786         ),
787
788         TP_printk("vcpu=%u prev=%llu next=%llu", __entry->vcpu_id,
789                   __entry->previous_tsc_offset, __entry->next_tsc_offset)
790 );
791
792 #ifdef CONFIG_X86_64
793
794 #define host_clocks                                     \
795         {VCLOCK_NONE, "none"},                          \
796         {VCLOCK_TSC,  "tsc"},                           \
797         {VCLOCK_HPET, "hpet"}                           \
798
799 TRACE_EVENT(kvm_update_master_clock,
800         TP_PROTO(bool use_master_clock, unsigned int host_clock, bool offset_matched),
801         TP_ARGS(use_master_clock, host_clock, offset_matched),
802
803         TP_STRUCT__entry(
804                 __field(                bool,   use_master_clock        )
805                 __field(        unsigned int,   host_clock              )
806                 __field(                bool,   offset_matched          )
807         ),
808
809         TP_fast_assign(
810                 __entry->use_master_clock       = use_master_clock;
811                 __entry->host_clock             = host_clock;
812                 __entry->offset_matched         = offset_matched;
813         ),
814
815         TP_printk("masterclock %d hostclock %s offsetmatched %u",
816                   __entry->use_master_clock,
817                   __print_symbolic(__entry->host_clock, host_clocks),
818                   __entry->offset_matched)
819 );
820
821 TRACE_EVENT(kvm_track_tsc,
822         TP_PROTO(unsigned int vcpu_id, unsigned int nr_matched,
823                  unsigned int online_vcpus, bool use_master_clock,
824                  unsigned int host_clock),
825         TP_ARGS(vcpu_id, nr_matched, online_vcpus, use_master_clock,
826                 host_clock),
827
828         TP_STRUCT__entry(
829                 __field(        unsigned int,   vcpu_id                 )
830                 __field(        unsigned int,   nr_vcpus_matched_tsc    )
831                 __field(        unsigned int,   online_vcpus            )
832                 __field(        bool,           use_master_clock        )
833                 __field(        unsigned int,   host_clock              )
834         ),
835
836         TP_fast_assign(
837                 __entry->vcpu_id                = vcpu_id;
838                 __entry->nr_vcpus_matched_tsc   = nr_matched;
839                 __entry->online_vcpus           = online_vcpus;
840                 __entry->use_master_clock       = use_master_clock;
841                 __entry->host_clock             = host_clock;
842         ),
843
844         TP_printk("vcpu_id %u masterclock %u offsetmatched %u nr_online %u"
845                   " hostclock %s",
846                   __entry->vcpu_id, __entry->use_master_clock,
847                   __entry->nr_vcpus_matched_tsc, __entry->online_vcpus,
848                   __print_symbolic(__entry->host_clock, host_clocks))
849 );
850
851 #endif /* CONFIG_X86_64 */
852
853 #endif /* _TRACE_KVM_H */
854
855 #undef TRACE_INCLUDE_PATH
856 #define TRACE_INCLUDE_PATH arch/x86/kvm
857 #undef TRACE_INCLUDE_FILE
858 #define TRACE_INCLUDE_FILE trace
859
860 /* This part must be outside protection */
861 #include <trace/define_trace.h>