trace.h 18 KB

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