xref: /openbmc/linux/arch/x86/kvm/mmu/mmutrace.h (revision 5276c616)
133e3042dSSean Christopherson /* SPDX-License-Identifier: GPL-2.0 */
233e3042dSSean Christopherson #if !defined(_TRACE_KVMMMU_H) || defined(TRACE_HEADER_MULTI_READ)
333e3042dSSean Christopherson #define _TRACE_KVMMMU_H
433e3042dSSean Christopherson 
533e3042dSSean Christopherson #include <linux/tracepoint.h>
633e3042dSSean Christopherson #include <linux/trace_events.h>
733e3042dSSean Christopherson 
833e3042dSSean Christopherson #undef TRACE_SYSTEM
933e3042dSSean Christopherson #define TRACE_SYSTEM kvmmmu
1033e3042dSSean Christopherson 
1133e3042dSSean Christopherson #define KVM_MMU_PAGE_FIELDS		\
1233e3042dSSean Christopherson 	__field(__u8, mmu_valid_gen)	\
1333e3042dSSean Christopherson 	__field(__u64, gfn)		\
1433e3042dSSean Christopherson 	__field(__u32, role)		\
1533e3042dSSean Christopherson 	__field(__u32, root_count)	\
1633e3042dSSean Christopherson 	__field(bool, unsync)
1733e3042dSSean Christopherson 
1833e3042dSSean Christopherson #define KVM_MMU_PAGE_ASSIGN(sp)				\
1933e3042dSSean Christopherson 	__entry->mmu_valid_gen = sp->mmu_valid_gen;	\
2033e3042dSSean Christopherson 	__entry->gfn = sp->gfn;				\
2133e3042dSSean Christopherson 	__entry->role = sp->role.word;			\
2233e3042dSSean Christopherson 	__entry->root_count = sp->root_count;		\
2333e3042dSSean Christopherson 	__entry->unsync = sp->unsync;
2433e3042dSSean Christopherson 
2533e3042dSSean Christopherson #define KVM_MMU_PAGE_PRINTK() ({				        \
2633e3042dSSean Christopherson 	const char *saved_ptr = trace_seq_buffer_ptr(p);		\
2733e3042dSSean Christopherson 	static const char *access_str[] = {			        \
2833e3042dSSean Christopherson 		"---", "--x", "w--", "w-x", "-u-", "-ux", "wu-", "wux"  \
2933e3042dSSean Christopherson 	};							        \
3033e3042dSSean Christopherson 	union kvm_mmu_page_role role;				        \
3133e3042dSSean Christopherson 								        \
3233e3042dSSean Christopherson 	role.word = __entry->role;					\
3333e3042dSSean Christopherson 									\
3433e3042dSSean Christopherson 	trace_seq_printf(p, "sp gen %u gfn %llx l%u %u-byte q%u%s %s%s"	\
3533e3042dSSean Christopherson 			 " %snxe %sad root %u %s%c",			\
3633e3042dSSean Christopherson 			 __entry->mmu_valid_gen,			\
3733e3042dSSean Christopherson 			 __entry->gfn, role.level,			\
38bb3b394dSLai Jiangshan 			 role.has_4_byte_gpte ? 4 : 8,			\
3933e3042dSSean Christopherson 			 role.quadrant,					\
4033e3042dSSean Christopherson 			 role.direct ? " direct" : "",			\
4133e3042dSSean Christopherson 			 access_str[role.access],			\
4233e3042dSSean Christopherson 			 role.invalid ? " invalid" : "",		\
43167f8a5cSSean Christopherson 			 role.efer_nx ? "" : "!",			\
4433e3042dSSean Christopherson 			 role.ad_disabled ? "!" : "",			\
4533e3042dSSean Christopherson 			 __entry->root_count,				\
4633e3042dSSean Christopherson 			 __entry->unsync ? "unsync" : "sync", 0);	\
4733e3042dSSean Christopherson 	saved_ptr;							\
4833e3042dSSean Christopherson 		})
4933e3042dSSean Christopherson 
5033e3042dSSean Christopherson #define kvm_mmu_trace_pferr_flags       \
5133e3042dSSean Christopherson 	{ PFERR_PRESENT_MASK, "P" },	\
5233e3042dSSean Christopherson 	{ PFERR_WRITE_MASK, "W" },	\
5333e3042dSSean Christopherson 	{ PFERR_USER_MASK, "U" },	\
5433e3042dSSean Christopherson 	{ PFERR_RSVD_MASK, "RSVD" },	\
5533e3042dSSean Christopherson 	{ PFERR_FETCH_MASK, "F" }
5633e3042dSSean Christopherson 
57*5276c616SSean Christopherson TRACE_DEFINE_ENUM(RET_PF_CONTINUE);
5861bcd360SDavid Matlack TRACE_DEFINE_ENUM(RET_PF_RETRY);
5961bcd360SDavid Matlack TRACE_DEFINE_ENUM(RET_PF_EMULATE);
6061bcd360SDavid Matlack TRACE_DEFINE_ENUM(RET_PF_INVALID);
6161bcd360SDavid Matlack TRACE_DEFINE_ENUM(RET_PF_FIXED);
6261bcd360SDavid Matlack TRACE_DEFINE_ENUM(RET_PF_SPURIOUS);
6361bcd360SDavid Matlack 
6433e3042dSSean Christopherson /*
6533e3042dSSean Christopherson  * A pagetable walk has started
6633e3042dSSean Christopherson  */
6733e3042dSSean Christopherson TRACE_EVENT(
6833e3042dSSean Christopherson 	kvm_mmu_pagetable_walk,
6933e3042dSSean Christopherson 	TP_PROTO(u64 addr, u32 pferr),
7033e3042dSSean Christopherson 	TP_ARGS(addr, pferr),
7133e3042dSSean Christopherson 
7233e3042dSSean Christopherson 	TP_STRUCT__entry(
7333e3042dSSean Christopherson 		__field(__u64, addr)
7433e3042dSSean Christopherson 		__field(__u32, pferr)
7533e3042dSSean Christopherson 	),
7633e3042dSSean Christopherson 
7733e3042dSSean Christopherson 	TP_fast_assign(
7833e3042dSSean Christopherson 		__entry->addr = addr;
7933e3042dSSean Christopherson 		__entry->pferr = pferr;
8033e3042dSSean Christopherson 	),
8133e3042dSSean Christopherson 
8233e3042dSSean Christopherson 	TP_printk("addr %llx pferr %x %s", __entry->addr, __entry->pferr,
8333e3042dSSean Christopherson 		  __print_flags(__entry->pferr, "|", kvm_mmu_trace_pferr_flags))
8433e3042dSSean Christopherson );
8533e3042dSSean Christopherson 
8633e3042dSSean Christopherson 
8733e3042dSSean Christopherson /* We just walked a paging element */
8833e3042dSSean Christopherson TRACE_EVENT(
8933e3042dSSean Christopherson 	kvm_mmu_paging_element,
9033e3042dSSean Christopherson 	TP_PROTO(u64 pte, int level),
9133e3042dSSean Christopherson 	TP_ARGS(pte, level),
9233e3042dSSean Christopherson 
9333e3042dSSean Christopherson 	TP_STRUCT__entry(
9433e3042dSSean Christopherson 		__field(__u64, pte)
9533e3042dSSean Christopherson 		__field(__u32, level)
9633e3042dSSean Christopherson 		),
9733e3042dSSean Christopherson 
9833e3042dSSean Christopherson 	TP_fast_assign(
9933e3042dSSean Christopherson 		__entry->pte = pte;
10033e3042dSSean Christopherson 		__entry->level = level;
10133e3042dSSean Christopherson 		),
10233e3042dSSean Christopherson 
10333e3042dSSean Christopherson 	TP_printk("pte %llx level %u", __entry->pte, __entry->level)
10433e3042dSSean Christopherson );
10533e3042dSSean Christopherson 
10633e3042dSSean Christopherson DECLARE_EVENT_CLASS(kvm_mmu_set_bit_class,
10733e3042dSSean Christopherson 
10833e3042dSSean Christopherson 	TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size),
10933e3042dSSean Christopherson 
11033e3042dSSean Christopherson 	TP_ARGS(table_gfn, index, size),
11133e3042dSSean Christopherson 
11233e3042dSSean Christopherson 	TP_STRUCT__entry(
11333e3042dSSean Christopherson 		__field(__u64, gpa)
11433e3042dSSean Christopherson 	),
11533e3042dSSean Christopherson 
11633e3042dSSean Christopherson 	TP_fast_assign(
11733e3042dSSean Christopherson 		__entry->gpa = ((u64)table_gfn << PAGE_SHIFT)
11833e3042dSSean Christopherson 				+ index * size;
11933e3042dSSean Christopherson 		),
12033e3042dSSean Christopherson 
12133e3042dSSean Christopherson 	TP_printk("gpa %llx", __entry->gpa)
12233e3042dSSean Christopherson );
12333e3042dSSean Christopherson 
12433e3042dSSean Christopherson /* We set a pte accessed bit */
12533e3042dSSean Christopherson DEFINE_EVENT(kvm_mmu_set_bit_class, kvm_mmu_set_accessed_bit,
12633e3042dSSean Christopherson 
12733e3042dSSean Christopherson 	TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size),
12833e3042dSSean Christopherson 
12933e3042dSSean Christopherson 	TP_ARGS(table_gfn, index, size)
13033e3042dSSean Christopherson );
13133e3042dSSean Christopherson 
13233e3042dSSean Christopherson /* We set a pte dirty bit */
13333e3042dSSean Christopherson DEFINE_EVENT(kvm_mmu_set_bit_class, kvm_mmu_set_dirty_bit,
13433e3042dSSean Christopherson 
13533e3042dSSean Christopherson 	TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size),
13633e3042dSSean Christopherson 
13733e3042dSSean Christopherson 	TP_ARGS(table_gfn, index, size)
13833e3042dSSean Christopherson );
13933e3042dSSean Christopherson 
14033e3042dSSean Christopherson TRACE_EVENT(
14133e3042dSSean Christopherson 	kvm_mmu_walker_error,
14233e3042dSSean Christopherson 	TP_PROTO(u32 pferr),
14333e3042dSSean Christopherson 	TP_ARGS(pferr),
14433e3042dSSean Christopherson 
14533e3042dSSean Christopherson 	TP_STRUCT__entry(
14633e3042dSSean Christopherson 		__field(__u32, pferr)
14733e3042dSSean Christopherson 		),
14833e3042dSSean Christopherson 
14933e3042dSSean Christopherson 	TP_fast_assign(
15033e3042dSSean Christopherson 		__entry->pferr = pferr;
15133e3042dSSean Christopherson 		),
15233e3042dSSean Christopherson 
15333e3042dSSean Christopherson 	TP_printk("pferr %x %s", __entry->pferr,
15433e3042dSSean Christopherson 		  __print_flags(__entry->pferr, "|", kvm_mmu_trace_pferr_flags))
15533e3042dSSean Christopherson );
15633e3042dSSean Christopherson 
15733e3042dSSean Christopherson TRACE_EVENT(
15833e3042dSSean Christopherson 	kvm_mmu_get_page,
15933e3042dSSean Christopherson 	TP_PROTO(struct kvm_mmu_page *sp, bool created),
16033e3042dSSean Christopherson 	TP_ARGS(sp, created),
16133e3042dSSean Christopherson 
16233e3042dSSean Christopherson 	TP_STRUCT__entry(
16333e3042dSSean Christopherson 		KVM_MMU_PAGE_FIELDS
16433e3042dSSean Christopherson 		__field(bool, created)
16533e3042dSSean Christopherson 		),
16633e3042dSSean Christopherson 
16733e3042dSSean Christopherson 	TP_fast_assign(
16833e3042dSSean Christopherson 		KVM_MMU_PAGE_ASSIGN(sp)
16933e3042dSSean Christopherson 		__entry->created = created;
17033e3042dSSean Christopherson 		),
17133e3042dSSean Christopherson 
17233e3042dSSean Christopherson 	TP_printk("%s %s", KVM_MMU_PAGE_PRINTK(),
17333e3042dSSean Christopherson 		  __entry->created ? "new" : "existing")
17433e3042dSSean Christopherson );
17533e3042dSSean Christopherson 
17633e3042dSSean Christopherson DECLARE_EVENT_CLASS(kvm_mmu_page_class,
17733e3042dSSean Christopherson 
17833e3042dSSean Christopherson 	TP_PROTO(struct kvm_mmu_page *sp),
17933e3042dSSean Christopherson 	TP_ARGS(sp),
18033e3042dSSean Christopherson 
18133e3042dSSean Christopherson 	TP_STRUCT__entry(
18233e3042dSSean Christopherson 		KVM_MMU_PAGE_FIELDS
18333e3042dSSean Christopherson 	),
18433e3042dSSean Christopherson 
18533e3042dSSean Christopherson 	TP_fast_assign(
18633e3042dSSean Christopherson 		KVM_MMU_PAGE_ASSIGN(sp)
18733e3042dSSean Christopherson 	),
18833e3042dSSean Christopherson 
18933e3042dSSean Christopherson 	TP_printk("%s", KVM_MMU_PAGE_PRINTK())
19033e3042dSSean Christopherson );
19133e3042dSSean Christopherson 
19233e3042dSSean Christopherson DEFINE_EVENT(kvm_mmu_page_class, kvm_mmu_sync_page,
19333e3042dSSean Christopherson 	TP_PROTO(struct kvm_mmu_page *sp),
19433e3042dSSean Christopherson 
19533e3042dSSean Christopherson 	TP_ARGS(sp)
19633e3042dSSean Christopherson );
19733e3042dSSean Christopherson 
19833e3042dSSean Christopherson DEFINE_EVENT(kvm_mmu_page_class, kvm_mmu_unsync_page,
19933e3042dSSean Christopherson 	TP_PROTO(struct kvm_mmu_page *sp),
20033e3042dSSean Christopherson 
20133e3042dSSean Christopherson 	TP_ARGS(sp)
20233e3042dSSean Christopherson );
20333e3042dSSean Christopherson 
20433e3042dSSean Christopherson DEFINE_EVENT(kvm_mmu_page_class, kvm_mmu_prepare_zap_page,
20533e3042dSSean Christopherson 	TP_PROTO(struct kvm_mmu_page *sp),
20633e3042dSSean Christopherson 
20733e3042dSSean Christopherson 	TP_ARGS(sp)
20833e3042dSSean Christopherson );
20933e3042dSSean Christopherson 
21033e3042dSSean Christopherson TRACE_EVENT(
21133e3042dSSean Christopherson 	mark_mmio_spte,
212bb18842eSBen Gardon 	TP_PROTO(u64 *sptep, gfn_t gfn, u64 spte),
213bb18842eSBen Gardon 	TP_ARGS(sptep, gfn, spte),
21433e3042dSSean Christopherson 
21533e3042dSSean Christopherson 	TP_STRUCT__entry(
21633e3042dSSean Christopherson 		__field(void *, sptep)
21733e3042dSSean Christopherson 		__field(gfn_t, gfn)
21833e3042dSSean Christopherson 		__field(unsigned, access)
21933e3042dSSean Christopherson 		__field(unsigned int, gen)
22033e3042dSSean Christopherson 	),
22133e3042dSSean Christopherson 
22233e3042dSSean Christopherson 	TP_fast_assign(
22333e3042dSSean Christopherson 		__entry->sptep = sptep;
22433e3042dSSean Christopherson 		__entry->gfn = gfn;
225bb18842eSBen Gardon 		__entry->access = spte & ACC_ALL;
226bb18842eSBen Gardon 		__entry->gen = get_mmio_spte_generation(spte);
22733e3042dSSean Christopherson 	),
22833e3042dSSean Christopherson 
22933e3042dSSean Christopherson 	TP_printk("sptep:%p gfn %llx access %x gen %x", __entry->sptep,
23033e3042dSSean Christopherson 		  __entry->gfn, __entry->access, __entry->gen)
23133e3042dSSean Christopherson );
23233e3042dSSean Christopherson 
23333e3042dSSean Christopherson TRACE_EVENT(
23433e3042dSSean Christopherson 	handle_mmio_page_fault,
23533e3042dSSean Christopherson 	TP_PROTO(u64 addr, gfn_t gfn, unsigned access),
23633e3042dSSean Christopherson 	TP_ARGS(addr, gfn, access),
23733e3042dSSean Christopherson 
23833e3042dSSean Christopherson 	TP_STRUCT__entry(
23933e3042dSSean Christopherson 		__field(u64, addr)
24033e3042dSSean Christopherson 		__field(gfn_t, gfn)
24133e3042dSSean Christopherson 		__field(unsigned, access)
24233e3042dSSean Christopherson 	),
24333e3042dSSean Christopherson 
24433e3042dSSean Christopherson 	TP_fast_assign(
24533e3042dSSean Christopherson 		__entry->addr = addr;
24633e3042dSSean Christopherson 		__entry->gfn = gfn;
24733e3042dSSean Christopherson 		__entry->access = access;
24833e3042dSSean Christopherson 	),
24933e3042dSSean Christopherson 
25033e3042dSSean Christopherson 	TP_printk("addr:%llx gfn %llx access %x", __entry->addr, __entry->gfn,
25133e3042dSSean Christopherson 		  __entry->access)
25233e3042dSSean Christopherson );
25333e3042dSSean Christopherson 
25433e3042dSSean Christopherson TRACE_EVENT(
25533e3042dSSean Christopherson 	fast_page_fault,
256f0066d94SPaolo Bonzini 	TP_PROTO(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault,
257c4371c2aSSean Christopherson 		 u64 *sptep, u64 old_spte, int ret),
258f0066d94SPaolo Bonzini 	TP_ARGS(vcpu, fault, sptep, old_spte, ret),
25933e3042dSSean Christopherson 
26033e3042dSSean Christopherson 	TP_STRUCT__entry(
26133e3042dSSean Christopherson 		__field(int, vcpu_id)
26233e3042dSSean Christopherson 		__field(gpa_t, cr2_or_gpa)
26333e3042dSSean Christopherson 		__field(u32, error_code)
26433e3042dSSean Christopherson 		__field(u64 *, sptep)
26533e3042dSSean Christopherson 		__field(u64, old_spte)
26633e3042dSSean Christopherson 		__field(u64, new_spte)
267c4371c2aSSean Christopherson 		__field(int, ret)
26833e3042dSSean Christopherson 	),
26933e3042dSSean Christopherson 
27033e3042dSSean Christopherson 	TP_fast_assign(
27133e3042dSSean Christopherson 		__entry->vcpu_id = vcpu->vcpu_id;
272f0066d94SPaolo Bonzini 		__entry->cr2_or_gpa = fault->addr;
273f0066d94SPaolo Bonzini 		__entry->error_code = fault->error_code;
27433e3042dSSean Christopherson 		__entry->sptep = sptep;
27533e3042dSSean Christopherson 		__entry->old_spte = old_spte;
27633e3042dSSean Christopherson 		__entry->new_spte = *sptep;
277c4371c2aSSean Christopherson 		__entry->ret = ret;
27833e3042dSSean Christopherson 	),
27933e3042dSSean Christopherson 
28033e3042dSSean Christopherson 	TP_printk("vcpu %d gva %llx error_code %s sptep %p old %#llx"
28133e3042dSSean Christopherson 		  " new %llx spurious %d fixed %d", __entry->vcpu_id,
28233e3042dSSean Christopherson 		  __entry->cr2_or_gpa, __print_flags(__entry->error_code, "|",
28333e3042dSSean Christopherson 		  kvm_mmu_trace_pferr_flags), __entry->sptep,
28433e3042dSSean Christopherson 		  __entry->old_spte, __entry->new_spte,
285c4371c2aSSean Christopherson 		  __entry->ret == RET_PF_SPURIOUS, __entry->ret == RET_PF_FIXED
28633e3042dSSean Christopherson 	)
28733e3042dSSean Christopherson );
28833e3042dSSean Christopherson 
28933e3042dSSean Christopherson TRACE_EVENT(
29033e3042dSSean Christopherson 	kvm_mmu_zap_all_fast,
29133e3042dSSean Christopherson 	TP_PROTO(struct kvm *kvm),
29233e3042dSSean Christopherson 	TP_ARGS(kvm),
29333e3042dSSean Christopherson 
29433e3042dSSean Christopherson 	TP_STRUCT__entry(
29533e3042dSSean Christopherson 		__field(__u8, mmu_valid_gen)
29633e3042dSSean Christopherson 		__field(unsigned int, mmu_used_pages)
29733e3042dSSean Christopherson 	),
29833e3042dSSean Christopherson 
29933e3042dSSean Christopherson 	TP_fast_assign(
30033e3042dSSean Christopherson 		__entry->mmu_valid_gen = kvm->arch.mmu_valid_gen;
30133e3042dSSean Christopherson 		__entry->mmu_used_pages = kvm->arch.n_used_mmu_pages;
30233e3042dSSean Christopherson 	),
30333e3042dSSean Christopherson 
30433e3042dSSean Christopherson 	TP_printk("kvm-mmu-valid-gen %u used_pages %x",
30533e3042dSSean Christopherson 		  __entry->mmu_valid_gen, __entry->mmu_used_pages
30633e3042dSSean Christopherson 	)
30733e3042dSSean Christopherson );
30833e3042dSSean Christopherson 
30933e3042dSSean Christopherson 
31033e3042dSSean Christopherson TRACE_EVENT(
31133e3042dSSean Christopherson 	check_mmio_spte,
31233e3042dSSean Christopherson 	TP_PROTO(u64 spte, unsigned int kvm_gen, unsigned int spte_gen),
31333e3042dSSean Christopherson 	TP_ARGS(spte, kvm_gen, spte_gen),
31433e3042dSSean Christopherson 
31533e3042dSSean Christopherson 	TP_STRUCT__entry(
31633e3042dSSean Christopherson 		__field(unsigned int, kvm_gen)
31733e3042dSSean Christopherson 		__field(unsigned int, spte_gen)
31833e3042dSSean Christopherson 		__field(u64, spte)
31933e3042dSSean Christopherson 	),
32033e3042dSSean Christopherson 
32133e3042dSSean Christopherson 	TP_fast_assign(
32233e3042dSSean Christopherson 		__entry->kvm_gen = kvm_gen;
32333e3042dSSean Christopherson 		__entry->spte_gen = spte_gen;
32433e3042dSSean Christopherson 		__entry->spte = spte;
32533e3042dSSean Christopherson 	),
32633e3042dSSean Christopherson 
32733e3042dSSean Christopherson 	TP_printk("spte %llx kvm_gen %x spte-gen %x valid %d", __entry->spte,
32833e3042dSSean Christopherson 		  __entry->kvm_gen, __entry->spte_gen,
32933e3042dSSean Christopherson 		  __entry->kvm_gen == __entry->spte_gen
33033e3042dSSean Christopherson 	)
33133e3042dSSean Christopherson );
33233e3042dSSean Christopherson 
33333e3042dSSean Christopherson TRACE_EVENT(
33433e3042dSSean Christopherson 	kvm_mmu_set_spte,
33533e3042dSSean Christopherson 	TP_PROTO(int level, gfn_t gfn, u64 *sptep),
33633e3042dSSean Christopherson 	TP_ARGS(level, gfn, sptep),
33733e3042dSSean Christopherson 
33833e3042dSSean Christopherson 	TP_STRUCT__entry(
33933e3042dSSean Christopherson 		__field(u64, gfn)
34033e3042dSSean Christopherson 		__field(u64, spte)
34133e3042dSSean Christopherson 		__field(u64, sptep)
34233e3042dSSean Christopherson 		__field(u8, level)
34333e3042dSSean Christopherson 		/* These depend on page entry type, so compute them now.  */
34433e3042dSSean Christopherson 		__field(bool, r)
34533e3042dSSean Christopherson 		__field(bool, x)
34633e3042dSSean Christopherson 		__field(signed char, u)
34733e3042dSSean Christopherson 	),
34833e3042dSSean Christopherson 
34933e3042dSSean Christopherson 	TP_fast_assign(
35033e3042dSSean Christopherson 		__entry->gfn = gfn;
35133e3042dSSean Christopherson 		__entry->spte = *sptep;
35233e3042dSSean Christopherson 		__entry->sptep = virt_to_phys(sptep);
35333e3042dSSean Christopherson 		__entry->level = level;
35433e3042dSSean Christopherson 		__entry->r = shadow_present_mask || (__entry->spte & PT_PRESENT_MASK);
35533e3042dSSean Christopherson 		__entry->x = is_executable_pte(__entry->spte);
35633e3042dSSean Christopherson 		__entry->u = shadow_user_mask ? !!(__entry->spte & shadow_user_mask) : -1;
35733e3042dSSean Christopherson 	),
35833e3042dSSean Christopherson 
35933e3042dSSean Christopherson 	TP_printk("gfn %llx spte %llx (%s%s%s%s) level %d at %llx",
36033e3042dSSean Christopherson 		  __entry->gfn, __entry->spte,
36133e3042dSSean Christopherson 		  __entry->r ? "r" : "-",
36233e3042dSSean Christopherson 		  __entry->spte & PT_WRITABLE_MASK ? "w" : "-",
36333e3042dSSean Christopherson 		  __entry->x ? "x" : "-",
36433e3042dSSean Christopherson 		  __entry->u == -1 ? "" : (__entry->u ? "u" : "-"),
36533e3042dSSean Christopherson 		  __entry->level, __entry->sptep
36633e3042dSSean Christopherson 	)
36733e3042dSSean Christopherson );
36833e3042dSSean Christopherson 
36933e3042dSSean Christopherson TRACE_EVENT(
37033e3042dSSean Christopherson 	kvm_mmu_spte_requested,
371f0066d94SPaolo Bonzini 	TP_PROTO(struct kvm_page_fault *fault),
372f0066d94SPaolo Bonzini 	TP_ARGS(fault),
37333e3042dSSean Christopherson 
37433e3042dSSean Christopherson 	TP_STRUCT__entry(
37533e3042dSSean Christopherson 		__field(u64, gfn)
37633e3042dSSean Christopherson 		__field(u64, pfn)
37733e3042dSSean Christopherson 		__field(u8, level)
37833e3042dSSean Christopherson 	),
37933e3042dSSean Christopherson 
38033e3042dSSean Christopherson 	TP_fast_assign(
381f0066d94SPaolo Bonzini 		__entry->gfn = fault->gfn;
382f0066d94SPaolo Bonzini 		__entry->pfn = fault->pfn | (fault->gfn & (KVM_PAGES_PER_HPAGE(fault->goal_level) - 1));
383f0066d94SPaolo Bonzini 		__entry->level = fault->goal_level;
38433e3042dSSean Christopherson 	),
38533e3042dSSean Christopherson 
38633e3042dSSean Christopherson 	TP_printk("gfn %llx pfn %llx level %d",
38733e3042dSSean Christopherson 		  __entry->gfn, __entry->pfn, __entry->level
38833e3042dSSean Christopherson 	)
38933e3042dSSean Christopherson );
39033e3042dSSean Christopherson 
391b9a98c34SBen Gardon TRACE_EVENT(
392b9a98c34SBen Gardon 	kvm_tdp_mmu_spte_changed,
393b9a98c34SBen Gardon 	TP_PROTO(int as_id, gfn_t gfn, int level, u64 old_spte, u64 new_spte),
394b9a98c34SBen Gardon 	TP_ARGS(as_id, gfn, level, old_spte, new_spte),
395b9a98c34SBen Gardon 
396b9a98c34SBen Gardon 	TP_STRUCT__entry(
397b9a98c34SBen Gardon 		__field(u64, gfn)
398b9a98c34SBen Gardon 		__field(u64, old_spte)
399b9a98c34SBen Gardon 		__field(u64, new_spte)
400b9a98c34SBen Gardon 		/* Level cannot be larger than 5 on x86, so it fits in a u8. */
401b9a98c34SBen Gardon 		__field(u8, level)
402b9a98c34SBen Gardon 		/* as_id can only be 0 or 1 x86, so it fits in a u8. */
403b9a98c34SBen Gardon 		__field(u8, as_id)
404b9a98c34SBen Gardon 	),
405b9a98c34SBen Gardon 
406b9a98c34SBen Gardon 	TP_fast_assign(
407b9a98c34SBen Gardon 		__entry->gfn = gfn;
408b9a98c34SBen Gardon 		__entry->old_spte = old_spte;
409b9a98c34SBen Gardon 		__entry->new_spte = new_spte;
410b9a98c34SBen Gardon 		__entry->level = level;
411b9a98c34SBen Gardon 		__entry->as_id = as_id;
412b9a98c34SBen Gardon 	),
413b9a98c34SBen Gardon 
414b9a98c34SBen Gardon 	TP_printk("as id %d gfn %llx level %d old_spte %llx new_spte %llx",
415b9a98c34SBen Gardon 		  __entry->as_id, __entry->gfn, __entry->level,
416b9a98c34SBen Gardon 		  __entry->old_spte, __entry->new_spte
417b9a98c34SBen Gardon 	)
418b9a98c34SBen Gardon );
419b9a98c34SBen Gardon 
420e0b728b1SDavid Matlack TRACE_EVENT(
421e0b728b1SDavid Matlack 	kvm_mmu_split_huge_page,
422e0b728b1SDavid Matlack 	TP_PROTO(u64 gfn, u64 spte, int level, int errno),
423e0b728b1SDavid Matlack 	TP_ARGS(gfn, spte, level, errno),
424e0b728b1SDavid Matlack 
425e0b728b1SDavid Matlack 	TP_STRUCT__entry(
426e0b728b1SDavid Matlack 		__field(u64, gfn)
427e0b728b1SDavid Matlack 		__field(u64, spte)
428e0b728b1SDavid Matlack 		__field(int, level)
429e0b728b1SDavid Matlack 		__field(int, errno)
430e0b728b1SDavid Matlack 	),
431e0b728b1SDavid Matlack 
432e0b728b1SDavid Matlack 	TP_fast_assign(
433e0b728b1SDavid Matlack 		__entry->gfn = gfn;
434e0b728b1SDavid Matlack 		__entry->spte = spte;
435e0b728b1SDavid Matlack 		__entry->level = level;
436e0b728b1SDavid Matlack 		__entry->errno = errno;
437e0b728b1SDavid Matlack 	),
438e0b728b1SDavid Matlack 
439e0b728b1SDavid Matlack 	TP_printk("gfn %llx spte %llx level %d errno %d",
440e0b728b1SDavid Matlack 		  __entry->gfn, __entry->spte, __entry->level, __entry->errno)
441e0b728b1SDavid Matlack );
442e0b728b1SDavid Matlack 
44333e3042dSSean Christopherson #endif /* _TRACE_KVMMMU_H */
44433e3042dSSean Christopherson 
44533e3042dSSean Christopherson #undef TRACE_INCLUDE_PATH
44633e3042dSSean Christopherson #define TRACE_INCLUDE_PATH mmu
44733e3042dSSean Christopherson #undef TRACE_INCLUDE_FILE
44833e3042dSSean Christopherson #define TRACE_INCLUDE_FILE mmutrace
44933e3042dSSean Christopherson 
45033e3042dSSean Christopherson /* This part must be outside protection */
45133e3042dSSean Christopherson #include <trace/define_trace.h>
452