1 /* SPDX-License-Identifier: GPL-2.0 */
2 #if !defined(_TRACE_KVM_MAIN_H) || defined(TRACE_HEADER_MULTI_READ)
3 #define _TRACE_KVM_MAIN_H
5 #include <linux/tracepoint.h>
8 #define TRACE_SYSTEM kvm
10 #define ERSN(x) { KVM_EXIT_##x, "KVM_EXIT_" #x }
12 #define kvm_trace_exit_reason \
13 ERSN(UNKNOWN), ERSN(EXCEPTION), ERSN(IO), ERSN(HYPERCALL), \
14 ERSN(DEBUG), ERSN(HLT), ERSN(MMIO), ERSN(IRQ_WINDOW_OPEN), \
15 ERSN(SHUTDOWN), ERSN(FAIL_ENTRY), ERSN(INTR), ERSN(SET_TPR), \
16 ERSN(TPR_ACCESS), ERSN(S390_SIEIC), ERSN(S390_RESET), ERSN(DCR),\
17 ERSN(NMI), ERSN(INTERNAL_ERROR), ERSN(OSI), ERSN(PAPR_HCALL), \
18 ERSN(S390_UCONTROL), ERSN(WATCHDOG), ERSN(S390_TSCH), ERSN(EPR),\
19 ERSN(SYSTEM_EVENT), ERSN(S390_STSI), ERSN(IOAPIC_EOI), \
20 ERSN(HYPERV), ERSN(ARM_NISV), ERSN(X86_RDMSR), ERSN(X86_WRMSR)
22 TRACE_EVENT(kvm_userspace_exit
,
23 TP_PROTO(__u32 reason
, int errno
),
24 TP_ARGS(reason
, errno
),
27 __field( __u32
, reason
)
32 __entry
->reason
= reason
;
33 __entry
->errno
= errno
;
36 TP_printk("reason %s (%d)",
38 (__entry
->errno
== -EINTR
? "restart" : "error") :
39 __print_symbolic(__entry
->reason
, kvm_trace_exit_reason
),
40 __entry
->errno
< 0 ? -__entry
->errno
: __entry
->reason
)
43 TRACE_EVENT(kvm_vcpu_wakeup
,
44 TP_PROTO(__u64 ns
, bool waited
, bool valid
),
45 TP_ARGS(ns
, waited
, valid
),
49 __field( bool, waited
)
50 __field( bool, valid
)
55 __entry
->waited
= waited
;
56 __entry
->valid
= valid
;
59 TP_printk("%s time %lld ns, polling %s",
60 __entry
->waited
? "wait" : "poll",
62 __entry
->valid
? "valid" : "invalid")
65 #if defined(CONFIG_HAVE_KVM_IRQFD)
66 TRACE_EVENT(kvm_set_irq
,
67 TP_PROTO(unsigned int gsi
, int level
, int irq_source_id
),
68 TP_ARGS(gsi
, level
, irq_source_id
),
71 __field( unsigned int, gsi
)
73 __field( int, irq_source_id
)
78 __entry
->level
= level
;
79 __entry
->irq_source_id
= irq_source_id
;
82 TP_printk("gsi %u level %d source %d",
83 __entry
->gsi
, __entry
->level
, __entry
->irq_source_id
)
85 #endif /* defined(CONFIG_HAVE_KVM_IRQFD) */
87 #if defined(__KVM_HAVE_IOAPIC)
88 #define kvm_deliver_mode \
98 TRACE_EVENT(kvm_ioapic_set_irq
,
99 TP_PROTO(__u64 e
, int pin
, bool coalesced
),
100 TP_ARGS(e
, pin
, coalesced
),
105 __field( bool, coalesced
)
111 __entry
->coalesced
= coalesced
;
114 TP_printk("pin %u dst %x vec %u (%s|%s|%s%s)%s",
115 __entry
->pin
, (u8
)(__entry
->e
>> 56), (u8
)__entry
->e
,
116 __print_symbolic((__entry
->e
>> 8 & 0x7), kvm_deliver_mode
),
117 (__entry
->e
& (1<<11)) ? "logical" : "physical",
118 (__entry
->e
& (1<<15)) ? "level" : "edge",
119 (__entry
->e
& (1<<16)) ? "|masked" : "",
120 __entry
->coalesced
? " (coalesced)" : "")
123 TRACE_EVENT(kvm_ioapic_delayed_eoi_inj
,
135 TP_printk("dst %x vec %u (%s|%s|%s%s)",
136 (u8
)(__entry
->e
>> 56), (u8
)__entry
->e
,
137 __print_symbolic((__entry
->e
>> 8 & 0x7), kvm_deliver_mode
),
138 (__entry
->e
& (1<<11)) ? "logical" : "physical",
139 (__entry
->e
& (1<<15)) ? "level" : "edge",
140 (__entry
->e
& (1<<16)) ? "|masked" : "")
143 TRACE_EVENT(kvm_msi_set_irq
,
144 TP_PROTO(__u64 address
, __u64 data
),
145 TP_ARGS(address
, data
),
148 __field( __u64
, address
)
149 __field( __u64
, data
)
153 __entry
->address
= address
;
154 __entry
->data
= data
;
157 TP_printk("dst %llx vec %u (%s|%s|%s%s)",
158 (u8
)(__entry
->address
>> 12) | ((__entry
->address
>> 32) & 0xffffff00),
160 __print_symbolic((__entry
->data
>> 8 & 0x7), kvm_deliver_mode
),
161 (__entry
->address
& (1<<2)) ? "logical" : "physical",
162 (__entry
->data
& (1<<15)) ? "level" : "edge",
163 (__entry
->address
& (1<<3)) ? "|rh" : "")
166 #define kvm_irqchips \
167 {KVM_IRQCHIP_PIC_MASTER, "PIC master"}, \
168 {KVM_IRQCHIP_PIC_SLAVE, "PIC slave"}, \
169 {KVM_IRQCHIP_IOAPIC, "IOAPIC"}
171 #endif /* defined(__KVM_HAVE_IOAPIC) */
173 #if defined(CONFIG_HAVE_KVM_IRQFD)
176 #define kvm_ack_irq_string "irqchip %s pin %u"
177 #define kvm_ack_irq_parm __print_symbolic(__entry->irqchip, kvm_irqchips), __entry->pin
179 #define kvm_ack_irq_string "irqchip %d pin %u"
180 #define kvm_ack_irq_parm __entry->irqchip, __entry->pin
183 TRACE_EVENT(kvm_ack_irq
,
184 TP_PROTO(unsigned int irqchip
, unsigned int pin
),
185 TP_ARGS(irqchip
, pin
),
188 __field( unsigned int, irqchip
)
189 __field( unsigned int, pin
)
193 __entry
->irqchip
= irqchip
;
197 TP_printk(kvm_ack_irq_string
, kvm_ack_irq_parm
)
200 #endif /* defined(CONFIG_HAVE_KVM_IRQFD) */
204 #define KVM_TRACE_MMIO_READ_UNSATISFIED 0
205 #define KVM_TRACE_MMIO_READ 1
206 #define KVM_TRACE_MMIO_WRITE 2
208 #define kvm_trace_symbol_mmio \
209 { KVM_TRACE_MMIO_READ_UNSATISFIED, "unsatisfied-read" }, \
210 { KVM_TRACE_MMIO_READ, "read" }, \
211 { KVM_TRACE_MMIO_WRITE, "write" }
213 TRACE_EVENT(kvm_mmio
,
214 TP_PROTO(int type
, int len
, u64 gpa
, void *val
),
215 TP_ARGS(type
, len
, gpa
, val
),
225 __entry
->type
= type
;
230 memcpy(&__entry
->val
, val
,
231 min_t(u32
, sizeof(__entry
->val
), len
));
234 TP_printk("mmio %s len %u gpa 0x%llx val 0x%llx",
235 __print_symbolic(__entry
->type
, kvm_trace_symbol_mmio
),
236 __entry
->len
, __entry
->gpa
, __entry
->val
)
239 #define kvm_fpu_load_symbol \
252 __entry
->load
= load
;
255 TP_printk("%s", __print_symbolic(__entry
->load
, kvm_fpu_load_symbol
))
258 TRACE_EVENT(kvm_age_page
,
259 TP_PROTO(ulong gfn
, int level
, struct kvm_memory_slot
*slot
, int ref
),
260 TP_ARGS(gfn
, level
, slot
, ref
),
266 __field( u8
, referenced
)
271 __entry
->level
= level
;
272 __entry
->hva
= ((gfn
- slot
->base_gfn
) <<
273 PAGE_SHIFT
) + slot
->userspace_addr
;
274 __entry
->referenced
= ref
;
277 TP_printk("hva %llx gfn %llx level %u %s",
278 __entry
->hva
, __entry
->gfn
, __entry
->level
,
279 __entry
->referenced
? "YOUNG" : "OLD")
282 #ifdef CONFIG_KVM_ASYNC_PF
283 DECLARE_EVENT_CLASS(kvm_async_get_page_class
,
285 TP_PROTO(u64 gva
, u64 gfn
),
299 TP_printk("gva = %#llx, gfn = %#llx", __entry
->gva
, __entry
->gfn
)
302 DEFINE_EVENT(kvm_async_get_page_class
, kvm_try_async_get_page
,
304 TP_PROTO(u64 gva
, u64 gfn
),
309 DEFINE_EVENT(kvm_async_get_page_class
, kvm_async_pf_doublefault
,
311 TP_PROTO(u64 gva
, u64 gfn
),
316 DECLARE_EVENT_CLASS(kvm_async_pf_nopresent_ready
,
318 TP_PROTO(u64 token
, u64 gva
),
323 __field(__u64
, token
)
328 __entry
->token
= token
;
332 TP_printk("token %#llx gva %#llx", __entry
->token
, __entry
->gva
)
336 DEFINE_EVENT(kvm_async_pf_nopresent_ready
, kvm_async_pf_not_present
,
338 TP_PROTO(u64 token
, u64 gva
),
343 DEFINE_EVENT(kvm_async_pf_nopresent_ready
, kvm_async_pf_ready
,
345 TP_PROTO(u64 token
, u64 gva
),
351 kvm_async_pf_completed
,
352 TP_PROTO(unsigned long address
, u64 gva
),
353 TP_ARGS(address
, gva
),
356 __field(unsigned long, address
)
361 __entry
->address
= address
;
365 TP_printk("gva %#llx address %#lx", __entry
->gva
,
371 TRACE_EVENT(kvm_halt_poll_ns
,
372 TP_PROTO(bool grow
, unsigned int vcpu_id
, unsigned int new,
374 TP_ARGS(grow
, vcpu_id
, new, old
),
378 __field(unsigned int, vcpu_id
)
379 __field(unsigned int, new)
380 __field(unsigned int, old
)
384 __entry
->grow
= grow
;
385 __entry
->vcpu_id
= vcpu_id
;
390 TP_printk("vcpu %u: halt_poll_ns %u (%s %u)",
393 __entry
->grow
? "grow" : "shrink",
397 #define trace_kvm_halt_poll_ns_grow(vcpu_id, new, old) \
398 trace_kvm_halt_poll_ns(true, vcpu_id, new, old)
399 #define trace_kvm_halt_poll_ns_shrink(vcpu_id, new, old) \
400 trace_kvm_halt_poll_ns(false, vcpu_id, new, old)
402 TRACE_EVENT(kvm_dirty_ring_push
,
403 TP_PROTO(struct kvm_dirty_ring
*ring
, u32 slot
, u64 offset
),
404 TP_ARGS(ring
, slot
, offset
),
408 __field(u32
, dirty_index
)
409 __field(u32
, reset_index
)
415 __entry
->index
= ring
->index
;
416 __entry
->dirty_index
= ring
->dirty_index
;
417 __entry
->reset_index
= ring
->reset_index
;
418 __entry
->slot
= slot
;
419 __entry
->offset
= offset
;
422 TP_printk("ring %d: dirty 0x%x reset 0x%x "
423 "slot %u offset 0x%llx (used %u)",
424 __entry
->index
, __entry
->dirty_index
,
425 __entry
->reset_index
, __entry
->slot
, __entry
->offset
,
426 __entry
->dirty_index
- __entry
->reset_index
)
429 TRACE_EVENT(kvm_dirty_ring_reset
,
430 TP_PROTO(struct kvm_dirty_ring
*ring
),
435 __field(u32
, dirty_index
)
436 __field(u32
, reset_index
)
440 __entry
->index
= ring
->index
;
441 __entry
->dirty_index
= ring
->dirty_index
;
442 __entry
->reset_index
= ring
->reset_index
;
445 TP_printk("ring %d: dirty 0x%x reset 0x%x (used %u)",
446 __entry
->index
, __entry
->dirty_index
, __entry
->reset_index
,
447 __entry
->dirty_index
- __entry
->reset_index
)
450 TRACE_EVENT(kvm_dirty_ring_exit
,
451 TP_PROTO(struct kvm_vcpu
*vcpu
),
455 __field(int, vcpu_id
)
459 __entry
->vcpu_id
= vcpu
->vcpu_id
;
462 TP_printk("vcpu %d", __entry
->vcpu_id
)
465 #endif /* _TRACE_KVM_MAIN_H */
467 /* This part must be outside protection */
468 #include <trace/define_trace.h>