blob: 10610229b248ff18627397a9ac882d694577ff3e [file] [log] [blame]
Marcelo Tosatti229456f2009-06-17 09:22:14 -03001#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
Marcelo Tosatti229456f2009-06-17 09:22:14 -03008
9/*
10 * Tracepoint for guest mode entry.
11 */
12TRACE_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 */
30TRACE_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/*
Gleb Natapov55cd8e52010-01-17 15:51:22 +020057 * Tracepoint for hypercall.
58 */
59TRACE_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/*
Marcelo Tosatti229456f2009-06-17 09:22:14 -030089 * Tracepoint for PIO.
90 */
91TRACE_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 */
118TRACE_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
Avi Kivitycb247722009-07-01 18:25:44 +0300144#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)
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300153/*
154 * Tracepoint for apic access.
155 */
156TRACE_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
Avi Kivitycb247722009-07-01 18:25:44 +0300172 TP_printk("apic_%s %s = 0x%x",
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300173 __entry->rw ? "write" : "read",
Avi Kivitycb247722009-07-01 18:25:44 +0300174 __print_symbolic(__entry->reg, kvm_trace_symbol_apic),
175 __entry->val)
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300176);
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
Avi Kivityaa179112010-11-17 18:44:19 +0200181#define KVM_ISA_VMX 1
182#define KVM_ISA_SVM 2
183
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300184/*
185 * Tracepoint for kvm guest exit:
186 */
187TRACE_EVENT(kvm_exit,
Avi Kivityaa179112010-11-17 18:44:19 +0200188 TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa),
189 TP_ARGS(exit_reason, vcpu, isa),
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300190
191 TP_STRUCT__entry(
192 __field( unsigned int, exit_reason )
193 __field( unsigned long, guest_rip )
Avi Kivityaa179112010-11-17 18:44:19 +0200194 __field( u32, isa )
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300195 ),
196
197 TP_fast_assign(
198 __entry->exit_reason = exit_reason;
Avi Kivity5bfd8b52010-03-11 10:50:44 +0200199 __entry->guest_rip = kvm_rip_read(vcpu);
Avi Kivityaa179112010-11-17 18:44:19 +0200200 __entry->isa = isa;
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300201 ),
202
203 TP_printk("reason %s rip 0x%lx",
204 ftrace_print_symbols_seq(p, __entry->exit_reason,
205 kvm_x86_ops->exit_reasons_str),
206 __entry->guest_rip)
207);
208
209/*
210 * Tracepoint for kvm interrupt injection:
211 */
212TRACE_EVENT(kvm_inj_virq,
213 TP_PROTO(unsigned int irq),
214 TP_ARGS(irq),
215
216 TP_STRUCT__entry(
217 __field( unsigned int, irq )
218 ),
219
220 TP_fast_assign(
221 __entry->irq = irq;
222 ),
223
224 TP_printk("irq %u", __entry->irq)
225);
226
Avi Kivity5c1c85d02010-03-11 13:01:59 +0200227#define EXS(x) { x##_VECTOR, "#" #x }
228
229#define kvm_trace_sym_exc \
230 EXS(DE), EXS(DB), EXS(BP), EXS(OF), EXS(BR), EXS(UD), EXS(NM), \
231 EXS(DF), EXS(TS), EXS(NP), EXS(SS), EXS(GP), EXS(PF), \
232 EXS(MF), EXS(MC)
233
234/*
235 * Tracepoint for kvm interrupt injection:
236 */
237TRACE_EVENT(kvm_inj_exception,
238 TP_PROTO(unsigned exception, bool has_error, unsigned error_code),
239 TP_ARGS(exception, has_error, error_code),
240
241 TP_STRUCT__entry(
242 __field( u8, exception )
243 __field( u8, has_error )
244 __field( u32, error_code )
245 ),
246
247 TP_fast_assign(
248 __entry->exception = exception;
249 __entry->has_error = has_error;
250 __entry->error_code = error_code;
251 ),
252
253 TP_printk("%s (0x%x)",
254 __print_symbolic(__entry->exception, kvm_trace_sym_exc),
255 /* FIXME: don't print error_code if not present */
256 __entry->has_error ? __entry->error_code : 0)
257);
258
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300259/*
260 * Tracepoint for page fault.
261 */
262TRACE_EVENT(kvm_page_fault,
263 TP_PROTO(unsigned long fault_address, unsigned int error_code),
264 TP_ARGS(fault_address, error_code),
265
266 TP_STRUCT__entry(
267 __field( unsigned long, fault_address )
268 __field( unsigned int, error_code )
269 ),
270
271 TP_fast_assign(
272 __entry->fault_address = fault_address;
273 __entry->error_code = error_code;
274 ),
275
276 TP_printk("address %lx error_code %x",
277 __entry->fault_address, __entry->error_code)
278);
279
280/*
281 * Tracepoint for guest MSR access.
282 */
283TRACE_EVENT(kvm_msr,
Avi Kivity59200272010-01-25 19:47:02 +0200284 TP_PROTO(unsigned write, u32 ecx, u64 data, bool exception),
285 TP_ARGS(write, ecx, data, exception),
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300286
287 TP_STRUCT__entry(
Avi Kivity6e7d1522010-01-25 19:36:03 +0200288 __field( unsigned, write )
289 __field( u32, ecx )
290 __field( u64, data )
Avi Kivity59200272010-01-25 19:47:02 +0200291 __field( u8, exception )
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300292 ),
293
294 TP_fast_assign(
Avi Kivity6e7d1522010-01-25 19:36:03 +0200295 __entry->write = write;
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300296 __entry->ecx = ecx;
297 __entry->data = data;
Avi Kivity59200272010-01-25 19:47:02 +0200298 __entry->exception = exception;
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300299 ),
300
Avi Kivity59200272010-01-25 19:47:02 +0200301 TP_printk("msr_%s %x = 0x%llx%s",
Avi Kivity6e7d1522010-01-25 19:36:03 +0200302 __entry->write ? "write" : "read",
Avi Kivity59200272010-01-25 19:47:02 +0200303 __entry->ecx, __entry->data,
304 __entry->exception ? " (#GP)" : "")
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300305);
306
Avi Kivity59200272010-01-25 19:47:02 +0200307#define trace_kvm_msr_read(ecx, data) trace_kvm_msr(0, ecx, data, false)
308#define trace_kvm_msr_write(ecx, data) trace_kvm_msr(1, ecx, data, false)
309#define trace_kvm_msr_read_ex(ecx) trace_kvm_msr(0, ecx, 0, true)
310#define trace_kvm_msr_write_ex(ecx, data) trace_kvm_msr(1, ecx, data, true)
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300311
312/*
313 * Tracepoint for guest CR access.
314 */
315TRACE_EVENT(kvm_cr,
316 TP_PROTO(unsigned int rw, unsigned int cr, unsigned long val),
317 TP_ARGS(rw, cr, val),
318
319 TP_STRUCT__entry(
320 __field( unsigned int, rw )
321 __field( unsigned int, cr )
322 __field( unsigned long, val )
323 ),
324
325 TP_fast_assign(
326 __entry->rw = rw;
327 __entry->cr = cr;
328 __entry->val = val;
329 ),
330
331 TP_printk("cr_%s %x = 0x%lx",
332 __entry->rw ? "write" : "read",
333 __entry->cr, __entry->val)
334);
335
336#define trace_kvm_cr_read(cr, val) trace_kvm_cr(0, cr, val)
337#define trace_kvm_cr_write(cr, val) trace_kvm_cr(1, cr, val)
338
Gleb Natapov1000ff82009-07-07 16:00:57 +0300339TRACE_EVENT(kvm_pic_set_irq,
340 TP_PROTO(__u8 chip, __u8 pin, __u8 elcr, __u8 imr, bool coalesced),
341 TP_ARGS(chip, pin, elcr, imr, coalesced),
342
343 TP_STRUCT__entry(
344 __field( __u8, chip )
345 __field( __u8, pin )
346 __field( __u8, elcr )
347 __field( __u8, imr )
348 __field( bool, coalesced )
349 ),
350
351 TP_fast_assign(
352 __entry->chip = chip;
353 __entry->pin = pin;
354 __entry->elcr = elcr;
355 __entry->imr = imr;
356 __entry->coalesced = coalesced;
357 ),
358
359 TP_printk("chip %u pin %u (%s%s)%s",
360 __entry->chip, __entry->pin,
361 (__entry->elcr & (1 << __entry->pin)) ? "level":"edge",
362 (__entry->imr & (1 << __entry->pin)) ? "|masked":"",
363 __entry->coalesced ? " (coalesced)" : "")
364);
365
366#define kvm_apic_dst_shorthand \
367 {0x0, "dst"}, \
368 {0x1, "self"}, \
369 {0x2, "all"}, \
370 {0x3, "all-but-self"}
371
372TRACE_EVENT(kvm_apic_ipi,
373 TP_PROTO(__u32 icr_low, __u32 dest_id),
374 TP_ARGS(icr_low, dest_id),
375
376 TP_STRUCT__entry(
377 __field( __u32, icr_low )
378 __field( __u32, dest_id )
379 ),
380
381 TP_fast_assign(
382 __entry->icr_low = icr_low;
383 __entry->dest_id = dest_id;
384 ),
385
386 TP_printk("dst %x vec %u (%s|%s|%s|%s|%s)",
387 __entry->dest_id, (u8)__entry->icr_low,
388 __print_symbolic((__entry->icr_low >> 8 & 0x7),
389 kvm_deliver_mode),
390 (__entry->icr_low & (1<<11)) ? "logical" : "physical",
391 (__entry->icr_low & (1<<14)) ? "assert" : "de-assert",
392 (__entry->icr_low & (1<<15)) ? "level" : "edge",
393 __print_symbolic((__entry->icr_low >> 18 & 0x3),
394 kvm_apic_dst_shorthand))
395);
396
397TRACE_EVENT(kvm_apic_accept_irq,
398 TP_PROTO(__u32 apicid, __u16 dm, __u8 tm, __u8 vec, bool coalesced),
399 TP_ARGS(apicid, dm, tm, vec, coalesced),
400
401 TP_STRUCT__entry(
402 __field( __u32, apicid )
403 __field( __u16, dm )
404 __field( __u8, tm )
405 __field( __u8, vec )
406 __field( bool, coalesced )
407 ),
408
409 TP_fast_assign(
410 __entry->apicid = apicid;
411 __entry->dm = dm;
412 __entry->tm = tm;
413 __entry->vec = vec;
414 __entry->coalesced = coalesced;
415 ),
416
417 TP_printk("apicid %x vec %u (%s|%s)%s",
418 __entry->apicid, __entry->vec,
419 __print_symbolic((__entry->dm >> 8 & 0x7), kvm_deliver_mode),
420 __entry->tm ? "level" : "edge",
421 __entry->coalesced ? " (coalesced)" : "")
422);
423
Joerg Roedel0ac406d2009-10-09 16:08:27 +0200424/*
425 * Tracepoint for nested VMRUN
426 */
427TRACE_EVENT(kvm_nested_vmrun,
428 TP_PROTO(__u64 rip, __u64 vmcb, __u64 nested_rip, __u32 int_ctl,
429 __u32 event_inj, bool npt),
430 TP_ARGS(rip, vmcb, nested_rip, int_ctl, event_inj, npt),
431
432 TP_STRUCT__entry(
433 __field( __u64, rip )
434 __field( __u64, vmcb )
435 __field( __u64, nested_rip )
436 __field( __u32, int_ctl )
437 __field( __u32, event_inj )
438 __field( bool, npt )
439 ),
440
441 TP_fast_assign(
442 __entry->rip = rip;
443 __entry->vmcb = vmcb;
444 __entry->nested_rip = nested_rip;
445 __entry->int_ctl = int_ctl;
446 __entry->event_inj = event_inj;
447 __entry->npt = npt;
448 ),
449
450 TP_printk("rip: 0x%016llx vmcb: 0x%016llx nrip: 0x%016llx int_ctl: 0x%08x "
Joerg Roedel052ce622010-02-19 16:23:09 +0100451 "event_inj: 0x%08x npt: %s",
Joerg Roedel0ac406d2009-10-09 16:08:27 +0200452 __entry->rip, __entry->vmcb, __entry->nested_rip,
453 __entry->int_ctl, __entry->event_inj,
454 __entry->npt ? "on" : "off")
455);
456
Joerg Roedel2e554e82010-02-24 18:59:14 +0100457TRACE_EVENT(kvm_nested_intercepts,
458 TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u64 intercept),
459 TP_ARGS(cr_read, cr_write, exceptions, intercept),
460
461 TP_STRUCT__entry(
462 __field( __u16, cr_read )
463 __field( __u16, cr_write )
464 __field( __u32, exceptions )
465 __field( __u64, intercept )
466 ),
467
468 TP_fast_assign(
469 __entry->cr_read = cr_read;
470 __entry->cr_write = cr_write;
471 __entry->exceptions = exceptions;
472 __entry->intercept = intercept;
473 ),
474
475 TP_printk("cr_read: %04x cr_write: %04x excp: %08x intercept: %016llx",
476 __entry->cr_read, __entry->cr_write, __entry->exceptions,
477 __entry->intercept)
478);
Joerg Roedeld8cabdd2009-10-09 16:08:28 +0200479/*
480 * Tracepoint for #VMEXIT while nested
481 */
482TRACE_EVENT(kvm_nested_vmexit,
483 TP_PROTO(__u64 rip, __u32 exit_code,
484 __u64 exit_info1, __u64 exit_info2,
485 __u32 exit_int_info, __u32 exit_int_info_err),
486 TP_ARGS(rip, exit_code, exit_info1, exit_info2,
487 exit_int_info, exit_int_info_err),
488
489 TP_STRUCT__entry(
490 __field( __u64, rip )
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->rip = rip;
500 __entry->exit_code = exit_code;
501 __entry->exit_info1 = exit_info1;
502 __entry->exit_info2 = exit_info2;
503 __entry->exit_int_info = exit_int_info;
504 __entry->exit_int_info_err = exit_int_info_err;
505 ),
506 TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx "
Joerg Roedel052ce622010-02-19 16:23:09 +0100507 "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
Joerg Roedeld8cabdd2009-10-09 16:08:28 +0200508 __entry->rip,
509 ftrace_print_symbols_seq(p, __entry->exit_code,
510 kvm_x86_ops->exit_reasons_str),
511 __entry->exit_info1, __entry->exit_info2,
512 __entry->exit_int_info, __entry->exit_int_info_err)
513);
514
Joerg Roedel17897f32009-10-09 16:08:29 +0200515/*
516 * Tracepoint for #VMEXIT reinjected to the guest
517 */
518TRACE_EVENT(kvm_nested_vmexit_inject,
519 TP_PROTO(__u32 exit_code,
520 __u64 exit_info1, __u64 exit_info2,
521 __u32 exit_int_info, __u32 exit_int_info_err),
522 TP_ARGS(exit_code, exit_info1, exit_info2,
523 exit_int_info, exit_int_info_err),
524
525 TP_STRUCT__entry(
526 __field( __u32, exit_code )
527 __field( __u64, exit_info1 )
528 __field( __u64, exit_info2 )
529 __field( __u32, exit_int_info )
530 __field( __u32, exit_int_info_err )
531 ),
532
533 TP_fast_assign(
534 __entry->exit_code = exit_code;
535 __entry->exit_info1 = exit_info1;
536 __entry->exit_info2 = exit_info2;
537 __entry->exit_int_info = exit_int_info;
538 __entry->exit_int_info_err = exit_int_info_err;
539 ),
540
541 TP_printk("reason: %s ext_inf1: 0x%016llx "
Joerg Roedel052ce622010-02-19 16:23:09 +0100542 "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
Joerg Roedel17897f32009-10-09 16:08:29 +0200543 ftrace_print_symbols_seq(p, __entry->exit_code,
544 kvm_x86_ops->exit_reasons_str),
545 __entry->exit_info1, __entry->exit_info2,
546 __entry->exit_int_info, __entry->exit_int_info_err)
547);
Joerg Roedel236649d2009-10-09 16:08:30 +0200548
549/*
550 * Tracepoint for nested #vmexit because of interrupt pending
551 */
552TRACE_EVENT(kvm_nested_intr_vmexit,
553 TP_PROTO(__u64 rip),
554 TP_ARGS(rip),
555
556 TP_STRUCT__entry(
557 __field( __u64, rip )
558 ),
559
560 TP_fast_assign(
561 __entry->rip = rip
562 ),
563
Joerg Roedel052ce622010-02-19 16:23:09 +0100564 TP_printk("rip: 0x%016llx", __entry->rip)
Joerg Roedel236649d2009-10-09 16:08:30 +0200565);
Joerg Roedelec1ff792009-10-09 16:08:31 +0200566
567/*
568 * Tracepoint for nested #vmexit because of interrupt pending
569 */
570TRACE_EVENT(kvm_invlpga,
571 TP_PROTO(__u64 rip, int asid, u64 address),
572 TP_ARGS(rip, asid, address),
573
574 TP_STRUCT__entry(
575 __field( __u64, rip )
576 __field( int, asid )
577 __field( __u64, address )
578 ),
579
580 TP_fast_assign(
581 __entry->rip = rip;
582 __entry->asid = asid;
583 __entry->address = address;
584 ),
585
Joerg Roedel052ce622010-02-19 16:23:09 +0100586 TP_printk("rip: 0x%016llx asid: %d address: 0x%016llx",
Joerg Roedelec1ff792009-10-09 16:08:31 +0200587 __entry->rip, __entry->asid, __entry->address)
588);
Joerg Roedel532a46b2009-10-09 16:08:32 +0200589
590/*
591 * Tracepoint for nested #vmexit because of interrupt pending
592 */
593TRACE_EVENT(kvm_skinit,
594 TP_PROTO(__u64 rip, __u32 slb),
595 TP_ARGS(rip, slb),
596
597 TP_STRUCT__entry(
598 __field( __u64, rip )
599 __field( __u32, slb )
600 ),
601
602 TP_fast_assign(
603 __entry->rip = rip;
604 __entry->slb = slb;
605 ),
606
Joerg Roedel052ce622010-02-19 16:23:09 +0100607 TP_printk("rip: 0x%016llx slb: 0x%08x",
Joerg Roedel532a46b2009-10-09 16:08:32 +0200608 __entry->rip, __entry->slb)
609);
610
Avi Kivitye46479f2010-04-11 13:05:16 +0300611#define __print_insn(insn, ilen) ({ \
612 int i; \
613 const char *ret = p->buffer + p->len; \
614 \
615 for (i = 0; i < ilen; ++i) \
616 trace_seq_printf(p, " %02x", insn[i]); \
617 trace_seq_printf(p, "%c", 0); \
618 ret; \
619 })
620
621#define KVM_EMUL_INSN_F_CR0_PE (1 << 0)
622#define KVM_EMUL_INSN_F_EFL_VM (1 << 1)
623#define KVM_EMUL_INSN_F_CS_D (1 << 2)
624#define KVM_EMUL_INSN_F_CS_L (1 << 3)
625
626#define kvm_trace_symbol_emul_flags \
627 { 0, "real" }, \
628 { KVM_EMUL_INSN_F_CR0_PE \
629 | KVM_EMUL_INSN_F_EFL_VM, "vm16" }, \
630 { KVM_EMUL_INSN_F_CR0_PE, "prot16" }, \
631 { KVM_EMUL_INSN_F_CR0_PE \
632 | KVM_EMUL_INSN_F_CS_D, "prot32" }, \
633 { KVM_EMUL_INSN_F_CR0_PE \
634 | KVM_EMUL_INSN_F_CS_L, "prot64" }
635
636#define kei_decode_mode(mode) ({ \
637 u8 flags = 0xff; \
638 switch (mode) { \
639 case X86EMUL_MODE_REAL: \
640 flags = 0; \
641 break; \
642 case X86EMUL_MODE_VM86: \
643 flags = KVM_EMUL_INSN_F_EFL_VM; \
644 break; \
645 case X86EMUL_MODE_PROT16: \
646 flags = KVM_EMUL_INSN_F_CR0_PE; \
647 break; \
648 case X86EMUL_MODE_PROT32: \
649 flags = KVM_EMUL_INSN_F_CR0_PE \
650 | KVM_EMUL_INSN_F_CS_D; \
651 break; \
652 case X86EMUL_MODE_PROT64: \
653 flags = KVM_EMUL_INSN_F_CR0_PE \
654 | KVM_EMUL_INSN_F_CS_L; \
655 break; \
656 } \
657 flags; \
658 })
659
660TRACE_EVENT(kvm_emulate_insn,
661 TP_PROTO(struct kvm_vcpu *vcpu, __u8 failed),
662 TP_ARGS(vcpu, failed),
663
664 TP_STRUCT__entry(
665 __field( __u64, rip )
666 __field( __u32, csbase )
667 __field( __u8, len )
668 __array( __u8, insn, 15 )
669 __field( __u8, flags )
670 __field( __u8, failed )
671 ),
672
673 TP_fast_assign(
674 __entry->rip = vcpu->arch.emulate_ctxt.decode.fetch.start;
675 __entry->csbase = kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS);
676 __entry->len = vcpu->arch.emulate_ctxt.decode.eip
677 - vcpu->arch.emulate_ctxt.decode.fetch.start;
678 memcpy(__entry->insn,
679 vcpu->arch.emulate_ctxt.decode.fetch.data,
680 15);
681 __entry->flags = kei_decode_mode(vcpu->arch.emulate_ctxt.mode);
682 __entry->failed = failed;
683 ),
684
685 TP_printk("%x:%llx:%s (%s)%s",
686 __entry->csbase, __entry->rip,
687 __print_insn(__entry->insn, __entry->len),
688 __print_symbolic(__entry->flags,
689 kvm_trace_symbol_emul_flags),
690 __entry->failed ? " failed" : ""
691 )
692 );
693
694#define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0)
695#define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1)
696
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300697#endif /* _TRACE_KVM_H */
698
Xiao Guangrong2ed152a2010-03-10 19:00:43 +0800699#undef TRACE_INCLUDE_PATH
700#define TRACE_INCLUDE_PATH arch/x86/kvm
701#undef TRACE_INCLUDE_FILE
702#define TRACE_INCLUDE_FILE trace
703
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300704/* This part must be outside protection */
705#include <trace/define_trace.h>