1 /* SPDX-License-Identifier: GPL-2.0 */
2 #if !defined(_TRACE_KVMMMU_H) || defined(TRACE_HEADER_MULTI_READ)
3 #define _TRACE_KVMMMU_H
5 #include <linux/tracepoint.h>
6 #include <linux/trace_events.h>
9 #define TRACE_SYSTEM kvmmmu
11 #define KVM_MMU_PAGE_FIELDS \
12 __field(unsigned long, mmu_valid_gen) \
14 __field(__u32, role) \
15 __field(__u32, root_count) \
18 #define KVM_MMU_PAGE_ASSIGN(sp) \
19 __entry->mmu_valid_gen = sp->mmu_valid_gen; \
20 __entry->gfn = sp->gfn; \
21 __entry->role = sp->role.word; \
22 __entry->root_count = sp->root_count; \
23 __entry->unsync = sp->unsync;
25 #define KVM_MMU_PAGE_PRINTK() ({ \
26 const char *saved_ptr = trace_seq_buffer_ptr(p); \
27 static const char *access_str[] = { \
28 "---", "--x", "w--", "w-x", "-u-", "-ux", "wu-", "wux" \
30 union kvm_mmu_page_role role; \
32 role.word = __entry->role; \
34 trace_seq_printf(p, "sp gen %lx gfn %llx l%u%s q%u%s %s%s" \
35 " %snxe %sad root %u %s%c", \
36 __entry->mmu_valid_gen, \
37 __entry->gfn, role.level, \
38 role.cr4_pae ? " pae" : "", \
40 role.direct ? " direct" : "", \
41 access_str[role.access], \
42 role.invalid ? " invalid" : "", \
43 role.nxe ? "" : "!", \
44 role.ad_disabled ? "!" : "", \
45 __entry->root_count, \
46 __entry->unsync ? "unsync" : "sync", 0); \
50 #define kvm_mmu_trace_pferr_flags \
51 { PFERR_PRESENT_MASK, "P" }, \
52 { PFERR_WRITE_MASK, "W" }, \
53 { PFERR_USER_MASK, "U" }, \
54 { PFERR_RSVD_MASK, "RSVD" }, \
55 { PFERR_FETCH_MASK, "F" }
58 * A pagetable walk has started
61 kvm_mmu_pagetable_walk
,
62 TP_PROTO(u64 addr
, u32 pferr
),
72 __entry
->pferr
= pferr
;
75 TP_printk("addr %llx pferr %x %s", __entry
->addr
, __entry
->pferr
,
76 __print_flags(__entry
->pferr
, "|", kvm_mmu_trace_pferr_flags
))
80 /* We just walked a paging element */
82 kvm_mmu_paging_element
,
83 TP_PROTO(u64 pte
, int level
),
93 __entry
->level
= level
;
96 TP_printk("pte %llx level %u", __entry
->pte
, __entry
->level
)
99 DECLARE_EVENT_CLASS(kvm_mmu_set_bit_class
,
101 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
103 TP_ARGS(table_gfn
, index
, size
),
110 __entry
->gpa
= ((u64
)table_gfn
<< PAGE_SHIFT
)
114 TP_printk("gpa %llx", __entry
->gpa
)
117 /* We set a pte accessed bit */
118 DEFINE_EVENT(kvm_mmu_set_bit_class
, kvm_mmu_set_accessed_bit
,
120 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
122 TP_ARGS(table_gfn
, index
, size
)
125 /* We set a pte dirty bit */
126 DEFINE_EVENT(kvm_mmu_set_bit_class
, kvm_mmu_set_dirty_bit
,
128 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
130 TP_ARGS(table_gfn
, index
, size
)
134 kvm_mmu_walker_error
,
139 __field(__u32
, pferr
)
143 __entry
->pferr
= pferr
;
146 TP_printk("pferr %x %s", __entry
->pferr
,
147 __print_flags(__entry
->pferr
, "|", kvm_mmu_trace_pferr_flags
))
152 TP_PROTO(struct kvm_mmu_page
*sp
, bool created
),
153 TP_ARGS(sp
, created
),
157 __field(bool, created
)
161 KVM_MMU_PAGE_ASSIGN(sp
)
162 __entry
->created
= created
;
165 TP_printk("%s %s", KVM_MMU_PAGE_PRINTK(),
166 __entry
->created
? "new" : "existing")
169 DECLARE_EVENT_CLASS(kvm_mmu_page_class
,
171 TP_PROTO(struct kvm_mmu_page
*sp
),
179 KVM_MMU_PAGE_ASSIGN(sp
)
182 TP_printk("%s", KVM_MMU_PAGE_PRINTK())
185 DEFINE_EVENT(kvm_mmu_page_class
, kvm_mmu_sync_page
,
186 TP_PROTO(struct kvm_mmu_page
*sp
),
191 DEFINE_EVENT(kvm_mmu_page_class
, kvm_mmu_unsync_page
,
192 TP_PROTO(struct kvm_mmu_page
*sp
),
197 DEFINE_EVENT(kvm_mmu_page_class
, kvm_mmu_prepare_zap_page
,
198 TP_PROTO(struct kvm_mmu_page
*sp
),
205 TP_PROTO(u64
*sptep
, gfn_t gfn
, unsigned access
, unsigned int gen
),
206 TP_ARGS(sptep
, gfn
, access
, gen
),
209 __field(void *, sptep
)
211 __field(unsigned, access
)
212 __field(unsigned int, gen
)
216 __entry
->sptep
= sptep
;
218 __entry
->access
= access
;
222 TP_printk("sptep:%p gfn %llx access %x gen %x", __entry
->sptep
,
223 __entry
->gfn
, __entry
->access
, __entry
->gen
)
227 handle_mmio_page_fault
,
228 TP_PROTO(u64 addr
, gfn_t gfn
, unsigned access
),
229 TP_ARGS(addr
, gfn
, access
),
234 __field(unsigned, access
)
238 __entry
->addr
= addr
;
240 __entry
->access
= access
;
243 TP_printk("addr:%llx gfn %llx access %x", __entry
->addr
, __entry
->gfn
,
247 #define __spte_satisfied(__spte) \
248 (__entry->retry && is_writable_pte(__entry->__spte))
252 TP_PROTO(struct kvm_vcpu
*vcpu
, gva_t gva
, u32 error_code
,
253 u64
*sptep
, u64 old_spte
, bool retry
),
254 TP_ARGS(vcpu
, gva
, error_code
, sptep
, old_spte
, retry
),
257 __field(int, vcpu_id
)
259 __field(u32
, error_code
)
260 __field(u64
*, sptep
)
261 __field(u64
, old_spte
)
262 __field(u64
, new_spte
)
267 __entry
->vcpu_id
= vcpu
->vcpu_id
;
269 __entry
->error_code
= error_code
;
270 __entry
->sptep
= sptep
;
271 __entry
->old_spte
= old_spte
;
272 __entry
->new_spte
= *sptep
;
273 __entry
->retry
= retry
;
276 TP_printk("vcpu %d gva %lx error_code %s sptep %p old %#llx"
277 " new %llx spurious %d fixed %d", __entry
->vcpu_id
,
278 __entry
->gva
, __print_flags(__entry
->error_code
, "|",
279 kvm_mmu_trace_pferr_flags
), __entry
->sptep
,
280 __entry
->old_spte
, __entry
->new_spte
,
281 __spte_satisfied(old_spte
), __spte_satisfied(new_spte
)
286 kvm_mmu_invalidate_zap_all_pages
,
287 TP_PROTO(struct kvm
*kvm
),
291 __field(unsigned long, mmu_valid_gen
)
292 __field(unsigned int, mmu_used_pages
)
296 __entry
->mmu_valid_gen
= kvm
->arch
.mmu_valid_gen
;
297 __entry
->mmu_used_pages
= kvm
->arch
.n_used_mmu_pages
;
300 TP_printk("kvm-mmu-valid-gen %lx used_pages %x",
301 __entry
->mmu_valid_gen
, __entry
->mmu_used_pages
308 TP_PROTO(u64 spte
, unsigned int kvm_gen
, unsigned int spte_gen
),
309 TP_ARGS(spte
, kvm_gen
, spte_gen
),
312 __field(unsigned int, kvm_gen
)
313 __field(unsigned int, spte_gen
)
318 __entry
->kvm_gen
= kvm_gen
;
319 __entry
->spte_gen
= spte_gen
;
320 __entry
->spte
= spte
;
323 TP_printk("spte %llx kvm_gen %x spte-gen %x valid %d", __entry
->spte
,
324 __entry
->kvm_gen
, __entry
->spte_gen
,
325 __entry
->kvm_gen
== __entry
->spte_gen
328 #endif /* _TRACE_KVMMMU_H */
330 #undef TRACE_INCLUDE_PATH
331 #define TRACE_INCLUDE_PATH .
332 #undef TRACE_INCLUDE_FILE
333 #define TRACE_INCLUDE_FILE mmutrace
335 /* This part must be outside protection */
336 #include <trace/define_trace.h>