diff mbox series

[bpf-next,v3,1/6] xsk: add tracepoints for packet drops

Message ID 20210202133642.8562-2-ciara.loftus@intel.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series AF_XDP Packet Drop Tracing | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 13 maintainers not CCed: songliubraving@fb.com andrii@kernel.org jonathan.lemon@gmail.com ast@kernel.org hawk@kernel.org rostedt@goodmis.org mingo@redhat.com kpsingh@kernel.org davem@davemloft.net john.fastabend@gmail.com kuba@kernel.org kafai@fb.com yhs@fb.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit fail Errors and warnings before: 94 this patch: 97
netdev/kdoc success Errors and warnings before: 1 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch warning CHECK: Alignment should match open parenthesis CHECK: Lines should not end with a '(' CHECK: Please don't use multiple blank lines WARNING: Duplicate signature WARNING: line length of 81 exceeds 80 columns WARNING: line length of 82 exceeds 80 columns WARNING: line length of 83 exceeds 80 columns WARNING: line length of 85 exceeds 80 columns WARNING: line length of 92 exceeds 80 columns
netdev/build_allmodconfig_warn fail Errors and warnings before: 94 this patch: 97
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Ciara Loftus Feb. 2, 2021, 1:36 p.m. UTC
This commit introduces tracing infrastructure for AF_XDP sockets
(xsks) and a new trace event called 'xsk_packet_drop'. This trace
event is triggered when a packet cannot be processed by the socket
due to one of the following issues:
(1) packet exceeds the maximum permitted size.
(2) invalid fill descriptor address.
(3) invalid tx descriptor field.

The trace provides information about the error to the user. For
example the size vs permitted size is provided for (1). For (2)
and (3) the relevant descriptor fields are printed. This information
should help a user troubleshoot packet drops by providing this extra
level of detail which is not available through use of simple counters.

The tracepoint can be enabled/disabled by toggling
/sys/kernel/debug/tracing/events/xsk/xsk_packet_drop/enable

Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
---
 MAINTAINERS                       |  1 +
 include/linux/bpf_trace.h         |  1 +
 include/trace/events/xsk.h        | 73 +++++++++++++++++++++++++++++++
 include/uapi/linux/if_xdp.h       |  6 +++
 kernel/bpf/core.c                 |  1 +
 net/xdp/xsk.c                     |  7 ++-
 net/xdp/xsk_buff_pool.c           |  3 ++
 net/xdp/xsk_queue.h               |  4 ++
 tools/include/uapi/linux/if_xdp.h |  6 +++
 9 files changed, 101 insertions(+), 1 deletion(-)
 create mode 100644 include/trace/events/xsk.h

Comments

kernel test robot Feb. 2, 2021, 8:02 p.m. UTC | #1
Hi Ciara,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on bpf-next/master]

url:    https://github.com/0day-ci/linux/commits/Ciara-Loftus/AF_XDP-Packet-Drop-Tracing/20210203-020056
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: x86_64-randconfig-s022-20210202 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.3-215-g0fb77bb6-dirty
        # https://github.com/0day-ci/linux/commit/8566dfd5799adb0033d56bc33146947b9469c362
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Ciara-Loftus/AF_XDP-Packet-Drop-Tracing/20210203-020056
        git checkout 8566dfd5799adb0033d56bc33146947b9469c362
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   kernel/bpf/core.c:1350:12: warning: no previous prototype for 'bpf_probe_read_kernel' [-Wmissing-prototypes]
    1350 | u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
         |            ^~~~~~~~~~~~~~~~~~~~~
   In file included from include/trace/define_trace.h:102,
                    from include/trace/events/xsk.h:73,
                    from include/linux/bpf_trace.h:6,
                    from kernel/bpf/core.c:2361:
   include/trace/events/xsk.h: In function 'trace_raw_output_xsk_packet_drop':
