Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 1 | #if !defined(_TRACE_KVMMMU_H) || defined(TRACE_HEADER_MULTI_READ) |
| 2 | #define _TRACE_KVMMMU_H |
| 3 | |
| 4 | #include <linux/tracepoint.h> |
Steven Rostedt (Red Hat) | af658dc | 2015-04-29 14:36:05 -0400 | [diff] [blame] | 5 | #include <linux/trace_events.h> |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 6 | |
| 7 | #undef TRACE_SYSTEM |
| 8 | #define TRACE_SYSTEM kvmmmu |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 9 | |
Xiao Guangrong | 2248b02 | 2013-05-31 08:36:24 +0800 | [diff] [blame] | 10 | #define KVM_MMU_PAGE_FIELDS \ |
| 11 | __field(unsigned long, mmu_valid_gen) \ |
| 12 | __field(__u64, gfn) \ |
| 13 | __field(__u32, role) \ |
| 14 | __field(__u32, root_count) \ |
Gui Jianfeng | df2fb6e | 2010-04-22 17:33:57 +0800 | [diff] [blame] | 15 | __field(bool, unsync) |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 16 | |
Xiao Guangrong | 2248b02 | 2013-05-31 08:36:24 +0800 | [diff] [blame] | 17 | #define KVM_MMU_PAGE_ASSIGN(sp) \ |
| 18 | __entry->mmu_valid_gen = sp->mmu_valid_gen; \ |
| 19 | __entry->gfn = sp->gfn; \ |
| 20 | __entry->role = sp->role.word; \ |
| 21 | __entry->root_count = sp->root_count; \ |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 22 | __entry->unsync = sp->unsync; |
| 23 | |
| 24 | #define KVM_MMU_PAGE_PRINTK() ({ \ |
Steven Rostedt (Red Hat) | 467aa1f | 2014-09-24 18:52:39 -0400 | [diff] [blame] | 25 | const char *saved_ptr = trace_seq_buffer_ptr(p); \ |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 26 | static const char *access_str[] = { \ |
| 27 | "---", "--x", "w--", "w-x", "-u-", "-ux", "wu-", "wux" \ |
| 28 | }; \ |
| 29 | union kvm_mmu_page_role role; \ |
| 30 | \ |
| 31 | role.word = __entry->role; \ |
| 32 | \ |
Xiao Guangrong | 2248b02 | 2013-05-31 08:36:24 +0800 | [diff] [blame] | 33 | trace_seq_printf(p, "sp gen %lx gfn %llx %u%s q%u%s %s%s" \ |
| 34 | " %snxe root %u %s%c", __entry->mmu_valid_gen, \ |
Avi Kivity | 5b7e010 | 2010-04-14 19:20:03 +0300 | [diff] [blame] | 35 | __entry->gfn, role.level, \ |
| 36 | role.cr4_pae ? " pae" : "", \ |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 37 | role.quadrant, \ |
| 38 | role.direct ? " direct" : "", \ |
| 39 | access_str[role.access], \ |
| 40 | role.invalid ? " invalid" : "", \ |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 41 | role.nxe ? "" : "!", \ |
| 42 | __entry->root_count, \ |
| 43 | __entry->unsync ? "unsync" : "sync", 0); \ |
Steven Rostedt (Red Hat) | 467aa1f | 2014-09-24 18:52:39 -0400 | [diff] [blame] | 44 | saved_ptr; \ |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 45 | }) |
| 46 | |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 47 | #define kvm_mmu_trace_pferr_flags \ |
| 48 | { PFERR_PRESENT_MASK, "P" }, \ |
| 49 | { PFERR_WRITE_MASK, "W" }, \ |
| 50 | { PFERR_USER_MASK, "U" }, \ |
| 51 | { PFERR_RSVD_MASK, "RSVD" }, \ |
| 52 | { PFERR_FETCH_MASK, "F" } |
| 53 | |
| 54 | /* |
| 55 | * A pagetable walk has started |
| 56 | */ |
| 57 | TRACE_EVENT( |
| 58 | kvm_mmu_pagetable_walk, |
Xiao Guangrong | 6fbc277 | 2012-06-20 16:00:00 +0800 | [diff] [blame] | 59 | TP_PROTO(u64 addr, u32 pferr), |
| 60 | TP_ARGS(addr, pferr), |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 61 | |
| 62 | TP_STRUCT__entry( |
| 63 | __field(__u64, addr) |
| 64 | __field(__u32, pferr) |
| 65 | ), |
| 66 | |
| 67 | TP_fast_assign( |
| 68 | __entry->addr = addr; |
Xiao Guangrong | 6fbc277 | 2012-06-20 16:00:00 +0800 | [diff] [blame] | 69 | __entry->pferr = pferr; |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 70 | ), |
| 71 | |
| 72 | TP_printk("addr %llx pferr %x %s", __entry->addr, __entry->pferr, |
| 73 | __print_flags(__entry->pferr, "|", kvm_mmu_trace_pferr_flags)) |
| 74 | ); |
| 75 | |
| 76 | |
| 77 | /* We just walked a paging element */ |
| 78 | TRACE_EVENT( |
| 79 | kvm_mmu_paging_element, |
| 80 | TP_PROTO(u64 pte, int level), |
| 81 | TP_ARGS(pte, level), |
| 82 | |
| 83 | TP_STRUCT__entry( |
| 84 | __field(__u64, pte) |
| 85 | __field(__u32, level) |
| 86 | ), |
| 87 | |
| 88 | TP_fast_assign( |
| 89 | __entry->pte = pte; |
| 90 | __entry->level = level; |
| 91 | ), |
| 92 | |
| 93 | TP_printk("pte %llx level %u", __entry->pte, __entry->level) |
| 94 | ); |
| 95 | |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 96 | DECLARE_EVENT_CLASS(kvm_mmu_set_bit_class, |
| 97 | |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 98 | TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size), |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 99 | |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 100 | TP_ARGS(table_gfn, index, size), |
| 101 | |
| 102 | TP_STRUCT__entry( |
| 103 | __field(__u64, gpa) |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 104 | ), |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 105 | |
| 106 | TP_fast_assign( |
| 107 | __entry->gpa = ((u64)table_gfn << PAGE_SHIFT) |
| 108 | + index * size; |
| 109 | ), |
| 110 | |
| 111 | TP_printk("gpa %llx", __entry->gpa) |
| 112 | ); |
| 113 | |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 114 | /* We set a pte accessed bit */ |
| 115 | DEFINE_EVENT(kvm_mmu_set_bit_class, kvm_mmu_set_accessed_bit, |
| 116 | |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 117 | TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size), |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 118 | |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 119 | TP_ARGS(table_gfn, index, size) |
| 120 | ); |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 121 | |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 122 | /* We set a pte dirty bit */ |
| 123 | DEFINE_EVENT(kvm_mmu_set_bit_class, kvm_mmu_set_dirty_bit, |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 124 | |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 125 | TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size), |
| 126 | |
| 127 | TP_ARGS(table_gfn, index, size) |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 128 | ); |
| 129 | |
| 130 | TRACE_EVENT( |
| 131 | kvm_mmu_walker_error, |
| 132 | TP_PROTO(u32 pferr), |
| 133 | TP_ARGS(pferr), |
| 134 | |
| 135 | TP_STRUCT__entry( |
| 136 | __field(__u32, pferr) |
| 137 | ), |
| 138 | |
| 139 | TP_fast_assign( |
| 140 | __entry->pferr = pferr; |
| 141 | ), |
| 142 | |
| 143 | TP_printk("pferr %x %s", __entry->pferr, |
| 144 | __print_flags(__entry->pferr, "|", kvm_mmu_trace_pferr_flags)) |
| 145 | ); |
| 146 | |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 147 | TRACE_EVENT( |
| 148 | kvm_mmu_get_page, |
| 149 | TP_PROTO(struct kvm_mmu_page *sp, bool created), |
| 150 | TP_ARGS(sp, created), |
| 151 | |
| 152 | TP_STRUCT__entry( |
| 153 | KVM_MMU_PAGE_FIELDS |
| 154 | __field(bool, created) |
| 155 | ), |
| 156 | |
| 157 | TP_fast_assign( |
| 158 | KVM_MMU_PAGE_ASSIGN(sp) |
| 159 | __entry->created = created; |
| 160 | ), |
| 161 | |
| 162 | TP_printk("%s %s", KVM_MMU_PAGE_PRINTK(), |
| 163 | __entry->created ? "new" : "existing") |
| 164 | ); |
| 165 | |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 166 | DECLARE_EVENT_CLASS(kvm_mmu_page_class, |
| 167 | |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 168 | TP_PROTO(struct kvm_mmu_page *sp), |
| 169 | TP_ARGS(sp), |
| 170 | |
| 171 | TP_STRUCT__entry( |
| 172 | KVM_MMU_PAGE_FIELDS |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 173 | ), |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 174 | |
| 175 | TP_fast_assign( |
| 176 | KVM_MMU_PAGE_ASSIGN(sp) |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 177 | ), |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 178 | |
| 179 | TP_printk("%s", KVM_MMU_PAGE_PRINTK()) |
| 180 | ); |
| 181 | |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 182 | DEFINE_EVENT(kvm_mmu_page_class, kvm_mmu_sync_page, |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 183 | TP_PROTO(struct kvm_mmu_page *sp), |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 184 | |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 185 | TP_ARGS(sp) |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 186 | ); |
| 187 | |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 188 | DEFINE_EVENT(kvm_mmu_page_class, kvm_mmu_unsync_page, |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 189 | TP_PROTO(struct kvm_mmu_page *sp), |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 190 | |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 191 | TP_ARGS(sp) |
Avi Kivity | f691fe1 | 2009-07-06 15:58:14 +0300 | [diff] [blame] | 192 | ); |
| 193 | |
Xiao Guangrong | 7775834 | 2010-06-04 21:53:54 +0800 | [diff] [blame] | 194 | DEFINE_EVENT(kvm_mmu_page_class, kvm_mmu_prepare_zap_page, |
Xiao Guangrong | 85f2067 | 2010-04-28 11:54:55 +0800 | [diff] [blame] | 195 | TP_PROTO(struct kvm_mmu_page *sp), |
| 196 | |
| 197 | TP_ARGS(sp) |
| 198 | ); |
Xiao Guangrong | 8b1fe17 | 2010-08-30 18:22:53 +0800 | [diff] [blame] | 199 | |
Xiao Guangrong | 4f02264 | 2011-07-12 03:34:24 +0800 | [diff] [blame] | 200 | TRACE_EVENT( |
| 201 | mark_mmio_spte, |
Xiao Guangrong | f2fd125 | 2013-06-07 16:51:24 +0800 | [diff] [blame] | 202 | TP_PROTO(u64 *sptep, gfn_t gfn, unsigned access, unsigned int gen), |
| 203 | TP_ARGS(sptep, gfn, access, gen), |
Xiao Guangrong | 4f02264 | 2011-07-12 03:34:24 +0800 | [diff] [blame] | 204 | |
| 205 | TP_STRUCT__entry( |
| 206 | __field(void *, sptep) |
| 207 | __field(gfn_t, gfn) |
| 208 | __field(unsigned, access) |
Xiao Guangrong | f2fd125 | 2013-06-07 16:51:24 +0800 | [diff] [blame] | 209 | __field(unsigned int, gen) |
Xiao Guangrong | 4f02264 | 2011-07-12 03:34:24 +0800 | [diff] [blame] | 210 | ), |
| 211 | |
| 212 | TP_fast_assign( |
| 213 | __entry->sptep = sptep; |
| 214 | __entry->gfn = gfn; |
| 215 | __entry->access = access; |
Xiao Guangrong | f2fd125 | 2013-06-07 16:51:24 +0800 | [diff] [blame] | 216 | __entry->gen = gen; |
Xiao Guangrong | 4f02264 | 2011-07-12 03:34:24 +0800 | [diff] [blame] | 217 | ), |
| 218 | |
Xiao Guangrong | f2fd125 | 2013-06-07 16:51:24 +0800 | [diff] [blame] | 219 | TP_printk("sptep:%p gfn %llx access %x gen %x", __entry->sptep, |
| 220 | __entry->gfn, __entry->access, __entry->gen) |
Xiao Guangrong | 4f02264 | 2011-07-12 03:34:24 +0800 | [diff] [blame] | 221 | ); |
| 222 | |
| 223 | TRACE_EVENT( |
| 224 | handle_mmio_page_fault, |
| 225 | TP_PROTO(u64 addr, gfn_t gfn, unsigned access), |
| 226 | TP_ARGS(addr, gfn, access), |
| 227 | |
| 228 | TP_STRUCT__entry( |
| 229 | __field(u64, addr) |
| 230 | __field(gfn_t, gfn) |
| 231 | __field(unsigned, access) |
| 232 | ), |
| 233 | |
| 234 | TP_fast_assign( |
| 235 | __entry->addr = addr; |
| 236 | __entry->gfn = gfn; |
| 237 | __entry->access = access; |
| 238 | ), |
| 239 | |
| 240 | TP_printk("addr:%llx gfn %llx access %x", __entry->addr, __entry->gfn, |
| 241 | __entry->access) |
| 242 | ); |
Xiao Guangrong | a72faf2 | 2012-06-20 15:59:41 +0800 | [diff] [blame] | 243 | |
| 244 | #define __spte_satisfied(__spte) \ |
| 245 | (__entry->retry && is_writable_pte(__entry->__spte)) |
| 246 | |
| 247 | TRACE_EVENT( |
| 248 | fast_page_fault, |
| 249 | TP_PROTO(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code, |
| 250 | u64 *sptep, u64 old_spte, bool retry), |
| 251 | TP_ARGS(vcpu, gva, error_code, sptep, old_spte, retry), |
| 252 | |
| 253 | TP_STRUCT__entry( |
| 254 | __field(int, vcpu_id) |
| 255 | __field(gva_t, gva) |
| 256 | __field(u32, error_code) |
| 257 | __field(u64 *, sptep) |
| 258 | __field(u64, old_spte) |
| 259 | __field(u64, new_spte) |
| 260 | __field(bool, retry) |
| 261 | ), |
| 262 | |
| 263 | TP_fast_assign( |
| 264 | __entry->vcpu_id = vcpu->vcpu_id; |
| 265 | __entry->gva = gva; |
| 266 | __entry->error_code = error_code; |
| 267 | __entry->sptep = sptep; |
| 268 | __entry->old_spte = old_spte; |
| 269 | __entry->new_spte = *sptep; |
| 270 | __entry->retry = retry; |
| 271 | ), |
| 272 | |
| 273 | TP_printk("vcpu %d gva %lx error_code %s sptep %p old %#llx" |
| 274 | " new %llx spurious %d fixed %d", __entry->vcpu_id, |
| 275 | __entry->gva, __print_flags(__entry->error_code, "|", |
| 276 | kvm_mmu_trace_pferr_flags), __entry->sptep, |
| 277 | __entry->old_spte, __entry->new_spte, |
| 278 | __spte_satisfied(old_spte), __spte_satisfied(new_spte) |
| 279 | ) |
| 280 | ); |
Xiao Guangrong | 3500612 | 2013-05-31 08:36:25 +0800 | [diff] [blame] | 281 | |
| 282 | TRACE_EVENT( |
| 283 | kvm_mmu_invalidate_zap_all_pages, |
| 284 | TP_PROTO(struct kvm *kvm), |
| 285 | TP_ARGS(kvm), |
| 286 | |
| 287 | TP_STRUCT__entry( |
| 288 | __field(unsigned long, mmu_valid_gen) |
| 289 | __field(unsigned int, mmu_used_pages) |
| 290 | ), |
| 291 | |
| 292 | TP_fast_assign( |
| 293 | __entry->mmu_valid_gen = kvm->arch.mmu_valid_gen; |
| 294 | __entry->mmu_used_pages = kvm->arch.n_used_mmu_pages; |
| 295 | ), |
| 296 | |
| 297 | TP_printk("kvm-mmu-valid-gen %lx used_pages %x", |
| 298 | __entry->mmu_valid_gen, __entry->mmu_used_pages |
| 299 | ) |
| 300 | ); |
Xiao Guangrong | 089504c | 2013-06-07 16:51:27 +0800 | [diff] [blame] | 301 | |
| 302 | |
| 303 | TRACE_EVENT( |
| 304 | check_mmio_spte, |
| 305 | TP_PROTO(u64 spte, unsigned int kvm_gen, unsigned int spte_gen), |
| 306 | TP_ARGS(spte, kvm_gen, spte_gen), |
| 307 | |
| 308 | TP_STRUCT__entry( |
| 309 | __field(unsigned int, kvm_gen) |
| 310 | __field(unsigned int, spte_gen) |
| 311 | __field(u64, spte) |
| 312 | ), |
| 313 | |
| 314 | TP_fast_assign( |
| 315 | __entry->kvm_gen = kvm_gen; |
| 316 | __entry->spte_gen = spte_gen; |
| 317 | __entry->spte = spte; |
| 318 | ), |
| 319 | |
| 320 | TP_printk("spte %llx kvm_gen %x spte-gen %x valid %d", __entry->spte, |
| 321 | __entry->kvm_gen, __entry->spte_gen, |
| 322 | __entry->kvm_gen == __entry->spte_gen |
| 323 | ) |
| 324 | ); |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 325 | #endif /* _TRACE_KVMMMU_H */ |
| 326 | |
Xiao Guangrong | 2ed152a | 2010-03-10 19:00:43 +0800 | [diff] [blame] | 327 | #undef TRACE_INCLUDE_PATH |
| 328 | #define TRACE_INCLUDE_PATH . |
| 329 | #undef TRACE_INCLUDE_FILE |
| 330 | #define TRACE_INCLUDE_FILE mmutrace |
| 331 | |
Avi Kivity | 0742017 | 2009-07-06 12:21:32 +0300 | [diff] [blame] | 332 | /* This part must be outside protection */ |
| 333 | #include <trace/define_trace.h> |