1 /* SPDX-License-Identifier: GPL-2.0 */
3 #define TRACE_SYSTEM xdp
5 #if !defined(_TRACE_XDP_H) || defined(TRACE_HEADER_MULTI_READ)
8 #include <linux/netdevice.h>
9 #include <linux/filter.h>
10 #include <linux/tracepoint.h>
11 #include <linux/bpf.h>
14 #define __XDP_ACT_MAP(FN) \
21 #define __XDP_ACT_TP_FN(x) \
22 TRACE_DEFINE_ENUM(XDP_##x);
23 #define __XDP_ACT_SYM_FN(x) \
25 #define __XDP_ACT_SYM_TAB \
26 __XDP_ACT_MAP(__XDP_ACT_SYM_FN) { -1, NULL }
27 __XDP_ACT_MAP(__XDP_ACT_TP_FN
)
29 TRACE_EVENT(xdp_exception
,
31 TP_PROTO(const struct net_device
*dev
,
32 const struct bpf_prog
*xdp
, u32 act
),
34 TP_ARGS(dev
, xdp
, act
),
43 __entry
->prog_id
= xdp
->aux
->id
;
45 __entry
->ifindex
= dev
->ifindex
;
48 TP_printk("prog_id=%d action=%s ifindex=%d",
50 __print_symbolic(__entry
->act
, __XDP_ACT_SYM_TAB
),
54 TRACE_EVENT(xdp_bulk_tx
,
56 TP_PROTO(const struct net_device
*dev
,
57 int sent
, int drops
, int err
),
59 TP_ARGS(dev
, sent
, drops
, err
),
70 __entry
->ifindex
= dev
->ifindex
;
71 __entry
->act
= XDP_TX
;
72 __entry
->drops
= drops
;
77 TP_printk("ifindex=%d action=%s sent=%d drops=%d err=%d",
79 __print_symbolic(__entry
->act
, __XDP_ACT_SYM_TAB
),
80 __entry
->sent
, __entry
->drops
, __entry
->err
)
83 #ifndef __DEVMAP_OBJ_TYPE
84 #define __DEVMAP_OBJ_TYPE
85 struct _bpf_dtab_netdev
{
86 struct net_device
*dev
;
88 #endif /* __DEVMAP_OBJ_TYPE */
90 DECLARE_EVENT_CLASS(xdp_redirect_template
,
92 TP_PROTO(const struct net_device
*dev
,
93 const struct bpf_prog
*xdp
,
94 const void *tgt
, int err
,
95 enum bpf_map_type map_type
,
96 u32 map_id
, u32 index
),
98 TP_ARGS(dev
, xdp
, tgt
, err
, map_type
, map_id
, index
),
101 __field(int, prog_id
)
103 __field(int, ifindex
)
105 __field(int, to_ifindex
)
107 __field(int, map_index
)
111 u32 ifindex
= 0, map_index
= index
;
113 if (map_type
== BPF_MAP_TYPE_DEVMAP
|| map_type
== BPF_MAP_TYPE_DEVMAP_HASH
) {
114 /* Just leave to_ifindex to 0 if do broadcast redirect,
115 * as tgt will be NULL.
118 ifindex
= ((struct _bpf_dtab_netdev
*)tgt
)->dev
->ifindex
;
119 } else if (map_type
== BPF_MAP_TYPE_UNSPEC
&& map_id
== INT_MAX
) {
124 __entry
->prog_id
= xdp
->aux
->id
;
125 __entry
->act
= XDP_REDIRECT
;
126 __entry
->ifindex
= dev
->ifindex
;
128 __entry
->to_ifindex
= ifindex
;
129 __entry
->map_id
= map_id
;
130 __entry
->map_index
= map_index
;
133 TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d"
134 " map_id=%d map_index=%d",
136 __print_symbolic(__entry
->act
, __XDP_ACT_SYM_TAB
),
137 __entry
->ifindex
, __entry
->to_ifindex
,
138 __entry
->err
, __entry
->map_id
, __entry
->map_index
)
141 DEFINE_EVENT(xdp_redirect_template
, xdp_redirect
,
142 TP_PROTO(const struct net_device
*dev
,
143 const struct bpf_prog
*xdp
,
144 const void *tgt
, int err
,
145 enum bpf_map_type map_type
,
146 u32 map_id
, u32 index
),
147 TP_ARGS(dev
, xdp
, tgt
, err
, map_type
, map_id
, index
)
150 DEFINE_EVENT(xdp_redirect_template
, xdp_redirect_err
,
151 TP_PROTO(const struct net_device
*dev
,
152 const struct bpf_prog
*xdp
,
153 const void *tgt
, int err
,
154 enum bpf_map_type map_type
,
155 u32 map_id
, u32 index
),
156 TP_ARGS(dev
, xdp
, tgt
, err
, map_type
, map_id
, index
)
159 #define _trace_xdp_redirect(dev, xdp, to) \
160 trace_xdp_redirect(dev, xdp, NULL, 0, BPF_MAP_TYPE_UNSPEC, INT_MAX, to)
162 #define _trace_xdp_redirect_err(dev, xdp, to, err) \
163 trace_xdp_redirect_err(dev, xdp, NULL, err, BPF_MAP_TYPE_UNSPEC, INT_MAX, to)
165 #define _trace_xdp_redirect_map(dev, xdp, to, map_type, map_id, index) \
166 trace_xdp_redirect(dev, xdp, to, 0, map_type, map_id, index)
168 #define _trace_xdp_redirect_map_err(dev, xdp, to, map_type, map_id, index, err) \
169 trace_xdp_redirect_err(dev, xdp, to, err, map_type, map_id, index)
171 /* not used anymore, but kept around so as not to break old programs */
172 DEFINE_EVENT(xdp_redirect_template
, xdp_redirect_map
,
173 TP_PROTO(const struct net_device
*dev
,
174 const struct bpf_prog
*xdp
,
175 const void *tgt
, int err
,
176 enum bpf_map_type map_type
,
177 u32 map_id
, u32 index
),
178 TP_ARGS(dev
, xdp
, tgt
, err
, map_type
, map_id
, index
)
181 DEFINE_EVENT(xdp_redirect_template
, xdp_redirect_map_err
,
182 TP_PROTO(const struct net_device
*dev
,
183 const struct bpf_prog
*xdp
,
184 const void *tgt
, int err
,
185 enum bpf_map_type map_type
,
186 u32 map_id
, u32 index
),
187 TP_ARGS(dev
, xdp
, tgt
, err
, map_type
, map_id
, index
)
190 TRACE_EVENT(xdp_cpumap_kthread
,
192 TP_PROTO(int map_id
, unsigned int processed
, unsigned int drops
,
193 int sched
, struct xdp_cpumap_stats
*xdp_stats
),
195 TP_ARGS(map_id
, processed
, drops
, sched
, xdp_stats
),
201 __field(unsigned int, drops
)
202 __field(unsigned int, processed
)
204 __field(unsigned int, xdp_pass
)
205 __field(unsigned int, xdp_drop
)
206 __field(unsigned int, xdp_redirect
)
210 __entry
->map_id
= map_id
;
211 __entry
->act
= XDP_REDIRECT
;
212 __entry
->cpu
= smp_processor_id();
213 __entry
->drops
= drops
;
214 __entry
->processed
= processed
;
215 __entry
->sched
= sched
;
216 __entry
->xdp_pass
= xdp_stats
->pass
;
217 __entry
->xdp_drop
= xdp_stats
->drop
;
218 __entry
->xdp_redirect
= xdp_stats
->redirect
;
222 " cpu=%d map_id=%d action=%s"
223 " processed=%u drops=%u"
225 " xdp_pass=%u xdp_drop=%u xdp_redirect=%u",
226 __entry
->cpu
, __entry
->map_id
,
227 __print_symbolic(__entry
->act
, __XDP_ACT_SYM_TAB
),
228 __entry
->processed
, __entry
->drops
,
230 __entry
->xdp_pass
, __entry
->xdp_drop
, __entry
->xdp_redirect
)
233 TRACE_EVENT(xdp_cpumap_enqueue
,
235 TP_PROTO(int map_id
, unsigned int processed
, unsigned int drops
,
238 TP_ARGS(map_id
, processed
, drops
, to_cpu
),
244 __field(unsigned int, drops
)
245 __field(unsigned int, processed
)
250 __entry
->map_id
= map_id
;
251 __entry
->act
= XDP_REDIRECT
;
252 __entry
->cpu
= smp_processor_id();
253 __entry
->drops
= drops
;
254 __entry
->processed
= processed
;
255 __entry
->to_cpu
= to_cpu
;
259 " cpu=%d map_id=%d action=%s"
260 " processed=%u drops=%u"
262 __entry
->cpu
, __entry
->map_id
,
263 __print_symbolic(__entry
->act
, __XDP_ACT_SYM_TAB
),
264 __entry
->processed
, __entry
->drops
,
268 TRACE_EVENT(xdp_devmap_xmit
,
270 TP_PROTO(const struct net_device
*from_dev
,
271 const struct net_device
*to_dev
,
272 int sent
, int drops
, int err
),
274 TP_ARGS(from_dev
, to_dev
, sent
, drops
, err
),
277 __field(int, from_ifindex
)
279 __field(int, to_ifindex
)
286 __entry
->from_ifindex
= from_dev
->ifindex
;
287 __entry
->act
= XDP_REDIRECT
;
288 __entry
->to_ifindex
= to_dev
->ifindex
;
289 __entry
->drops
= drops
;
290 __entry
->sent
= sent
;
294 TP_printk("ndo_xdp_xmit"
295 " from_ifindex=%d to_ifindex=%d action=%s"
298 __entry
->from_ifindex
, __entry
->to_ifindex
,
299 __print_symbolic(__entry
->act
, __XDP_ACT_SYM_TAB
),
300 __entry
->sent
, __entry
->drops
,
304 /* Expect users already include <net/xdp.h>, but not xdp_priv.h */
305 #include <net/xdp_priv.h>
307 #define __MEM_TYPE_MAP(FN) \
313 #define __MEM_TYPE_TP_FN(x) \
314 TRACE_DEFINE_ENUM(MEM_TYPE_##x);
315 #define __MEM_TYPE_SYM_FN(x) \
316 { MEM_TYPE_##x, #x },
317 #define __MEM_TYPE_SYM_TAB \
318 __MEM_TYPE_MAP(__MEM_TYPE_SYM_FN) { -1, 0 }
319 __MEM_TYPE_MAP(__MEM_TYPE_TP_FN
)
321 TRACE_EVENT(mem_disconnect
,
323 TP_PROTO(const struct xdp_mem_allocator
*xa
),
328 __field(const struct xdp_mem_allocator
*, xa
)
330 __field(u32
, mem_type
)
331 __field(const void *, allocator
)
336 __entry
->mem_id
= xa
->mem
.id
;
337 __entry
->mem_type
= xa
->mem
.type
;
338 __entry
->allocator
= xa
->allocator
;
341 TP_printk("mem_id=%d mem_type=%s allocator=%p",
343 __print_symbolic(__entry
->mem_type
, __MEM_TYPE_SYM_TAB
),
348 TRACE_EVENT(mem_connect
,
350 TP_PROTO(const struct xdp_mem_allocator
*xa
,
351 const struct xdp_rxq_info
*rxq
),
356 __field(const struct xdp_mem_allocator
*, xa
)
358 __field(u32
, mem_type
)
359 __field(const void *, allocator
)
360 __field(const struct xdp_rxq_info
*, rxq
)
361 __field(int, ifindex
)
366 __entry
->mem_id
= xa
->mem
.id
;
367 __entry
->mem_type
= xa
->mem
.type
;
368 __entry
->allocator
= xa
->allocator
;
370 __entry
->ifindex
= rxq
->dev
->ifindex
;
373 TP_printk("mem_id=%d mem_type=%s allocator=%p"
376 __print_symbolic(__entry
->mem_type
, __MEM_TYPE_SYM_TAB
),
382 TRACE_EVENT(mem_return_failed
,
384 TP_PROTO(const struct xdp_mem_info
*mem
,
385 const struct page
*page
),
390 __field(const struct page
*, page
)
392 __field(u32
, mem_type
)
396 __entry
->page
= page
;
397 __entry
->mem_id
= mem
->id
;
398 __entry
->mem_type
= mem
->type
;
401 TP_printk("mem_id=%d mem_type=%s page=%p",
403 __print_symbolic(__entry
->mem_type
, __MEM_TYPE_SYM_TAB
),
408 TRACE_EVENT(bpf_xdp_link_attach_failed
,
410 TP_PROTO(const char *msg
),
422 TP_printk("errmsg=%s", __get_str(msg
))
425 #endif /* _TRACE_XDP_H */
427 #include <trace/define_trace.h>