>> include/trace/events/xsk.h:63:12: warning: format '%lu' expects argument of type 'long unsigned int', but argument 7 has type 'u64' {aka 'long long unsigned int'} [-Wformat=]
      63 |  TP_printk("netdev: %s qid %u reason: %s: %s %lu %s %lu %s %lu",
         |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/trace/trace_events.h:367:22: note: in definition of macro 'DECLARE_EVENT_CLASS'
     367 |  trace_seq_printf(s, print);     \
         |                      ^~~~~
   include/trace/trace_events.h:80:9: note: in expansion of macro 'PARAMS'
      80 |         PARAMS(print));         \
         |         ^~~~~~
   include/trace/events/xsk.h:39:1: note: in expansion of macro 'TRACE_EVENT'
      39 | TRACE_EVENT(xsk_packet_drop,
         | ^~~~~~~~~~~
   include/trace/events/xsk.h:63:2: note: in expansion of macro 'TP_printk'
      63 |  TP_printk("netdev: %s qid %u reason: %s: %s %lu %s %lu %s %lu",
         |  ^~~~~~~~~
   In file included from include/trace/trace_events.h:401,
                    from include/trace/define_trace.h:102,
                    from include/trace/events/xsk.h:73,
                    from include/linux/bpf_trace.h:6,
                    from kernel/bpf/core.c:2361:
   include/trace/events/xsk.h:63:48: note: format string is defined here
      63 |  TP_printk("netdev: %s qid %u reason: %s: %s %lu %s %lu %s %lu",
         |                                              ~~^
         |                                                |
         |                                                long unsigned int
         |                                              %llu
   In file included from include/trace/define_trace.h:102,
                    from include/trace/events/xsk.h:73,
                    from include/linux/bpf_trace.h:6,
                    from kernel/bpf/core.c:2361:
   include/trace/events/xsk.h:63:12: warning: format '%lu' expects argument of type 'long unsigned int', but argument 9 has type 'u64' {aka 'long long unsigned int'} [-Wformat=]
      63 |  TP_printk("netdev: %s qid %u reason: %s: %s %lu %s %lu %s %lu",
         |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/trace/trace_events.h:367:22: note: in definition of macro 'DECLARE_EVENT_CLASS'
     367 |  trace_seq_printf(s, print);     \
         |                      ^~~~~
   include/trace/trace_events.h:80:9: note: in expansion of macro 'PARAMS'
      80 |         PARAMS(print));         \
         |         ^~~~~~
   include/trace/events/xsk.h:39:1: note: in expansion of macro 'TRACE_EVENT'
      39 | TRACE_EVENT(xsk_packet_drop,
         | ^~~~~~~~~~~
   include/trace/events/xsk.h:63:2: note: in expansion of macro 'TP_printk'
      63 |  TP_printk("netdev: %s qid %u reason: %s: %s %lu %s %lu %s %lu",
         |  ^~~~~~~~~
   In file included from include/trace/trace_events.h:401,
                    from include/trace/define_trace.h:102,
                    from include/trace/events/xsk.h:73,
                    from include/linux/bpf_trace.h:6,
                    from kernel/bpf/core.c:2361:
   include/trace/events/xsk.h:63:55: note: format string is defined here
      63 |  TP_printk("netdev: %s qid %u reason: %s: %s %lu %s %lu %s %lu",
         |                                                     ~~^
         |                                                       |
         |                                                       long unsigned int
         |                                                     %llu
   In file included from include/trace/define_trace.h:102,
                    from include/trace/events/xsk.h:73,
                    from include/linux/bpf_trace.h:6,
                    from kernel/bpf/core.c:2361:
   include/trace/events/xsk.h:63:12: warning: format '%lu' expects argument of type 'long unsigned int', but argument 11 has type 'u64' {aka 'long long unsigned int'} [-Wformat=]
      63 |  TP_printk("netdev: %s qid %u reason: %s: %s %lu %s %lu %s %lu",
         |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/trace/trace_events.h:367:22: note: in definition of macro 'DECLARE_EVENT_CLASS'
     367 |  trace_seq_printf(s, print);     \
         |                      ^~~~~
   include/trace/trace_events.h:80:9: note: in expansion of macro 'PARAMS'
      80 |         PARAMS(print));         \
         |         ^~~~~~
   include/trace/events/xsk.h:39:1: note: in expansion of macro 'TRACE_EVENT'
      39 | TRACE_EVENT(xsk_packet_drop,
         | ^~~~~~~~~~~
   include/trace/events/xsk.h:63:2: note: in expansion of macro 'TP_printk'
      63 |  TP_printk("netdev: %s qid %u reason: %s: %s %lu %s %lu %s %lu",
         |  ^~~~~~~~~
   In file included from include/trace/trace_events.h:401,
                    from include/trace/define_trace.h:102,
                    from include/trace/events/xsk.h:73,
                    from include/linux/bpf_trace.h:6,
                    from kernel/bpf/core.c:2361:
   include/trace/events/xsk.h:63:62: note: format string is defined here
      63 |  TP_printk("netdev: %s qid %u reason: %s: %s %lu %s %lu %s %lu",
         |                                                            ~~^
         |                                                              |
         |                                                              long unsigned int
         |                                                            %llu


vim +63 include/trace/events/xsk.h

    40	
    41		TP_PROTO(char *name, u16 queue_id, u32 reason, u64 val1, u64 val2, u64 val3),
    42	
    43		TP_ARGS(name, queue_id, reason, val1, val2, val3),
    44	
    45		TP_STRUCT__entry(
    46			__field(char *, name)
    47			__field(u16, queue_id)
    48			__field(u32, reason)
    49			__field(u64, val1)
    50			__field(u64, val2)
    51			__field(u64, val3)
    52		),
    53	
    54		TP_fast_assign(
    55			__entry->name = name;
    56			__entry->queue_id = queue_id;
    57			__entry->reason = reason;
    58			__entry->val1 = val1;
    59			__entry->val2 = val2;
    60			__entry->val3 = val3;
    61		),
    62	
  > 63		TP_printk("netdev: %s qid %u reason: %s: %s %lu %s %lu %s %lu",
    64			  __entry->name, __entry->queue_id, print_reason(__entry->reason),
    65			  print_val1(__entry->reason), __entry->val1,
    66			  print_val2(__entry->reason), __entry->val2,
    67			  print_val3(__entry->reason), __entry->val3
    68		)
    69	);
    70	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot Feb. 2, 2021, 8:16 p.m. UTC | #2
Hi Ciara,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on bpf-next/master]

url:    https://github.com/0day-ci/linux/commits/Ciara-Loftus/AF_XDP-Packet-Drop-Tracing/20210203-020056
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: arm-randconfig-r015-20210202 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 275c6af7d7f1ed63a03d05b4484413e447133269)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://github.com/0day-ci/linux/commit/8566dfd5799adb0033d56bc33146947b9469c362
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Ciara-Loftus/AF_XDP-Packet-Drop-Tracing/20210203-020056
        git checkout 8566dfd5799adb0033d56bc33146947b9469c362
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   kernel/bpf/core.c:1350:12: warning: no previous prototype for function 'bpf_probe_read_kernel' [-Wmissing-prototypes]
   u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
              ^
   kernel/bpf/core.c:1350:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   u64 __weak bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
   ^
   static 
   In file included from kernel/bpf/core.c:2361:
   In file included from include/linux/bpf_trace.h:6:
   In file included from include/trace/events/xsk.h:73:
   In file included from include/trace/define_trace.h:102:
   In file included from include/trace/trace_events.h:401:
>> include/trace/events/xsk.h:65:34: warning: format specifies type 'unsigned long' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
                     print_val1(__entry->reason), __entry->val1,
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
   include/trace/trace_events.h:263:17: note: expanded from macro '__entry'
   #define __entry field
                   ^
   include/trace/trace_events.h:266:43: note: expanded from macro 'TP_printk'
   #define TP_printk(fmt, args...) fmt "\n", args
                                   ~~~       ^
   include/trace/trace_events.h:80:16: note: expanded from macro 'TRACE_EVENT'
                                PARAMS(print));                   \
                                ~~~~~~~^~~~~~~
   include/linux/tracepoint.h:97:25: note: expanded from macro 'PARAMS'
   #define PARAMS(args...) args
                           ^~~~
   include/trace/trace_events.h:367:22: note: expanded from macro 'DECLARE_EVENT_CLASS'
           trace_seq_printf(s, print);                                     \
                               ^~~~~
   In file included from kernel/bpf/core.c:2361:
   In file included from include/linux/bpf_trace.h:6:
   In file included from include/trace/events/xsk.h:73:
   In file included from include/trace/define_trace.h:102:
   In file included from include/trace/trace_events.h:401:
   include/trace/events/xsk.h:66:34: warning: format specifies type 'unsigned long' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
                     print_val2(__entry->reason), __entry->val2,
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
   include/trace/trace_events.h:263:17: note: expanded from macro '__entry'
   #define __entry field
                   ^
   include/trace/trace_events.h:266:43: note: expanded from macro 'TP_printk'
   #define TP_printk(fmt, args...) fmt "\n", args
                                   ~~~       ^
   include/trace/trace_events.h:80:16: note: expanded from macro 'TRACE_EVENT'
                                PARAMS(print));                   \
                                ~~~~~~~^~~~~~~
   include/linux/tracepoint.h:97:25: note: expanded from macro 'PARAMS'
   #define PARAMS(args...) args
                           ^~~~
   include/trace/trace_events.h:367:22: note: expanded from macro 'DECLARE_EVENT_CLASS'
           trace_seq_printf(s, print);                                     \
                               ^~~~~
   In file included from kernel/bpf/core.c:2361:
   In file included from include/linux/bpf_trace.h:6:
   In file included from include/trace/events/xsk.h:73:
   In file included from include/trace/define_trace.h:102:
   In file included from include/trace/trace_events.h:401:
   include/trace/events/xsk.h:67:34: warning: format specifies type 'unsigned long' but the argument has type 'u64' (aka 'unsigned long long') [-Wformat]
                     print_val3(__entry->reason), __entry->val3
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
   include/trace/trace_events.h:263:17: note: expanded from macro '__entry'
   #define __entry field
                   ^
   include/trace/trace_events.h:266:43: note: expanded from macro 'TP_printk'
   #define TP_printk(fmt, args...) fmt "\n", args
                                   ~~~       ^
   include/trace/trace_events.h:80:16: note: expanded from macro 'TRACE_EVENT'
                                PARAMS(print));                   \
                                ~~~~~~~^~~~~~~
   include/linux/tracepoint.h:97:25: note: expanded from macro 'PARAMS'
   #define PARAMS(args...) args
                           ^~~~
   include/trace/trace_events.h:367:22: note: expanded from macro 'DECLARE_EVENT_CLASS'
           trace_seq_printf(s, print);                                     \
                               ^~~~~
   4 warnings generated.


vim +65 include/trace/events/xsk.h

    40	
    41		TP_PROTO(char *name, u16 queue_id, u32 reason, u64 val1, u64 val2, u64 val3),
    42	
    43		TP_ARGS(name, queue_id, reason, val1, val2, val3),
    44	
    45		TP_STRUCT__entry(
    46			__field(char *, name)
    47			__field(u16, queue_id)
    48			__field(u32, reason)
    49			__field(u64, val1)
    50			__field(u64, val2)
    51			__field(u64, val3)
    52		),
    53	
    54		TP_fast_assign(
    55			__entry->name = name;
    56			__entry->queue_id = queue_id;
    57			__entry->reason = reason;
    58			__entry->val1 = val1;
    59			__entry->val2 = val2;
    60			__entry->val3 = val3;
    61		),
    62	
    63		TP_printk("netdev: %s qid %u reason: %s: %s %lu %s %lu %s %lu",
    64			  __entry->name, __entry->queue_id, print_reason(__entry->reason),
  > 65			  print_val1(__entry->reason), __entry->val1,
    66			  print_val2(__entry->reason), __entry->val2,
    67			  print_val3(__entry->reason), __entry->val3
    68		)
    69	);
    70	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index 1df56a32d2df..efe6662d4198 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -19440,6 +19440,7 @@  S:	Maintained
 F:	Documentation/networking/af_xdp.rst
 F:	include/net/xdp_sock*
 F:	include/net/xsk_buff_pool.h
+F:	include/trace/events/xsk.h
 F:	include/uapi/linux/if_xdp.h
 F:	include/uapi/linux/xdp_diag.h
 F:	include/net/netns/xdp.h
diff --git a/include/linux/bpf_trace.h b/include/linux/bpf_trace.h
index ddf896abcfb6..477d29b6c2c1 100644
--- a/include/linux/bpf_trace.h
+++ b/include/linux/bpf_trace.h
@@ -3,5 +3,6 @@ 
 #define __LINUX_BPF_TRACE_H__
 
 #include <trace/events/xdp.h>
+#include <trace/events/xsk.h>
 
 #endif /* __LINUX_BPF_TRACE_H__ */
diff --git a/include/trace/events/xsk.h b/include/trace/events/xsk.h
new file mode 100644
index 000000000000..74b53b10c40b
--- /dev/null
+++ b/include/trace/events/xsk.h
@@ -0,0 +1,73 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright(c) 2021 Intel Corporation. */
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM xsk
+
+#if !defined(_TRACE_XSK_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_XSK_H
+
+#include <linux/if_xdp.h>
+#include <linux/tracepoint.h>
+
+#define print_reason(reason) \
+	__print_symbolic(reason, \
+			{ XSK_TRACE_DROP_PKT_TOO_BIG, "packet too big" }, \
+			{ XSK_TRACE_DROP_INVALID_FILLADDR, "invalid fill addr" }, \
+			{ XSK_TRACE_DROP_INVALID_TXD, "invalid tx desc" })
+
+#define print_val1(reason) \
+	__print_symbolic(reason, \
+			{ XSK_TRACE_DROP_PKT_TOO_BIG, "len" }, \
+			{ XSK_TRACE_DROP_INVALID_FILLADDR, "addr" }, \
+			{ XSK_TRACE_DROP_INVALID_TXD, "addr" })
+
+#define print_val2(reason) \
+	__print_symbolic(reason, \
+			{ XSK_TRACE_DROP_PKT_TOO_BIG, "max" }, \
+			{ XSK_TRACE_DROP_INVALID_FILLADDR, "not_used" }, \
+			{ XSK_TRACE_DROP_INVALID_TXD, "len" })
+
+#define print_val3(reason) \
+	__print_symbolic(reason, \
+			{ XSK_TRACE_DROP_PKT_TOO_BIG, "not_used" }, \
+			{ XSK_TRACE_DROP_INVALID_FILLADDR, "not_used" }, \
+			{ XSK_TRACE_DROP_INVALID_TXD, "options" })
+
+
+
+TRACE_EVENT(xsk_packet_drop,
+
+	TP_PROTO(char *name, u16 queue_id, u32 reason, u64 val1, u64 val2, u64 val3),
+
+	TP_ARGS(name, queue_id, reason, val1, val2, val3),
+
+	TP_STRUCT__entry(
+		__field(char *, name)
+		__field(u16, queue_id)
+		__field(u32, reason)
+		__field(u64, val1)
+		__field(u64, val2)
+		__field(u64, val3)
+	),
+
+	TP_fast_assign(
+		__entry->name = name;
+		__entry->queue_id = queue_id;
+		__entry->reason = reason;
+		__entry->val1 = val1;
+		__entry->val2 = val2;
+		__entry->val3 = val3;
+	),
+
+	TP_printk("netdev: %s qid %u reason: %s: %s %lu %s %lu %s %lu",
+		  __entry->name, __entry->queue_id, print_reason(__entry->reason),
+		  print_val1(__entry->reason), __entry->val1,
+		  print_val2(__entry->reason), __entry->val2,
+		  print_val3(__entry->reason), __entry->val3
+	)
+);
+
+#endif /* _TRACE_XSK_H */
+
+#include <trace/define_trace.h>
diff --git a/include/uapi/linux/if_xdp.h b/include/uapi/linux/if_xdp.h
index a78a8096f4ce..d7eb031d2465 100644
--- a/include/uapi/linux/if_xdp.h
+++ b/include/uapi/linux/if_xdp.h
@@ -108,4 +108,10 @@  struct xdp_desc {
 
 /* UMEM descriptor is __u64 */
 
+enum xdp_trace_reasons {
+	XSK_TRACE_DROP_PKT_TOO_BIG,
+	XSK_TRACE_DROP_INVALID_FILLADDR,
+	XSK_TRACE_DROP_INVALID_TXD,
+};
+
 #endif /* _LINUX_IF_XDP_H */
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 5bbd4884ff7a..442b0d7f9bf8 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -2362,3 +2362,4 @@  EXPORT_SYMBOL(bpf_stats_enabled_key);
 
 EXPORT_TRACEPOINT_SYMBOL_GPL(xdp_exception);
 EXPORT_TRACEPOINT_SYMBOL_GPL(xdp_bulk_tx);
+EXPORT_TRACEPOINT_SYMBOL_GPL(xsk_packet_drop);
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index 4faabd1ecfd1..689da22c8e4f 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -11,6 +11,7 @@ 
 
 #define pr_fmt(fmt) "AF_XDP: %s: " fmt, __func__
 
+#include <linux/bpf_trace.h>
 #include <linux/if_xdp.h>
 #include <linux/init.h>
 #include <linux/sched/mm.h>
@@ -189,9 +190,13 @@  static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
 	struct xdp_buff *xsk_xdp;
 	int err;
 	u32 len;
+	u32 max = xsk_pool_get_rx_frame_size(xs->pool);
 
 	len = xdp->data_end - xdp->data;
-	if (len > xsk_pool_get_rx_frame_size(xs->pool)) {
+	if (len > max) {
+		trace_xsk_packet_drop(xs->dev->name, xs->queue_id,
+				      XSK_TRACE_DROP_PKT_TOO_BIG,
+				      len, max, 0);
 		xs->rx_dropped++;
 		return -ENOSPC;
 	}
diff --git a/net/xdp/xsk_buff_pool.c b/net/xdp/xsk_buff_pool.c
index 8de01aaac4a0..e0bd1bfd4324 100644
--- a/net/xdp/xsk_buff_pool.c
+++ b/net/xdp/xsk_buff_pool.c
@@ -1,5 +1,6 @@ 
 // SPDX-License-Identifier: GPL-2.0
 
+#include <linux/bpf_trace.h>
 #include <net/xsk_buff_pool.h>
 #include <net/xdp_sock.h>
 #include <net/xdp_sock_drv.h>
@@ -460,6 +461,8 @@  static struct xdp_buff_xsk *__xp_alloc(struct xsk_buff_pool *pool)
 		ok = pool->unaligned ? xp_check_unaligned(pool, &addr) :
 		     xp_check_aligned(pool, &addr);
 		if (!ok) {
+			trace_xsk_packet_drop(pool->netdev->name, pool->queue_id,
+					       XSK_TRACE_DROP_INVALID_FILLADDR, addr, 0, 0);
 			pool->fq->invalid_descs++;
 			xskq_cons_release(pool->fq);
 			continue;
diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h
index 2823b7c3302d..8e9ba3cfe286 100644
--- a/net/xdp/xsk_queue.h
+++ b/net/xdp/xsk_queue.h
@@ -6,6 +6,7 @@ 
 #ifndef _LINUX_XSK_QUEUE_H
 #define _LINUX_XSK_QUEUE_H
 
+#include <linux/bpf_trace.h>
 #include <linux/types.h>
 #include <linux/if_xdp.h>
 #include <net/xdp_sock.h>
@@ -175,6 +176,9 @@  static inline bool xskq_cons_is_valid_desc(struct xsk_queue *q,
 					   struct xsk_buff_pool *pool)
 {
 	if (!xp_validate_desc(pool, d)) {
+		trace_xsk_packet_drop(pool->netdev->name, pool->queue_id,
+				       XSK_TRACE_DROP_INVALID_TXD, d->addr,
+				       d->len, d->options);
 		q->invalid_descs++;
 		return false;
 	}
diff --git a/tools/include/uapi/linux/if_xdp.h b/tools/include/uapi/linux/if_xdp.h
index a78a8096f4ce..d7eb031d2465 100644
--- a/tools/include/uapi/linux/if_xdp.h
+++ b/tools/include/uapi/linux/if_xdp.h
@@ -108,4 +108,10 @@  struct xdp_desc {
 
 /* UMEM descriptor is __u64 */
 
+enum xdp_trace_reasons {
+	XSK_TRACE_DROP_PKT_TOO_BIG,
+	XSK_TRACE_DROP_INVALID_FILLADDR,
+	XSK_TRACE_DROP_INVALID_TXD,
+};
+
 #endif /* _LINUX_IF_XDP_H */