From nobody Thu Jan 8 17:49:53 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B926143C61 for ; Sun, 4 Jan 2026 05:29:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767504596; cv=none; b=dPP8FokAZtHXK/NzC+imQ888z8ArWADbZ9b/bDw99LWDph32s4EyUPMoRVp2rIDe6yXng6SCgFtylWaMaSczG8Y4taD90caKbzbbULAw6fdylf9XTTHEViHtkWeVoDK2IOXUIhjQjhNnZ/fPXa9T29LRnQk3ZS47MhxP8BhZNUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767504596; c=relaxed/simple; bh=0ZJUYG4aAcOhwd+3x/4Sxfke82RmGeOFLgWpvICaIHs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JEV3xbE1hWeBe2IL2NUt10PrLusvL6n4oyNrHstkBZZ3C76JLunIXQqFulib6nVWH0SRm9An53L78KX6v3ii7q5nv5sjqficzPZxc9WTVvTA5JVQT7FgUOV36V8yuW7BRn8JwAySjSa5UJDlc/+DkGo5Mpkrn5/I3Mndpzvm/+s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BmyxK/gB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BmyxK/gB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12C05C4CEF7; Sun, 4 Jan 2026 05:29:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767504595; bh=0ZJUYG4aAcOhwd+3x/4Sxfke82RmGeOFLgWpvICaIHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BmyxK/gBPn4IIFPhQS2rsaXs88S5EL2+ZrwlM8JSD84OQhik73Klr1C4dVbFhymBf OgX0bp/CMujckY34mMAurhwPyT64jgQKBE7sBEPUnigmvdlotgJqvPqmTmYDG4ch+Q 3Aojnkey4TvWigNp2GRVqF7BeTGOqN/iUSuqtsUhjGEeB2cwsJONxtvepgSbwjNIUQ rqXZUk1RIziTvZNAv7BXb5XWawa6LcTqgKwbMvYuvQC49AMg7UNZfZ0O+VSTEYj+a6 L66/3mZ5xgr6i/n1hQWumi1Xn5LPS/RCc+k1puhJsNM4Ok4sN9dr/NkWU3fy0HlsBq t0pKVPAsvTjJg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , kernel test robot , Cong Wang Subject: [PATCH mptcp-next v2 1/3] mptcp: implement psock_update_sk_prot Date: Sun, 4 Jan 2026 13:29:42 +0800 Message-ID: <2dd903c035b44e5f117e322ff91dab859d430113.1767504329.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Add MPTCP support for BPF sockmap by implementing psock_update_sk_prot callback. This allows MPTCP sockets to dynamically switch protocol handlers when attached to or detached from sockmap programs. Separate protocol structures are maintained for IPv4/IPv6 and TX/RX configurations. tcp_bpf_update_proto() in net/ipv4/tcp_bpf.c is a frame of reference for this patch. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202512261144.DxrvwMS3-lkp@int= el.com/ Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/521 Cc: Cong Wang Signed-off-by: Geliang Tang --- net/mptcp/protocol.c | 105 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 900f26e21acd..0b655efb9bd8 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -4017,6 +4018,98 @@ static int mptcp_connect(struct sock *sk, struct soc= kaddr_unsized *uaddr, return 0; } =20 +#ifdef CONFIG_BPF_SYSCALL +enum { + MPTCP_BPF_IPV4, + MPTCP_BPF_IPV6, + MPTCP_BPF_NUM_PROTS, +}; + +enum { + MPTCP_BPF_BASE, + MPTCP_BPF_TX, + MPTCP_BPF_RX, + MPTCP_BPF_TXRX, + MPTCP_BPF_NUM_CFGS, +}; + +static struct proto mptcp_bpf_prots[MPTCP_BPF_NUM_PROTS][MPTCP_BPF_NUM_CFG= S]; + +static void mptcp_bpf_rebuild_protos(struct proto prot[MPTCP_BPF_NUM_CFGS], + struct proto *base) +{ + prot[MPTCP_BPF_BASE] =3D *base; + prot[MPTCP_BPF_BASE].destroy =3D sock_map_destroy; + prot[MPTCP_BPF_BASE].close =3D sock_map_close; + prot[MPTCP_BPF_BASE].sock_is_readable =3D sk_msg_is_readable; + + prot[MPTCP_BPF_TX] =3D prot[MPTCP_BPF_BASE]; + prot[MPTCP_BPF_RX] =3D prot[MPTCP_BPF_BASE]; + prot[MPTCP_BPF_TXRX] =3D prot[MPTCP_BPF_TX]; +} + +#if IS_ENABLED(CONFIG_MPTCP_IPV6) +static struct proto *mptcpv6_prot_saved __read_mostly; +static DEFINE_SPINLOCK(mptcpv6_prot_lock); + +static void mptcp_bpf_check_v6_needs_rebuild(struct proto *ops) +{ + /* + * Load with acquire semantics to ensure we see the latest protocol + * structure before checking for rebuild. + */ + if (unlikely(ops !=3D smp_load_acquire(&mptcpv6_prot_saved))) { + spin_lock_bh(&mptcpv6_prot_lock); + if (likely(ops !=3D mptcpv6_prot_saved)) { + mptcp_bpf_rebuild_protos(mptcp_bpf_prots[MPTCP_BPF_IPV6], ops); + /* Ensure mptcpv6_prot_saved update is visible before releasing lock */ + smp_store_release(&mptcpv6_prot_saved, ops); + } + spin_unlock_bh(&mptcpv6_prot_lock); + } +} + +static int mptcp_bpf_assert_proto_ops(struct proto *ops) +{ + /* In order to avoid retpoline, we make assumptions when we call + * into ops if e.g. a psock is not present. Make sure they are + * indeed valid assumptions. + */ + return ops->recvmsg =3D=3D mptcp_recvmsg && + ops->sendmsg =3D=3D mptcp_sendmsg ? 0 : -EOPNOTSUPP; +} +#endif + +static int mptcp_bpf_update_proto(struct sock *sk, struct sk_psock *psock,= bool restore) +{ + int family =3D sk->sk_family =3D=3D AF_INET6 ? MPTCP_BPF_IPV6 : MPTCP_BPF= _IPV4; + int config =3D psock->progs.msg_parser ? MPTCP_BPF_TX : MPTCP_BPF_BAS= E; + + if (psock->progs.stream_verdict || psock->progs.skb_verdict) + config =3D (config =3D=3D MPTCP_BPF_TX) ? MPTCP_BPF_TXRX : MPTCP_BPF_RX; + + if (restore) { + sk->sk_write_space =3D psock->saved_write_space; + /* Pairs with lockless read in sk_clone_lock() */ + sock_replace_proto(sk, psock->sk_proto); + return 0; + } + +#if IS_ENABLED(CONFIG_MPTCP_IPV6) + if (sk->sk_family =3D=3D AF_INET6) { + if (mptcp_bpf_assert_proto_ops(psock->sk_proto)) + return -EINVAL; + + mptcp_bpf_check_v6_needs_rebuild(psock->sk_proto); + } +#endif + + /* Pairs with lockless read in sk_clone_lock() */ + sock_replace_proto(sk, &mptcp_bpf_prots[family][config]); + return 0; +} +#endif + static struct proto mptcp_prot =3D { .name =3D "MPTCP", .owner =3D THIS_MODULE, @@ -4048,8 +4141,20 @@ static struct proto mptcp_prot =3D { .obj_size =3D sizeof(struct mptcp_sock), .slab_flags =3D SLAB_TYPESAFE_BY_RCU, .no_autobind =3D true, +#ifdef CONFIG_BPF_SYSCALL + .psock_update_sk_prot =3D mptcp_bpf_update_proto, +#endif }; =20 +#ifdef CONFIG_BPF_SYSCALL +static int __init mptcp_bpf_v4_build_proto(void) +{ + mptcp_bpf_rebuild_protos(mptcp_bpf_prots[MPTCP_BPF_IPV4], &mptcp_prot); + return 0; +} +late_initcall(mptcp_bpf_v4_build_proto); +#endif + static int mptcp_bind(struct socket *sock, struct sockaddr_unsized *uaddr,= int addr_len) { struct mptcp_sock *msk =3D mptcp_sk(sock->sk); --=20 2.51.0 From nobody Thu Jan 8 17:49:53 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3FE03143C61 for ; Sun, 4 Jan 2026 05:29:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767504599; cv=none; b=V3Bvscax+O8pF/bjybw9jBCllFZUn1IQTztN0AB0Fvl/th33Lfl986MxLOPyyEpz/6pY34W20YUG6gozbRdsNBerSN3NHX2GIETvalLxrqN0h/BaXqChJrDUAJDWRAPVOR4FL0oGznHehKg5GW6EsFs7KYcaHxLgh5/qDyG9HQ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767504599; c=relaxed/simple; bh=dQa2mQD1k8jMXM428vmJcI3XZnE4oX5j4J4zESf4rEM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T7PZnExaqIPyFx8bpq5+O/t1T8bYaRpjIYYhLFdWdBEWIrnCEYmdRllCoecRGaLcwAaY21ti2QUL/CaQpgExnnjald5oKCYq1lRLDPgE6HN9nZWX9PQQc24gUau2ggDkaUGquI8rUAUkkk/B2tzKydfrULJcsFwrStrQYZqBiIE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p228+bEg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p228+bEg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 846B0C4CEF7; Sun, 4 Jan 2026 05:29:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767504598; bh=dQa2mQD1k8jMXM428vmJcI3XZnE4oX5j4J4zESf4rEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p228+bEgtHwY42wohPRNIB19teqP966jUk1B2N/FWkWmYfHl2E4+8i8Gfqq8yaEgn bL8qWq/p18utFfFxQVob9UqZzaAY7Gpll7pMQlJNk0zKHev11PjYhoZhrKrOkopBRh E913LnDDXU/VIZ3nor2Dde8MPP1WxeKe7UNQ2FiYaxSsoVkPpHeQaxUeWVF8a+7Yzo V5Xq2+qTe/LRpLh/srAdMegqYRE0C51cnTqj4qmfyx+J0Ac9Lhve2TjqQliPh1qj/u 9N0r7pDmQbvpRhClKZKsAvNFOuzrYKJRMqRC3gIK5OwpUO0J1S94DAHUGcJyRzlUYs g6lBPzTOK7tAA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Paolo Abeni , Gang Yan Subject: [PATCH mptcp-next v2 2/3] mptcp: allow overridden write_space to be invoked Date: Sun, 4 Jan 2026 13:29:43 +0800 Message-ID: <2efc3455052c3a33cad0c8744b171dfc6e7a6d8a.1767504329.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang psock may override its own sk_write_space functions. This patch ensures that the overridden sk_write_space can be invoked by MPTCP. Note: This patch was initially included in the NVME MPTCP set. Suggested-by: Paolo Abeni Co-developed-by: Gang Yan Signed-off-by: Gang Yan Signed-off-by: Geliang Tang --- net/mptcp/protocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index cd5266099993..f5d4d7d030f2 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1014,7 +1014,7 @@ static inline void mptcp_write_space(struct sock *sk) /* pairs with memory barrier in mptcp_poll */ smp_mb(); if (mptcp_stream_memory_free(sk, 1)) - sk_stream_write_space(sk); + INDIRECT_CALL_1(sk->sk_write_space, sk_stream_write_space, sk); } =20 static inline void __mptcp_sync_sndbuf(struct sock *sk) --=20 2.51.0 From nobody Thu Jan 8 17:49:53 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36CDF2D5A16 for ; Sun, 4 Jan 2026 05:30:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767504603; cv=none; b=Sn0wp0p7+0QyQynZsXCsv5QLsK5+seflv6uPXWGnMeOtLUv11d0dlkDVamznG3dHGZleGiGe1X8eNejWvh59USwTkmGZeRN/XHifv2Vynbc6aezmL9Ok7+UtpfB4z4nlHy7r1/mAh3YD+CofUqEzB1icAmkjDlUU5a0qGlU4kuI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767504603; c=relaxed/simple; bh=5e+wGjokdw9lf/RAoaGCcvmbjc2NWW1OltWOGet5qj8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=soajv+9g95JhiaNq1hryAnjwr7OrhHb5Vf0ygdLgZOzrjlQoDFWkxDHaf52o0ddBdZhQaSC41ihMfGdQW0JZycHJE+00Fg5w3jknrDSZEdVcvxhUKUaIEZAdZ3zhhJJJHgHeMgEc3W32TCjBX1oi/zpAKgXCIcqwjGWAJgEjlZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QuuozCSu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QuuozCSu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76AC2C4CEF7; Sun, 4 Jan 2026 05:29:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767504601; bh=5e+wGjokdw9lf/RAoaGCcvmbjc2NWW1OltWOGet5qj8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QuuozCSunSk+i9+ZidHEZTjbDkiBOx9JmH/jUrzMjTwGlaTxWAs0C5vQ9M0AMF9/h h3DH1cilJuHs9fa3/MeVLZhHkgkIhtxju0TJLQXTvbe9wlTvfj8wyKe05x89lOdDUW Jg0R/i1p8ovKPs2CcpAdo6paDcp7/ymB9wCDtOdMJRViYpk8Yzohq1XQSIZcX9uHT/ 5b6YjxXSK98R54TitGbtsqjDrvJbG3zGuwevAdNjMm4FLPL78Lf6ZHvK2co4kOIvUv zFEe9omlpUCiIIOM24cr34H2gskh8LSasEvR0wEDyycxo7c4Z5/TlBOCh++1W8M9Te R8nW+ZBpGuSSQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 3/3] selftests/bpf: Update sockmap tests for MPTCP Date: Sun, 4 Jan 2026 13:29:44 +0800 Message-ID: X-Mailer: git-send-email 2.51.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Update sockmap tests to reflect new MPTCP support. MPTCP sockets are now allowed in sockmap, so test expectations are adjusted accordingly. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing= /selftests/bpf/prog_tests/mptcp.c index 7f48fd9e94e1..217ecc59c8a2 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -570,13 +570,13 @@ static void test_sockmap_reject_mptcp(struct mptcp_so= ckmap *skel) server_fd =3D accept(listen_fd, NULL, 0); err =3D bpf_map_update_elem(bpf_map__fd(skel->maps.sock_map), &zero, &server_fd, BPF_NOEXIST); - if (!ASSERT_EQ(err, -EOPNOTSUPP, "server should be disallowed")) + if (!ASSERT_EQ(err, 0, "server should be allowed")) goto end; =20 /* MPTCP client should also be disallowed */ err =3D bpf_map_update_elem(bpf_map__fd(skel->maps.sock_map), &zero, &client_fd1, BPF_NOEXIST); - if (!ASSERT_EQ(err, -EOPNOTSUPP, "client should be disallowed")) + if (!ASSERT_EQ(err, -EEXIST, "client should be allowed")) goto end; end: if (client_fd1 >=3D 0) --=20 2.51.0