From patchwork Mon Feb 17 10:33:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13977523 X-Patchwork-Delegate: mat@martineau.name 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 08C7A215F68 for ; Mon, 17 Feb 2025 10:34:10 +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=1739788451; cv=none; b=gc7IWcjOjT8nipNS7W8wQxFMfJFiKqSw7tY89jDfhNe2PsYo2hhcTkUAwsqcpGYiN9+dO1r0XlqJXFbv1LGPuK+FQaeRoQGF8my1GahSV3gUnLbXSvBbDYcHA0hAC98GK+cQLR4AkxpnGAR66NVfjlWx4DbMVKXubDBD3v7E39o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739788451; c=relaxed/simple; bh=7+9tzmSBEyJZstB88VcME9Hams9OlyqDoObVFKD9GZM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PaT5fOOd1MdDyT3/4srI/gGDmCknoB+N+QuIfBdvJDypK72QTS96pBEbXhugKoMVsXS3gGa2afRA64qTr510ZRgU6/jHHbvVcLUM+jw0ciQAohOfISnOwfUQUmFG1wrzsGvBr/y4K3G5/H0B3I2NP9Bje4uWyQ8x9JYRL3mT3XY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nJ5y8vFs; 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="nJ5y8vFs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47238C4CEE2; Mon, 17 Feb 2025 10:34:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739788450; bh=7+9tzmSBEyJZstB88VcME9Hams9OlyqDoObVFKD9GZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nJ5y8vFslSM7hn6W2+8DW3KtdS/aM8EGs6tevmen4ZN4wNI+9jre0nMBfs1ox5dqj awgtfdUGCY72pIKKbOqb9dH3+rS5Xo56C+5jxHd8xpf0V1sprp5626H01tY5JBxUth aUSD5HY7lMr3aBC5mNj3edgy2EpoPvfPI8uSh/f9N7JTav3KMaqqG5vz3Z+zykmAAo edi0NmoR4gus5L136nrMbrDv6fbfeNv0TOwn15uolJe5+oheRvwAJVdZN3ldBFxMrR S17iBR+wXDlt8eIzFsjbZTBa2lpvMO3gVDTdVPyZn7n2URhsFht91b2vgFj3UiLIZF o9RIm4mj/wsqg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 1/5] Revert "bpf: Extend bpf_skc_to_mptcp_sock to MPTCP sock" Date: Mon, 17 Feb 2025 18:33:58 +0800 Message-ID: <0928d84e9ad5ee43779dda3de9be77ad28006ded.1739787744.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang bpf_core_cast() can be used in mptcp_subflow bpf_iter selftests to get the msk, instead of using bpf_skc_to_mptcp_sock(). No need to add this patch anymore, revert it. Signed-off-by: Geliang Tang --- include/net/mptcp.h | 4 ++-- net/core/filter.c | 2 +- net/mptcp/bpf.c | 10 ++-------- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 72d6e6597add..2c85ca92bb1c 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -323,9 +323,9 @@ static inline void mptcpv6_handle_mapped(struct sock *sk, bool mapped) { } #endif #if defined(CONFIG_MPTCP) && defined(CONFIG_BPF_SYSCALL) -struct mptcp_sock *bpf_mptcp_sock_from_sock(struct sock *sk); +struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk); #else -static inline struct mptcp_sock *bpf_mptcp_sock_from_sock(struct sock *sk) { return NULL; } +static inline struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk) { return NULL; } #endif #if !IS_ENABLED(CONFIG_MPTCP) diff --git a/net/core/filter.c b/net/core/filter.c index fc094e8d53d3..2ec162dd83c4 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -11843,7 +11843,7 @@ const struct bpf_func_proto bpf_skc_to_unix_sock_proto = { BPF_CALL_1(bpf_skc_to_mptcp_sock, struct sock *, sk) { BTF_TYPE_EMIT(struct mptcp_sock); - return (unsigned long)bpf_mptcp_sock_from_sock(sk); + return (unsigned long)bpf_mptcp_sock_from_subflow(sk); } const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto = { diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index be222fa5f308..7e9d9c9a04cf 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -195,15 +195,9 @@ static struct bpf_struct_ops bpf_mptcp_sched_ops = { }; #endif /* CONFIG_BPF_JIT */ -struct mptcp_sock *bpf_mptcp_sock_from_sock(struct sock *sk) +struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk) { - if (unlikely(!sk || !sk_fullsock(sk))) - return NULL; - - if (sk->sk_protocol == IPPROTO_MPTCP) - return mptcp_sk(sk); - - if (sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk)) + if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk)) return mptcp_sk(mptcp_subflow_ctx(sk)->conn); return NULL; From patchwork Mon Feb 17 10:33:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13977524 X-Patchwork-Delegate: mat@martineau.name 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 CB17C23CE for ; Mon, 17 Feb 2025 10:34:12 +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=1739788452; cv=none; b=C2zpBeOqdNVkGbCiaXf0hezRAyDZc9tJVTGmJ6YmmTxv+kVuR4OE353lMGwG81YnN8oVNWHe3dxqDmfTZGHedx5HwzayTPzf3EkhJLTpoTnsv6si7UQbRYRsjSnGsZ2uhELm8P+cehSnWLItO/pfQG/yXSJWLNNuFpJ8BVOWqhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739788452; c=relaxed/simple; bh=Y/nSLpzRC0NZxGyn2KF0Yxwg1I5WdIB6hNFwT4Y3kEw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ED91iAbuojEQhkCuH+XPqxj+oJJ3Mz/9DLL3AEMIwF3ZJHNFDKaVTBFRvM0ZdE9vL9Tr+GcILM2h2CXKzQs2rgRbDzuSNbpCl4H/bslkzt0kTZt/Fi2DGCTGyHNK8nAUQms8Oi1QXbq2bY6o0oXN+S8H008lCyqkNggRzvFdL6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OzbvSd1c; 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="OzbvSd1c" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20A93C4CED1; Mon, 17 Feb 2025 10:34:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739788452; bh=Y/nSLpzRC0NZxGyn2KF0Yxwg1I5WdIB6hNFwT4Y3kEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OzbvSd1cSpg7ozdWzZEplAJCjHSnfDwvLZpPBVh8hckII+z6TpgY1NTA/4oTB0524 eeCbgwwoxm6xHz9g+oOWdQT2q8OjuYvoR8DC3XBQBv3oQjbA8/n3/FIBN5sYErCiE5 ivOwU0SbBAlAlECWIjINgvzSYswrbloJgNKE7YizWIQumzTzgi28h6axLJC31kxJKE UBy1nSJN62EEd5MaaLz6YemZcuNclcrhJGIxDc66V9PARVUH6HZWnJU/dPLcKVoKQe QKt3YgJ4isuX6YTZOyK2QFEYsjdp7f03oZFYOHWoF64VvhhazP6IMcnPlkpSSr1W+D 1DB26p3wBfA8w== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 2/5] Revert "bpf: Allow use of skc_to_mptcp_sock in cg_sockopt" Date: Mon, 17 Feb 2025 18:33:59 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang bpf_core_cast() can be used in mptcp_subflow bpf_iter selftests to get the msk, instead of using bpf_skc_to_mptcp_sock(). No need to add this patch anymore, revert it. This reverts commit d8d42f5a4542c2dc31e4e00c58508a821c6ab789. --- kernel/bpf/cgroup.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index 1ca22e4842cf..46e5db65dbc8 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -2358,8 +2358,6 @@ cg_sockopt_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) #ifdef CONFIG_INET case BPF_FUNC_tcp_sock: return &bpf_tcp_sock_proto; - case BPF_FUNC_skc_to_mptcp_sock: - return &bpf_skc_to_mptcp_sock_proto; #endif case BPF_FUNC_perf_event_output: return &bpf_event_output_data_proto; From patchwork Mon Feb 17 10:34:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13977525 X-Patchwork-Delegate: mat@martineau.name 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 7B6591A5B8C for ; Mon, 17 Feb 2025 10:34:14 +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=1739788454; cv=none; b=qQxEBhAu4xmqI6A0qiTKgZp94wjqY8KlOqjmVagJQkrt4saClPffW91vA63Huscy61/So8f+lmyz/7Q7JTOkzGI6Ri8EM2fSehe8ZHOTtkmW9lZfqdW7nXXbVtIgBgFfw1tjm5lsvLvFARJO4sUWR1R82VrBC09w3aSxlWBN198= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739788454; c=relaxed/simple; bh=uNMVqv4YBalTJC0bicKoa36ZNouE1vzGkeNHqVUhMn0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L41CbeqQzY1DxC3Tq4P+8+fZXOKe0J3LV03S5SgJ3gqjwW2ncPIxjqurXGFM40ptwpAY1//A6kTLdQ/aKjhRFCcR8uy7LRE6X3cf3lJzifrR9J1oh0ETQaAhfACoXOllfvnKpNpkbXZI9ahBcUlbsZJ7isKlNkbRobpCowxjgXE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KHXb7Y1x; 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="KHXb7Y1x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5976C4CEE4; Mon, 17 Feb 2025 10:34:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739788454; bh=uNMVqv4YBalTJC0bicKoa36ZNouE1vzGkeNHqVUhMn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KHXb7Y1x5RtTq6hBAllMc1khLlNxhk1aenxpKTL6TWotPfLOy7tIKhLilKNUeKnz2 GKgNMz113tTpf1z9v0yJMLGj/ZkG6FeZZl1KT7EBt7+fMvDQw9GKx1NGPj5V3Sj2Tt 6z2YuQxY/tb6/v2/WVnVOjPL415vQcQncL6/wPNUxjuBMJtoNXqeFZqv1nuwhTRQOg DDh5udRDylqK3yF2n4pNfHVmgXaZHCXx8w8kSra77loy6SECeNVJ/0/adRQDMOjRPb ANUJZ2V4zPyt68a9gpVYg1JepcJlviqlqYZUSOTkrJDwxLUYdnwMD6tocysSIKXJkF 7Ko132BJJ1H3A== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 3/5] Squash to "bpf: Add mptcp_subflow bpf_iter" Date: Mon, 17 Feb 2025 18:34:00 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Drop the NULL check for 'msk' as Martin suggested, add more checks for 'sk'. Use the "struct sock *sk" instead of "struct mptcp-sock *msk" as the argument in the bpf_iter_mptcp_subflow_new as Martin suggested. v3: - continue to use sock_owned_by_user_nocheck and spin_is_locked checks instead of using msk_owned_by_me(). v2: - check the owner before assigning the msk as Mat suggested. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 7e9d9c9a04cf..06fb0f88e35f 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -235,24 +235,28 @@ bpf_mptcp_subflow_ctx(const struct sock *sk) __bpf_kfunc static int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it, - struct mptcp_sock *msk) + struct sock *sk) { struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; - struct sock *sk = (struct sock *)msk; + struct mptcp_sock *msk; BUILD_BUG_ON(sizeof(struct bpf_iter_mptcp_subflow_kern) > sizeof(struct bpf_iter_mptcp_subflow)); BUILD_BUG_ON(__alignof__(struct bpf_iter_mptcp_subflow_kern) != __alignof__(struct bpf_iter_mptcp_subflow)); - kit->msk = msk; - if (!msk) + if (unlikely(!sk || !sk_fullsock(sk))) + return -EINVAL; + + if (sk->sk_protocol != IPPROTO_MPTCP) return -EINVAL; if (!sock_owned_by_user_nocheck(sk) && !spin_is_locked(&sk->sk_lock.slock)) return -EINVAL; + msk = mptcp_sk(sk); + kit->msk = msk; kit->pos = &msk->conn_list; return 0; } From patchwork Mon Feb 17 10:34:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13977526 X-Patchwork-Delegate: mat@martineau.name 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 336B01A5B8C for ; Mon, 17 Feb 2025 10:34:15 +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=1739788458; cv=none; b=DKrIeOjCGXcTq5TPNNLu57R8ChXmxXVAZdB7bUeEqRx8kZpqJJTptG0pm1JKF/MQHY/CfhWgRtvwTv7TUI8Myi/AoG5zoCayu/9vYGU+99HzGZpRzWLkXdCNmKqkmMw7H51NulQ7N6deFRrVdbSk4ADP+S92Nsdb4wV2rcjeyVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739788458; c=relaxed/simple; bh=FmZ9/jn3TitLxcMXG2LVFBIVimxoZsguzgy/ogPWiwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pUPzUTM7x7ifi+UX8NP4p6ysP9jNdN/SXdysx7yp8xkkoFj2imlv01SikFoSW8K8IaB/8x/e6+Ic18Ju4dkUhGZ46+igmFOGj7424S5HpC6fr+8SyHnSLbI0CVDaVcnEkQxUrGOkoQ/0bZjsLuM7T8AvpMwZK5le88KcgG6KYv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FGlOxInE; 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="FGlOxInE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E87EC4CED1; Mon, 17 Feb 2025 10:34:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739788455; bh=FmZ9/jn3TitLxcMXG2LVFBIVimxoZsguzgy/ogPWiwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FGlOxInEk+THbTmT7oL7T206CsBdR9lvC9WBlJex1cXl/D3avE4Kh3mwq1Nc01wcy qBjGWK/XyhyJGyCwswM0DpcJkubCPSEM8x03osCcOuiFcES8sJFgN35G9ax2wnn0mX vtteZRx8ojrfsre0aSqy7yokQrSMmP621sjlz/j2eu/xuEkXTSN198hG2DSY+eCF+x MQvvZ+HN2+IQFvGsFkIUiYo15bv+6Of+55v2kfmnCRjHZwpe3rgUG6/ibbikb0jkKV 9z+EUGDvT9sIn854NoFFE4I3f2iNEvW7ty9Q8JS71rq+B3KNaISDaN4cDNHgDIJUil KaHbDLj3XCCLQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 4/5] Revert "bpf: Acquire and release mptcp socket" Date: Mon, 17 Feb 2025 18:34:01 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Drop this patch as Martin suggested. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 06fb0f88e35f..2256d4de1e20 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -278,23 +278,6 @@ bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it) { } -__bpf_kfunc static struct -mptcp_sock *bpf_mptcp_sock_acquire(struct mptcp_sock *msk) -{ - struct sock *sk = (struct sock *)msk; - - if (sk && refcount_inc_not_zero(&sk->sk_refcnt)) - return msk; - return NULL; -} - -__bpf_kfunc static void bpf_mptcp_sock_release(struct mptcp_sock *msk) -{ - struct sock *sk = (struct sock *)msk; - - WARN_ON_ONCE(!sk || !refcount_dec_not_one(&sk->sk_refcnt)); -} - __bpf_kfunc struct mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int pos) { @@ -315,8 +298,6 @@ BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx, KF_RET_NULL) BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new, KF_ITER_NEW | KF_TRUSTED_ARGS) BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next, KF_ITER_NEXT | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy, KF_ITER_DESTROY) -BTF_ID_FLAGS(func, bpf_mptcp_sock_acquire, KF_ACQUIRE | KF_RET_NULL) -BTF_ID_FLAGS(func, bpf_mptcp_sock_release, KF_RELEASE) BTF_KFUNCS_END(bpf_mptcp_common_kfunc_ids) static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = { From patchwork Mon Feb 17 10:34:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13977527 X-Patchwork-Delegate: mat@martineau.name 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 A215D216E20 for ; Mon, 17 Feb 2025 10:34:17 +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=1739788459; cv=none; b=ZwYa2Bpt08yQIwyqqc/87MTCb2RFFZrkubdkgn3SD+lIae+L/8i9I/6dvt0NHJXuJwJF2CU/ek1t+HsDOBKnQ68YF9fUehh6T1T3DR8Bs2quRysukJDlzgo2jrZNZ5rK/tYJESwz8RKvVTkACdcipUnyd71iN+T1hTBNBUsrOrA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739788459; c=relaxed/simple; bh=oTWOORozCRRkx+BuuccJDCPwDpq0zB0utA9Z7QbqOj4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rvWOPJTs2fs3rQdTwoeA7JXZVS6ECZQrsnEZlAqWsB0RAF3tFUQKPQUzuNfSEN5tEKD74MlYd/IG3SVrRtGGyrhIjoQQvIs6J0pZmnMXuHNNhGTd1dzSxpNvOhwu6LXygtwSD2CpahPu08i77Wcp5TsedsqX7skKG/JQ2g199Dg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=juiM/D5+; 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="juiM/D5+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DED1C4CEE2; Mon, 17 Feb 2025 10:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739788457; bh=oTWOORozCRRkx+BuuccJDCPwDpq0zB0utA9Z7QbqOj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=juiM/D5+jsVYfctFQUZEBNhxcB6vwGTnhD+H4xJkwrS3GcARso4lDvShTbFI/XrDU cvCvIzQCWYKvkyRJiqytLaL88ZAhXDPjV+A/+hkwsE6tMSd7S6czZllH7uTMsEBqXt 2RgIDL+SqNIvbYsS3SVkk7gibzN8gbCnkTY5pXT+8Com8rV4nB8pgZbgWrPnHAJCRB itgk8NqD6Hlzn/Ne/uOgOOkFNOGHGd9UCRZOKLCOeuPPiLQeIPW1ZrIMroVST/uXZD K/5Q0ALBH4WFKj2ENTxvG8ojBjypPAxWs44/eds9gVFD6SrCNez+Dm+PDfBvkLL5Ik YJ+FODgWTR80Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 5/5] Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest" Date: Mon, 17 Feb 2025 18:34:02 +0800 Message-ID: <29c255b7037e5bcb2995a3ea8f8d52592dbe6cac.1739787744.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Geliang Tang Use bpf_core_cast() instead of bpf_skc_to_mptcp_sock(). Change the 2nd parameter type of bpf_for_each() as 'struct sock'. Drop use of bpf_mptcp_sock_acquire/release. Drop declaration of bpf_mptcp_subflow_tcp_sock. It's no longer used. Update the comment for mptcp_subflow_tcp_sock(), which is a BPF helper, not a kfunc. Please update the commit log as: ''' This patch adds a "cgroup/getsockopt" program "iters_subflow" to test the newly added mptcp_subflow bpf_iter. Export mptcp_subflow helpers bpf_iter_mptcp_subflow_new/_next/_destroy and other helpers into bpf_experimental.h. Use bpf_for_each() to walk the subflow list of this msk. MPTCP-specific packet scheduler kfunc can be called in the loop. In this test, just add all subflow ids to local variable local_ids, then invoke the helper mptcp_subflow_tcp_sock() in the loop to pick a subsocket. Out of the loop, use bpf_mptcp_subflow_ctx() to get the subflow context of the picked subsocket and do some verification. Finally, assign local_ids to global variable ids so that the application can obtain this value. Add a subtest named test_iters_subflow to load and verify the newly added mptcp_subflow type bpf_iter example in test_mptcp. Use the helper endpoint_init() to add 3 new subflow endpoints. Send a byte of message to start the mptcp connection, and wait for new subflows to be added. getsockopt() is invoked to trigger the "cgroup/getsockopt" test program "iters_subflow". Check if skel->bss->ids equals 10 to verify whether this mptcp_subflow bpf_iter loops correctly as expected. ''' Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/bpf_experimental.h | 2 +- tools/testing/selftests/bpf/progs/mptcp_bpf.h | 5 ----- tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c | 10 +++------- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h index 2ab3f0063c0f..6a96c56f0725 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -577,7 +577,7 @@ extern void bpf_iter_css_destroy(struct bpf_iter_css *it) __weak __ksym; struct bpf_iter_mptcp_subflow; extern int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it, - struct mptcp_sock *msk) __weak __ksym; + struct sock *sk) __weak __ksym; extern struct mptcp_subflow_context * bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subflow *it) __weak __ksym; extern void diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf.h b/tools/testing/selftests/bpf/progs/mptcp_bpf.h index b1f6e1fb467e..72263672510a 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -43,13 +43,8 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) } /* ksym */ -extern struct mptcp_sock *bpf_mptcp_sock_acquire(struct mptcp_sock *msk) __ksym; -extern void bpf_mptcp_sock_release(struct mptcp_sock *msk) __ksym; - extern struct mptcp_subflow_context * bpf_mptcp_subflow_ctx(const struct sock *sk) __ksym; -extern struct sock * -bpf_mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) __ksym; extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, bool scheduled) __ksym; diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c index fd5691a4073b..a1d8f9b20259 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c @@ -24,14 +24,11 @@ int iters_subflow(struct bpf_sockopt *ctx) if (ctx->level != SOL_TCP || ctx->optname != TCP_IS_MPTCP) return 1; - msk = bpf_skc_to_mptcp_sock(sk); + msk = bpf_core_cast(sk, struct mptcp_sock); if (!msk || msk->pm.server_side || !msk->pm.subflows) return 1; - msk = bpf_mptcp_sock_acquire(msk); - if (!msk) - return 1; - bpf_for_each(mptcp_subflow, subflow, msk) { + bpf_for_each(mptcp_subflow, subflow, (struct sock *)sk) { /* Here MPTCP-specific packet scheduler kfunc can be called: * this test is not doing anything really useful, only to * verify the iteration works. @@ -39,7 +36,7 @@ int iters_subflow(struct bpf_sockopt *ctx) local_ids += subflow->subflow_id; - /* only to check the following kfunc works */ + /* only to check the following helper works */ ssk = mptcp_subflow_tcp_sock(subflow); } @@ -58,6 +55,5 @@ int iters_subflow(struct bpf_sockopt *ctx) ids = local_ids; out: - bpf_mptcp_sock_release(msk); return 1; }