1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #if !defined(LTTNG_TRACE_KVM_MMU_H) || defined(TRACE_HEADER_MULTI_READ)
3 #define LTTNG_TRACE_KVM_MMU_H
5 #include <lttng/tracepoint-event.h>
6 #include <lttng/kernel-version.h>
8 #include <linux/trace_events.h>
11 #define TRACE_SYSTEM kvm_mmu
13 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,1,0) || \
14 LTTNG_RHEL_KERNEL_RANGE(4,18,0,147,0,0, 4,19,0,0,0,0))
16 #define LTTNG_KVM_MMU_PAGE_FIELDS \
17 ctf_integer(__u64, gfn, (sp)->gfn) \
18 ctf_integer(__u32, role, (sp)->role.word) \
19 ctf_integer(__u32, root_count, (sp)->root_count) \
20 ctf_integer(bool, unsync, (sp)->unsync)
24 #define LTTNG_KVM_MMU_PAGE_FIELDS \
25 ctf_integer(unsigned long, mmu_valid_gen, (sp)->mmu_valid_gen) \
26 ctf_integer(__u64, gfn, (sp)->gfn) \
27 ctf_integer(__u32, role, (sp)->role.word) \
28 ctf_integer(__u32, root_count, (sp)->root_count) \
29 ctf_integer(bool, unsync, (sp)->unsync)
34 * A pagetable walk has started
36 LTTNG_TRACEPOINT_EVENT(
37 kvm_mmu_pagetable_walk
,
38 TP_PROTO(u64 addr
, u32 pferr
),
42 ctf_integer_hex(__u64
, addr
, addr
)
43 ctf_integer(__u32
, pferr
, pferr
)
47 /* We just walked a paging element */
48 LTTNG_TRACEPOINT_EVENT(
49 kvm_mmu_paging_element
,
50 TP_PROTO(u64 pte
, int level
),
54 ctf_integer(__u64
, pte
, pte
)
55 ctf_integer(__u32
, level
, level
)
59 LTTNG_TRACEPOINT_EVENT_CLASS(kvm_mmu_set_bit_class
,
61 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
63 TP_ARGS(table_gfn
, index
, size
),
66 ctf_integer(__u64
, gpa
,
67 ((u64
)table_gfn
<< PAGE_SHIFT
) + index
* size
)
71 /* We set a pte accessed bit */
72 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_set_bit_class
, kvm_mmu_set_accessed_bit
,
74 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
76 TP_ARGS(table_gfn
, index
, size
)
79 /* We set a pte dirty bit */
80 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_set_bit_class
, kvm_mmu_set_dirty_bit
,
82 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
84 TP_ARGS(table_gfn
, index
, size
)
87 LTTNG_TRACEPOINT_EVENT(
93 ctf_integer(__u32
, pferr
, pferr
)
97 LTTNG_TRACEPOINT_EVENT(
99 TP_PROTO(struct kvm_mmu_page
*sp
, bool created
),
100 TP_ARGS(sp
, created
),
103 LTTNG_KVM_MMU_PAGE_FIELDS
104 ctf_integer(bool, created
, created
)
108 LTTNG_TRACEPOINT_EVENT_CLASS(kvm_mmu_page_class
,
110 TP_PROTO(struct kvm_mmu_page
*sp
),
114 LTTNG_KVM_MMU_PAGE_FIELDS
118 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class
, kvm_mmu_sync_page
,
119 TP_PROTO(struct kvm_mmu_page
*sp
),
124 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class
, kvm_mmu_unsync_page
,
125 TP_PROTO(struct kvm_mmu_page
*sp
),
130 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class
, kvm_mmu_prepare_zap_page
,
131 TP_PROTO(struct kvm_mmu_page
*sp
),
136 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,10,0))
138 LTTNG_TRACEPOINT_EVENT_MAP(
141 kvm_mmu_mark_mmio_spte
,
143 TP_PROTO(u64
*sptep
, gfn_t gfn
, u64 spte
),
144 TP_ARGS(sptep
, gfn
, spte
),
147 ctf_integer_hex(void *, sptep
, sptep
)
148 ctf_integer(gfn_t
, gfn
, gfn
)
149 ctf_integer(unsigned, access
, spte
& ACC_ALL
)
150 ctf_integer(unsigned int, gen
, get_mmio_spte_generation(spte
))
156 LTTNG_TRACEPOINT_EVENT_MAP(
159 kvm_mmu_mark_mmio_spte
,
161 TP_PROTO(u64
*sptep
, gfn_t gfn
, unsigned access
, unsigned int gen
),
162 TP_ARGS(sptep
, gfn
, access
, gen
),
165 ctf_integer_hex(void *, sptep
, sptep
)
166 ctf_integer(gfn_t
, gfn
, gfn
)
167 ctf_integer(unsigned, access
, access
)
168 ctf_integer(unsigned int, gen
, gen
)
173 LTTNG_TRACEPOINT_EVENT_MAP(
174 handle_mmio_page_fault
,
176 kvm_mmu_handle_mmio_page_fault
,
178 TP_PROTO(u64 addr
, gfn_t gfn
, unsigned access
),
179 TP_ARGS(addr
, gfn
, access
),
182 ctf_integer_hex(u64
, addr
, addr
)
183 ctf_integer(gfn_t
, gfn
, gfn
)
184 ctf_integer(unsigned, access
, access
)
188 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,16,0))
189 LTTNG_TRACEPOINT_EVENT_MAP(
192 kvm_mmu_fast_page_fault
,
194 TP_PROTO(struct kvm_vcpu
*vcpu
, struct kvm_page_fault
*fault
,
195 u64
*sptep
, u64 old_spte
, int ret
),
196 TP_ARGS(vcpu
, fault
, sptep
, old_spte
, ret
),
199 ctf_integer(int, vcpu_id
, vcpu
->vcpu_id
)
200 ctf_integer(gpa_t
, cr2_or_gpa
, fault
->addr
)
201 ctf_integer(u32
, error_code
, fault
->error_code
)
202 ctf_integer_hex(u64
*, sptep
, sptep
)
203 ctf_integer(u64
, old_spte
, old_spte
)
204 ctf_integer(u64
, new_spte
, *sptep
)
205 ctf_integer(int, ret
, ret
)
208 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,10,0))
209 LTTNG_TRACEPOINT_EVENT_MAP(
212 kvm_mmu_fast_page_fault
,
214 TP_PROTO(struct kvm_vcpu
*vcpu
, gpa_t cr2_or_gpa
, u32 error_code
,
215 u64
*sptep
, u64 old_spte
, int ret
),
216 TP_ARGS(vcpu
, cr2_or_gpa
, error_code
, sptep
, old_spte
, ret
),
219 ctf_integer(int, vcpu_id
, vcpu
->vcpu_id
)
220 ctf_integer(gpa_t
, cr2_or_gpa
, cr2_or_gpa
)
221 ctf_integer(u32
, error_code
, error_code
)
222 ctf_integer_hex(u64
*, sptep
, sptep
)
223 ctf_integer(u64
, old_spte
, old_spte
)
224 ctf_integer(u64
, new_spte
, *sptep
)
225 ctf_integer(int, ret
, ret
)
228 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0) || \
229 LTTNG_KERNEL_RANGE(4,19,103, 4,20,0) || \
230 LTTNG_KERNEL_RANGE(5,4,19, 5,5,0) || \
231 LTTNG_KERNEL_RANGE(5,5,3, 5,6,0) || \
232 LTTNG_UBUNTU_KERNEL_RANGE(4,15,18,92, 4,16,0,0) || \
233 LTTNG_UBUNTU_KERNEL_RANGE(5,0,21,44, 5,1,0,0) || \
234 LTTNG_UBUNTU_KERNEL_RANGE(5,3,18,43, 5,3,18,45) || \
235 LTTNG_UBUNTU_KERNEL_RANGE(5,3,18,46, 5,4,0,0))
236 LTTNG_TRACEPOINT_EVENT_MAP(
239 kvm_mmu_fast_page_fault
,
241 TP_PROTO(struct kvm_vcpu
*vcpu
, gpa_t cr2_or_gpa
, u32 error_code
,
242 u64
*sptep
, u64 old_spte
, bool retry
),
243 TP_ARGS(vcpu
, cr2_or_gpa
, error_code
, sptep
, old_spte
, retry
),
246 ctf_integer(int, vcpu_id
, vcpu
->vcpu_id
)
247 ctf_integer(gpa_t
, cr2_or_gpa
, cr2_or_gpa
)
248 ctf_integer(u32
, error_code
, error_code
)
249 ctf_integer_hex(u64
*, sptep
, sptep
)
250 ctf_integer(u64
, old_spte
, old_spte
)
251 ctf_integer(u64
, new_spte
, *sptep
)
252 ctf_integer(bool, retry
, retry
)
256 LTTNG_TRACEPOINT_EVENT_MAP(
259 kvm_mmu_fast_page_fault
,
261 TP_PROTO(struct kvm_vcpu
*vcpu
, gva_t gva
, u32 error_code
,
262 u64
*sptep
, u64 old_spte
, bool retry
),
263 TP_ARGS(vcpu
, gva
, error_code
, sptep
, old_spte
, retry
),
266 ctf_integer(int, vcpu_id
, vcpu
->vcpu_id
)
267 ctf_integer(gva_t
, gva
, gva
)
268 ctf_integer(u32
, error_code
, error_code
)
269 ctf_integer_hex(u64
*, sptep
, sptep
)
270 ctf_integer(u64
, old_spte
, old_spte
)
271 ctf_integer(u64
, new_spte
, *sptep
)
272 ctf_integer(bool, retry
, retry
)
277 #endif /* LTTNG_TRACE_KVM_MMU_H */
279 #undef TRACE_INCLUDE_PATH
280 #define TRACE_INCLUDE_PATH instrumentation/events/arch/x86/kvm
281 #undef TRACE_INCLUDE_FILE
282 #define TRACE_INCLUDE_FILE mmutrace
284 /* This part must be outside protection */
285 #include <lttng/define_trace.h>