KVM: SVM: Add kvm_nested_intercepts tracepoint
[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, bool exception),
250         TP_ARGS(write, ecx, data, exception),
251
252         TP_STRUCT__entry(
253                 __field(        unsigned,       write           )
254                 __field(        u32,            ecx             )
255                 __field(        u64,            data            )
256                 __field(        u8,             exception       )
257         ),
258
259         TP_fast_assign(
260                 __entry->write          = write;
261                 __entry->ecx            = ecx;
262                 __entry->data           = data;
263                 __entry->exception      = exception;
264         ),
265
266         TP_printk("msr_%s %x = 0x%llx%s",
267                   __entry->write ? "write" : "read",
268                   __entry->ecx, __entry->data,
269                   __entry->exception ? " (#GP)" : "")
270 );
271
272 #define trace_kvm_msr_read(ecx, data)      trace_kvm_msr(0, ecx, data, false)
273 #define trace_kvm_msr_write(ecx, data)     trace_kvm_msr(1, ecx, data, false)
274 #define trace_kvm_msr_read_ex(ecx)         trace_kvm_msr(0, ecx, 0, true)
275 #define trace_kvm_msr_write_ex(ecx, data)  trace_kvm_msr(1, ecx, data, true)
276
277 /*
278  * Tracepoint for guest CR access.
279  */
280 TRACE_EVENT(kvm_cr,
281         TP_PROTO(unsigned int rw, unsigned int cr, unsigned long val),
282         TP_ARGS(rw, cr, val),
283
284         TP_STRUCT__entry(
285                 __field(        unsigned int,   rw              )
286                 __field(        unsigned int,   cr              )
287                 __field(        unsigned long,  val             )
288         ),
289
290         TP_fast_assign(
291                 __entry->rw             = rw;
292                 __entry->cr             = cr;
293                 __entry->val            = val;
294         ),
295
296         TP_printk("cr_%s %x = 0x%lx",
297                   __entry->rw ? "write" : "read",
298                   __entry->cr, __entry->val)
299 );
300
301 #define trace_kvm_cr_read(cr, val)              trace_kvm_cr(0, cr, val)
302 #define trace_kvm_cr_write(cr, val)             trace_kvm_cr(1, cr, val)
303
304 TRACE_EVENT(kvm_pic_set_irq,
305             TP_PROTO(__u8 chip, __u8 pin, __u8 elcr, __u8 imr, bool coalesced),
306             TP_ARGS(chip, pin, elcr, imr, coalesced),
307
308         TP_STRUCT__entry(
309                 __field(        __u8,           chip            )
310                 __field(        __u8,           pin             )
311                 __field(        __u8,           elcr            )
312                 __field(        __u8,           imr             )
313                 __field(        bool,           coalesced       )
314         ),
315
316         TP_fast_assign(
317                 __entry->chip           = chip;
318                 __entry->pin            = pin;
319                 __entry->elcr           = elcr;
320                 __entry->imr            = imr;
321                 __entry->coalesced      = coalesced;
322         ),
323
324         TP_printk("chip %u pin %u (%s%s)%s",
325                   __entry->chip, __entry->pin,
326                   (__entry->elcr & (1 << __entry->pin)) ? "level":"edge",
327                   (__entry->imr & (1 << __entry->pin)) ? "|masked":"",
328                   __entry->coalesced ? " (coalesced)" : "")
329 );
330
331 #define kvm_apic_dst_shorthand          \
332         {0x0, "dst"},                   \
333         {0x1, "self"},                  \
334         {0x2, "all"},                   \
335         {0x3, "all-but-self"}
336
337 TRACE_EVENT(kvm_apic_ipi,
338             TP_PROTO(__u32 icr_low, __u32 dest_id),
339             TP_ARGS(icr_low, dest_id),
340
341         TP_STRUCT__entry(
342                 __field(        __u32,          icr_low         )
343                 __field(        __u32,          dest_id         )
344         ),
345
346         TP_fast_assign(
347                 __entry->icr_low        = icr_low;
348                 __entry->dest_id        = dest_id;
349         ),
350
351         TP_printk("dst %x vec %u (%s|%s|%s|%s|%s)",
352                   __entry->dest_id, (u8)__entry->icr_low,
353                   __print_symbolic((__entry->icr_low >> 8 & 0x7),
354                                    kvm_deliver_mode),
355                   (__entry->icr_low & (1<<11)) ? "logical" : "physical",
356                   (__entry->icr_low & (1<<14)) ? "assert" : "de-assert",
357                   (__entry->icr_low & (1<<15)) ? "level" : "edge",
358                   __print_symbolic((__entry->icr_low >> 18 & 0x3),
359                                    kvm_apic_dst_shorthand))
360 );
361
362 TRACE_EVENT(kvm_apic_accept_irq,
363             TP_PROTO(__u32 apicid, __u16 dm, __u8 tm, __u8 vec, bool coalesced),
364             TP_ARGS(apicid, dm, tm, vec, coalesced),
365
366         TP_STRUCT__entry(
367                 __field(        __u32,          apicid          )
368                 __field(        __u16,          dm              )
369                 __field(        __u8,           tm              )
370                 __field(        __u8,           vec             )
371                 __field(        bool,           coalesced       )
372         ),
373
374         TP_fast_assign(
375                 __entry->apicid         = apicid;
376                 __entry->dm             = dm;
377                 __entry->tm             = tm;
378                 __entry->vec            = vec;
379                 __entry->coalesced      = coalesced;
380         ),
381
382         TP_printk("apicid %x vec %u (%s|%s)%s",
383                   __entry->apicid, __entry->vec,
384                   __print_symbolic((__entry->dm >> 8 & 0x7), kvm_deliver_mode),
385                   __entry->tm ? "level" : "edge",
386                   __entry->coalesced ? " (coalesced)" : "")
387 );
388
389 /*
390  * Tracepoint for nested VMRUN
391  */
392 TRACE_EVENT(kvm_nested_vmrun,
393             TP_PROTO(__u64 rip, __u64 vmcb, __u64 nested_rip, __u32 int_ctl,
394                      __u32 event_inj, bool npt),
395             TP_ARGS(rip, vmcb, nested_rip, int_ctl, event_inj, npt),
396
397         TP_STRUCT__entry(
398                 __field(        __u64,          rip             )
399                 __field(        __u64,          vmcb            )
400                 __field(        __u64,          nested_rip      )
401                 __field(        __u32,          int_ctl         )
402                 __field(        __u32,          event_inj       )
403                 __field(        bool,           npt             )
404         ),
405
406         TP_fast_assign(
407                 __entry->rip            = rip;
408                 __entry->vmcb           = vmcb;
409                 __entry->nested_rip     = nested_rip;
410                 __entry->int_ctl        = int_ctl;
411                 __entry->event_inj      = event_inj;
412                 __entry->npt            = npt;
413         ),
414
415         TP_printk("rip: 0x%016llx vmcb: 0x%016llx nrip: 0x%016llx int_ctl: 0x%08x "
416                   "event_inj: 0x%08x npt: %s",
417                 __entry->rip, __entry->vmcb, __entry->nested_rip,
418                 __entry->int_ctl, __entry->event_inj,
419                 __entry->npt ? "on" : "off")
420 );
421
422 TRACE_EVENT(kvm_nested_intercepts,
423             TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u64 intercept),
424             TP_ARGS(cr_read, cr_write, exceptions, intercept),
425
426         TP_STRUCT__entry(
427                 __field(        __u16,          cr_read         )
428                 __field(        __u16,          cr_write        )
429                 __field(        __u32,          exceptions      )
430                 __field(        __u64,          intercept       )
431         ),
432
433         TP_fast_assign(
434                 __entry->cr_read        = cr_read;
435                 __entry->cr_write       = cr_write;
436                 __entry->exceptions     = exceptions;
437                 __entry->intercept      = intercept;
438         ),
439
440         TP_printk("cr_read: %04x cr_write: %04x excp: %08x intercept: %016llx",
441                 __entry->cr_read, __entry->cr_write, __entry->exceptions,
442                 __entry->intercept)
443 );
444 /*
445  * Tracepoint for #VMEXIT while nested
446  */
447 TRACE_EVENT(kvm_nested_vmexit,
448             TP_PROTO(__u64 rip, __u32 exit_code,
449                      __u64 exit_info1, __u64 exit_info2,
450                      __u32 exit_int_info, __u32 exit_int_info_err),
451             TP_ARGS(rip, exit_code, exit_info1, exit_info2,
452                     exit_int_info, exit_int_info_err),
453
454         TP_STRUCT__entry(
455                 __field(        __u64,          rip                     )
456                 __field(        __u32,          exit_code               )
457                 __field(        __u64,          exit_info1              )
458                 __field(        __u64,          exit_info2              )
459                 __field(        __u32,          exit_int_info           )
460                 __field(        __u32,          exit_int_info_err       )
461         ),
462
463         TP_fast_assign(
464                 __entry->rip                    = rip;
465                 __entry->exit_code              = exit_code;
466                 __entry->exit_info1             = exit_info1;
467                 __entry->exit_info2             = exit_info2;
468                 __entry->exit_int_info          = exit_int_info;
469                 __entry->exit_int_info_err      = exit_int_info_err;
470         ),
471         TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx "
472                   "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
473                   __entry->rip,
474                   ftrace_print_symbols_seq(p, __entry->exit_code,
475                                            kvm_x86_ops->exit_reasons_str),
476                   __entry->exit_info1, __entry->exit_info2,
477                   __entry->exit_int_info, __entry->exit_int_info_err)
478 );
479
480 /*
481  * Tracepoint for #VMEXIT reinjected to the guest
482  */
483 TRACE_EVENT(kvm_nested_vmexit_inject,
484             TP_PROTO(__u32 exit_code,
485                      __u64 exit_info1, __u64 exit_info2,
486                      __u32 exit_int_info, __u32 exit_int_info_err),
487             TP_ARGS(exit_code, exit_info1, exit_info2,
488                     exit_int_info, exit_int_info_err),
489
490         TP_STRUCT__entry(
491                 __field(        __u32,          exit_code               )
492                 __field(        __u64,          exit_info1              )
493                 __field(        __u64,          exit_info2              )
494                 __field(        __u32,          exit_int_info           )
495                 __field(        __u32,          exit_int_info_err       )
496         ),
497
498         TP_fast_assign(
499                 __entry->exit_code              = exit_code;
500                 __entry->exit_info1             = exit_info1;
501                 __entry->exit_info2             = exit_info2;
502                 __entry->exit_int_info          = exit_int_info;
503                 __entry->exit_int_info_err      = exit_int_info_err;
504         ),
505
506         TP_printk("reason: %s ext_inf1: 0x%016llx "
507                   "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
508                   ftrace_print_symbols_seq(p, __entry->exit_code,
509                                            kvm_x86_ops->exit_reasons_str),
510                 __entry->exit_info1, __entry->exit_info2,
511                 __entry->exit_int_info, __entry->exit_int_info_err)
512 );
513
514 /*
515  * Tracepoint for nested #vmexit because of interrupt pending
516  */
517 TRACE_EVENT(kvm_nested_intr_vmexit,
518             TP_PROTO(__u64 rip),
519             TP_ARGS(rip),
520
521         TP_STRUCT__entry(
522                 __field(        __u64,  rip     )
523         ),
524
525         TP_fast_assign(
526                 __entry->rip    =       rip
527         ),
528
529         TP_printk("rip: 0x%016llx", __entry->rip)
530 );
531
532 /*
533  * Tracepoint for nested #vmexit because of interrupt pending
534  */
535 TRACE_EVENT(kvm_invlpga,
536             TP_PROTO(__u64 rip, int asid, u64 address),
537             TP_ARGS(rip, asid, address),
538
539         TP_STRUCT__entry(
540                 __field(        __u64,  rip     )
541                 __field(        int,    asid    )
542                 __field(        __u64,  address )
543         ),
544
545         TP_fast_assign(
546                 __entry->rip            =       rip;
547                 __entry->asid           =       asid;
548                 __entry->address        =       address;
549         ),
550
551         TP_printk("rip: 0x%016llx asid: %d address: 0x%016llx",
552                   __entry->rip, __entry->asid, __entry->address)
553 );
554
555 /*
556  * Tracepoint for nested #vmexit because of interrupt pending
557  */
558 TRACE_EVENT(kvm_skinit,
559             TP_PROTO(__u64 rip, __u32 slb),
560             TP_ARGS(rip, slb),
561
562         TP_STRUCT__entry(
563                 __field(        __u64,  rip     )
564                 __field(        __u32,  slb     )
565         ),
566
567         TP_fast_assign(
568                 __entry->rip            =       rip;
569                 __entry->slb            =       slb;
570         ),
571
572         TP_printk("rip: 0x%016llx slb: 0x%08x",
573                   __entry->rip, __entry->slb)
574 );
575
576 #endif /* _TRACE_KVM_H */
577
578 /* This part must be outside protection */
579 #include <trace/define_trace.h>