From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3920C43DEC8 for ; Wed, 23 Sep 2026 21:37:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790199444; cv=none; b=E8fasXTSTuPpzp72bvs2/RvjDSBnKTSnnd6tukAs/6UrpwO7/X6xUxO3XdI2jZtuShhGuP27sd7hvxN4t1RaU0yxWYdAzDG+ragh/HnNwxskDN0PNW9o+gHPHFPJpqqg8rvvji5Wd6GyHH+yJ57FSzThE/Ti14WQlf9DyMFjCA4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790199444; c=relaxed/simple; bh=+g2TQZbj0y8d+xQ2Zm2UwnJZ3gjRdu0REmdwLwpE1L0=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=A6PIWLYXoXOYttcHZwnsRkxw5q4Uw/cRf4O4Z+mJTI1ieL5OnBKXOnCNc1iEWFMKFmIRxND8ZQk9kHcOz3EBdxMaXoYggqJva9Cys4D9zgMr4SrnP0S1cy1aSd8obPMiPAFvVmDxp1+oEZr18HvfDl8ap5lD1uR8tT0XTGjU9kw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=lNyYirKa; arc=none smtp.client-ip=209.85.210.197 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lNyYirKa" Received: by mail-pf1-f197.google.com with SMTP id d2e1a72fcca58-8633c0d7353so1064774b3a.3 for ; Wed, 23 Sep 2026 14:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1790199442; x=1790804242; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=27SgLD1I/Cvv7dG/kGYKQA4JzrNe4m10wNb0sLptOo0=; b=lNyYirKaFHsmSkJ1Et7sEgWn8ylkvQ+AxhfmJjELppScO4d7VHsou0mMyYi/9/zXSd EMwEMYbkDDmeO3mVJSPEjMqygVh0WmC82Jc5s5/rtLC63avSPCLNGOr5epH9qp63F0Dd +JL8jtm+Q8vnzx/OQEkE7A8C8M6lbpC+a3UyG5q7yrUVs0MUV+eSOwDpX136tCe88/Ay ek6H/uJtvQt2IH52l7srXmuf2GoaaeKq0Vesu9fw9bzVPHNldJgHHpiq/LJ3Qx/+oh53 7NKfZSwnGap/GF1z5LI1rjZuD0ud1Y0v2JSxEjNs1ESwQv2PkFYXnsmJHB2TTPsJLGPM EcAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790199442; x=1790804242; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=27SgLD1I/Cvv7dG/kGYKQA4JzrNe4m10wNb0sLptOo0=; b=m03hZ/+R4g3Wrv3F7eGLaGncpq1cGfhxafBgbD1+pX06HIDvqxJvlkTNh+bKp7Ko7q cz6JlxAXMwId2OEjJw+fwAt+OtQ0RNA0sdPOFDxhsbOju2MQqYfn9GfQV2eDOcaHe3tU cjr03m7MTlQC1jAqKzI5ZOYINMOGqorePZcW07NHe8GH5RTCAtVsdKQ8nfFcZVT44+wc nLi6P1r3E4md7ZykvTSxCU5k1hv8UvopZ5zqa26thFFv+GdZ/71foHy+h1ilZ1Br+FpE u4rCnihSUu7ykVnkuyeqXcunMmYz3MA3LBPX/Yxiobqb8qQavv2FrXcntB/AUxbgS7hO GqTA== X-Forwarded-Encrypted: i=1; AKwUvBzbd1efm0xXX9Ldjbfc+T47mZK2hmSXZ20yyDKl0Qrm7lhG4q/pPRwCxylj0Sj+c0QznChNotU=@vger.kernel.org X-Gm-Message-State: AFuF++kYoOz0Xd+qOM1im3aiBaQFbYwi5XeamSrDfQ6nxBTe1A4dD5Lb OuDMFh7sA0T+JcXfAv6LLXcKZfbFNvRprPy+/PTDoMuS8hc53Ovl9iVroviHm+WvFjtyb9J24V7 G2K/Wew== X-Received: from pfbgp6.prod.google.com ([2002:a05:6a00:3b86:b0:87a:d557:6bfe]) (user=kuniyu job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:6088:b0:87c:b5c0:738 with SMTP id d2e1a72fcca58-87e993770a9mr337321b3a.19.1790199442355; Wed, 23 Sep 2026 14:37:22 -0700 (PDT) Date: Wed, 23 Sep 2026 21:35:30 +0000 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.56.0.rc1.315.gc6ed9934b7-goog Message-ID: <20260923213719.224838-1-kuniyu@google.com> Subject: [PATCH v2 bpf-next 0/8] bpf: Add bpf_tcp_ops hooks for TCP AutoLOWAT. From: Kuniyuki Iwashima To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Kumar Kartikeya Dwivedi Cc: Yonghong Song , John Fastabend , Stanislav Fomichev , Eric Dumazet , Neal Cardwell , Willem de Bruijn , Tenzin Ukyab , "=?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?=" , Kuniyuki Iwashima , Kuniyuki Iwashima , bpf@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" This series introduces two callbacks for bpf_tcp_ops: .enqueue_rcvq(): invoked when TCP stack enqueues skb to sk->sk_receive_queue .dequeue_rcvq(): invoked in tcp_cleanup_rbuf() after data is dequeued from sk->sk_receive_queue Those callbacks can be enabled on a per-socket basis by bpf_setsockopt(): int flags = BPF_SOCK_OPS_RCVQ_CB_FLAG; bpf_setsockopt(sk, SOL_TCP, TCP_BPF_SOCK_OPS_CB_FLAGS, &flags, sizeof(flags)); or via the bpf_tcp_ops-specific helper added in the next patch: bpf_sock_ops_cb_flags_set(sk, BPF_SOCK_OPS_RCVQ_CB_FLAG); This allows the BPF prog to dynamically adjust sk->sk_rcvlowat, suppressing unnecessary EPOLLIN wakeups until sufficient data is available in the receive queue. This functionality, which we call "TCP AutoLOWAT", was originally developed in 2020 by Tenzin Ukyab with the help of Soheil Hassas Yeganeh, Arjun Roy, and Eric Dumazet. It has served Google RPC workloads for more than 5 years. Combined with TCP RX zerocopy, this typically allows us to read an entire RPC frame with just a single wakeup and a single system call. While the original implementation was specialised for our internal RPC format, this series introduces a more flexible version by leveraging BPF. The bpf prog in the last selftest patch closely mirrors the core logic of the original implementation to provide a real-world example. Note that the new callbacks are not supported on legacy SOCK_OPS. Changes: v2: * Add patch 1 not to allow setsockopt() from new callbacks * Patch 8 (selftest) * Avoid address comparison for a specific version of gcc. * Make rpc_test_cases[] static. * Update comment in rpc_test_case[]. v1: https://lore.kernel.org/bpf/20260920195633.3033620-1-kuniyu@google.com/ Legacy SOCK_OPS version: v3: https://lore.kernel.org/bpf/20260523083001.2911931-1-kuniyu@google.com/ v2: https://lore.kernel.org/bpf/20260522074601.1658705-1-kuniyu@google.com/ v1: https://lore.kernel.org/bpf/20260508073355.3916746-1-kuniyu@google.com/ Kuniyuki Iwashima (8): bpf: tcp: Convert deny-list for bpf_{get,set}sockopt() to allow-list. selftest: bpf: Use BPF_SOCK_OPS_ALL_CB_FLAGS + 1 for bad_cb_test_rv. bpf: tcp: Introduce bpf_tcp_ops.{enqueue,dequeue}_rcvq(). bpf: tcp: Support bpf_sock_ops_cb_flags_set() for bpf_tcp_ops. tcp: Split out __tcp_set_rcvlowat(). bpf: mptcp: Don't support BPF_SOCK_OPS_RCVQ_CB_FLAG. bpf: tcp: Add kfunc to adjust sk->sk_rcvlowat. selftest: bpf: Add test for bpf_tcp_ops.{enqueue,dequeue}_rcvq(). include/net/tcp.h | 34 ++ include/uapi/linux/bpf.h | 13 +- net/core/filter.c | 10 +- net/ipv4/bpf_tcp_ops.c | 135 ++++++- net/ipv4/tcp.c | 14 +- net/ipv4/tcp_fastopen.c | 2 + net/ipv4/tcp_input.c | 4 + tools/include/uapi/linux/bpf.h | 13 +- .../selftests/bpf/prog_tests/tcp_autolowat.c | 350 ++++++++++++++++++ .../selftests/bpf/prog_tests/tcpbpf_user.c | 3 +- .../selftests/bpf/progs/bpf_tracing_net.h | 2 + .../selftests/bpf/progs/tcp_autolowat.c | 312 ++++++++++++++++ .../selftests/bpf/progs/test_tcpbpf_kern.c | 3 +- 13 files changed, 866 insertions(+), 29 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/tcp_autolowat.c create mode 100644 tools/testing/selftests/bpf/progs/tcp_autolowat.c -- 2.56.0.rc1.315.gc6ed9934b7-goog