1 // SPDX-FileCopyrightText: 2013 Mohamad Gebai <mohamad.gebai@polymtl.ca>
3 // SPDX-License-Identifier: GPL-2.0-only
5 #if !defined(LTTNG_TRACE_KVM_MMU_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define LTTNG_TRACE_KVM_MMU_H
8 #include <lttng/tracepoint-event.h>
9 #include <lttng/kernel-version.h>
11 #include <linux/trace_events.h>
14 #define TRACE_SYSTEM kvm_mmu
16 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,1,0) || \
17 LTTNG_RHEL_KERNEL_RANGE(4,18,0,147,0,0, 4,19,0,0,0,0))
19 #define LTTNG_KVM_MMU_PAGE_FIELDS \
20 ctf_integer(__u64, gfn, (sp)->gfn) \
21 ctf_integer(__u32, role, (sp)->role.word) \
22 ctf_integer(__u32, root_count, (sp)->root_count) \
23 ctf_integer(bool, unsync, (sp)->unsync)
27 #define LTTNG_KVM_MMU_PAGE_FIELDS \
28 ctf_integer(unsigned long, mmu_valid_gen, (sp)->mmu_valid_gen) \
29 ctf_integer(__u64, gfn, (sp)->gfn) \
30 ctf_integer(__u32, role, (sp)->role.word) \
31 ctf_integer(__u32, root_count, (sp)->root_count) \
32 ctf_integer(bool, unsync, (sp)->unsync)
37 * A pagetable walk has started
39 LTTNG_TRACEPOINT_EVENT(
40 kvm_mmu_pagetable_walk
,
41 TP_PROTO(u64 addr
, u32 pferr
),
45 ctf_integer_hex(__u64
, addr
, addr
)
46 ctf_integer(__u32
, pferr
, pferr
)
50 /* We just walked a paging element */
51 LTTNG_TRACEPOINT_EVENT(
52 kvm_mmu_paging_element
,
53 TP_PROTO(u64 pte
, int level
),
57 ctf_integer(__u64
, pte
, pte
)
58 ctf_integer(__u32
, level
, level
)
62 LTTNG_TRACEPOINT_EVENT_CLASS(kvm_mmu_set_bit_class
,
64 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
66 TP_ARGS(table_gfn
, index
, size
),
69 ctf_integer(__u64
, gpa
,
70 ((u64
)table_gfn
<< PAGE_SHIFT
) + index
* size
)
74 /* We set a pte accessed bit */
75 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_set_bit_class
, kvm_mmu_set_accessed_bit
,
77 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
79 TP_ARGS(table_gfn
, index
, size
)
82 /* We set a pte dirty bit */
83 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_set_bit_class
, kvm_mmu_set_dirty_bit
,
85 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
87 TP_ARGS(table_gfn
, index
, size
)
90 LTTNG_TRACEPOINT_EVENT(
96 ctf_integer(__u32
, pferr
, pferr
)
100 LTTNG_TRACEPOINT_EVENT(
102 TP_PROTO(struct kvm_mmu_page
*sp
, bool created
),
103 TP_ARGS(sp
, created
),
106 LTTNG_KVM_MMU_PAGE_FIELDS
107 ctf_integer(bool, created
, created
)
111 LTTNG_TRACEPOINT_EVENT_CLASS(kvm_mmu_page_class
,
113 TP_PROTO(struct kvm_mmu_page
*sp
),
117 LTTNG_KVM_MMU_PAGE_FIELDS
121 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class
, kvm_mmu_sync_page
,
122 TP_PROTO(struct kvm_mmu_page
*sp
),
127 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class
, kvm_mmu_unsync_page
,
128 TP_PROTO(struct kvm_mmu_page
*sp
),
133 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class
, kvm_mmu_prepare_zap_page
,
134 TP_PROTO(struct kvm_mmu_page
*sp
),
139 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,10,0) || \
140 LTTNG_RHEL_KERNEL_RANGE(4,18,0,305,0,0, 4,19,0,0,0,0))
142 LTTNG_TRACEPOINT_EVENT_MAP(
145 kvm_mmu_mark_mmio_spte
,
147 TP_PROTO(u64
*sptep
, gfn_t gfn
, u64 spte
),
148 TP_ARGS(sptep
, gfn
, spte
),
151 ctf_integer_hex(void *, sptep
, sptep
)
152 ctf_integer(gfn_t
, gfn
, gfn
)
153 ctf_integer(unsigned, access
, spte
& ACC_ALL
)
154 ctf_integer(unsigned int, gen
, get_mmio_spte_generation(spte
))
160 LTTNG_TRACEPOINT_EVENT_MAP(
163 kvm_mmu_mark_mmio_spte
,
165 TP_PROTO(u64
*sptep
, gfn_t gfn
, unsigned access
, unsigned int gen
),
166 TP_ARGS(sptep
, gfn
, access
, gen
),
169 ctf_integer_hex(void *, sptep
, sptep
)
170 ctf_integer(gfn_t
, gfn
, gfn
)
171 ctf_integer(unsigned, access
, access
)
172 ctf_integer(unsigned int, gen
, gen
)
177 LTTNG_TRACEPOINT_EVENT_MAP(
178 handle_mmio_page_fault
,
180 kvm_mmu_handle_mmio_page_fault
,
182 TP_PROTO(u64 addr
, gfn_t gfn
, unsigned access
),
183 TP_ARGS(addr
, gfn
, access
),
186 ctf_integer_hex(u64
, addr
, addr
)
187 ctf_integer(gfn_t
, gfn
, gfn
)
188 ctf_integer(unsigned, access
, access
)
192 #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,16,0))
193 LTTNG_TRACEPOINT_EVENT_MAP(
196 kvm_mmu_fast_page_fault
,
198 TP_PROTO(struct kvm_vcpu
*vcpu
, struct kvm_page_fault
*fault
,
199 u64
*sptep
, u64 old_spte
, int ret
),
200 TP_ARGS(vcpu
, fault
, sptep
, old_spte
, ret
),
203 ctf_integer(int, vcpu_id
, vcpu
->vcpu_id
)
204 ctf_integer(gpa_t
, cr2_or_gpa
, fault
->addr
)
205 ctf_integer(u32
, error_code
, fault
->error_code
)
206 ctf_integer_hex(u64
*, sptep
, sptep
)
207 ctf_integer(u64
, old_spte
, old_spte
)
208 ctf_integer(u64
, new_spte
, *sptep
)
209 ctf_integer(int, ret
, ret
)
212 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,10,0) || \
213 LTTNG_RHEL_KERNEL_RANGE(4,18,0,305,0,0, 4,19,0,0,0,0))
214 LTTNG_TRACEPOINT_EVENT_MAP(
217 kvm_mmu_fast_page_fault
,
219 TP_PROTO(struct kvm_vcpu
*vcpu
, gpa_t cr2_or_gpa
, u32 error_code
,
220 u64
*sptep
, u64 old_spte
, int ret
),
221 TP_ARGS(vcpu
, cr2_or_gpa
, error_code
, sptep
, old_spte
, ret
),
224 ctf_integer(int, vcpu_id
, vcpu
->vcpu_id
)
225 ctf_integer(gpa_t
, cr2_or_gpa
, cr2_or_gpa
)
226 ctf_integer(u32
, error_code
, error_code
)
227 ctf_integer_hex(u64
*, sptep
, sptep
)
228 ctf_integer(u64
, old_spte
, old_spte
)
229 ctf_integer(u64
, new_spte
, *sptep
)
230 ctf_integer(int, ret
, ret
)
233 #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0) || \
234 LTTNG_KERNEL_RANGE(4,19,103, 4,20,0) || \
235 LTTNG_KERNEL_RANGE(5,4,19, 5,5,0) || \
236 LTTNG_KERNEL_RANGE(5,5,3, 5,6,0) || \
237 LTTNG_UBUNTU_KERNEL_RANGE(4,15,18,92, 4,16,0,0) || \
238 LTTNG_UBUNTU_KERNEL_RANGE(5,0,21,44, 5,1,0,0) || \
239 LTTNG_UBUNTU_KERNEL_RANGE(5,3,18,43, 5,3,18,45) || \
240 LTTNG_UBUNTU_KERNEL_RANGE(5,3,18,46, 5,4,0,0))
241 LTTNG_TRACEPOINT_EVENT_MAP(
244 kvm_mmu_fast_page_fault
,
246 TP_PROTO(struct kvm_vcpu
*vcpu
, gpa_t cr2_or_gpa
, u32 error_code
,
247 u64
*sptep
, u64 old_spte
, bool retry
),
248 TP_ARGS(vcpu
, cr2_or_gpa
, error_code
, sptep
, old_spte
, retry
),
251 ctf_integer(int, vcpu_id
, vcpu
->vcpu_id
)
252 ctf_integer(gpa_t
, cr2_or_gpa
, cr2_or_gpa
)
253 ctf_integer(u32
, error_code
, error_code
)
254 ctf_integer_hex(u64
*, sptep
, sptep
)
255 ctf_integer(u64
, old_spte
, old_spte
)
256 ctf_integer(u64
, new_spte
, *sptep
)
257 ctf_integer(bool, retry
, retry
)
261 LTTNG_TRACEPOINT_EVENT_MAP(
264 kvm_mmu_fast_page_fault
,
266 TP_PROTO(struct kvm_vcpu
*vcpu
, gva_t gva
, u32 error_code
,
267 u64
*sptep
, u64 old_spte
, bool retry
),
268 TP_ARGS(vcpu
, gva
, error_code
, sptep
, old_spte
, retry
),
271 ctf_integer(int, vcpu_id
, vcpu
->vcpu_id
)
272 ctf_integer(gva_t
, gva
, gva
)
273 ctf_integer(u32
, error_code
, error_code
)
274 ctf_integer_hex(u64
*, sptep
, sptep
)
275 ctf_integer(u64
, old_spte
, old_spte
)
276 ctf_integer(u64
, new_spte
, *sptep
)
277 ctf_integer(bool, retry
, retry
)
282 #endif /* LTTNG_TRACE_KVM_MMU_H */
284 #undef TRACE_INCLUDE_PATH
285 #define TRACE_INCLUDE_PATH instrumentation/events/arch/x86/kvm
286 #undef TRACE_INCLUDE_FILE
287 #define TRACE_INCLUDE_FILE mmutrace
289 /* This part must be outside protection */
290 #include <lttng/define_trace.h>