blob: 52c8425d144b349988a16366ab69d0366bd0c065 [file] [log] [blame]
Daniel Borkmanna67edbf2017-01-25 02:28:18 +01001#undef TRACE_SYSTEM
2#define TRACE_SYSTEM bpf
3
4#if !defined(_TRACE_BPF_H) || defined(TRACE_HEADER_MULTI_READ)
5#define _TRACE_BPF_H
6
7#include <linux/filter.h>
8#include <linux/bpf.h>
9#include <linux/fs.h>
10#include <linux/tracepoint.h>
11
12#define __PROG_TYPE_MAP(FN) \
13 FN(SOCKET_FILTER) \
14 FN(KPROBE) \
15 FN(SCHED_CLS) \
16 FN(SCHED_ACT) \
17 FN(TRACEPOINT) \
18 FN(XDP) \
19 FN(PERF_EVENT) \
20 FN(CGROUP_SKB) \
21 FN(CGROUP_SOCK) \
22 FN(LWT_IN) \
23 FN(LWT_OUT) \
24 FN(LWT_XMIT)
25
26#define __MAP_TYPE_MAP(FN) \
27 FN(HASH) \
28 FN(ARRAY) \
29 FN(PROG_ARRAY) \
30 FN(PERF_EVENT_ARRAY) \
31 FN(PERCPU_HASH) \
32 FN(PERCPU_ARRAY) \
33 FN(STACK_TRACE) \
34 FN(CGROUP_ARRAY) \
35 FN(LRU_HASH) \
36 FN(LRU_PERCPU_HASH) \
37 FN(LPM_TRIE)
38
39#define __PROG_TYPE_TP_FN(x) \
40 TRACE_DEFINE_ENUM(BPF_PROG_TYPE_##x);
41#define __PROG_TYPE_SYM_FN(x) \
42 { BPF_PROG_TYPE_##x, #x },
43#define __PROG_TYPE_SYM_TAB \
44 __PROG_TYPE_MAP(__PROG_TYPE_SYM_FN) { -1, 0 }
45__PROG_TYPE_MAP(__PROG_TYPE_TP_FN)
46
47#define __MAP_TYPE_TP_FN(x) \
48 TRACE_DEFINE_ENUM(BPF_MAP_TYPE_##x);
49#define __MAP_TYPE_SYM_FN(x) \
50 { BPF_MAP_TYPE_##x, #x },
51#define __MAP_TYPE_SYM_TAB \
52 __MAP_TYPE_MAP(__MAP_TYPE_SYM_FN) { -1, 0 }
53__MAP_TYPE_MAP(__MAP_TYPE_TP_FN)
54
55DECLARE_EVENT_CLASS(bpf_prog_event,
56
57 TP_PROTO(const struct bpf_prog *prg),
58
59 TP_ARGS(prg),
60
61 TP_STRUCT__entry(
62 __array(u8, prog_tag, 8)
63 __field(u32, type)
64 ),
65
66 TP_fast_assign(
67 BUILD_BUG_ON(sizeof(__entry->prog_tag) != sizeof(prg->tag));
68 memcpy(__entry->prog_tag, prg->tag, sizeof(prg->tag));
69 __entry->type = prg->type;
70 ),
71
72 TP_printk("prog=%s type=%s",
73 __print_hex_str(__entry->prog_tag, 8),
74 __print_symbolic(__entry->type, __PROG_TYPE_SYM_TAB))
75);
76
77DEFINE_EVENT(bpf_prog_event, bpf_prog_get_type,
78
79 TP_PROTO(const struct bpf_prog *prg),
80
81 TP_ARGS(prg)
82);
83
84DEFINE_EVENT(bpf_prog_event, bpf_prog_put_rcu,
85
86 TP_PROTO(const struct bpf_prog *prg),
87
88 TP_ARGS(prg)
89);
90
91TRACE_EVENT(bpf_prog_load,
92
93 TP_PROTO(const struct bpf_prog *prg, int ufd),
94
95 TP_ARGS(prg, ufd),
96
97 TP_STRUCT__entry(
98 __array(u8, prog_tag, 8)
99 __field(u32, type)
100 __field(int, ufd)
101 ),
102
103 TP_fast_assign(
104 BUILD_BUG_ON(sizeof(__entry->prog_tag) != sizeof(prg->tag));
105 memcpy(__entry->prog_tag, prg->tag, sizeof(prg->tag));
106 __entry->type = prg->type;
107 __entry->ufd = ufd;
108 ),
109
110 TP_printk("prog=%s type=%s ufd=%d",
111 __print_hex_str(__entry->prog_tag, 8),
112 __print_symbolic(__entry->type, __PROG_TYPE_SYM_TAB),
113 __entry->ufd)
114);
115
116TRACE_EVENT(bpf_map_create,
117
118 TP_PROTO(const struct bpf_map *map, int ufd),
119
120 TP_ARGS(map, ufd),
121
122 TP_STRUCT__entry(
123 __field(u32, type)
124 __field(u32, size_key)
125 __field(u32, size_value)
126 __field(u32, max_entries)
127 __field(u32, flags)
128 __field(int, ufd)
129 ),
130
131 TP_fast_assign(
132 __entry->type = map->map_type;
133 __entry->size_key = map->key_size;
134 __entry->size_value = map->value_size;
135 __entry->max_entries = map->max_entries;
136 __entry->flags = map->map_flags;
137 __entry->ufd = ufd;
138 ),
139
140 TP_printk("map type=%s ufd=%d key=%u val=%u max=%u flags=%x",
141 __print_symbolic(__entry->type, __MAP_TYPE_SYM_TAB),
142 __entry->ufd, __entry->size_key, __entry->size_value,
143 __entry->max_entries, __entry->flags)
144);
145
146DECLARE_EVENT_CLASS(bpf_obj_prog,
147
148 TP_PROTO(const struct bpf_prog *prg, int ufd,
149 const struct filename *pname),
150
151 TP_ARGS(prg, ufd, pname),
152
153 TP_STRUCT__entry(
154 __array(u8, prog_tag, 8)
155 __field(int, ufd)
156 __string(path, pname->name)
157 ),
158
159 TP_fast_assign(
160 BUILD_BUG_ON(sizeof(__entry->prog_tag) != sizeof(prg->tag));
161 memcpy(__entry->prog_tag, prg->tag, sizeof(prg->tag));
162 __assign_str(path, pname->name);
163 __entry->ufd = ufd;
164 ),
165
166 TP_printk("prog=%s path=%s ufd=%d",
167 __print_hex_str(__entry->prog_tag, 8),
168 __get_str(path), __entry->ufd)
169);
170
171DEFINE_EVENT(bpf_obj_prog, bpf_obj_pin_prog,
172
173 TP_PROTO(const struct bpf_prog *prg, int ufd,
174 const struct filename *pname),
175
176 TP_ARGS(prg, ufd, pname)
177);
178
179DEFINE_EVENT(bpf_obj_prog, bpf_obj_get_prog,
180
181 TP_PROTO(const struct bpf_prog *prg, int ufd,
182 const struct filename *pname),
183
184 TP_ARGS(prg, ufd, pname)
185);
186
187DECLARE_EVENT_CLASS(bpf_obj_map,
188
189 TP_PROTO(const struct bpf_map *map, int ufd,
190 const struct filename *pname),
191
192 TP_ARGS(map, ufd, pname),
193
194 TP_STRUCT__entry(
195 __field(u32, type)
196 __field(int, ufd)
197 __string(path, pname->name)
198 ),
199
200 TP_fast_assign(
201 __assign_str(path, pname->name);
202 __entry->type = map->map_type;
203 __entry->ufd = ufd;
204 ),
205
206 TP_printk("map type=%s ufd=%d path=%s",
207 __print_symbolic(__entry->type, __MAP_TYPE_SYM_TAB),
208 __entry->ufd, __get_str(path))
209);
210
211DEFINE_EVENT(bpf_obj_map, bpf_obj_pin_map,
212
213 TP_PROTO(const struct bpf_map *map, int ufd,
214 const struct filename *pname),
215
216 TP_ARGS(map, ufd, pname)
217);
218
219DEFINE_EVENT(bpf_obj_map, bpf_obj_get_map,
220
221 TP_PROTO(const struct bpf_map *map, int ufd,
222 const struct filename *pname),
223
224 TP_ARGS(map, ufd, pname)
225);
226
227DECLARE_EVENT_CLASS(bpf_map_keyval,
228
229 TP_PROTO(const struct bpf_map *map, int ufd,
230 const void *key, const void *val),
231
232 TP_ARGS(map, ufd, key, val),
233
234 TP_STRUCT__entry(
235 __field(u32, type)
236 __field(u32, key_len)
237 __dynamic_array(u8, key, map->key_size)
238 __field(bool, key_trunc)
239 __field(u32, val_len)
240 __dynamic_array(u8, val, map->value_size)
241 __field(bool, val_trunc)
242 __field(int, ufd)
243 ),
244
245 TP_fast_assign(
246 memcpy(__get_dynamic_array(key), key, map->key_size);
247 memcpy(__get_dynamic_array(val), val, map->value_size);
248 __entry->type = map->map_type;
249 __entry->key_len = min(map->key_size, 16U);
250 __entry->key_trunc = map->key_size != __entry->key_len;
251 __entry->val_len = min(map->value_size, 16U);
252 __entry->val_trunc = map->value_size != __entry->val_len;
253 __entry->ufd = ufd;
254 ),
255
256 TP_printk("map type=%s ufd=%d key=[%s%s] val=[%s%s]",
257 __print_symbolic(__entry->type, __MAP_TYPE_SYM_TAB),
258 __entry->ufd,
259 __print_hex(__get_dynamic_array(key), __entry->key_len),
260 __entry->key_trunc ? " ..." : "",
261 __print_hex(__get_dynamic_array(val), __entry->val_len),
262 __entry->val_trunc ? " ..." : "")
263);
264
265DEFINE_EVENT(bpf_map_keyval, bpf_map_lookup_elem,
266
267 TP_PROTO(const struct bpf_map *map, int ufd,
268 const void *key, const void *val),
269
270 TP_ARGS(map, ufd, key, val)
271);
272
273DEFINE_EVENT(bpf_map_keyval, bpf_map_update_elem,
274
275 TP_PROTO(const struct bpf_map *map, int ufd,
276 const void *key, const void *val),
277
278 TP_ARGS(map, ufd, key, val)
279);
280
281TRACE_EVENT(bpf_map_delete_elem,
282
283 TP_PROTO(const struct bpf_map *map, int ufd,
284 const void *key),
285
286 TP_ARGS(map, ufd, key),
287
288 TP_STRUCT__entry(
289 __field(u32, type)
290 __field(u32, key_len)
291 __dynamic_array(u8, key, map->key_size)
292 __field(bool, key_trunc)
293 __field(int, ufd)
294 ),
295
296 TP_fast_assign(
297 memcpy(__get_dynamic_array(key), key, map->key_size);
298 __entry->type = map->map_type;
299 __entry->key_len = min(map->key_size, 16U);
300 __entry->key_trunc = map->key_size != __entry->key_len;
301 __entry->ufd = ufd;
302 ),
303
304 TP_printk("map type=%s ufd=%d key=[%s%s]",
305 __print_symbolic(__entry->type, __MAP_TYPE_SYM_TAB),
306 __entry->ufd,
307 __print_hex(__get_dynamic_array(key), __entry->key_len),
308 __entry->key_trunc ? " ..." : "")
309);
310
311TRACE_EVENT(bpf_map_next_key,
312
313 TP_PROTO(const struct bpf_map *map, int ufd,
314 const void *key, const void *key_next),
315
316 TP_ARGS(map, ufd, key, key_next),
317
318 TP_STRUCT__entry(
319 __field(u32, type)
320 __field(u32, key_len)
321 __dynamic_array(u8, key, map->key_size)
322 __dynamic_array(u8, nxt, map->key_size)
323 __field(bool, key_trunc)
Teng Qin8fe45922017-04-24 19:00:37 -0700324 __field(bool, key_null)
Daniel Borkmanna67edbf2017-01-25 02:28:18 +0100325 __field(int, ufd)
326 ),
327
328 TP_fast_assign(
Teng Qin8fe45922017-04-24 19:00:37 -0700329 if (key)
330 memcpy(__get_dynamic_array(key), key, map->key_size);
331 __entry->key_null = !key;
Daniel Borkmanna67edbf2017-01-25 02:28:18 +0100332 memcpy(__get_dynamic_array(nxt), key_next, map->key_size);
333 __entry->type = map->map_type;
334 __entry->key_len = min(map->key_size, 16U);
335 __entry->key_trunc = map->key_size != __entry->key_len;
336 __entry->ufd = ufd;
337 ),
338
339 TP_printk("map type=%s ufd=%d key=[%s%s] next=[%s%s]",
340 __print_symbolic(__entry->type, __MAP_TYPE_SYM_TAB),
341 __entry->ufd,
Teng Qin8fe45922017-04-24 19:00:37 -0700342 __entry->key_null ? "NULL" : __print_hex(__get_dynamic_array(key),
343 __entry->key_len),
344 __entry->key_trunc && !__entry->key_null ? " ..." : "",
Daniel Borkmanna67edbf2017-01-25 02:28:18 +0100345 __print_hex(__get_dynamic_array(nxt), __entry->key_len),
346 __entry->key_trunc ? " ..." : "")
347);
348
349#endif /* _TRACE_BPF_H */
350
351#include <trace/define_trace.h>