Commit | Line | Data |
---|---|---|
9f36eaed | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
9bbf98da MD |
2 | #if !defined(LTTNG_TRACE_KVM_MMU_H) || defined(TRACE_HEADER_MULTI_READ) |
3 | #define LTTNG_TRACE_KVM_MMU_H | |
b3c40230 | 4 | |
6ec43db8 | 5 | #include <probes/lttng-tracepoint-event.h> |
d3a7bdc5 | 6 | #include <linux/version.h> |
b3c40230 | 7 | |
55d9985e MD |
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)) */ | |
13 | ||
b3c40230 | 14 | #undef TRACE_SYSTEM |
9bbf98da | 15 | #define TRACE_SYSTEM kvm_mmu |
b3c40230 | 16 | |
8a88382f MJ |
17 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0)) |
18 | ||
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) | |
24 | ||
25 | #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) | |
05b915ce | 26 | |
f127e61e | 27 | #define LTTNG_KVM_MMU_PAGE_FIELDS \ |
05b915ce | 28 | ctf_integer(unsigned long, mmu_valid_gen, (sp)->mmu_valid_gen) \ |
f127e61e MD |
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) | |
b3c40230 | 33 | |
05b915ce MD |
34 | #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) */ |
35 | ||
36 | #define LTTNG_KVM_MMU_PAGE_FIELDS \ | |
37 | ctf_integer(__u64, gfn, (sp)->gfn) \ | |
38 | ctf_integer(__u32, role, (sp)->role.word) \ | |
39 | ctf_integer(__u32, root_count, (sp)->root_count) \ | |
40 | ctf_integer(bool, unsync, (sp)->unsync) | |
41 | ||
42 | #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) */ | |
43 | ||
4bbec2e1 | 44 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)) |
b3c40230 MG |
45 | /* |
46 | * A pagetable walk has started | |
47 | */ | |
3bc29f0a | 48 | LTTNG_TRACEPOINT_EVENT( |
b3c40230 MG |
49 | kvm_mmu_pagetable_walk, |
50 | TP_PROTO(u64 addr, u32 pferr), | |
51 | TP_ARGS(addr, pferr), | |
52 | ||
f127e61e MD |
53 | TP_FIELDS( |
54 | ctf_integer(__u64, addr, addr) | |
55 | ctf_integer(__u32, pferr, pferr) | |
56 | ) | |
b3c40230 | 57 | ) |
4bbec2e1 MD |
58 | #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)) */ |
59 | /* | |
60 | * A pagetable walk has started | |
61 | */ | |
62 | LTTNG_TRACEPOINT_EVENT( | |
63 | kvm_mmu_pagetable_walk, | |
64 | TP_PROTO(u64 addr, int write_fault, int user_fault, int fetch_fault), | |
65 | TP_ARGS(addr, write_fault, user_fault, fetch_fault), | |
b3c40230 | 66 | |
4bbec2e1 MD |
67 | TP_FIELDS( |
68 | ctf_integer(__u64, addr, addr) | |
69 | ctf_integer(__u32, pferr, | |
70 | (!!write_fault << 1) | (!!user_fault << 2) | |
71 | | (!!fetch_fault << 4)) | |
72 | ) | |
73 | ) | |
74 | #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)) */ | |
b3c40230 MG |
75 | |
76 | /* We just walked a paging element */ | |
3bc29f0a | 77 | LTTNG_TRACEPOINT_EVENT( |
b3c40230 MG |
78 | kvm_mmu_paging_element, |
79 | TP_PROTO(u64 pte, int level), | |
80 | TP_ARGS(pte, level), | |
81 | ||
f127e61e MD |
82 | TP_FIELDS( |
83 | ctf_integer(__u64, pte, pte) | |
84 | ctf_integer(__u32, level, level) | |
85 | ) | |
b3c40230 MG |
86 | ) |
87 | ||
3bc29f0a | 88 | LTTNG_TRACEPOINT_EVENT_CLASS(kvm_mmu_set_bit_class, |
b3c40230 MG |
89 | |
90 | TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size), | |
91 | ||
92 | TP_ARGS(table_gfn, index, size), | |
93 | ||
f127e61e MD |
94 | TP_FIELDS( |
95 | ctf_integer(__u64, gpa, | |
96 | ((u64)table_gfn << PAGE_SHIFT) + index * size) | |
97 | ) | |
b3c40230 MG |
98 | ) |
99 | ||
100 | /* We set a pte accessed bit */ | |
3bc29f0a | 101 | LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_set_bit_class, kvm_mmu_set_accessed_bit, |
b3c40230 MG |
102 | |
103 | TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size), | |
104 | ||
105 | TP_ARGS(table_gfn, index, size) | |
106 | ) | |
107 | ||
108 | /* We set a pte dirty bit */ | |
3bc29f0a | 109 | LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_set_bit_class, kvm_mmu_set_dirty_bit, |
b3c40230 MG |
110 | |
111 | TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size), | |
112 | ||
113 | TP_ARGS(table_gfn, index, size) | |
114 | ) | |
115 | ||
3bc29f0a | 116 | LTTNG_TRACEPOINT_EVENT( |
b3c40230 MG |
117 | kvm_mmu_walker_error, |
118 | TP_PROTO(u32 pferr), | |
119 | TP_ARGS(pferr), | |
120 | ||
f127e61e MD |
121 | TP_FIELDS( |
122 | ctf_integer(__u32, pferr, pferr) | |
123 | ) | |
b3c40230 MG |
124 | ) |
125 | ||
3bc29f0a | 126 | LTTNG_TRACEPOINT_EVENT( |
b3c40230 MG |
127 | kvm_mmu_get_page, |
128 | TP_PROTO(struct kvm_mmu_page *sp, bool created), | |
129 | TP_ARGS(sp, created), | |
130 | ||
f127e61e MD |
131 | TP_FIELDS( |
132 | LTTNG_KVM_MMU_PAGE_FIELDS | |
133 | ctf_integer(bool, created, created) | |
134 | ) | |
b3c40230 MG |
135 | ) |
136 | ||
3bc29f0a | 137 | LTTNG_TRACEPOINT_EVENT_CLASS(kvm_mmu_page_class, |
b3c40230 MG |
138 | |
139 | TP_PROTO(struct kvm_mmu_page *sp), | |
140 | TP_ARGS(sp), | |
141 | ||
f127e61e MD |
142 | TP_FIELDS( |
143 | LTTNG_KVM_MMU_PAGE_FIELDS | |
144 | ) | |
b3c40230 MG |
145 | ) |
146 | ||
3bc29f0a | 147 | LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class, kvm_mmu_sync_page, |
b3c40230 MG |
148 | TP_PROTO(struct kvm_mmu_page *sp), |
149 | ||
150 | TP_ARGS(sp) | |
151 | ) | |
152 | ||
3bc29f0a | 153 | LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class, kvm_mmu_unsync_page, |
b3c40230 MG |
154 | TP_PROTO(struct kvm_mmu_page *sp), |
155 | ||
156 | TP_ARGS(sp) | |
157 | ) | |
158 | ||
3bc29f0a | 159 | LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class, kvm_mmu_prepare_zap_page, |
b3c40230 MG |
160 | TP_PROTO(struct kvm_mmu_page *sp), |
161 | ||
162 | TP_ARGS(sp) | |
163 | ) | |
164 | ||
d3a7bdc5 MD |
165 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) |
166 | ||
167 | LTTNG_TRACEPOINT_EVENT_MAP( | |
168 | mark_mmio_spte, | |
169 | ||
170 | kvm_mmu_mark_mmio_spte, | |
171 | ||
172 | TP_PROTO(u64 *sptep, gfn_t gfn, unsigned access, unsigned int gen), | |
173 | TP_ARGS(sptep, gfn, access, gen), | |
174 | ||
175 | TP_FIELDS( | |
fa91fcac | 176 | ctf_integer_hex(void *, sptep, sptep) |
d3a7bdc5 MD |
177 | ctf_integer(gfn_t, gfn, gfn) |
178 | ctf_integer(unsigned, access, access) | |
179 | ctf_integer(unsigned int, gen, gen) | |
180 | ) | |
181 | ) | |
182 | ||
183 | #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) */ | |
184 | ||
9bbf98da | 185 | LTTNG_TRACEPOINT_EVENT_MAP( |
b3c40230 | 186 | mark_mmio_spte, |
9bbf98da MD |
187 | |
188 | kvm_mmu_mark_mmio_spte, | |
189 | ||
b3c40230 MG |
190 | TP_PROTO(u64 *sptep, gfn_t gfn, unsigned access), |
191 | TP_ARGS(sptep, gfn, access), | |
192 | ||
f127e61e | 193 | TP_FIELDS( |
fa91fcac | 194 | ctf_integer_hex(void *, sptep, sptep) |
f127e61e MD |
195 | ctf_integer(gfn_t, gfn, gfn) |
196 | ctf_integer(unsigned, access, access) | |
197 | ) | |
b3c40230 MG |
198 | ) |
199 | ||
d3a7bdc5 MD |
200 | #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)) */ |
201 | ||
9bbf98da | 202 | LTTNG_TRACEPOINT_EVENT_MAP( |
b3c40230 | 203 | handle_mmio_page_fault, |
9bbf98da MD |
204 | |
205 | kvm_mmu_handle_mmio_page_fault, | |
206 | ||
b3c40230 MG |
207 | TP_PROTO(u64 addr, gfn_t gfn, unsigned access), |
208 | TP_ARGS(addr, gfn, access), | |
209 | ||
f127e61e MD |
210 | TP_FIELDS( |
211 | ctf_integer(u64, addr, addr) | |
212 | ctf_integer(gfn_t, gfn, gfn) | |
213 | ctf_integer(unsigned, access, access) | |
214 | ) | |
b3c40230 MG |
215 | ) |
216 | ||
adab0aca MJ |
217 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0) || \ |
218 | LTTNG_KERNEL_RANGE(4,19,103, 4,20,0) || \ | |
219 | LTTNG_KERNEL_RANGE(5,4,19, 5,5,0) || \ | |
c12bf012 | 220 | LTTNG_KERNEL_RANGE(5,5,3, 5,6,0) || \ |
47f5f96c | 221 | LTTNG_UBUNTU_KERNEL_RANGE(4,15,18,92, 4,16,0,0) || \ |
3b708973 MJ |
222 | LTTNG_UBUNTU_KERNEL_RANGE(5,3,18,43, 5,3,18,45) || \ |
223 | LTTNG_UBUNTU_KERNEL_RANGE(5,3,18,46, 5,4,0,0)) | |
adab0aca MJ |
224 | LTTNG_TRACEPOINT_EVENT_MAP( |
225 | fast_page_fault, | |
226 | ||
227 | kvm_mmu_fast_page_fault, | |
228 | ||
229 | TP_PROTO(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u32 error_code, | |
230 | u64 *sptep, u64 old_spte, bool retry), | |
231 | TP_ARGS(vcpu, cr2_or_gpa, error_code, sptep, old_spte, retry), | |
232 | ||
233 | TP_FIELDS( | |
234 | ctf_integer(int, vcpu_id, vcpu->vcpu_id) | |
235 | ctf_integer(gpa_t, cr2_or_gpa, cr2_or_gpa) | |
236 | ctf_integer(u32, error_code, error_code) | |
237 | ctf_integer_hex(u64 *, sptep, sptep) | |
238 | ctf_integer(u64, old_spte, old_spte) | |
239 | ctf_integer(u64, new_spte, *sptep) | |
240 | ctf_integer(bool, retry, retry) | |
241 | ) | |
242 | ) | |
243 | #else | |
9bbf98da | 244 | LTTNG_TRACEPOINT_EVENT_MAP( |
b3c40230 | 245 | fast_page_fault, |
9bbf98da MD |
246 | |
247 | kvm_mmu_fast_page_fault, | |
248 | ||
b3c40230 MG |
249 | TP_PROTO(struct kvm_vcpu *vcpu, gva_t gva, u32 error_code, |
250 | u64 *sptep, u64 old_spte, bool retry), | |
251 | TP_ARGS(vcpu, gva, error_code, sptep, old_spte, retry), | |
252 | ||
f127e61e MD |
253 | TP_FIELDS( |
254 | ctf_integer(int, vcpu_id, vcpu->vcpu_id) | |
255 | ctf_integer(gva_t, gva, gva) | |
256 | ctf_integer(u32, error_code, error_code) | |
fa91fcac | 257 | ctf_integer_hex(u64 *, sptep, sptep) |
f127e61e MD |
258 | ctf_integer(u64, old_spte, old_spte) |
259 | ctf_integer(u64, new_spte, *sptep) | |
260 | ctf_integer(bool, retry, retry) | |
b3c40230 MG |
261 | ) |
262 | ) | |
adab0aca MJ |
263 | #endif |
264 | ||
9bbf98da | 265 | #endif /* LTTNG_TRACE_KVM_MMU_H */ |
b3c40230 MG |
266 | |
267 | #undef TRACE_INCLUDE_PATH | |
c075712b | 268 | #define TRACE_INCLUDE_PATH instrumentation/events/lttng-module/arch/x86/kvm |
b3c40230 MG |
269 | #undef TRACE_INCLUDE_FILE |
270 | #define TRACE_INCLUDE_FILE mmutrace | |
271 | ||
272 | /* This part must be outside protection */ | |
6ec43db8 | 273 | #include <probes/define_trace.h> |