Context |
Check |
Description |
netdev/series_format |
success
|
Single patches do not need cover letters
|
netdev/tree_selection |
success
|
Clearly marked for bpf-next, async
|
netdev/ynl |
success
|
Generated files up to date;
no warnings/errors;
no diff in generated;
|
netdev/fixes_present |
success
|
Fixes tag not required for -next series
|
netdev/header_inline |
success
|
No static functions without inline keyword in header files
|
netdev/build_32bit |
success
|
Errors and warnings before: 0 this patch: 0
|
netdev/build_tools |
success
|
Errors and warnings before: 26 (+2) this patch: 26 (+2)
|
netdev/cc_maintainers |
success
|
CCed 24 of 24 maintainers
|
netdev/build_clang |
success
|
Errors and warnings before: 0 this patch: 0
|
netdev/verify_signedoff |
success
|
Signed-off-by tag matches author and committer
|
netdev/deprecated_api |
success
|
None detected
|
netdev/check_selftest |
success
|
No net selftest shell script
|
netdev/verify_fixes |
success
|
No Fixes tag
|
netdev/build_allmodconfig_warn |
success
|
Errors and warnings before: 78 this patch: 78
|
netdev/checkpatch |
warning
|
CHECK: Alignment should match open parenthesis
CHECK: Lines should not end with a '('
WARNING: quoted string split across lines
|
netdev/build_clang_rust |
success
|
No Rust files in patch. Skipping build
|
netdev/kdoc |
success
|
Errors and warnings before: 0 this patch: 0
|
netdev/source_inline |
success
|
Was 0 now: 0
|
bpf/vmtest-bpf-next-PR |
success
|
PR summary
|
bpf/vmtest-bpf-next-VM_Test-1 |
success
|
Logs for ShellCheck
|
bpf/vmtest-bpf-next-VM_Test-0 |
success
|
Logs for Lint
|
bpf/vmtest-bpf-next-VM_Test-2 |
success
|
Logs for Unittests
|
bpf/vmtest-bpf-next-VM_Test-3 |
success
|
Logs for Validate matrix.py
|
bpf/vmtest-bpf-next-VM_Test-5 |
success
|
Logs for aarch64-gcc / build / build for aarch64 with gcc
|
bpf/vmtest-bpf-next-VM_Test-4 |
success
|
Logs for aarch64-gcc / GCC BPF
|
bpf/vmtest-bpf-next-VM_Test-6 |
success
|
Logs for aarch64-gcc / build-release
|
bpf/vmtest-bpf-next-VM_Test-7 |
success
|
Logs for aarch64-gcc / test (test_maps, false, 360) / test_maps on aarch64 with gcc
|
bpf/vmtest-bpf-next-VM_Test-11 |
success
|
Logs for aarch64-gcc / veristat-kernel
|
bpf/vmtest-bpf-next-VM_Test-12 |
success
|
Logs for aarch64-gcc / veristat-meta
|
bpf/vmtest-bpf-next-VM_Test-13 |
success
|
Logs for s390x-gcc / GCC BPF
|
bpf/vmtest-bpf-next-VM_Test-14 |
success
|
Logs for s390x-gcc / build / build for s390x with gcc
|
bpf/vmtest-bpf-next-VM_Test-15 |
success
|
Logs for s390x-gcc / build-release
|
bpf/vmtest-bpf-next-VM_Test-19 |
success
|
Logs for s390x-gcc / veristat-kernel
|
bpf/vmtest-bpf-next-VM_Test-20 |
success
|
Logs for s390x-gcc / veristat-meta
|
bpf/vmtest-bpf-next-VM_Test-21 |
success
|
Logs for set-matrix
|
bpf/vmtest-bpf-next-VM_Test-22 |
success
|
Logs for x86_64-gcc / GCC BPF / GCC BPF
|
bpf/vmtest-bpf-next-VM_Test-23 |
success
|
Logs for x86_64-gcc / build / build for x86_64 with gcc
|
bpf/vmtest-bpf-next-VM_Test-24 |
success
|
Logs for x86_64-gcc / build-release
|
bpf/vmtest-bpf-next-VM_Test-25 |
success
|
Logs for x86_64-gcc / test (test_maps, false, 360) / test_maps on x86_64 with gcc
|
bpf/vmtest-bpf-next-VM_Test-34 |
success
|
Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17
|
bpf/vmtest-bpf-next-VM_Test-33 |
success
|
Logs for x86_64-llvm-17 / GCC BPF / GCC BPF
|
bpf/vmtest-bpf-next-VM_Test-44 |
success
|
Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
|
bpf/vmtest-bpf-next-VM_Test-42 |
success
|
Logs for x86_64-llvm-18 / GCC BPF / GCC BPF
|
bpf/vmtest-bpf-next-VM_Test-40 |
success
|
Logs for x86_64-llvm-17 / veristat-kernel
|
bpf/vmtest-bpf-next-VM_Test-35 |
success
|
Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
|
bpf/vmtest-bpf-next-VM_Test-41 |
success
|
Logs for x86_64-llvm-17 / veristat-meta
|
bpf/vmtest-bpf-next-VM_Test-43 |
success
|
Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
|
bpf/vmtest-bpf-next-VM_Test-26 |
success
|
Logs for x86_64-gcc / test (test_progs, false, 360) / test_progs on x86_64 with gcc
|
bpf/vmtest-bpf-next-VM_Test-50 |
success
|
Logs for x86_64-llvm-18 / veristat-kernel
|
bpf/vmtest-bpf-next-VM_Test-51 |
success
|
Logs for x86_64-llvm-18 / veristat-meta
|
bpf/vmtest-bpf-next-VM_Test-8 |
success
|
Logs for aarch64-gcc / test (test_progs, false, 360) / test_progs on aarch64 with gcc
|
bpf/vmtest-bpf-next-VM_Test-10 |
success
|
Logs for aarch64-gcc / test (test_verifier, false, 360) / test_verifier on aarch64 with gcc
|
bpf/vmtest-bpf-next-VM_Test-32 |
success
|
Logs for x86_64-gcc / veristat-meta / x86_64-gcc veristat_meta
|
bpf/vmtest-bpf-next-VM_Test-36 |
success
|
Logs for x86_64-llvm-17 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-17
|
bpf/vmtest-bpf-next-VM_Test-39 |
success
|
Logs for x86_64-llvm-17 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-17
|
bpf/vmtest-bpf-next-VM_Test-27 |
success
|
Logs for x86_64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with gcc
|
bpf/vmtest-bpf-next-VM_Test-9 |
success
|
Logs for aarch64-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on aarch64 with gcc
|
bpf/vmtest-bpf-next-VM_Test-29 |
success
|
Logs for x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
|
bpf/vmtest-bpf-next-VM_Test-18 |
success
|
Logs for s390x-gcc / test (test_verifier, false, 360) / test_verifier on s390x with gcc
|
bpf/vmtest-bpf-next-VM_Test-17 |
success
|
Logs for s390x-gcc / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on s390x with gcc
|
bpf/vmtest-bpf-next-VM_Test-16 |
success
|
Logs for s390x-gcc / test (test_progs, false, 360) / test_progs on s390x with gcc
|
bpf/vmtest-bpf-next-VM_Test-28 |
success
|
Logs for x86_64-gcc / test (test_progs_no_alu32_parallel, true, 30) / test_progs_no_alu32_parallel on x86_64 with gcc
|
bpf/vmtest-bpf-next-VM_Test-30 |
success
|
Logs for x86_64-gcc / test (test_verifier, false, 360) / test_verifier on x86_64 with gcc
|
bpf/vmtest-bpf-next-VM_Test-31 |
success
|
Logs for x86_64-gcc / veristat-kernel / x86_64-gcc veristat_kernel
|
bpf/vmtest-bpf-next-VM_Test-49 |
success
|
Logs for x86_64-llvm-18 / test (test_verifier, false, 360) / test_verifier on x86_64 with llvm-18
|
bpf/vmtest-bpf-next-VM_Test-37 |
success
|
Logs for x86_64-llvm-17 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-17
|
bpf/vmtest-bpf-next-VM_Test-47 |
success
|
Logs for x86_64-llvm-18 / test (test_progs_cpuv4, false, 360) / test_progs_cpuv4 on x86_64 with llvm-18
|
bpf/vmtest-bpf-next-VM_Test-48 |
success
|
Logs for x86_64-llvm-18 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-18
|
bpf/vmtest-bpf-next-VM_Test-38 |
success
|
Logs for x86_64-llvm-17 / test (test_progs_no_alu32, false, 360) / test_progs_no_alu32 on x86_64 with llvm-17
|
bpf/vmtest-bpf-next-VM_Test-45 |
success
|
Logs for x86_64-llvm-18 / test (test_maps, false, 360) / test_maps on x86_64 with llvm-18
|
bpf/vmtest-bpf-next-VM_Test-46 |
success
|
Logs for x86_64-llvm-18 / test (test_progs, false, 360) / test_progs on x86_64 with llvm-18
|
@@ -4420,6 +4420,7 @@ L: netdev@vger.kernel.org
L: bpf@vger.kernel.org
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
@@ -3,5 +3,6 @@
#define __LINUX_BPF_TRACE_H__
#include <trace/events/xdp.h>
+#include <trace/events/sockmap.h>
#endif /* __LINUX_BPF_TRACE_H__ */
new file mode 100644
@@ -0,0 +1,158 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM sockmap
+
+#if !defined(_TRACE_SOCKMAP_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_SOCKMAP_H
+
+#include <linux/tracepoint.h>
+#include <linux/bpf.h>
+#include <linux/skmsg.h>
+
+#ifndef __TRACE_SOCKMAP_HELPER_ONCE_ONLY
+#define __TRACE_SOCKMAP_HELPER_ONCE_ONLY
+
+enum sockmap_direct_type {
+ SOCKMAP_REDIR_NONE = 0,
+ SOCKMAP_REDIR_INGRESS,
+ SOCKMAP_REDIR_EGRESS,
+};
+
+enum sockmap_data_type {
+ SOCKMAP_MSG = 0,
+ SOCKMAP_SKB,
+};
+
+#endif /* end __TRACE_SOCKMAP_HELPER_ONCE_ONLY */
+
+TRACE_DEFINE_ENUM(SOCKMAP_MSG);
+TRACE_DEFINE_ENUM(SOCKMAP_SKB);
+TRACE_DEFINE_ENUM(SOCKMAP_REDIR_NONE);
+TRACE_DEFINE_ENUM(SOCKMAP_REDIR_INGRESS);
+TRACE_DEFINE_ENUM(SOCKMAP_REDIR_EGRESS);
+
+TRACE_DEFINE_ENUM(__SK_DROP);
+TRACE_DEFINE_ENUM(__SK_PASS);
+TRACE_DEFINE_ENUM(__SK_REDIRECT);
+TRACE_DEFINE_ENUM(__SK_NONE);
+
+#define show_redirect_type(x) \
+ __print_symbolic(x, \
+ { SOCKMAP_REDIR_NONE, "none" }, \
+ { SOCKMAP_REDIR_INGRESS, "ingress" }, \
+ { SOCKMAP_REDIR_EGRESS, "egress" })
+
+#define show_act(x) \
+ __print_symbolic(x, \
+ { __SK_DROP, "DROP" }, \
+ { __SK_PASS, "PASS" }, \
+ { __SK_REDIRECT, "REDIRECT" }, \
+ { __SK_NONE, "NONE" })
+
+#define show_data_type(x) \
+ __print_symbolic(x, \
+ { SOCKMAP_MSG, "msg" }, \
+ { SOCKMAP_SKB, "skb" })
+
+#define trace_sockmap_skmsg_redirect(sk, prog, msg, act) \
+ trace_sockmap_redirect((sk), SOCKMAP_MSG, (prog), \
+ (msg)->sg.size, (act), \
+ sk_msg_to_ingress(msg))
+
+#define trace_sockmap_skb_redirect(sk, prog, skb, act) \
+ trace_sockmap_redirect((sk), SOCKMAP_SKB, (prog), \
+ (skb)->len, (act), \
+ skb_bpf_ingress(skb))
+
+#define trace_sockmap_skb_strp_parse(sk, prog, skb, ret) \
+ trace_sockmap_strparser((sk), (prog), (skb)->len, (ret))
+
+TRACE_EVENT(sockmap_redirect,
+
+ TP_PROTO(const struct sock *sk, enum sockmap_data_type type,
+ const struct bpf_prog *prog, int len, int act,
+ bool ingress),
+
+ TP_ARGS(sk, type, prog, len, act, ingress),
+
+ TP_STRUCT__entry(
+ __field(const void *, sk)
+ __field(unsigned long, ino)
+ __field(unsigned int, netns_ino)
+ __field(__u16, family)
+ __field(__u16, protocol)
+ __field(int, prog_id)
+ __field(int, len)
+ __field(int, act)
+ __field(enum sockmap_data_type, type)
+ __field(enum sockmap_direct_type, redir)
+ ),
+
+ TP_fast_assign(
+ /* 'redir' is undefined if action is not REDIRECT */
+ enum sockmap_direct_type redir = SOCKMAP_REDIR_NONE;
+
+ if (act == __SK_REDIRECT) {
+ if (ingress)
+ redir = SOCKMAP_REDIR_INGRESS;
+ else
+ redir = SOCKMAP_REDIR_EGRESS;
+ }
+ __entry->sk = sk;
+ __entry->ino = sock_i_ino((struct sock *)sk);
+ __entry->netns_ino = sock_net(sk)->ns.inum;
+ __entry->type = type;
+ __entry->family = sk->sk_family;
+ __entry->protocol = sk->sk_protocol;
+ __entry->prog_id = prog->aux->id;
+ __entry->len = len;
+ __entry->act = act;
+ __entry->redir = redir;
+ ),
+
+ TP_printk("sk=%p, netns=%u, inode=%lu, family=%u, protocol=%u,"
+ " prog_id=%d, len=%d, type=%s, action=%s, redirect_type=%s",
+ __entry->sk, __entry->netns_ino, __entry->ino,
+ __entry->family, __entry->protocol, __entry->prog_id,
+ __entry->len, show_data_type(__entry->type),
+ show_act(__entry->act), show_redirect_type(__entry->redir))
+);
+
+TRACE_EVENT(sockmap_strparser,
+
+ TP_PROTO(const struct sock *sk, const struct bpf_prog *prog,
+ int in_len, int full_len),
+
+ TP_ARGS(sk, prog, in_len, full_len),
+
+ TP_STRUCT__entry(
+ __field(const void *, sk)
+ __field(unsigned long, ino)
+ __field(unsigned int, netns_ino)
+ __field(__u16, family)
+ __field(__u16, protocol)
+ __field(int, prog_id)
+ __field(int, in_len)
+ __field(int, full_len)
+ ),
+
+ TP_fast_assign(
+ __entry->sk = sk;
+ __entry->ino = sock_i_ino((struct sock *)sk);
+ __entry->netns_ino = sock_net(sk)->ns.inum;
+ __entry->family = sk->sk_family;
+ __entry->protocol = sk->sk_protocol;
+ __entry->prog_id = prog->aux->id;
+ __entry->in_len = in_len;
+ __entry->full_len = full_len;
+ ),
+
+ TP_printk("sk=%p, netns=%u, inode=%lu, family=%u, protocol=%u,"
+ " prog_id=%d, in_len=%d, full_len=%d",
+ __entry->sk, __entry->netns_ino, __entry->ino,
+ __entry->family, __entry->protocol, __entry->prog_id,
+ __entry->in_len, __entry->full_len)
+);
+#endif /* _TRACE_SOCKMAP_H */
+
+#include <trace/define_trace.h>
@@ -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)
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 ''' Suggested-by: Jakub Sitnicki <jakub@cloudflare.com> Suggested-by: Cong Wang <xiyou.wangcong@gmail.com> Suggested-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev> --- 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