mmutrace.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #if !defined(_TRACE_KVMMMU_H) || defined(TRACE_HEADER_MULTI_READ)
  2. #define _TRACE_KVMMMU_H
  3. #include <linux/tracepoint.h>
  4. #include <linux/ftrace_event.h>
  5. #undef TRACE_SYSTEM
  6. #define TRACE_SYSTEM kvmmmu
  7. #define KVM_MMU_PAGE_FIELDS \
  8. __field(__u64, gfn) \
  9. __field(__u32, role) \
  10. __field(__u32, root_count) \
  11. __field(bool, unsync)
  12. #define KVM_MMU_PAGE_ASSIGN(sp) \
  13. __entry->gfn = sp->gfn; \
  14. __entry->role = sp->role.word; \
  15. __entry->root_count = sp->root_count; \
  16. __entry->unsync = sp->unsync;
  17. #define KVM_MMU_PAGE_PRINTK() ({ \
  18. const char *ret = p->buffer + p->len; \
  19. static const char *access_str[] = { \
  20. "---", "--x", "w--", "w-x", "-u-", "-ux", "wu-", "wux" \
  21. }; \
  22. union kvm_mmu_page_role role; \
  23. \
  24. role.word = __entry->role; \
  25. \
  26. trace_seq_printf(p, "sp gfn %llx %u%s q%u%s %s%s" \
  27. " %snxe root %u %s%c", \
  28. __entry->gfn, role.level, \
  29. role.cr4_pae ? " pae" : "", \
  30. role.quadrant, \
  31. role.direct ? " direct" : "", \
  32. access_str[role.access], \
  33. role.invalid ? " invalid" : "", \
  34. role.nxe ? "" : "!", \
  35. __entry->root_count, \
  36. __entry->unsync ? "unsync" : "sync", 0); \
  37. ret; \
  38. })
  39. #define kvm_mmu_trace_pferr_flags \
  40. { PFERR_PRESENT_MASK, "P" }, \
  41. { PFERR_WRITE_MASK, "W" }, \
  42. { PFERR_USER_MASK, "U" }, \
  43. { PFERR_RSVD_MASK, "RSVD" }, \
  44. { PFERR_FETCH_MASK, "F" }
  45. /*
  46. * A pagetable walk has started
  47. */
  48. TRACE_EVENT(
  49. kvm_mmu_pagetable_walk,
  50. TP_PROTO(u64 addr, int write_fault, int user_fault, int fetch_fault),
  51. TP_ARGS(addr, write_fault, user_fault, fetch_fault),
  52. TP_STRUCT__entry(
  53. __field(__u64, addr)
  54. __field(__u32, pferr)
  55. ),
  56. TP_fast_assign(
  57. __entry->addr = addr;
  58. __entry->pferr = (!!write_fault << 1) | (!!user_fault << 2)
  59. | (!!fetch_fault << 4);
  60. ),
  61. TP_printk("addr %llx pferr %x %s", __entry->addr, __entry->pferr,
  62. __print_flags(__entry->pferr, "|", kvm_mmu_trace_pferr_flags))
  63. );
  64. /* We just walked a paging element */
  65. TRACE_EVENT(
  66. kvm_mmu_paging_element,
  67. TP_PROTO(u64 pte, int level),
  68. TP_ARGS(pte, level),
  69. TP_STRUCT__entry(
  70. __field(__u64, pte)
  71. __field(__u32, level)
  72. ),
  73. TP_fast_assign(
  74. __entry->pte = pte;
  75. __entry->level = level;
  76. ),
  77. TP_printk("pte %llx level %u", __entry->pte, __entry->level)
  78. );
  79. DECLARE_EVENT_CLASS(kvm_mmu_set_bit_class,
  80. TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size),
  81. TP_ARGS(table_gfn, index, size),
  82. TP_STRUCT__entry(
  83. __field(__u64, gpa)
  84. ),
  85. TP_fast_assign(
  86. __entry->gpa = ((u64)table_gfn << PAGE_SHIFT)
  87. + index * size;
  88. ),
  89. TP_printk("gpa %llx", __entry->gpa)
  90. );
  91. /* We set a pte accessed bit */
  92. DEFINE_EVENT(kvm_mmu_set_bit_class, kvm_mmu_set_accessed_bit,
  93. TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size),
  94. TP_ARGS(table_gfn, index, size)
  95. );
  96. /* We set a pte dirty bit */
  97. DEFINE_EVENT(kvm_mmu_set_bit_class, kvm_mmu_set_dirty_bit,
  98. TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size),
  99. TP_ARGS(table_gfn, index, size)
  100. );
  101. TRACE_EVENT(
  102. kvm_mmu_walker_error,
  103. TP_PROTO(u32 pferr),
  104. TP_ARGS(pferr),
  105. TP_STRUCT__entry(
  106. __field(__u32, pferr)
  107. ),
  108. TP_fast_assign(
  109. __entry->pferr = pferr;
  110. ),
  111. TP_printk("pferr %x %s", __entry->pferr,
  112. __print_flags(__entry->pferr, "|", kvm_mmu_trace_pferr_flags))
  113. );
  114. TRACE_EVENT(
  115. kvm_mmu_get_page,
  116. TP_PROTO(struct kvm_mmu_page *sp, bool created),
  117. TP_ARGS(sp, created),
  118. TP_STRUCT__entry(
  119. KVM_MMU_PAGE_FIELDS
  120. __field(bool, created)
  121. ),
  122. TP_fast_assign(
  123. KVM_MMU_PAGE_ASSIGN(sp)
  124. __entry->created = created;
  125. ),
  126. TP_printk("%s %s", KVM_MMU_PAGE_PRINTK(),
  127. __entry->created ? "new" : "existing")
  128. );
  129. DECLARE_EVENT_CLASS(kvm_mmu_page_class,
  130. TP_PROTO(struct kvm_mmu_page *sp),
  131. TP_ARGS(sp),
  132. TP_STRUCT__entry(
  133. KVM_MMU_PAGE_FIELDS
  134. ),
  135. TP_fast_assign(
  136. KVM_MMU_PAGE_ASSIGN(sp)
  137. ),
  138. TP_printk("%s", KVM_MMU_PAGE_PRINTK())
  139. );
  140. DEFINE_EVENT(kvm_mmu_page_class, kvm_mmu_sync_page,
  141. TP_PROTO(struct kvm_mmu_page *sp),
  142. TP_ARGS(sp)
  143. );
  144. DEFINE_EVENT(kvm_mmu_page_class, kvm_mmu_unsync_page,
  145. TP_PROTO(struct kvm_mmu_page *sp),
  146. TP_ARGS(sp)
  147. );
  148. DEFINE_EVENT(kvm_mmu_page_class, kvm_mmu_prepare_zap_page,
  149. TP_PROTO(struct kvm_mmu_page *sp),
  150. TP_ARGS(sp)
  151. );
  152. TRACE_EVENT(
  153. kvm_mmu_audit,
  154. TP_PROTO(struct kvm_vcpu *vcpu, int audit_point),
  155. TP_ARGS(vcpu, audit_point),
  156. TP_STRUCT__entry(
  157. __field(struct kvm_vcpu *, vcpu)
  158. __field(int, audit_point)
  159. ),
  160. TP_fast_assign(
  161. __entry->vcpu = vcpu;
  162. __entry->audit_point = audit_point;
  163. ),
  164. TP_printk("vcpu:%d %s", __entry->vcpu->cpu,
  165. audit_point_name[__entry->audit_point])
  166. );
  167. #endif /* _TRACE_KVMMMU_H */
  168. #undef TRACE_INCLUDE_PATH
  169. #define TRACE_INCLUDE_PATH .
  170. #undef TRACE_INCLUDE_FILE
  171. #define TRACE_INCLUDE_FILE mmutrace
  172. /* This part must be outside protection */
  173. #include <trace/define_trace.h>