xref: /openbmc/linux/include/trace/events/xen.h (revision a5d2bb06)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM xen
4 
5 #if !defined(_TRACE_XEN_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_XEN_H
7 
8 #include <linux/tracepoint.h>
9 #include <asm/xen/hypervisor.h>
10 #include <asm/xen/trace_types.h>
11 
12 struct multicall_entry;
13 
14 /* Multicalls */
15 DECLARE_EVENT_CLASS(xen_mc__batch,
16 	    TP_PROTO(enum xen_lazy_mode mode),
17 	    TP_ARGS(mode),
18 	    TP_STRUCT__entry(
19 		    __field(enum xen_lazy_mode, mode)
20 		    ),
21 	    TP_fast_assign(__entry->mode = mode),
22 	    TP_printk("start batch LAZY_%s",
23 		      (__entry->mode == XEN_LAZY_MMU) ? "MMU" :
24 		      (__entry->mode == XEN_LAZY_CPU) ? "CPU" : "NONE")
25 	);
26 #define DEFINE_XEN_MC_BATCH(name)			\
27 	DEFINE_EVENT(xen_mc__batch, name,		\
28 		TP_PROTO(enum xen_lazy_mode mode),	\
29 		     TP_ARGS(mode))
30 
31 DEFINE_XEN_MC_BATCH(xen_mc_batch);
32 DEFINE_XEN_MC_BATCH(xen_mc_issue);
33 
34 TRACE_DEFINE_SIZEOF(ulong);
35 
36 TRACE_EVENT(xen_mc_entry,
37 	    TP_PROTO(struct multicall_entry *mc, unsigned nargs),
38 	    TP_ARGS(mc, nargs),
39 	    TP_STRUCT__entry(
40 		    __field(unsigned int, op)
41 		    __field(unsigned int, nargs)
42 		    __array(unsigned long, args, 6)
43 		    ),
44 	    TP_fast_assign(__entry->op = mc->op;
45 			   __entry->nargs = nargs;
46 			   memcpy(__entry->args, mc->args, sizeof(ulong) * nargs);
47 			   memset(__entry->args + nargs, 0, sizeof(ulong) * (6 - nargs));
48 		    ),
49 	    TP_printk("op %u%s args [%lx, %lx, %lx, %lx, %lx, %lx]",
50 		      __entry->op, xen_hypercall_name(__entry->op),
51 		      __entry->args[0], __entry->args[1], __entry->args[2],
52 		      __entry->args[3], __entry->args[4], __entry->args[5])
53 	);
54 
55 TRACE_EVENT(xen_mc_entry_alloc,
56 	    TP_PROTO(size_t args),
57 	    TP_ARGS(args),
58 	    TP_STRUCT__entry(
59 		    __field(size_t, args)
60 		    ),
61 	    TP_fast_assign(__entry->args = args),
62 	    TP_printk("alloc entry %zu arg bytes", __entry->args)
63 	);
64 
65 TRACE_EVENT(xen_mc_callback,
66 	    TP_PROTO(xen_mc_callback_fn_t fn, void *data),
67 	    TP_ARGS(fn, data),
68 	    TP_STRUCT__entry(
69 		    /*
70 		     * Use field_struct to avoid is_signed_type()
71 		     * comparison of a function pointer.
72 		     */
73 		    __field_struct(xen_mc_callback_fn_t, fn)
74 		    __field(void *, data)
75 		    ),
76 	    TP_fast_assign(
77 		    __entry->fn = fn;
78 		    __entry->data = data;
79 		    ),
80 	    TP_printk("callback %ps, data %p",
81 		      __entry->fn, __entry->data)
82 	);
83 
84 TRACE_EVENT(xen_mc_flush_reason,
85 	    TP_PROTO(enum xen_mc_flush_reason reason),
86 	    TP_ARGS(reason),
87 	    TP_STRUCT__entry(
88 		    __field(enum xen_mc_flush_reason, reason)
89 		    ),
90 	    TP_fast_assign(__entry->reason = reason),
91 	    TP_printk("flush reason %s",
92 		      (__entry->reason == XEN_MC_FL_NONE) ? "NONE" :
93 		      (__entry->reason == XEN_MC_FL_BATCH) ? "BATCH" :
94 		      (__entry->reason == XEN_MC_FL_ARGS) ? "ARGS" :
95 		      (__entry->reason == XEN_MC_FL_CALLBACK) ? "CALLBACK" : "??")
96 	);
97 
98 TRACE_EVENT(xen_mc_flush,
99 	    TP_PROTO(unsigned mcidx, unsigned argidx, unsigned cbidx),
100 	    TP_ARGS(mcidx, argidx, cbidx),
101 	    TP_STRUCT__entry(
102 		    __field(unsigned, mcidx)
103 		    __field(unsigned, argidx)
104 		    __field(unsigned, cbidx)
105 		    ),
106 	    TP_fast_assign(__entry->mcidx = mcidx;
107 			   __entry->argidx = argidx;
108 			   __entry->cbidx = cbidx),
109 	    TP_printk("flushing %u hypercalls, %u arg bytes, %u callbacks",
110 		      __entry->mcidx, __entry->argidx, __entry->cbidx)
111 	);
112 
113 TRACE_EVENT(xen_mc_extend_args,
114 	    TP_PROTO(unsigned long op, size_t args, enum xen_mc_extend_args res),
115 	    TP_ARGS(op, args, res),
116 	    TP_STRUCT__entry(
117 		    __field(unsigned int, op)
118 		    __field(size_t, args)
119 		    __field(enum xen_mc_extend_args, res)
120 		    ),
121 	    TP_fast_assign(__entry->op = op;
122 			   __entry->args = args;
123 			   __entry->res = res),
124 	    TP_printk("extending op %u%s by %zu bytes res %s",
125 		      __entry->op, xen_hypercall_name(__entry->op),
126 		      __entry->args,
127 		      __entry->res == XEN_MC_XE_OK ? "OK" :
128 		      __entry->res == XEN_MC_XE_BAD_OP ? "BAD_OP" :
129 		      __entry->res == XEN_MC_XE_NO_SPACE ? "NO_SPACE" : "???")
130 	);
131 
132 TRACE_DEFINE_SIZEOF(pteval_t);
133 /* mmu */
134 DECLARE_EVENT_CLASS(xen_mmu__set_pte,
135 	    TP_PROTO(pte_t *ptep, pte_t pteval),
136 	    TP_ARGS(ptep, pteval),
137 	    TP_STRUCT__entry(
138 		    __field(pte_t *, ptep)
139 		    __field(pteval_t, pteval)
140 		    ),
141 	    TP_fast_assign(__entry->ptep = ptep;
142 			   __entry->pteval = pteval.pte),
143 	    TP_printk("ptep %p pteval %0*llx (raw %0*llx)",
144 		      __entry->ptep,
145 		      (int)sizeof(pteval_t) * 2, (unsigned long long)pte_val(native_make_pte(__entry->pteval)),
146 		      (int)sizeof(pteval_t) * 2, (unsigned long long)__entry->pteval)
147 	);
148 
149 #define DEFINE_XEN_MMU_SET_PTE(name)				\
150 	DEFINE_EVENT(xen_mmu__set_pte, name,			\
151 		     TP_PROTO(pte_t *ptep, pte_t pteval),	\
152 		     TP_ARGS(ptep, pteval))
153 
154 DEFINE_XEN_MMU_SET_PTE(xen_mmu_set_pte);
155 
156 TRACE_DEFINE_SIZEOF(pmdval_t);
157 
158 TRACE_EVENT(xen_mmu_set_pmd,
159 	    TP_PROTO(pmd_t *pmdp, pmd_t pmdval),
160 	    TP_ARGS(pmdp, pmdval),
161 	    TP_STRUCT__entry(
162 		    __field(pmd_t *, pmdp)
163 		    __field(pmdval_t, pmdval)
164 		    ),
165 	    TP_fast_assign(__entry->pmdp = pmdp;
166 			   __entry->pmdval = pmdval.pmd),
167 	    TP_printk("pmdp %p pmdval %0*llx (raw %0*llx)",
168 		      __entry->pmdp,
169 		      (int)sizeof(pmdval_t) * 2, (unsigned long long)pmd_val(native_make_pmd(__entry->pmdval)),
170 		      (int)sizeof(pmdval_t) * 2, (unsigned long long)__entry->pmdval)
171 	);
172 
173 #ifdef CONFIG_X86_PAE
174 DEFINE_XEN_MMU_SET_PTE(xen_mmu_set_pte_atomic);
175 
176 TRACE_EVENT(xen_mmu_pte_clear,
177 	    TP_PROTO(struct mm_struct *mm, unsigned long addr, pte_t *ptep),
178 	    TP_ARGS(mm, addr, ptep),
179 	    TP_STRUCT__entry(
180 		    __field(struct mm_struct *, mm)
181 		    __field(unsigned long, addr)
182 		    __field(pte_t *, ptep)
183 		    ),
184 	    TP_fast_assign(__entry->mm = mm;
185 			   __entry->addr = addr;
186 			   __entry->ptep = ptep),
187 	    TP_printk("mm %p addr %lx ptep %p",
188 		      __entry->mm, __entry->addr, __entry->ptep)
189 	);
190 
191 TRACE_EVENT(xen_mmu_pmd_clear,
192 	    TP_PROTO(pmd_t *pmdp),
193 	    TP_ARGS(pmdp),
194 	    TP_STRUCT__entry(
195 		    __field(pmd_t *, pmdp)
196 		    ),
197 	    TP_fast_assign(__entry->pmdp = pmdp),
198 	    TP_printk("pmdp %p", __entry->pmdp)
199 	);
200 #endif
201 
202 #if CONFIG_PGTABLE_LEVELS >= 4
203 
204 TRACE_DEFINE_SIZEOF(pudval_t);
205 
206 TRACE_EVENT(xen_mmu_set_pud,
207 	    TP_PROTO(pud_t *pudp, pud_t pudval),
208 	    TP_ARGS(pudp, pudval),
209 	    TP_STRUCT__entry(
210 		    __field(pud_t *, pudp)
211 		    __field(pudval_t, pudval)
212 		    ),
213 	    TP_fast_assign(__entry->pudp = pudp;
214 			   __entry->pudval = native_pud_val(pudval)),
215 	    TP_printk("pudp %p pudval %0*llx (raw %0*llx)",
216 		      __entry->pudp,
217 		      (int)sizeof(pudval_t) * 2, (unsigned long long)pud_val(native_make_pud(__entry->pudval)),
218 		      (int)sizeof(pudval_t) * 2, (unsigned long long)__entry->pudval)
219 	);
220 
221 TRACE_DEFINE_SIZEOF(p4dval_t);
222 
223 TRACE_EVENT(xen_mmu_set_p4d,
224 	    TP_PROTO(p4d_t *p4dp, p4d_t *user_p4dp, p4d_t p4dval),
225 	    TP_ARGS(p4dp, user_p4dp, p4dval),
226 	    TP_STRUCT__entry(
227 		    __field(p4d_t *, p4dp)
228 		    __field(p4d_t *, user_p4dp)
229 		    __field(p4dval_t, p4dval)
230 		    ),
231 	    TP_fast_assign(__entry->p4dp = p4dp;
232 			   __entry->user_p4dp = user_p4dp;
233 			   __entry->p4dval = p4d_val(p4dval)),
234 	    TP_printk("p4dp %p user_p4dp %p p4dval %0*llx (raw %0*llx)",
235 		      __entry->p4dp, __entry->user_p4dp,
236 		      (int)sizeof(p4dval_t) * 2, (unsigned long long)pgd_val(native_make_pgd(__entry->p4dval)),
237 		      (int)sizeof(p4dval_t) * 2, (unsigned long long)__entry->p4dval)
238 	);
239 #else
240 
241 TRACE_EVENT(xen_mmu_set_pud,
242 	    TP_PROTO(pud_t *pudp, pud_t pudval),
243 	    TP_ARGS(pudp, pudval),
244 	    TP_STRUCT__entry(
245 		    __field(pud_t *, pudp)
246 		    __field(pudval_t, pudval)
247 		    ),
248 	    TP_fast_assign(__entry->pudp = pudp;
249 			   __entry->pudval = native_pud_val(pudval)),
250 	    TP_printk("pudp %p pudval %0*llx (raw %0*llx)",
251 		      __entry->pudp,
252 		      (int)sizeof(pudval_t) * 2, (unsigned long long)pgd_val(native_make_pgd(__entry->pudval)),
253 		      (int)sizeof(pudval_t) * 2, (unsigned long long)__entry->pudval)
254 	);
255 
256 #endif
257 
258 DECLARE_EVENT_CLASS(xen_mmu_ptep_modify_prot,
259 	    TP_PROTO(struct mm_struct *mm, unsigned long addr,
260 		     pte_t *ptep, pte_t pteval),
261 	    TP_ARGS(mm, addr, ptep, pteval),
262 	    TP_STRUCT__entry(
263 		    __field(struct mm_struct *, mm)
264 		    __field(unsigned long, addr)
265 		    __field(pte_t *, ptep)
266 		    __field(pteval_t, pteval)
267 		    ),
268 	    TP_fast_assign(__entry->mm = mm;
269 			   __entry->addr = addr;
270 			   __entry->ptep = ptep;
271 			   __entry->pteval = pteval.pte),
272 	    TP_printk("mm %p addr %lx ptep %p pteval %0*llx (raw %0*llx)",
273 		      __entry->mm, __entry->addr, __entry->ptep,
274 		      (int)sizeof(pteval_t) * 2, (unsigned long long)pte_val(native_make_pte(__entry->pteval)),
275 		      (int)sizeof(pteval_t) * 2, (unsigned long long)__entry->pteval)
276 	);
277 #define DEFINE_XEN_MMU_PTEP_MODIFY_PROT(name)				\
278 	DEFINE_EVENT(xen_mmu_ptep_modify_prot, name,			\
279 		     TP_PROTO(struct mm_struct *mm, unsigned long addr,	\
280 			      pte_t *ptep, pte_t pteval),		\
281 		     TP_ARGS(mm, addr, ptep, pteval))
282 
283 DEFINE_XEN_MMU_PTEP_MODIFY_PROT(xen_mmu_ptep_modify_prot_start);
284 DEFINE_XEN_MMU_PTEP_MODIFY_PROT(xen_mmu_ptep_modify_prot_commit);
285 
286 TRACE_EVENT(xen_mmu_alloc_ptpage,
287 	    TP_PROTO(struct mm_struct *mm, unsigned long pfn, unsigned level, bool pinned),
288 	    TP_ARGS(mm, pfn, level, pinned),
289 	    TP_STRUCT__entry(
290 		    __field(struct mm_struct *, mm)
291 		    __field(unsigned long, pfn)
292 		    __field(unsigned, level)
293 		    __field(bool, pinned)
294 		    ),
295 	    TP_fast_assign(__entry->mm = mm;
296 			   __entry->pfn = pfn;
297 			   __entry->level = level;
298 			   __entry->pinned = pinned),
299 	    TP_printk("mm %p  pfn %lx  level %d  %spinned",
300 		      __entry->mm, __entry->pfn, __entry->level,
301 		      __entry->pinned ? "" : "un")
302 	);
303 
304 TRACE_EVENT(xen_mmu_release_ptpage,
305 	    TP_PROTO(unsigned long pfn, unsigned level, bool pinned),
306 	    TP_ARGS(pfn, level, pinned),
307 	    TP_STRUCT__entry(
308 		    __field(unsigned long, pfn)
309 		    __field(unsigned, level)
310 		    __field(bool, pinned)
311 		    ),
312 	    TP_fast_assign(__entry->pfn = pfn;
313 			   __entry->level = level;
314 			   __entry->pinned = pinned),
315 	    TP_printk("pfn %lx  level %d  %spinned",
316 		      __entry->pfn, __entry->level,
317 		      __entry->pinned ? "" : "un")
318 	);
319 
320 DECLARE_EVENT_CLASS(xen_mmu_pgd,
321 	    TP_PROTO(struct mm_struct *mm, pgd_t *pgd),
322 	    TP_ARGS(mm, pgd),
323 	    TP_STRUCT__entry(
324 		    __field(struct mm_struct *, mm)
325 		    __field(pgd_t *, pgd)
326 		    ),
327 	    TP_fast_assign(__entry->mm = mm;
328 			   __entry->pgd = pgd),
329 	    TP_printk("mm %p pgd %p", __entry->mm, __entry->pgd)
330 	);
331 #define DEFINE_XEN_MMU_PGD_EVENT(name)				\
332 	DEFINE_EVENT(xen_mmu_pgd, name,				\
333 		TP_PROTO(struct mm_struct *mm, pgd_t *pgd),	\
334 		     TP_ARGS(mm, pgd))
335 
336 DEFINE_XEN_MMU_PGD_EVENT(xen_mmu_pgd_pin);
337 DEFINE_XEN_MMU_PGD_EVENT(xen_mmu_pgd_unpin);
338 
339 TRACE_EVENT(xen_mmu_flush_tlb_one_user,
340 	    TP_PROTO(unsigned long addr),
341 	    TP_ARGS(addr),
342 	    TP_STRUCT__entry(
343 		    __field(unsigned long, addr)
344 		    ),
345 	    TP_fast_assign(__entry->addr = addr),
346 	    TP_printk("addr %lx", __entry->addr)
347 	);
348 
349 TRACE_EVENT(xen_mmu_flush_tlb_multi,
350 	    TP_PROTO(const struct cpumask *cpus, struct mm_struct *mm,
351 		     unsigned long addr, unsigned long end),
352 	    TP_ARGS(cpus, mm, addr, end),
353 	    TP_STRUCT__entry(
354 		    __field(unsigned, ncpus)
355 		    __field(struct mm_struct *, mm)
356 		    __field(unsigned long, addr)
357 		    __field(unsigned long, end)
358 		    ),
359 	    TP_fast_assign(__entry->ncpus = cpumask_weight(cpus);
360 			   __entry->mm = mm;
361 			   __entry->addr = addr,
362 			   __entry->end = end),
363 	    TP_printk("ncpus %d mm %p addr %lx, end %lx",
364 		      __entry->ncpus, __entry->mm, __entry->addr, __entry->end)
365 	);
366 
367 TRACE_EVENT(xen_mmu_write_cr3,
368 	    TP_PROTO(bool kernel, unsigned long cr3),
369 	    TP_ARGS(kernel, cr3),
370 	    TP_STRUCT__entry(
371 		    __field(bool, kernel)
372 		    __field(unsigned long, cr3)
373 		    ),
374 	    TP_fast_assign(__entry->kernel = kernel;
375 			   __entry->cr3 = cr3),
376 	    TP_printk("%s cr3 %lx",
377 		      __entry->kernel ? "kernel" : "user", __entry->cr3)
378 	);
379 
380 
381 /* CPU */
382 TRACE_EVENT(xen_cpu_write_ldt_entry,
383 	    TP_PROTO(struct desc_struct *dt, int entrynum, u64 desc),
384 	    TP_ARGS(dt, entrynum, desc),
385 	    TP_STRUCT__entry(
386 		    __field(struct desc_struct *, dt)
387 		    __field(int, entrynum)
388 		    __field(u64, desc)
389 		    ),
390 	    TP_fast_assign(__entry->dt = dt;
391 			   __entry->entrynum = entrynum;
392 			   __entry->desc = desc;
393 		    ),
394 	    TP_printk("dt %p  entrynum %d  entry %016llx",
395 		      __entry->dt, __entry->entrynum,
396 		      (unsigned long long)__entry->desc)
397 	);
398 
399 TRACE_EVENT(xen_cpu_write_idt_entry,
400 	    TP_PROTO(gate_desc *dt, int entrynum, const gate_desc *ent),
401 	    TP_ARGS(dt, entrynum, ent),
402 	    TP_STRUCT__entry(
403 		    __field(gate_desc *, dt)
404 		    __field(int, entrynum)
405 		    ),
406 	    TP_fast_assign(__entry->dt = dt;
407 			   __entry->entrynum = entrynum;
408 		    ),
409 	    TP_printk("dt %p  entrynum %d",
410 		      __entry->dt, __entry->entrynum)
411 	);
412 
413 TRACE_EVENT(xen_cpu_load_idt,
414 	    TP_PROTO(const struct desc_ptr *desc),
415 	    TP_ARGS(desc),
416 	    TP_STRUCT__entry(
417 		    __field(unsigned long, addr)
418 		    ),
419 	    TP_fast_assign(__entry->addr = desc->address),
420 	    TP_printk("addr %lx", __entry->addr)
421 	);
422 
423 TRACE_EVENT(xen_cpu_write_gdt_entry,
424 	    TP_PROTO(struct desc_struct *dt, int entrynum, const void *desc, int type),
425 	    TP_ARGS(dt, entrynum, desc, type),
426 	    TP_STRUCT__entry(
427 		    __field(u64, desc)
428 		    __field(struct desc_struct *, dt)
429 		    __field(int, entrynum)
430 		    __field(int, type)
431 		    ),
432 	    TP_fast_assign(__entry->dt = dt;
433 			   __entry->entrynum = entrynum;
434 			   __entry->desc = *(u64 *)desc;
435 			   __entry->type = type;
436 		    ),
437 	    TP_printk("dt %p  entrynum %d  type %d  desc %016llx",
438 		      __entry->dt, __entry->entrynum, __entry->type,
439 		      (unsigned long long)__entry->desc)
440 	);
441 
442 TRACE_EVENT(xen_cpu_set_ldt,
443 	    TP_PROTO(const void *addr, unsigned entries),
444 	    TP_ARGS(addr, entries),
445 	    TP_STRUCT__entry(
446 		    __field(const void *, addr)
447 		    __field(unsigned, entries)
448 		    ),
449 	    TP_fast_assign(__entry->addr = addr;
450 			   __entry->entries = entries),
451 	    TP_printk("addr %p  entries %u",
452 		      __entry->addr, __entry->entries)
453 	);
454 
455 
456 #endif /*  _TRACE_XEN_H */
457 
458 /* This part must be outside protection */
459 #include <trace/define_trace.h>
460