xref: /linux/arch/mips/kvm/trace.h (revision e5c86679d5e864947a52fb31e45a425dea3e7fa9)
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 2012  MIPS Technologies, Inc.  All rights reserved.
7  * Authors: Sanjay Lal <sanjayl@kymasys.com>
8  */
9 
10 #if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
11 #define _TRACE_KVM_H
12 
13 #include <linux/tracepoint.h>
14 
15 #undef TRACE_SYSTEM
16 #define TRACE_SYSTEM kvm
17 #define TRACE_INCLUDE_PATH .
18 #define TRACE_INCLUDE_FILE trace
19 
20 /*
21  * Tracepoints for VM enters
22  */
23 DECLARE_EVENT_CLASS(kvm_transition,
24 	TP_PROTO(struct kvm_vcpu *vcpu),
25 	TP_ARGS(vcpu),
26 	TP_STRUCT__entry(
27 		__field(unsigned long, pc)
28 	),
29 
30 	TP_fast_assign(
31 		__entry->pc = vcpu->arch.pc;
32 	),
33 
34 	TP_printk("PC: 0x%08lx",
35 		  __entry->pc)
36 );
37 
38 DEFINE_EVENT(kvm_transition, kvm_enter,
39 	     TP_PROTO(struct kvm_vcpu *vcpu),
40 	     TP_ARGS(vcpu));
41 
42 DEFINE_EVENT(kvm_transition, kvm_reenter,
43 	     TP_PROTO(struct kvm_vcpu *vcpu),
44 	     TP_ARGS(vcpu));
45 
46 DEFINE_EVENT(kvm_transition, kvm_out,
47 	     TP_PROTO(struct kvm_vcpu *vcpu),
48 	     TP_ARGS(vcpu));
49 
50 /* The first 32 exit reasons correspond to Cause.ExcCode */
51 #define KVM_TRACE_EXIT_INT		 0
52 #define KVM_TRACE_EXIT_TLBMOD		 1
53 #define KVM_TRACE_EXIT_TLBMISS_LD	 2
54 #define KVM_TRACE_EXIT_TLBMISS_ST	 3
55 #define KVM_TRACE_EXIT_ADDRERR_LD	 4
56 #define KVM_TRACE_EXIT_ADDRERR_ST	 5
57 #define KVM_TRACE_EXIT_SYSCALL		 8
58 #define KVM_TRACE_EXIT_BREAK_INST	 9
59 #define KVM_TRACE_EXIT_RESVD_INST	10
60 #define KVM_TRACE_EXIT_COP_UNUSABLE	11
61 #define KVM_TRACE_EXIT_TRAP_INST	13
62 #define KVM_TRACE_EXIT_MSA_FPE		14
63 #define KVM_TRACE_EXIT_FPE		15
64 #define KVM_TRACE_EXIT_MSA_DISABLED	21
65 /* Further exit reasons */
66 #define KVM_TRACE_EXIT_WAIT		32
67 #define KVM_TRACE_EXIT_CACHE		33
68 #define KVM_TRACE_EXIT_SIGNAL		34
69 
70 /* Tracepoints for VM exits */
71 #define kvm_trace_symbol_exit_types				\
72 	{ KVM_TRACE_EXIT_INT,		"Interrupt" },		\
73 	{ KVM_TRACE_EXIT_TLBMOD,	"TLB Mod" },		\
74 	{ KVM_TRACE_EXIT_TLBMISS_LD,	"TLB Miss (LD)" },	\
75 	{ KVM_TRACE_EXIT_TLBMISS_ST,	"TLB Miss (ST)" },	\
76 	{ KVM_TRACE_EXIT_ADDRERR_LD,	"Address Error (LD)" },	\
77 	{ KVM_TRACE_EXIT_ADDRERR_ST,	"Address Err (ST)" },	\
78 	{ KVM_TRACE_EXIT_SYSCALL,	"System Call" },	\
79 	{ KVM_TRACE_EXIT_BREAK_INST,	"Break Inst" },		\
80 	{ KVM_TRACE_EXIT_RESVD_INST,	"Reserved Inst" },	\
81 	{ KVM_TRACE_EXIT_COP_UNUSABLE,	"COP0/1 Unusable" },	\
82 	{ KVM_TRACE_EXIT_TRAP_INST,	"Trap Inst" },		\
83 	{ KVM_TRACE_EXIT_MSA_FPE,	"MSA FPE" },		\
84 	{ KVM_TRACE_EXIT_FPE,		"FPE" },		\
85 	{ KVM_TRACE_EXIT_MSA_DISABLED,	"MSA Disabled" },	\
86 	{ KVM_TRACE_EXIT_WAIT,		"WAIT" },		\
87 	{ KVM_TRACE_EXIT_CACHE,		"CACHE" },		\
88 	{ KVM_TRACE_EXIT_SIGNAL,	"Signal" }
89 
90 TRACE_EVENT(kvm_exit,
91 	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int reason),
92 	    TP_ARGS(vcpu, reason),
93 	    TP_STRUCT__entry(
94 			__field(unsigned long, pc)
95 			__field(unsigned int, reason)
96 	    ),
97 
98 	    TP_fast_assign(
99 			__entry->pc = vcpu->arch.pc;
100 			__entry->reason = reason;
101 	    ),
102 
103 	    TP_printk("[%s]PC: 0x%08lx",
104 		      __print_symbolic(__entry->reason,
105 				       kvm_trace_symbol_exit_types),
106 		      __entry->pc)
107 );
108 
109 #define KVM_TRACE_MFC0		0
110 #define KVM_TRACE_MTC0		1
111 #define KVM_TRACE_DMFC0		2
112 #define KVM_TRACE_DMTC0		3
113 #define KVM_TRACE_RDHWR		4
114 
115 #define KVM_TRACE_HWR_COP0	0
116 #define KVM_TRACE_HWR_HWR	1
117 
118 #define KVM_TRACE_COP0(REG, SEL)	((KVM_TRACE_HWR_COP0 << 8) |	\
119 					 ((REG) << 3) | (SEL))
120 #define KVM_TRACE_HWR(REG, SEL)		((KVM_TRACE_HWR_HWR  << 8) |	\
121 					 ((REG) << 3) | (SEL))
122 
123 #define kvm_trace_symbol_hwr_ops				\
124 	{ KVM_TRACE_MFC0,		"MFC0" },		\
125 	{ KVM_TRACE_MTC0,		"MTC0" },		\
126 	{ KVM_TRACE_DMFC0,		"DMFC0" },		\
127 	{ KVM_TRACE_DMTC0,		"DMTC0" },		\
128 	{ KVM_TRACE_RDHWR,		"RDHWR" }
129 
130 #define kvm_trace_symbol_hwr_cop				\
131 	{ KVM_TRACE_HWR_COP0,		"COP0" },		\
132 	{ KVM_TRACE_HWR_HWR,		"HWR" }
133 
134 #define kvm_trace_symbol_hwr_regs				\
135 	{ KVM_TRACE_COP0( 0, 0),	"Index" },		\
136 	{ KVM_TRACE_COP0( 2, 0),	"EntryLo0" },		\
137 	{ KVM_TRACE_COP0( 3, 0),	"EntryLo1" },		\
138 	{ KVM_TRACE_COP0( 4, 0),	"Context" },		\
139 	{ KVM_TRACE_COP0( 4, 2),	"UserLocal" },		\
140 	{ KVM_TRACE_COP0( 5, 0),	"PageMask" },		\
141 	{ KVM_TRACE_COP0( 6, 0),	"Wired" },		\
142 	{ KVM_TRACE_COP0( 7, 0),	"HWREna" },		\
143 	{ KVM_TRACE_COP0( 8, 0),	"BadVAddr" },		\
144 	{ KVM_TRACE_COP0( 9, 0),	"Count" },		\
145 	{ KVM_TRACE_COP0(10, 0),	"EntryHi" },		\
146 	{ KVM_TRACE_COP0(11, 0),	"Compare" },		\
147 	{ KVM_TRACE_COP0(12, 0),	"Status" },		\
148 	{ KVM_TRACE_COP0(12, 1),	"IntCtl" },		\
149 	{ KVM_TRACE_COP0(12, 2),	"SRSCtl" },		\
150 	{ KVM_TRACE_COP0(13, 0),	"Cause" },		\
151 	{ KVM_TRACE_COP0(14, 0),	"EPC" },		\
152 	{ KVM_TRACE_COP0(15, 0),	"PRId" },		\
153 	{ KVM_TRACE_COP0(15, 1),	"EBase" },		\
154 	{ KVM_TRACE_COP0(16, 0),	"Config" },		\
155 	{ KVM_TRACE_COP0(16, 1),	"Config1" },		\
156 	{ KVM_TRACE_COP0(16, 2),	"Config2" },		\
157 	{ KVM_TRACE_COP0(16, 3),	"Config3" },		\
158 	{ KVM_TRACE_COP0(16, 4),	"Config4" },		\
159 	{ KVM_TRACE_COP0(16, 5),	"Config5" },		\
160 	{ KVM_TRACE_COP0(16, 7),	"Config7" },		\
161 	{ KVM_TRACE_COP0(26, 0),	"ECC" },		\
162 	{ KVM_TRACE_COP0(30, 0),	"ErrorEPC" },		\
163 	{ KVM_TRACE_COP0(31, 2),	"KScratch1" },		\
164 	{ KVM_TRACE_COP0(31, 3),	"KScratch2" },		\
165 	{ KVM_TRACE_COP0(31, 4),	"KScratch3" },		\
166 	{ KVM_TRACE_COP0(31, 5),	"KScratch4" },		\
167 	{ KVM_TRACE_COP0(31, 6),	"KScratch5" },		\
168 	{ KVM_TRACE_COP0(31, 7),	"KScratch6" },		\
169 	{ KVM_TRACE_HWR( 0, 0),		"CPUNum" },		\
170 	{ KVM_TRACE_HWR( 1, 0),		"SYNCI_Step" },		\
171 	{ KVM_TRACE_HWR( 2, 0),		"CC" },			\
172 	{ KVM_TRACE_HWR( 3, 0),		"CCRes" },		\
173 	{ KVM_TRACE_HWR(29, 0),		"ULR" }
174 
175 TRACE_EVENT(kvm_hwr,
176 	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int op, unsigned int reg,
177 		     unsigned long val),
178 	    TP_ARGS(vcpu, op, reg, val),
179 	    TP_STRUCT__entry(
180 			__field(unsigned long, val)
181 			__field(u16, reg)
182 			__field(u8, op)
183 	    ),
184 
185 	    TP_fast_assign(
186 			__entry->val = val;
187 			__entry->reg = reg;
188 			__entry->op = op;
189 	    ),
190 
191 	    TP_printk("%s %s (%s:%u:%u) 0x%08lx",
192 		      __print_symbolic(__entry->op,
193 				       kvm_trace_symbol_hwr_ops),
194 		      __print_symbolic(__entry->reg,
195 				       kvm_trace_symbol_hwr_regs),
196 		      __print_symbolic(__entry->reg >> 8,
197 				       kvm_trace_symbol_hwr_cop),
198 		      (__entry->reg >> 3) & 0x1f,
199 		      __entry->reg & 0x7,
200 		      __entry->val)
201 );
202 
203 #define KVM_TRACE_AUX_RESTORE		0
204 #define KVM_TRACE_AUX_SAVE		1
205 #define KVM_TRACE_AUX_ENABLE		2
206 #define KVM_TRACE_AUX_DISABLE		3
207 #define KVM_TRACE_AUX_DISCARD		4
208 
209 #define KVM_TRACE_AUX_FPU		1
210 #define KVM_TRACE_AUX_MSA		2
211 #define KVM_TRACE_AUX_FPU_MSA		3
212 
213 #define kvm_trace_symbol_aux_op		\
214 	{ KVM_TRACE_AUX_RESTORE, "restore" },	\
215 	{ KVM_TRACE_AUX_SAVE,    "save" },	\
216 	{ KVM_TRACE_AUX_ENABLE,  "enable" },	\
217 	{ KVM_TRACE_AUX_DISABLE, "disable" },	\
218 	{ KVM_TRACE_AUX_DISCARD, "discard" }
219 
220 #define kvm_trace_symbol_aux_state		\
221 	{ KVM_TRACE_AUX_FPU,     "FPU" },	\
222 	{ KVM_TRACE_AUX_MSA,     "MSA" },	\
223 	{ KVM_TRACE_AUX_FPU_MSA, "FPU & MSA" }
224 
225 TRACE_EVENT(kvm_aux,
226 	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int op,
227 		     unsigned int state),
228 	    TP_ARGS(vcpu, op, state),
229 	    TP_STRUCT__entry(
230 			__field(unsigned long, pc)
231 			__field(u8, op)
232 			__field(u8, state)
233 	    ),
234 
235 	    TP_fast_assign(
236 			__entry->pc = vcpu->arch.pc;
237 			__entry->op = op;
238 			__entry->state = state;
239 	    ),
240 
241 	    TP_printk("%s %s PC: 0x%08lx",
242 		      __print_symbolic(__entry->op,
243 				       kvm_trace_symbol_aux_op),
244 		      __print_symbolic(__entry->state,
245 				       kvm_trace_symbol_aux_state),
246 		      __entry->pc)
247 );
248 
249 TRACE_EVENT(kvm_asid_change,
250 	    TP_PROTO(struct kvm_vcpu *vcpu, unsigned int old_asid,
251 		     unsigned int new_asid),
252 	    TP_ARGS(vcpu, old_asid, new_asid),
253 	    TP_STRUCT__entry(
254 			__field(unsigned long, pc)
255 			__field(u8, old_asid)
256 			__field(u8, new_asid)
257 	    ),
258 
259 	    TP_fast_assign(
260 			__entry->pc = vcpu->arch.pc;
261 			__entry->old_asid = old_asid;
262 			__entry->new_asid = new_asid;
263 	    ),
264 
265 	    TP_printk("PC: 0x%08lx old: 0x%02x new: 0x%02x",
266 		      __entry->pc,
267 		      __entry->old_asid,
268 		      __entry->new_asid)
269 );
270 
271 #endif /* _TRACE_KVM_H */
272 
273 /* This part must be outside protection */
274 #include <trace/define_trace.h>
275