Commit | Line | Data |
---|---|---|
b7cdc182 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
9bbf98da MD |
2 | #if !defined(LTTNG_TRACE_KVM_MMU_H) || defined(TRACE_HEADER_MULTI_READ) |
3 | #define LTTNG_TRACE_KVM_MMU_H | |
b3c40230 | 4 | |
3b4aafcb | 5 | #include <lttng/tracepoint-event.h> |
5f4c791e | 6 | #include <lttng/kernel-version.h> |
b3c40230 | 7 | |
55d9985e | 8 | #include <linux/trace_events.h> |
55d9985e | 9 | |
b3c40230 | 10 | #undef TRACE_SYSTEM |
9bbf98da | 11 | #define TRACE_SYSTEM kvm_mmu |
b3c40230 | 12 | |
5f4c791e | 13 | #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,1,0) || \ |
b2e8ba42 | 14 | LTTNG_RHEL_KERNEL_RANGE(4,18,0,147,0,0, 4,19,0,0,0,0)) |
8a88382f MJ |
15 | |
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) | |
21 | ||
35893182 | 22 | #else |
05b915ce | 23 | |
f127e61e | 24 | #define LTTNG_KVM_MMU_PAGE_FIELDS \ |
05b915ce | 25 | ctf_integer(unsigned long, mmu_valid_gen, (sp)->mmu_valid_gen) \ |
f127e61e MD |
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) | |
b3c40230 | 30 | |
35893182 | 31 | #endif |
05b915ce | 32 | |
b3c40230 MG |
33 | /* |
34 | * A pagetable walk has started | |
35 | */ | |
3bc29f0a | 36 | LTTNG_TRACEPOINT_EVENT( |
b3c40230 MG |
37 | kvm_mmu_pagetable_walk, |
38 | TP_PROTO(u64 addr, u32 pferr), | |
39 | TP_ARGS(addr, pferr), | |
40 | ||
f127e61e | 41 | TP_FIELDS( |
2c054599 | 42 | ctf_integer_hex(__u64, addr, addr) |
f127e61e MD |
43 | ctf_integer(__u32, pferr, pferr) |
44 | ) | |
b3c40230 | 45 | ) |
b3c40230 MG |
46 | |
47 | /* We just walked a paging element */ | |
3bc29f0a | 48 | LTTNG_TRACEPOINT_EVENT( |
b3c40230 MG |
49 | kvm_mmu_paging_element, |
50 | TP_PROTO(u64 pte, int level), | |
51 | TP_ARGS(pte, level), | |
52 | ||
f127e61e MD |
53 | TP_FIELDS( |
54 | ctf_integer(__u64, pte, pte) | |
55 | ctf_integer(__u32, level, level) | |
56 | ) | |
b3c40230 MG |
57 | ) |
58 | ||
3bc29f0a | 59 | LTTNG_TRACEPOINT_EVENT_CLASS(kvm_mmu_set_bit_class, |
b3c40230 MG |
60 | |
61 | TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size), | |
62 | ||
63 | TP_ARGS(table_gfn, index, size), | |
64 | ||
f127e61e MD |
65 | TP_FIELDS( |
66 | ctf_integer(__u64, gpa, | |
67 | ((u64)table_gfn << PAGE_SHIFT) + index * size) | |
68 | ) | |
b3c40230 MG |
69 | ) |
70 | ||
71 | /* We set a pte accessed bit */ | |
3bc29f0a | 72 | LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_set_bit_class, kvm_mmu_set_accessed_bit, |
b3c40230 MG |
73 | |
74 | TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size), | |
75 | ||
76 | TP_ARGS(table_gfn, index, size) | |
77 | ) | |
78 | ||
79 | /* We set a pte dirty bit */ | |
3bc29f0a | 80 | LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_set_bit_class, kvm_mmu_set_dirty_bit, |
b3c40230 MG |
81 | |
82 | TP_PROTO(unsigned long table_gfn, unsigned index, unsigned size), | |
83 | ||
84 | TP_ARGS(table_gfn, index, size) | |
85 | ) | |
86 | ||
3bc29f0a | 87 | LTTNG_TRACEPOINT_EVENT( |
b3c40230 MG |
88 | kvm_mmu_walker_error, |
89 | TP_PROTO(u32 pferr), | |
90 | TP_ARGS(pferr), | |
91 | ||
f127e61e MD |
92 | TP_FIELDS( |
93 | ctf_integer(__u32, pferr, pferr) | |
94 | ) | |
b3c40230 MG |
95 | ) |
96 | ||
3bc29f0a | 97 | LTTNG_TRACEPOINT_EVENT( |
b3c40230 MG |
98 | kvm_mmu_get_page, |
99 | TP_PROTO(struct kvm_mmu_page *sp, bool created), | |
100 | TP_ARGS(sp, created), | |
101 | ||
f127e61e MD |
102 | TP_FIELDS( |
103 | LTTNG_KVM_MMU_PAGE_FIELDS | |
104 | ctf_integer(bool, created, created) | |
105 | ) | |
b3c40230 MG |
106 | ) |
107 | ||
3bc29f0a | 108 | LTTNG_TRACEPOINT_EVENT_CLASS(kvm_mmu_page_class, |
b3c40230 MG |
109 | |
110 | TP_PROTO(struct kvm_mmu_page *sp), | |
111 | TP_ARGS(sp), | |
112 | ||
f127e61e MD |
113 | TP_FIELDS( |
114 | LTTNG_KVM_MMU_PAGE_FIELDS | |
115 | ) | |
b3c40230 MG |
116 | ) |
117 | ||
3bc29f0a | 118 | LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class, kvm_mmu_sync_page, |
b3c40230 MG |
119 | TP_PROTO(struct kvm_mmu_page *sp), |
120 | ||
121 | TP_ARGS(sp) | |
122 | ) | |
123 | ||
3bc29f0a | 124 | LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class, kvm_mmu_unsync_page, |
b3c40230 MG |
125 | TP_PROTO(struct kvm_mmu_page *sp), |
126 | ||
127 | TP_ARGS(sp) | |
128 | ) | |
129 | ||
3bc29f0a | 130 | LTTNG_TRACEPOINT_EVENT_INSTANCE(kvm_mmu_page_class, kvm_mmu_prepare_zap_page, |
b3c40230 MG |
131 | TP_PROTO(struct kvm_mmu_page *sp), |
132 | ||
133 | TP_ARGS(sp) | |
134 | ) | |
135 | ||
5f4c791e | 136 | #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,10,0)) |
6e139dda MJ |
137 | |
138 | LTTNG_TRACEPOINT_EVENT_MAP( | |
139 | mark_mmio_spte, | |
140 | ||
141 | kvm_mmu_mark_mmio_spte, | |
142 | ||
143 | TP_PROTO(u64 *sptep, gfn_t gfn, u64 spte), | |
144 | TP_ARGS(sptep, gfn, spte), | |
145 | ||
146 | TP_FIELDS( | |
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)) | |
151 | ) | |
152 | ) | |
153 | ||
35893182 | 154 | #else |
d3a7bdc5 MD |
155 | |
156 | LTTNG_TRACEPOINT_EVENT_MAP( | |
157 | mark_mmio_spte, | |
158 | ||
159 | kvm_mmu_mark_mmio_spte, | |
160 | ||
161 | TP_PROTO(u64 *sptep, gfn_t gfn, unsigned access, unsigned int gen), | |
162 | TP_ARGS(sptep, gfn, access, gen), | |
163 | ||
164 | TP_FIELDS( | |
fa91fcac | 165 | ctf_integer_hex(void *, sptep, sptep) |
d3a7bdc5 MD |
166 | ctf_integer(gfn_t, gfn, gfn) |
167 | ctf_integer(unsigned, access, access) | |
168 | ctf_integer(unsigned int, gen, gen) | |
169 | ) | |
170 | ) | |
35893182 | 171 | #endif |
d3a7bdc5 | 172 | |
9bbf98da | 173 | LTTNG_TRACEPOINT_EVENT_MAP( |
b3c40230 | 174 | handle_mmio_page_fault, |
9bbf98da MD |
175 | |
176 | kvm_mmu_handle_mmio_page_fault, | |
177 | ||
b3c40230 MG |
178 | TP_PROTO(u64 addr, gfn_t gfn, unsigned access), |
179 | TP_ARGS(addr, gfn, access), | |
180 | ||
f127e61e | 181 | TP_FIELDS( |
2c054599 | 182 | ctf_integer_hex(u64, addr, addr) |
f127e61e MD |
183 | ctf_integer(gfn_t, gfn, gfn) |
184 | ctf_integer(unsigned, access, access) | |
185 | ) | |
b3c40230 MG |
186 | ) |
187 | ||
f4c179bc MJ |
188 | #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,16,0)) |
189 | LTTNG_TRACEPOINT_EVENT_MAP( | |
190 | fast_page_fault, | |
191 | ||
192 | kvm_mmu_fast_page_fault, | |
193 | ||
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), | |
197 | ||
198 | TP_FIELDS( | |
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) | |
206 | ) | |
207 | ) | |
208 | #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,10,0)) | |
5e331750 MJ |
209 | LTTNG_TRACEPOINT_EVENT_MAP( |
210 | fast_page_fault, | |
211 | ||
212 | kvm_mmu_fast_page_fault, | |
213 | ||
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), | |
217 | ||
218 | TP_FIELDS( | |
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) | |
226 | ) | |
227 | ) | |
5f4c791e | 228 | #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,6,0) || \ |
c5db2e0a MJ |
229 | LTTNG_KERNEL_RANGE(4,19,103, 4,20,0) || \ |
230 | LTTNG_KERNEL_RANGE(5,4,19, 5,5,0) || \ | |
9b364f49 | 231 | LTTNG_KERNEL_RANGE(5,5,3, 5,6,0) || \ |
66d91dec | 232 | LTTNG_UBUNTU_KERNEL_RANGE(4,15,18,92, 4,16,0,0) || \ |
7c9ce673 | 233 | LTTNG_UBUNTU_KERNEL_RANGE(5,0,21,44, 5,1,0,0) || \ |
0d8c4f9c MJ |
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)) | |
c5db2e0a MJ |
236 | LTTNG_TRACEPOINT_EVENT_MAP( |
237 | fast_page_fault, | |
238 | ||
239 | kvm_mmu_fast_page_fault, | |
240 | ||
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), | |
244 | ||
245 | TP_FIELDS( | |
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) | |
253 | ) | |
254 | ) | |
255 | #else | |
9bbf98da | 256 | LTTNG_TRACEPOINT_EVENT_MAP( |
b3c40230 | 257 | fast_page_fault, |
9bbf98da MD |
258 | |
259 | kvm_mmu_fast_page_fault, | |
260 | ||
b3c40230 MG |
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), | |
264 | ||
f127e61e MD |
265 | TP_FIELDS( |
266 | ctf_integer(int, vcpu_id, vcpu->vcpu_id) | |
267 | ctf_integer(gva_t, gva, gva) | |
268 | ctf_integer(u32, error_code, error_code) | |
fa91fcac | 269 | ctf_integer_hex(u64 *, sptep, sptep) |
f127e61e MD |
270 | ctf_integer(u64, old_spte, old_spte) |
271 | ctf_integer(u64, new_spte, *sptep) | |
272 | ctf_integer(bool, retry, retry) | |
b3c40230 MG |
273 | ) |
274 | ) | |
c5db2e0a MJ |
275 | #endif |
276 | ||
9bbf98da | 277 | #endif /* LTTNG_TRACE_KVM_MMU_H */ |
b3c40230 MG |
278 | |
279 | #undef TRACE_INCLUDE_PATH | |
4f47ccf0 | 280 | #define TRACE_INCLUDE_PATH instrumentation/events/arch/x86/kvm |
b3c40230 MG |
281 | #undef TRACE_INCLUDE_FILE |
282 | #define TRACE_INCLUDE_FILE mmutrace | |
283 | ||
284 | /* This part must be outside protection */ | |
3b4aafcb | 285 | #include <lttng/define_trace.h> |