trace.h 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. #if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
  2. #define _TRACE_KVM_H
  3. #include <linux/tracepoint.h>
  4. #include <asm/vmx.h>
  5. #include <asm/svm.h>
  6. #include <asm/clocksource.h>
  7. #include <asm/pvclock-abi.h>
  8. #undef TRACE_SYSTEM
  9. #define TRACE_SYSTEM kvm
  10. /*
  11. * Tracepoint for guest mode entry.
  12. */
  13. TRACE_EVENT(kvm_entry,
  14. TP_PROTO(unsigned int vcpu_id),
  15. TP_ARGS(vcpu_id),
  16. TP_STRUCT__entry(
  17. __field( unsigned int, vcpu_id )
  18. ),
  19. TP_fast_assign(
  20. __entry->vcpu_id = vcpu_id;
  21. ),
  22. TP_printk("vcpu %u", __entry->vcpu_id)
  23. );
  24. /*
  25. * Tracepoint for hypercall.
  26. */
  27. TRACE_EVENT(kvm_hypercall,
  28. TP_PROTO(unsigned long nr, unsigned long a0, unsigned long a1,
  29. unsigned long a2, unsigned long a3),
  30. TP_ARGS(nr, a0, a1, a2, a3),
  31. TP_STRUCT__entry(
  32. __field( unsigned long, nr )
  33. __field( unsigned long, a0 )
  34. __field( unsigned long, a1 )
  35. __field( unsigned long, a2 )
  36. __field( unsigned long, a3 )
  37. ),
  38. TP_fast_assign(
  39. __entry->nr = nr;
  40. __entry->a0 = a0;
  41. __entry->a1 = a1;
  42. __entry->a2 = a2;
  43. __entry->a3 = a3;
  44. ),
  45. TP_printk("nr 0x%lx a0 0x%lx a1 0x%lx a2 0x%lx a3 0x%lx",
  46. __entry->nr, __entry->a0, __entry->a1, __entry->a2,
  47. __entry->a3)
  48. );
  49. /*
  50. * Tracepoint for hypercall.
  51. */
  52. TRACE_EVENT(kvm_hv_hypercall,
  53. TP_PROTO(__u16 code, bool fast, __u16 rep_cnt, __u16 rep_idx,
  54. __u64 ingpa, __u64 outgpa),
  55. TP_ARGS(code, fast, rep_cnt, rep_idx, ingpa, outgpa),
  56. TP_STRUCT__entry(
  57. __field( __u16, rep_cnt )
  58. __field( __u16, rep_idx )
  59. __field( __u64, ingpa )
  60. __field( __u64, outgpa )
  61. __field( __u16, code )
  62. __field( bool, fast )
  63. ),
  64. TP_fast_assign(
  65. __entry->rep_cnt = rep_cnt;
  66. __entry->rep_idx = rep_idx;
  67. __entry->ingpa = ingpa;
  68. __entry->outgpa = outgpa;
  69. __entry->code = code;
  70. __entry->fast = fast;
  71. ),
  72. TP_printk("code 0x%x %s cnt 0x%x idx 0x%x in 0x%llx out 0x%llx",
  73. __entry->code, __entry->fast ? "fast" : "slow",
  74. __entry->rep_cnt, __entry->rep_idx, __entry->ingpa,
  75. __entry->outgpa)
  76. );
  77. /*
  78. * Tracepoint for PIO.
  79. */
  80. #define KVM_PIO_IN 0
  81. #define KVM_PIO_OUT 1
  82. TRACE_EVENT(kvm_pio,
  83. TP_PROTO(unsigned int rw, unsigned int port, unsigned int size,
  84. unsigned int count, void *data),
  85. TP_ARGS(rw, port, size, count, data),
  86. TP_STRUCT__entry(
  87. __field( unsigned int, rw )
  88. __field( unsigned int, port )
  89. __field( unsigned int, size )
  90. __field( unsigned int, count )
  91. __field( unsigned int, val )
  92. ),
  93. TP_fast_assign(
  94. __entry->rw = rw;
  95. __entry->port = port;
  96. __entry->size = size;
  97. __entry->count = count;
  98. if (size == 1)
  99. __entry->val = *(unsigned char *)data;
  100. else if (size == 2)
  101. __entry->val = *(unsigned short *)data;
  102. else
  103. __entry->val = *(unsigned int *)data;
  104. ),
  105. TP_printk("pio_%s at 0x%x size %d count %d val 0x%x %s",
  106. __entry->rw ? "write" : "read",
  107. __entry->port, __entry->size, __entry->count, __entry->val,
  108. __entry->count > 1 ? "(...)" : "")
  109. );
  110. /*
  111. * Tracepoint for fast mmio.
  112. */
  113. TRACE_EVENT(kvm_fast_mmio,
  114. TP_PROTO(u64 gpa),
  115. TP_ARGS(gpa),
  116. TP_STRUCT__entry(
  117. __field(u64, gpa)
  118. ),
  119. TP_fast_assign(
  120. __entry->gpa = gpa;
  121. ),
  122. TP_printk("fast mmio at gpa 0x%llx", __entry->gpa)
  123. );
  124. /*
  125. * Tracepoint for cpuid.
  126. */
  127. TRACE_EVENT(kvm_cpuid,
  128. TP_PROTO(unsigned int function, unsigned long rax, unsigned long rbx,
  129. unsigned long rcx, unsigned long rdx),
  130. TP_ARGS(function, rax, rbx, rcx, rdx),
  131. TP_STRUCT__entry(
  132. __field( unsigned int, function )
  133. __field( unsigned long, rax )
  134. __field( unsigned long, rbx )
  135. __field( unsigned long, rcx )
  136. __field( unsigned long, rdx )
  137. ),
  138. TP_fast_assign(
  139. __entry->function = function;
  140. __entry->rax = rax;
  141. __entry->rbx = rbx;
  142. __entry->rcx = rcx;
  143. __entry->rdx = rdx;
  144. ),
  145. TP_printk("func %x rax %lx rbx %lx rcx %lx rdx %lx",
  146. __entry->function, __entry->rax,
  147. __entry->rbx, __entry->rcx, __entry->rdx)
  148. );
  149. #define AREG(x) { APIC_##x, "APIC_" #x }
  150. #define kvm_trace_symbol_apic \
  151. AREG(ID), AREG(LVR), AREG(TASKPRI), AREG(ARBPRI), AREG(PROCPRI), \
  152. AREG(EOI), AREG(RRR), AREG(LDR), AREG(DFR), AREG(SPIV), AREG(ISR), \
  153. AREG(TMR), AREG(IRR), AREG(ESR), AREG(ICR), AREG(ICR2), AREG(LVTT), \
  154. AREG(LVTTHMR), AREG(LVTPC), AREG(LVT0), AREG(LVT1), AREG(LVTERR), \
  155. AREG(TMICT), AREG(TMCCT), AREG(TDCR), AREG(SELF_IPI), AREG(EFEAT), \
  156. AREG(ECTRL)
  157. /*
  158. * Tracepoint for apic access.
  159. */
  160. TRACE_EVENT(kvm_apic,
  161. TP_PROTO(unsigned int rw, unsigned int reg, unsigned int val),
  162. TP_ARGS(rw, reg, val),
  163. TP_STRUCT__entry(
  164. __field( unsigned int, rw )
  165. __field( unsigned int, reg )
  166. __field( unsigned int, val )
  167. ),
  168. TP_fast_assign(
  169. __entry->rw = rw;
  170. __entry->reg = reg;
  171. __entry->val = val;
  172. ),
  173. TP_printk("apic_%s %s = 0x%x",
  174. __entry->rw ? "write" : "read",
  175. __print_symbolic(__entry->reg, kvm_trace_symbol_apic),
  176. __entry->val)
  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. #define KVM_ISA_VMX 1
  181. #define KVM_ISA_SVM 2
  182. /*
  183. * Tracepoint for kvm guest exit:
  184. */
  185. TRACE_EVENT(kvm_exit,
  186. TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa),
  187. TP_ARGS(exit_reason, vcpu, isa),
  188. TP_STRUCT__entry(
  189. __field( unsigned int, exit_reason )
  190. __field( unsigned long, guest_rip )
  191. __field( u32, isa )
  192. __field( u64, info1 )
  193. __field( u64, info2 )
  194. ),
  195. TP_fast_assign(
  196. __entry->exit_reason = exit_reason;
  197. __entry->guest_rip = kvm_rip_read(vcpu);
  198. __entry->isa = isa;
  199. kvm_x86_ops->get_exit_info(vcpu, &__entry->info1,
  200. &__entry->info2);
  201. ),
  202. TP_printk("reason %s rip 0x%lx info %llx %llx",
  203. (__entry->isa == KVM_ISA_VMX) ?
  204. __print_symbolic(__entry->exit_reason, VMX_EXIT_REASONS) :
  205. __print_symbolic(__entry->exit_reason, SVM_EXIT_REASONS),
  206. __entry->guest_rip, __entry->info1, __entry->info2)
  207. );
  208. /*
  209. * Tracepoint for kvm interrupt injection:
  210. */
  211. TRACE_EVENT(kvm_inj_virq,
  212. TP_PROTO(unsigned int irq),
  213. TP_ARGS(irq),
  214. TP_STRUCT__entry(
  215. __field( unsigned int, irq )
  216. ),
  217. TP_fast_assign(
  218. __entry->irq = irq;
  219. ),
  220. TP_printk("irq %u", __entry->irq)
  221. );
  222. #define EXS(x) { x##_VECTOR, "#" #x }
  223. #define kvm_trace_sym_exc \
  224. EXS(DE), EXS(DB), EXS(BP), EXS(OF), EXS(BR), EXS(UD), EXS(NM), \
  225. EXS(DF), EXS(TS), EXS(NP), EXS(SS), EXS(GP), EXS(PF), \
  226. EXS(MF), EXS(AC), EXS(MC)
  227. /*
  228. * Tracepoint for kvm interrupt injection:
  229. */
  230. TRACE_EVENT(kvm_inj_exception,
  231. TP_PROTO(unsigned exception, bool has_error, unsigned error_code),
  232. TP_ARGS(exception, has_error, error_code),
  233. TP_STRUCT__entry(
  234. __field( u8, exception )
  235. __field( u8, has_error )
  236. __field( u32, error_code )
  237. ),
  238. TP_fast_assign(
  239. __entry->exception = exception;
  240. __entry->has_error = has_error;
  241. __entry->error_code = error_code;
  242. ),
  243. TP_printk("%s (0x%x)",
  244. __print_symbolic(__entry->exception, kvm_trace_sym_exc),
  245. /* FIXME: don't print error_code if not present */
  246. __entry->has_error ? __entry->error_code : 0)
  247. );
  248. /*
  249. * Tracepoint for page fault.
  250. */
  251. TRACE_EVENT(kvm_page_fault,
  252. TP_PROTO(unsigned long fault_address, unsigned int error_code),
  253. TP_ARGS(fault_address, error_code),
  254. TP_STRUCT__entry(
  255. __field( unsigned long, fault_address )
  256. __field( unsigned int, error_code )
  257. ),
  258. TP_fast_assign(
  259. __entry->fault_address = fault_address;
  260. __entry->error_code = error_code;
  261. ),
  262. TP_printk("address %lx error_code %x",
  263. __entry->fault_address, __entry->error_code)
  264. );
  265. /*
  266. * Tracepoint for guest MSR access.
  267. */
  268. TRACE_EVENT(kvm_msr,
  269. TP_PROTO(unsigned write, u32 ecx, u64 data, bool exception),
  270. TP_ARGS(write, ecx, data, exception),
  271. TP_STRUCT__entry(
  272. __field( unsigned, write )
  273. __field( u32, ecx )
  274. __field( u64, data )
  275. __field( u8, exception )
  276. ),
  277. TP_fast_assign(
  278. __entry->write = write;
  279. __entry->ecx = ecx;
  280. __entry->data = data;
  281. __entry->exception = exception;
  282. ),
  283. TP_printk("msr_%s %x = 0x%llx%s",
  284. __entry->write ? "write" : "read",
  285. __entry->ecx, __entry->data,
  286. __entry->exception ? " (#GP)" : "")
  287. );
  288. #define trace_kvm_msr_read(ecx, data) trace_kvm_msr(0, ecx, data, false)
  289. #define trace_kvm_msr_write(ecx, data) trace_kvm_msr(1, ecx, data, false)
  290. #define trace_kvm_msr_read_ex(ecx) trace_kvm_msr(0, ecx, 0, true)
  291. #define trace_kvm_msr_write_ex(ecx, data) trace_kvm_msr(1, ecx, data, true)
  292. /*
  293. * Tracepoint for guest CR access.
  294. */
  295. TRACE_EVENT(kvm_cr,
  296. TP_PROTO(unsigned int rw, unsigned int cr, unsigned long val),
  297. TP_ARGS(rw, cr, val),
  298. TP_STRUCT__entry(
  299. __field( unsigned int, rw )
  300. __field( unsigned int, cr )
  301. __field( unsigned long, val )
  302. ),
  303. TP_fast_assign(
  304. __entry->rw = rw;
  305. __entry->cr = cr;
  306. __entry->val = val;
  307. ),
  308. TP_printk("cr_%s %x = 0x%lx",
  309. __entry->rw ? "write" : "read",
  310. __entry->cr, __entry->val)
  311. );
  312. #define trace_kvm_cr_read(cr, val) trace_kvm_cr(0, cr, val)
  313. #define trace_kvm_cr_write(cr, val) trace_kvm_cr(1, cr, val)
  314. TRACE_EVENT(kvm_pic_set_irq,
  315. TP_PROTO(__u8 chip, __u8 pin, __u8 elcr, __u8 imr, bool coalesced),
  316. TP_ARGS(chip, pin, elcr, imr, coalesced),
  317. TP_STRUCT__entry(
  318. __field( __u8, chip )
  319. __field( __u8, pin )
  320. __field( __u8, elcr )
  321. __field( __u8, imr )
  322. __field( bool, coalesced )
  323. ),
  324. TP_fast_assign(
  325. __entry->chip = chip;
  326. __entry->pin = pin;
  327. __entry->elcr = elcr;
  328. __entry->imr = imr;
  329. __entry->coalesced = coalesced;
  330. ),
  331. TP_printk("chip %u pin %u (%s%s)%s",
  332. __entry->chip, __entry->pin,
  333. (__entry->elcr & (1 << __entry->pin)) ? "level":"edge",
  334. (__entry->imr & (1 << __entry->pin)) ? "|masked":"",
  335. __entry->coalesced ? " (coalesced)" : "")
  336. );
  337. #define kvm_apic_dst_shorthand \
  338. {0x0, "dst"}, \
  339. {0x1, "self"}, \
  340. {0x2, "all"}, \
  341. {0x3, "all-but-self"}
  342. TRACE_EVENT(kvm_apic_ipi,
  343. TP_PROTO(__u32 icr_low, __u32 dest_id),
  344. TP_ARGS(icr_low, dest_id),
  345. TP_STRUCT__entry(
  346. __field( __u32, icr_low )
  347. __field( __u32, dest_id )
  348. ),
  349. TP_fast_assign(
  350. __entry->icr_low = icr_low;
  351. __entry->dest_id = dest_id;
  352. ),
  353. TP_printk("dst %x vec %u (%s|%s|%s|%s|%s)",
  354. __entry->dest_id, (u8)__entry->icr_low,
  355. __print_symbolic((__entry->icr_low >> 8 & 0x7),
  356. kvm_deliver_mode),
  357. (__entry->icr_low & (1<<11)) ? "logical" : "physical",
  358. (__entry->icr_low & (1<<14)) ? "assert" : "de-assert",
  359. (__entry->icr_low & (1<<15)) ? "level" : "edge",
  360. __print_symbolic((__entry->icr_low >> 18 & 0x3),
  361. kvm_apic_dst_shorthand))
  362. );
  363. TRACE_EVENT(kvm_apic_accept_irq,
  364. TP_PROTO(__u32 apicid, __u16 dm, __u8 tm, __u8 vec),
  365. TP_ARGS(apicid, dm, tm, vec),
  366. TP_STRUCT__entry(
  367. __field( __u32, apicid )
  368. __field( __u16, dm )
  369. __field( __u8, tm )
  370. __field( __u8, vec )
  371. ),
  372. TP_fast_assign(
  373. __entry->apicid = apicid;
  374. __entry->dm = dm;
  375. __entry->tm = tm;
  376. __entry->vec = vec;
  377. ),
  378. TP_printk("apicid %x vec %u (%s|%s)",
  379. __entry->apicid, __entry->vec,
  380. __print_symbolic((__entry->dm >> 8 & 0x7), kvm_deliver_mode),
  381. __entry->tm ? "level" : "edge")
  382. );
  383. TRACE_EVENT(kvm_eoi,
  384. TP_PROTO(struct kvm_lapic *apic, int vector),
  385. TP_ARGS(apic, vector),
  386. TP_STRUCT__entry(
  387. __field( __u32, apicid )
  388. __field( int, vector )
  389. ),
  390. TP_fast_assign(
  391. __entry->apicid = apic->vcpu->vcpu_id;
  392. __entry->vector = vector;
  393. ),
  394. TP_printk("apicid %x vector %d", __entry->apicid, __entry->vector)
  395. );
  396. TRACE_EVENT(kvm_pv_eoi,
  397. TP_PROTO(struct kvm_lapic *apic, int vector),
  398. TP_ARGS(apic, vector),
  399. TP_STRUCT__entry(
  400. __field( __u32, apicid )
  401. __field( int, vector )
  402. ),
  403. TP_fast_assign(
  404. __entry->apicid = apic->vcpu->vcpu_id;
  405. __entry->vector = vector;
  406. ),
  407. TP_printk("apicid %x vector %d", __entry->apicid, __entry->vector)
  408. );
  409. /*
  410. * Tracepoint for nested VMRUN
  411. */
  412. TRACE_EVENT(kvm_nested_vmrun,
  413. TP_PROTO(__u64 rip, __u64 vmcb, __u64 nested_rip, __u32 int_ctl,
  414. __u32 event_inj, bool npt),
  415. TP_ARGS(rip, vmcb, nested_rip, int_ctl, event_inj, npt),
  416. TP_STRUCT__entry(
  417. __field( __u64, rip )
  418. __field( __u64, vmcb )
  419. __field( __u64, nested_rip )
  420. __field( __u32, int_ctl )
  421. __field( __u32, event_inj )
  422. __field( bool, npt )
  423. ),
  424. TP_fast_assign(
  425. __entry->rip = rip;
  426. __entry->vmcb = vmcb;
  427. __entry->nested_rip = nested_rip;
  428. __entry->int_ctl = int_ctl;
  429. __entry->event_inj = event_inj;
  430. __entry->npt = npt;
  431. ),
  432. TP_printk("rip: 0x%016llx vmcb: 0x%016llx nrip: 0x%016llx int_ctl: 0x%08x "
  433. "event_inj: 0x%08x npt: %s",
  434. __entry->rip, __entry->vmcb, __entry->nested_rip,
  435. __entry->int_ctl, __entry->event_inj,
  436. __entry->npt ? "on" : "off")
  437. );
  438. TRACE_EVENT(kvm_nested_intercepts,
  439. TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u64 intercept),
  440. TP_ARGS(cr_read, cr_write, exceptions, intercept),
  441. TP_STRUCT__entry(
  442. __field( __u16, cr_read )
  443. __field( __u16, cr_write )
  444. __field( __u32, exceptions )
  445. __field( __u64, intercept )
  446. ),
  447. TP_fast_assign(
  448. __entry->cr_read = cr_read;
  449. __entry->cr_write = cr_write;
  450. __entry->exceptions = exceptions;
  451. __entry->intercept = intercept;
  452. ),
  453. TP_printk("cr_read: %04x cr_write: %04x excp: %08x intercept: %016llx",
  454. __entry->cr_read, __entry->cr_write, __entry->exceptions,
  455. __entry->intercept)
  456. );
  457. /*
  458. * Tracepoint for #VMEXIT while nested
  459. */
  460. TRACE_EVENT(kvm_nested_vmexit,
  461. TP_PROTO(__u64 rip, __u32 exit_code,
  462. __u64 exit_info1, __u64 exit_info2,
  463. __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
  464. TP_ARGS(rip, exit_code, exit_info1, exit_info2,
  465. exit_int_info, exit_int_info_err, isa),
  466. TP_STRUCT__entry(
  467. __field( __u64, rip )
  468. __field( __u32, exit_code )
  469. __field( __u64, exit_info1 )
  470. __field( __u64, exit_info2 )
  471. __field( __u32, exit_int_info )
  472. __field( __u32, exit_int_info_err )
  473. __field( __u32, isa )
  474. ),
  475. TP_fast_assign(
  476. __entry->rip = rip;
  477. __entry->exit_code = exit_code;
  478. __entry->exit_info1 = exit_info1;
  479. __entry->exit_info2 = exit_info2;
  480. __entry->exit_int_info = exit_int_info;
  481. __entry->exit_int_info_err = exit_int_info_err;
  482. __entry->isa = isa;
  483. ),
  484. TP_printk("rip: 0x%016llx reason: %s ext_inf1: 0x%016llx "
  485. "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
  486. __entry->rip,
  487. (__entry->isa == KVM_ISA_VMX) ?
  488. __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
  489. __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
  490. __entry->exit_info1, __entry->exit_info2,
  491. __entry->exit_int_info, __entry->exit_int_info_err)
  492. );
  493. /*
  494. * Tracepoint for #VMEXIT reinjected to the guest
  495. */
  496. TRACE_EVENT(kvm_nested_vmexit_inject,
  497. TP_PROTO(__u32 exit_code,
  498. __u64 exit_info1, __u64 exit_info2,
  499. __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa),
  500. TP_ARGS(exit_code, exit_info1, exit_info2,
  501. exit_int_info, exit_int_info_err, isa),
  502. TP_STRUCT__entry(
  503. __field( __u32, exit_code )
  504. __field( __u64, exit_info1 )
  505. __field( __u64, exit_info2 )
  506. __field( __u32, exit_int_info )
  507. __field( __u32, exit_int_info_err )
  508. __field( __u32, isa )
  509. ),
  510. TP_fast_assign(
  511. __entry->exit_code = exit_code;
  512. __entry->exit_info1 = exit_info1;
  513. __entry->exit_info2 = exit_info2;
  514. __entry->exit_int_info = exit_int_info;
  515. __entry->exit_int_info_err = exit_int_info_err;
  516. __entry->isa = isa;
  517. ),
  518. TP_printk("reason: %s ext_inf1: 0x%016llx "
  519. "ext_inf2: 0x%016llx ext_int: 0x%08x ext_int_err: 0x%08x",
  520. (__entry->isa == KVM_ISA_VMX) ?
  521. __print_symbolic(__entry->exit_code, VMX_EXIT_REASONS) :
  522. __print_symbolic(__entry->exit_code, SVM_EXIT_REASONS),
  523. __entry->exit_info1, __entry->exit_info2,
  524. __entry->exit_int_info, __entry->exit_int_info_err)
  525. );
  526. /*
  527. * Tracepoint for nested #vmexit because of interrupt pending
  528. */
  529. TRACE_EVENT(kvm_nested_intr_vmexit,
  530. TP_PROTO(__u64 rip),
  531. TP_ARGS(rip),
  532. TP_STRUCT__entry(
  533. __field( __u64, rip )
  534. ),
  535. TP_fast_assign(
  536. __entry->rip = rip
  537. ),
  538. TP_printk("rip: 0x%016llx", __entry->rip)
  539. );
  540. /*
  541. * Tracepoint for nested #vmexit because of interrupt pending
  542. */
  543. TRACE_EVENT(kvm_invlpga,
  544. TP_PROTO(__u64 rip, int asid, u64 address),
  545. TP_ARGS(rip, asid, address),
  546. TP_STRUCT__entry(
  547. __field( __u64, rip )
  548. __field( int, asid )
  549. __field( __u64, address )
  550. ),
  551. TP_fast_assign(
  552. __entry->rip = rip;
  553. __entry->asid = asid;
  554. __entry->address = address;
  555. ),
  556. TP_printk("rip: 0x%016llx asid: %d address: 0x%016llx",
  557. __entry->rip, __entry->asid, __entry->address)
  558. );
  559. /*
  560. * Tracepoint for nested #vmexit because of interrupt pending
  561. */
  562. TRACE_EVENT(kvm_skinit,
  563. TP_PROTO(__u64 rip, __u32 slb),
  564. TP_ARGS(rip, slb),
  565. TP_STRUCT__entry(
  566. __field( __u64, rip )
  567. __field( __u32, slb )
  568. ),
  569. TP_fast_assign(
  570. __entry->rip = rip;
  571. __entry->slb = slb;
  572. ),
  573. TP_printk("rip: 0x%016llx slb: 0x%08x",
  574. __entry->rip, __entry->slb)
  575. );
  576. #define KVM_EMUL_INSN_F_CR0_PE (1 << 0)
  577. #define KVM_EMUL_INSN_F_EFL_VM (1 << 1)
  578. #define KVM_EMUL_INSN_F_CS_D (1 << 2)
  579. #define KVM_EMUL_INSN_F_CS_L (1 << 3)
  580. #define kvm_trace_symbol_emul_flags \
  581. { 0, "real" }, \
  582. { KVM_EMUL_INSN_F_CR0_PE \
  583. | KVM_EMUL_INSN_F_EFL_VM, "vm16" }, \
  584. { KVM_EMUL_INSN_F_CR0_PE, "prot16" }, \
  585. { KVM_EMUL_INSN_F_CR0_PE \
  586. | KVM_EMUL_INSN_F_CS_D, "prot32" }, \
  587. { KVM_EMUL_INSN_F_CR0_PE \
  588. | KVM_EMUL_INSN_F_CS_L, "prot64" }
  589. #define kei_decode_mode(mode) ({ \
  590. u8 flags = 0xff; \
  591. switch (mode) { \
  592. case X86EMUL_MODE_REAL: \
  593. flags = 0; \
  594. break; \
  595. case X86EMUL_MODE_VM86: \
  596. flags = KVM_EMUL_INSN_F_EFL_VM; \
  597. break; \
  598. case X86EMUL_MODE_PROT16: \
  599. flags = KVM_EMUL_INSN_F_CR0_PE; \
  600. break; \
  601. case X86EMUL_MODE_PROT32: \
  602. flags = KVM_EMUL_INSN_F_CR0_PE \
  603. | KVM_EMUL_INSN_F_CS_D; \
  604. break; \
  605. case X86EMUL_MODE_PROT64: \
  606. flags = KVM_EMUL_INSN_F_CR0_PE \
  607. | KVM_EMUL_INSN_F_CS_L; \
  608. break; \
  609. } \
  610. flags; \
  611. })
  612. TRACE_EVENT(kvm_emulate_insn,
  613. TP_PROTO(struct kvm_vcpu *vcpu, __u8 failed),
  614. TP_ARGS(vcpu, failed),
  615. TP_STRUCT__entry(
  616. __field( __u64, rip )
  617. __field( __u32, csbase )
  618. __field( __u8, len )
  619. __array( __u8, insn, 15 )
  620. __field( __u8, flags )
  621. __field( __u8, failed )
  622. ),
  623. TP_fast_assign(
  624. __entry->csbase = kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS);
  625. __entry->len = vcpu->arch.emulate_ctxt.fetch.ptr
  626. - vcpu->arch.emulate_ctxt.fetch.data;
  627. __entry->rip = vcpu->arch.emulate_ctxt._eip - __entry->len;
  628. memcpy(__entry->insn,
  629. vcpu->arch.emulate_ctxt.fetch.data,
  630. 15);
  631. __entry->flags = kei_decode_mode(vcpu->arch.emulate_ctxt.mode);
  632. __entry->failed = failed;
  633. ),
  634. TP_printk("%x:%llx:%s (%s)%s",
  635. __entry->csbase, __entry->rip,
  636. __print_hex(__entry->insn, __entry->len),
  637. __print_symbolic(__entry->flags,
  638. kvm_trace_symbol_emul_flags),
  639. __entry->failed ? " failed" : ""
  640. )
  641. );
  642. #define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0)
  643. #define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1)
  644. TRACE_EVENT(
  645. vcpu_match_mmio,
  646. TP_PROTO(gva_t gva, gpa_t gpa, bool write, bool gpa_match),
  647. TP_ARGS(gva, gpa, write, gpa_match),
  648. TP_STRUCT__entry(
  649. __field(gva_t, gva)
  650. __field(gpa_t, gpa)
  651. __field(bool, write)
  652. __field(bool, gpa_match)
  653. ),
  654. TP_fast_assign(
  655. __entry->gva = gva;
  656. __entry->gpa = gpa;
  657. __entry->write = write;
  658. __entry->gpa_match = gpa_match
  659. ),
  660. TP_printk("gva %#lx gpa %#llx %s %s", __entry->gva, __entry->gpa,
  661. __entry->write ? "Write" : "Read",
  662. __entry->gpa_match ? "GPA" : "GVA")
  663. );
  664. TRACE_EVENT(kvm_write_tsc_offset,
  665. TP_PROTO(unsigned int vcpu_id, __u64 previous_tsc_offset,
  666. __u64 next_tsc_offset),
  667. TP_ARGS(vcpu_id, previous_tsc_offset, next_tsc_offset),
  668. TP_STRUCT__entry(
  669. __field( unsigned int, vcpu_id )
  670. __field( __u64, previous_tsc_offset )
  671. __field( __u64, next_tsc_offset )
  672. ),
  673. TP_fast_assign(
  674. __entry->vcpu_id = vcpu_id;
  675. __entry->previous_tsc_offset = previous_tsc_offset;
  676. __entry->next_tsc_offset = next_tsc_offset;
  677. ),
  678. TP_printk("vcpu=%u prev=%llu next=%llu", __entry->vcpu_id,
  679. __entry->previous_tsc_offset, __entry->next_tsc_offset)
  680. );
  681. #ifdef CONFIG_X86_64
  682. #define host_clocks \
  683. {VCLOCK_NONE, "none"}, \
  684. {VCLOCK_TSC, "tsc"}, \
  685. {VCLOCK_HPET, "hpet"} \
  686. TRACE_EVENT(kvm_update_master_clock,
  687. TP_PROTO(bool use_master_clock, unsigned int host_clock, bool offset_matched),
  688. TP_ARGS(use_master_clock, host_clock, offset_matched),
  689. TP_STRUCT__entry(
  690. __field( bool, use_master_clock )
  691. __field( unsigned int, host_clock )
  692. __field( bool, offset_matched )
  693. ),
  694. TP_fast_assign(
  695. __entry->use_master_clock = use_master_clock;
  696. __entry->host_clock = host_clock;
  697. __entry->offset_matched = offset_matched;
  698. ),
  699. TP_printk("masterclock %d hostclock %s offsetmatched %u",
  700. __entry->use_master_clock,
  701. __print_symbolic(__entry->host_clock, host_clocks),
  702. __entry->offset_matched)
  703. );
  704. TRACE_EVENT(kvm_track_tsc,
  705. TP_PROTO(unsigned int vcpu_id, unsigned int nr_matched,
  706. unsigned int online_vcpus, bool use_master_clock,
  707. unsigned int host_clock),
  708. TP_ARGS(vcpu_id, nr_matched, online_vcpus, use_master_clock,
  709. host_clock),
  710. TP_STRUCT__entry(
  711. __field( unsigned int, vcpu_id )
  712. __field( unsigned int, nr_vcpus_matched_tsc )
  713. __field( unsigned int, online_vcpus )
  714. __field( bool, use_master_clock )
  715. __field( unsigned int, host_clock )
  716. ),
  717. TP_fast_assign(
  718. __entry->vcpu_id = vcpu_id;
  719. __entry->nr_vcpus_matched_tsc = nr_matched;
  720. __entry->online_vcpus = online_vcpus;
  721. __entry->use_master_clock = use_master_clock;
  722. __entry->host_clock = host_clock;
  723. ),
  724. TP_printk("vcpu_id %u masterclock %u offsetmatched %u nr_online %u"
  725. " hostclock %s",
  726. __entry->vcpu_id, __entry->use_master_clock,
  727. __entry->nr_vcpus_matched_tsc, __entry->online_vcpus,
  728. __print_symbolic(__entry->host_clock, host_clocks))
  729. );
  730. #endif /* CONFIG_X86_64 */
  731. /*
  732. * Tracepoint for PML full VMEXIT.
  733. */
  734. TRACE_EVENT(kvm_pml_full,
  735. TP_PROTO(unsigned int vcpu_id),
  736. TP_ARGS(vcpu_id),
  737. TP_STRUCT__entry(
  738. __field( unsigned int, vcpu_id )
  739. ),
  740. TP_fast_assign(
  741. __entry->vcpu_id = vcpu_id;
  742. ),
  743. TP_printk("vcpu %d: PML full", __entry->vcpu_id)
  744. );
  745. TRACE_EVENT(kvm_ple_window,
  746. TP_PROTO(bool grow, unsigned int vcpu_id, int new, int old),
  747. TP_ARGS(grow, vcpu_id, new, old),
  748. TP_STRUCT__entry(
  749. __field( bool, grow )
  750. __field( unsigned int, vcpu_id )
  751. __field( int, new )
  752. __field( int, old )
  753. ),
  754. TP_fast_assign(
  755. __entry->grow = grow;
  756. __entry->vcpu_id = vcpu_id;
  757. __entry->new = new;
  758. __entry->old = old;
  759. ),
  760. TP_printk("vcpu %u: ple_window %d (%s %d)",
  761. __entry->vcpu_id,
  762. __entry->new,
  763. __entry->grow ? "grow" : "shrink",
  764. __entry->old)
  765. );
  766. #define trace_kvm_ple_window_grow(vcpu_id, new, old) \
  767. trace_kvm_ple_window(true, vcpu_id, new, old)
  768. #define trace_kvm_ple_window_shrink(vcpu_id, new, old) \
  769. trace_kvm_ple_window(false, vcpu_id, new, old)
  770. TRACE_EVENT(kvm_pvclock_update,
  771. TP_PROTO(unsigned int vcpu_id, struct pvclock_vcpu_time_info *pvclock),
  772. TP_ARGS(vcpu_id, pvclock),
  773. TP_STRUCT__entry(
  774. __field( unsigned int, vcpu_id )
  775. __field( __u32, version )
  776. __field( __u64, tsc_timestamp )
  777. __field( __u64, system_time )
  778. __field( __u32, tsc_to_system_mul )
  779. __field( __s8, tsc_shift )
  780. __field( __u8, flags )
  781. ),
  782. TP_fast_assign(
  783. __entry->vcpu_id = vcpu_id;
  784. __entry->version = pvclock->version;
  785. __entry->tsc_timestamp = pvclock->tsc_timestamp;
  786. __entry->system_time = pvclock->system_time;
  787. __entry->tsc_to_system_mul = pvclock->tsc_to_system_mul;
  788. __entry->tsc_shift = pvclock->tsc_shift;
  789. __entry->flags = pvclock->flags;
  790. ),
  791. TP_printk("vcpu_id %u, pvclock { version %u, tsc_timestamp 0x%llx, "
  792. "system_time 0x%llx, tsc_to_system_mul 0x%x, tsc_shift %d, "
  793. "flags 0x%x }",
  794. __entry->vcpu_id,
  795. __entry->version,
  796. __entry->tsc_timestamp,
  797. __entry->system_time,
  798. __entry->tsc_to_system_mul,
  799. __entry->tsc_shift,
  800. __entry->flags)
  801. );
  802. TRACE_EVENT(kvm_wait_lapic_expire,
  803. TP_PROTO(unsigned int vcpu_id, s64 delta),
  804. TP_ARGS(vcpu_id, delta),
  805. TP_STRUCT__entry(
  806. __field( unsigned int, vcpu_id )
  807. __field( s64, delta )
  808. ),
  809. TP_fast_assign(
  810. __entry->vcpu_id = vcpu_id;
  811. __entry->delta = delta;
  812. ),
  813. TP_printk("vcpu %u: delta %lld (%s)",
  814. __entry->vcpu_id,
  815. __entry->delta,
  816. __entry->delta < 0 ? "early" : "late")
  817. );
  818. TRACE_EVENT(kvm_enter_smm,
  819. TP_PROTO(unsigned int vcpu_id, u64 smbase, bool entering),
  820. TP_ARGS(vcpu_id, smbase, entering),
  821. TP_STRUCT__entry(
  822. __field( unsigned int, vcpu_id )
  823. __field( u64, smbase )
  824. __field( bool, entering )
  825. ),
  826. TP_fast_assign(
  827. __entry->vcpu_id = vcpu_id;
  828. __entry->smbase = smbase;
  829. __entry->entering = entering;
  830. ),
  831. TP_printk("vcpu %u: %s SMM, smbase 0x%llx",
  832. __entry->vcpu_id,
  833. __entry->entering ? "entering" : "leaving",
  834. __entry->smbase)
  835. );
  836. /*
  837. * Tracepoint for VT-d posted-interrupts.
  838. */
  839. TRACE_EVENT(kvm_pi_irte_update,
  840. TP_PROTO(unsigned int vcpu_id, unsigned int gsi,
  841. unsigned int gvec, u64 pi_desc_addr, bool set),
  842. TP_ARGS(vcpu_id, gsi, gvec, pi_desc_addr, set),
  843. TP_STRUCT__entry(
  844. __field( unsigned int, vcpu_id )
  845. __field( unsigned int, gsi )
  846. __field( unsigned int, gvec )
  847. __field( u64, pi_desc_addr )
  848. __field( bool, set )
  849. ),
  850. TP_fast_assign(
  851. __entry->vcpu_id = vcpu_id;
  852. __entry->gsi = gsi;
  853. __entry->gvec = gvec;
  854. __entry->pi_desc_addr = pi_desc_addr;
  855. __entry->set = set;
  856. ),
  857. TP_printk("VT-d PI is %s for this irq, vcpu %u, gsi: 0x%x, "
  858. "gvec: 0x%x, pi_desc_addr: 0x%llx",
  859. __entry->set ? "enabled and being updated" : "disabled",
  860. __entry->vcpu_id,
  861. __entry->gsi,
  862. __entry->gvec,
  863. __entry->pi_desc_addr)
  864. );
  865. #endif /* _TRACE_KVM_H */
  866. #undef TRACE_INCLUDE_PATH
  867. #define TRACE_INCLUDE_PATH arch/x86/kvm
  868. #undef TRACE_INCLUDE_FILE
  869. #define TRACE_INCLUDE_FILE trace
  870. /* This part must be outside protection */
  871. #include <trace/define_trace.h>