1 /* SPDX-License-Identifier: GPL-2.0 */
2 #if !defined(LTTNG_TRACE_KVM_MMU_H) || defined(TRACE_HEADER_MULTI_READ)
3 #define LTTNG_TRACE_KVM_MMU_H
5 #include <probes/lttng-tracepoint-event.h>
6 #include <linux/version.h>
8 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0))
9 #include <linux/trace_events.h>
10 #else /* if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)) */
11 #include <linux/ftrace_event.h>
12 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)) */
15 #define TRACE_SYSTEM kvm_mmu
17 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0) || \
18 LTTNG_RHEL_KERNEL_RANGE(4,18,0,147,0,0, 4,19,0,0,0,0))
20 #define LTTNG_KVM_MMU_PAGE_FIELDS \
21 ctf_integer(__u64, gfn, (sp)->gfn) \
22 ctf_integer(__u32, role, (sp)->role.word) \
23 ctf_integer(__u32, root_count, (sp)->root_count) \
24 ctf_integer(bool, unsync, (sp)->unsync)
26 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0))
28 #define LTTNG_KVM_MMU_PAGE_FIELDS \
29 ctf_integer(unsigned long, mmu_valid_gen, (sp)->mmu_valid_gen) \
30 ctf_integer(__u64, gfn, (sp)->gfn) \
31 ctf_integer(__u32, role, (sp)->role.word) \
32 ctf_integer(__u32, root_count, (sp)->root_count) \
33 ctf_integer(bool, unsync, (sp)->unsync)
35 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) */
37 #define LTTNG_KVM_MMU_PAGE_FIELDS \
38 ctf_integer(__u64, gfn, (sp)->gfn) \
39 ctf_integer(__u32, role, (sp)->role.word) \
40 ctf_integer(__u32, root_count, (sp)->root_count) \
41 ctf_integer(bool, unsync, (sp)->unsync)
43 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) */
45 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
47 * A pagetable walk has started
49 LTTNG_TRACEPOINT_EVENT(
50 kvm_mmu_pagetable_walk
,
51 TP_PROTO(u64 addr
, u32 pferr
),
55 ctf_integer(__u64
, addr
, addr
)
56 ctf_integer(__u32
, pferr
, pferr
)
59 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)) */
61 * A pagetable walk has started
63 LTTNG_TRACEPOINT_EVENT(
64 kvm_mmu_pagetable_walk
,
65 TP_PROTO(u64 addr
, int write_fault
, int user_fault
, int fetch_fault
),
66 TP_ARGS(addr
, write_fault
, user_fault
, fetch_fault
),
69 ctf_integer(__u64
, addr
, addr
)
70 ctf_integer(__u32
, pferr
,
71 (!!write_fault
<< 1) | (!!user_fault
<< 2)
72 | (!!fetch_fault
<< 4))
75 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)) */
77 /* We just walked a paging element */
78 LTTNG_TRACEPOINT_EVENT(
79 kvm_mmu_paging_element
,
80 TP_PROTO(u64 pte
, int level
),
84 ctf_integer(__u64
, pte
, pte
)
85 ctf_integer(__u32
, level
, level
)
89 LTTNG_TRACEPOINT_EVENT_CLASS(kvm_mmu_set_bit_class
,
91 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
93 TP_ARGS(table_gfn
, index
, size
),
96 ctf_integer(__u64
, gpa
,
97 ((u64
)table_gfn
<< PAGE_SHIFT
) + index
* size
)
101 /* We set a pte accessed bit */
102 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_set_bit_class
, kvm_mmu_set_accessed_bit
,
104 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
106 TP_ARGS(table_gfn
, index
, size
)
109 /* We set a pte dirty bit */
110 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_set_bit_class
, kvm_mmu_set_dirty_bit
,
112 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
114 TP_ARGS(table_gfn
, index
, size
)
117 LTTNG_TRACEPOINT_EVENT(
118 kvm_mmu_walker_error
,
123 ctf_integer(__u32
, pferr
, pferr
)
127 LTTNG_TRACEPOINT_EVENT(
129 TP_PROTO(struct kvm_mmu_page
*sp
, bool created
),
130 TP_ARGS(sp
, created
),
133 LTTNG_KVM_MMU_PAGE_FIELDS
134 ctf_integer(bool, created
, created
)
138 LTTNG_TRACEPOINT_EVENT_CLASS(kvm_mmu_page_class
,
140 TP_PROTO(struct kvm_mmu_page
*sp
),
144 LTTNG_KVM_MMU_PAGE_FIELDS
148 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class
, kvm_mmu_sync_page
,
149 TP_PROTO(struct kvm_mmu_page
*sp
),
154 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class
, kvm_mmu_unsync_page
,
155 TP_PROTO(struct kvm_mmu_page
*sp
),
160 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class
, kvm_mmu_prepare_zap_page
,
161 TP_PROTO(struct kvm_mmu_page
*sp
),
166 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0))
168 LTTNG_TRACEPOINT_EVENT_MAP(
171 kvm_mmu_mark_mmio_spte
,
173 TP_PROTO(u64
*sptep
, gfn_t gfn
, unsigned access
, unsigned int gen
),
174 TP_ARGS(sptep
, gfn
, access
, gen
),
177 ctf_integer_hex(void *, sptep
, sptep
)
178 ctf_integer(gfn_t
, gfn
, gfn
)
179 ctf_integer(unsigned, access
, access
)
180 ctf_integer(unsigned int, gen
, gen
)
184 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) */
186 LTTNG_TRACEPOINT_EVENT_MAP(
189 kvm_mmu_mark_mmio_spte
,
191 TP_PROTO(u64
*sptep
, gfn_t gfn
, unsigned access
),
192 TP_ARGS(sptep
, gfn
, access
),
195 ctf_integer_hex(void *, sptep
, sptep
)
196 ctf_integer(gfn_t
, gfn
, gfn
)
197 ctf_integer(unsigned, access
, access
)
201 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) */
203 LTTNG_TRACEPOINT_EVENT_MAP(
204 handle_mmio_page_fault
,
206 kvm_mmu_handle_mmio_page_fault
,
208 TP_PROTO(u64 addr
, gfn_t gfn
, unsigned access
),
209 TP_ARGS(addr
, gfn
, access
),
212 ctf_integer(u64
, addr
, addr
)
213 ctf_integer(gfn_t
, gfn
, gfn
)
214 ctf_integer(unsigned, access
, access
)
218 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0) || \
219 LTTNG_KERNEL_RANGE(4,19,103, 4,20,0) || \
220 LTTNG_KERNEL_RANGE(5,4,19, 5,5,0) || \
221 LTTNG_KERNEL_RANGE(5,5,3, 5,6,0) || \
222 LTTNG_UBUNTU_KERNEL_RANGE(4,15,18,92, 4,16,0,0) || \
223 LTTNG_UBUNTU_KERNEL_RANGE(5,0,21,44, 5,1,0,0) || \
224 LTTNG_UBUNTU_KERNEL_RANGE(5,3,18,43, 5,3,18,45) || \
225 LTTNG_UBUNTU_KERNEL_RANGE(5,3,18,46, 5,4,0,0))
226 LTTNG_TRACEPOINT_EVENT_MAP(
229 kvm_mmu_fast_page_fault
,
231 TP_PROTO(struct kvm_vcpu
*vcpu
, gpa_t cr2_or_gpa
, u32 error_code
,
232 u64
*sptep
, u64 old_spte
, bool retry
),
233 TP_ARGS(vcpu
, cr2_or_gpa
, error_code
, sptep
, old_spte
, retry
),
236 ctf_integer(int, vcpu_id
, vcpu
->vcpu_id
)
237 ctf_integer(gpa_t
, cr2_or_gpa
, cr2_or_gpa
)
238 ctf_integer(u32
, error_code
, error_code
)
239 ctf_integer_hex(u64
*, sptep
, sptep
)
240 ctf_integer(u64
, old_spte
, old_spte
)
241 ctf_integer(u64
, new_spte
, *sptep
)
242 ctf_integer(bool, retry
, retry
)
246 LTTNG_TRACEPOINT_EVENT_MAP(
249 kvm_mmu_fast_page_fault
,
251 TP_PROTO(struct kvm_vcpu
*vcpu
, gva_t gva
, u32 error_code
,
252 u64
*sptep
, u64 old_spte
, bool retry
),
253 TP_ARGS(vcpu
, gva
, error_code
, sptep
, old_spte
, retry
),
256 ctf_integer(int, vcpu_id
, vcpu
->vcpu_id
)
257 ctf_integer(gva_t
, gva
, gva
)
258 ctf_integer(u32
, error_code
, error_code
)
259 ctf_integer_hex(u64
*, sptep
, sptep
)
260 ctf_integer(u64
, old_spte
, old_spte
)
261 ctf_integer(u64
, new_spte
, *sptep
)
262 ctf_integer(bool, retry
, retry
)
267 #endif /* LTTNG_TRACE_KVM_MMU_H */
269 #undef TRACE_INCLUDE_PATH
270 #define TRACE_INCLUDE_PATH instrumentation/events/lttng-module/arch/x86/kvm
271 #undef TRACE_INCLUDE_FILE
272 #define TRACE_INCLUDE_FILE mmutrace
274 /* This part must be outside protection */
275 #include <probes/define_trace.h>