| 1 | // SPDX-FileCopyrightText: 2013 Mohamad Gebai <mohamad.gebai@polymtl.ca> |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-2.0-only |
| 4 | |
| 5 | #if !defined(LTTNG_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ) |
| 6 | #define LTTNG_TRACE_KVM_H |
| 7 | |
| 8 | #include <lttng/tracepoint-event.h> |
| 9 | #include <asm/vmx.h> |
| 10 | #include <asm/svm.h> |
| 11 | #include <asm/clocksource.h> |
| 12 | #include <lttng/kernel-version.h> |
| 13 | #include <wrapper/kvm-x86.h> |
| 14 | #include <../arch/x86/kvm/lapic.h> |
| 15 | #include <../arch/x86/kvm/kvm_cache_regs.h> |
| 16 | |
| 17 | #undef TRACE_SYSTEM |
| 18 | #define TRACE_SYSTEM kvm_x86 |
| 19 | |
| 20 | /* |
| 21 | * Tracepoint for guest mode entry. |
| 22 | */ |
| 23 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_entry, kvm_x86_entry, |
| 24 | TP_PROTO(unsigned int vcpu_id), |
| 25 | TP_ARGS(vcpu_id), |
| 26 | |
| 27 | TP_FIELDS( |
| 28 | ctf_integer(unsigned int, vcpu_id, vcpu_id) |
| 29 | ) |
| 30 | ) |
| 31 | |
| 32 | /* |
| 33 | * Tracepoint for hypercall. |
| 34 | */ |
| 35 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_hypercall, kvm_x86_hypercall, |
| 36 | TP_PROTO(unsigned long nr, unsigned long a0, unsigned long a1, |
| 37 | unsigned long a2, unsigned long a3), |
| 38 | TP_ARGS(nr, a0, a1, a2, a3), |
| 39 | |
| 40 | TP_FIELDS( |
| 41 | ctf_integer(unsigned long, nr, nr) |
| 42 | ctf_integer(unsigned long, a0, a0) |
| 43 | ctf_integer(unsigned long, a1, a1) |
| 44 | ctf_integer(unsigned long, a2, a2) |
| 45 | ctf_integer(unsigned long, a3, a3) |
| 46 | ) |
| 47 | ) |
| 48 | |
| 49 | /* |
| 50 | * Tracepoint for hypercall. |
| 51 | */ |
| 52 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_hv_hypercall, kvm_x86_hv_hypercall, |
| 53 | TP_PROTO(__u16 code, bool fast, __u16 rep_cnt, __u16 rep_idx, |
| 54 | __u64 ingpa, __u64 outgpa), |
| 55 | TP_ARGS(code, fast, rep_cnt, rep_idx, ingpa, outgpa), |
| 56 | |
| 57 | TP_FIELDS( |
| 58 | ctf_integer(__u16, rep_cnt, rep_cnt) |
| 59 | ctf_integer(__u16, rep_idx, rep_idx) |
| 60 | ctf_integer(__u64, ingpa, ingpa) |
| 61 | ctf_integer(__u64, outgpa, outgpa) |
| 62 | ctf_integer(__u16, code, code) |
| 63 | ctf_integer(bool, fast, fast) |
| 64 | ) |
| 65 | ) |
| 66 | |
| 67 | /* |
| 68 | * Tracepoint for PIO. |
| 69 | */ |
| 70 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_pio, kvm_x86_pio, |
| 71 | TP_PROTO(unsigned int rw, unsigned int port, unsigned int size, |
| 72 | unsigned int count), |
| 73 | TP_ARGS(rw, port, size, count), |
| 74 | |
| 75 | TP_FIELDS( |
| 76 | ctf_integer(unsigned int, rw, rw) |
| 77 | ctf_integer(unsigned int, port, port) |
| 78 | ctf_integer(unsigned int, size, size) |
| 79 | ctf_integer(unsigned int, count, count) |
| 80 | ) |
| 81 | ) |
| 82 | |
| 83 | /* |
| 84 | * Tracepoint for cpuid. |
| 85 | */ |
| 86 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_cpuid, kvm_x86_cpuid, |
| 87 | TP_PROTO(unsigned int function, unsigned long rax, unsigned long rbx, |
| 88 | unsigned long rcx, unsigned long rdx), |
| 89 | TP_ARGS(function, rax, rbx, rcx, rdx), |
| 90 | |
| 91 | TP_FIELDS( |
| 92 | ctf_integer(unsigned int, function, function) |
| 93 | ctf_integer(unsigned long, rax, rax) |
| 94 | ctf_integer(unsigned long, rbx, rbx) |
| 95 | ctf_integer(unsigned long, rcx, rcx) |
| 96 | ctf_integer(unsigned long, rdx, rdx) |
| 97 | ) |
| 98 | ) |
| 99 | |
| 100 | /* |
| 101 | * Tracepoint for apic access. |
| 102 | */ |
| 103 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_apic, kvm_x86_apic, |
| 104 | TP_PROTO(unsigned int rw, unsigned int reg, unsigned int val), |
| 105 | TP_ARGS(rw, reg, val), |
| 106 | |
| 107 | TP_FIELDS( |
| 108 | ctf_integer(unsigned int, rw, rw) |
| 109 | ctf_integer(unsigned int, reg, reg) |
| 110 | ctf_integer(unsigned int, val, val) |
| 111 | ) |
| 112 | ) |
| 113 | |
| 114 | #define trace_kvm_apic_read(reg, val) trace_kvm_apic(0, reg, val) |
| 115 | #define trace_kvm_apic_write(reg, val) trace_kvm_apic(1, reg, val) |
| 116 | |
| 117 | /* |
| 118 | * Tracepoint for kvm guest exit: |
| 119 | */ |
| 120 | #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,18,0)) |
| 121 | LTTNG_TRACEPOINT_EVENT_CODE_MAP(kvm_exit, kvm_x86_exit, |
| 122 | TP_PROTO(struct kvm_vcpu *vcpu, u32 isa), |
| 123 | TP_ARGS(vcpu, isa), |
| 124 | |
| 125 | TP_locvar( |
| 126 | u32 exit_reason; |
| 127 | u64 info1, info2; |
| 128 | u32 intr_info, error_code; |
| 129 | ), |
| 130 | |
| 131 | TP_code_pre( |
| 132 | lttng_kvm_x86_get_exit_info(vcpu, |
| 133 | &tp_locvar->exit_reason, |
| 134 | &tp_locvar->info1, |
| 135 | &tp_locvar->info2, |
| 136 | &tp_locvar->intr_info, |
| 137 | &tp_locvar->error_code); |
| 138 | ), |
| 139 | |
| 140 | TP_FIELDS( |
| 141 | ctf_integer(unsigned int, exit_reason, tp_locvar->exit_reason) |
| 142 | ctf_integer(unsigned long, guest_rip, kvm_rip_read(vcpu)) |
| 143 | ctf_integer(u32, isa, isa) |
| 144 | ctf_integer(u64, info1, tp_locvar->info1) |
| 145 | ctf_integer(u64, info2, tp_locvar->info2) |
| 146 | ctf_integer(u32, intr_info, tp_locvar->intr_info) |
| 147 | ctf_integer(u32, error_code, tp_locvar->error_code) |
| 148 | ctf_integer(unsigned int, vcpu_id, vcpu->vcpu_id) |
| 149 | ), |
| 150 | |
| 151 | TP_code_post() |
| 152 | ) |
| 153 | #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,16,0)) |
| 154 | LTTNG_TRACEPOINT_EVENT_CODE_MAP(kvm_exit, kvm_x86_exit, |
| 155 | TP_PROTO(struct kvm_vcpu *vcpu, u32 isa), |
| 156 | TP_ARGS(vcpu, isa), |
| 157 | |
| 158 | TP_locvar( |
| 159 | u32 reason; |
| 160 | u64 info1, info2; |
| 161 | u32 intr_info, error_code; |
| 162 | ), |
| 163 | |
| 164 | TP_code_pre( |
| 165 | kvm_x86_ops.get_exit_info(vcpu, &tp_locvar->reason, |
| 166 | &tp_locvar->info1, |
| 167 | &tp_locvar->info2, |
| 168 | &tp_locvar->intr_info, |
| 169 | &tp_locvar->error_code); |
| 170 | ), |
| 171 | |
| 172 | TP_FIELDS( |
| 173 | ctf_integer(u32, exit_reason, tp_locvar->reason) |
| 174 | ctf_integer(unsigned long, guest_rip, kvm_rip_read(vcpu)) |
| 175 | ctf_integer(u32, isa, isa) |
| 176 | ctf_integer(u64, info1, tp_locvar->info1) |
| 177 | ctf_integer(u64, info2, tp_locvar->info2) |
| 178 | ctf_integer(u32, intr_info, tp_locvar->intr_info) |
| 179 | ctf_integer(u32, error_code, tp_locvar->error_code) |
| 180 | ctf_integer(unsigned int, vcpu_id, vcpu->vcpu_id) |
| 181 | ), |
| 182 | |
| 183 | TP_code_post() |
| 184 | ) |
| 185 | #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,10,0) || \ |
| 186 | LTTNG_RHEL_KERNEL_RANGE(4,18,0,240,0,0, 4,19,0,0,0,0)) |
| 187 | LTTNG_TRACEPOINT_EVENT_CODE_MAP(kvm_exit, kvm_x86_exit, |
| 188 | TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa), |
| 189 | TP_ARGS(exit_reason, vcpu, isa), |
| 190 | |
| 191 | TP_locvar( |
| 192 | u64 info1, info2; |
| 193 | u32 intr_info, error_code; |
| 194 | ), |
| 195 | |
| 196 | TP_code_pre( |
| 197 | kvm_x86_ops.get_exit_info(vcpu, &tp_locvar->info1, |
| 198 | &tp_locvar->info2, |
| 199 | &tp_locvar->intr_info, |
| 200 | &tp_locvar->error_code); |
| 201 | ), |
| 202 | |
| 203 | TP_FIELDS( |
| 204 | ctf_integer(unsigned int, exit_reason, exit_reason) |
| 205 | ctf_integer(unsigned long, guest_rip, kvm_rip_read(vcpu)) |
| 206 | ctf_integer(u32, isa, isa) |
| 207 | ctf_integer(u64, info1, tp_locvar->info1) |
| 208 | ctf_integer(u64, info2, tp_locvar->info2) |
| 209 | ctf_integer(u32, intr_info, tp_locvar->intr_info) |
| 210 | ctf_integer(u32, error_code, tp_locvar->error_code) |
| 211 | ctf_integer(unsigned int, vcpu_id, vcpu->vcpu_id) |
| 212 | ), |
| 213 | |
| 214 | TP_code_post() |
| 215 | ) |
| 216 | #elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,7,0)) |
| 217 | LTTNG_TRACEPOINT_EVENT_CODE_MAP(kvm_exit, kvm_x86_exit, |
| 218 | TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa), |
| 219 | TP_ARGS(exit_reason, vcpu, isa), |
| 220 | |
| 221 | TP_locvar( |
| 222 | u64 info1, info2; |
| 223 | ), |
| 224 | |
| 225 | TP_code_pre( |
| 226 | kvm_x86_ops.get_exit_info(vcpu, &tp_locvar->info1, |
| 227 | &tp_locvar->info2); |
| 228 | ), |
| 229 | |
| 230 | TP_FIELDS( |
| 231 | ctf_integer(unsigned int, exit_reason, exit_reason) |
| 232 | ctf_integer(unsigned long, guest_rip, kvm_rip_read(vcpu)) |
| 233 | ctf_integer(u32, isa, isa) |
| 234 | ctf_integer(u64, info1, tp_locvar->info1) |
| 235 | ctf_integer(u64, info2, tp_locvar->info2) |
| 236 | ), |
| 237 | |
| 238 | TP_code_post() |
| 239 | ) |
| 240 | #else |
| 241 | LTTNG_TRACEPOINT_EVENT_CODE_MAP(kvm_exit, kvm_x86_exit, |
| 242 | TP_PROTO(unsigned int exit_reason, struct kvm_vcpu *vcpu, u32 isa), |
| 243 | TP_ARGS(exit_reason, vcpu, isa), |
| 244 | |
| 245 | TP_locvar( |
| 246 | u64 info1, info2; |
| 247 | ), |
| 248 | |
| 249 | TP_code_pre( |
| 250 | kvm_x86_ops->get_exit_info(vcpu, &tp_locvar->info1, |
| 251 | &tp_locvar->info2); |
| 252 | ), |
| 253 | |
| 254 | TP_FIELDS( |
| 255 | ctf_integer(unsigned int, exit_reason, exit_reason) |
| 256 | ctf_integer(unsigned long, guest_rip, kvm_rip_read(vcpu)) |
| 257 | ctf_integer(u32, isa, isa) |
| 258 | ctf_integer(u64, info1, tp_locvar->info1) |
| 259 | ctf_integer(u64, info2, tp_locvar->info2) |
| 260 | ), |
| 261 | |
| 262 | TP_code_post() |
| 263 | ) |
| 264 | #endif |
| 265 | |
| 266 | /* |
| 267 | * Tracepoint for kvm interrupt injection: |
| 268 | */ |
| 269 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_inj_virq, kvm_x86_inj_virq, |
| 270 | TP_PROTO(unsigned int irq), |
| 271 | TP_ARGS(irq), |
| 272 | |
| 273 | TP_FIELDS( |
| 274 | ctf_integer(unsigned int, irq, irq) |
| 275 | ) |
| 276 | ) |
| 277 | |
| 278 | /* |
| 279 | * Tracepoint for kvm interrupt injection: |
| 280 | */ |
| 281 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_inj_exception, kvm_x86_inj_exception, |
| 282 | TP_PROTO(unsigned exception, bool has_error, unsigned error_code), |
| 283 | TP_ARGS(exception, has_error, error_code), |
| 284 | |
| 285 | TP_FIELDS( |
| 286 | ctf_integer(u8, exception, exception) |
| 287 | ctf_integer(u8, has_error, has_error) |
| 288 | ctf_integer(u32, error_code, error_code) |
| 289 | ) |
| 290 | ) |
| 291 | |
| 292 | /* |
| 293 | * Tracepoint for page fault. |
| 294 | */ |
| 295 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_page_fault, kvm_x86_page_fault, |
| 296 | TP_PROTO(unsigned long fault_address, unsigned int error_code), |
| 297 | TP_ARGS(fault_address, error_code), |
| 298 | |
| 299 | TP_FIELDS( |
| 300 | ctf_integer_hex(unsigned long, fault_address, fault_address) |
| 301 | ctf_integer(unsigned int, error_code, error_code) |
| 302 | ) |
| 303 | ) |
| 304 | |
| 305 | /* |
| 306 | * Tracepoint for guest MSR access. |
| 307 | */ |
| 308 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_msr, kvm_x86_msr, |
| 309 | TP_PROTO(unsigned write, u32 ecx, u64 data, bool exception), |
| 310 | TP_ARGS(write, ecx, data, exception), |
| 311 | |
| 312 | TP_FIELDS( |
| 313 | ctf_integer(unsigned, write, write) |
| 314 | ctf_integer(u32, ecx, ecx) |
| 315 | ctf_integer(u64, data, data) |
| 316 | ctf_integer(u8, exception, exception) |
| 317 | ) |
| 318 | ) |
| 319 | |
| 320 | #define trace_kvm_msr_read(ecx, data) trace_kvm_msr(0, ecx, data, false) |
| 321 | #define trace_kvm_msr_write(ecx, data) trace_kvm_msr(1, ecx, data, false) |
| 322 | #define trace_kvm_msr_read_ex(ecx) trace_kvm_msr(0, ecx, 0, true) |
| 323 | #define trace_kvm_msr_write_ex(ecx, data) trace_kvm_msr(1, ecx, data, true) |
| 324 | |
| 325 | /* |
| 326 | * Tracepoint for guest CR access. |
| 327 | */ |
| 328 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_cr, kvm_x86_cr, |
| 329 | TP_PROTO(unsigned int rw, unsigned int cr, unsigned long val), |
| 330 | TP_ARGS(rw, cr, val), |
| 331 | |
| 332 | TP_FIELDS( |
| 333 | ctf_integer(unsigned int, rw, rw) |
| 334 | ctf_integer(unsigned int, cr, cr) |
| 335 | ctf_integer(unsigned long, val, val) |
| 336 | ) |
| 337 | ) |
| 338 | |
| 339 | #define trace_kvm_cr_read(cr, val) trace_kvm_cr(0, cr, val) |
| 340 | #define trace_kvm_cr_write(cr, val) trace_kvm_cr(1, cr, val) |
| 341 | |
| 342 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_pic_set_irq, kvm_x86_pic_set_irq, |
| 343 | TP_PROTO(__u8 chip, __u8 pin, __u8 elcr, __u8 imr, bool coalesced), |
| 344 | TP_ARGS(chip, pin, elcr, imr, coalesced), |
| 345 | |
| 346 | TP_FIELDS( |
| 347 | ctf_integer(__u8, chip, chip) |
| 348 | ctf_integer(__u8, pin, pin) |
| 349 | ctf_integer(__u8, elcr, elcr) |
| 350 | ctf_integer(__u8, imr, imr) |
| 351 | ctf_integer(bool, coalesced, coalesced) |
| 352 | ) |
| 353 | ) |
| 354 | |
| 355 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_apic_ipi, kvm_x86_apic_ipi, |
| 356 | TP_PROTO(__u32 icr_low, __u32 dest_id), |
| 357 | TP_ARGS(icr_low, dest_id), |
| 358 | |
| 359 | TP_FIELDS( |
| 360 | ctf_integer(__u32, icr_low, icr_low) |
| 361 | ctf_integer(__u32, dest_id, dest_id) |
| 362 | ) |
| 363 | ) |
| 364 | |
| 365 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_apic_accept_irq, kvm_x86_apic_accept_irq, |
| 366 | TP_PROTO(__u32 apicid, __u16 dm, __u8 tm, __u8 vec, bool coalesced), |
| 367 | TP_ARGS(apicid, dm, tm, vec, coalesced), |
| 368 | |
| 369 | TP_FIELDS( |
| 370 | ctf_integer(__u32, apicid, apicid) |
| 371 | ctf_integer(__u16, dm, dm) |
| 372 | ctf_integer(__u8, tm, tm) |
| 373 | ctf_integer(__u8, vec, vec) |
| 374 | ctf_integer(bool, coalesced, coalesced) |
| 375 | ) |
| 376 | ) |
| 377 | |
| 378 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_eoi, kvm_x86_eoi, |
| 379 | TP_PROTO(struct kvm_lapic *apic, int vector), |
| 380 | TP_ARGS(apic, vector), |
| 381 | |
| 382 | TP_FIELDS( |
| 383 | ctf_integer(__u32, apicid, apic->vcpu->vcpu_id) |
| 384 | ctf_integer(int, vector, vector) |
| 385 | ) |
| 386 | ) |
| 387 | |
| 388 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_pv_eoi, kvm_x86_pv_eoi, |
| 389 | TP_PROTO(struct kvm_lapic *apic, int vector), |
| 390 | TP_ARGS(apic, vector), |
| 391 | |
| 392 | TP_FIELDS( |
| 393 | ctf_integer(__u32, apicid, apic->vcpu->vcpu_id) |
| 394 | ctf_integer(int, vector, vector) |
| 395 | ) |
| 396 | ) |
| 397 | |
| 398 | /* |
| 399 | * Tracepoint for nested VMRUN |
| 400 | */ |
| 401 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_vmrun, kvm_x86_nested_vmrun, |
| 402 | TP_PROTO(__u64 rip, __u64 vmcb, __u64 nested_rip, __u32 int_ctl, |
| 403 | __u32 event_inj, bool npt), |
| 404 | TP_ARGS(rip, vmcb, nested_rip, int_ctl, event_inj, npt), |
| 405 | |
| 406 | TP_FIELDS( |
| 407 | ctf_integer(__u64, rip, rip) |
| 408 | ctf_integer(__u64, vmcb, vmcb) |
| 409 | ctf_integer(__u64, nested_rip, nested_rip) |
| 410 | ctf_integer(__u32, int_ctl, int_ctl) |
| 411 | ctf_integer(__u32, event_inj, event_inj) |
| 412 | ctf_integer(bool, npt, npt) |
| 413 | ) |
| 414 | ) |
| 415 | |
| 416 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_intercepts, kvm_x86_nested_intercepts, |
| 417 | TP_PROTO(__u16 cr_read, __u16 cr_write, __u32 exceptions, __u64 intercept), |
| 418 | TP_ARGS(cr_read, cr_write, exceptions, intercept), |
| 419 | |
| 420 | TP_FIELDS( |
| 421 | ctf_integer(__u16, cr_read, cr_read) |
| 422 | ctf_integer(__u16, cr_write, cr_write) |
| 423 | ctf_integer(__u32, exceptions, exceptions) |
| 424 | ctf_integer(__u64, intercept, intercept) |
| 425 | ) |
| 426 | ) |
| 427 | /* |
| 428 | * Tracepoint for #VMEXIT while nested |
| 429 | */ |
| 430 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_vmexit, kvm_x86_nested_vmexit, |
| 431 | TP_PROTO(__u64 rip, __u32 exit_code, |
| 432 | __u64 exit_info1, __u64 exit_info2, |
| 433 | __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa), |
| 434 | TP_ARGS(rip, exit_code, exit_info1, exit_info2, |
| 435 | exit_int_info, exit_int_info_err, isa), |
| 436 | |
| 437 | TP_FIELDS( |
| 438 | ctf_integer(__u64, rip, rip) |
| 439 | ctf_integer(__u32, exit_code, exit_code) |
| 440 | ctf_integer(__u64, exit_info1, exit_info1) |
| 441 | ctf_integer(__u64, exit_info2, exit_info2) |
| 442 | ctf_integer(__u32, exit_int_info, exit_int_info) |
| 443 | ctf_integer(__u32, exit_int_info_err, exit_int_info_err) |
| 444 | ctf_integer(__u32, isa, isa) |
| 445 | ) |
| 446 | ) |
| 447 | |
| 448 | /* |
| 449 | * Tracepoint for #VMEXIT reinjected to the guest |
| 450 | */ |
| 451 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_vmexit_inject, kvm_x86_nested_vmexit_inject, |
| 452 | TP_PROTO(__u32 exit_code, |
| 453 | __u64 exit_info1, __u64 exit_info2, |
| 454 | __u32 exit_int_info, __u32 exit_int_info_err, __u32 isa), |
| 455 | TP_ARGS(exit_code, exit_info1, exit_info2, |
| 456 | exit_int_info, exit_int_info_err, isa), |
| 457 | |
| 458 | TP_FIELDS( |
| 459 | ctf_integer(__u32, exit_code, exit_code) |
| 460 | ctf_integer(__u64, exit_info1, exit_info1) |
| 461 | ctf_integer(__u64, exit_info2, exit_info2) |
| 462 | ctf_integer(__u32, exit_int_info, exit_int_info) |
| 463 | ctf_integer(__u32, exit_int_info_err, exit_int_info_err) |
| 464 | ctf_integer(__u32, isa, isa) |
| 465 | ) |
| 466 | ) |
| 467 | |
| 468 | /* |
| 469 | * Tracepoint for nested #vmexit because of interrupt pending |
| 470 | */ |
| 471 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_nested_intr_vmexit, kvm_x86_nested_intr_vmexit, |
| 472 | TP_PROTO(__u64 rip), |
| 473 | TP_ARGS(rip), |
| 474 | |
| 475 | TP_FIELDS( |
| 476 | ctf_integer(__u64, rip, rip) |
| 477 | ) |
| 478 | ) |
| 479 | |
| 480 | /* |
| 481 | * Tracepoint for nested #vmexit because of interrupt pending |
| 482 | */ |
| 483 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_invlpga, kvm_x86_invlpga, |
| 484 | TP_PROTO(__u64 rip, int asid, u64 address), |
| 485 | TP_ARGS(rip, asid, address), |
| 486 | |
| 487 | TP_FIELDS( |
| 488 | ctf_integer(__u64, rip, rip) |
| 489 | ctf_integer(int, asid, asid) |
| 490 | ctf_integer_hex(__u64, address, address) |
| 491 | ) |
| 492 | ) |
| 493 | |
| 494 | /* |
| 495 | * Tracepoint for nested #vmexit because of interrupt pending |
| 496 | */ |
| 497 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_skinit, kvm_x86_skinit, |
| 498 | TP_PROTO(__u64 rip, __u32 slb), |
| 499 | TP_ARGS(rip, slb), |
| 500 | |
| 501 | TP_FIELDS( |
| 502 | ctf_integer(__u64, rip, rip) |
| 503 | ctf_integer(__u32, slb, slb) |
| 504 | ) |
| 505 | ) |
| 506 | |
| 507 | #define KVM_EMUL_INSN_F_CR0_PE (1 << 0) |
| 508 | #define KVM_EMUL_INSN_F_EFL_VM (1 << 1) |
| 509 | #define KVM_EMUL_INSN_F_CS_D (1 << 2) |
| 510 | #define KVM_EMUL_INSN_F_CS_L (1 << 3) |
| 511 | |
| 512 | #define kvm_trace_symbol_emul_flags \ |
| 513 | { 0, "real" }, \ |
| 514 | { KVM_EMUL_INSN_F_CR0_PE \ |
| 515 | | KVM_EMUL_INSN_F_EFL_VM, "vm16" }, \ |
| 516 | { KVM_EMUL_INSN_F_CR0_PE, "prot16" }, \ |
| 517 | { KVM_EMUL_INSN_F_CR0_PE \ |
| 518 | | KVM_EMUL_INSN_F_CS_D, "prot32" }, \ |
| 519 | { KVM_EMUL_INSN_F_CR0_PE \ |
| 520 | | KVM_EMUL_INSN_F_CS_L, "prot64" } |
| 521 | |
| 522 | #define kei_decode_mode(mode) ({ \ |
| 523 | u8 flags = 0xff; \ |
| 524 | switch (mode) { \ |
| 525 | case X86EMUL_MODE_REAL: \ |
| 526 | flags = 0; \ |
| 527 | break; \ |
| 528 | case X86EMUL_MODE_VM86: \ |
| 529 | flags = KVM_EMUL_INSN_F_EFL_VM; \ |
| 530 | break; \ |
| 531 | case X86EMUL_MODE_PROT16: \ |
| 532 | flags = KVM_EMUL_INSN_F_CR0_PE; \ |
| 533 | break; \ |
| 534 | case X86EMUL_MODE_PROT32: \ |
| 535 | flags = KVM_EMUL_INSN_F_CR0_PE \ |
| 536 | | KVM_EMUL_INSN_F_CS_D; \ |
| 537 | break; \ |
| 538 | case X86EMUL_MODE_PROT64: \ |
| 539 | flags = KVM_EMUL_INSN_F_CR0_PE \ |
| 540 | | KVM_EMUL_INSN_F_CS_L; \ |
| 541 | break; \ |
| 542 | } \ |
| 543 | flags; \ |
| 544 | }) |
| 545 | |
| 546 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_emulate_insn, kvm_x86_emulate_insn, |
| 547 | TP_PROTO(struct kvm_vcpu *vcpu, __u8 failed), |
| 548 | TP_ARGS(vcpu, failed), |
| 549 | |
| 550 | TP_FIELDS( |
| 551 | #if (LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(5,7,0) && \ |
| 552 | !LTTNG_RHEL_KERNEL_RANGE(4,18,0,305,0,0, 4,19,0,0,0,0)) |
| 553 | ctf_integer(__u64, rip, vcpu->arch.emulate_ctxt._eip - |
| 554 | (vcpu->arch.emulate_ctxt.fetch.ptr - |
| 555 | vcpu->arch.emulate_ctxt.fetch.data)) |
| 556 | ctf_integer(__u32, csbase, kvm_x86_ops->get_segment_base(vcpu, VCPU_SREG_CS)) |
| 557 | ctf_integer(__u8, len, vcpu->arch.emulate_ctxt.fetch.ptr - |
| 558 | vcpu->arch.emulate_ctxt.fetch.data) |
| 559 | ctf_array(__u8, insn, vcpu->arch.emulate_ctxt.fetch.data, 15) |
| 560 | ctf_integer(__u8, flags, kei_decode_mode(vcpu->arch.emulate_ctxt.mode)) |
| 561 | #elif (LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(5,18,0) || \ |
| 562 | LTTNG_RHEL_KERNEL_RANGE(4,18,0,305,0,0, 4,19,0,0,0,0)) |
| 563 | ctf_integer(__u64, rip, vcpu->arch.emulate_ctxt->_eip - |
| 564 | (vcpu->arch.emulate_ctxt->fetch.ptr - |
| 565 | vcpu->arch.emulate_ctxt->fetch.data)) |
| 566 | ctf_integer(__u32, csbase, kvm_x86_ops.get_segment_base(vcpu, VCPU_SREG_CS)) |
| 567 | ctf_integer(__u8, len, vcpu->arch.emulate_ctxt->fetch.ptr - |
| 568 | vcpu->arch.emulate_ctxt->fetch.data) |
| 569 | ctf_array(__u8, insn, vcpu->arch.emulate_ctxt->fetch.data, 15) |
| 570 | ctf_integer(__u8, flags, kei_decode_mode(vcpu->arch.emulate_ctxt->mode)) |
| 571 | #else |
| 572 | ctf_integer(__u64, rip, vcpu->arch.emulate_ctxt->_eip - |
| 573 | (vcpu->arch.emulate_ctxt->fetch.ptr - |
| 574 | vcpu->arch.emulate_ctxt->fetch.data)) |
| 575 | ctf_integer(__u32, csbase, lttng_kvm_x86_get_segment_base(vcpu, VCPU_SREG_CS)) |
| 576 | ctf_integer(__u8, len, vcpu->arch.emulate_ctxt->fetch.ptr - |
| 577 | vcpu->arch.emulate_ctxt->fetch.data) |
| 578 | ctf_array(__u8, insn, vcpu->arch.emulate_ctxt->fetch.data, 15) |
| 579 | ctf_integer(__u8, flags, kei_decode_mode(vcpu->arch.emulate_ctxt->mode)) |
| 580 | #endif |
| 581 | ctf_integer(__u8, failed, failed) |
| 582 | ) |
| 583 | ) |
| 584 | |
| 585 | #define trace_kvm_emulate_insn_start(vcpu) trace_kvm_emulate_insn(vcpu, 0) |
| 586 | #define trace_kvm_emulate_insn_failed(vcpu) trace_kvm_emulate_insn(vcpu, 1) |
| 587 | |
| 588 | LTTNG_TRACEPOINT_EVENT_MAP( |
| 589 | vcpu_match_mmio, kvm_x86_vcpu_match_mmio, |
| 590 | TP_PROTO(gva_t gva, gpa_t gpa, bool write, bool gpa_match), |
| 591 | TP_ARGS(gva, gpa, write, gpa_match), |
| 592 | |
| 593 | TP_FIELDS( |
| 594 | ctf_integer(gva_t, gva, gva) |
| 595 | ctf_integer(gpa_t, gpa, gpa) |
| 596 | ctf_integer(bool, write, write) |
| 597 | ctf_integer(bool, gpa_match, gpa_match) |
| 598 | ) |
| 599 | ) |
| 600 | |
| 601 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_write_tsc_offset, kvm_x86_write_tsc_offset, |
| 602 | TP_PROTO(unsigned int vcpu_id, __u64 previous_tsc_offset, |
| 603 | __u64 next_tsc_offset), |
| 604 | TP_ARGS(vcpu_id, previous_tsc_offset, next_tsc_offset), |
| 605 | |
| 606 | TP_FIELDS( |
| 607 | ctf_integer(unsigned int, vcpu_id, vcpu_id) |
| 608 | ctf_integer(__u64, previous_tsc_offset, previous_tsc_offset) |
| 609 | ctf_integer(__u64, next_tsc_offset, next_tsc_offset) |
| 610 | ) |
| 611 | ) |
| 612 | |
| 613 | #ifdef CONFIG_X86_64 |
| 614 | |
| 615 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_update_master_clock, kvm_x86_update_master_clock, |
| 616 | TP_PROTO(bool use_master_clock, unsigned int host_clock, bool offset_matched), |
| 617 | TP_ARGS(use_master_clock, host_clock, offset_matched), |
| 618 | |
| 619 | TP_FIELDS( |
| 620 | ctf_integer(bool, use_master_clock, use_master_clock) |
| 621 | ctf_integer(unsigned int, host_clock, host_clock) |
| 622 | ctf_integer(bool, offset_matched, offset_matched) |
| 623 | ) |
| 624 | ) |
| 625 | |
| 626 | LTTNG_TRACEPOINT_EVENT_MAP(kvm_track_tsc, kvm_x86_track_tsc, |
| 627 | TP_PROTO(unsigned int vcpu_id, unsigned int nr_matched, |
| 628 | unsigned int online_vcpus, bool use_master_clock, |
| 629 | unsigned int host_clock), |
| 630 | TP_ARGS(vcpu_id, nr_matched, online_vcpus, use_master_clock, |
| 631 | host_clock), |
| 632 | |
| 633 | TP_FIELDS( |
| 634 | ctf_integer(unsigned int, vcpu_id, vcpu_id) |
| 635 | ctf_integer(unsigned int, nr_vcpus_matched_tsc, nr_matched) |
| 636 | ctf_integer(unsigned int, online_vcpus, online_vcpus) |
| 637 | ctf_integer(bool, use_master_clock, use_master_clock) |
| 638 | ctf_integer(unsigned int, host_clock, host_clock) |
| 639 | ) |
| 640 | ) |
| 641 | |
| 642 | #endif /* CONFIG_X86_64 */ |
| 643 | |
| 644 | #endif /* LTTNG_TRACE_KVM_H */ |
| 645 | |
| 646 | #undef TRACE_INCLUDE_PATH |
| 647 | #define TRACE_INCLUDE_PATH instrumentation/events/arch/x86/kvm |
| 648 | #undef TRACE_INCLUDE_FILE |
| 649 | #define TRACE_INCLUDE_FILE trace |
| 650 | |
| 651 | /* This part must be outside protection */ |
| 652 | #include <lttng/define_trace.h> |