From nobody Sun Dec 22 06:23:59 2024 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 3A3B5167265; Tue, 10 Sep 2024 05:37:36 +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=1725946657; cv=none; b=GoPHrrXfct1+pz9tuvqCmjSwatrzc241h6j6VHo3+4M8wUhDhWcfXgFE/ytgQMm0MnQHqN4+w27UFlq9git9k7ebDulPpIZJ/z6nnm4XNRALdcuduxuoTYDRCIapk4VJL0OXTqn9jUK9RCZG1REaAVN8Wpo4lyM7BQ2WbiMRVVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725946657; c=relaxed/simple; bh=D5TYavM29ltridmAsCsO8PzJ/nzNH0IhkjhLoU87B1Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B40pJV+dKKc+ecUBlmNYc8KDKwjjzFS17I89j8iBePOkXSwU9zIfO0LtAKObVIhSBrFXPhNlrNSueriGny7i1hmeS+Lv63+vf39b2dFYgPUrmhyCCRUxsstpz2qjZtexSzhNlWSwF0tlJbSVbPuFMc1txbV/rsMD/ABiAs8/7sA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jb/M3JU0; 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="Jb/M3JU0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06FE0C4CEC3; Tue, 10 Sep 2024 05:37:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725946656; bh=D5TYavM29ltridmAsCsO8PzJ/nzNH0IhkjhLoU87B1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jb/M3JU04RjAlCYKSqVHue2EQuRIqTq2kyBE1AFwZKgOXv+NOx8MvUXdIMkIVmZeF FkRMc/6q8eijqY+KID39U+RlEWUzJRpRX3iSa0gBS1mGvVBD6iQ7tGigEB1FD/XytO wPWOPbOxyIPSlpGFgj8/X2XK6Mx4L7QDJ+pqiUkb7VyszzhJH60ndn5dXtOeMvgHzS 7dzt7wiP0BWE5/eI2tlq58zRNREAJyWqURpdWBwOJYmfAv3WhfIjN9g5MoqCy6sO3L U31j2Xn4tn45rVGwz2YWJED1FEMJmhrX5f6aNPAdulgysopZMz9IcYQJBYJ/Pji1i0 q7CJ8VoPMbqXw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang , bpf , Martin KaFai Lau Subject: [PATCH mptcp-next v3 1/5] bpf: Add mptcp_subflow bpf_iter Date: Tue, 10 Sep 2024 13:37:23 +0800 Message-ID: <026dce3d6903ad189e4b0518a64b60c910e660c0.1725946276.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang It's necessary to traverse all subflows on the conn_list of an MPTCP socket and then call kfunc to modify the fields of each subflow. In kernel space, mptcp_for_each_subflow() helper is used for this: mptcp_for_each_subflow(msk, subflow) kfunc(subflow); But in the MPTCP BPF program, this has not yet been implemented. As Martin suggested recently, this conn_list walking + modify-by-kfunc usage fits the bpf_iter use case. So this patch adds a new bpf_iter type named "mptcp_subflow" to do this and implements its helpers bpf_iter_mptcp_subflow_new()/_next()/_destroy(). Then bpf_for_each() for mptcp_subflow can be used in BPF program like this: bpf_rcu_read_lock(); bpf_for_each(mptcp_subflow, subflow, msk) kfunc(subflow); bpf_rcu_read_unlock(); Suggested-by: Martin KaFai Lau Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 6414824402e6..350672e24a3d 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -201,9 +201,48 @@ static const struct btf_kfunc_id_set bpf_mptcp_fmodret= _set =3D { .set =3D &bpf_mptcp_fmodret_ids, }; =20 -__diag_push(); -__diag_ignore_all("-Wmissing-prototypes", - "kfuncs which will be used in BPF programs"); +struct bpf_iter_mptcp_subflow { + __u64 __opaque[2]; +} __attribute__((aligned(8))); + +struct bpf_iter_mptcp_subflow_kern { + struct mptcp_sock *msk; + struct list_head *pos; +} __attribute__((aligned(8))); + +__bpf_kfunc_start_defs(); + +__bpf_kfunc int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *= it, + struct mptcp_sock *msk) +{ + struct bpf_iter_mptcp_subflow_kern *kit =3D (void *)it; + + if (!msk) + return -EINVAL; + + kit->msk =3D msk; + kit->pos =3D &msk->conn_list; + return 0; +} + +__bpf_kfunc struct mptcp_subflow_context * +bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subflow *it) +{ + struct bpf_iter_mptcp_subflow_kern *kit =3D (void *)it; + struct mptcp_subflow_context *subflow; + struct mptcp_sock *msk =3D kit->msk; + + subflow =3D list_entry((kit->pos)->next, struct mptcp_subflow_context, no= de); + if (!msk || list_entry_is_head(subflow, &msk->conn_list, node)) + return NULL; + + kit->pos =3D &subflow->node; + return subflow; +} + +__bpf_kfunc void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subf= low *it) +{ +} =20 __bpf_kfunc struct mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned= int pos) @@ -218,7 +257,7 @@ __bpf_kfunc bool bpf_mptcp_subflow_queues_empty(struct = sock *sk) return tcp_rtx_queue_empty(sk); } =20 -__diag_pop(); +__bpf_kfunc_end_defs(); =20 BTF_KFUNCS_START(bpf_mptcp_sched_kfunc_ids) BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled) --=20 2.43.0 From nobody Sun Dec 22 06:23:59 2024 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 C9FC9745E4 for ; Tue, 10 Sep 2024 05:37:38 +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=1725946658; cv=none; b=rqgv3zwBHuVYPmI5p5xujxEZLf+rkMbW53OS9qbuAyakbZ1UpPjKLLl1luroYjfo/UGjzvu32a411r0eMfIwDGA8+Zs7hDQr9EqA3xPqCXlWh7l4Fq1qli9Xw+Iqt0UTdbBm73EmwcKvBbSgPrMyVetf3+5k2Ezjk05e9UjNvA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725946658; c=relaxed/simple; bh=tmUhyMbuivaejbJwrRN0H8HLOXpXYI1ZrAXOA8fWcYw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fov2oISn2QQ1n1KYUfsCbqBi5EGPHrsNvPWfFAMqe+UKeIc9zgspwUsVN2x4gEvAfhvfVbM1oeuEcG7iWuOQeQ2fnsa/3iozyokYnT8OMY/5wTQHYNfpJNyhmDqYQDK21zySnzCJwC5Yh4oBcllMVfaqVBCnAdD/lWnF3+xBncU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GfnZZfBS; 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="GfnZZfBS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7556BC4CEC4; Tue, 10 Sep 2024 05:37:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725946658; bh=tmUhyMbuivaejbJwrRN0H8HLOXpXYI1ZrAXOA8fWcYw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GfnZZfBSRT3p4AfOUZkfQSFpo236l4tHKElJNJJo/VcG3EWtJ70+aXCsmnz8ie7iu N3gziGhU8ZHTmeA2AJRnjecsUHP1/a6OcsBEH6r7TIGHrxJimQBUrZPaVq0ydPNGFf Q8DszEmzcEDVdhwNmuhs9nCaPjqjU8OknPyKeK0tdbBf04aT7TLBLnSFCTfYnxuFUO u682OT3KvNh/4j9D/wUjNi5b2oP2g4CPlycDM07UCxRCk/9tkTcAcAhMhLxa3Caupr KLGSIh732GZMeNVsrqgM9u0WP82Wpq/ZO3bGaLSh2ogmoOnVl66y3q0gzX1q8LTy/8 SjkcEy2Sut5jA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 2/5] Squash to "mptcp: add sched_data helpers" Date: Tue, 10 Sep 2024 13:37:24 +0800 Message-ID: <4f91d977cc858cddcc9620a0b4ff3eb01c66c2a0.1725946276.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Drop bpf_mptcp_subflow_ctx_by_pos declaration, since "-Wmissing-declarations" is ignored in __bpf_kfunc_start_defs. Signed-off-by: Geliang Tang --- net/mptcp/protocol.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 6e7d88ca7d42..aa0969d4440b 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -722,8 +722,6 @@ void mptcp_sock_graft(struct sock *sk, struct socket *p= arent); u64 mptcp_wnd_end(const struct mptcp_sock *msk); void mptcp_set_timeout(struct sock *sk); bool bpf_mptcp_subflow_queues_empty(struct sock *sk); -struct mptcp_subflow_context * -bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned= int pos); struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk); bool __mptcp_close(struct sock *sk, long timeout); void mptcp_cancel_work(struct sock *sk); --=20 2.43.0 From nobody Sun Dec 22 06:23:59 2024 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 E8AF4745E4 for ; Tue, 10 Sep 2024 05:37:40 +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=1725946661; cv=none; b=lsirrPbDKr3GJGbF0ncAUw/90RRhCinqbjfBkchptKKWfxmQVFg53xqMp2KuAcn9O9UlQ2TYvRQLplVN2qXajT05ovLDmRDPte4KImQBUZkYP5SCV0qAObWUGxstA1NcnMPYN2UYjg2NbcWbAE8sVP0RBatxQZknCM08SGnGtj0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725946661; c=relaxed/simple; bh=ctGM5HNGWg+TWVqntqqihBJb2GadXoWB4w1z564E9+8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SxmuZSiw22ym6sKseqyvaQ2s0IusTl8qdxxGNhc4wm+NIwbQsox4MwjFuZyZ4IgjkfmW5hZ91QGMnR3TO1cZsmoyVc7eOdj2bvgPw73/1YBS9CkStDzsVBo1erK0Tf1CfAEqX3fBrgOG4AElpzEm4+qNhnab5GI15cLSb0aDh30= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Oz2DVOdr; 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="Oz2DVOdr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D5FEC4CEC3; Tue, 10 Sep 2024 05:37:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725946660; bh=ctGM5HNGWg+TWVqntqqihBJb2GadXoWB4w1z564E9+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Oz2DVOdr+VvI7/44iJslvxhy3ZTzW7IDr2RrikdlefATT0aLt/fS0FU9HhNdaIhMd mqqwIKf6U5EKk+GicXOjdQi8vjdwuQ2kTlUxfsz9DKJLIYvu+Ur4lFrP9O9H05rTML IsX1cWMgDbvEtjbsRObcc/KrqP750QkHE1mVn3c0Lu8bAa7DA37XAwtxyUOfS2TiTk 93YGxAFtm54xPUh1VNMmfvWE9gYIn8EhEjMDyMR98IVj9Nd9IKvwtZYgeHh5jVY3FD bSJya0rPMnl7NNr3SJbnzoFC/54kjayVhVXf84Cz3vaBNSfavHsRMESvQ8+/qAE+ub DwHgR8OUDudHQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 3/5] bpf: Register mptcp tracing kfunc set Date: Tue, 10 Sep 2024 13:37:25 +0800 Message-ID: <868a19c46b7ec5592d1173e52470bb62c9a0344d.1725946276.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Since the kfuncs mptcp_subflow_active() and mptcp_subflow_set_scheduled() are invoked in the mptcp_subflow bpf_iter test in a ftrace hook for mptcp_sched_get_send(), it's necessary to register them into a BPF_PROG_TYPE_TRACING type kfunc set together with the bpf_iter mptcp_subflow helpers bpf_iter_mptcp_subflow_new()/_next()/_destroy(). Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 350672e24a3d..0b7a0c2634c4 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -260,9 +260,12 @@ __bpf_kfunc bool bpf_mptcp_subflow_queues_empty(struct= sock *sk) __bpf_kfunc_end_defs(); =20 BTF_KFUNCS_START(bpf_mptcp_sched_kfunc_ids) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy) +BTF_ID_FLAGS(func, mptcp_subflow_active) BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled) BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx_by_pos) -BTF_ID_FLAGS(func, mptcp_subflow_active) BTF_ID_FLAGS(func, mptcp_set_timeout) BTF_ID_FLAGS(func, mptcp_wnd_end) BTF_ID_FLAGS(func, tcp_stream_memory_free) @@ -280,6 +283,8 @@ static int __init bpf_mptcp_kfunc_init(void) int ret; =20 ret =3D register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set); + ret =3D ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_TRACING, + &bpf_mptcp_sched_kfunc_set); ret =3D ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &bpf_mptcp_sched_kfunc_set); #ifdef CONFIG_BPF_JIT --=20 2.43.0 From nobody Sun Dec 22 06:23:59 2024 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 560054F218 for ; Tue, 10 Sep 2024 05:37:42 +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=1725946662; cv=none; b=aMnmaSptwxx+CR4JoHZ4ERMeyeXrlL6YRGIEbE+m5gq7QIhbrOR3jDpyekYMJK1gWMjmCNFWxUuCWVf8Vgn2R1gPnd1EKRLP9f7A5CsWnptACWZkxPuYub6N2CVDBr0N1rdTX0Ozfl9uqsubGv7A3qUCdztyPNYZg57rGh6iyZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725946662; c=relaxed/simple; bh=O7H5p81f3ccOd4bUeotTC/JgYHamD54yF+Aj4VgqtxI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UcQTbjhEzQZQXw1kcsOY8rCZMSx39FYmz7cilVTc4W8JroYbUj0a2EgvdQzOi3kJBNjJZLMmL2/GUDT3G2lYvcE2DBu1nBjnrGTj4Wp4l7fZjpQ0nBKbwOFkeHUVlHaQhmztu7R+AQXIwLJyB2/r/4YSmtC6OSzvKpgCMYO2vwY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZWOePvNi; 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="ZWOePvNi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 278D4C4CEC3; Tue, 10 Sep 2024 05:37:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725946662; bh=O7H5p81f3ccOd4bUeotTC/JgYHamD54yF+Aj4VgqtxI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZWOePvNiMh7ekWzoUABPZi5h5M1Qk36sZvLBXBZOPTbfQBMkJO606kO1Qi2RE2QN+ YJurFRxncjFgmX9qz9w2nU/nuywnmJPSICgpcsjU2E0iw6FRhfZg7IC2uspp8oSIit jEPOuBADA8fJmDrHyTOawj5bf+DYXgfo6PTY5zUspn69xceS/UT737n/CBqfPkaK5o b3tUDl91dAqqeALzaRd0WZ1NRX1e9Q/BzEREYQjBxGwpXnb9namRd0yCUcW231uzTe OyTqXaZw4HtRSJj+JQQr4pCJUm7HFpg3hmLsU1L9lmrSm4Cf9Xq4b8iMoitooe2Rp2 R5ACUTXgIYx1Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 4/5] selftests/bpf: Add mptcp_subflow bpf_iter test prog Date: Tue, 10 Sep 2024 13:37:26 +0800 Message-ID: <4a114f88e8dce06e88e312268d0b35284ccd3f66.1725946276.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch adds a new mptcp bpf selftest program for the newly added mptcp_subflow bpf_iter. Export bpf_iter_mptcp_subflow_new/_next/_destroy into bpf_experimental.h then use bpf_for_each(mptcp_subflow, subflow, msk) to walk the mptcp subflow list. Add a ftrace hook for mptcp_sched_get_send() to do this test and invoke kfuncs mptcp_subflow_active() and mptcp_subflow_set_scheduled() in the loops. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/bpf_experimental.h | 7 ++++ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 4 ++ .../selftests/bpf/progs/mptcp_bpf_iter.c | 38 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_iter.c diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing= /selftests/bpf/bpf_experimental.h index 828556cdc2f0..97aad95c90c6 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -549,6 +549,13 @@ extern int bpf_iter_css_new(struct bpf_iter_css *it, extern struct cgroup_subsys_state *bpf_iter_css_next(struct bpf_iter_css *= it) __weak __ksym; extern void bpf_iter_css_destroy(struct bpf_iter_css *it) __weak __ksym; =20 +struct bpf_iter_mptcp_subflow; +extern int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it, + struct mptcp_sock *msk) __weak __ksym; +extern struct mptcp_subflow_context * +bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subflow *it) __weak __ks= ym; +extern void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *= it) __weak __ksym; + extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags= ) __weak __ksym; extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ks= ym; extern int bpf_wq_set_callback_impl(struct bpf_wq *wq, diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf.h b/tools/testing/= selftests/bpf/progs/mptcp_bpf.h index 928a1e5ad8db..3280d4183beb 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -43,9 +43,13 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_contex= t *subflow) } =20 /* ksym */ +extern bool mptcp_subflow_active(struct mptcp_subflow_context *subflow) __= ksym; extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subf= low, bool scheduled) __ksym; =20 +extern void bpf_rcu_read_lock(void) __ksym; +extern void bpf_rcu_read_unlock(void) __ksym; + extern struct mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned= int pos) __ksym; =20 diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_iter.c b/tools/tes= ting/selftests/bpf/progs/mptcp_bpf_iter.c new file mode 100644 index 000000000000..03168be3980b --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_iter.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2024, Kylin Software */ + +/* vmlinux.h, bpf_helpers.h and other 'define' */ +#include "bpf_tracing_net.h" +#include "mptcp_bpf.h" + +char _license[] SEC("license") =3D "GPL"; +int iter =3D 0; +int pid; + +SEC("fentry/mptcp_sched_get_send") +int BPF_PROG(trace_mptcp_sched_get_send, struct mptcp_sock *msk) +{ + struct mptcp_subflow_context *subflow; + int i =3D 0; + + if (bpf_get_current_pid_tgid() >> 32 !=3D pid) + return 0; + + bpf_rcu_read_lock(); + bpf_for_each(mptcp_subflow, subflow, msk) { + if (i++ >=3D MPTCP_SUBFLOWS_MAX) + break; + + if (subflow->token !=3D msk->token) + break; + + if (!mptcp_subflow_active(subflow)) + continue; + + mptcp_subflow_set_scheduled(subflow, false); + } + bpf_rcu_read_unlock(); + + iter =3D i; + return 0; +} --=20 2.43.0 From nobody Sun Dec 22 06:23:59 2024 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 6006214F122 for ; Tue, 10 Sep 2024 05:37:44 +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=1725946664; cv=none; b=upQMQHne1AEK35GQvZ8RnrgphE/grfDkGEh+05iarU+IANxroZuX88U4aY5XXgNaz8Os5Vrn0iQUmEr+AUseE18X8i8+/mfRkoL/SyIwF2pr+zIdyJOGE0vJEb2Fw6/7YmKGXSoa/S4lzc/RvHapUqPnAAvv4L9iy8IGRhEP0/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725946664; c=relaxed/simple; bh=NLfU1pjQezFnY8YcUH3vbn2qS4tUWZXoLEA1DCH68hg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OnGTnbmFL06+BYCcSNWKxs+EdBa+9iKQ6/5IaVlsO6/Mv2cCT4z+NVqbkE2LJXlJrK6SW6XnSNPrgvEKf3cKx8ZGU1jUl1GBDrhI9wIVSL80XZOZoW6C8GjKHfNgNanOg0XN8JUYvFwkzW4q/iW50OnljWEWMDth9pU9ZoQy3js= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WrOCgdS4; 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="WrOCgdS4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4F28C4CEC6; Tue, 10 Sep 2024 05:37:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725946664; bh=NLfU1pjQezFnY8YcUH3vbn2qS4tUWZXoLEA1DCH68hg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WrOCgdS4EZbR1tbM+zqe53rKJJUtmYW9HH5yBJsPA7tpRTEYxxUGOLBTWxMw8f+oZ crzbLmoXFjZILnvSwWwPpxkTfiGTnkfmD8tyAYSOfEXCx32YSbpgpO2yBOE0EFhpAe iiKfgRZuwVhaGbls/B5O3paIinumFUagkCXdZvxmhD8OOY3YIFqiR5J0rgS2Pbl3Yt BpWEVIOtBnnsMFLOYVgZEzxzKU3+RvPr2K35O7XyRJt7Kj8WIYASTXIQ2vtv1aAknz 0j8WNsDzw3/oQ0v4YUlgqiaXh/yBRHfhrIMLLbgfMTdbHVfnPuK3ay7NbrM2rTX6lp UjrI74q7n19TQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 5/5] selftests/bpf: Add mptcp_subflow bpf_iter subtest Date: Tue, 10 Sep 2024 13:37:27 +0800 Message-ID: <619a37a579799413134ef8c9fe804a00c54b7304.1725946276.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch adds a subtest named test_bpf_iter to load and verify the newly added mptcp_subflow type bpf_iter example in test_mptcp. Use endpoint_init() to add a new subflow endpoint. A new helper recv_send() is invoked to trigg= er the ftrace hook for mptcp_sched_get_send() after wait_for_new_subflows(). Check if skel->bss->iter equals 2 to verify whether the ftrace program loops twice as expected. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing= /selftests/bpf/prog_tests/mptcp.c index 2476f0a083bc..4ecfa6570b85 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -10,6 +10,7 @@ #include "mptcp_sock.skel.h" #include "mptcpify.skel.h" #include "mptcp_subflow.skel.h" +#include "mptcp_bpf_iter.skel.h" #include "mptcp_bpf_first.skel.h" #include "mptcp_bpf_bkup.skel.h" #include "mptcp_bpf_rr.skel.h" @@ -258,6 +259,34 @@ static void send_byte(int fd) ASSERT_EQ(write(fd, &b, sizeof(b)), 1, "send single byte"); } =20 +static int recv_send(int server_fd) +{ + char buf[1]; + int ret, fd; + ssize_t n; + + fd =3D accept(server_fd, NULL, NULL); + if (!ASSERT_OK_FD(fd, "accept")) + return -1; + + n =3D recv(fd, buf, sizeof(buf), 0); + if (!ASSERT_GT(n, 0, "recv")) { + ret =3D -1; + goto close; + } + + n =3D send(fd, buf, n, 0); + if (!ASSERT_GT(n, 0, "send")) { + ret =3D -1; + goto close; + } + + ret =3D 0; +close: + close(fd); + return ret; +} + static int verify_mptcpify(int server_fd, int client_fd) { struct __mptcp_info info; @@ -470,6 +499,60 @@ static void test_subflow(void) close(cgroup_fd); } =20 +static void run_bpf_iter(void) +{ + int server_fd, client_fd; + + server_fd =3D start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0); + if (!ASSERT_OK_FD(server_fd, "start_mptcp_server")) + return; + + client_fd =3D connect_to_fd(server_fd, 0); + if (!ASSERT_OK_FD(client_fd, "connect_to_fd")) + goto close_server; + + send_byte(client_fd); + wait_for_new_subflows(client_fd); + recv_send(server_fd); + + close(client_fd); +close_server: + close(server_fd); +} + +static void test_bpf_iter(void) +{ + struct mptcp_bpf_iter *skel; + struct nstoken *nstoken; + int err; + + skel =3D mptcp_bpf_iter__open_and_load(); + if (!ASSERT_OK_PTR(skel, "skel_open_load: mptcp_iter")) + return; + + skel->bss->pid =3D getpid(); + + err =3D mptcp_bpf_iter__attach(skel); + if (!ASSERT_OK(err, "skel_attach: mptcp_iter")) + goto skel_destroy; + + nstoken =3D create_netns(); + if (!ASSERT_OK_PTR(nstoken, "create_netns: mptcp_iter")) + goto skel_destroy; + + if (endpoint_init("subflow") < 0) + goto close_netns; + + run_bpf_iter(); + + ASSERT_EQ(skel->bss->iter, 2, "iter"); + +close_netns: + cleanup_netns(nstoken); +skel_destroy: + mptcp_bpf_iter__destroy(skel); +} + static struct nstoken *sched_init(char *flags, char *sched) { struct nstoken *nstoken; @@ -651,6 +734,8 @@ void test_mptcp(void) test_mptcpify(); if (test__start_subtest("subflow")) test_subflow(); + if (test__start_subtest("bpf_iter")) + test_bpf_iter(); if (test__start_subtest("default")) test_default(); if (test__start_subtest("first")) --=20 2.43.0