From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.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 260B34A8A3E for ; Tue, 6 Oct 2026 19:26:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791314789; cv=none; b=TePUeCRxmkIc01FkTCU1O7Wt+ftmq3sFEl5XT83lvaHnyZ6cEQOaROckqUNwS0AY11GCkCeAPnL7QPSS8AXw9k4ySbJgJ0k9rL0OH8FJZ0n7fdfSBhW8STdXAL+Fbvrt5A9ZAuUeQaZXPZpX6WqCTq9uyJpMm9IpXRvcQguArXQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791314789; c=relaxed/simple; bh=+KbLmsJgbCpsRE2TpVJS149pVOWFQIlDi8Ye9ATEYVY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fa6asp/SkhN9V6UMkB4W4SMo4xuKBKXcm8eJ25VLo8lecbtdGrpaTBPLcALHxtoJ6s76YC7ejPeFoafA7Q2ER5FHyVnS2cm2fkdzMa6NHNBdaqg5qI0UrXbuMxD/V3HAh0Q66EUUoFsAiPjtTrtm+rYTBKpwi7pOPvz8ZbyN610= 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=aYI75SFg; arc=none smtp.client-ip=209.85.215.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="aYI75SFg" Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-cc7e0321ec1so3468989a12.0 for ; Tue, 06 Oct 2026 12:26:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1791314788; x=1791919588; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=LBgRk2qc0jw9FV7CDv8XbUFpGaTrixA96Y4TcCIuQbA=; b=aYI75SFgR4u/zWdCA2gW3hI2isInFa5I/XZXB8XNvDYrxbUEg6WpyYd8YDUD9V6/Y6 ALPhTqjhtv5drXDZqCBp3LutE6BlLqsKLX31Zb4BENT4ModhNwo0EOcJ671m+eav5s+m xQMdfeqzt2maBl6proS2aDt7N7uQWi4p0l2H1404KBc/Kcux2s42nEUkJR6ty1IjVPYZ NrdzHnMMHxP9m6rxDu/jYxP1Mxja0F6v2YMNYNV3nFwZu1pHGQuowWfO6ynteejWnonA U0Gr9PjBFIUMwljJl5dYP4N4Lr11niYGtQp5HjNmGskYckny7Nk+huuM3zMekfpaqYoE vJ/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791314788; x=1791919588; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=LBgRk2qc0jw9FV7CDv8XbUFpGaTrixA96Y4TcCIuQbA=; b=f9EGUwlsLoTheq+lxuF687m4opJE3JJBsu19vCB4WVcdjMQ8+OSsN+MQvGVmPV2p6l 1hhU/4WugQRzf+Lfh4S+/Rz+OQpMut9uxhd3bZ3LRjHPMc3X5YDpkMHcmu4lUhmS2iQG JQnLYYcad0YhvzBTy88tSoG66JmLimE0sUX7xtljCX2emrOZ0G+KQrLSVtCEfhMWSA1k /xlDeEC8d9K4iV1nfubGL2evre4cKyk/R/Pz5e6CN9jQrzvndKXFjcDIOw3kexMp/LxT /imZaEOuguXt9OdWidLhgcQpxl/9x+8uVQGZSPpHL6yFj5sJHrAwS2/SSp8vSuI0LWJQ 3NHA== X-Forwarded-Encrypted: i=1; AKwUvBwDdD4wIZBmpfM6OLffiwC8fjpgU38NRIVNZajPalMlNOpJ+k1uVWgnlUWtIDZZllV0bM1XGko=@vger.kernel.org X-Gm-Message-State: AFq9FYI8ao8ursVG4DAVrbXoagboVNK7D2Z0/7VRv+aw8sktaQI1R2qX fJkJilyUQb4+lyClPnEkbTMI2Qu8pXpywKw5I8EVfQAyg/pAluY+uA4/DI5F7lIyw2W2eFBq2gW mXnVRXg== X-Received: from plcn4.prod.google.com ([2002:a17:902:d2c4:b0:2df:8129:75b6]) (user=kuniyu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:ac7:b0:2e2:e6f1:5e10 with SMTP id d9443c01a7336-2e5ffaf0558mr3130455ad.4.1791314787378; Tue, 06 Oct 2026 12:26:27 -0700 (PDT) Date: Tue, 6 Oct 2026 19:24:35 +0000 In-Reply-To: <20261006192601.1875100-1-kuniyu@google.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20261006192601.1875100-1-kuniyu@google.com> X-Mailer: git-send-email 2.56.0.360.g66cac248cb-goog Message-ID: <20261006192601.1875100-10-kuniyu@google.com> Subject: [PATCH v4 bpf-next 09/10] bpf: tcp: Add kfunc to adjust sk->sk_rcvlowat. From: Kuniyuki Iwashima To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Kumar Kartikeya Dwivedi Cc: Amery Hung , 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, Emil Tsalapatis Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable bpf_tcp_ops.{enqueue,dequeue}_rcvq() were added to parse skb and adjust sk->sk_rcvlowat dynamically to suppress unnecessary wakeups. Let's add a new kfunc to set sk->sk_rcvlowat. Negative values are clamped to INT_MAX, consistent with SO_RCVLOWAT. For enqueue_rcvq(), wakeup is set to false because: * tcp_data_ready() is always called after the hooks in tcp_queue_rcv() and tcp_ofo_queue(). * when tcp_fastopen_add_skb() is called for TFO SYN, the socket is not yet accept()ed, and when called for TFO SYN+ACK, the socket is woken up by sk->sk_state_change() anyway. For dequeue_rcvq(), wakeup is set to true because tcp_data_ready() is not called in that path. An alternative would be to support bpf_setsockopt() for these hooks. However, that approach involves excessive conditionals and an unnecessary memcpy(), costs we do not want to pay for every skb in the TCP fast path. Signed-off-by: Kuniyuki Iwashima Acked-by: Stanislav Fomichev Tested-by: Cl=C3=A9ment L=C3=A9ger Reviewed-by: Emil Tsalapatis --- net/ipv4/bpf_tcp_ops.c | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/net/ipv4/bpf_tcp_ops.c b/net/ipv4/bpf_tcp_ops.c index 8182037c4269..2ba73dd6c52c 100644 --- a/net/ipv4/bpf_tcp_ops.c +++ b/net/ipv4/bpf_tcp_ops.c @@ -361,12 +361,31 @@ __bpf_kfunc int bpf_tcp_ops_set_flags(struct tcp_sock= *tp, u32 enable, u32 disab return 0; } =20 +__bpf_kfunc int bpf_tcp_ops_set_rcvlowat(struct sock *sk, int rcvlowat, + const struct bpf_prog_aux *aux) +{ + u32 moff =3D aux->attach_st_ops_member_off; + bool wakeup =3D false; + + if (moff =3D=3D offsetof(struct bpf_tcp_ops, dequeue_rcvq)) + wakeup =3D true; + + if (rcvlowat < 0) + rcvlowat =3D INT_MAX; + + return __tcp_set_rcvlowat(sk, rcvlowat, wakeup); +} + __bpf_kfunc_end_defs(); =20 BTF_KFUNCS_START(bpf_tcp_ops_set_flags_kfunc_set) BTF_ID_FLAGS(func, bpf_tcp_ops_set_flags) BTF_KFUNCS_END(bpf_tcp_ops_set_flags_kfunc_set) =20 +BTF_KFUNCS_START(bpf_tcp_ops_set_rcvlowat_kfunc_set) +BTF_ID_FLAGS(func, bpf_tcp_ops_set_rcvlowat, KF_IMPLICIT_ARGS) +BTF_KFUNCS_END(bpf_tcp_ops_set_rcvlowat_kfunc_set) + static int bpf_tcp_ops_set_flags_kfunc_filter(const struct bpf_prog *prog, u32 kfunc_id) { @@ -390,6 +409,31 @@ static const struct btf_kfunc_id_set bpf_tcp_ops_set_f= lags_kfunc_id_set =3D { .filter =3D bpf_tcp_ops_set_flags_kfunc_filter, }; =20 +static int bpf_tcp_ops_set_rcvlowat_kfunc_filter(const struct bpf_prog *pr= og, + u32 kfunc_id) +{ + u32 moff; + + if (!btf_id_set8_contains(&bpf_tcp_ops_set_rcvlowat_kfunc_set, kfunc_id)) + return 0; + + if (prog->aux->st_ops !=3D &bpf_tcp_ops) + return -EACCES; + + moff =3D prog->aux->attach_st_ops_member_off; + if (moff !=3D offsetof(struct bpf_tcp_ops, enqueue_rcvq) && + moff !=3D offsetof(struct bpf_tcp_ops, dequeue_rcvq)) + return -EACCES; + + return 0; +} + +static const struct btf_kfunc_id_set bpf_tcp_ops_set_rcvlowat_kfunc_id_set= =3D { + .owner =3D THIS_MODULE, + .set =3D &bpf_tcp_ops_set_rcvlowat_kfunc_set, + .filter =3D bpf_tcp_ops_set_rcvlowat_kfunc_filter, +}; + static int __init __bpf_tcp_ops_init(void) { int ret; @@ -399,6 +443,8 @@ static int __init __bpf_tcp_ops_init(void) /* BPF_PROG_TYPE_CGROUP_{SOCKOPT,SKB} share BTF_KFUNC_HOOK_CGROUP. */ ret =3D ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCKOPT, &bpf_tcp_ops_set_flags_kfunc_id_set); + ret =3D ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, + &bpf_tcp_ops_set_rcvlowat_kfunc_id_set); ret =3D ret ?: register_bpf_struct_ops(&bpf_tcp_ops, bpf_tcp_ops); =20 return ret; --=20 2.56.0.360.g66cac248cb-goog