xref: /linux/include/trace/events/kvm.h (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
1 #if !defined(_TRACE_KVM_MAIN_H) || defined(TRACE_HEADER_MULTI_READ)
2 #define _TRACE_KVM_MAIN_H
3 
4 #include <linux/tracepoint.h>
5 
6 #undef TRACE_SYSTEM
7 #define TRACE_SYSTEM kvm
8 
9 #define ERSN(x) { KVM_EXIT_##x, "KVM_EXIT_" #x }
10 
11 #define kvm_trace_exit_reason						\
12 	ERSN(UNKNOWN), ERSN(EXCEPTION), ERSN(IO), ERSN(HYPERCALL),	\
13 	ERSN(DEBUG), ERSN(HLT), ERSN(MMIO), ERSN(IRQ_WINDOW_OPEN),	\
14 	ERSN(SHUTDOWN), ERSN(FAIL_ENTRY), ERSN(INTR), ERSN(SET_TPR),	\
15 	ERSN(TPR_ACCESS), ERSN(S390_SIEIC), ERSN(S390_RESET), ERSN(DCR),\
16 	ERSN(NMI), ERSN(INTERNAL_ERROR), ERSN(OSI), ERSN(PAPR_HCALL),	\
17 	ERSN(S390_UCONTROL), ERSN(WATCHDOG), ERSN(S390_TSCH)
18 
19 TRACE_EVENT(kvm_userspace_exit,
20 	    TP_PROTO(__u32 reason, int errno),
21 	    TP_ARGS(reason, errno),
22 
23 	TP_STRUCT__entry(
24 		__field(	__u32,		reason		)
25 		__field(	int,		errno		)
26 	),
27 
28 	TP_fast_assign(
29 		__entry->reason		= reason;
30 		__entry->errno		= errno;
31 	),
32 
33 	TP_printk("reason %s (%d)",
34 		  __entry->errno < 0 ?
35 		  (__entry->errno == -EINTR ? "restart" : "error") :
36 		  __print_symbolic(__entry->reason, kvm_trace_exit_reason),
37 		  __entry->errno < 0 ? -__entry->errno : __entry->reason)
38 );
39 
40 TRACE_EVENT(kvm_vcpu_wakeup,
41 	    TP_PROTO(__u64 ns, bool waited),
42 	    TP_ARGS(ns, waited),
43 
44 	TP_STRUCT__entry(
45 		__field(	__u64,		ns		)
46 		__field(	bool,		waited		)
47 	),
48 
49 	TP_fast_assign(
50 		__entry->ns		= ns;
51 		__entry->waited		= waited;
52 	),
53 
54 	TP_printk("%s time %lld ns",
55 		  __entry->waited ? "wait" : "poll",
56 		  __entry->ns)
57 );
58 
59 #if defined(CONFIG_HAVE_KVM_IRQFD)
60 TRACE_EVENT(kvm_set_irq,
61 	TP_PROTO(unsigned int gsi, int level, int irq_source_id),
62 	TP_ARGS(gsi, level, irq_source_id),
63 
64 	TP_STRUCT__entry(
65 		__field(	unsigned int,	gsi		)
66 		__field(	int,		level		)
67 		__field(	int,		irq_source_id	)
68 	),
69 
70 	TP_fast_assign(
71 		__entry->gsi		= gsi;
72 		__entry->level		= level;
73 		__entry->irq_source_id	= irq_source_id;
74 	),
75 
76 	TP_printk("gsi %u level %d source %d",
77 		  __entry->gsi, __entry->level, __entry->irq_source_id)
78 );
79 #endif /* defined(CONFIG_HAVE_KVM_IRQFD) */
80 
81 #if defined(__KVM_HAVE_IOAPIC)
82 #define kvm_deliver_mode		\
83 	{0x0, "Fixed"},			\
84 	{0x1, "LowPrio"},		\
85 	{0x2, "SMI"},			\
86 	{0x3, "Res3"},			\
87 	{0x4, "NMI"},			\
88 	{0x5, "INIT"},			\
89 	{0x6, "SIPI"},			\
90 	{0x7, "ExtINT"}
91 
92 TRACE_EVENT(kvm_ioapic_set_irq,
93 	    TP_PROTO(__u64 e, int pin, bool coalesced),
94 	    TP_ARGS(e, pin, coalesced),
95 
96 	TP_STRUCT__entry(
97 		__field(	__u64,		e		)
98 		__field(	int,		pin		)
99 		__field(	bool,		coalesced	)
100 	),
101 
102 	TP_fast_assign(
103 		__entry->e		= e;
104 		__entry->pin		= pin;
105 		__entry->coalesced	= coalesced;
106 	),
107 
108 	TP_printk("pin %u dst %x vec=%u (%s|%s|%s%s)%s",
109 		  __entry->pin, (u8)(__entry->e >> 56), (u8)__entry->e,
110 		  __print_symbolic((__entry->e >> 8 & 0x7), kvm_deliver_mode),
111 		  (__entry->e & (1<<11)) ? "logical" : "physical",
112 		  (__entry->e & (1<<15)) ? "level" : "edge",
113 		  (__entry->e & (1<<16)) ? "|masked" : "",
114 		  __entry->coalesced ? " (coalesced)" : "")
115 );
116 
117 TRACE_EVENT(kvm_ioapic_delayed_eoi_inj,
118 	    TP_PROTO(__u64 e),
119 	    TP_ARGS(e),
120 
121 	TP_STRUCT__entry(
122 		__field(	__u64,		e		)
123 	),
124 
125 	TP_fast_assign(
126 		__entry->e		= e;
127 	),
128 
129 	TP_printk("dst %x vec=%u (%s|%s|%s%s)",
130 		  (u8)(__entry->e >> 56), (u8)__entry->e,
131 		  __print_symbolic((__entry->e >> 8 & 0x7), kvm_deliver_mode),
132 		  (__entry->e & (1<<11)) ? "logical" : "physical",
133 		  (__entry->e & (1<<15)) ? "level" : "edge",
134 		  (__entry->e & (1<<16)) ? "|masked" : "")
135 );
136 
137 TRACE_EVENT(kvm_msi_set_irq,
138 	    TP_PROTO(__u64 address, __u64 data),
139 	    TP_ARGS(address, data),
140 
141 	TP_STRUCT__entry(
142 		__field(	__u64,		address		)
143 		__field(	__u64,		data		)
144 	),
145 
146 	TP_fast_assign(
147 		__entry->address	= address;
148 		__entry->data		= data;
149 	),
150 
151 	TP_printk("dst %u vec %x (%s|%s|%s%s)",
152 		  (u8)(__entry->address >> 12), (u8)__entry->data,
153 		  __print_symbolic((__entry->data >> 8 & 0x7), kvm_deliver_mode),
154 		  (__entry->address & (1<<2)) ? "logical" : "physical",
155 		  (__entry->data & (1<<15)) ? "level" : "edge",
156 		  (__entry->address & (1<<3)) ? "|rh" : "")
157 );
158 
159 #define kvm_irqchips						\
160 	{KVM_IRQCHIP_PIC_MASTER,	"PIC master"},		\
161 	{KVM_IRQCHIP_PIC_SLAVE,		"PIC slave"},		\
162 	{KVM_IRQCHIP_IOAPIC,		"IOAPIC"}
163 
164 #endif /* defined(__KVM_HAVE_IOAPIC) */
165 
166 #if defined(CONFIG_HAVE_KVM_IRQFD)
167 
168 #ifdef kvm_irqchips
169 #define kvm_ack_irq_string "irqchip %s pin %u"
170 #define kvm_ack_irq_parm  __print_symbolic(__entry->irqchip, kvm_irqchips), __entry->pin
171 #else
172 #define kvm_ack_irq_string "irqchip %d pin %u"
173 #define kvm_ack_irq_parm  __entry->irqchip, __entry->pin
174 #endif
175 
176 TRACE_EVENT(kvm_ack_irq,
177 	TP_PROTO(unsigned int irqchip, unsigned int pin),
178 	TP_ARGS(irqchip, pin),
179 
180 	TP_STRUCT__entry(
181 		__field(	unsigned int,	irqchip		)
182 		__field(	unsigned int,	pin		)
183 	),
184 
185 	TP_fast_assign(
186 		__entry->irqchip	= irqchip;
187 		__entry->pin		= pin;
188 	),
189 
190 	TP_printk(kvm_ack_irq_string, kvm_ack_irq_parm)
191 );
192 
193 #endif /* defined(CONFIG_HAVE_KVM_IRQFD) */
194 
195 
196 
197 #define KVM_TRACE_MMIO_READ_UNSATISFIED 0
198 #define KVM_TRACE_MMIO_READ 1
199 #define KVM_TRACE_MMIO_WRITE 2
200 
201 #define kvm_trace_symbol_mmio \
202 	{ KVM_TRACE_MMIO_READ_UNSATISFIED, "unsatisfied-read" }, \
203 	{ KVM_TRACE_MMIO_READ, "read" }, \
204 	{ KVM_TRACE_MMIO_WRITE, "write" }
205 
206 TRACE_EVENT(kvm_mmio,
207 	TP_PROTO(int type, int len, u64 gpa, u64 val),
208 	TP_ARGS(type, len, gpa, val),
209 
210 	TP_STRUCT__entry(
211 		__field(	u32,	type		)
212 		__field(	u32,	len		)
213 		__field(	u64,	gpa		)
214 		__field(	u64,	val		)
215 	),
216 
217 	TP_fast_assign(
218 		__entry->type		= type;
219 		__entry->len		= len;
220 		__entry->gpa		= gpa;
221 		__entry->val		= val;
222 	),
223 
224 	TP_printk("mmio %s len %u gpa 0x%llx val 0x%llx",
225 		  __print_symbolic(__entry->type, kvm_trace_symbol_mmio),
226 		  __entry->len, __entry->gpa, __entry->val)
227 );
228 
229 #define kvm_fpu_load_symbol	\
230 	{0, "unload"},		\
231 	{1, "load"}
232 
233 TRACE_EVENT(kvm_fpu,
234 	TP_PROTO(int load),
235 	TP_ARGS(load),
236 
237 	TP_STRUCT__entry(
238 		__field(	u32,	        load		)
239 	),
240 
241 	TP_fast_assign(
242 		__entry->load		= load;
243 	),
244 
245 	TP_printk("%s", __print_symbolic(__entry->load, kvm_fpu_load_symbol))
246 );
247 
248 TRACE_EVENT(kvm_age_page,
249 	TP_PROTO(ulong gfn, int level, struct kvm_memory_slot *slot, int ref),
250 	TP_ARGS(gfn, level, slot, ref),
251 
252 	TP_STRUCT__entry(
253 		__field(	u64,	hva		)
254 		__field(	u64,	gfn		)
255 		__field(	u8,	level		)
256 		__field(	u8,	referenced	)
257 	),
258 
259 	TP_fast_assign(
260 		__entry->gfn		= gfn;
261 		__entry->level		= level;
262 		__entry->hva		= ((gfn - slot->base_gfn) <<
263 					    PAGE_SHIFT) + slot->userspace_addr;
264 		__entry->referenced	= ref;
265 	),
266 
267 	TP_printk("hva %llx gfn %llx level %u %s",
268 		  __entry->hva, __entry->gfn, __entry->level,
269 		  __entry->referenced ? "YOUNG" : "OLD")
270 );
271 
272 #ifdef CONFIG_KVM_ASYNC_PF
273 DECLARE_EVENT_CLASS(kvm_async_get_page_class,
274 
275 	TP_PROTO(u64 gva, u64 gfn),
276 
277 	TP_ARGS(gva, gfn),
278 
279 	TP_STRUCT__entry(
280 		__field(__u64, gva)
281 		__field(u64, gfn)
282 	),
283 
284 	TP_fast_assign(
285 		__entry->gva = gva;
286 		__entry->gfn = gfn;
287 	),
288 
289 	TP_printk("gva = %#llx, gfn = %#llx", __entry->gva, __entry->gfn)
290 );
291 
292 DEFINE_EVENT(kvm_async_get_page_class, kvm_try_async_get_page,
293 
294 	TP_PROTO(u64 gva, u64 gfn),
295 
296 	TP_ARGS(gva, gfn)
297 );
298 
299 DEFINE_EVENT(kvm_async_get_page_class, kvm_async_pf_doublefault,
300 
301 	TP_PROTO(u64 gva, u64 gfn),
302 
303 	TP_ARGS(gva, gfn)
304 );
305 
306 DECLARE_EVENT_CLASS(kvm_async_pf_nopresent_ready,
307 
308 	TP_PROTO(u64 token, u64 gva),
309 
310 	TP_ARGS(token, gva),
311 
312 	TP_STRUCT__entry(
313 		__field(__u64, token)
314 		__field(__u64, gva)
315 	),
316 
317 	TP_fast_assign(
318 		__entry->token = token;
319 		__entry->gva = gva;
320 	),
321 
322 	TP_printk("token %#llx gva %#llx", __entry->token, __entry->gva)
323 
324 );
325 
326 DEFINE_EVENT(kvm_async_pf_nopresent_ready, kvm_async_pf_not_present,
327 
328 	TP_PROTO(u64 token, u64 gva),
329 
330 	TP_ARGS(token, gva)
331 );
332 
333 DEFINE_EVENT(kvm_async_pf_nopresent_ready, kvm_async_pf_ready,
334 
335 	TP_PROTO(u64 token, u64 gva),
336 
337 	TP_ARGS(token, gva)
338 );
339 
340 TRACE_EVENT(
341 	kvm_async_pf_completed,
342 	TP_PROTO(unsigned long address, u64 gva),
343 	TP_ARGS(address, gva),
344 
345 	TP_STRUCT__entry(
346 		__field(unsigned long, address)
347 		__field(u64, gva)
348 		),
349 
350 	TP_fast_assign(
351 		__entry->address = address;
352 		__entry->gva = gva;
353 		),
354 
355 	TP_printk("gva %#llx address %#lx",  __entry->gva,
356 		  __entry->address)
357 );
358 
359 #endif
360 
361 TRACE_EVENT(kvm_halt_poll_ns,
362 	TP_PROTO(bool grow, unsigned int vcpu_id, int new, int old),
363 	TP_ARGS(grow, vcpu_id, new, old),
364 
365 	TP_STRUCT__entry(
366 		__field(bool, grow)
367 		__field(unsigned int, vcpu_id)
368 		__field(int, new)
369 		__field(int, old)
370 	),
371 
372 	TP_fast_assign(
373 		__entry->grow           = grow;
374 		__entry->vcpu_id        = vcpu_id;
375 		__entry->new            = new;
376 		__entry->old            = old;
377 	),
378 
379 	TP_printk("vcpu %u: halt_poll_ns %d (%s %d)",
380 			__entry->vcpu_id,
381 			__entry->new,
382 			__entry->grow ? "grow" : "shrink",
383 			__entry->old)
384 );
385 
386 #define trace_kvm_halt_poll_ns_grow(vcpu_id, new, old) \
387 	trace_kvm_halt_poll_ns(true, vcpu_id, new, old)
388 #define trace_kvm_halt_poll_ns_shrink(vcpu_id, new, old) \
389 	trace_kvm_halt_poll_ns(false, vcpu_id, new, old)
390 
391 #endif /* _TRACE_KVM_MAIN_H */
392 
393 /* This part must be outside protection */
394 #include <trace/define_trace.h>
395