Thread (21 messages) 21 messages, 4 authors, 19d ago

Re: [PATCH v3 bpf-next 4/9] bpf: tcp: Guard fast-path bpf_tcp_ops_call() under per-socket flag.

flat view

From: Kuniyuki Iwashima <kuniyu@google.com>
Date: 2026-10-05 19:13:29
Also in: bpf

On Mon, Oct 5, 2026 at 12:10 PM Amery Hung [off-list ref] wrote:
On Mon, Oct 5, 2026 at 8:45 AM Kuniyuki Iwashima [off-list ref] wrote:
quoted
bpf_tcp_ops.{parse_hdr,hdr_opt_len} are called for every
incoming / outgoing skb.

bpf_tcp_ops.rtt is called once per RTT, which is every
incoming skb in ping-pong workloads like tcp_rr.

Even attaching NULL callbacks in the fast path hurts performance.

Let's guard them (and write_hdr_opt) with the new per-socket flags.

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
---
 include/net/tcp.h     |  3 ++-
 net/ipv4/tcp_input.c  |  7 +++++++
 net/ipv4/tcp_output.c | 20 +++++++++++---------
 3 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index f69091f5e01f..48487135c076 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -3142,7 +3142,8 @@ static inline void tcp_bpf_rtt(struct sock *sk, long mrtt, u32 srtt)
 {90
        if (BPF_SOCK_OPS_TEST_FLAG(tcp_sk(sk), BPF_SOCK_OPS_RTT_CB_FLAG))
                tcp_call_bpf_2arg(sk, BPF_SOCK_OPS_RTT_CB, mrtt, srtt);
-       bpf_tcp_ops_call(rtt, sk, mrtt, srtt);
+       if (BPF_TCP_OPS_TEST_FLAG(tcp_sk(sk), RTT))
+               bpf_tcp_ops_call(rtt, sk, mrtt, srtt);
The new per-socket flag load happens before the static-key check
inside bpf_tcp_ops_call(). Thus, even when no bpf_tcp_ops is attached
anywhere, every RTT sample (and other similar places) now touches
tp->bpf_tcp_ops_flags, whereas previously the path stopped at the
disabled static branch.

Can we add something like bpf_tcp_ops_call_flag(op, flag, sk, ...),
with the static-key check first and the flag check before the cgroup
lookup/array scan? This would preserve both the no-attachment fast
path and the flag-clear optimization for attached programs.
Makes sense, I'll add that in v4.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help