From patchwork Mon Mar 3 10:33:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13998534 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 691D41F3BA2 for ; Mon, 3 Mar 2025 10:33:46 +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=1740998026; cv=none; b=FNaa3vt1wUaekrFMom+0UA178ItdLXVo50l+oCVvySyIWpuPCiGgI5vZVmpD9wsfu2/VlzqGrS1BfggEAnJMR3PAxJ12STQng34tVsgJBak1CDIHAqU6IOgFK77OLYiwE2YRbMFLDQ4tChpJfOwazW5i72yUIfuORvL22tlqPRM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740998026; c=relaxed/simple; bh=3w0UiAWIzMtUk5kXRKMpKaYmdGWKWd8bQ1iWq34N8Uo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VgpFwotj/WOpbd06skmXNxYj8wQJ2xVWUqtPA8/vN0wBnoe95Nto72grq6IgvY+5nMlsoy6OdxgQ6jRHGZbuBYHMhG5CjhIdXyesMIU+YYqfZRTFawsKPN8ErryXP0+l5fEVHkotNH9I/YxIQSqtx0xl4aXnXlevRCnCaojcnbo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AqEwzPKB; 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="AqEwzPKB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F40F0C4CED6; Mon, 3 Mar 2025 10:33:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740998026; bh=3w0UiAWIzMtUk5kXRKMpKaYmdGWKWd8bQ1iWq34N8Uo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AqEwzPKBBjg04zCGxdb4IifT6OBiOXP8/zjwPIqFPXP8ok5o/e3YtUZJ/YpR8ZUvK RZ71DlBNCG6EjrAuZVsb6KRhl1x2h6taPU6erfU6g3P6tOqPZGiyjA4LV4f2a9eJi0 0WVR4tkJ204Hz1p3s30derAI4CH6dwdnI/OqrhaqDnf5/5MMzyXKVSZwRhis+WgoVK ydAClRyMvwqhMVFq/SEqOeUANChf47pM5h8PHe0Vn4+arRZROdR2gJ6ej1js0hukER 05tbrgGTI2h8Ck6ZyA0IRqvyhWOSodyLK72q+Ux2oKEJmaGEw/FvE2ueSegvHqdNTC a+PHeJmvSQrwQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , Mat Martineau Subject: [PATCH mptcp-next v5 1/5] mptcp: add bpf_iter_task for mptcp_sock Date: Mon, 3 Mar 2025 18:33:33 +0800 Message-ID: <7ff2760dcee1532f624e2ccf4fd67e83ec09a01b.1740997925.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 To make sure the mptcp_subflow bpf_iter is running in the MPTCP context. This patch adds a simplified version of tracking for it: 1. Add a 'struct task_struct *bpf_iter_task' field to struct mptcp_sock. 2. Do a WRITE_ONCE(msk->bpf_iter_task, current) before calling a MPTCP BPF hook, and WRITE_ONCE(msk->bpf_iter_task, NULL) after the hook returns. 3. In bpf_iter_mptcp_subflow_new(), check "READ_ONCE(msk->bpf_scheduler_task) == current" to confirm the correct task, return -EINVAL if it doesn't match. Also creates helpers for setting, clearing and checking that value. Suggested-by: Mat Martineau Signed-off-by: Geliang Tang --- net/mptcp/protocol.c | 1 + net/mptcp/protocol.h | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 2b48cf648346..fec776c23fcd 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2726,6 +2726,7 @@ static void __mptcp_init_sock(struct sock *sk) msk->scaling_ratio = TCP_DEFAULT_SCALING_RATIO; WRITE_ONCE(msk->first, NULL); + WRITE_ONCE(msk->bpf_iter_task, NULL); inet_csk(sk)->icsk_sync_mss = mptcp_sync_mss; WRITE_ONCE(msk->csum_enabled, mptcp_is_checksum_enabled(sock_net(sk))); WRITE_ONCE(msk->allow_infinite_fallback, true); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index ef1d43406f9b..836891bc28d5 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -327,6 +327,7 @@ struct mptcp_sock { struct list_head conn_list; struct list_head rtx_queue; struct mptcp_data_frag *first_pending; + struct task_struct *bpf_iter_task; struct list_head join_list; struct sock *first; /* The mptcp ops can safely dereference, using suitable * ONCE annotation, the subflow outside the socket @@ -1291,4 +1292,19 @@ mptcp_token_join_cookie_init_state(struct mptcp_subflow_request_sock *subflow_re static inline void mptcp_join_cookie_init(void) {} #endif +static inline void mptcp_set_bpf_iter_task(struct mptcp_sock *msk) +{ + WRITE_ONCE(msk->bpf_iter_task, current); +} + +static inline void mptcp_clear_bpf_iter_task(struct mptcp_sock *msk) +{ + WRITE_ONCE(msk->bpf_iter_task, NULL); +} + +static inline struct task_struct *mptcp_get_bpf_iter_task(struct mptcp_sock *msk) +{ + return READ_ONCE(msk->bpf_iter_task); +} + #endif /* __MPTCP_PROTOCOL_H */ From patchwork Mon Mar 3 10:33:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13998535 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 2F26F1D5CD9 for ; Mon, 3 Mar 2025 10:33:48 +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=1740998028; cv=none; b=BACy1zOvrUB6PFnELuIBD5mlWLHM6iX+Tq62aed9NZx/UtAfhuoqMSXfjHStQVb4lnJdGQZ1KONIKTGrQp9+uh4mox7mwxl5Ww7iZK/dE93wkQYT8h482UEvAmEnO+OkJof0ud9LcnecXtc06LV4YO1S2pm5opQob9V0zihGgPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740998028; c=relaxed/simple; bh=vKlvxkWIzS/8vMddXtyi+A5jNgKZvuAia2fitdYo9Do=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z66S/RxI8rcVF9Rha6m5rwtjbQSnTlMBs7Ciq9uTQitvg+Y/IDW9URilekfXPTNipC7HSCkaioTBBGGkeQiVBLxNcW/nqtVjB9SnApVlHabO9dvDKNWwkNDRiJP/SbjYCWsHB/7ey9JUUw06+kjTRdojyAtW6VHBEZ6GbAxb71A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZrFnpVEh; 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="ZrFnpVEh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7556C4CEE8; Mon, 3 Mar 2025 10:33:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740998028; bh=vKlvxkWIzS/8vMddXtyi+A5jNgKZvuAia2fitdYo9Do=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZrFnpVEhONKMs9jO5ZIt5VyfVca/lGRCjjwhzhBgWrTujDrQB+AtD8hFxBDspp2U8 oTcberZYnBZgkvzafqdl2HrTbNZnUjNSZCGvhZAYVynwlpNx2cDa5q1EswKDv+K7pJ r+cwPaDIdSzbAPqJMdbL5SYVQoTD4oPRkEFuvNDxWVEUqncMGZnsMG7M7NTouLK66g YSNjX8edXTb7SYiA+qNNI1j4xBVtdWyuBJXud7ur6M0Nz1AHzV7xqGvJDrnyPC841v 2hTnFPlv4kaEtQPkvy2Kxm4/hK0GcYhA6CkpGZpdQpvvtwLYBE+Tc+g+iij/fk1w4i /iVnQ8dTl3fuA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v5 2/5] Squash to "bpf: Extend bpf_skc_to_mptcp_sock to MPTCP sock" Date: Mon, 3 Mar 2025 18:33:34 +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 Set msk->bpf_iter_task in bpf_mptcp_sock_from_sock() to allow mptcp_subflow bpt_iter can be used in cgroup/getsockopt, otherwise, the selftest in this set fails. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index be222fa5f308..aff92f458e7f 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -197,14 +197,22 @@ static struct bpf_struct_ops bpf_mptcp_sched_ops = { struct mptcp_sock *bpf_mptcp_sock_from_sock(struct sock *sk) { + struct mptcp_sock *msk; + if (unlikely(!sk || !sk_fullsock(sk))) return NULL; - if (sk->sk_protocol == IPPROTO_MPTCP) - return mptcp_sk(sk); + if (sk->sk_protocol == IPPROTO_MPTCP) { + msk = mptcp_sk(sk); + mptcp_set_bpf_iter_task(msk); + return msk; + } - if (sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk)) - return mptcp_sk(mptcp_subflow_ctx(sk)->conn); + if (sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk)) { + msk = mptcp_sk(mptcp_subflow_ctx(sk)->conn); + mptcp_set_bpf_iter_task(msk); + return msk; + } return NULL; } From patchwork Mon Mar 3 10:33:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13998536 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 647C81F3BB2 for ; Mon, 3 Mar 2025 10:33:50 +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=1740998030; cv=none; b=gVb3L0L8nrwt/QIlMRAGLWJDFpqv+XWETZJ/1ciauUxUVC+/icBdvFJTl7WclZef0WNuzmCMZSNhqO8DVABnKEA8EQ1XWNb9Da5gnN8zBLtT63O4GGz9GQt+/Xeoo7BjhZq4f1LcWjzIndG0qjPI6EnEpEsvtONdk3097HmpgJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740998030; c=relaxed/simple; bh=GxH2KhnDE+Z4TKKIkD4+oWWc3Mf1jcD4ONU5q7pfUjU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hlxNpOhi2S7vzcQDPvJJtDa4fSA2DkFcD6w75E1Uomsdfq+15qYum74X30qI/i3jAd0wNyHDf8jrGJcnCH51jlsjVN0q57ETkSjsj8BgOqcaI1IW0ZCAwC7np51dV7qX/iJm0axFNxMoEtzr6MxH24vZ6v+ER6o9opVUmYQ4CeE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fqpRv3aw; 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="fqpRv3aw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7722C4CED6; Mon, 3 Mar 2025 10:33:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740998029; bh=GxH2KhnDE+Z4TKKIkD4+oWWc3Mf1jcD4ONU5q7pfUjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fqpRv3awfLSiPUShEd7fe4sUCaiJlmvOqsDVliqkjuC6B4KOasK8jksAanuXZAyPr ChmTEWDNC9G5k37dyMsUlGrPJ40MuBVjQJCNapkwsSU+5y8moa+ctqLabgQzuXDznF ghpJMIU/g1W5/b8Rj4s/9qYFLJLbJuJ/l43APg5xnvABvV0n0rT51Js/eri7O1dghW l+6/QfQaHv2RgSlY9saqE6QCSGoz3dfEcrD2JnICZ7kx+1mxw6RlWAMzp8QqkU9GqA WrKYZTCLzjUzxf2jspLwjxupiZkdmWe2sqDfoy+wETXMWM8yG4wUGfR+Sg9J+/idej gsjEJVO6q5VtA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v5 3/5] Squash to "bpf: Add mptcp_subflow bpf_iter" Date: Mon, 3 Mar 2025 18:33:35 +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. v5: - check bpf_iter_task in mptcp_subflow_new() v4: - drop sock_owned_by_user_nocheck and spin_is_locked. According to comments from Mat [2] and Martin [1], in this set mptcp_subflow bpf_iter only used from a cg sockopt bpf prog, no need to add these check at this moment. [1] https://lore.kernel.org/all/fdf0ddbe-e007-4a5f-bbdf-9a144e8fbe35@linux.dev/ [2] https://patchwork.kernel.org/project/mptcp/patch/f6469225598beecbf0bda12a4c33fafa86c0ff15.1739787744.git.tanggeliang@kylinos.cn/ 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 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index aff92f458e7f..a307490bb20e 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -249,24 +249,33 @@ 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 task_struct *task; + 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 (!sock_owned_by_user_nocheck(sk) && - !spin_is_locked(&sk->sk_lock.slock)) + if (sk->sk_protocol != IPPROTO_MPTCP) return -EINVAL; + msk = mptcp_sk(sk); + task = mptcp_get_bpf_iter_task(msk); + if (!task || task != current) + return -EINVAL; + + mptcp_clear_bpf_iter_task(msk); + + msk_owned_by_me(msk); + + kit->msk = msk; kit->pos = &msk->conn_list; return 0; } From patchwork Mon Mar 3 10:33:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13998537 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 335EE1F3BAD for ; Mon, 3 Mar 2025 10:33:51 +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=1740998032; cv=none; b=GJU0vCc1I7az+o5ICQtq7K69zZbb1vt5bLnvfrFIfPY5hjxM1v0efD8zY9UmH851WLF97qqMhr0mQKvcGBPINePs4541Rg2+5m1YfyJrmfq0uCQHFdy5eeLlzTH1d3YlIW7D4rGOcPNs1480ZpOnMWTZD91n55+dbyqxqaILwUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740998032; c=relaxed/simple; bh=dco71mADKrWFOJx0j5CmX6RjpZLYY5fBgwGpgyFHs1I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q95cOM0UvGdoQXTQM3YqSfVG+VaOeUuJLS94wIMEqMFCKR/biALLzjbcOUCLD3Q6xBmFZsmqMDL51o+YElHfNRQFwJQ4NC9+g6VMk9a6ojMJxxRJbZdSKt70q7tE45/UT+IfdzRGtiLpIU3xl8kH06IaksNLZjVi2znNopGq9js= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NOsHi7u5; 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="NOsHi7u5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81146C4CEE5; Mon, 3 Mar 2025 10:33:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740998031; bh=dco71mADKrWFOJx0j5CmX6RjpZLYY5fBgwGpgyFHs1I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NOsHi7u5JEq3x27L2IY4VbDJOU0ttcU+19uepTFbMH0RIU9vPJqwVlEggOwSmf+9l bqmVacT8CClieBDch3502RMmXP8vzcTN2ghtwbErlZXK22iEhKp4NBRvg5WCodRjrv G8ofp8DushiRIEJ9g0VCjQtcM/poGMyaklalGaxPbRwgqWkbeAhBwx0ozQX+3lvFUN 0eVu+6jBd70/WvW6rAZ6FwVidAyQiOR+D0NU1vw1sW70LHA/+zexLxp1asWQ/XFEP8 6aIMFuyd5uBq+DSe0e8CPw4sQdcC4KX4RFxK7Sb+i3Lv1eqgQzRrNgjHtVAh76MXZo HDlXW7Hs+VePw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v5 4/5] Revert "bpf: Acquire and release mptcp socket" Date: Mon, 3 Mar 2025 18:33:36 +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. From Martin's review [1], this mptcp_sock_acquire() helper was a workaround only to please the verifier, but they were not needed. [1] https://lore.kernel.org/9b373a23-c093-42d8-b4ae-99f2e62e7681@linux.dev 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 a307490bb20e..9091da0a24b0 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -297,23 +297,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) { @@ -334,8 +317,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 Mar 3 10:33:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13998538 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 F1F171E7C32 for ; Mon, 3 Mar 2025 10:33:53 +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=1740998034; cv=none; b=r1EoGOxoscNfbzjASw2hZ+DUdFPM2l6dmFNyVVoirpgMEG1YfLDTY2MZ5FsUVkRCi0V4IfC9j96bGxOwL+gnnHNejaqqTw7louw72Aqi8IODO390RhbuEv9bDuV6JPnyy3AtposCi/+p26V5+PbKe6vcNyfZk58JXTJz5MFgvjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740998034; c=relaxed/simple; bh=rAnQKGajgsDwrJkO6LoSKauFlpSITe8Ph+M7eJIoDGU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tYzWl7NuX3RvLmODDkHuKPvVVlVHh1i9a0IQ3r8MdZHSvQd4sYmWsnUC7l0mxgtvnDKXe2qttDjBRiADLtVtLsGXW1Pe+niTqogLQQwQ6ie2vBnAmWjJN+rizcmjLVXbW54S+AlQq2iTWeHK70mllyAAH4dN+GOTn4mjKkG8I/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cRXcV7Z3; 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="cRXcV7Z3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B5A3C4CED6; Mon, 3 Mar 2025 10:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740998033; bh=rAnQKGajgsDwrJkO6LoSKauFlpSITe8Ph+M7eJIoDGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cRXcV7Z3fjOZAtIr60mVWlzikbo/9UFr3apuIuhjx6bg+ZU6oJRdaEnHQZbWP5guD vzsRsPf2OYtvUgEvGv8yb1gP1BW6aw6jsVhzQ9C9tem/K4LkeA/Yh9qVZbVWnHpmGu I3PsFILJwFmO3VJUcKiFvFMOZh/bJ8lUcV6zzFtonNlBEcTSJxuRenSzz3eB5Y5jwu t9Je8MqAejcxX/fYC4YjTKjlXs2a2DLMyk5aWZKEA0ygywxSGJeLyj41sWKxCXjTuA L/nP+i3Uae89JIVbq+Up9e4t3chnrcLfTTBlFQi/8+hOPRuXIOrjs+33hAZvMaTjvN 92LHAZyBx/obA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v5 5/5] Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest" Date: Mon, 3 Mar 2025 18:33:37 +0800 Message-ID: <68093cf9d188808f50cf36f6c8ac8d4a69d853b1.1740997925.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 | 8 ++------ 3 files changed, 3 insertions(+), 12 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..a69e88cc191d 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c @@ -28,10 +28,7 @@ int iters_subflow(struct bpf_sockopt *ctx) 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; }