xdp.h 6.9 KB

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