Merge tag 'apparmor-pr-2017-11-21' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-microblaze.git] / include / trace / events / xdp.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM xdp
4
5 #if !defined(_TRACE_XDP_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_XDP_H
7
8 #include <linux/netdevice.h>
9 #include <linux/filter.h>
10 #include <linux/tracepoint.h>
11
12 #define __XDP_ACT_MAP(FN)       \
13         FN(ABORTED)             \
14         FN(DROP)                \
15         FN(PASS)                \
16         FN(TX)                  \
17         FN(REDIRECT)
18
19 #define __XDP_ACT_TP_FN(x)      \
20         TRACE_DEFINE_ENUM(XDP_##x);
21 #define __XDP_ACT_SYM_FN(x)     \
22         { XDP_##x, #x },
23 #define __XDP_ACT_SYM_TAB       \
24         __XDP_ACT_MAP(__XDP_ACT_SYM_FN) { -1, 0 }
25 __XDP_ACT_MAP(__XDP_ACT_TP_FN)
26
27 TRACE_EVENT(xdp_exception,
28
29         TP_PROTO(const struct net_device *dev,
30                  const struct bpf_prog *xdp, u32 act),
31
32         TP_ARGS(dev, xdp, act),
33
34         TP_STRUCT__entry(
35                 __field(int, prog_id)
36                 __field(u32, act)
37                 __field(int, ifindex)
38         ),
39
40         TP_fast_assign(
41                 __entry->prog_id        = xdp->aux->id;
42                 __entry->act            = act;
43                 __entry->ifindex        = dev->ifindex;
44         ),
45
46         TP_printk("prog_id=%d action=%s ifindex=%d",
47                   __entry->prog_id,
48                   __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
49                   __entry->ifindex)
50 );
51
52 DECLARE_EVENT_CLASS(xdp_redirect_template,
53
54         TP_PROTO(const struct net_device *dev,
55                  const struct bpf_prog *xdp,
56                  int to_ifindex, int err,
57                  const struct bpf_map *map, u32 map_index),
58
59         TP_ARGS(dev, xdp, to_ifindex, err, map, map_index),
60
61         TP_STRUCT__entry(
62                 __field(int, prog_id)
63                 __field(u32, act)
64                 __field(int, ifindex)
65                 __field(int, err)
66                 __field(int, to_ifindex)
67                 __field(u32, map_id)
68                 __field(int, map_index)
69         ),
70
71         TP_fast_assign(
72                 __entry->prog_id        = xdp->aux->id;
73                 __entry->act            = XDP_REDIRECT;
74                 __entry->ifindex        = dev->ifindex;
75                 __entry->err            = err;
76                 __entry->to_ifindex     = to_ifindex;
77                 __entry->map_id         = map ? map->id : 0;
78                 __entry->map_index      = map_index;
79         ),
80
81         TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d",
82                   __entry->prog_id,
83                   __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
84                   __entry->ifindex, __entry->to_ifindex,
85                   __entry->err)
86 );
87
88 DEFINE_EVENT(xdp_redirect_template, xdp_redirect,
89         TP_PROTO(const struct net_device *dev,
90                  const struct bpf_prog *xdp,
91                  int to_ifindex, int err,
92                  const struct bpf_map *map, u32 map_index),
93         TP_ARGS(dev, xdp, to_ifindex, err, map, map_index)
94 );
95
96 DEFINE_EVENT(xdp_redirect_template, xdp_redirect_err,
97         TP_PROTO(const struct net_device *dev,
98                  const struct bpf_prog *xdp,
99                  int to_ifindex, int err,
100                  const struct bpf_map *map, u32 map_index),
101         TP_ARGS(dev, xdp, to_ifindex, err, map, map_index)
102 );
103
104 #define _trace_xdp_redirect(dev, xdp, to)               \
105          trace_xdp_redirect(dev, xdp, to, 0, NULL, 0);
106
107 #define _trace_xdp_redirect_err(dev, xdp, to, err)      \
108          trace_xdp_redirect_err(dev, xdp, to, err, NULL, 0);
109
110 DEFINE_EVENT_PRINT(xdp_redirect_template, xdp_redirect_map,
111         TP_PROTO(const struct net_device *dev,
112                  const struct bpf_prog *xdp,
113                  int to_ifindex, int err,
114                  const struct bpf_map *map, u32 map_index),
115         TP_ARGS(dev, xdp, to_ifindex, err, map, map_index),
116         TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d"
117                   " map_id=%d map_index=%d",
118                   __entry->prog_id,
119                   __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
120                   __entry->ifindex, __entry->to_ifindex,
121                   __entry->err,
122                   __entry->map_id, __entry->map_index)
123 );
124
125 DEFINE_EVENT_PRINT(xdp_redirect_template, xdp_redirect_map_err,
126         TP_PROTO(const struct net_device *dev,
127                  const struct bpf_prog *xdp,
128                  int to_ifindex, int err,
129                  const struct bpf_map *map, u32 map_index),
130         TP_ARGS(dev, xdp, to_ifindex, err, map, map_index),
131         TP_printk("prog_id=%d action=%s ifindex=%d to_ifindex=%d err=%d"
132                   " map_id=%d map_index=%d",
133                   __entry->prog_id,
134                   __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
135                   __entry->ifindex, __entry->to_ifindex,
136                   __entry->err,
137                   __entry->map_id, __entry->map_index)
138 );
139
140 #define devmap_ifindex(fwd, map)                                \
141         (!fwd ? 0 :                                             \
142          (!map ? 0 :                                            \
143           ((map->map_type == BPF_MAP_TYPE_DEVMAP) ?             \
144            ((struct net_device *)fwd)->ifindex : 0)))
145
146 #define _trace_xdp_redirect_map(dev, xdp, fwd, map, idx)                \
147          trace_xdp_redirect_map(dev, xdp, devmap_ifindex(fwd, map),     \
148                                 0, map, idx)
149
150 #define _trace_xdp_redirect_map_err(dev, xdp, fwd, map, idx, err)       \
151          trace_xdp_redirect_map_err(dev, xdp, devmap_ifindex(fwd, map), \
152                                     err, map, idx)
153
154 TRACE_EVENT(xdp_cpumap_kthread,
155
156         TP_PROTO(int map_id, unsigned int processed,  unsigned int drops,
157                  int sched),
158
159         TP_ARGS(map_id, processed, drops, sched),
160
161         TP_STRUCT__entry(
162                 __field(int, map_id)
163                 __field(u32, act)
164                 __field(int, cpu)
165                 __field(unsigned int, drops)
166                 __field(unsigned int, processed)
167                 __field(int, sched)
168         ),
169
170         TP_fast_assign(
171                 __entry->map_id         = map_id;
172                 __entry->act            = XDP_REDIRECT;
173                 __entry->cpu            = smp_processor_id();
174                 __entry->drops          = drops;
175                 __entry->processed      = processed;
176                 __entry->sched  = sched;
177         ),
178
179         TP_printk("kthread"
180                   " cpu=%d map_id=%d action=%s"
181                   " processed=%u drops=%u"
182                   " sched=%d",
183                   __entry->cpu, __entry->map_id,
184                   __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
185                   __entry->processed, __entry->drops,
186                   __entry->sched)
187 );
188
189 TRACE_EVENT(xdp_cpumap_enqueue,
190
191         TP_PROTO(int map_id, unsigned int processed,  unsigned int drops,
192                  int to_cpu),
193
194         TP_ARGS(map_id, processed, drops, to_cpu),
195
196         TP_STRUCT__entry(
197                 __field(int, map_id)
198                 __field(u32, act)
199                 __field(int, cpu)
200                 __field(unsigned int, drops)
201                 __field(unsigned int, processed)
202                 __field(int, to_cpu)
203         ),
204
205         TP_fast_assign(
206                 __entry->map_id         = map_id;
207                 __entry->act            = XDP_REDIRECT;
208                 __entry->cpu            = smp_processor_id();
209                 __entry->drops          = drops;
210                 __entry->processed      = processed;
211                 __entry->to_cpu         = to_cpu;
212         ),
213
214         TP_printk("enqueue"
215                   " cpu=%d map_id=%d action=%s"
216                   " processed=%u drops=%u"
217                   " to_cpu=%d",
218                   __entry->cpu, __entry->map_id,
219                   __print_symbolic(__entry->act, __XDP_ACT_SYM_TAB),
220                   __entry->processed, __entry->drops,
221                   __entry->to_cpu)
222 );
223
224 #endif /* _TRACE_XDP_H */
225
226 #include <trace/define_trace.h>