1 #if !defined(LTTNG_TRACE_KVM_MMU_H) || defined(TRACE_HEADER_MULTI_READ)
2 #define LTTNG_TRACE_KVM_MMU_H
4 #include <probes/lttng-tracepoint-event.h>
5 #include <linux/version.h>
7 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0))
8 #include <linux/trace_events.h>
9 #else /* if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)) */
10 #include <linux/ftrace_event.h>
11 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)) */
14 #define TRACE_SYSTEM kvm_mmu
16 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0))
18 #define LTTNG_KVM_MMU_PAGE_FIELDS \
19 ctf_integer(__u64, gfn, (sp)->gfn) \
20 ctf_integer(__u32, role, (sp)->role.word) \
21 ctf_integer(__u32, root_count, (sp)->root_count) \
22 ctf_integer(bool, unsync, (sp)->unsync)
24 #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0))
26 #define LTTNG_KVM_MMU_PAGE_FIELDS \
27 ctf_integer(unsigned long, mmu_valid_gen, (sp)->mmu_valid_gen) \
28 ctf_integer(__u64, gfn, (sp)->gfn) \
29 ctf_integer(__u32, role, (sp)->role.word) \
30 ctf_integer(__u32, root_count, (sp)->root_count) \
31 ctf_integer(bool, unsync, (sp)->unsync)
33 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) */
35 #define LTTNG_KVM_MMU_PAGE_FIELDS \
36 ctf_integer(__u64, gfn, (sp)->gfn) \
37 ctf_integer(__u32, role, (sp)->role.word) \
38 ctf_integer(__u32, root_count, (sp)->root_count) \
39 ctf_integer(bool, unsync, (sp)->unsync)
41 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) */
43 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
45 * A pagetable walk has started
47 LTTNG_TRACEPOINT_EVENT(
48 kvm_mmu_pagetable_walk
,
49 TP_PROTO(u64 addr
, u32 pferr
),
53 ctf_integer(__u64
, addr
, addr
)
54 ctf_integer(__u32
, pferr
, pferr
)
57 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)) */
59 * A pagetable walk has started
61 LTTNG_TRACEPOINT_EVENT(
62 kvm_mmu_pagetable_walk
,
63 TP_PROTO(u64 addr
, int write_fault
, int user_fault
, int fetch_fault
),
64 TP_ARGS(addr
, write_fault
, user_fault
, fetch_fault
),
67 ctf_integer(__u64
, addr
, addr
)
68 ctf_integer(__u32
, pferr
,
69 (!!write_fault
<< 1) | (!!user_fault
<< 2)
70 | (!!fetch_fault
<< 4))
73 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)) */
75 /* We just walked a paging element */
76 LTTNG_TRACEPOINT_EVENT(
77 kvm_mmu_paging_element
,
78 TP_PROTO(u64 pte
, int level
),
82 ctf_integer(__u64
, pte
, pte
)
83 ctf_integer(__u32
, level
, level
)
87 LTTNG_TRACEPOINT_EVENT_CLASS(kvm_mmu_set_bit_class
,
89 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
91 TP_ARGS(table_gfn
, index
, size
),
94 ctf_integer(__u64
, gpa
,
95 ((u64
)table_gfn
<< PAGE_SHIFT
) + index
* size
)
99 /* We set a pte accessed bit */
100 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_set_bit_class
, kvm_mmu_set_accessed_bit
,
102 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
104 TP_ARGS(table_gfn
, index
, size
)
107 /* We set a pte dirty bit */
108 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_set_bit_class
, kvm_mmu_set_dirty_bit
,
110 TP_PROTO(unsigned long table_gfn
, unsigned index
, unsigned size
),
112 TP_ARGS(table_gfn
, index
, size
)
115 LTTNG_TRACEPOINT_EVENT(
116 kvm_mmu_walker_error
,
121 ctf_integer(__u32
, pferr
, pferr
)
125 LTTNG_TRACEPOINT_EVENT(
127 TP_PROTO(struct kvm_mmu_page
*sp
, bool created
),
128 TP_ARGS(sp
, created
),
131 LTTNG_KVM_MMU_PAGE_FIELDS
132 ctf_integer(bool, created
, created
)
136 LTTNG_TRACEPOINT_EVENT_CLASS(kvm_mmu_page_class
,
138 TP_PROTO(struct kvm_mmu_page
*sp
),
142 LTTNG_KVM_MMU_PAGE_FIELDS
146 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class
, kvm_mmu_sync_page
,
147 TP_PROTO(struct kvm_mmu_page
*sp
),
152 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class
, kvm_mmu_unsync_page
,
153 TP_PROTO(struct kvm_mmu_page
*sp
),
158 LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class
, kvm_mmu_prepare_zap_page
,
159 TP_PROTO(struct kvm_mmu_page
*sp
),
164 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0))
166 LTTNG_TRACEPOINT_EVENT_MAP(
169 kvm_mmu_mark_mmio_spte
,
171 TP_PROTO(u64
*sptep
, gfn_t gfn
, unsigned access
, unsigned int gen
),
172 TP_ARGS(sptep
, gfn
, access
, gen
),
175 ctf_integer_hex(void *, sptep
, sptep
)
176 ctf_integer(gfn_t
, gfn
, gfn
)
177 ctf_integer(unsigned, access
, access
)
178 ctf_integer(unsigned int, gen
, gen
)
182 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) */
184 LTTNG_TRACEPOINT_EVENT_MAP(
187 kvm_mmu_mark_mmio_spte
,
189 TP_PROTO(u64
*sptep
, gfn_t gfn
, unsigned access
),
190 TP_ARGS(sptep
, gfn
, access
),
193 ctf_integer_hex(void *, sptep
, sptep
)
194 ctf_integer(gfn_t
, gfn
, gfn
)
195 ctf_integer(unsigned, access
, access
)
199 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) */
201 LTTNG_TRACEPOINT_EVENT_MAP(
202 handle_mmio_page_fault
,
204 kvm_mmu_handle_mmio_page_fault
,
206 TP_PROTO(u64 addr
, gfn_t gfn
, unsigned access
),
207 TP_ARGS(addr
, gfn
, access
),
210 ctf_integer(u64
, addr
, addr
)
211 ctf_integer(gfn_t
, gfn
, gfn
)
212 ctf_integer(unsigned, access
, access
)
216 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0) || \
217 LTTNG_KERNEL_RANGE(4,19,103, 4,20,0) || \
218 LTTNG_KERNEL_RANGE(5,4,19, 5,5,0) || \
219 LTTNG_KERNEL_RANGE(5,5,3, 5,6,0) || \
220 LTTNG_UBUNTU_KERNEL_RANGE(4,15,18,92, 4,16,0,0) || \
221 LTTNG_UBUNTU_KERNEL_RANGE(5,3,18,43, 5,3,18,45) || \
222 LTTNG_UBUNTU_KERNEL_RANGE(5,3,18,46, 5,4,0,0))
223 LTTNG_TRACEPOINT_EVENT_MAP(
226 kvm_mmu_fast_page_fault
,
228 TP_PROTO(struct kvm_vcpu
*vcpu
, gpa_t cr2_or_gpa
, u32 error_code
,
229 u64
*sptep
, u64 old_spte
, bool retry
),
230 TP_ARGS(vcpu
, cr2_or_gpa
, error_code
, sptep
, old_spte
, retry
),
233 ctf_integer(int, vcpu_id
, vcpu
->vcpu_id
)
234 ctf_integer(gpa_t
, cr2_or_gpa
, cr2_or_gpa
)
235 ctf_integer(u32
, error_code
, error_code
)
236 ctf_integer_hex(u64
*, sptep
, sptep
)
237 ctf_integer(u64
, old_spte
, old_spte
)
238 ctf_integer(u64
, new_spte
, *sptep
)
239 ctf_integer(bool, retry
, retry
)
243 LTTNG_TRACEPOINT_EVENT_MAP(
246 kvm_mmu_fast_page_fault
,
248 TP_PROTO(struct kvm_vcpu
*vcpu
, gva_t gva
, u32 error_code
,
249 u64
*sptep
, u64 old_spte
, bool retry
),
250 TP_ARGS(vcpu
, gva
, error_code
, sptep
, old_spte
, retry
),
253 ctf_integer(int, vcpu_id
, vcpu
->vcpu_id
)
254 ctf_integer(gva_t
, gva
, gva
)
255 ctf_integer(u32
, error_code
, error_code
)
256 ctf_integer_hex(u64
*, sptep
, sptep
)
257 ctf_integer(u64
, old_spte
, old_spte
)
258 ctf_integer(u64
, new_spte
, *sptep
)
259 ctf_integer(bool, retry
, retry
)
264 #endif /* LTTNG_TRACE_KVM_MMU_H */
266 #undef TRACE_INCLUDE_PATH
267 #define TRACE_INCLUDE_PATH instrumentation/events/lttng-module/arch/x86/kvm
268 #undef TRACE_INCLUDE_FILE
269 #define TRACE_INCLUDE_FILE mmutrace
271 /* This part must be outside protection */
272 #include <probes/define_trace.h>