KVM: Fix msr trace
[linux-3.10.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
6 #undef TRACE_SYSTEM
7 #define TRACE_SYSTEM kvm
8 #define TRACE_INCLUDE_PATH arch/x86/kvm
9 #define TRACE_INCLUDE_FILE trace
10
11 /*
12  * Tracepoint for guest mode entry.
13  */
14 TRACE_EVENT(kvm_entry,
15         TP_PROTO(unsigned int vcpu_id),
16         TP_ARGS(vcpu_id),
17
18         TP_STRUCT__entry(
19                 __field(        unsigned int,   vcpu_id         )
20         ),
21
22         TP_fast_assign(
23                 __entry->vcpu_id        = vcpu_id;
24         ),
25
26         TP_printk("vcpu %u", __entry->vcpu_id)
27 );
28
29 /*
30  * Tracepoint for hypercall.
31  */
32 TRACE_EVENT(kvm_hypercall,
33         TP_PROTO(unsigned long nr, unsigned long a0, unsigned long a1,
34                  unsigned long a2, unsigned long a3),
35         TP_ARGS(nr, a0, a1, a2, a3),
36
37         TP_STRUCT__entry(
38                 __field(        unsigned long,  nr              )
39                 __field(        unsigned long,  a0              )
40                 __field(        unsigned long,  a1              )
41                 __field(        unsigned long,  a2              )
42                 __field(        unsigned long,  a3              )
43         ),
44
45         TP_fast_assign(
46                 __entry->nr             = nr;
47                 __entry->a0             = a0;
48                 __entry->a1             = a1;
49                 __entry->a2             = a2;
50                 __entry->a3             = a3;
51         ),
52
53         TP_printk("nr 0x%lx a0 0x%lx a1 0x%lx a2 0x%lx a3 0x%lx",
54                  __entry->nr, __entry->a0, __entry->a1,  __entry->a2,
55                  __entry->a3)
56 );
57
58 /*
59  * Tracepoint for hypercall.
60  */
61 TRACE_EVENT(kvm_hv_hypercall,
62         TP_PROTO(__u16 code, bool fast, __u16 rep_cnt, __u16 rep_idx,
63                  __u64 ingpa, __u64 outgpa),
64         TP_ARGS(code, fast, rep_cnt, rep_idx, ingpa, outgpa),
65
66         TP_STRUCT__entry(
67                 __field(        __u16,          code            )
68                 __field(        bool,           fast            )
69                 __field(        __u16,          rep_cnt         )
70                 __field(        __u16,          rep_idx         )
71                 __field(        __u64,          ingpa           )
72                 __field(        __u64,          outgpa          )
73         ),
74
75         TP_fast_assign(
76                 __entry->code           = code;
77                 __entry->fast           = fast;
78                 __entry->rep_cnt        = rep_cnt;
79                 __entry->rep_idx        = rep_idx;
80                 __entry->ingpa          = ingpa;
81                 __entry->outgpa         = outgpa;
82         ),
83
84         TP_printk("code 0x%x %s cnt 0x%x idx 0x%x in 0x%llx out 0x%llx",
85                   __entry->code, __entry->fast ? "fast" : "slow",
86                   __entry->rep_cnt, __entry->rep_idx,  __entry->ingpa,
87                   __entry->outgpa)
88 );
89
90 /*
91  * Tracepoint for PIO.
92  */
93 TRACE_EVENT(kvm_pio,
94         TP_PROTO(unsigned int rw, unsigned int port, unsigned int size,
95                  unsigned int count),
96         TP_ARGS(rw, port, size, count),
97
98         TP_STRUCT__entry(
99                 __field(        unsigned int,   rw              )
100                 __field(        unsigned int,   port            )
101                 __field(        unsigned int,   size            )
102                 __field(        unsigned int,   count           )
103         ),
104
105         TP_fast_assign(
106                 __entry->rw             = rw;
107                 __entry->port           = port;
108                 __entry->size           = size;
109                 __entry->count          = count;
110         ),
111
112         TP_printk("pio_%s at 0x%x size %d count %d",
113                   __entry->rw ? "write" : "read",
114                   __entry->port, __entry->size, __entry->count)
115 );
116
117 /*
118  * Tracepoint for cpuid.
119  */
120 TRACE_EVENT(kvm_cpuid,
121         TP_PROTO(unsigned int function, unsigned long rax, unsigned long rbx,
122                  unsigned long rcx, unsigned long rdx),
123         TP_ARGS(function, rax, rbx, rcx, rdx),
124
125         TP_STRUCT__entry(
126                 __field(        unsigned int,   function        )
127                 __field(        unsigned long,  rax             )
128                 __field(        unsigned long,  rbx             )
129                 __field(        unsigned long,  rcx             )
130                 __field(        unsigned long,  rdx             )
131         ),
132
133         TP_fast_assign(
134                 __entry->function       = function;
135                 __entry->rax            = rax;
136                 __entry->rbx            = rbx;
137                 __entry->rcx            = rcx;
138                 __entry->rdx            = rdx;
139         ),
140
141         TP_printk("func %x rax %lx rbx %lx rcx %lx rdx %lx",
142                   __entry->function, __entry->rax,
143                   __entry->rbx, __entry->rcx, __entry->rdx)
144 );
145
146 #define AREG(x) { APIC_##x, "APIC_" #x }
147
148 #define kvm_trace_symbol_apic                                               \
149         AREG(ID), AREG(LVR), AREG(TASKPRI), AREG(ARBPRI), AREG(PROCPRI),    \
150         AREG(EOI), AREG(RRR), AREG(LDR), AREG(DFR), AREG(SPIV), AREG(ISR),  \
151         AREG(TMR), AREG(IRR), AREG(ESR), AREG(ICR), AREG(ICR2), AREG(LVTT), \
152         AREG(LVTTHMR), AREG(LVTPC), AREG(LVT0), AREG(LVT1), AREG(LVTERR),   \
153         AREG(TMICT), AREG(TMCCT), AREG(TDCR), AREG(SELF_IPI), AREG(EFEAT),  \
154         AREG(ECTRL)
155 /*
156  * Tracepoint for apic access.
157  */
158 TRACE_EVENT(kvm_apic,
159         TP_PROTO(unsigned int rw, unsigned int reg, unsigned int val),
160         TP_ARGS(rw, reg, val),
161
162         TP_STRUCT__entry(
163                 __field(        unsigned int,   rw              )
164                 __field(        unsigned int,   reg             )
165                 __field(        unsigned int,   val             )
166         ),
167
168         TP_fast_assign(
169                 __entry->rw             = rw;
170                 __entry->reg            = reg;
171                 __entry->val            = val;
172         ),
173
174         TP_printk("apic_%s %s = 0x%x",
175                   __entry->rw ? "write" : "read",
176                   __print_symbolic(__entry->reg, kvm_trace_symbol_apic),
177                   __entry->val)
178 );
179
180 #define trace_kvm_apic_read(reg, val)           trace_kvm_apic(0, reg, val)
181 #define trace_kvm_apic_write(reg, val)          trace_kvm_apic(1, reg, val)
182
183 /*
184  * Tracepoint for kvm guest exit:
185  */
186 TRACE_EVENT(kvm_exit,
187         TP_PROTO(unsigned int exit_reason, unsigned long guest_rip),
188         TP_ARGS(exit_reason, guest_rip),
189
190         TP_STRUCT__entry(
191                 __field(        unsigned int,   exit_reason     )
192                 __field(        unsigned long,  guest_rip       )
193         ),
194
195         TP_fast_assign(
196                 __entry->exit_reason    = exit_reason;
197                 __entry->guest_rip      = guest_rip;
198         ),
199
200         TP_printk("reason %s rip 0x%lx",
201                  ftrace_print_symbols_seq(p, __entry->exit_reason,
202                                           kvm_x86_ops->exit_reasons_str),
203                  __entry->guest_rip)
204 );
205
206 /*
207  * Tracepoint for kvm interrupt injection:
208  */
209 TRACE_EVENT(kvm_inj_virq,
210         TP_PROTO(unsigned int irq),
211         TP_ARGS(irq),
212
213         TP_STRUCT__entry(
214                 __field(        unsigned int,   irq             )
215         ),
216
217         TP_fast_assign(
218                 __entry->irq            = irq;
219         ),
220
221         TP_printk("irq %u", __entry->irq)
222 );
223
224 /*
225  * Tracepoint for page fault.
226  */
227 TRACE_EVENT(kvm_page_fault,
228         TP_PROTO(unsigned long fault_address, unsigned int error_code),
229         TP_ARGS(fault_address, error_code),
230
231         TP_STRUCT__entry(
232                 __field(        unsigned long,  fault_address   )
233                 __field(        unsigned int,   error_code      )
234         ),
235
236         TP_fast_assign(
237                 __entry->fault_address  = fault_address;
238                 __entry->error_code     = error_code;
239         ),
240
241         TP_printk("address %lx error_code %x",
242                   __entry->fault_address, __entry->error_code)
243 );
244
245 /*
246  * Tracepoint for guest MSR access.
247  */
248 TRACE_EVENT(kvm_msr,
249         TP_PROTO(unsigned write, u32 ecx, u64 data),
250         TP_ARGS(write, ecx, data),
251
252         TP_STRUCT__entry(
253                 __field(        unsigned,       write           )
254                 __field(        u32,            ecx             )
255                 __field(        u64,            data            )
256         ),
257
258         TP_fast_assign(
259                 __entry->write          = write;
260                 __entry->ecx            = ecx;
261                 __entry->data           = data;
262         ),
263
264         TP_printk("msr_%s %x = 0x%llx",
265                   __entry->write ? "write" : "read",
266                   __entry->ecx, __entry->data)
267 );
268
269 #define trace_kvm_msr_read(ecx, data)           trace_kvm_msr(0, ecx, data)
270 #define trace_kvm_msr_write(ecx, data)          trace_kvm_msr(1, ecx, data)
271
272 /*
273  * Tracepoint for guest CR access.
274  */
275 TRACE_EVENT(kvm_cr,
276         TP_PROTO(unsigned int rw, unsigned int cr, unsigned long val),
277         TP_ARGS(rw, cr, val),
278
279         TP_STRUCT__entry(
280                 __field(        unsigned int,   rw              )
281                 __field(        unsigned int,   cr              )
282                 __field(        unsigned long,  val             )
283         ),
284
285         TP_fast_assign(
286                 __entry->rw             = rw;
287                 __entry->cr             = cr;
288                 __entry->val            = val;
289         ),
290
291         TP_printk("cr_%s %x = 0x%lx",
292                   __entry->rw ? "write" : "read",
293                   __entry->cr, __entry->val)
294 );
295
296 #define trace_kvm_cr_read(cr, val)              trace_kvm_cr(0, cr, val)
297 #define trace_kvm_cr_write(cr, val)             trace_kvm_cr(1, cr, val)
298
299 TRACE_EVENT(kvm_pic_set_irq,
300             TP_PROTO(__u8 chip, __u8 pin, __u8 elcr, __u8 imr, bool coalesced),
301             TP_ARGS(chip, pin, elcr, imr, coalesced),
302
303         TP_STRUCT__entry(
304                 __field(        __u8,           chip            )
305                 __field(        __u8,           pin             )
306                 __field(        __u8,           elcr            )
307                 __field(        __u8,           imr             )
308                 __field(        bool,           coalesced       )
309         ),
310
311         TP_fast_assign(
312                 __entry->chip           = chip;
313                 __entry->pin            = pin;
314                 __entry->elcr           = elcr;
315                 __entry->imr            = imr;
316                 __entry->coalesced      = coalesced;
317         ),
318
319         TP_printk("chip %u pin %u (%s%s)%s",
320                   __entry->chip, __entry->pin,
321                   (__entry->elcr & (1 << __entry->pin)) ? "level":"edge",
322                   (__entry->imr & (1 << __entry->pin)) ? "|masked":"",
323                   __entry->coalesced ? " (coalesced)" : "")
324 );
325
326 #define kvm_apic_dst_shorthand          \
327         {0x0, "dst"},                   \
328         {0x1, "self"},                  \
329         {0x2, "all"},                   \
330         {0x3, "all-but-self"}
331
332 TRACE_EVENT(kvm_apic_ipi,
333             TP_PROTO(__u32 icr_low, __u32 dest_id),
334             TP_ARGS(icr_low, dest_id),
335
336         TP_STRUCT__entry(
337                 __field(        __u32,          icr_low         )
338                 __field(        __u32,          dest_id         )
339         ),
340
341         TP_fast_assign(
342                 __entry->icr_low        = icr_low;
343                 __entry->dest_id        = dest_id;
344         ),
345
346         TP_printk("dst %x vec %u (%s|%s|%s|%s|%s)",
347                   __entry->dest_id, (u8)__entry->icr_low,
348                   __print_symbolic((__entry->icr_low >> 8 & 0x7),
349                                    kvm_deliver_mode),
350                   (__entry->icr_low & (1<<11)) ? "logical" : "physical",
351                   (__entry->icr_low & (1<<14)) ? "assert" : "de-assert",
352                   (__entry->icr_low & (1<<15)) ? "level" : "edge",
353                   __print_symbolic((__entry->icr_low >> 18 & 0x3),
354                                    kvm_apic_dst_shorthand))
355 );
356
357 TRACE_EVENT(kvm_apic_accept_irq,
358             TP_PROTO(__u32 apicid, __u16 dm, __u8 tm, __u8 vec, bool coalesced),
359             TP_ARGS(apicid, dm, tm, vec, coalesced),
360
361         TP_STRUCT__entry(
362                 __field(        __u32,          apicid          )
363                 __field(        __u16,          dm              )
364                 __field(        __u8,           tm              )
365                 __field(        __u8,           vec             )
366                 __field(        bool,           coalesced       )
367         ),
368
369         TP_fast_assign(
370                 __entry->apicid         = apicid;
371                 __entry->dm             = dm;
372                 __entry->tm             = tm;
373                 __entry->vec            = vec;
374                 __entry->coalesced      = coalesced;
375         ),
376
377         TP_printk("apicid %x vec %u (%s|%s)%s",
378                   __entry->apicid, __entry->vec,
379                   __print_symbolic((__entry->dm >> 8 & 0x7), kvm_deliver_mode),
380                   __entry->tm ? "level" : "edge",
381                   __entry->coalesced ? " (coalesced)" : "")
382 );
383
384 /*
385  * Tracepoint for nested VMRUN
386  */
387 TRACE_EVENT(kvm_nested_vmrun,
388             TP_PROTO(__u64 rip, __u64 vmcb, __u64 nested_rip, __u32 int_ctl,
389                      __u32 event_inj, bool npt),
390             TP_ARGS(rip, vmcb, nested_rip, int_ctl, event_inj, npt),
391
392         TP_STRUCT__entry(
393                 __field(        __u64,          rip             )
394                 __field(        __u64,          vmcb            )
395                 __field(        __u64,          nested_rip      )
396                 __field(        __u32,          int_ctl         )
397                 __field(        __u32,          event_inj       )
398                 __field(        bool,           npt             )
399         ),
400
401         TP_fast_assign(
402                 __entry->rip            = rip;
403                 __entry->vmcb           = vmcb;
404                 __entry->nested_rip     = nested_rip;
405                 __entry->int_ctl        = int_ctl;
406                 __entry->event_inj      = event_inj;
407                 __entry->npt            = npt;
408         ),
409
410         TP_printk("rip: 0x%016llx vmcb: 0x%016llx nrip: 0x%016llx int_ctl: 0x%08x "
411                   "event_inj: 0x%08x npt: %s\n",
412                 __entry->rip, __entry->vmcb, __entry->nested_rip,
413                 __entry->int_ctl, __entry->event_inj,
414                 __entry->npt ? "on" : "off")
415 );
416
417 /*
418  * Tracepoint for #VMEXIT while nested
419  */
420 TRACE_EVENT(kvm_nested_vmexit,
421             TP_PROTO(__u64 rip, __u32 exit_code,
422                      __u64 exit_info1, __u64 exit_info2,
423                      __u32 exit_int_info, __u32 exit_int_info_err),
424             TP_ARGS(rip, exit_code, exit_info1, exit_info2,
425                     exit_int_info, exit_int_info_err),
426
427         TP_STRUCT__entry(
428                 __field(        __u64,          rip                     )
429                 __field(        __u32,          exit_code               )
430                 __field(        __u64,          exit_info1              )
431                 __field(        __u64,          exit_info2              )
432                 __field(        __u32,          exit_int_info           )
433                 __field(        __u32,          exit_int_info_err       )
434         ),
435
436         TP_fast_assign(
437                 __entry->rip                    = rip;
438                 __entry->exit_code              = exit_code;
439                 __entry->exit_info1             = exit_info1;
440                 __entry->exit_info2             = exit_info2;
441                 __entry->exit_int_info          = exit_int_info;
442                 __entry->exit_int_info_err      = exit_int_info_err;
443         ),
444         TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx "
445                   "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x\n",
446                   __entry->rip,
447                   ftrace_print_symbols_seq(p, __entry->exit_code,
448                                            kvm_x86_ops->exit_reasons_str),
449                   __entry->exit_info1, __entry->exit_info2,
450                   __entry->exit_int_info, __entry->exit_int_info_err)
451 );
452
453 /*
454  * Tracepoint for #VMEXIT reinjected to the guest
455  */
456 TRACE_EVENT(kvm_nested_vmexit_inject,
457             TP_PROTO(__u32 exit_code,
458                      __u64 exit_info1, __u64 exit_info2,
459                      __u32 exit_int_info, __u32 exit_int_info_err),
460             TP_ARGS(exit_code, exit_info1, exit_info2,
461                     exit_int_info, exit_int_info_err),
462
463         TP_STRUCT__entry(
464                 __field(        __u32,          exit_code               )
465                 __field(        __u64,          exit_info1              )
466                 __field(        __u64,          exit_info2              )
467                 __field(        __u32,          exit_int_info           )
468                 __field(        __u32,          exit_int_info_err       )
469         ),
470
471         TP_fast_assign(
472                 __entry->exit_code              = exit_code;
473                 __entry->exit_info1             = exit_info1;
474                 __entry->exit_info2             = exit_info2;
475                 __entry->exit_int_info          = exit_int_info;
476                 __entry->exit_int_info_err      = exit_int_info_err;
477         ),
478
479         TP_printk("reason: %s ext_inf1: 0x%016llx "
480                   "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x\n",
481                   ftrace_print_symbols_seq(p, __entry->exit_code,
482                                            kvm_x86_ops->exit_reasons_str),
483                 __entry->exit_info1, __entry->exit_info2,
484                 __entry->exit_int_info, __entry->exit_int_info_err)
485 );
486
487 /*
488  * Tracepoint for nested #vmexit because of interrupt pending
489  */
490 TRACE_EVENT(kvm_nested_intr_vmexit,
491             TP_PROTO(__u64 rip),
492             TP_ARGS(rip),
493
494         TP_STRUCT__entry(
495                 __field(        __u64,  rip     )
496         ),
497
498         TP_fast_assign(
499                 __entry->rip    =       rip
500         ),
501
502         TP_printk("rip: 0x%016llx\n", __entry->rip)
503 );
504
505 /*
506  * Tracepoint for nested #vmexit because of interrupt pending
507  */
508 TRACE_EVENT(kvm_invlpga,
509             TP_PROTO(__u64 rip, int asid, u64 address),
510             TP_ARGS(rip, asid, address),
511
512         TP_STRUCT__entry(
513                 __field(        __u64,  rip     )
514                 __field(        int,    asid    )
515                 __field(        __u64,  address )
516         ),
517
518         TP_fast_assign(
519                 __entry->rip            =       rip;
520                 __entry->asid           =       asid;
521                 __entry->address        =       address;
522         ),
523
524         TP_printk("rip: 0x%016llx asid: %d address: 0x%016llx\n",
525                   __entry->rip, __entry->asid, __entry->address)
526 );
527
528 /*
529  * Tracepoint for nested #vmexit because of interrupt pending
530  */
531 TRACE_EVENT(kvm_skinit,
532             TP_PROTO(__u64 rip, __u32 slb),
533             TP_ARGS(rip, slb),
534
535         TP_STRUCT__entry(
536                 __field(        __u64,  rip     )
537                 __field(        __u32,  slb     )
538         ),
539
540         TP_fast_assign(
541                 __entry->rip            =       rip;
542                 __entry->slb            =       slb;
543         ),
544
545         TP_printk("rip: 0x%016llx slb: 0x%08x\n",
546                   __entry->rip, __entry->slb)
547 );
548
549 #endif /* _TRACE_KVM_H */
550
551 /* This part must be outside protection */
552 #include <trace/define_trace.h>