kvm.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. #if !defined(_TRACE_KVM_MAIN_H) || defined(TRACE_HEADER_MULTI_READ)
  2. #define _TRACE_KVM_MAIN_H
  3. #include <linux/tracepoint.h>
  4. #undef TRACE_SYSTEM
  5. #define TRACE_SYSTEM kvm
  6. #define ERSN(x) { KVM_EXIT_##x, "KVM_EXIT_" #x }
  7. #define kvm_trace_exit_reason \
  8. ERSN(UNKNOWN), ERSN(EXCEPTION), ERSN(IO), ERSN(HYPERCALL), \
  9. ERSN(DEBUG), ERSN(HLT), ERSN(MMIO), ERSN(IRQ_WINDOW_OPEN), \
  10. ERSN(SHUTDOWN), ERSN(FAIL_ENTRY), ERSN(INTR), ERSN(SET_TPR), \
  11. ERSN(TPR_ACCESS), ERSN(S390_SIEIC), ERSN(S390_RESET), ERSN(DCR),\
  12. ERSN(NMI), ERSN(INTERNAL_ERROR), ERSN(OSI), ERSN(PAPR_HCALL), \
  13. ERSN(S390_UCONTROL), ERSN(WATCHDOG), ERSN(S390_TSCH)
  14. TRACE_EVENT(kvm_userspace_exit,
  15. TP_PROTO(__u32 reason, int errno),
  16. TP_ARGS(reason, errno),
  17. TP_STRUCT__entry(
  18. __field( __u32, reason )
  19. __field( int, errno )
  20. ),
  21. TP_fast_assign(
  22. __entry->reason = reason;
  23. __entry->errno = errno;
  24. ),
  25. TP_printk("reason %s (%d)",
  26. __entry->errno < 0 ?
  27. (__entry->errno == -EINTR ? "restart" : "error") :
  28. __print_symbolic(__entry->reason, kvm_trace_exit_reason),
  29. __entry->errno < 0 ? -__entry->errno : __entry->reason)
  30. );
  31. TRACE_EVENT(kvm_vcpu_wakeup,
  32. TP_PROTO(__u64 ns, bool waited),
  33. TP_ARGS(ns, waited),
  34. TP_STRUCT__entry(
  35. __field( __u64, ns )
  36. __field( bool, waited )
  37. ),
  38. TP_fast_assign(
  39. __entry->ns = ns;
  40. __entry->waited = waited;
  41. ),
  42. TP_printk("%s time %lld ns",
  43. __entry->waited ? "wait" : "poll",
  44. __entry->ns)
  45. );
  46. #if defined(CONFIG_HAVE_KVM_IRQFD)
  47. TRACE_EVENT(kvm_set_irq,
  48. TP_PROTO(unsigned int gsi, int level, int irq_source_id),
  49. TP_ARGS(gsi, level, irq_source_id),
  50. TP_STRUCT__entry(
  51. __field( unsigned int, gsi )
  52. __field( int, level )
  53. __field( int, irq_source_id )
  54. ),
  55. TP_fast_assign(
  56. __entry->gsi = gsi;
  57. __entry->level = level;
  58. __entry->irq_source_id = irq_source_id;
  59. ),
  60. TP_printk("gsi %u level %d source %d",
  61. __entry->gsi, __entry->level, __entry->irq_source_id)
  62. );
  63. #endif /* defined(CONFIG_HAVE_KVM_IRQFD) */
  64. #if defined(__KVM_HAVE_IOAPIC)
  65. #define kvm_deliver_mode \
  66. {0x0, "Fixed"}, \
  67. {0x1, "LowPrio"}, \
  68. {0x2, "SMI"}, \
  69. {0x3, "Res3"}, \
  70. {0x4, "NMI"}, \
  71. {0x5, "INIT"}, \
  72. {0x6, "SIPI"}, \
  73. {0x7, "ExtINT"}
  74. TRACE_EVENT(kvm_ioapic_set_irq,
  75. TP_PROTO(__u64 e, int pin, bool coalesced),
  76. TP_ARGS(e, pin, coalesced),
  77. TP_STRUCT__entry(
  78. __field( __u64, e )
  79. __field( int, pin )
  80. __field( bool, coalesced )
  81. ),
  82. TP_fast_assign(
  83. __entry->e = e;
  84. __entry->pin = pin;
  85. __entry->coalesced = coalesced;
  86. ),
  87. TP_printk("pin %u dst %x vec=%u (%s|%s|%s%s)%s",
  88. __entry->pin, (u8)(__entry->e >> 56), (u8)__entry->e,
  89. __print_symbolic((__entry->e >> 8 & 0x7), kvm_deliver_mode),
  90. (__entry->e & (1<<11)) ? "logical" : "physical",
  91. (__entry->e & (1<<15)) ? "level" : "edge",
  92. (__entry->e & (1<<16)) ? "|masked" : "",
  93. __entry->coalesced ? " (coalesced)" : "")
  94. );
  95. TRACE_EVENT(kvm_ioapic_delayed_eoi_inj,
  96. TP_PROTO(__u64 e),
  97. TP_ARGS(e),
  98. TP_STRUCT__entry(
  99. __field( __u64, e )
  100. ),
  101. TP_fast_assign(
  102. __entry->e = e;
  103. ),
  104. TP_printk("dst %x vec=%u (%s|%s|%s%s)",
  105. (u8)(__entry->e >> 56), (u8)__entry->e,
  106. __print_symbolic((__entry->e >> 8 & 0x7), kvm_deliver_mode),
  107. (__entry->e & (1<<11)) ? "logical" : "physical",
  108. (__entry->e & (1<<15)) ? "level" : "edge",
  109. (__entry->e & (1<<16)) ? "|masked" : "")
  110. );
  111. TRACE_EVENT(kvm_msi_set_irq,
  112. TP_PROTO(__u64 address, __u64 data),
  113. TP_ARGS(address, data),
  114. TP_STRUCT__entry(
  115. __field( __u64, address )
  116. __field( __u64, data )
  117. ),
  118. TP_fast_assign(
  119. __entry->address = address;
  120. __entry->data = data;
  121. ),
  122. TP_printk("dst %u vec %x (%s|%s|%s%s)",
  123. (u8)(__entry->address >> 12), (u8)__entry->data,
  124. __print_symbolic((__entry->data >> 8 & 0x7), kvm_deliver_mode),
  125. (__entry->address & (1<<2)) ? "logical" : "physical",
  126. (__entry->data & (1<<15)) ? "level" : "edge",
  127. (__entry->address & (1<<3)) ? "|rh" : "")
  128. );
  129. #define kvm_irqchips \
  130. {KVM_IRQCHIP_PIC_MASTER, "PIC master"}, \
  131. {KVM_IRQCHIP_PIC_SLAVE, "PIC slave"}, \
  132. {KVM_IRQCHIP_IOAPIC, "IOAPIC"}
  133. #endif /* defined(__KVM_HAVE_IOAPIC) */
  134. #if defined(CONFIG_HAVE_KVM_IRQFD)
  135. #ifdef kvm_irqchips
  136. #define kvm_ack_irq_string "irqchip %s pin %u"
  137. #define kvm_ack_irq_parm __print_symbolic(__entry->irqchip, kvm_irqchips), __entry->pin
  138. #else
  139. #define kvm_ack_irq_string "irqchip %d pin %u"
  140. #define kvm_ack_irq_parm __entry->irqchip, __entry->pin
  141. #endif
  142. TRACE_EVENT(kvm_ack_irq,
  143. TP_PROTO(unsigned int irqchip, unsigned int pin),
  144. TP_ARGS(irqchip, pin),
  145. TP_STRUCT__entry(
  146. __field( unsigned int, irqchip )
  147. __field( unsigned int, pin )
  148. ),
  149. TP_fast_assign(
  150. __entry->irqchip = irqchip;
  151. __entry->pin = pin;
  152. ),
  153. TP_printk(kvm_ack_irq_string, kvm_ack_irq_parm)
  154. );
  155. #endif /* defined(CONFIG_HAVE_KVM_IRQFD) */
  156. #define KVM_TRACE_MMIO_READ_UNSATISFIED 0
  157. #define KVM_TRACE_MMIO_READ 1
  158. #define KVM_TRACE_MMIO_WRITE 2
  159. #define kvm_trace_symbol_mmio \
  160. { KVM_TRACE_MMIO_READ_UNSATISFIED, "unsatisfied-read" }, \
  161. { KVM_TRACE_MMIO_READ, "read" }, \
  162. { KVM_TRACE_MMIO_WRITE, "write" }
  163. TRACE_EVENT(kvm_mmio,
  164. TP_PROTO(int type, int len, u64 gpa, void *val),
  165. TP_ARGS(type, len, gpa, val),
  166. TP_STRUCT__entry(
  167. __field( u32, type )
  168. __field( u32, len )
  169. __field( u64, gpa )
  170. __field( u64, val )
  171. ),
  172. TP_fast_assign(
  173. __entry->type = type;
  174. __entry->len = len;
  175. __entry->gpa = gpa;
  176. __entry->val = 0;
  177. if (val)
  178. memcpy(&__entry->val, val,
  179. min_t(u32, sizeof(__entry->val), len));
  180. ),
  181. TP_printk("mmio %s len %u gpa 0x%llx val 0x%llx",
  182. __print_symbolic(__entry->type, kvm_trace_symbol_mmio),
  183. __entry->len, __entry->gpa, __entry->val)
  184. );
  185. #define kvm_fpu_load_symbol \
  186. {0, "unload"}, \
  187. {1, "load"}
  188. TRACE_EVENT(kvm_fpu,
  189. TP_PROTO(int load),
  190. TP_ARGS(load),
  191. TP_STRUCT__entry(
  192. __field( u32, load )
  193. ),
  194. TP_fast_assign(
  195. __entry->load = load;
  196. ),
  197. TP_printk("%s", __print_symbolic(__entry->load, kvm_fpu_load_symbol))
  198. );
  199. TRACE_EVENT(kvm_age_page,
  200. TP_PROTO(ulong gfn, int level, struct kvm_memory_slot *slot, int ref),
  201. TP_ARGS(gfn, level, slot, ref),
  202. TP_STRUCT__entry(
  203. __field( u64, hva )
  204. __field( u64, gfn )
  205. __field( u8, level )
  206. __field( u8, referenced )
  207. ),
  208. TP_fast_assign(
  209. __entry->gfn = gfn;
  210. __entry->level = level;
  211. __entry->hva = ((gfn - slot->base_gfn) <<
  212. PAGE_SHIFT) + slot->userspace_addr;
  213. __entry->referenced = ref;
  214. ),
  215. TP_printk("hva %llx gfn %llx level %u %s",
  216. __entry->hva, __entry->gfn, __entry->level,
  217. __entry->referenced ? "YOUNG" : "OLD")
  218. );
  219. #ifdef CONFIG_KVM_ASYNC_PF
  220. DECLARE_EVENT_CLASS(kvm_async_get_page_class,
  221. TP_PROTO(u64 gva, u64 gfn),
  222. TP_ARGS(gva, gfn),
  223. TP_STRUCT__entry(
  224. __field(__u64, gva)
  225. __field(u64, gfn)
  226. ),
  227. TP_fast_assign(
  228. __entry->gva = gva;
  229. __entry->gfn = gfn;
  230. ),
  231. TP_printk("gva = %#llx, gfn = %#llx", __entry->gva, __entry->gfn)
  232. );
  233. DEFINE_EVENT(kvm_async_get_page_class, kvm_try_async_get_page,
  234. TP_PROTO(u64 gva, u64 gfn),
  235. TP_ARGS(gva, gfn)
  236. );
  237. DEFINE_EVENT(kvm_async_get_page_class, kvm_async_pf_doublefault,
  238. TP_PROTO(u64 gva, u64 gfn),
  239. TP_ARGS(gva, gfn)
  240. );
  241. DECLARE_EVENT_CLASS(kvm_async_pf_nopresent_ready,
  242. TP_PROTO(u64 token, u64 gva),
  243. TP_ARGS(token, gva),
  244. TP_STRUCT__entry(
  245. __field(__u64, token)
  246. __field(__u64, gva)
  247. ),
  248. TP_fast_assign(
  249. __entry->token = token;
  250. __entry->gva = gva;
  251. ),
  252. TP_printk("token %#llx gva %#llx", __entry->token, __entry->gva)
  253. );
  254. DEFINE_EVENT(kvm_async_pf_nopresent_ready, kvm_async_pf_not_present,
  255. TP_PROTO(u64 token, u64 gva),
  256. TP_ARGS(token, gva)
  257. );
  258. DEFINE_EVENT(kvm_async_pf_nopresent_ready, kvm_async_pf_ready,
  259. TP_PROTO(u64 token, u64 gva),
  260. TP_ARGS(token, gva)
  261. );
  262. TRACE_EVENT(
  263. kvm_async_pf_completed,
  264. TP_PROTO(unsigned long address, u64 gva),
  265. TP_ARGS(address, gva),
  266. TP_STRUCT__entry(
  267. __field(unsigned long, address)
  268. __field(u64, gva)
  269. ),
  270. TP_fast_assign(
  271. __entry->address = address;
  272. __entry->gva = gva;
  273. ),
  274. TP_printk("gva %#llx address %#lx", __entry->gva,
  275. __entry->address)
  276. );
  277. #endif
  278. TRACE_EVENT(kvm_halt_poll_ns,
  279. TP_PROTO(bool grow, unsigned int vcpu_id, int new, int old),
  280. TP_ARGS(grow, vcpu_id, new, old),
  281. TP_STRUCT__entry(
  282. __field(bool, grow)
  283. __field(unsigned int, vcpu_id)
  284. __field(int, new)
  285. __field(int, old)
  286. ),
  287. TP_fast_assign(
  288. __entry->grow = grow;
  289. __entry->vcpu_id = vcpu_id;
  290. __entry->new = new;
  291. __entry->old = old;
  292. ),
  293. TP_printk("vcpu %u: halt_poll_ns %d (%s %d)",
  294. __entry->vcpu_id,
  295. __entry->new,
  296. __entry->grow ? "grow" : "shrink",
  297. __entry->old)
  298. );
  299. #define trace_kvm_halt_poll_ns_grow(vcpu_id, new, old) \
  300. trace_kvm_halt_poll_ns(true, vcpu_id, new, old)
  301. #define trace_kvm_halt_poll_ns_shrink(vcpu_id, new, old) \
  302. trace_kvm_halt_poll_ns(false, vcpu_id, new, old)
  303. #endif /* _TRACE_KVM_MAIN_H */
  304. /* This part must be outside protection */
  305. #include <trace/define_trace.h>