1 /* SPDX-License-Identifier: GPL-2.0 */
3 #define TRACE_SYSTEM bpf
5 #if !defined(_TRACE_BPF_H) || defined(TRACE_HEADER_MULTI_READ)
8 /* These are only used within the BPF_SYSCALL code */
9 #ifdef CONFIG_BPF_SYSCALL
11 #include <linux/filter.h>
12 #include <linux/bpf.h>
14 #include <linux/tracepoint.h>
16 #define __PROG_TYPE_MAP(FN) \
30 #define __MAP_TYPE_MAP(FN) \
34 FN(PERF_EVENT_ARRAY) \
43 #define __PROG_TYPE_TP_FN(x) \
44 TRACE_DEFINE_ENUM(BPF_PROG_TYPE_##x);
45 #define __PROG_TYPE_SYM_FN(x) \
46 { BPF_PROG_TYPE_##x, #x },
47 #define __PROG_TYPE_SYM_TAB \
48 __PROG_TYPE_MAP(__PROG_TYPE_SYM_FN) { -1, 0 }
49 __PROG_TYPE_MAP(__PROG_TYPE_TP_FN
)
51 #define __MAP_TYPE_TP_FN(x) \
52 TRACE_DEFINE_ENUM(BPF_MAP_TYPE_##x);
53 #define __MAP_TYPE_SYM_FN(x) \
54 { BPF_MAP_TYPE_##x, #x },
55 #define __MAP_TYPE_SYM_TAB \
56 __MAP_TYPE_MAP(__MAP_TYPE_SYM_FN) { -1, 0 }
57 __MAP_TYPE_MAP(__MAP_TYPE_TP_FN
)
59 DECLARE_EVENT_CLASS(bpf_prog_event
,
61 TP_PROTO(const struct bpf_prog
*prg
),
66 __array(u8
, prog_tag
, 8)
71 BUILD_BUG_ON(sizeof(__entry
->prog_tag
) != sizeof(prg
->tag
));
72 memcpy(__entry
->prog_tag
, prg
->tag
, sizeof(prg
->tag
));
73 __entry
->type
= prg
->type
;
76 TP_printk("prog=%s type=%s",
77 __print_hex_str(__entry
->prog_tag
, 8),
78 __print_symbolic(__entry
->type
, __PROG_TYPE_SYM_TAB
))
81 DEFINE_EVENT(bpf_prog_event
, bpf_prog_get_type
,
83 TP_PROTO(const struct bpf_prog
*prg
),
88 DEFINE_EVENT(bpf_prog_event
, bpf_prog_put_rcu
,
90 TP_PROTO(const struct bpf_prog
*prg
),
95 TRACE_EVENT(bpf_prog_load
,
97 TP_PROTO(const struct bpf_prog
*prg
, int ufd
),
102 __array(u8
, prog_tag
, 8)
108 BUILD_BUG_ON(sizeof(__entry
->prog_tag
) != sizeof(prg
->tag
));
109 memcpy(__entry
->prog_tag
, prg
->tag
, sizeof(prg
->tag
));
110 __entry
->type
= prg
->type
;
114 TP_printk("prog=%s type=%s ufd=%d",
115 __print_hex_str(__entry
->prog_tag
, 8),
116 __print_symbolic(__entry
->type
, __PROG_TYPE_SYM_TAB
),
120 TRACE_EVENT(bpf_map_create
,
122 TP_PROTO(const struct bpf_map
*map
, int ufd
),
128 __field(u32
, size_key
)
129 __field(u32
, size_value
)
130 __field(u32
, max_entries
)
136 __entry
->type
= map
->map_type
;
137 __entry
->size_key
= map
->key_size
;
138 __entry
->size_value
= map
->value_size
;
139 __entry
->max_entries
= map
->max_entries
;
140 __entry
->flags
= map
->map_flags
;
144 TP_printk("map type=%s ufd=%d key=%u val=%u max=%u flags=%x",
145 __print_symbolic(__entry
->type
, __MAP_TYPE_SYM_TAB
),
146 __entry
->ufd
, __entry
->size_key
, __entry
->size_value
,
147 __entry
->max_entries
, __entry
->flags
)
150 DECLARE_EVENT_CLASS(bpf_obj_prog
,
152 TP_PROTO(const struct bpf_prog
*prg
, int ufd
,
153 const struct filename
*pname
),
155 TP_ARGS(prg
, ufd
, pname
),
158 __array(u8
, prog_tag
, 8)
160 __string(path
, pname
->name
)
164 BUILD_BUG_ON(sizeof(__entry
->prog_tag
) != sizeof(prg
->tag
));
165 memcpy(__entry
->prog_tag
, prg
->tag
, sizeof(prg
->tag
));
166 __assign_str(path
, pname
->name
);
170 TP_printk("prog=%s path=%s ufd=%d",
171 __print_hex_str(__entry
->prog_tag
, 8),
172 __get_str(path
), __entry
->ufd
)
175 DEFINE_EVENT(bpf_obj_prog
, bpf_obj_pin_prog
,
177 TP_PROTO(const struct bpf_prog
*prg
, int ufd
,
178 const struct filename
*pname
),
180 TP_ARGS(prg
, ufd
, pname
)
183 DEFINE_EVENT(bpf_obj_prog
, bpf_obj_get_prog
,
185 TP_PROTO(const struct bpf_prog
*prg
, int ufd
,
186 const struct filename
*pname
),
188 TP_ARGS(prg
, ufd
, pname
)
191 DECLARE_EVENT_CLASS(bpf_obj_map
,
193 TP_PROTO(const struct bpf_map
*map
, int ufd
,
194 const struct filename
*pname
),
196 TP_ARGS(map
, ufd
, pname
),
201 __string(path
, pname
->name
)
205 __assign_str(path
, pname
->name
);
206 __entry
->type
= map
->map_type
;
210 TP_printk("map type=%s ufd=%d path=%s",
211 __print_symbolic(__entry
->type
, __MAP_TYPE_SYM_TAB
),
212 __entry
->ufd
, __get_str(path
))
215 DEFINE_EVENT(bpf_obj_map
, bpf_obj_pin_map
,
217 TP_PROTO(const struct bpf_map
*map
, int ufd
,
218 const struct filename
*pname
),
220 TP_ARGS(map
, ufd
, pname
)
223 DEFINE_EVENT(bpf_obj_map
, bpf_obj_get_map
,
225 TP_PROTO(const struct bpf_map
*map
, int ufd
,
226 const struct filename
*pname
),
228 TP_ARGS(map
, ufd
, pname
)
231 DECLARE_EVENT_CLASS(bpf_map_keyval
,
233 TP_PROTO(const struct bpf_map
*map
, int ufd
,
234 const void *key
, const void *val
),
236 TP_ARGS(map
, ufd
, key
, val
),
240 __field(u32
, key_len
)
241 __dynamic_array(u8
, key
, map
->key_size
)
242 __field(bool, key_trunc
)
243 __field(u32
, val_len
)
244 __dynamic_array(u8
, val
, map
->value_size
)
245 __field(bool, val_trunc
)
250 memcpy(__get_dynamic_array(key
), key
, map
->key_size
);
251 memcpy(__get_dynamic_array(val
), val
, map
->value_size
);
252 __entry
->type
= map
->map_type
;
253 __entry
->key_len
= min(map
->key_size
, 16U);
254 __entry
->key_trunc
= map
->key_size
!= __entry
->key_len
;
255 __entry
->val_len
= min(map
->value_size
, 16U);
256 __entry
->val_trunc
= map
->value_size
!= __entry
->val_len
;
260 TP_printk("map type=%s ufd=%d key=[%s%s] val=[%s%s]",
261 __print_symbolic(__entry
->type
, __MAP_TYPE_SYM_TAB
),
263 __print_hex(__get_dynamic_array(key
), __entry
->key_len
),
264 __entry
->key_trunc
? " ..." : "",
265 __print_hex(__get_dynamic_array(val
), __entry
->val_len
),
266 __entry
->val_trunc
? " ..." : "")
269 DEFINE_EVENT(bpf_map_keyval
, bpf_map_lookup_elem
,
271 TP_PROTO(const struct bpf_map
*map
, int ufd
,
272 const void *key
, const void *val
),
274 TP_ARGS(map
, ufd
, key
, val
)
277 DEFINE_EVENT(bpf_map_keyval
, bpf_map_update_elem
,
279 TP_PROTO(const struct bpf_map
*map
, int ufd
,
280 const void *key
, const void *val
),
282 TP_ARGS(map
, ufd
, key
, val
)
285 TRACE_EVENT(bpf_map_delete_elem
,
287 TP_PROTO(const struct bpf_map
*map
, int ufd
,
290 TP_ARGS(map
, ufd
, key
),
294 __field(u32
, key_len
)
295 __dynamic_array(u8
, key
, map
->key_size
)
296 __field(bool, key_trunc
)
301 memcpy(__get_dynamic_array(key
), key
, map
->key_size
);
302 __entry
->type
= map
->map_type
;
303 __entry
->key_len
= min(map
->key_size
, 16U);
304 __entry
->key_trunc
= map
->key_size
!= __entry
->key_len
;
308 TP_printk("map type=%s ufd=%d key=[%s%s]",
309 __print_symbolic(__entry
->type
, __MAP_TYPE_SYM_TAB
),
311 __print_hex(__get_dynamic_array(key
), __entry
->key_len
),
312 __entry
->key_trunc
? " ..." : "")
315 TRACE_EVENT(bpf_map_next_key
,
317 TP_PROTO(const struct bpf_map
*map
, int ufd
,
318 const void *key
, const void *key_next
),
320 TP_ARGS(map
, ufd
, key
, key_next
),
324 __field(u32
, key_len
)
325 __dynamic_array(u8
, key
, map
->key_size
)
326 __dynamic_array(u8
, nxt
, map
->key_size
)
327 __field(bool, key_trunc
)
328 __field(bool, key_null
)
334 memcpy(__get_dynamic_array(key
), key
, map
->key_size
);
335 __entry
->key_null
= !key
;
336 memcpy(__get_dynamic_array(nxt
), key_next
, map
->key_size
);
337 __entry
->type
= map
->map_type
;
338 __entry
->key_len
= min(map
->key_size
, 16U);
339 __entry
->key_trunc
= map
->key_size
!= __entry
->key_len
;
343 TP_printk("map type=%s ufd=%d key=[%s%s] next=[%s%s]",
344 __print_symbolic(__entry
->type
, __MAP_TYPE_SYM_TAB
),
346 __entry
->key_null
? "NULL" : __print_hex(__get_dynamic_array(key
),
348 __entry
->key_trunc
&& !__entry
->key_null
? " ..." : "",
349 __print_hex(__get_dynamic_array(nxt
), __entry
->key_len
),
350 __entry
->key_trunc
? " ..." : "")
352 #endif /* CONFIG_BPF_SYSCALL */
353 #endif /* _TRACE_BPF_H */
355 #include <trace/define_trace.h>