xref: /linux/arch/powerpc/kvm/trace.h (revision b889fcf63cb62e7fdb7816565e28f44dbe4a76a5)
1 #if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
2 #define _TRACE_KVM_H
3 
4 #include <linux/tracepoint.h>
5 
6 #undef TRACE_SYSTEM
7 #define TRACE_SYSTEM kvm
8 #define TRACE_INCLUDE_PATH .
9 #define TRACE_INCLUDE_FILE trace
10 
11 /*
12  * Tracepoint for guest mode entry.
13  */
14 TRACE_EVENT(kvm_ppc_instr,
15 	TP_PROTO(unsigned int inst, unsigned long _pc, unsigned int emulate),
16 	TP_ARGS(inst, _pc, emulate),
17 
18 	TP_STRUCT__entry(
19 		__field(	unsigned int,	inst		)
20 		__field(	unsigned long,	pc		)
21 		__field(	unsigned int,	emulate		)
22 	),
23 
24 	TP_fast_assign(
25 		__entry->inst		= inst;
26 		__entry->pc		= _pc;
27 		__entry->emulate	= emulate;
28 	),
29 
30 	TP_printk("inst %u pc 0x%lx emulate %u\n",
31 		  __entry->inst, __entry->pc, __entry->emulate)
32 );
33 
34 #ifdef CONFIG_PPC_BOOK3S
35 #define kvm_trace_symbol_exit \
36 	{0x100, "SYSTEM_RESET"}, \
37 	{0x200, "MACHINE_CHECK"}, \
38 	{0x300, "DATA_STORAGE"}, \
39 	{0x380, "DATA_SEGMENT"}, \
40 	{0x400, "INST_STORAGE"}, \
41 	{0x480, "INST_SEGMENT"}, \
42 	{0x500, "EXTERNAL"}, \
43 	{0x501, "EXTERNAL_LEVEL"}, \
44 	{0x502, "EXTERNAL_HV"}, \
45 	{0x600, "ALIGNMENT"}, \
46 	{0x700, "PROGRAM"}, \
47 	{0x800, "FP_UNAVAIL"}, \
48 	{0x900, "DECREMENTER"}, \
49 	{0x980, "HV_DECREMENTER"}, \
50 	{0xc00, "SYSCALL"}, \
51 	{0xd00, "TRACE"}, \
52 	{0xe00, "H_DATA_STORAGE"}, \
53 	{0xe20, "H_INST_STORAGE"}, \
54 	{0xe40, "H_EMUL_ASSIST"}, \
55 	{0xf00, "PERFMON"}, \
56 	{0xf20, "ALTIVEC"}, \
57 	{0xf40, "VSX"}
58 #else
59 #define kvm_trace_symbol_exit \
60 	{0, "CRITICAL"}, \
61 	{1, "MACHINE_CHECK"}, \
62 	{2, "DATA_STORAGE"}, \
63 	{3, "INST_STORAGE"}, \
64 	{4, "EXTERNAL"}, \
65 	{5, "ALIGNMENT"}, \
66 	{6, "PROGRAM"}, \
67 	{7, "FP_UNAVAIL"}, \
68 	{8, "SYSCALL"}, \
69 	{9, "AP_UNAVAIL"}, \
70 	{10, "DECREMENTER"}, \
71 	{11, "FIT"}, \
72 	{12, "WATCHDOG"}, \
73 	{13, "DTLB_MISS"}, \
74 	{14, "ITLB_MISS"}, \
75 	{15, "DEBUG"}, \
76 	{32, "SPE_UNAVAIL"}, \
77 	{33, "SPE_FP_DATA"}, \
78 	{34, "SPE_FP_ROUND"}, \
79 	{35, "PERFORMANCE_MONITOR"}, \
80 	{36, "DOORBELL"}, \
81 	{37, "DOORBELL_CRITICAL"}, \
82 	{38, "GUEST_DBELL"}, \
83 	{39, "GUEST_DBELL_CRIT"}, \
84 	{40, "HV_SYSCALL"}, \
85 	{41, "HV_PRIV"}
86 #endif
87 
88 TRACE_EVENT(kvm_exit,
89 	TP_PROTO(unsigned int exit_nr, struct kvm_vcpu *vcpu),
90 	TP_ARGS(exit_nr, vcpu),
91 
92 	TP_STRUCT__entry(
93 		__field(	unsigned int,	exit_nr		)
94 		__field(	unsigned long,	pc		)
95 		__field(	unsigned long,	msr		)
96 		__field(	unsigned long,	dar		)
97 #ifdef CONFIG_KVM_BOOK3S_PR
98 		__field(	unsigned long,	srr1		)
99 #endif
100 		__field(	unsigned long,	last_inst	)
101 	),
102 
103 	TP_fast_assign(
104 #ifdef CONFIG_KVM_BOOK3S_PR
105 		struct kvmppc_book3s_shadow_vcpu *svcpu;
106 #endif
107 		__entry->exit_nr	= exit_nr;
108 		__entry->pc		= kvmppc_get_pc(vcpu);
109 		__entry->dar		= kvmppc_get_fault_dar(vcpu);
110 		__entry->msr		= vcpu->arch.shared->msr;
111 #ifdef CONFIG_KVM_BOOK3S_PR
112 		svcpu = svcpu_get(vcpu);
113 		__entry->srr1		= svcpu->shadow_srr1;
114 		svcpu_put(svcpu);
115 #endif
116 		__entry->last_inst	= vcpu->arch.last_inst;
117 	),
118 
119 	TP_printk("exit=%s"
120 		" | pc=0x%lx"
121 		" | msr=0x%lx"
122 		" | dar=0x%lx"
123 #ifdef CONFIG_KVM_BOOK3S_PR
124 		" | srr1=0x%lx"
125 #endif
126 		" | last_inst=0x%lx"
127 		,
128 		__print_symbolic(__entry->exit_nr, kvm_trace_symbol_exit),
129 		__entry->pc,
130 		__entry->msr,
131 		__entry->dar,
132 #ifdef CONFIG_KVM_BOOK3S_PR
133 		__entry->srr1,
134 #endif
135 		__entry->last_inst
136 		)
137 );
138 
139 TRACE_EVENT(kvm_unmap_hva,
140 	TP_PROTO(unsigned long hva),
141 	TP_ARGS(hva),
142 
143 	TP_STRUCT__entry(
144 		__field(	unsigned long,	hva		)
145 	),
146 
147 	TP_fast_assign(
148 		__entry->hva		= hva;
149 	),
150 
151 	TP_printk("unmap hva 0x%lx\n", __entry->hva)
152 );
153 
154 TRACE_EVENT(kvm_stlb_inval,
155 	TP_PROTO(unsigned int stlb_index),
156 	TP_ARGS(stlb_index),
157 
158 	TP_STRUCT__entry(
159 		__field(	unsigned int,	stlb_index	)
160 	),
161 
162 	TP_fast_assign(
163 		__entry->stlb_index	= stlb_index;
164 	),
165 
166 	TP_printk("stlb_index %u", __entry->stlb_index)
167 );
168 
169 TRACE_EVENT(kvm_stlb_write,
170 	TP_PROTO(unsigned int victim, unsigned int tid, unsigned int word0,
171 		 unsigned int word1, unsigned int word2),
172 	TP_ARGS(victim, tid, word0, word1, word2),
173 
174 	TP_STRUCT__entry(
175 		__field(	unsigned int,	victim		)
176 		__field(	unsigned int,	tid		)
177 		__field(	unsigned int,	word0		)
178 		__field(	unsigned int,	word1		)
179 		__field(	unsigned int,	word2		)
180 	),
181 
182 	TP_fast_assign(
183 		__entry->victim		= victim;
184 		__entry->tid		= tid;
185 		__entry->word0		= word0;
186 		__entry->word1		= word1;
187 		__entry->word2		= word2;
188 	),
189 
190 	TP_printk("victim %u tid %u w0 %u w1 %u w2 %u",
191 		__entry->victim, __entry->tid, __entry->word0,
192 		__entry->word1, __entry->word2)
193 );
194 
195 TRACE_EVENT(kvm_gtlb_write,
196 	TP_PROTO(unsigned int gtlb_index, unsigned int tid, unsigned int word0,
197 		 unsigned int word1, unsigned int word2),
198 	TP_ARGS(gtlb_index, tid, word0, word1, word2),
199 
200 	TP_STRUCT__entry(
201 		__field(	unsigned int,	gtlb_index	)
202 		__field(	unsigned int,	tid		)
203 		__field(	unsigned int,	word0		)
204 		__field(	unsigned int,	word1		)
205 		__field(	unsigned int,	word2		)
206 	),
207 
208 	TP_fast_assign(
209 		__entry->gtlb_index	= gtlb_index;
210 		__entry->tid		= tid;
211 		__entry->word0		= word0;
212 		__entry->word1		= word1;
213 		__entry->word2		= word2;
214 	),
215 
216 	TP_printk("gtlb_index %u tid %u w0 %u w1 %u w2 %u",
217 		__entry->gtlb_index, __entry->tid, __entry->word0,
218 		__entry->word1, __entry->word2)
219 );
220 
221 TRACE_EVENT(kvm_check_requests,
222 	TP_PROTO(struct kvm_vcpu *vcpu),
223 	TP_ARGS(vcpu),
224 
225 	TP_STRUCT__entry(
226 		__field(	__u32,	cpu_nr		)
227 		__field(	__u32,	requests	)
228 	),
229 
230 	TP_fast_assign(
231 		__entry->cpu_nr		= vcpu->vcpu_id;
232 		__entry->requests	= vcpu->requests;
233 	),
234 
235 	TP_printk("vcpu=%x requests=%x",
236 		__entry->cpu_nr, __entry->requests)
237 );
238 
239 
240 /*************************************************************************
241  *                         Book3S trace points                           *
242  *************************************************************************/
243 
244 #ifdef CONFIG_KVM_BOOK3S_PR
245 
246 TRACE_EVENT(kvm_book3s_reenter,
247 	TP_PROTO(int r, struct kvm_vcpu *vcpu),
248 	TP_ARGS(r, vcpu),
249 
250 	TP_STRUCT__entry(
251 		__field(	unsigned int,	r		)
252 		__field(	unsigned long,	pc		)
253 	),
254 
255 	TP_fast_assign(
256 		__entry->r		= r;
257 		__entry->pc		= kvmppc_get_pc(vcpu);
258 	),
259 
260 	TP_printk("reentry r=%d | pc=0x%lx", __entry->r, __entry->pc)
261 );
262 
263 #ifdef CONFIG_PPC_BOOK3S_64
264 
265 TRACE_EVENT(kvm_book3s_64_mmu_map,
266 	TP_PROTO(int rflags, ulong hpteg, ulong va, pfn_t hpaddr,
267 		 struct kvmppc_pte *orig_pte),
268 	TP_ARGS(rflags, hpteg, va, hpaddr, orig_pte),
269 
270 	TP_STRUCT__entry(
271 		__field(	unsigned char,		flag_w		)
272 		__field(	unsigned char,		flag_x		)
273 		__field(	unsigned long,		eaddr		)
274 		__field(	unsigned long,		hpteg		)
275 		__field(	unsigned long,		va		)
276 		__field(	unsigned long long,	vpage		)
277 		__field(	unsigned long,		hpaddr		)
278 	),
279 
280 	TP_fast_assign(
281 		__entry->flag_w	= ((rflags & HPTE_R_PP) == 3) ? '-' : 'w';
282 		__entry->flag_x	= (rflags & HPTE_R_N) ? '-' : 'x';
283 		__entry->eaddr	= orig_pte->eaddr;
284 		__entry->hpteg	= hpteg;
285 		__entry->va	= va;
286 		__entry->vpage	= orig_pte->vpage;
287 		__entry->hpaddr	= hpaddr;
288 	),
289 
290 	TP_printk("KVM: %c%c Map 0x%lx: [%lx] 0x%lx (0x%llx) -> %lx",
291 		  __entry->flag_w, __entry->flag_x, __entry->eaddr,
292 		  __entry->hpteg, __entry->va, __entry->vpage, __entry->hpaddr)
293 );
294 
295 #endif /* CONFIG_PPC_BOOK3S_64 */
296 
297 TRACE_EVENT(kvm_book3s_mmu_map,
298 	TP_PROTO(struct hpte_cache *pte),
299 	TP_ARGS(pte),
300 
301 	TP_STRUCT__entry(
302 		__field(	u64,		host_vpn	)
303 		__field(	u64,		pfn		)
304 		__field(	ulong,		eaddr		)
305 		__field(	u64,		vpage		)
306 		__field(	ulong,		raddr		)
307 		__field(	int,		flags		)
308 	),
309 
310 	TP_fast_assign(
311 		__entry->host_vpn	= pte->host_vpn;
312 		__entry->pfn		= pte->pfn;
313 		__entry->eaddr		= pte->pte.eaddr;
314 		__entry->vpage		= pte->pte.vpage;
315 		__entry->raddr		= pte->pte.raddr;
316 		__entry->flags		= (pte->pte.may_read ? 0x4 : 0) |
317 					  (pte->pte.may_write ? 0x2 : 0) |
318 					  (pte->pte.may_execute ? 0x1 : 0);
319 	),
320 
321 	TP_printk("Map: hvpn=%llx pfn=%llx ea=%lx vp=%llx ra=%lx [%x]",
322 		  __entry->host_vpn, __entry->pfn, __entry->eaddr,
323 		  __entry->vpage, __entry->raddr, __entry->flags)
324 );
325 
326 TRACE_EVENT(kvm_book3s_mmu_invalidate,
327 	TP_PROTO(struct hpte_cache *pte),
328 	TP_ARGS(pte),
329 
330 	TP_STRUCT__entry(
331 		__field(	u64,		host_vpn	)
332 		__field(	u64,		pfn		)
333 		__field(	ulong,		eaddr		)
334 		__field(	u64,		vpage		)
335 		__field(	ulong,		raddr		)
336 		__field(	int,		flags		)
337 	),
338 
339 	TP_fast_assign(
340 		__entry->host_vpn	= pte->host_vpn;
341 		__entry->pfn		= pte->pfn;
342 		__entry->eaddr		= pte->pte.eaddr;
343 		__entry->vpage		= pte->pte.vpage;
344 		__entry->raddr		= pte->pte.raddr;
345 		__entry->flags		= (pte->pte.may_read ? 0x4 : 0) |
346 					  (pte->pte.may_write ? 0x2 : 0) |
347 					  (pte->pte.may_execute ? 0x1 : 0);
348 	),
349 
350 	TP_printk("Flush: hva=%llx pfn=%llx ea=%lx vp=%llx ra=%lx [%x]",
351 		  __entry->host_vpn, __entry->pfn, __entry->eaddr,
352 		  __entry->vpage, __entry->raddr, __entry->flags)
353 );
354 
355 TRACE_EVENT(kvm_book3s_mmu_flush,
356 	TP_PROTO(const char *type, struct kvm_vcpu *vcpu, unsigned long long p1,
357 		 unsigned long long p2),
358 	TP_ARGS(type, vcpu, p1, p2),
359 
360 	TP_STRUCT__entry(
361 		__field(	int,			count		)
362 		__field(	unsigned long long,	p1		)
363 		__field(	unsigned long long,	p2		)
364 		__field(	const char *,		type		)
365 	),
366 
367 	TP_fast_assign(
368 		__entry->count		= to_book3s(vcpu)->hpte_cache_count;
369 		__entry->p1		= p1;
370 		__entry->p2		= p2;
371 		__entry->type		= type;
372 	),
373 
374 	TP_printk("Flush %d %sPTEs: %llx - %llx",
375 		  __entry->count, __entry->type, __entry->p1, __entry->p2)
376 );
377 
378 TRACE_EVENT(kvm_book3s_slb_found,
379 	TP_PROTO(unsigned long long gvsid, unsigned long long hvsid),
380 	TP_ARGS(gvsid, hvsid),
381 
382 	TP_STRUCT__entry(
383 		__field(	unsigned long long,	gvsid		)
384 		__field(	unsigned long long,	hvsid		)
385 	),
386 
387 	TP_fast_assign(
388 		__entry->gvsid		= gvsid;
389 		__entry->hvsid		= hvsid;
390 	),
391 
392 	TP_printk("%llx -> %llx", __entry->gvsid, __entry->hvsid)
393 );
394 
395 TRACE_EVENT(kvm_book3s_slb_fail,
396 	TP_PROTO(u16 sid_map_mask, unsigned long long gvsid),
397 	TP_ARGS(sid_map_mask, gvsid),
398 
399 	TP_STRUCT__entry(
400 		__field(	unsigned short,		sid_map_mask	)
401 		__field(	unsigned long long,	gvsid		)
402 	),
403 
404 	TP_fast_assign(
405 		__entry->sid_map_mask	= sid_map_mask;
406 		__entry->gvsid		= gvsid;
407 	),
408 
409 	TP_printk("%x/%x: %llx", __entry->sid_map_mask,
410 		  SID_MAP_MASK - __entry->sid_map_mask, __entry->gvsid)
411 );
412 
413 TRACE_EVENT(kvm_book3s_slb_map,
414 	TP_PROTO(u16 sid_map_mask, unsigned long long gvsid,
415 		 unsigned long long hvsid),
416 	TP_ARGS(sid_map_mask, gvsid, hvsid),
417 
418 	TP_STRUCT__entry(
419 		__field(	unsigned short,		sid_map_mask	)
420 		__field(	unsigned long long,	guest_vsid	)
421 		__field(	unsigned long long,	host_vsid	)
422 	),
423 
424 	TP_fast_assign(
425 		__entry->sid_map_mask	= sid_map_mask;
426 		__entry->guest_vsid	= gvsid;
427 		__entry->host_vsid	= hvsid;
428 	),
429 
430 	TP_printk("%x: %llx -> %llx", __entry->sid_map_mask,
431 		  __entry->guest_vsid, __entry->host_vsid)
432 );
433 
434 TRACE_EVENT(kvm_book3s_slbmte,
435 	TP_PROTO(u64 slb_vsid, u64 slb_esid),
436 	TP_ARGS(slb_vsid, slb_esid),
437 
438 	TP_STRUCT__entry(
439 		__field(	u64,	slb_vsid	)
440 		__field(	u64,	slb_esid	)
441 	),
442 
443 	TP_fast_assign(
444 		__entry->slb_vsid	= slb_vsid;
445 		__entry->slb_esid	= slb_esid;
446 	),
447 
448 	TP_printk("%llx, %llx", __entry->slb_vsid, __entry->slb_esid)
449 );
450 
451 #endif /* CONFIG_PPC_BOOK3S */
452 
453 
454 /*************************************************************************
455  *                         Book3E trace points                           *
456  *************************************************************************/
457 
458 #ifdef CONFIG_BOOKE
459 
460 TRACE_EVENT(kvm_booke206_stlb_write,
461 	TP_PROTO(__u32 mas0, __u32 mas8, __u32 mas1, __u64 mas2, __u64 mas7_3),
462 	TP_ARGS(mas0, mas8, mas1, mas2, mas7_3),
463 
464 	TP_STRUCT__entry(
465 		__field(	__u32,	mas0		)
466 		__field(	__u32,	mas8		)
467 		__field(	__u32,	mas1		)
468 		__field(	__u64,	mas2		)
469 		__field(	__u64,	mas7_3		)
470 	),
471 
472 	TP_fast_assign(
473 		__entry->mas0		= mas0;
474 		__entry->mas8		= mas8;
475 		__entry->mas1		= mas1;
476 		__entry->mas2		= mas2;
477 		__entry->mas7_3		= mas7_3;
478 	),
479 
480 	TP_printk("mas0=%x mas8=%x mas1=%x mas2=%llx mas7_3=%llx",
481 		__entry->mas0, __entry->mas8, __entry->mas1,
482 		__entry->mas2, __entry->mas7_3)
483 );
484 
485 TRACE_EVENT(kvm_booke206_gtlb_write,
486 	TP_PROTO(__u32 mas0, __u32 mas1, __u64 mas2, __u64 mas7_3),
487 	TP_ARGS(mas0, mas1, mas2, mas7_3),
488 
489 	TP_STRUCT__entry(
490 		__field(	__u32,	mas0		)
491 		__field(	__u32,	mas1		)
492 		__field(	__u64,	mas2		)
493 		__field(	__u64,	mas7_3		)
494 	),
495 
496 	TP_fast_assign(
497 		__entry->mas0		= mas0;
498 		__entry->mas1		= mas1;
499 		__entry->mas2		= mas2;
500 		__entry->mas7_3		= mas7_3;
501 	),
502 
503 	TP_printk("mas0=%x mas1=%x mas2=%llx mas7_3=%llx",
504 		__entry->mas0, __entry->mas1,
505 		__entry->mas2, __entry->mas7_3)
506 );
507 
508 TRACE_EVENT(kvm_booke206_ref_release,
509 	TP_PROTO(__u64 pfn, __u32 flags),
510 	TP_ARGS(pfn, flags),
511 
512 	TP_STRUCT__entry(
513 		__field(	__u64,	pfn		)
514 		__field(	__u32,	flags		)
515 	),
516 
517 	TP_fast_assign(
518 		__entry->pfn		= pfn;
519 		__entry->flags		= flags;
520 	),
521 
522 	TP_printk("pfn=%llx flags=%x",
523 		__entry->pfn, __entry->flags)
524 );
525 
526 TRACE_EVENT(kvm_booke_queue_irqprio,
527 	TP_PROTO(struct kvm_vcpu *vcpu, unsigned int priority),
528 	TP_ARGS(vcpu, priority),
529 
530 	TP_STRUCT__entry(
531 		__field(	__u32,	cpu_nr		)
532 		__field(	__u32,	priority		)
533 		__field(	unsigned long,	pending		)
534 	),
535 
536 	TP_fast_assign(
537 		__entry->cpu_nr		= vcpu->vcpu_id;
538 		__entry->priority	= priority;
539 		__entry->pending	= vcpu->arch.pending_exceptions;
540 	),
541 
542 	TP_printk("vcpu=%x prio=%x pending=%lx",
543 		__entry->cpu_nr, __entry->priority, __entry->pending)
544 );
545 
546 #endif
547 
548 #endif /* _TRACE_KVM_H */
549 
550 /* This part must be outside protection */
551 #include <trace/define_trace.h>
552