blob: 5a24b846a1cb8cf2d7d66bcdb275c50c2f483626 [file] [log] [blame]
Avi Kivity07420172009-07-06 12:21:32 +03001#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)af658dc2015-04-29 14:36:05 -04005#include <linux/trace_events.h>
Avi Kivity07420172009-07-06 12:21:32 +03006
7#undef TRACE_SYSTEM
8#define TRACE_SYSTEM kvmmmu
Avi Kivity07420172009-07-06 12:21:32 +03009
Xiao Guangrong2248b022013-05-31 08:36:24 +080010#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 Jianfengdf2fb6e2010-04-22 17:33:57 +080015 __field(bool, unsync)
Avi Kivityf691fe12009-07-06 15:58:14 +030016
Xiao Guangrong2248b022013-05-31 08:36:24 +080017#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 Kivityf691fe12009-07-06 15:58:14 +030022 __entry->unsync = sp->unsync;
23
24#define KVM_MMU_PAGE_PRINTK() ({ \
Steven Rostedt (Red Hat)467aa1f2014-09-24 18:52:39 -040025 const char *saved_ptr = trace_seq_buffer_ptr(p); \
Avi Kivityf691fe12009-07-06 15:58:14 +030026 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 Guangrong2248b022013-05-31 08:36:24 +080033 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 Kivity5b7e0102010-04-14 19:20:03 +030035 __entry->gfn, role.level, \
36 role.cr4_pae ? " pae" : "", \
Avi Kivityf691fe12009-07-06 15:58:14 +030037 role.quadrant, \
38 role.direct ? " direct" : "", \
39 access_str[role.access], \
40 role.invalid ? " invalid" : "", \
Avi Kivityf691fe12009-07-06 15:58:14 +030041 role.nxe ? "" : "!", \
42 __entry->root_count, \
43 __entry->unsync ? "unsync" : "sync", 0); \
Steven Rostedt (Red Hat)467aa1f2014-09-24 18:52:39 -040044 saved_ptr; \
Avi Kivityf691fe12009-07-06 15:58:14 +030045 })
46
Avi Kivity07420172009-07-06 12:21:32 +030047#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 */
57TRACE_EVENT(
58 kvm_mmu_pagetable_walk,
Xiao Guangrong6fbc2772012-06-20 16:00:00 +080059 TP_PROTO(u64 addr, u32 pferr),
60 TP_ARGS(addr, pferr),
Avi Kivity07420172009-07-06 12:21:32 +030061
62 TP_STRUCT__entry(
63 __field(__u64, addr)
64 __field(__u32, pferr)
65 ),
66
67 TP_fast_assign(
68 __entry->addr = addr;
Xiao Guangrong6fbc2772012-06-20 16:00:00 +080069 __entry->pferr = pferr;
Avi Kivity07420172009-07-06 12:21:32 +030070 ),
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 */
78TRACE_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 Guangrong85f20672010-04-28 11:54:55 +080096DECLARE_EVENT_CLASS(kvm_mmu_set_bit_class,
97
Avi Kivity07420172009-07-06 12:21:32 +030098 TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size),
Xiao Guangrong85f20672010-04-28 11:54:55 +080099
Avi Kivity07420172009-07-06 12:21:32 +0300100 TP_ARGS(table_gfn, index, size),
101
102 TP_STRUCT__entry(
103 __field(__u64, gpa)
Xiao Guangrong85f20672010-04-28 11:54:55 +0800104 ),
Avi Kivity07420172009-07-06 12:21:32 +0300105
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 Guangrong85f20672010-04-28 11:54:55 +0800114/* We set a pte accessed bit */
115DEFINE_EVENT(kvm_mmu_set_bit_class, kvm_mmu_set_accessed_bit,
116
Avi Kivity07420172009-07-06 12:21:32 +0300117 TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size),
Avi Kivity07420172009-07-06 12:21:32 +0300118
Xiao Guangrong85f20672010-04-28 11:54:55 +0800119 TP_ARGS(table_gfn, index, size)
120);
Avi Kivity07420172009-07-06 12:21:32 +0300121
Xiao Guangrong85f20672010-04-28 11:54:55 +0800122/* We set a pte dirty bit */
123DEFINE_EVENT(kvm_mmu_set_bit_class, kvm_mmu_set_dirty_bit,
Avi Kivity07420172009-07-06 12:21:32 +0300124
Xiao Guangrong85f20672010-04-28 11:54:55 +0800125 TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size),
126
127 TP_ARGS(table_gfn, index, size)
Avi Kivity07420172009-07-06 12:21:32 +0300128);
129
130TRACE_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 Kivityf691fe12009-07-06 15:58:14 +0300147TRACE_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 Guangrong85f20672010-04-28 11:54:55 +0800166DECLARE_EVENT_CLASS(kvm_mmu_page_class,
167
Avi Kivityf691fe12009-07-06 15:58:14 +0300168 TP_PROTO(struct kvm_mmu_page *sp),
169 TP_ARGS(sp),
170
171 TP_STRUCT__entry(
172 KVM_MMU_PAGE_FIELDS
Xiao Guangrong85f20672010-04-28 11:54:55 +0800173 ),
Avi Kivityf691fe12009-07-06 15:58:14 +0300174
175 TP_fast_assign(
176 KVM_MMU_PAGE_ASSIGN(sp)
Xiao Guangrong85f20672010-04-28 11:54:55 +0800177 ),
Avi Kivityf691fe12009-07-06 15:58:14 +0300178
179 TP_printk("%s", KVM_MMU_PAGE_PRINTK())
180);
181
Xiao Guangrong85f20672010-04-28 11:54:55 +0800182DEFINE_EVENT(kvm_mmu_page_class, kvm_mmu_sync_page,
Avi Kivityf691fe12009-07-06 15:58:14 +0300183 TP_PROTO(struct kvm_mmu_page *sp),
Avi Kivityf691fe12009-07-06 15:58:14 +0300184
Xiao Guangrong85f20672010-04-28 11:54:55 +0800185 TP_ARGS(sp)
Avi Kivityf691fe12009-07-06 15:58:14 +0300186);
187
Xiao Guangrong85f20672010-04-28 11:54:55 +0800188DEFINE_EVENT(kvm_mmu_page_class, kvm_mmu_unsync_page,
Avi Kivityf691fe12009-07-06 15:58:14 +0300189 TP_PROTO(struct kvm_mmu_page *sp),
Avi Kivityf691fe12009-07-06 15:58:14 +0300190
Xiao Guangrong85f20672010-04-28 11:54:55 +0800191 TP_ARGS(sp)
Avi Kivityf691fe12009-07-06 15:58:14 +0300192);
193
Xiao Guangrong77758342010-06-04 21:53:54 +0800194DEFINE_EVENT(kvm_mmu_page_class, kvm_mmu_prepare_zap_page,
Xiao Guangrong85f20672010-04-28 11:54:55 +0800195 TP_PROTO(struct kvm_mmu_page *sp),
196
197 TP_ARGS(sp)
198);
Xiao Guangrong8b1fe172010-08-30 18:22:53 +0800199
Xiao Guangrong4f022642011-07-12 03:34:24 +0800200TRACE_EVENT(
201 mark_mmio_spte,
Xiao Guangrongf2fd1252013-06-07 16:51:24 +0800202 TP_PROTO(u64 *sptep, gfn_t gfn, unsigned access, unsigned int gen),
203 TP_ARGS(sptep, gfn, access, gen),
Xiao Guangrong4f022642011-07-12 03:34:24 +0800204
205 TP_STRUCT__entry(
206 __field(void *, sptep)
207 __field(gfn_t, gfn)
208 __field(unsigned, access)
Xiao Guangrongf2fd1252013-06-07 16:51:24 +0800209 __field(unsigned int, gen)
Xiao Guangrong4f022642011-07-12 03:34:24 +0800210 ),
211
212 TP_fast_assign(
213 __entry->sptep = sptep;
214 __entry->gfn = gfn;
215 __entry->access = access;
Xiao Guangrongf2fd1252013-06-07 16:51:24 +0800216 __entry->gen = gen;
Xiao Guangrong4f022642011-07-12 03:34:24 +0800217 ),
218
Xiao Guangrongf2fd1252013-06-07 16:51:24 +0800219 TP_printk("sptep:%p gfn %llx access %x gen %x", __entry->sptep,
220 __entry->gfn, __entry->access, __entry->gen)
Xiao Guangrong4f022642011-07-12 03:34:24 +0800221);
222
223TRACE_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 Guangronga72faf22012-06-20 15:59:41 +0800243
244#define __spte_satisfied(__spte) \
245 (__entry->retry && is_writable_pte(__entry->__spte))
246
247TRACE_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 Guangrong35006122013-05-31 08:36:25 +0800281
282TRACE_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 Guangrong089504c2013-06-07 16:51:27 +0800301
302
303TRACE_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 Kivity07420172009-07-06 12:21:32 +0300325#endif /* _TRACE_KVMMMU_H */
326
Xiao Guangrong2ed152a2010-03-10 19:00:43 +0800327#undef TRACE_INCLUDE_PATH
328#define TRACE_INCLUDE_PATH .
329#undef TRACE_INCLUDE_FILE
330#define TRACE_INCLUDE_FILE mmutrace
331
Avi Kivity07420172009-07-06 12:21:32 +0300332/* This part must be outside protection */
333#include <trace/define_trace.h>