xref: /openbmc/linux/arch/s390/kvm/trace.h (revision b34e08d5)
1 #if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ)
2 #define _TRACE_KVM_H
3 
4 #include <linux/tracepoint.h>
5 #include <asm/sigp.h>
6 #include <asm/debug.h>
7 #include <asm/dis.h>
8 
9 #undef TRACE_SYSTEM
10 #define TRACE_SYSTEM kvm
11 #define TRACE_INCLUDE_PATH .
12 #undef TRACE_INCLUDE_FILE
13 #define TRACE_INCLUDE_FILE trace
14 
15 /*
16  * Helpers for vcpu-specific tracepoints containing the same information
17  * as s390dbf VCPU_EVENTs.
18  */
19 #define VCPU_PROTO_COMMON struct kvm_vcpu *vcpu
20 #define VCPU_ARGS_COMMON vcpu
21 #define VCPU_FIELD_COMMON __field(int, id)			\
22 	__field(unsigned long, pswmask)				\
23 	__field(unsigned long, pswaddr)
24 #define VCPU_ASSIGN_COMMON do {						\
25 	__entry->id = vcpu->vcpu_id;					\
26 	__entry->pswmask = vcpu->arch.sie_block->gpsw.mask;		\
27 	__entry->pswaddr = vcpu->arch.sie_block->gpsw.addr;		\
28 	} while (0);
29 #define VCPU_TP_PRINTK(p_str, p_args...)				\
30 	TP_printk("%02d[%016lx-%016lx]: " p_str, __entry->id,		\
31 		  __entry->pswmask, __entry->pswaddr, p_args)
32 
33 TRACE_EVENT(kvm_s390_major_guest_pfault,
34 	    TP_PROTO(VCPU_PROTO_COMMON),
35 	    TP_ARGS(VCPU_ARGS_COMMON),
36 
37 	    TP_STRUCT__entry(
38 		    VCPU_FIELD_COMMON
39 		    ),
40 
41 	    TP_fast_assign(
42 		    VCPU_ASSIGN_COMMON
43 		    ),
44 	    VCPU_TP_PRINTK("%s", "major fault, maybe applicable for pfault")
45 	);
46 
47 TRACE_EVENT(kvm_s390_pfault_init,
48 	    TP_PROTO(VCPU_PROTO_COMMON, long pfault_token),
49 	    TP_ARGS(VCPU_ARGS_COMMON, pfault_token),
50 
51 	    TP_STRUCT__entry(
52 		    VCPU_FIELD_COMMON
53 		    __field(long, pfault_token)
54 		    ),
55 
56 	    TP_fast_assign(
57 		    VCPU_ASSIGN_COMMON
58 		    __entry->pfault_token = pfault_token;
59 		    ),
60 	    VCPU_TP_PRINTK("init pfault token %ld", __entry->pfault_token)
61 	);
62 
63 TRACE_EVENT(kvm_s390_pfault_done,
64 	    TP_PROTO(VCPU_PROTO_COMMON, long pfault_token),
65 	    TP_ARGS(VCPU_ARGS_COMMON, pfault_token),
66 
67 	    TP_STRUCT__entry(
68 		    VCPU_FIELD_COMMON
69 		    __field(long, pfault_token)
70 		    ),
71 
72 	    TP_fast_assign(
73 		    VCPU_ASSIGN_COMMON
74 		    __entry->pfault_token = pfault_token;
75 		    ),
76 	    VCPU_TP_PRINTK("done pfault token %ld", __entry->pfault_token)
77 	);
78 
79 /*
80  * Tracepoints for SIE entry and exit.
81  */
82 TRACE_EVENT(kvm_s390_sie_enter,
83 	    TP_PROTO(VCPU_PROTO_COMMON, int cpuflags),
84 	    TP_ARGS(VCPU_ARGS_COMMON, cpuflags),
85 
86 	    TP_STRUCT__entry(
87 		    VCPU_FIELD_COMMON
88 		    __field(int, cpuflags)
89 		    ),
90 
91 	    TP_fast_assign(
92 		    VCPU_ASSIGN_COMMON
93 		    __entry->cpuflags = cpuflags;
94 		    ),
95 
96 	    VCPU_TP_PRINTK("entering sie flags %x", __entry->cpuflags)
97 	);
98 
99 TRACE_EVENT(kvm_s390_sie_fault,
100 	    TP_PROTO(VCPU_PROTO_COMMON),
101 	    TP_ARGS(VCPU_ARGS_COMMON),
102 
103 	    TP_STRUCT__entry(
104 		    VCPU_FIELD_COMMON
105 		    ),
106 
107 	    TP_fast_assign(
108 		    VCPU_ASSIGN_COMMON
109 		    ),
110 
111 	    VCPU_TP_PRINTK("%s", "fault in sie instruction")
112 	);
113 
114 #define sie_intercept_code				\
115 	{0x04, "Instruction"},				\
116 	{0x08, "Program interruption"},			\
117 	{0x0C, "Instruction and program interruption"},	\
118 	{0x10, "External request"},			\
119 	{0x14, "External interruption"},		\
120 	{0x18, "I/O request"},				\
121 	{0x1C, "Wait state"},				\
122 	{0x20, "Validity"},				\
123 	{0x28, "Stop request"}
124 
125 TRACE_EVENT(kvm_s390_sie_exit,
126 	    TP_PROTO(VCPU_PROTO_COMMON, u8 icptcode),
127 	    TP_ARGS(VCPU_ARGS_COMMON, icptcode),
128 
129 	    TP_STRUCT__entry(
130 		    VCPU_FIELD_COMMON
131 		    __field(u8, icptcode)
132 		    ),
133 
134 	    TP_fast_assign(
135 		    VCPU_ASSIGN_COMMON
136 		    __entry->icptcode = icptcode;
137 		    ),
138 
139 	    VCPU_TP_PRINTK("exit sie icptcode %d (%s)", __entry->icptcode,
140 			   __print_symbolic(__entry->icptcode,
141 					    sie_intercept_code))
142 	);
143 
144 /*
145  * Trace point for intercepted instructions.
146  */
147 TRACE_EVENT(kvm_s390_intercept_instruction,
148 	    TP_PROTO(VCPU_PROTO_COMMON, __u16 ipa, __u32 ipb),
149 	    TP_ARGS(VCPU_ARGS_COMMON, ipa, ipb),
150 
151 	    TP_STRUCT__entry(
152 		    VCPU_FIELD_COMMON
153 		    __field(__u64, instruction)
154 		    __field(char, insn[8])
155 		    ),
156 
157 	    TP_fast_assign(
158 		    VCPU_ASSIGN_COMMON
159 		    __entry->instruction = ((__u64)ipa << 48) |
160 		    ((__u64)ipb << 16);
161 		    ),
162 
163 	    VCPU_TP_PRINTK("intercepted instruction %016llx (%s)",
164 			   __entry->instruction,
165 			   insn_to_mnemonic((unsigned char *)
166 					    &__entry->instruction,
167 					 __entry->insn, sizeof(__entry->insn)) ?
168 			   "unknown" : __entry->insn)
169 	);
170 
171 /*
172  * Trace point for intercepted program interruptions.
173  */
174 TRACE_EVENT(kvm_s390_intercept_prog,
175 	    TP_PROTO(VCPU_PROTO_COMMON, __u16 code),
176 	    TP_ARGS(VCPU_ARGS_COMMON, code),
177 
178 	    TP_STRUCT__entry(
179 		    VCPU_FIELD_COMMON
180 		    __field(__u16, code)
181 		    ),
182 
183 	    TP_fast_assign(
184 		    VCPU_ASSIGN_COMMON
185 		    __entry->code = code;
186 		    ),
187 
188 	    VCPU_TP_PRINTK("intercepted program interruption %04x",
189 			   __entry->code)
190 	);
191 
192 /*
193  * Trace point for validity intercepts.
194  */
195 TRACE_EVENT(kvm_s390_intercept_validity,
196 	    TP_PROTO(VCPU_PROTO_COMMON, __u16 viwhy),
197 	    TP_ARGS(VCPU_ARGS_COMMON, viwhy),
198 
199 	    TP_STRUCT__entry(
200 		    VCPU_FIELD_COMMON
201 		    __field(__u16, viwhy)
202 		    ),
203 
204 	    TP_fast_assign(
205 		    VCPU_ASSIGN_COMMON
206 		    __entry->viwhy = viwhy;
207 		    ),
208 
209 	    VCPU_TP_PRINTK("got validity intercept %04x", __entry->viwhy)
210 	);
211 
212 /*
213  * Trace points for instructions that are of special interest.
214  */
215 
216 #define sigp_order_codes					\
217 	{SIGP_SENSE, "sense"},					\
218 	{SIGP_EXTERNAL_CALL, "external call"},			\
219 	{SIGP_EMERGENCY_SIGNAL, "emergency signal"},		\
220 	{SIGP_STOP, "stop"},					\
221 	{SIGP_STOP_AND_STORE_STATUS, "stop and store status"},	\
222 	{SIGP_SET_ARCHITECTURE, "set architecture"},		\
223 	{SIGP_SET_PREFIX, "set prefix"},			\
224 	{SIGP_STORE_STATUS_AT_ADDRESS, "store status at addr"},	\
225 	{SIGP_SENSE_RUNNING, "sense running"},			\
226 	{SIGP_RESTART, "restart"}
227 
228 TRACE_EVENT(kvm_s390_handle_sigp,
229 	    TP_PROTO(VCPU_PROTO_COMMON, __u8 order_code, __u16 cpu_addr, \
230 		     __u32 parameter),
231 	    TP_ARGS(VCPU_ARGS_COMMON, order_code, cpu_addr, parameter),
232 
233 	    TP_STRUCT__entry(
234 		    VCPU_FIELD_COMMON
235 		    __field(__u8, order_code)
236 		    __field(__u16, cpu_addr)
237 		    __field(__u32, parameter)
238 		    ),
239 
240 	    TP_fast_assign(
241 		    VCPU_ASSIGN_COMMON
242 		    __entry->order_code = order_code;
243 		    __entry->cpu_addr = cpu_addr;
244 		    __entry->parameter = parameter;
245 		    ),
246 
247 	    VCPU_TP_PRINTK("handle sigp order %02x (%s), cpu address %04x, " \
248 			   "parameter %08x", __entry->order_code,
249 			   __print_symbolic(__entry->order_code,
250 					    sigp_order_codes),
251 			   __entry->cpu_addr, __entry->parameter)
252 	);
253 
254 #define diagnose_codes				\
255 	{0x10, "release pages"},		\
256 	{0x44, "time slice end"},		\
257 	{0x308, "ipl functions"},		\
258 	{0x500, "kvm hypercall"},		\
259 	{0x501, "kvm breakpoint"}
260 
261 TRACE_EVENT(kvm_s390_handle_diag,
262 	    TP_PROTO(VCPU_PROTO_COMMON, __u16 code),
263 	    TP_ARGS(VCPU_ARGS_COMMON, code),
264 
265 	    TP_STRUCT__entry(
266 		    VCPU_FIELD_COMMON
267 		    __field(__u16, code)
268 		    ),
269 
270 	    TP_fast_assign(
271 		    VCPU_ASSIGN_COMMON
272 		    __entry->code = code;
273 		    ),
274 
275 	    VCPU_TP_PRINTK("handle diagnose call %04x (%s)", __entry->code,
276 			   __print_symbolic(__entry->code, diagnose_codes))
277 	);
278 
279 TRACE_EVENT(kvm_s390_handle_lctl,
280 	    TP_PROTO(VCPU_PROTO_COMMON, int g, int reg1, int reg3, u64 addr),
281 	    TP_ARGS(VCPU_ARGS_COMMON, g, reg1, reg3, addr),
282 
283 	    TP_STRUCT__entry(
284 		    VCPU_FIELD_COMMON
285 		    __field(int, g)
286 		    __field(int, reg1)
287 		    __field(int, reg3)
288 		    __field(u64, addr)
289 		    ),
290 
291 	    TP_fast_assign(
292 		    VCPU_ASSIGN_COMMON
293 		    __entry->g = g;
294 		    __entry->reg1 = reg1;
295 		    __entry->reg3 = reg3;
296 		    __entry->addr = addr;
297 		    ),
298 
299 	    VCPU_TP_PRINTK("%s: loading cr %x-%x from %016llx",
300 			   __entry->g ? "lctlg" : "lctl",
301 			   __entry->reg1, __entry->reg3, __entry->addr)
302 	);
303 
304 TRACE_EVENT(kvm_s390_handle_prefix,
305 	    TP_PROTO(VCPU_PROTO_COMMON, int set, u32 address),
306 	    TP_ARGS(VCPU_ARGS_COMMON, set, address),
307 
308 	    TP_STRUCT__entry(
309 		    VCPU_FIELD_COMMON
310 		    __field(int, set)
311 		    __field(u32, address)
312 		    ),
313 
314 	    TP_fast_assign(
315 		    VCPU_ASSIGN_COMMON
316 		    __entry->set = set;
317 		    __entry->address = address;
318 		    ),
319 
320 	    VCPU_TP_PRINTK("%s prefix to %08x",
321 			   __entry->set ? "setting" : "storing",
322 			   __entry->address)
323 	);
324 
325 TRACE_EVENT(kvm_s390_handle_stap,
326 	    TP_PROTO(VCPU_PROTO_COMMON, u64 address),
327 	    TP_ARGS(VCPU_ARGS_COMMON, address),
328 
329 	    TP_STRUCT__entry(
330 		    VCPU_FIELD_COMMON
331 		    __field(u64, address)
332 		    ),
333 
334 	    TP_fast_assign(
335 		    VCPU_ASSIGN_COMMON
336 		    __entry->address = address;
337 		    ),
338 
339 	    VCPU_TP_PRINTK("storing cpu address to %016llx",
340 			   __entry->address)
341 	);
342 
343 TRACE_EVENT(kvm_s390_handle_stfl,
344 	    TP_PROTO(VCPU_PROTO_COMMON, unsigned int facility_list),
345 	    TP_ARGS(VCPU_ARGS_COMMON, facility_list),
346 
347 	    TP_STRUCT__entry(
348 		    VCPU_FIELD_COMMON
349 		    __field(unsigned int, facility_list)
350 		    ),
351 
352 	    TP_fast_assign(
353 		    VCPU_ASSIGN_COMMON
354 		    __entry->facility_list = facility_list;
355 		    ),
356 
357 	    VCPU_TP_PRINTK("store facility list value %08x",
358 			   __entry->facility_list)
359 	);
360 
361 TRACE_EVENT(kvm_s390_handle_stsi,
362 	    TP_PROTO(VCPU_PROTO_COMMON, int fc, int sel1, int sel2, u64 addr),
363 	    TP_ARGS(VCPU_ARGS_COMMON, fc, sel1, sel2, addr),
364 
365 	    TP_STRUCT__entry(
366 		    VCPU_FIELD_COMMON
367 		    __field(int, fc)
368 		    __field(int, sel1)
369 		    __field(int, sel2)
370 		    __field(u64, addr)
371 		    ),
372 
373 	    TP_fast_assign(
374 		    VCPU_ASSIGN_COMMON
375 		    __entry->fc = fc;
376 		    __entry->sel1 = sel1;
377 		    __entry->sel2 = sel2;
378 		    __entry->addr = addr;
379 		    ),
380 
381 	    VCPU_TP_PRINTK("STSI %d.%d.%d information stored to %016llx",
382 			   __entry->fc, __entry->sel1, __entry->sel2,
383 			   __entry->addr)
384 	);
385 
386 #endif /* _TRACE_KVM_H */
387 
388 /* This part must be outside protection */
389 #include <trace/define_trace.h>
390