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(__u8, 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 %u gfn %llx l%u %u-byte q%u%s %s%s" \
35 " %snxe %sad root %u %s%c", \
36 __entry->mmu_valid_gen, \
37 __entry->gfn, role.level, \
38 role.gpte_is_8_bytes ? 8 : 4, \
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, u64 spte),
206 TP_ARGS(sptep, gfn, spte),
209 __field(void *, sptep)
211 __field(unsigned, access)
212 __field(unsigned int, gen)
216 __entry->sptep = sptep;
218 __entry->access = spte & ACC_ALL;
219 __entry->gen = get_mmio_spte_generation(spte);
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,
249 TP_PROTO(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u32 error_code,
250 u64 *sptep, u64 old_spte, int ret),
251 TP_ARGS(vcpu, cr2_or_gpa, error_code, sptep, old_spte, ret),
254 __field(int, vcpu_id)
255 __field(gpa_t, cr2_or_gpa)
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;
265 __entry->cr2_or_gpa = cr2_or_gpa;
266 __entry->error_code = error_code;
267 __entry->sptep = sptep;
268 __entry->old_spte = old_spte;
269 __entry->new_spte = *sptep;
273 TP_printk("vcpu %d gva %llx error_code %s sptep %p old %#llx"
274 " new %llx spurious %d fixed %d", __entry->vcpu_id,
275 __entry->cr2_or_gpa, __print_flags(__entry->error_code, "|",
276 kvm_mmu_trace_pferr_flags), __entry->sptep,
277 __entry->old_spte, __entry->new_spte,
278 __entry->ret == RET_PF_SPURIOUS, __entry->ret == RET_PF_FIXED
283 kvm_mmu_zap_all_fast,
284 TP_PROTO(struct kvm *kvm),
288 __field(__u8, 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 %u 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
328 TP_PROTO(int level, gfn_t gfn, u64 *sptep),
329 TP_ARGS(level, gfn, sptep),
336 /* These depend on page entry type, so compute them now. */
339 __field(signed char, u)
344 __entry->spte = *sptep;
345 __entry->sptep = virt_to_phys(sptep);
346 __entry->level = level;
347 __entry->r = shadow_present_mask || (__entry->spte & PT_PRESENT_MASK);
348 __entry->x = is_executable_pte(__entry->spte);
349 __entry->u = shadow_user_mask ? !!(__entry->spte & shadow_user_mask) : -1;
352 TP_printk("gfn %llx spte %llx (%s%s%s%s) level %d at %llx",
353 __entry->gfn, __entry->spte,
354 __entry->r ? "r" : "-",
355 __entry->spte & PT_WRITABLE_MASK ? "w" : "-",
356 __entry->x ? "x" : "-",
357 __entry->u == -1 ? "" : (__entry->u ? "u" : "-"),
358 __entry->level, __entry->sptep
363 kvm_mmu_spte_requested,
364 TP_PROTO(gpa_t addr, int level, kvm_pfn_t pfn),
365 TP_ARGS(addr, level, pfn),
374 __entry->gfn = addr >> PAGE_SHIFT;
375 __entry->pfn = pfn | (__entry->gfn & (KVM_PAGES_PER_HPAGE(level) - 1));
376 __entry->level = level;
379 TP_printk("gfn %llx pfn %llx level %d",
380 __entry->gfn, __entry->pfn, __entry->level
384 #endif /* _TRACE_KVMMMU_H */
386 #undef TRACE_INCLUDE_PATH
387 #define TRACE_INCLUDE_PATH mmu
388 #undef TRACE_INCLUDE_FILE
389 #define TRACE_INCLUDE_FILE mmutrace
391 /* This part must be outside protection */
392 #include <trace/define_trace.h>