Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[pandora-kernel.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
9 /*
10  * Tracepoint for guest mode entry.
11  */
12 TRACE_EVENT(kvm_entry,
13         TP_PROTO(unsigned int vcpu_id),
14         TP_ARGS(vcpu_id),
15
16         TP_STRUCT__entry(
17                 __field(        unsigned int,   vcpu_id         )
18         ),
19
20         TP_fast_assign(
21                 __entry->vcpu_id        = vcpu_id;
22         ),
23
24         TP_printk("vcpu %u", __entry->vcpu_id)
25 );
26
27 /*
28  * Tracepoint for hypercall.
29  */
30 TRACE_EVENT(kvm_hypercall,
31         TP_PROTO(unsigned long nr, unsigned long a0, unsigned long a1,
32                  unsigned long a2, unsigned long a3),
33         TP_ARGS(nr, a0, a1, a2, a3),
34
35         TP_STRUCT__entry(
36                 __field(        unsigned long,  nr              )
37                 __field(        unsigned long,  a0              )
38                 __field(        unsigned long,  a1              )
39                 __field(        unsigned long,  a2              )
40                 __field(        unsigned long,  a3              )
41         ),
42
43         TP_fast_assign(
44                 __entry->nr             = nr;
45                 __entry->a0             = a0;
46                 __entry->a1             = a1;
47                 __entry->a2             = a2;
48                 __entry->a3             = a3;
49         ),
50
51         TP_printk("nr 0x%lx a0 0x%lx a1 0x%lx a2 0x%lx a3 0x%lx",
52                  __entry->nr, __entry->a0, __entry->a1,  __entry->a2,
53                  __entry->a3)
54 );
55
56 /*
57  * Tracepoint for hypercall.
58  */
59 TRACE_EVENT(kvm_hv_hypercall,
60         TP_PROTO(__u16 code, bool fast, __u16 rep_cnt, __u16 rep_idx,
61                  __u64 ingpa, __u64 outgpa),
62         TP_ARGS(code, fast, rep_cnt, rep_idx, ingpa, outgpa),
63
64         TP_STRUCT__entry(
65                 __field(        __u16,          code            )
66                 __field(        bool,           fast            )
67                 __field(        __u16,          rep_cnt         )
68                 __field(        __u16,          rep_idx         )
69                 __field(        __u64,          ingpa           )
70                 __field(        __u64,          outgpa          )
71         ),
72
73         TP_fast_assign(
74                 __entry->code           = code;
75                 __entry->fast           = fast;
76                 __entry->rep_cnt        = rep_cnt;
77                 __entry->rep_idx        = rep_idx;
78                 __entry->ingpa          = ingpa;
79                 __entry->outgpa         = outgpa;
80         ),
81
82         TP_printk("code 0x%x %s cnt 0x%x idx 0x%x in 0x%llx out 0x%llx",
83                   __entry->code, __entry->fast ? "fast" : "slow",
84                   __entry->rep_cnt, __entry->rep_idx,  __entry->ingpa,
85                   __entry->outgpa)
86 );
87
88 /*
89  * Tracepoint for PIO.
90  */
91 TRACE_EVENT(kvm_pio,
92         TP_PROTO(unsigned int rw, unsigned int port, unsigned int size,
93                  unsigned int count),
94         TP_ARGS(rw, port, size, count),
95
96         TP_STRUCT__entry(
97                 __field(        unsigned int,   rw              )
98                 __field(        unsigned int,   port            )
99                 __field(        unsigned int,   size            )
100                 __field(        unsigned int,   count           )
101         ),
102
103         TP_fast_assign(
104                 __entry->rw             = rw;
105                 __entry->port           = port;
106                 __entry->size           = size;
107                 __entry->count          = count;
108         ),
109
110         TP_printk("pio_%s at 0x%x size %d count %d",
111                   __entry->rw ? "write" : "read",
112                   __entry->port, __entry->size, __entry->count)
113 );
114
115 /*
116  * Tracepoint for cpuid.
117  */
118 TRACE_EVENT(kvm_cpuid,
119         TP_PROTO(unsigned int function, unsigned long rax, unsigned long rbx,
120                  unsigned long rcx, unsigned long rdx),
121         TP_ARGS(function, rax, rbx, rcx, rdx),
122
123         TP_STRUCT__entry(
124                 __field(        unsigned int,   function        )
125                 __field(        unsigned long,  rax             )
126                 __field(        unsigned long,  rbx             )
127                 __field(        unsigned long,  rcx             )
128                 __field(        unsigned long,  rdx             )
129         ),
130
131         TP_fast_assign(
132                 __entry->function       = function;
133                 __entry->rax            = rax;
134                 __entry->rbx            = rbx;
135                 __entry->rcx            = rcx;
136                 __entry->rdx            = rdx;
137         ),
138
139         TP_printk("func %x rax %lx rbx %lx rcx %lx rdx %lx",
140                   __entry->function, __entry->rax,
141                   __entry->rbx, __entry->rcx, __entry->rdx)
142 );
143
144 #define AREG(x) { APIC_##x, "APIC_" #x }
145
146 #define kvm_trace_symbol_apic                                               \
147         AREG(ID), AREG(LVR), AREG(TASKPRI), AREG(ARBPRI), AREG(PROCPRI),    \
148         AREG(EOI), AREG(RRR), AREG(LDR), AREG(DFR), AREG(SPIV), AREG(ISR),  \
149         AREG(TMR), AREG(IRR), AREG(ESR), AREG(ICR), AREG(ICR2), AREG(LVTT), \
150         AREG(LVTTHMR), AREG(LVTPC), AREG(LVT0), AREG(LVT1), AREG(LVTERR),   \
151         AREG(TMICT), AREG(TMCCT), AREG(TDCR), AREG(SELF_IPI), AREG(EFEAT),  \
152         AREG(ECTRL)
153 /*
154  * Tracepoint for apic access.
155  */
156 TRACE_EVENT(kvm_apic,
157         TP_PROTO(unsigned int rw, unsigned int reg, unsigned int val),
158         TP_ARGS(rw, reg, val),
159
160         TP_STRUCT__entry(
161                 __field(        unsigned int,   rw              )
162                 __field(        unsigned int,   reg             )
163                 __field(        unsigned int,   val             )
164         ),
165
166         TP_fast_assign(
167                 __entry->rw             = rw;
168                 __entry->reg            = reg;
169                 __entry->val            = val;
170         ),
171
172         TP_printk("apic_%s %s = 0x%x",
173                   __entry->rw ? "write" : "read",
174                   __print_symbolic(__entry->reg, kvm_trace_symbol_apic),
175                   __entry->val)
176 );
177
178 #define trace_kvm_apic_read(reg, val)           trace_kvm_apic(0, reg, val)
179 #define trace_kvm_apic_write(reg, val)          trace_kvm_apic(1, reg, val)
180
181 /*
182  * Tracepoint for kvm guest exit:
183  */
184 TRACE_EVENT(kvm_exit,
185         TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu),
186         TP_ARGS(exit_reason, vcpu),
187
188         TP_STRUCT__entry(
189                 __field(        unsigned int,   exit_reason     )
190                 __field(        unsigned long,  guest_rip       )
191         ),
192
193         TP_fast_assign(
194                 __entry->exit_reason    = exit_reason;
195                 __entry->guest_rip      = kvm_rip_read(vcpu);
196         ),
197
198         TP_printk("reason %s rip 0x%lx",
199                  ftrace_print_symbols_seq(p, __entry->exit_reason,
200                                           kvm_x86_ops->exit_reasons_str),
201                  __entry->guest_rip)
202 );
203
204 /*
205  * Tracepoint for kvm interrupt injection:
206  */
207 TRACE_EVENT(kvm_inj_virq,
208         TP_PROTO(unsigned int irq),
209         TP_ARGS(irq),
210
211         TP_STRUCT__entry(
212                 __field(        unsigned int,   irq             )
213         ),
214
215         TP_fast_assign(
216                 __entry->irq            = irq;
217         ),
218
219         TP_printk("irq %u", __entry->irq)
220 );
221
222 #define EXS(x) { x##_VECTOR, "#" #x }
223
224 #define kvm_trace_sym_exc                                               \
225         EXS(DE), EXS(DB), EXS(BP), EXS(OF), EXS(BR), EXS(UD), EXS(NM),  \
226         EXS(DF), EXS(TS), EXS(NP), EXS(SS), EXS(GP), EXS(PF),           \
227         EXS(MF), EXS(MC)
228
229 /*
230  * Tracepoint for kvm interrupt injection:
231  */
232 TRACE_EVENT(kvm_inj_exception,
233         TP_PROTO(unsigned exception, bool has_error, unsigned error_code),
234         TP_ARGS(exception, has_error, error_code),
235
236         TP_STRUCT__entry(
237                 __field(        u8,     exception       )
238                 __field(        u8,     has_error       )
239                 __field(        u32,    error_code      )
240         ),
241
242         TP_fast_assign(
243                 __entry->exception      = exception;
244                 __entry->has_error      = has_error;
245                 __entry->error_code     = error_code;
246         ),
247
248         TP_printk("%s (0x%x)",
249                   __print_symbolic(__entry->exception, kvm_trace_sym_exc),
250                   /* FIXME: don't print error_code if not present */
251                   __entry->has_error ? __entry->error_code : 0)
252 );
253
254 /*
255  * Tracepoint for page fault.
256  */
257 TRACE_EVENT(kvm_page_fault,
258         TP_PROTO(unsigned long fault_address, unsigned int error_code),
259         TP_ARGS(fault_address, error_code),
260
261         TP_STRUCT__entry(
262                 __field(        unsigned long,  fault_address   )
263                 __field(        unsigned int,   error_code      )
264         ),
265
266         TP_fast_assign(
267                 __entry->fault_address  = fault_address;
268                 __entry->error_code     = error_code;
269         ),
270
271         TP_printk("address %lx error_code %x",
272                   __entry->fault_address, __entry->error_code)
273 );
274
275 /*
276  * Tracepoint for guest MSR access.
277  */
278 TRACE_EVENT(kvm_msr,
279         TP_PROTO(unsigned write, u32 ecx, u64 data, bool exception),
280         TP_ARGS(write, ecx, data, exception),
281
282         TP_STRUCT__entry(
283                 __field(        unsigned,       write           )
284                 __field(        u32,            ecx             )
285                 __field(        u64,            data            )
286                 __field(        u8,             exception       )
287         ),
288
289         TP_fast_assign(
290                 __entry->write          = write;
291                 __entry->ecx            = ecx;
292                 __entry->data           = data;
293                 __entry->exception      = exception;
294         ),
295
296         TP_printk("msr_%s %x = 0x%llx%s",
297                   __entry->write ? "write" : "read",
298                   __entry->ecx, __entry->data,
299                   __entry->exception ? " (#GP)" : "")
300 );
301
302 #define trace_kvm_msr_read(ecx, data)      trace_kvm_msr(0, ecx, data, false)
303 #define trace_kvm_msr_write(ecx, data)     trace_kvm_msr(1, ecx, data, false)
304 #define trace_kvm_msr_read_ex(ecx)         trace_kvm_msr(0, ecx, 0, true)
305 #define trace_kvm_msr_write_ex(ecx, data)  trace_kvm_msr(1, ecx, data, true)
306
307 /*
308  * Tracepoint for guest CR access.
309  */
310 TRACE_EVENT(kvm_cr,
311         TP_PROTO(unsigned int rw, unsigned int cr, unsigned long val),
312         TP_ARGS(rw, cr, val),
313
314         TP_STRUCT__entry(
315                 __field(        unsigned int,   rw              )
316                 __field(        unsigned int,   cr              )
317                 __field(        unsigned long,  val             )
318         ),
319
320         TP_fast_assign(
321                 __entry->rw             = rw;
322                 __entry->cr             = cr;
323                 __entry->val            = val;
324         ),
325
326         TP_printk("cr_%s %x = 0x%lx",
327                   __entry->rw ? "write" : "read",
328                   __entry->cr, __entry->val)
329 );
330
331 #define trace_kvm_cr_read(cr, val)              trace_kvm_cr(0, cr, val)
332 #define trace_kvm_cr_write(cr, val)             trace_kvm_cr(1, cr, val)
333
334 TRACE_EVENT(kvm_pic_set_irq,
335             TP_PROTO(__u8 chip, __u8 pin, __u8 elcr, __u8 imr, bool coalesced),
336             TP_ARGS(chip, pin, elcr, imr, coalesced),
337
338         TP_STRUCT__entry(
339                 __field(        __u8,           chip            )
340                 __field(        __u8,           pin             )
341                 __field(        __u8,           elcr            )
342                 __field(        __u8,           imr             )
343                 __field(        bool,           coalesced       )
344         ),
345
346         TP_fast_assign(
347                 __entry->chip           = chip;
348                 __entry->pin            = pin;
349                 __entry->elcr           = elcr;
350                 __entry->imr            = imr;
351                 __entry->coalesced      = coalesced;
352         ),
353
354         TP_printk("chip %u pin %u (%s%s)%s",
355                   __entry->chip, __entry->pin,
356                   (__entry->elcr & (1 << __entry->pin)) ? "level":"edge",
357                   (__entry->imr & (1 << __entry->pin)) ? "|masked":"",
358                   __entry->coalesced ? " (coalesced)" : "")
359 );
360
361 #define kvm_apic_dst_shorthand          \
362         {0x0, "dst"},                   \
363         {0x1, "self"},                  \
364         {0x2, "all"},                   \
365         {0x3, "all-but-self"}
366
367 TRACE_EVENT(kvm_apic_ipi,
368             TP_PROTO(__u32 icr_low, __u32 dest_id),
369             TP_ARGS(icr_low, dest_id),
370
371         TP_STRUCT__entry(
372                 __field(        __u32,          icr_low         )
373                 __field(        __u32,          dest_id         )
374         ),
375
376         TP_fast_assign(
377                 __entry->icr_low        = icr_low;
378                 __entry->dest_id        = dest_id;
379         ),
380
381         TP_printk("dst %x vec %u (%s|%s|%s|%s|%s)",
382                   __entry->dest_id, (u8)__entry->icr_low,
383                   __print_symbolic((__entry->icr_low >> 8 & 0x7),
384                                    kvm_deliver_mode),
385                   (__entry->icr_low & (1<<11)) ? "logical" : "physical",
386                   (__entry->icr_low & (1<<14)) ? "assert" : "de-assert",
387                   (__entry->icr_low & (1<<15)) ? "level" : "edge",
388                   __print_symbolic((__entry->icr_low >> 18 & 0x3),
389                                    kvm_apic_dst_shorthand))
390 );
391
392 TRACE_EVENT(kvm_apic_accept_irq,
393             TP_PROTO(__u32 apicid, __u16 dm, __u8 tm, __u8 vec, bool coalesced),
394             TP_ARGS(apicid, dm, tm, vec, coalesced),
395
396         TP_STRUCT__entry(
397                 __field(        __u32,          apicid          )
398                 __field(        __u16,          dm              )
399                 __field(        __u8,           tm              )
400                 __field(        __u8,           vec             )
401                 __field(        bool,           coalesced       )
402         ),
403
404         TP_fast_assign(
405                 __entry->apicid         = apicid;
406                 __entry->dm             = dm;
407                 __entry->tm             = tm;
408                 __entry->vec            = vec;
409                 __entry->coalesced      = coalesced;
410         ),
411
412         TP_printk("apicid %x vec %u (%s|%s)%s",
413                   __entry->apicid, __entry->vec,
414                   __print_symbolic((__entry->dm >> 8 & 0x7), kvm_deliver_mode),
415                   __entry->tm ? "level" : "edge",
416                   __entry->coalesced ? " (coalesced)" : "")
417 );
418
419 /*
420  * Tracepoint for nested VMRUN
421  */
422 TRACE_EVENT(kvm_nested_vmrun,
423             TP_PROTO(__u64 rip, __u64 vmcb, __u64 nested_rip, __u32 int_ctl,
424                      __u32 event_inj, bool npt),
425             TP_ARGS(rip, vmcb, nested_rip, int_ctl, event_inj, npt),
426
427         TP_STRUCT__entry(
428                 __field(        __u64,          rip             )
429                 __field(        __u64,          vmcb            )
430                 __field(        __u64,          nested_rip      )
431                 __field(        __u32,          int_ctl         )
432                 __field(        __u32,          event_inj       )
433                 __field(        bool,           npt             )
434         ),
435
436         TP_fast_assign(
437                 __entry->rip            = rip;
438                 __entry->vmcb           = vmcb;
439                 __entry->nested_rip     = nested_rip;
440                 __entry->int_ctl        = int_ctl;
441                 __entry->event_inj      = event_inj;
442                 __entry->npt            = npt;
443         ),
444
445         TP_printk("rip: 0x%016llx vmcb: 0x%016llx nrip: 0x%016llx int_ctl: 0x%08x "
446                   "event_inj: 0x%08x npt: %s",
447                 __entry->rip, __entry->vmcb, __entry->nested_rip,
448                 __entry->int_ctl, __entry->event_inj,
449                 __entry->npt ? "on" : "off")
450 );
451
452 TRACE_EVENT(kvm_nested_intercepts,
453             TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u64 intercept),
454             TP_ARGS(cr_read, cr_write, exceptions, intercept),
455
456         TP_STRUCT__entry(
457                 __field(        __u16,          cr_read         )
458                 __field(        __u16,          cr_write        )
459                 __field(        __u32,          exceptions      )
460                 __field(        __u64,          intercept       )
461         ),
462
463         TP_fast_assign(
464                 __entry->cr_read        = cr_read;
465                 __entry->cr_write       = cr_write;
466                 __entry->exceptions     = exceptions;
467                 __entry->intercept      = intercept;
468         ),
469
470         TP_printk("cr_read: %04x cr_write: %04x excp: %08x intercept: %016llx",
471                 __entry->cr_read, __entry->cr_write, __entry->exceptions,
472                 __entry->intercept)
473 );
474 /*
475  * Tracepoint for #VMEXIT while nested
476  */
477 TRACE_EVENT(kvm_nested_vmexit,
478             TP_PROTO(__u64 rip, __u32 exit_code,
479                      __u64 exit_info1, __u64 exit_info2,
480                      __u32 exit_int_info, __u32 exit_int_info_err),
481             TP_ARGS(rip, exit_code, exit_info1, exit_info2,
482                     exit_int_info, exit_int_info_err),
483
484         TP_STRUCT__entry(
485                 __field(        __u64,          rip                     )
486                 __field(        __u32,          exit_code               )
487                 __field(        __u64,          exit_info1              )
488                 __field(        __u64,          exit_info2              )
489                 __field(        __u32,          exit_int_info           )
490                 __field(        __u32,          exit_int_info_err       )
491         ),
492
493         TP_fast_assign(
494                 __entry->rip                    = rip;
495                 __entry->exit_code              = exit_code;
496                 __entry->exit_info1             = exit_info1;
497                 __entry->exit_info2             = exit_info2;
498                 __entry->exit_int_info          = exit_int_info;
499                 __entry->exit_int_info_err      = exit_int_info_err;
500         ),
501         TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx "
502                   "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
503                   __entry->rip,
504                   ftrace_print_symbols_seq(p, __entry->exit_code,
505                                            kvm_x86_ops->exit_reasons_str),
506                   __entry->exit_info1, __entry->exit_info2,
507                   __entry->exit_int_info, __entry->exit_int_info_err)
508 );
509
510 /*
511  * Tracepoint for #VMEXIT reinjected to the guest
512  */
513 TRACE_EVENT(kvm_nested_vmexit_inject,
514             TP_PROTO(__u32 exit_code,
515                      __u64 exit_info1, __u64 exit_info2,
516                      __u32 exit_int_info, __u32 exit_int_info_err),
517             TP_ARGS(exit_code, exit_info1, exit_info2,
518                     exit_int_info, exit_int_info_err),
519
520         TP_STRUCT__entry(
521                 __field(        __u32,          exit_code               )
522                 __field(        __u64,          exit_info1              )
523                 __field(        __u64,          exit_info2              )
524                 __field(        __u32,          exit_int_info           )
525                 __field(        __u32,          exit_int_info_err       )
526         ),
527
528         TP_fast_assign(
529                 __entry->exit_code              = exit_code;
530                 __entry->exit_info1             = exit_info1;
531                 __entry->exit_info2             = exit_info2;
532                 __entry->exit_int_info          = exit_int_info;
533                 __entry->exit_int_info_err      = exit_int_info_err;
534         ),
535
536         TP_printk("reason: %s ext_inf1: 0x%016llx "
537                   "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
538                   ftrace_print_symbols_seq(p, __entry->exit_code,
539                                            kvm_x86_ops->exit_reasons_str),
540                 __entry->exit_info1, __entry->exit_info2,
541                 __entry->exit_int_info, __entry->exit_int_info_err)
542 );
543
544 /*
545  * Tracepoint for nested #vmexit because of interrupt pending
546  */
547 TRACE_EVENT(kvm_nested_intr_vmexit,
548             TP_PROTO(__u64 rip),
549             TP_ARGS(rip),
550
551         TP_STRUCT__entry(
552                 __field(        __u64,  rip     )
553         ),
554
555         TP_fast_assign(
556                 __entry->rip    =       rip
557         ),
558
559         TP_printk("rip: 0x%016llx", __entry->rip)
560 );
561
562 /*
563  * Tracepoint for nested #vmexit because of interrupt pending
564  */
565 TRACE_EVENT(kvm_invlpga,
566             TP_PROTO(__u64 rip, int asid, u64 address),
567             TP_ARGS(rip, asid, address),
568
569         TP_STRUCT__entry(
570                 __field(        __u64,  rip     )
571                 __field(        int,    asid    )
572                 __field(        __u64,  address )
573         ),
574
575         TP_fast_assign(
576                 __entry->rip            =       rip;
577                 __entry->asid           =       asid;
578                 __entry->address        =       address;
579         ),
580
581         TP_printk("rip: 0x%016llx asid: %d address: 0x%016llx",
582                   __entry->rip, __entry->asid, __entry->address)
583 );
584
585 /*
586  * Tracepoint for nested #vmexit because of interrupt pending
587  */
588 TRACE_EVENT(kvm_skinit,
589             TP_PROTO(__u64 rip, __u32 slb),
590             TP_ARGS(rip, slb),
591
592         TP_STRUCT__entry(
593                 __field(        __u64,  rip     )
594                 __field(        __u32,  slb     )
595         ),
596
597         TP_fast_assign(
598                 __entry->rip            =       rip;
599                 __entry->slb            =       slb;
600         ),
601
602         TP_printk("rip: 0x%016llx slb: 0x%08x",
603                   __entry->rip, __entry->slb)
604 );
605
606 #define __print_insn(insn, ilen) ({                              \
607         int i;                                                   \
608         const char *ret = p->buffer + p->len;                    \
609                                                                  \
610         for (i = 0; i < ilen; ++i)                               \
611                 trace_seq_printf(p, " %02x", insn[i]);           \
612         trace_seq_printf(p, "%c", 0);                            \
613         ret;                                                     \
614         })
615
616 #define KVM_EMUL_INSN_F_CR0_PE (1 << 0)
617 #define KVM_EMUL_INSN_F_EFL_VM (1 << 1)
618 #define KVM_EMUL_INSN_F_CS_D   (1 << 2)
619 #define KVM_EMUL_INSN_F_CS_L   (1 << 3)
620
621 #define kvm_trace_symbol_emul_flags                       \
622         { 0,                        "real" },             \
623         { KVM_EMUL_INSN_F_CR0_PE                          \
624           | KVM_EMUL_INSN_F_EFL_VM, "vm16" },             \
625         { KVM_EMUL_INSN_F_CR0_PE,   "prot16" },           \
626         { KVM_EMUL_INSN_F_CR0_PE                          \
627           | KVM_EMUL_INSN_F_CS_D,   "prot32" },           \
628         { KVM_EMUL_INSN_F_CR0_PE                          \
629           | KVM_EMUL_INSN_F_CS_L,   "prot64" }
630
631 #define kei_decode_mode(mode) ({                        \
632         u8 flags = 0xff;                                \
633         switch (mode) {                                 \
634         case X86EMUL_MODE_REAL:                         \
635                 flags = 0;                              \
636                 break;                                  \
637         case X86EMUL_MODE_VM86:                         \
638                 flags = KVM_EMUL_INSN_F_EFL_VM;         \
639                 break;                                  \
640         case X86EMUL_MODE_PROT16:                       \
641                 flags = KVM_EMUL_INSN_F_CR0_PE;         \
642                 break;                                  \
643         case X86EMUL_MODE_PROT32:                       \
644                 flags = KVM_EMUL_INSN_F_CR0_PE          \
645                         | KVM_EMUL_INSN_F_CS_D;         \
646                 break;                                  \
647         case X86EMUL_MODE_PROT64:                       \
648                 flags = KVM_EMUL_INSN_F_CR0_PE          \
649                         | KVM_EMUL_INSN_F_CS_L;         \
650                 break;                                  \
651         }                                               \
652         flags;                                          \
653         })
654
655 TRACE_EVENT(kvm_emulate_insn,
656         TP_PROTO(struct kvm_vcpu *vcpu, __u8 failed),
657         TP_ARGS(vcpu, failed),
658
659         TP_STRUCT__entry(
660                 __field(    __u64, rip                       )
661                 __field(    __u32, csbase                    )
662                 __field(    __u8,  len                       )
663                 __array(    __u8,  insn,    15               )
664                 __field(    __u8,  flags                     )
665                 __field(    __u8,  failed                    )
666                 ),
667
668         TP_fast_assign(
669                 __entry->rip = vcpu->arch.emulate_ctxt.decode.fetch.start;
670                 __entry->csbase = kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS);
671                 __entry->len = vcpu->arch.emulate_ctxt.decode.eip
672                                - vcpu->arch.emulate_ctxt.decode.fetch.start;
673                 memcpy(__entry->insn,
674                        vcpu->arch.emulate_ctxt.decode.fetch.data,
675                        15);
676                 __entry->flags = kei_decode_mode(vcpu->arch.emulate_ctxt.mode);
677                 __entry->failed = failed;
678                 ),
679
680         TP_printk("%x:%llx:%s (%s)%s",
681                   __entry->csbase, __entry->rip,
682                   __print_insn(__entry->insn, __entry->len),
683                   __print_symbolic(__entry->flags,
684                                    kvm_trace_symbol_emul_flags),
685                   __entry->failed ? " failed" : ""
686                 )
687         );
688
689 #define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0)
690 #define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1)
691
692 #endif /* _TRACE_KVM_H */
693
694 #undef TRACE_INCLUDE_PATH
695 #define TRACE_INCLUDE_PATH arch/x86/kvm
696 #undef TRACE_INCLUDE_FILE
697 #define TRACE_INCLUDE_FILE trace
698
699 /* This part must be outside protection */
700 #include <trace/define_trace.h>