1 #if !defined(_TRACE_KVMMMU_H) || defined(TRACE_HEADER_MULTI_READ)
2 #define _TRACE_KVMMMU_H
4 #include <linux/tracepoint.h>
5 #include <linux/trace_events.h>
8 #define TRACE_SYSTEM kvmmmu
10 #define KVM_MMU_PAGE_FIELDS \
11 __field(unsigned long, mmu_valid_gen) \
13 __field(__u32, role) \
14 __field(__u32, root_count) \
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; \
22 __entry->unsync = sp->unsync;
24 #define KVM_MMU_PAGE_PRINTK() ({ \
25 const char *saved_ptr = trace_seq_buffer_ptr(p); \
26 static const char *access_str[] = { \
27 "---", "--x", "w--", "w-x", "-u-", "-ux", "wu-", "wux" \
29 union kvm_mmu_page_role role; \
31 role.word = __entry->role; \
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, \
35 __entry->gfn, role.level, \
36 role.cr4_pae ? " pae" : "", \
38 role.direct ? " direct" : "", \
39 access_str[role.access], \
40 role.invalid ? " invalid" : "", \
41 role.nxe ? "" : "!", \
42 __entry->root_count, \
43 __entry->unsync ? "unsync" : "sync", 0); \
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" }
55 * A pagetable walk has started
58 kvm_mmu_pagetable_walk
,
59 TP_PROTO(u64 addr
, u32 pferr
),
69 __entry
->pferr
= pferr
;
72 TP_printk("addr %llx pferr %x %s", __entry
->addr
, __entry
->pferr
,
73 __print_flags(__entry
->pferr
, "|", kvm_mmu_trace_pferr_flags
))
77 /* We just walked a paging element */
79 kvm_mmu_paging_element
,
80 TP_PROTO(u64 pte
, int level
),
90 __entry
->level
= level
;
93 TP_printk("pte %llx level %u", __entry
->pte
, __entry
->level
)
96 DECLARE_EVENT_CLASS(kvm_mmu_set_bit_class
,
98 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
100 TP_ARGS(table_gfn
, index
, size
),
107 __entry
->gpa
= ((u64
)table_gfn
<< PAGE_SHIFT
)
111 TP_printk("gpa %llx", __entry
->gpa
)
114 /* We set a pte accessed bit */
115 DEFINE_EVENT(kvm_mmu_set_bit_class
, kvm_mmu_set_accessed_bit
,
117 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
119 TP_ARGS(table_gfn
, index
, size
)
122 /* We set a pte dirty bit */
123 DEFINE_EVENT(kvm_mmu_set_bit_class
, kvm_mmu_set_dirty_bit
,
125 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
127 TP_ARGS(table_gfn
, index
, size
)
131 kvm_mmu_walker_error
,
136 __field(__u32
, pferr
)
140 __entry
->pferr
= pferr
;
143 TP_printk("pferr %x %s", __entry
->pferr
,
144 __print_flags(__entry
->pferr
, "|", kvm_mmu_trace_pferr_flags
))
149 TP_PROTO(struct kvm_mmu_page
*sp
, bool created
),
150 TP_ARGS(sp
, created
),
154 __field(bool, created
)
158 KVM_MMU_PAGE_ASSIGN(sp
)
159 __entry
->created
= created
;
162 TP_printk("%s %s", KVM_MMU_PAGE_PRINTK(),
163 __entry
->created
? "new" : "existing")
166 DECLARE_EVENT_CLASS(kvm_mmu_page_class
,
168 TP_PROTO(struct kvm_mmu_page
*sp
),
176 KVM_MMU_PAGE_ASSIGN(sp
)
179 TP_printk("%s", KVM_MMU_PAGE_PRINTK())
182 DEFINE_EVENT(kvm_mmu_page_class
, kvm_mmu_sync_page
,
183 TP_PROTO(struct kvm_mmu_page
*sp
),
188 DEFINE_EVENT(kvm_mmu_page_class
, kvm_mmu_unsync_page
,
189 TP_PROTO(struct kvm_mmu_page
*sp
),
194 DEFINE_EVENT(kvm_mmu_page_class
, kvm_mmu_prepare_zap_page
,
195 TP_PROTO(struct kvm_mmu_page
*sp
),
202 TP_PROTO(u64
*sptep
, gfn_t gfn
, unsigned access
, unsigned int gen
),
203 TP_ARGS(sptep
, gfn
, access
, gen
),
206 __field(void *, sptep
)
208 __field(unsigned, access
)
209 __field(unsigned int, gen
)
213 __entry
->sptep
= sptep
;
215 __entry
->access
= access
;
219 TP_printk("sptep:%p gfn %llx access %x gen %x", __entry
->sptep
,
220 __entry
->gfn
, __entry
->access
, __entry
->gen
)
224 handle_mmio_page_fault
,
225 TP_PROTO(u64 addr
, gfn_t gfn
, unsigned access
),
226 TP_ARGS(addr
, gfn
, access
),
231 __field(unsigned, access
)
235 __entry
->addr
= addr
;
237 __entry
->access
= access
;
240 TP_printk("addr:%llx gfn %llx access %x", __entry
->addr
, __entry
->gfn
,
244 #define __spte_satisfied(__spte) \
245 (__entry->retry && is_writable_pte(__entry->__spte))
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
),
254 __field(int, vcpu_id
)
256 __field(u32
, error_code
)
257 __field(u64
*, sptep
)
258 __field(u64
, old_spte
)
259 __field(u64
, new_spte
)
264 __entry
->vcpu_id
= vcpu
->vcpu_id
;
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
;
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
)
283 kvm_mmu_invalidate_zap_all_pages
,
284 TP_PROTO(struct kvm
*kvm
),
288 __field(unsigned long, mmu_valid_gen
)
289 __field(unsigned int, mmu_used_pages
)
293 __entry
->mmu_valid_gen
= kvm
->arch
.mmu_valid_gen
;
294 __entry
->mmu_used_pages
= kvm
->arch
.n_used_mmu_pages
;
297 TP_printk("kvm-mmu-valid-gen %lx used_pages %x",
298 __entry
->mmu_valid_gen
, __entry
->mmu_used_pages
305 TP_PROTO(u64 spte
, unsigned int kvm_gen
, unsigned int spte_gen
),
306 TP_ARGS(spte
, kvm_gen
, spte_gen
),
309 __field(unsigned int, kvm_gen
)
310 __field(unsigned int, spte_gen
)
315 __entry
->kvm_gen
= kvm_gen
;
316 __entry
->spte_gen
= spte_gen
;
317 __entry
->spte
= spte
;
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
325 #endif /* _TRACE_KVMMMU_H */
327 #undef TRACE_INCLUDE_PATH
328 #define TRACE_INCLUDE_PATH .
329 #undef TRACE_INCLUDE_FILE
330 #define TRACE_INCLUDE_FILE mmutrace
332 /* This part must be outside protection */
333 #include <trace/define_trace.h>