blob: e850a7d332be32a0f8c736bc0dced26b213b4b2d [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>
Stefan Hajnoczi0d460ff2011-07-22 12:46:53 +01005#include <asm/vmx.h>
6#include <asm/svm.h>
Marcelo Tosattid8281992012-11-27 23:29:01 -02007#include <asm/clocksource.h>
Marcelo Tosatti229456f2009-06-17 09:22:14 -03008
9#undef TRACE_SYSTEM
10#define TRACE_SYSTEM kvm
Marcelo Tosatti229456f2009-06-17 09:22:14 -030011
12/*
13 * Tracepoint for guest mode entry.
14 */
15TRACE_EVENT(kvm_entry,
16 TP_PROTO(unsigned int vcpu_id),
17 TP_ARGS(vcpu_id),
18
19 TP_STRUCT__entry(
20 __field( unsigned int, vcpu_id )
21 ),
22
23 TP_fast_assign(
24 __entry->vcpu_id = vcpu_id;
25 ),
26
27 TP_printk("vcpu %u", __entry->vcpu_id)
28);
29
30/*
31 * Tracepoint for hypercall.
32 */
33TRACE_EVENT(kvm_hypercall,
34 TP_PROTO(unsigned long nr, unsigned long a0, unsigned long a1,
35 unsigned long a2, unsigned long a3),
36 TP_ARGS(nr, a0, a1, a2, a3),
37
38 TP_STRUCT__entry(
39 __field( unsigned long, nr )
40 __field( unsigned long, a0 )
41 __field( unsigned long, a1 )
42 __field( unsigned long, a2 )
43 __field( unsigned long, a3 )
44 ),
45
46 TP_fast_assign(
47 __entry->nr = nr;
48 __entry->a0 = a0;
49 __entry->a1 = a1;
50 __entry->a2 = a2;
51 __entry->a3 = a3;
52 ),
53
54 TP_printk("nr 0x%lx a0 0x%lx a1 0x%lx a2 0x%lx a3 0x%lx",
55 __entry->nr, __entry->a0, __entry->a1, __entry->a2,
56 __entry->a3)
57);
58
59/*
Gleb Natapov55cd8e52010-01-17 15:51:22 +020060 * Tracepoint for hypercall.
61 */
62TRACE_EVENT(kvm_hv_hypercall,
63 TP_PROTO(__u16 code, bool fast, __u16 rep_cnt, __u16 rep_idx,
64 __u64 ingpa, __u64 outgpa),
65 TP_ARGS(code, fast, rep_cnt, rep_idx, ingpa, outgpa),
66
67 TP_STRUCT__entry(
Gleb Natapov55cd8e52010-01-17 15:51:22 +020068 __field( __u16, rep_cnt )
69 __field( __u16, rep_idx )
70 __field( __u64, ingpa )
71 __field( __u64, outgpa )
David Sharpd5bf2ff2010-12-03 16:13:21 -080072 __field( __u16, code )
73 __field( bool, fast )
Gleb Natapov55cd8e52010-01-17 15:51:22 +020074 ),
75
76 TP_fast_assign(
Gleb Natapov55cd8e52010-01-17 15:51:22 +020077 __entry->rep_cnt = rep_cnt;
78 __entry->rep_idx = rep_idx;
79 __entry->ingpa = ingpa;
80 __entry->outgpa = outgpa;
David Sharpd5bf2ff2010-12-03 16:13:21 -080081 __entry->code = code;
82 __entry->fast = fast;
Gleb Natapov55cd8e52010-01-17 15:51:22 +020083 ),
84
85 TP_printk("code 0x%x %s cnt 0x%x idx 0x%x in 0x%llx out 0x%llx",
86 __entry->code, __entry->fast ? "fast" : "slow",
87 __entry->rep_cnt, __entry->rep_idx, __entry->ingpa,
88 __entry->outgpa)
89);
90
91/*
Marcelo Tosatti229456f2009-06-17 09:22:14 -030092 * Tracepoint for PIO.
93 */
Ulrich Obergfell11719032014-05-02 17:57:47 +020094
95#define KVM_PIO_IN 0
96#define KVM_PIO_OUT 1
97
Marcelo Tosatti229456f2009-06-17 09:22:14 -030098TRACE_EVENT(kvm_pio,
99 TP_PROTO(unsigned int rw, unsigned int port, unsigned int size,
Ulrich Obergfell11719032014-05-02 17:57:47 +0200100 unsigned int count, void *data),
101 TP_ARGS(rw, port, size, count, data),
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300102
103 TP_STRUCT__entry(
104 __field( unsigned int, rw )
105 __field( unsigned int, port )
106 __field( unsigned int, size )
107 __field( unsigned int, count )
Ulrich Obergfell11719032014-05-02 17:57:47 +0200108 __field( unsigned int, val )
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300109 ),
110
111 TP_fast_assign(
112 __entry->rw = rw;
113 __entry->port = port;
114 __entry->size = size;
115 __entry->count = count;
Ulrich Obergfell11719032014-05-02 17:57:47 +0200116 if (size == 1)
117 __entry->val = *(unsigned char *)data;
118 else if (size == 2)
119 __entry->val = *(unsigned short *)data;
120 else
121 __entry->val = *(unsigned int *)data;
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300122 ),
123
Ulrich Obergfell11719032014-05-02 17:57:47 +0200124 TP_printk("pio_%s at 0x%x size %d count %d val 0x%x %s",
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300125 __entry->rw ? "write" : "read",
Ulrich Obergfell11719032014-05-02 17:57:47 +0200126 __entry->port, __entry->size, __entry->count, __entry->val,
127 __entry->count > 1 ? "(...)" : "")
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300128);
129
130/*
131 * Tracepoint for cpuid.
132 */
133TRACE_EVENT(kvm_cpuid,
134 TP_PROTO(unsigned int function, unsigned long rax, unsigned long rbx,
135 unsigned long rcx, unsigned long rdx),
136 TP_ARGS(function, rax, rbx, rcx, rdx),
137
138 TP_STRUCT__entry(
139 __field( unsigned int, function )
140 __field( unsigned long, rax )
141 __field( unsigned long, rbx )
142 __field( unsigned long, rcx )
143 __field( unsigned long, rdx )
144 ),
145
146 TP_fast_assign(
147 __entry->function = function;
148 __entry->rax = rax;
149 __entry->rbx = rbx;
150 __entry->rcx = rcx;
151 __entry->rdx = rdx;
152 ),
153
154 TP_printk("func %x rax %lx rbx %lx rcx %lx rdx %lx",
155 __entry->function, __entry->rax,
156 __entry->rbx, __entry->rcx, __entry->rdx)
157);
158
Avi Kivitycb247722009-07-01 18:25:44 +0300159#define AREG(x) { APIC_##x, "APIC_" #x }
160
161#define kvm_trace_symbol_apic \
162 AREG(ID), AREG(LVR), AREG(TASKPRI), AREG(ARBPRI), AREG(PROCPRI), \
163 AREG(EOI), AREG(RRR), AREG(LDR), AREG(DFR), AREG(SPIV), AREG(ISR), \
164 AREG(TMR), AREG(IRR), AREG(ESR), AREG(ICR), AREG(ICR2), AREG(LVTT), \
165 AREG(LVTTHMR), AREG(LVTPC), AREG(LVT0), AREG(LVT1), AREG(LVTERR), \
166 AREG(TMICT), AREG(TMCCT), AREG(TDCR), AREG(SELF_IPI), AREG(EFEAT), \
167 AREG(ECTRL)
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300168/*
169 * Tracepoint for apic access.
170 */
171TRACE_EVENT(kvm_apic,
172 TP_PROTO(unsigned int rw, unsigned int reg, unsigned int val),
173 TP_ARGS(rw, reg, val),
174
175 TP_STRUCT__entry(
176 __field( unsigned int, rw )
177 __field( unsigned int, reg )
178 __field( unsigned int, val )
179 ),
180
181 TP_fast_assign(
182 __entry->rw = rw;
183 __entry->reg = reg;
184 __entry->val = val;
185 ),
186
Avi Kivitycb247722009-07-01 18:25:44 +0300187 TP_printk("apic_%s %s = 0x%x",
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300188 __entry->rw ? "write" : "read",
Avi Kivitycb247722009-07-01 18:25:44 +0300189 __print_symbolic(__entry->reg, kvm_trace_symbol_apic),
190 __entry->val)
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300191);
192
193#define trace_kvm_apic_read(reg, val) trace_kvm_apic(0, reg, val)
194#define trace_kvm_apic_write(reg, val) trace_kvm_apic(1, reg, val)
195
Avi Kivityaa179112010-11-17 18:44:19 +0200196#define KVM_ISA_VMX 1
197#define KVM_ISA_SVM 2
198
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300199/*
200 * Tracepoint for kvm guest exit:
201 */
202TRACE_EVENT(kvm_exit,
Avi Kivityaa179112010-11-17 18:44:19 +0200203 TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa),
204 TP_ARGS(exit_reason, vcpu, isa),
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300205
206 TP_STRUCT__entry(
207 __field( unsigned int, exit_reason )
208 __field( unsigned long, guest_rip )
Avi Kivityaa179112010-11-17 18:44:19 +0200209 __field( u32, isa )
Avi Kivity586f9602010-11-18 13:09:54 +0200210 __field( u64, info1 )
211 __field( u64, info2 )
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300212 ),
213
214 TP_fast_assign(
215 __entry->exit_reason = exit_reason;
Avi Kivity5bfd8b52010-03-11 10:50:44 +0200216 __entry->guest_rip = kvm_rip_read(vcpu);
Avi Kivityaa179112010-11-17 18:44:19 +0200217 __entry->isa = isa;
Avi Kivity586f9602010-11-18 13:09:54 +0200218 kvm_x86_ops->get_exit_info(vcpu, &__entry->info1,
219 &__entry->info2);
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300220 ),
221
Avi Kivity586f9602010-11-18 13:09:54 +0200222 TP_printk("reason %s rip 0x%lx info %llx %llx",
Stefan Hajnoczi0d460ff2011-07-22 12:46:53 +0100223 (__entry->isa == KVM_ISA_VMX) ?
224 __print_symbolic(__entry->exit_reason, VMX_EXIT_REASONS) :
225 __print_symbolic(__entry->exit_reason, SVM_EXIT_REASONS),
Avi Kivity586f9602010-11-18 13:09:54 +0200226 __entry->guest_rip, __entry->info1, __entry->info2)
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300227);
228
229/*
230 * Tracepoint for kvm interrupt injection:
231 */
232TRACE_EVENT(kvm_inj_virq,
233 TP_PROTO(unsigned int irq),
234 TP_ARGS(irq),
235
236 TP_STRUCT__entry(
237 __field( unsigned int, irq )
238 ),
239
240 TP_fast_assign(
241 __entry->irq = irq;
242 ),
243
244 TP_printk("irq %u", __entry->irq)
245);
246
Avi Kivity5c1c85d2010-03-11 13:01:59 +0200247#define EXS(x) { x##_VECTOR, "#" #x }
248
249#define kvm_trace_sym_exc \
250 EXS(DE), EXS(DB), EXS(BP), EXS(OF), EXS(BR), EXS(UD), EXS(NM), \
251 EXS(DF), EXS(TS), EXS(NP), EXS(SS), EXS(GP), EXS(PF), \
252 EXS(MF), EXS(MC)
253
254/*
255 * Tracepoint for kvm interrupt injection:
256 */
257TRACE_EVENT(kvm_inj_exception,
258 TP_PROTO(unsigned exception, bool has_error, unsigned error_code),
259 TP_ARGS(exception, has_error, error_code),
260
261 TP_STRUCT__entry(
262 __field( u8, exception )
263 __field( u8, has_error )
264 __field( u32, error_code )
265 ),
266
267 TP_fast_assign(
268 __entry->exception = exception;
269 __entry->has_error = has_error;
270 __entry->error_code = error_code;
271 ),
272
273 TP_printk("%s (0x%x)",
274 __print_symbolic(__entry->exception, kvm_trace_sym_exc),
275 /* FIXME: don't print error_code if not present */
276 __entry->has_error ? __entry->error_code : 0)
277);
278
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300279/*
280 * Tracepoint for page fault.
281 */
282TRACE_EVENT(kvm_page_fault,
283 TP_PROTO(unsigned long fault_address, unsigned int error_code),
284 TP_ARGS(fault_address, error_code),
285
286 TP_STRUCT__entry(
287 __field( unsigned long, fault_address )
288 __field( unsigned int, error_code )
289 ),
290
291 TP_fast_assign(
292 __entry->fault_address = fault_address;
293 __entry->error_code = error_code;
294 ),
295
296 TP_printk("address %lx error_code %x",
297 __entry->fault_address, __entry->error_code)
298);
299
300/*
301 * Tracepoint for guest MSR access.
302 */
303TRACE_EVENT(kvm_msr,
Avi Kivity59200272010-01-25 19:47:02 +0200304 TP_PROTO(unsigned write, u32 ecx, u64 data, bool exception),
305 TP_ARGS(write, ecx, data, exception),
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300306
307 TP_STRUCT__entry(
Avi Kivity6e7d1522010-01-25 19:36:03 +0200308 __field( unsigned, write )
309 __field( u32, ecx )
310 __field( u64, data )
Avi Kivity59200272010-01-25 19:47:02 +0200311 __field( u8, exception )
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300312 ),
313
314 TP_fast_assign(
Avi Kivity6e7d1522010-01-25 19:36:03 +0200315 __entry->write = write;
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300316 __entry->ecx = ecx;
317 __entry->data = data;
Avi Kivity59200272010-01-25 19:47:02 +0200318 __entry->exception = exception;
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300319 ),
320
Avi Kivity59200272010-01-25 19:47:02 +0200321 TP_printk("msr_%s %x = 0x%llx%s",
Avi Kivity6e7d1522010-01-25 19:36:03 +0200322 __entry->write ? "write" : "read",
Avi Kivity59200272010-01-25 19:47:02 +0200323 __entry->ecx, __entry->data,
324 __entry->exception ? " (#GP)" : "")
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300325);
326
Avi Kivity59200272010-01-25 19:47:02 +0200327#define trace_kvm_msr_read(ecx, data) trace_kvm_msr(0, ecx, data, false)
328#define trace_kvm_msr_write(ecx, data) trace_kvm_msr(1, ecx, data, false)
329#define trace_kvm_msr_read_ex(ecx) trace_kvm_msr(0, ecx, 0, true)
330#define trace_kvm_msr_write_ex(ecx, data) trace_kvm_msr(1, ecx, data, true)
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300331
332/*
333 * Tracepoint for guest CR access.
334 */
335TRACE_EVENT(kvm_cr,
336 TP_PROTO(unsigned int rw, unsigned int cr, unsigned long val),
337 TP_ARGS(rw, cr, val),
338
339 TP_STRUCT__entry(
340 __field( unsigned int, rw )
341 __field( unsigned int, cr )
342 __field( unsigned long, val )
343 ),
344
345 TP_fast_assign(
346 __entry->rw = rw;
347 __entry->cr = cr;
348 __entry->val = val;
349 ),
350
351 TP_printk("cr_%s %x = 0x%lx",
352 __entry->rw ? "write" : "read",
353 __entry->cr, __entry->val)
354);
355
356#define trace_kvm_cr_read(cr, val) trace_kvm_cr(0, cr, val)
357#define trace_kvm_cr_write(cr, val) trace_kvm_cr(1, cr, val)
358
Gleb Natapov1000ff82009-07-07 16:00:57 +0300359TRACE_EVENT(kvm_pic_set_irq,
360 TP_PROTO(__u8 chip, __u8 pin, __u8 elcr, __u8 imr, bool coalesced),
361 TP_ARGS(chip, pin, elcr, imr, coalesced),
362
363 TP_STRUCT__entry(
364 __field( __u8, chip )
365 __field( __u8, pin )
366 __field( __u8, elcr )
367 __field( __u8, imr )
368 __field( bool, coalesced )
369 ),
370
371 TP_fast_assign(
372 __entry->chip = chip;
373 __entry->pin = pin;
374 __entry->elcr = elcr;
375 __entry->imr = imr;
376 __entry->coalesced = coalesced;
377 ),
378
379 TP_printk("chip %u pin %u (%s%s)%s",
380 __entry->chip, __entry->pin,
381 (__entry->elcr & (1 << __entry->pin)) ? "level":"edge",
382 (__entry->imr & (1 << __entry->pin)) ? "|masked":"",
383 __entry->coalesced ? " (coalesced)" : "")
384);
385
386#define kvm_apic_dst_shorthand \
387 {0x0, "dst"}, \
388 {0x1, "self"}, \
389 {0x2, "all"}, \
390 {0x3, "all-but-self"}
391
392TRACE_EVENT(kvm_apic_ipi,
393 TP_PROTO(__u32 icr_low, __u32 dest_id),
394 TP_ARGS(icr_low, dest_id),
395
396 TP_STRUCT__entry(
397 __field( __u32, icr_low )
398 __field( __u32, dest_id )
399 ),
400
401 TP_fast_assign(
402 __entry->icr_low = icr_low;
403 __entry->dest_id = dest_id;
404 ),
405
406 TP_printk("dst %x vec %u (%s|%s|%s|%s|%s)",
407 __entry->dest_id, (u8)__entry->icr_low,
408 __print_symbolic((__entry->icr_low >> 8 & 0x7),
409 kvm_deliver_mode),
410 (__entry->icr_low & (1<<11)) ? "logical" : "physical",
411 (__entry->icr_low & (1<<14)) ? "assert" : "de-assert",
412 (__entry->icr_low & (1<<15)) ? "level" : "edge",
413 __print_symbolic((__entry->icr_low >> 18 & 0x3),
414 kvm_apic_dst_shorthand))
415);
416
417TRACE_EVENT(kvm_apic_accept_irq,
418 TP_PROTO(__u32 apicid, __u16 dm, __u8 tm, __u8 vec, bool coalesced),
419 TP_ARGS(apicid, dm, tm, vec, coalesced),
420
421 TP_STRUCT__entry(
422 __field( __u32, apicid )
423 __field( __u16, dm )
424 __field( __u8, tm )
425 __field( __u8, vec )
426 __field( bool, coalesced )
427 ),
428
429 TP_fast_assign(
430 __entry->apicid = apicid;
431 __entry->dm = dm;
432 __entry->tm = tm;
433 __entry->vec = vec;
434 __entry->coalesced = coalesced;
435 ),
436
437 TP_printk("apicid %x vec %u (%s|%s)%s",
438 __entry->apicid, __entry->vec,
439 __print_symbolic((__entry->dm >> 8 & 0x7), kvm_deliver_mode),
440 __entry->tm ? "level" : "edge",
441 __entry->coalesced ? " (coalesced)" : "")
442);
443
Michael S. Tsirkinae7a2a32012-06-24 19:25:07 +0300444TRACE_EVENT(kvm_eoi,
445 TP_PROTO(struct kvm_lapic *apic, int vector),
446 TP_ARGS(apic, vector),
447
448 TP_STRUCT__entry(
449 __field( __u32, apicid )
450 __field( int, vector )
451 ),
452
453 TP_fast_assign(
454 __entry->apicid = apic->vcpu->vcpu_id;
455 __entry->vector = vector;
456 ),
457
458 TP_printk("apicid %x vector %d", __entry->apicid, __entry->vector)
459);
460
461TRACE_EVENT(kvm_pv_eoi,
462 TP_PROTO(struct kvm_lapic *apic, int vector),
463 TP_ARGS(apic, vector),
464
465 TP_STRUCT__entry(
466 __field( __u32, apicid )
467 __field( int, vector )
468 ),
469
470 TP_fast_assign(
471 __entry->apicid = apic->vcpu->vcpu_id;
472 __entry->vector = vector;
473 ),
474
475 TP_printk("apicid %x vector %d", __entry->apicid, __entry->vector)
476);
477
Joerg Roedel0ac406d2009-10-09 16:08:27 +0200478/*
479 * Tracepoint for nested VMRUN
480 */
481TRACE_EVENT(kvm_nested_vmrun,
482 TP_PROTO(__u64 rip, __u64 vmcb, __u64 nested_rip, __u32 int_ctl,
483 __u32 event_inj, bool npt),
484 TP_ARGS(rip, vmcb, nested_rip, int_ctl, event_inj, npt),
485
486 TP_STRUCT__entry(
487 __field( __u64, rip )
488 __field( __u64, vmcb )
489 __field( __u64, nested_rip )
490 __field( __u32, int_ctl )
491 __field( __u32, event_inj )
492 __field( bool, npt )
493 ),
494
495 TP_fast_assign(
496 __entry->rip = rip;
497 __entry->vmcb = vmcb;
498 __entry->nested_rip = nested_rip;
499 __entry->int_ctl = int_ctl;
500 __entry->event_inj = event_inj;
501 __entry->npt = npt;
502 ),
503
504 TP_printk("rip: 0x%016llx vmcb: 0x%016llx nrip: 0x%016llx int_ctl: 0x%08x "
Joerg Roedel052ce622010-02-19 16:23:09 +0100505 "event_inj: 0x%08x npt: %s",
Joerg Roedel0ac406d2009-10-09 16:08:27 +0200506 __entry->rip, __entry->vmcb, __entry->nested_rip,
507 __entry->int_ctl, __entry->event_inj,
508 __entry->npt ? "on" : "off")
509);
510
Joerg Roedel2e554e82010-02-24 18:59:14 +0100511TRACE_EVENT(kvm_nested_intercepts,
512 TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u64 intercept),
513 TP_ARGS(cr_read, cr_write, exceptions, intercept),
514
515 TP_STRUCT__entry(
516 __field( __u16, cr_read )
517 __field( __u16, cr_write )
518 __field( __u32, exceptions )
519 __field( __u64, intercept )
520 ),
521
522 TP_fast_assign(
523 __entry->cr_read = cr_read;
524 __entry->cr_write = cr_write;
525 __entry->exceptions = exceptions;
526 __entry->intercept = intercept;
527 ),
528
529 TP_printk("cr_read: %04x cr_write: %04x excp: %08x intercept: %016llx",
530 __entry->cr_read, __entry->cr_write, __entry->exceptions,
531 __entry->intercept)
532);
Joerg Roedeld8cabdd2009-10-09 16:08:28 +0200533/*
534 * Tracepoint for #VMEXIT while nested
535 */
536TRACE_EVENT(kvm_nested_vmexit,
537 TP_PROTO(__u64 rip, __u32 exit_code,
538 __u64 exit_info1, __u64 exit_info2,
Stefan Hajnoczie097e5f2011-07-22 12:46:52 +0100539 __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
Joerg Roedeld8cabdd2009-10-09 16:08:28 +0200540 TP_ARGS(rip, exit_code, exit_info1, exit_info2,
Stefan Hajnoczie097e5f2011-07-22 12:46:52 +0100541 exit_int_info, exit_int_info_err, isa),
Joerg Roedeld8cabdd2009-10-09 16:08:28 +0200542
543 TP_STRUCT__entry(
544 __field( __u64, rip )
545 __field( __u32, exit_code )
546 __field( __u64, exit_info1 )
547 __field( __u64, exit_info2 )
548 __field( __u32, exit_int_info )
549 __field( __u32, exit_int_info_err )
Stefan Hajnoczie097e5f2011-07-22 12:46:52 +0100550 __field( __u32, isa )
Joerg Roedeld8cabdd2009-10-09 16:08:28 +0200551 ),
552
553 TP_fast_assign(
554 __entry->rip = rip;
555 __entry->exit_code = exit_code;
556 __entry->exit_info1 = exit_info1;
557 __entry->exit_info2 = exit_info2;
558 __entry->exit_int_info = exit_int_info;
559 __entry->exit_int_info_err = exit_int_info_err;
Stefan Hajnoczie097e5f2011-07-22 12:46:52 +0100560 __entry->isa = isa;
Joerg Roedeld8cabdd2009-10-09 16:08:28 +0200561 ),
562 TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx "
Joerg Roedel052ce622010-02-19 16:23:09 +0100563 "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
Joerg Roedeld8cabdd2009-10-09 16:08:28 +0200564 __entry->rip,
Stefan Hajnoczi0d460ff2011-07-22 12:46:53 +0100565 (__entry->isa == KVM_ISA_VMX) ?
566 __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
567 __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
Joerg Roedeld8cabdd2009-10-09 16:08:28 +0200568 __entry->exit_info1, __entry->exit_info2,
569 __entry->exit_int_info, __entry->exit_int_info_err)
570);
571
Joerg Roedel17897f32009-10-09 16:08:29 +0200572/*
573 * Tracepoint for #VMEXIT reinjected to the guest
574 */
575TRACE_EVENT(kvm_nested_vmexit_inject,
576 TP_PROTO(__u32 exit_code,
577 __u64 exit_info1, __u64 exit_info2,
Stefan Hajnoczie097e5f2011-07-22 12:46:52 +0100578 __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
Joerg Roedel17897f32009-10-09 16:08:29 +0200579 TP_ARGS(exit_code, exit_info1, exit_info2,
Stefan Hajnoczie097e5f2011-07-22 12:46:52 +0100580 exit_int_info, exit_int_info_err, isa),
Joerg Roedel17897f32009-10-09 16:08:29 +0200581
582 TP_STRUCT__entry(
583 __field( __u32, exit_code )
584 __field( __u64, exit_info1 )
585 __field( __u64, exit_info2 )
586 __field( __u32, exit_int_info )
587 __field( __u32, exit_int_info_err )
Stefan Hajnoczie097e5f2011-07-22 12:46:52 +0100588 __field( __u32, isa )
Joerg Roedel17897f32009-10-09 16:08:29 +0200589 ),
590
591 TP_fast_assign(
592 __entry->exit_code = exit_code;
593 __entry->exit_info1 = exit_info1;
594 __entry->exit_info2 = exit_info2;
595 __entry->exit_int_info = exit_int_info;
596 __entry->exit_int_info_err = exit_int_info_err;
Stefan Hajnoczie097e5f2011-07-22 12:46:52 +0100597 __entry->isa = isa;
Joerg Roedel17897f32009-10-09 16:08:29 +0200598 ),
599
600 TP_printk("reason: %s ext_inf1: 0x%016llx "
Joerg Roedel052ce622010-02-19 16:23:09 +0100601 "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
Stefan Hajnoczi0d460ff2011-07-22 12:46:53 +0100602 (__entry->isa == KVM_ISA_VMX) ?
603 __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
604 __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
Joerg Roedel17897f32009-10-09 16:08:29 +0200605 __entry->exit_info1, __entry->exit_info2,
606 __entry->exit_int_info, __entry->exit_int_info_err)
607);
Joerg Roedel236649d2009-10-09 16:08:30 +0200608
609/*
610 * Tracepoint for nested #vmexit because of interrupt pending
611 */
612TRACE_EVENT(kvm_nested_intr_vmexit,
613 TP_PROTO(__u64 rip),
614 TP_ARGS(rip),
615
616 TP_STRUCT__entry(
617 __field( __u64, rip )
618 ),
619
620 TP_fast_assign(
621 __entry->rip = rip
622 ),
623
Joerg Roedel052ce622010-02-19 16:23:09 +0100624 TP_printk("rip: 0x%016llx", __entry->rip)
Joerg Roedel236649d2009-10-09 16:08:30 +0200625);
Joerg Roedelec1ff792009-10-09 16:08:31 +0200626
627/*
628 * Tracepoint for nested #vmexit because of interrupt pending
629 */
630TRACE_EVENT(kvm_invlpga,
631 TP_PROTO(__u64 rip, int asid, u64 address),
632 TP_ARGS(rip, asid, address),
633
634 TP_STRUCT__entry(
635 __field( __u64, rip )
636 __field( int, asid )
637 __field( __u64, address )
638 ),
639
640 TP_fast_assign(
641 __entry->rip = rip;
642 __entry->asid = asid;
643 __entry->address = address;
644 ),
645
Joerg Roedel052ce622010-02-19 16:23:09 +0100646 TP_printk("rip: 0x%016llx asid: %d address: 0x%016llx",
Joerg Roedelec1ff792009-10-09 16:08:31 +0200647 __entry->rip, __entry->asid, __entry->address)
648);
Joerg Roedel532a46b2009-10-09 16:08:32 +0200649
650/*
651 * Tracepoint for nested #vmexit because of interrupt pending
652 */
653TRACE_EVENT(kvm_skinit,
654 TP_PROTO(__u64 rip, __u32 slb),
655 TP_ARGS(rip, slb),
656
657 TP_STRUCT__entry(
658 __field( __u64, rip )
659 __field( __u32, slb )
660 ),
661
662 TP_fast_assign(
663 __entry->rip = rip;
664 __entry->slb = slb;
665 ),
666
Joerg Roedel052ce622010-02-19 16:23:09 +0100667 TP_printk("rip: 0x%016llx slb: 0x%08x",
Joerg Roedel532a46b2009-10-09 16:08:32 +0200668 __entry->rip, __entry->slb)
669);
670
Avi Kivitye46479f2010-04-11 13:05:16 +0300671#define KVM_EMUL_INSN_F_CR0_PE (1 << 0)
672#define KVM_EMUL_INSN_F_EFL_VM (1 << 1)
673#define KVM_EMUL_INSN_F_CS_D (1 << 2)
674#define KVM_EMUL_INSN_F_CS_L (1 << 3)
675
676#define kvm_trace_symbol_emul_flags \
677 { 0, "real" }, \
678 { KVM_EMUL_INSN_F_CR0_PE \
679 | KVM_EMUL_INSN_F_EFL_VM, "vm16" }, \
680 { KVM_EMUL_INSN_F_CR0_PE, "prot16" }, \
681 { KVM_EMUL_INSN_F_CR0_PE \
682 | KVM_EMUL_INSN_F_CS_D, "prot32" }, \
683 { KVM_EMUL_INSN_F_CR0_PE \
684 | KVM_EMUL_INSN_F_CS_L, "prot64" }
685
686#define kei_decode_mode(mode) ({ \
687 u8 flags = 0xff; \
688 switch (mode) { \
689 case X86EMUL_MODE_REAL: \
690 flags = 0; \
691 break; \
692 case X86EMUL_MODE_VM86: \
693 flags = KVM_EMUL_INSN_F_EFL_VM; \
694 break; \
695 case X86EMUL_MODE_PROT16: \
696 flags = KVM_EMUL_INSN_F_CR0_PE; \
697 break; \
698 case X86EMUL_MODE_PROT32: \
699 flags = KVM_EMUL_INSN_F_CR0_PE \
700 | KVM_EMUL_INSN_F_CS_D; \
701 break; \
702 case X86EMUL_MODE_PROT64: \
703 flags = KVM_EMUL_INSN_F_CR0_PE \
704 | KVM_EMUL_INSN_F_CS_L; \
705 break; \
706 } \
707 flags; \
708 })
709
710TRACE_EVENT(kvm_emulate_insn,
711 TP_PROTO(struct kvm_vcpu *vcpu, __u8 failed),
712 TP_ARGS(vcpu, failed),
713
714 TP_STRUCT__entry(
715 __field( __u64, rip )
716 __field( __u32, csbase )
717 __field( __u8, len )
718 __array( __u8, insn, 15 )
719 __field( __u8, flags )
720 __field( __u8, failed )
721 ),
722
723 TP_fast_assign(
Avi Kivitye46479f2010-04-11 13:05:16 +0300724 __entry->csbase = kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS);
Paolo Bonzini17052f12014-05-06 16:33:01 +0200725 __entry->len = vcpu->arch.emulate_ctxt.fetch.ptr
726 - vcpu->arch.emulate_ctxt.fetch.data;
727 __entry->rip = vcpu->arch.emulate_ctxt._eip - __entry->len;
Avi Kivitye46479f2010-04-11 13:05:16 +0300728 memcpy(__entry->insn,
Avi Kivity9dac77f2011-06-01 15:34:25 +0300729 vcpu->arch.emulate_ctxt.fetch.data,
Avi Kivitye46479f2010-04-11 13:05:16 +0300730 15);
731 __entry->flags = kei_decode_mode(vcpu->arch.emulate_ctxt.mode);
732 __entry->failed = failed;
733 ),
734
735 TP_printk("%x:%llx:%s (%s)%s",
736 __entry->csbase, __entry->rip,
Namhyung Kimb102f1d2012-06-27 09:41:39 +0900737 __print_hex(__entry->insn, __entry->len),
Avi Kivitye46479f2010-04-11 13:05:16 +0300738 __print_symbolic(__entry->flags,
739 kvm_trace_symbol_emul_flags),
740 __entry->failed ? " failed" : ""
741 )
742 );
743
744#define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0)
745#define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1)
746
Xiao Guangrong4f022642011-07-12 03:34:24 +0800747TRACE_EVENT(
748 vcpu_match_mmio,
749 TP_PROTO(gva_t gva, gpa_t gpa, bool write, bool gpa_match),
750 TP_ARGS(gva, gpa, write, gpa_match),
751
752 TP_STRUCT__entry(
753 __field(gva_t, gva)
754 __field(gpa_t, gpa)
755 __field(bool, write)
756 __field(bool, gpa_match)
757 ),
758
759 TP_fast_assign(
760 __entry->gva = gva;
761 __entry->gpa = gpa;
762 __entry->write = write;
763 __entry->gpa_match = gpa_match
764 ),
765
766 TP_printk("gva %#lx gpa %#llx %s %s", __entry->gva, __entry->gpa,
767 __entry->write ? "Write" : "Read",
768 __entry->gpa_match ? "GPA" : "GVA")
769);
Marcelo Tosattid8281992012-11-27 23:29:01 -0200770
Yoshihiro YUNOMAE489223e2013-06-12 16:43:44 +0900771TRACE_EVENT(kvm_write_tsc_offset,
772 TP_PROTO(unsigned int vcpu_id, __u64 previous_tsc_offset,
773 __u64 next_tsc_offset),
774 TP_ARGS(vcpu_id, previous_tsc_offset, next_tsc_offset),
775
776 TP_STRUCT__entry(
777 __field( unsigned int, vcpu_id )
778 __field( __u64, previous_tsc_offset )
779 __field( __u64, next_tsc_offset )
780 ),
781
782 TP_fast_assign(
783 __entry->vcpu_id = vcpu_id;
784 __entry->previous_tsc_offset = previous_tsc_offset;
785 __entry->next_tsc_offset = next_tsc_offset;
786 ),
787
788 TP_printk("vcpu=%u prev=%llu next=%llu", __entry->vcpu_id,
789 __entry->previous_tsc_offset, __entry->next_tsc_offset)
790);
791
Marcelo Tosattid8281992012-11-27 23:29:01 -0200792#ifdef CONFIG_X86_64
793
794#define host_clocks \
795 {VCLOCK_NONE, "none"}, \
796 {VCLOCK_TSC, "tsc"}, \
797 {VCLOCK_HPET, "hpet"} \
798
799TRACE_EVENT(kvm_update_master_clock,
Marcelo Tosattib48aa972012-11-27 23:29:03 -0200800 TP_PROTO(bool use_master_clock, unsigned int host_clock, bool offset_matched),
801 TP_ARGS(use_master_clock, host_clock, offset_matched),
Marcelo Tosattid8281992012-11-27 23:29:01 -0200802
803 TP_STRUCT__entry(
804 __field( bool, use_master_clock )
805 __field( unsigned int, host_clock )
Marcelo Tosattib48aa972012-11-27 23:29:03 -0200806 __field( bool, offset_matched )
Marcelo Tosattid8281992012-11-27 23:29:01 -0200807 ),
808
809 TP_fast_assign(
810 __entry->use_master_clock = use_master_clock;
811 __entry->host_clock = host_clock;
Marcelo Tosattib48aa972012-11-27 23:29:03 -0200812 __entry->offset_matched = offset_matched;
Marcelo Tosattid8281992012-11-27 23:29:01 -0200813 ),
814
Marcelo Tosattib48aa972012-11-27 23:29:03 -0200815 TP_printk("masterclock %d hostclock %s offsetmatched %u",
Marcelo Tosattid8281992012-11-27 23:29:01 -0200816 __entry->use_master_clock,
Marcelo Tosattib48aa972012-11-27 23:29:03 -0200817 __print_symbolic(__entry->host_clock, host_clocks),
818 __entry->offset_matched)
819);
820
821TRACE_EVENT(kvm_track_tsc,
822 TP_PROTO(unsigned int vcpu_id, unsigned int nr_matched,
823 unsigned int online_vcpus, bool use_master_clock,
824 unsigned int host_clock),
825 TP_ARGS(vcpu_id, nr_matched, online_vcpus, use_master_clock,
826 host_clock),
827
828 TP_STRUCT__entry(
829 __field( unsigned int, vcpu_id )
830 __field( unsigned int, nr_vcpus_matched_tsc )
831 __field( unsigned int, online_vcpus )
832 __field( bool, use_master_clock )
833 __field( unsigned int, host_clock )
834 ),
835
836 TP_fast_assign(
837 __entry->vcpu_id = vcpu_id;
838 __entry->nr_vcpus_matched_tsc = nr_matched;
839 __entry->online_vcpus = online_vcpus;
840 __entry->use_master_clock = use_master_clock;
841 __entry->host_clock = host_clock;
842 ),
843
844 TP_printk("vcpu_id %u masterclock %u offsetmatched %u nr_online %u"
845 " hostclock %s",
846 __entry->vcpu_id, __entry->use_master_clock,
847 __entry->nr_vcpus_matched_tsc, __entry->online_vcpus,
Marcelo Tosattid8281992012-11-27 23:29:01 -0200848 __print_symbolic(__entry->host_clock, host_clocks))
849);
850
851#endif /* CONFIG_X86_64 */
852
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300853#endif /* _TRACE_KVM_H */
854
Xiao Guangrong2ed152a2010-03-10 19:00:43 +0800855#undef TRACE_INCLUDE_PATH
856#define TRACE_INCLUDE_PATH arch/x86/kvm
857#undef TRACE_INCLUDE_FILE
858#define TRACE_INCLUDE_FILE trace
859
Marcelo Tosatti229456f2009-06-17 09:22:14 -0300860/* This part must be outside protection */
861#include <trace/define_trace.h>