1 #if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ) 2 #define _TRACE_KVM_H 3 4 #include <linux/tracepoint.h> 5 #include <asm/vmx.h> 6 #include <asm/svm.h> 7 #include <asm/clocksource.h> 8 9 #undef TRACE_SYSTEM 10 #define TRACE_SYSTEM kvm 11 12 /* 13 * Tracepoint for guest mode entry. 14 */ 15 TRACE_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 */ 33 TRACE_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 /* 60 * Tracepoint for hypercall. 61 */ 62 TRACE_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( 68 __field( __u16, rep_cnt ) 69 __field( __u16, rep_idx ) 70 __field( __u64, ingpa ) 71 __field( __u64, outgpa ) 72 __field( __u16, code ) 73 __field( bool, fast ) 74 ), 75 76 TP_fast_assign( 77 __entry->rep_cnt = rep_cnt; 78 __entry->rep_idx = rep_idx; 79 __entry->ingpa = ingpa; 80 __entry->outgpa = outgpa; 81 __entry->code = code; 82 __entry->fast = fast; 83 ), 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 /* 92 * Tracepoint for PIO. 93 */ 94 95 #define KVM_PIO_IN 0 96 #define KVM_PIO_OUT 1 97 98 TRACE_EVENT(kvm_pio, 99 TP_PROTO(unsigned int rw, unsigned int port, unsigned int size, 100 unsigned int count, void *data), 101 TP_ARGS(rw, port, size, count, data), 102 103 TP_STRUCT__entry( 104 __field( unsigned int, rw ) 105 __field( unsigned int, port ) 106 __field( unsigned int, size ) 107 __field( unsigned int, count ) 108 __field( unsigned int, val ) 109 ), 110 111 TP_fast_assign( 112 __entry->rw = rw; 113 __entry->port = port; 114 __entry->size = size; 115 __entry->count = count; 116 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; 122 ), 123 124 TP_printk("pio_%s at 0x%x size %d count %d val 0x%x %s", 125 __entry->rw ? "write" : "read", 126 __entry->port, __entry->size, __entry->count, __entry->val, 127 __entry->count > 1 ? "(...)" : "") 128 ); 129 130 /* 131 * Tracepoint for cpuid. 132 */ 133 TRACE_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 159 #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) 168 /* 169 * Tracepoint for apic access. 170 */ 171 TRACE_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 187 TP_printk("apic_%s %s = 0x%x", 188 __entry->rw ? "write" : "read", 189 __print_symbolic(__entry->reg, kvm_trace_symbol_apic), 190 __entry->val) 191 ); 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 196 #define KVM_ISA_VMX 1 197 #define KVM_ISA_SVM 2 198 199 /* 200 * Tracepoint for kvm guest exit: 201 */ 202 TRACE_EVENT(kvm_exit, 203 TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa), 204 TP_ARGS(exit_reason, vcpu, isa), 205 206 TP_STRUCT__entry( 207 __field( unsigned int, exit_reason ) 208 __field( unsigned long, guest_rip ) 209 __field( u32, isa ) 210 __field( u64, info1 ) 211 __field( u64, info2 ) 212 ), 213 214 TP_fast_assign( 215 __entry->exit_reason = exit_reason; 216 __entry->guest_rip = kvm_rip_read(vcpu); 217 __entry->isa = isa; 218 kvm_x86_ops->get_exit_info(vcpu, &__entry->info1, 219 &__entry->info2); 220 ), 221 222 TP_printk("reason %s rip 0x%lx info %llx %llx", 223 (__entry->isa == KVM_ISA_VMX) ? 224 __print_symbolic(__entry->exit_reason, VMX_EXIT_REASONS) : 225 __print_symbolic(__entry->exit_reason, SVM_EXIT_REASONS), 226 __entry->guest_rip, __entry->info1, __entry->info2) 227 ); 228 229 /* 230 * Tracepoint for kvm interrupt injection: 231 */ 232 TRACE_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 247 #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 */ 257 TRACE_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 279 /* 280 * Tracepoint for page fault. 281 */ 282 TRACE_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 */ 303 TRACE_EVENT(kvm_msr, 304 TP_PROTO(unsigned write, u32 ecx, u64 data, bool exception), 305 TP_ARGS(write, ecx, data, exception), 306 307 TP_STRUCT__entry( 308 __field( unsigned, write ) 309 __field( u32, ecx ) 310 __field( u64, data ) 311 __field( u8, exception ) 312 ), 313 314 TP_fast_assign( 315 __entry->write = write; 316 __entry->ecx = ecx; 317 __entry->data = data; 318 __entry->exception = exception; 319 ), 320 321 TP_printk("msr_%s %x = 0x%llx%s", 322 __entry->write ? "write" : "read", 323 __entry->ecx, __entry->data, 324 __entry->exception ? " (#GP)" : "") 325 ); 326 327 #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) 331 332 /* 333 * Tracepoint for guest CR access. 334 */ 335 TRACE_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 359 TRACE_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 392 TRACE_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 417 TRACE_EVENT(kvm_apic_accept_irq, 418 TP_PROTO(__u32 apicid, __u16 dm, __u8 tm, __u8 vec), 419 TP_ARGS(apicid, dm, tm, vec), 420 421 TP_STRUCT__entry( 422 __field( __u32, apicid ) 423 __field( __u16, dm ) 424 __field( __u8, tm ) 425 __field( __u8, vec ) 426 ), 427 428 TP_fast_assign( 429 __entry->apicid = apicid; 430 __entry->dm = dm; 431 __entry->tm = tm; 432 __entry->vec = vec; 433 ), 434 435 TP_printk("apicid %x vec %u (%s|%s)", 436 __entry->apicid, __entry->vec, 437 __print_symbolic((__entry->dm >> 8 & 0x7), kvm_deliver_mode), 438 __entry->tm ? "level" : "edge") 439 ); 440 441 TRACE_EVENT(kvm_eoi, 442 TP_PROTO(struct kvm_lapic *apic, int vector), 443 TP_ARGS(apic, vector), 444 445 TP_STRUCT__entry( 446 __field( __u32, apicid ) 447 __field( int, vector ) 448 ), 449 450 TP_fast_assign( 451 __entry->apicid = apic->vcpu->vcpu_id; 452 __entry->vector = vector; 453 ), 454 455 TP_printk("apicid %x vector %d", __entry->apicid, __entry->vector) 456 ); 457 458 TRACE_EVENT(kvm_pv_eoi, 459 TP_PROTO(struct kvm_lapic *apic, int vector), 460 TP_ARGS(apic, vector), 461 462 TP_STRUCT__entry( 463 __field( __u32, apicid ) 464 __field( int, vector ) 465 ), 466 467 TP_fast_assign( 468 __entry->apicid = apic->vcpu->vcpu_id; 469 __entry->vector = vector; 470 ), 471 472 TP_printk("apicid %x vector %d", __entry->apicid, __entry->vector) 473 ); 474 475 /* 476 * Tracepoint for nested VMRUN 477 */ 478 TRACE_EVENT(kvm_nested_vmrun, 479 TP_PROTO(__u64 rip, __u64 vmcb, __u64 nested_rip, __u32 int_ctl, 480 __u32 event_inj, bool npt), 481 TP_ARGS(rip, vmcb, nested_rip, int_ctl, event_inj, npt), 482 483 TP_STRUCT__entry( 484 __field( __u64, rip ) 485 __field( __u64, vmcb ) 486 __field( __u64, nested_rip ) 487 __field( __u32, int_ctl ) 488 __field( __u32, event_inj ) 489 __field( bool, npt ) 490 ), 491 492 TP_fast_assign( 493 __entry->rip = rip; 494 __entry->vmcb = vmcb; 495 __entry->nested_rip = nested_rip; 496 __entry->int_ctl = int_ctl; 497 __entry->event_inj = event_inj; 498 __entry->npt = npt; 499 ), 500 501 TP_printk("rip: 0x%016llx vmcb: 0x%016llx nrip: 0x%016llx int_ctl: 0x%08x " 502 "event_inj: 0x%08x npt: %s", 503 __entry->rip, __entry->vmcb, __entry->nested_rip, 504 __entry->int_ctl, __entry->event_inj, 505 __entry->npt ? "on" : "off") 506 ); 507 508 TRACE_EVENT(kvm_nested_intercepts, 509 TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u64 intercept), 510 TP_ARGS(cr_read, cr_write, exceptions, intercept), 511 512 TP_STRUCT__entry( 513 __field( __u16, cr_read ) 514 __field( __u16, cr_write ) 515 __field( __u32, exceptions ) 516 __field( __u64, intercept ) 517 ), 518 519 TP_fast_assign( 520 __entry->cr_read = cr_read; 521 __entry->cr_write = cr_write; 522 __entry->exceptions = exceptions; 523 __entry->intercept = intercept; 524 ), 525 526 TP_printk("cr_read: %04x cr_write: %04x excp: %08x intercept: %016llx", 527 __entry->cr_read, __entry->cr_write, __entry->exceptions, 528 __entry->intercept) 529 ); 530 /* 531 * Tracepoint for #VMEXIT while nested 532 */ 533 TRACE_EVENT(kvm_nested_vmexit, 534 TP_PROTO(__u64 rip, __u32 exit_code, 535 __u64 exit_info1, __u64 exit_info2, 536 __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa), 537 TP_ARGS(rip, exit_code, exit_info1, exit_info2, 538 exit_int_info, exit_int_info_err, isa), 539 540 TP_STRUCT__entry( 541 __field( __u64, rip ) 542 __field( __u32, exit_code ) 543 __field( __u64, exit_info1 ) 544 __field( __u64, exit_info2 ) 545 __field( __u32, exit_int_info ) 546 __field( __u32, exit_int_info_err ) 547 __field( __u32, isa ) 548 ), 549 550 TP_fast_assign( 551 __entry->rip = rip; 552 __entry->exit_code = exit_code; 553 __entry->exit_info1 = exit_info1; 554 __entry->exit_info2 = exit_info2; 555 __entry->exit_int_info = exit_int_info; 556 __entry->exit_int_info_err = exit_int_info_err; 557 __entry->isa = isa; 558 ), 559 TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx " 560 "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x", 561 __entry->rip, 562 (__entry->isa == KVM_ISA_VMX) ? 563 __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) : 564 __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS), 565 __entry->exit_info1, __entry->exit_info2, 566 __entry->exit_int_info, __entry->exit_int_info_err) 567 ); 568 569 /* 570 * Tracepoint for #VMEXIT reinjected to the guest 571 */ 572 TRACE_EVENT(kvm_nested_vmexit_inject, 573 TP_PROTO(__u32 exit_code, 574 __u64 exit_info1, __u64 exit_info2, 575 __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa), 576 TP_ARGS(exit_code, exit_info1, exit_info2, 577 exit_int_info, exit_int_info_err, isa), 578 579 TP_STRUCT__entry( 580 __field( __u32, exit_code ) 581 __field( __u64, exit_info1 ) 582 __field( __u64, exit_info2 ) 583 __field( __u32, exit_int_info ) 584 __field( __u32, exit_int_info_err ) 585 __field( __u32, isa ) 586 ), 587 588 TP_fast_assign( 589 __entry->exit_code = exit_code; 590 __entry->exit_info1 = exit_info1; 591 __entry->exit_info2 = exit_info2; 592 __entry->exit_int_info = exit_int_info; 593 __entry->exit_int_info_err = exit_int_info_err; 594 __entry->isa = isa; 595 ), 596 597 TP_printk("reason: %s ext_inf1: 0x%016llx " 598 "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x", 599 (__entry->isa == KVM_ISA_VMX) ? 600 __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) : 601 __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS), 602 __entry->exit_info1, __entry->exit_info2, 603 __entry->exit_int_info, __entry->exit_int_info_err) 604 ); 605 606 /* 607 * Tracepoint for nested #vmexit because of interrupt pending 608 */ 609 TRACE_EVENT(kvm_nested_intr_vmexit, 610 TP_PROTO(__u64 rip), 611 TP_ARGS(rip), 612 613 TP_STRUCT__entry( 614 __field( __u64, rip ) 615 ), 616 617 TP_fast_assign( 618 __entry->rip = rip 619 ), 620 621 TP_printk("rip: 0x%016llx", __entry->rip) 622 ); 623 624 /* 625 * Tracepoint for nested #vmexit because of interrupt pending 626 */ 627 TRACE_EVENT(kvm_invlpga, 628 TP_PROTO(__u64 rip, int asid, u64 address), 629 TP_ARGS(rip, asid, address), 630 631 TP_STRUCT__entry( 632 __field( __u64, rip ) 633 __field( int, asid ) 634 __field( __u64, address ) 635 ), 636 637 TP_fast_assign( 638 __entry->rip = rip; 639 __entry->asid = asid; 640 __entry->address = address; 641 ), 642 643 TP_printk("rip: 0x%016llx asid: %d address: 0x%016llx", 644 __entry->rip, __entry->asid, __entry->address) 645 ); 646 647 /* 648 * Tracepoint for nested #vmexit because of interrupt pending 649 */ 650 TRACE_EVENT(kvm_skinit, 651 TP_PROTO(__u64 rip, __u32 slb), 652 TP_ARGS(rip, slb), 653 654 TP_STRUCT__entry( 655 __field( __u64, rip ) 656 __field( __u32, slb ) 657 ), 658 659 TP_fast_assign( 660 __entry->rip = rip; 661 __entry->slb = slb; 662 ), 663 664 TP_printk("rip: 0x%016llx slb: 0x%08x", 665 __entry->rip, __entry->slb) 666 ); 667 668 #define KVM_EMUL_INSN_F_CR0_PE (1 << 0) 669 #define KVM_EMUL_INSN_F_EFL_VM (1 << 1) 670 #define KVM_EMUL_INSN_F_CS_D (1 << 2) 671 #define KVM_EMUL_INSN_F_CS_L (1 << 3) 672 673 #define kvm_trace_symbol_emul_flags \ 674 { 0, "real" }, \ 675 { KVM_EMUL_INSN_F_CR0_PE \ 676 | KVM_EMUL_INSN_F_EFL_VM, "vm16" }, \ 677 { KVM_EMUL_INSN_F_CR0_PE, "prot16" }, \ 678 { KVM_EMUL_INSN_F_CR0_PE \ 679 | KVM_EMUL_INSN_F_CS_D, "prot32" }, \ 680 { KVM_EMUL_INSN_F_CR0_PE \ 681 | KVM_EMUL_INSN_F_CS_L, "prot64" } 682 683 #define kei_decode_mode(mode) ({ \ 684 u8 flags = 0xff; \ 685 switch (mode) { \ 686 case X86EMUL_MODE_REAL: \ 687 flags = 0; \ 688 break; \ 689 case X86EMUL_MODE_VM86: \ 690 flags = KVM_EMUL_INSN_F_EFL_VM; \ 691 break; \ 692 case X86EMUL_MODE_PROT16: \ 693 flags = KVM_EMUL_INSN_F_CR0_PE; \ 694 break; \ 695 case X86EMUL_MODE_PROT32: \ 696 flags = KVM_EMUL_INSN_F_CR0_PE \ 697 | KVM_EMUL_INSN_F_CS_D; \ 698 break; \ 699 case X86EMUL_MODE_PROT64: \ 700 flags = KVM_EMUL_INSN_F_CR0_PE \ 701 | KVM_EMUL_INSN_F_CS_L; \ 702 break; \ 703 } \ 704 flags; \ 705 }) 706 707 TRACE_EVENT(kvm_emulate_insn, 708 TP_PROTO(struct kvm_vcpu *vcpu, __u8 failed), 709 TP_ARGS(vcpu, failed), 710 711 TP_STRUCT__entry( 712 __field( __u64, rip ) 713 __field( __u32, csbase ) 714 __field( __u8, len ) 715 __array( __u8, insn, 15 ) 716 __field( __u8, flags ) 717 __field( __u8, failed ) 718 ), 719 720 TP_fast_assign( 721 __entry->csbase = kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS); 722 __entry->len = vcpu->arch.emulate_ctxt.fetch.ptr 723 - vcpu->arch.emulate_ctxt.fetch.data; 724 __entry->rip = vcpu->arch.emulate_ctxt._eip - __entry->len; 725 memcpy(__entry->insn, 726 vcpu->arch.emulate_ctxt.fetch.data, 727 15); 728 __entry->flags = kei_decode_mode(vcpu->arch.emulate_ctxt.mode); 729 __entry->failed = failed; 730 ), 731 732 TP_printk("%x:%llx:%s (%s)%s", 733 __entry->csbase, __entry->rip, 734 __print_hex(__entry->insn, __entry->len), 735 __print_symbolic(__entry->flags, 736 kvm_trace_symbol_emul_flags), 737 __entry->failed ? " failed" : "" 738 ) 739 ); 740 741 #define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0) 742 #define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1) 743 744 TRACE_EVENT( 745 vcpu_match_mmio, 746 TP_PROTO(gva_t gva, gpa_t gpa, bool write, bool gpa_match), 747 TP_ARGS(gva, gpa, write, gpa_match), 748 749 TP_STRUCT__entry( 750 __field(gva_t, gva) 751 __field(gpa_t, gpa) 752 __field(bool, write) 753 __field(bool, gpa_match) 754 ), 755 756 TP_fast_assign( 757 __entry->gva = gva; 758 __entry->gpa = gpa; 759 __entry->write = write; 760 __entry->gpa_match = gpa_match 761 ), 762 763 TP_printk("gva %#lx gpa %#llx %s %s", __entry->gva, __entry->gpa, 764 __entry->write ? "Write" : "Read", 765 __entry->gpa_match ? "GPA" : "GVA") 766 ); 767 768 TRACE_EVENT(kvm_write_tsc_offset, 769 TP_PROTO(unsigned int vcpu_id, __u64 previous_tsc_offset, 770 __u64 next_tsc_offset), 771 TP_ARGS(vcpu_id, previous_tsc_offset, next_tsc_offset), 772 773 TP_STRUCT__entry( 774 __field( unsigned int, vcpu_id ) 775 __field( __u64, previous_tsc_offset ) 776 __field( __u64, next_tsc_offset ) 777 ), 778 779 TP_fast_assign( 780 __entry->vcpu_id = vcpu_id; 781 __entry->previous_tsc_offset = previous_tsc_offset; 782 __entry->next_tsc_offset = next_tsc_offset; 783 ), 784 785 TP_printk("vcpu=%u prev=%llu next=%llu", __entry->vcpu_id, 786 __entry->previous_tsc_offset, __entry->next_tsc_offset) 787 ); 788 789 #ifdef CONFIG_X86_64 790 791 #define host_clocks \ 792 {VCLOCK_NONE, "none"}, \ 793 {VCLOCK_TSC, "tsc"}, \ 794 {VCLOCK_HPET, "hpet"} \ 795 796 TRACE_EVENT(kvm_update_master_clock, 797 TP_PROTO(bool use_master_clock, unsigned int host_clock, bool offset_matched), 798 TP_ARGS(use_master_clock, host_clock, offset_matched), 799 800 TP_STRUCT__entry( 801 __field( bool, use_master_clock ) 802 __field( unsigned int, host_clock ) 803 __field( bool, offset_matched ) 804 ), 805 806 TP_fast_assign( 807 __entry->use_master_clock = use_master_clock; 808 __entry->host_clock = host_clock; 809 __entry->offset_matched = offset_matched; 810 ), 811 812 TP_printk("masterclock %d hostclock %s offsetmatched %u", 813 __entry->use_master_clock, 814 __print_symbolic(__entry->host_clock, host_clocks), 815 __entry->offset_matched) 816 ); 817 818 TRACE_EVENT(kvm_track_tsc, 819 TP_PROTO(unsigned int vcpu_id, unsigned int nr_matched, 820 unsigned int online_vcpus, bool use_master_clock, 821 unsigned int host_clock), 822 TP_ARGS(vcpu_id, nr_matched, online_vcpus, use_master_clock, 823 host_clock), 824 825 TP_STRUCT__entry( 826 __field( unsigned int, vcpu_id ) 827 __field( unsigned int, nr_vcpus_matched_tsc ) 828 __field( unsigned int, online_vcpus ) 829 __field( bool, use_master_clock ) 830 __field( unsigned int, host_clock ) 831 ), 832 833 TP_fast_assign( 834 __entry->vcpu_id = vcpu_id; 835 __entry->nr_vcpus_matched_tsc = nr_matched; 836 __entry->online_vcpus = online_vcpus; 837 __entry->use_master_clock = use_master_clock; 838 __entry->host_clock = host_clock; 839 ), 840 841 TP_printk("vcpu_id %u masterclock %u offsetmatched %u nr_online %u" 842 " hostclock %s", 843 __entry->vcpu_id, __entry->use_master_clock, 844 __entry->nr_vcpus_matched_tsc, __entry->online_vcpus, 845 __print_symbolic(__entry->host_clock, host_clocks)) 846 ); 847 848 #endif /* CONFIG_X86_64 */ 849 850 TRACE_EVENT(kvm_ple_window, 851 TP_PROTO(bool grow, unsigned int vcpu_id, int new, int old), 852 TP_ARGS(grow, vcpu_id, new, old), 853 854 TP_STRUCT__entry( 855 __field( bool, grow ) 856 __field( unsigned int, vcpu_id ) 857 __field( int, new ) 858 __field( int, old ) 859 ), 860 861 TP_fast_assign( 862 __entry->grow = grow; 863 __entry->vcpu_id = vcpu_id; 864 __entry->new = new; 865 __entry->old = old; 866 ), 867 868 TP_printk("vcpu %u: ple_window %d (%s %d)", 869 __entry->vcpu_id, 870 __entry->new, 871 __entry->grow ? "grow" : "shrink", 872 __entry->old) 873 ); 874 875 #define trace_kvm_ple_window_grow(vcpu_id, new, old) \ 876 trace_kvm_ple_window(true, vcpu_id, new, old) 877 #define trace_kvm_ple_window_shrink(vcpu_id, new, old) \ 878 trace_kvm_ple_window(false, vcpu_id, new, old) 879 880 #endif /* _TRACE_KVM_H */ 881 882 #undef TRACE_INCLUDE_PATH 883 #define TRACE_INCLUDE_PATH arch/x86/kvm 884 #undef TRACE_INCLUDE_FILE 885 #define TRACE_INCLUDE_FILE trace 886 887 /* This part must be outside protection */ 888 #include <trace/define_trace.h> 889