bpf, sockmap: Introduce tracing capability for sockmap
Subsystems (6)
Jiayuan Chen
maintainerPATCH v2 1/1 bpf, sockmap: Introduce tracing capability for sockmap
Sockmap has the same high-performance forwarding capability as XDP, but operates at Layer 7.
Introduce tracing capability for sockmap, to trace the execution results of BPF programs without modifying the programs themselves, similar to the existing trace_xdp_redirect{_map}.
It is crucial for debugging sockmap programs, especially in production environments.
Additionally, the new header file has to be added to bpf_trace.h to automatically generate tracepoints.
Test results:
$ echo "1" > /sys/kernel/tracing/events/sockmap/enable
msg/skb:
'''sockmap_redirect: sk=000000000ec02a93, netns=4026531840, inode=318, \
family=2, protocol=6, prog_id=59, len=8192, type=msg, action=REDIRECT, \
redirect_type=ingress
sockmap_redirect: sk=00000000d5d9c931, netns=4026531840, inode=64731, \
family=2, protocol=6, prog_id=91, len=8221, type=skb, action=REDIRECT, \
redirect_type=egress
sockmap_redirect: sk=00000000106fc281, netns=4026531840, inode=64729, \
family=2, protocol=6, prog_id=94, len=8192, type=msg, action=PASS, \
redirect_type=none
'''
strparser:
'''sockmap_strparser: sk=00000000f15fc1c8, netns=4026531840, inode=52396, \
family=2, protocol=6, prog_id=143, in_len=1000, full_len=10 '''
---
v1 -> v2: Print more valuable information as suggested by the maintainer.
--- MAINTAINERS | 1 + include/linux/bpf_trace.h | 1 + include/trace/events/sockmap.h | 158 +++++++++++++++++++++++++++++++++ net/core/skmsg.c | 6 ++ 4 files changed, 166 insertions(+) create mode 100644 include/trace/events/sockmap.h
MAINTAINERS +1 -0
@@ -4420,6 +4420,7 @@ L: [email protected] L: [email protected] S: Maintained F: include/linux/skmsg.h +F: include/trace/events/sockmap.h F: net/core/skmsg.c F: net/core/sock_map.c F: net/ipv4/tcp_bpf.c
include/linux/bpf_trace.h +1 -0
@@ -3,5 +3,6 @@#define __LINUX_BPF_TRACE_H__#include <trace/events/xdp.h> +#include <trace/events/sockmap.h> #endif /* __LINUX_BPF_TRACE_H__ */
include/trace/events/sockmap.h new file +158 -0
158 lines not on this page · raw message
net/core/skmsg.c +6 -0
@@ -9,6 +9,7 @@#include <net/tcp.h> #include <net/tls.h> #include <trace/events/sock.h> +#include <trace/events/sockmap.h> static bool sk_msg_try_coalesce_ok (struct sk_msg *msg,int elem_first_coalesce) {
@@ -910,6 +911,7 @@ int sk_psock_msg_verdict(struct sock *sk, struct sk_psock *psock,sock_hold (psock->sk_redir); } out: +trace_sockmap_skmsg_redirect (sk, prog, msg, ret);rcu_read_unlock ();return ret; }
@@ -981,6 +983,7 @@ int sk_psock_tls_strp_read(struct sk_psock *psock, struct sk_buff *skb) ret =bpf_prog_run_pin_on_cpu (prog, skb); ret =sk_psock_map_verd (ret,skb_bpf_redirect_fetch (skb)); skb->sk =NULL ; +trace_sockmap_skb_redirect (psock->sk, prog, skb, ret); }sk_psock_tls_verdict_apply (skb, psock, ret);rcu_read_unlock ();
@@ -1090,6 +1093,7 @@ static void sk_psock_strp_read(struct strparser *strp, struct sk_buff *skb)skb_bpf_set_strparser (skb); ret =sk_psock_map_verd (ret,skb_bpf_redirect_fetch (skb)); skb->sk =NULL ; +trace_sockmap_skb_redirect (sk, prog, skb, ret); }sk_psock_verdict_apply (psock, skb, ret); out:
@@ -1113,6 +1117,7 @@ static int sk_psock_strp_parse(struct strparser *strp, struct sk_buff *skb) skb->sk = psock->sk; ret =bpf_prog_run_pin_on_cpu (prog, skb); skb->sk =NULL ; +trace_sockmap_skb_strp_parse (psock->sk, prog, skb, ret); }rcu_read_unlock ();return ret;
@@ -1217,6 +1222,7 @@ static int sk_psock_verdict_recv(struct sock *sk, struct sk_buff *skb)skb_bpf_redirect_clear (skb); ret =bpf_prog_run_pin_on_cpu (prog, skb); ret =sk_psock_map_verd (ret,skb_bpf_redirect_fetch (skb)); +trace_sockmap_skb_redirect (psock->sk, prog, skb, ret); } ret =sk_psock_verdict_apply (psock, skb, ret);if (ret <0 )
Signature · 1 line
2.47.1
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Jiayuan,
kernel test robot noticed the following build errors:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Jiayuan-Chen/bpf-sockmap-Introduce-tracing-capability-for-sockmap/20250414-093146 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/20250411091634.336371-1-jiayuan.chen%40linux.dev patch subject: [PATCH bpf-next v2] bpf, sockmap: Introduce tracing capability for sockmap config: arm64-randconfig-001-20250414 (https://download.01.org/0day-ci/archive/20250414/[email protected]/config) compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project f819f46284f2a79790038e1f6649172789734ae8) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250414/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> ld.lld: error: undefined symbol: sock_i_ino >>> referenced by sockmap.h:70 (include/trace/events/sockmap.h:70) >>> kernel/bpf/core.o:(trace_event_raw_event_sockmap_redirect) in archive vmlinux.a >>> referenced by sockmap.h:121 (include/trace/events/sockmap.h:121) >>> kernel/bpf/core.o:(trace_event_raw_event_sockmap_strparser) in archive vmlinux.a
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Jiayuan Chen
maintainerQuoted 13 lines · kernel test robot
Hi Jiayuan,
kernel test robot noticed the following build errors:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Jiayuan-Chen/bpf-sockmap-Introduce-tracing-capability-for-sockmap/20250414-093146
base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
patch link: https://lore.kernel.org/r/20250411091634.336371-1-jiayuan.chen%40linux.dev
patch subject: [PATCH bpf-next v2] bpf, sockmap: Introduce tracing capability for sockmap
config: arm64-randconfig-001-20250414 (https://download.01.org/0day-ci/archive/20250414/[email protected]/config)
Quoted 18 lines
compiler: clang version 21.0.0git (https://github.com/llvm/llvm-project
f819f46284f2a79790038e1f6649172789734ae8)reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250414/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):Quoted 9 lines
Quoted 9 lines
ld.lld: error: undefined symbol:
sock_i_inoQuoted 4 lines
referenced by sockmap.h:70 (
include/trace/events/sockmap.h:70) kernel/bpf/core.o:(trace_event_raw_event_sockmap_redirect) in archive vmlinux.a referenced by sockmap.h:121 (include/trace/events/sockmap.h:121) kernel/bpf/core.o:(trace_event_raw_event_sockmap_strparser) in archive vmlinux.a
I see, CONFIG_NET is not set...
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Jiayuan,
kernel test robot noticed the following build errors:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Jiayuan-Chen/bpf-sockmap-Introduce-tracing-capability-for-sockmap/20250414-093146 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/20250411091634.336371-1-jiayuan.chen%40linux.dev patch subject: [PATCH bpf-next v2] bpf, sockmap: Introduce tracing capability for sockmap config: csky-randconfig-001-20250414 (https://download.01.org/0day-ci/archive/20250414/[email protected]/config) compiler: csky-linux-gcc (GCC) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250414/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
csky-linux-ld: kernel/bpf/core.o: in function `trace_event_raw_event_sockmap_redirect':
>> core.c:(.text+0x15e0): undefined reference to `sock_i_ino' csky-linux-ld: kernel/bpf/core.o: in function `trace_event_raw_event_sockmap_strparser': core.c:(.text+0x1684): undefined reference to `sock_i_ino' >> csky-linux-ld: core.c:(.text+0x1688): undefined reference to `init_net' >> csky-linux-ld: core.c:(.text+0x16a8): undefined reference to `sock_i_ino'
csky-linux-ld: kernel/bpf/core.o: in function `___bpf_prog_run':
core.c:(.text+0x1838): undefined reference to `sock_i_ino'
csky-linux-ld: core.c:(.text+0x183c): undefined reference to `init_net'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki