From patchwork Fri Oct 18 16:00:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13842002 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 C198A1DED5B for ; Fri, 18 Oct 2024 16:00: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=1729267236; cv=none; b=hLGf3idrtjsNbVZfNxn9DUlK5Xnyg0sG9qX2gWDyy0Lmyx+K5U4JBDgl9EGNrKpETj4I6HtYFepR0CHrZnKk+D8LUCWRnuzV9+x//qyeejzNRbstgkosft2ujhHJBBDCL7AXvleT/u1x0bkqqV5fpoM/0Dc/U+lLzN8FOthfrgI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729267236; c=relaxed/simple; bh=O/aDW83wsVpbVBtm3apBXP+i5+MgUJPEBFLiPHCpwps=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cqj2cdv4hZcWZvk11pMxsM95HHOE1hwYtR3ZRXQlKl0u4Zo/dNeftOHe5bd97uWmDvCON4fMa2PFoTNPxCizcTEsQPZCuLwrbmDQac3Rl/cpJxa43V7mnIVBMDWxY13/vqVI3Mp1VWQ1sYKkZXFP17J4QMdQWPXIhIz/6+vGy8c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ha+Ndawn; 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="ha+Ndawn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 273BFC4CEC7; Fri, 18 Oct 2024 16:00:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729267236; bh=O/aDW83wsVpbVBtm3apBXP+i5+MgUJPEBFLiPHCpwps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ha+NdawnexMXytLP/Ghwhua5/iYoXJzYIeMZc8bf9FRHSqyYyEY/4O6TBZ9vXxeC/ 3eO9vlc5mKWeXUDvNRQnl8Fy/z/BVRb3xJm4FhD768ouRgZKtwiWr8MdqjnN16iZ7N Za9tzxF5LwCHHGUrX/tCIkHr1j2Zb1GtgE8tWZ8Ih0dc0rzIgyO0UF8DpNR3HO0QiJ YjkVJ8UtbvnDkgV58YAzzv4W0n4vkZzbhqLE1KkKlefFHrSqoZE/bsEiDFpDlZvM1J Yeb0wtopMad6GwyxQdRBTcFDGphSDtmvPjfcUh14WEQl4h6KIcchHc8ZC+Ds7efZA4 uo0hQgqRu6pOA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v12 1/8] bpf: Register mptcp common kfunc set Date: Sat, 19 Oct 2024 00:00:21 +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 MPTCP helper mptcp_sk() is used to convert struct sock to mptcp_sock. Helpers mptcp_subflow_ctx() and mptcp_subflow_tcp_sock() are used to convert between struct mptcp_subflow_context and sock. They all will be used in MPTCP BPF programs too. This patch defines corresponding wrappers of them, and put the wrappers into mptcp common kfunc set and register the set with the flag BPF_PROG_TYPE_UNSPEC to let them accessible to all types of BPF programs. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index a9d6b5b939a2..efab2e6e28ef 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -209,6 +209,23 @@ __diag_push(); __diag_ignore_all("-Wmissing-prototypes", "kfuncs which will be used in BPF programs"); +__bpf_kfunc static struct mptcp_sock *bpf_mptcp_sk(struct sock *sk) +{ + return mptcp_sk(sk); +} + +__bpf_kfunc static struct mptcp_subflow_context * +bpf_mptcp_subflow_ctx(const struct sock *sk) +{ + return mptcp_subflow_ctx(sk); +} + +__bpf_kfunc static struct sock * +bpf_mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) +{ + return mptcp_subflow_tcp_sock(subflow); +} + __bpf_kfunc struct mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int pos) { @@ -224,6 +241,17 @@ __bpf_kfunc bool bpf_mptcp_subflow_queues_empty(struct sock *sk) __diag_pop(); +BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids) +BTF_ID_FLAGS(func, bpf_mptcp_sk) +BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx) +BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock) +BTF_KFUNCS_END(bpf_mptcp_common_kfunc_ids) + +static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = { + .owner = THIS_MODULE, + .set = &bpf_mptcp_common_kfunc_ids, +}; + BTF_KFUNCS_START(bpf_mptcp_sched_kfunc_ids) BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled) BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx_by_pos) @@ -245,6 +273,8 @@ static int __init bpf_mptcp_kfunc_init(void) int ret; ret = register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set); + ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_UNSPEC, + &bpf_mptcp_common_kfunc_set); ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &bpf_mptcp_sched_kfunc_set); #ifdef CONFIG_BPF_JIT From patchwork Fri Oct 18 16:00:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13842003 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 A7BAD1F4266 for ; Fri, 18 Oct 2024 16:00: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=1729267238; cv=none; b=HD7dnKVzQ3bGWheA9a8IToOu9KFAAl7+XbvQnyys4VjuiyeQyap4URrsomYF3Wylv5DmmJIFXKsHQzcG8u1K8EdVIcPac8GmMacrYmcpXJMm8L7gkPqForJvj+ZtKcQGRBJbtRSsmNrWgJNUuuAFPLSY+FGGFBg4C0KVE1z2ftM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729267238; c=relaxed/simple; bh=/UWS8+VBjYFrqdOw4KZJINWR8TNN98J/VAUIMhPLzWk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eUZMm/3NGUEOo9mMCYe/OfSr9VLWf0c9qoXbgsK9oXb4psZqBJdcau2Ww9pCkZID/rogHAaNvAKhep+z0tlda5jcrcMS2L9bIrjDj2PrbWldAiWl+ZapHUBLTnPt0fUDRTMK3E5M47IU25e6A92d/NStgzaaXlcATh31QnPoG2I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=syOxTWs0; 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="syOxTWs0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05133C4CEC3; Fri, 18 Oct 2024 16:00:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729267238; bh=/UWS8+VBjYFrqdOw4KZJINWR8TNN98J/VAUIMhPLzWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=syOxTWs0oGN5w1dAaZqkN0QmXXXWn1wrB+sUIB/UeQWFTWcWSGok+ECQOX/G7fIaE DtmCMYOnl+TdSMLW0Tb3eN45jlwhHJTRh7GCcrTRqVxVw1Ln+0NgtuNK5iu0sahNW7 Zvfpq3NzN+WntEzjUd/K1adIczeU/ZirMHXZZoxLbdf+7c+BxwtW+ZyEWvZmkrFAVt LwSU0+Ous51SDMHp2iNoQhqtdV0hbbhNgr9/qQqsXChFzw5LNKFTiZuhelyegw+PeV JGnlwFh+REqkuqOf2ATgfe7xUlHwIt4p3roVI0dUSQZTOzxnmFKO2W2WTRD/lgIB8b 4pJ+uujq0EgXw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v12 2/8] bpf: Add mptcp_subflow bpf_iter Date: Sat, 19 Oct 2024 00:00:22 +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 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(). And register these bpf_iter mptcp_subflow into mptcp common kfunc set. Then bpf_for_each() for mptcp_subflow can be used in BPF program like this: bpf_for_each(mptcp_subflow, subflow, msk) kfunc(subflow); v2: remove msk->pm.lock in _new() and _destroy() (Martin) drop DEFINE_BPF_ITER_FUNC, change opaque[3] to opaque[2] (Andrii) v3: drop bpf_iter__mptcp_subflow v4: if msk is NULL, initialize kit->msk to NULL in _new() and check it in _next() (Andrii) v5: use list_is_last() instead of list_entry_is_head() add KF_ITER_NEW/NEXT/DESTROY flags add msk_owned_by_me in _new() v6: add KF_TRUSTED_ARGS flag (Andrii, Martin) "Suggested-by: Martin KaFai Lau " Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index efab2e6e28ef..65fa84d1e745 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -205,9 +205,16 @@ static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { .set = &bpf_mptcp_fmodret_ids, }; -__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 static struct mptcp_sock *bpf_mptcp_sk(struct sock *sk) { @@ -226,6 +233,37 @@ bpf_mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) return mptcp_subflow_tcp_sock(subflow); } +__bpf_kfunc static int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it, + struct mptcp_sock *msk) +{ + struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + + kit->msk = msk; + if (!msk) + return -EINVAL; + + msk_owned_by_me(msk); + + kit->pos = &msk->conn_list; + return 0; +} + +__bpf_kfunc static struct mptcp_subflow_context * +bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subflow *it) +{ + struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + + if (!kit->msk || list_is_last(kit->pos, &kit->msk->conn_list)) + return NULL; + + kit->pos = kit->pos->next; + return list_entry(kit->pos, struct mptcp_subflow_context, node); +} + +__bpf_kfunc static void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it) +{ +} + __bpf_kfunc struct mptcp_subflow_context * bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int pos) { @@ -239,12 +277,15 @@ __bpf_kfunc bool bpf_mptcp_subflow_queues_empty(struct sock *sk) return tcp_rtx_queue_empty(sk); } -__diag_pop(); +__bpf_kfunc_end_defs(); BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids) BTF_ID_FLAGS(func, bpf_mptcp_sk) BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx) BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock) +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_KFUNCS_END(bpf_mptcp_common_kfunc_ids) static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = { From patchwork Fri Oct 18 16:00:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13842004 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 068744207A for ; Fri, 18 Oct 2024 16:00:39 +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=1729267240; cv=none; b=E8cGAOSfFPmKRtG+chzOcwQhdZHwnk/boRh1aZ44frZVeONapRsE1fSWyCn6JSjppJbAVM7K4E1OKI2x7+2NdEGrlKnegkihn5OHrv3ssGrkvgJYnL/Dd/ath3ni/A99pihiTBviRZzy2+PHiNiGP3I/KEsTqbP/14fkD9i5USc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729267240; c=relaxed/simple; bh=gfI7ffM4BR6nmpfVDJI4OeNg/i5LZsn1ZqXbETAKL/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XdOhcBsVIdpKh4IfMOEV3TGPCq7yRNbI2bjsgwuIZPJM1v6r8Ju7dfthakktJWlgdfk4L0p0CgJ8ZPizPYrLh0OA9K5h5+7qPGrut4Wg5jlCHeu9lfbo6D1BHCtrFbjL8wJGQt086ONpWRUzMv50c/B5yXP9Om3Ww2dxa08tmuM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k/Xaml/x; 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="k/Xaml/x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2862C4CEC5; Fri, 18 Oct 2024 16:00:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729267239; bh=gfI7ffM4BR6nmpfVDJI4OeNg/i5LZsn1ZqXbETAKL/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k/Xaml/xTiTeHhfDTcw2ff8IYFj6qidirdVAWgN6tgCKxi1RV0qzWcJdvqFGHd7k6 wKuH1zJXxdoCkaySTykicoavPH6hGq+LUsLrWeZPAthrc+rca/l4aZYGDsR7XzQElE gSyAs7jDFfNSzh5TzO+HjKXidLJSoMJBKWy9YnvP9CsbsqrolhCgxKW2bSwLRH9/OQ WqU4tDAhX98O9M1WNFl/dsCWeWieXtNcL4betRYeBWtSvp+QFkd5ANVmm36DA7k9wQ D5WgENYGzg3NxAIQlCc5t6irjpb4hQ9hlNh3g5GJLMmiP9kN3pItWhCGuocnHWvs3Y qeQBmg1n44p/g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v12 3/8] bpf: Acquire and release mptcp socket Date: Sat, 19 Oct 2024 00:00:23 +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 The KF_TRUSTED_ARGS flag is used for bpf_iter_mptcp_subflow_new, it indicates that the all pointer arguments are valid. It's necessary to add a KF_ACQUIRE helper to get valid "msk". This patch adds bpf_mptcp_sock_acquire() and bpf_mptcp_sock_release() helpers for this. Increase sk->sk_refcnt in _acquire() and decrease it in _release(). Register them with KF_ACQUIRE flag and KF_RELEASE flag. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 65fa84d1e745..cf660e561d7b 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -264,6 +264,22 @@ __bpf_kfunc static void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_sub { } +__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) { @@ -286,6 +302,8 @@ BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock) 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 Fri Oct 18 16:00:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13842005 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 1FAFD13BADF for ; Fri, 18 Oct 2024 16:00:41 +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=1729267242; cv=none; b=d/yx4zCu0iwiUq6+fGh7bId9Lj+SFiSCUr+3uB1aryZ1SvWCuTOgLEzoquiM0r3r04gD8bcx3fx2/NgtHXGcLLUvzuC+wCyXHMtcn9RDrNj4j3BUDZEXpoJqhNfN8aw55PZI2Bth7RnS75WJccmtccsghKOgNrMJqX9ufoUAo6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729267242; c=relaxed/simple; bh=Igt3me+CnEmDDCvFx8jssf6o0vBlnpw5qHsXTC9jK2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EWXf/AJ2p5whUAo/OrvjGA7i09yhOoasM+etm8jVcL/E9dMUYyD1zFHYYRSJEngdgWOfcGLYfg/rVzz2REvBOMqYf19uphHoAUsvuzRphpiWmCRUUux51y7vTxZg6UieKu2g4IoQd++2/9MMECVapLzYwvHMn4K6V257vLWwLTA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=teay/xw8; 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="teay/xw8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76715C4CEC3; Fri, 18 Oct 2024 16:00:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729267241; bh=Igt3me+CnEmDDCvFx8jssf6o0vBlnpw5qHsXTC9jK2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=teay/xw85hC2zGQrgaJiyqGTAvEZuyfiDI47MPz4Gv2Z6FkoJWWbx21kUckqRs7xX PkbKpKmRl/ORaRxq7f1Ho5pjC2t4NPADmV9WHdrEpxuD2L4VlUtDuXW3OO2wTsrlLb jQ4wlZWG0VX4rw4E78+jg1qJw/HJUZYlXpcCfEsKzxPAbBwncb4SHkhv8ShbINJRRR PytSCgyokGE692ZxV3bsWvs8H1srmPXyciH6ohwn1sXCyoB0uUIGMHpVRrm8b0Prw1 zE4R6m4H3q3dd7hefIWybCi65dKDCES8X7lPd/ZXRX9DRkPiGQswfo0etRuR9J+zQq NIuz6doJmIcrw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v12 4/8] selftests/bpf: More endpoints for endpoint_init Date: Sat, 19 Oct 2024 00:00:24 +0800 Message-ID: <7478ec95a1edd1c718c2123282e14eebbe98d2cf.1729267039.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 This patch changes ADDR_2 from "10.0.1.2" to "10.0.2.1", and adds two more IPv4 test addresses ADDR_3 - ADDR_4, four IPv6 addresses ADDR6_1 - ADDR6_4. Add a new helper address_init() to initialize all these addresses. Add a new parameter "endpoints" for endpoint_init() to control how many endpoints are used for the tests. This makes it more flexible. Update the parameters of endpoint_init() in test_subflow(). Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 56 +++++++++++++++++-- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index d0dc2e4fbe46..02fdff87df2d 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -19,7 +19,13 @@ #define NS_TEST "mptcp_ns" #define ADDR_1 "10.0.1.1" -#define ADDR_2 "10.0.1.2" +#define ADDR_2 "10.0.2.1" +#define ADDR_3 "10.0.3.1" +#define ADDR_4 "10.0.4.1" +#define ADDR6_1 "dead:beef:1::1" +#define ADDR6_2 "dead:beef:2::1" +#define ADDR6_3 "dead:beef:3::1" +#define ADDR6_4 "dead:beef:4::1" #define PORT_1 10001 #define WITH_DATA true #define WITHOUT_DATA false @@ -351,22 +357,60 @@ static void test_mptcpify(void) close(cgroup_fd); } -static int endpoint_init(char *flags) +static int address_init(void) { SYS(fail, "ip -net %s link add veth1 type veth peer name veth2", NS_TEST); SYS(fail, "ip -net %s addr add %s/24 dev veth1", NS_TEST, ADDR_1); + SYS(fail, "ip -net %s addr add %s/64 dev veth1 nodad", NS_TEST, ADDR6_1); SYS(fail, "ip -net %s link set dev veth1 up", NS_TEST); SYS(fail, "ip -net %s addr add %s/24 dev veth2", NS_TEST, ADDR_2); + SYS(fail, "ip -net %s addr add %s/64 dev veth2 nodad", NS_TEST, ADDR6_2); SYS(fail, "ip -net %s link set dev veth2 up", NS_TEST); - if (SYS_NOFAIL("ip -net %s mptcp endpoint add %s %s", NS_TEST, ADDR_2, flags)) { + + SYS(fail, "ip -net %s link add veth3 type veth peer name veth4", NS_TEST); + SYS(fail, "ip -net %s addr add %s/24 dev veth3", NS_TEST, ADDR_3); + SYS(fail, "ip -net %s addr add %s/64 dev veth3 nodad", NS_TEST, ADDR6_3); + SYS(fail, "ip -net %s link set dev veth3 up", NS_TEST); + SYS(fail, "ip -net %s addr add %s/24 dev veth4", NS_TEST, ADDR_4); + SYS(fail, "ip -net %s addr add %s/64 dev veth4 nodad", NS_TEST, ADDR6_4); + SYS(fail, "ip -net %s link set dev veth4 up", NS_TEST); + + return 0; +fail: + return -1; +} + +static int endpoint_add(char *addr, char *flags) +{ + return SYS_NOFAIL("ip -net %s mptcp endpoint add %s %s", NS_TEST, addr, flags); +} + +static int endpoint_init(char *flags, u8 endpoints) +{ + int ret = -1; + + if (!endpoints || endpoints > 4) + goto fail; + + if (address_init()) + goto fail; + + if (SYS_NOFAIL("ip -net %s mptcp limits set add_addr_accepted 4 subflows 4", + NS_TEST)) { printf("'ip mptcp' not supported, skip this test.\n"); test__skip(); goto fail; } - return 0; + if (endpoints > 1) + ret = endpoint_add(ADDR_2, flags); + if (endpoints > 2) + ret = ret ?: endpoint_add(ADDR_3, flags); + if (endpoints > 3) + ret = ret ?: endpoint_add(ADDR_4, flags); + fail: - return -1; + return ret; } static void wait_for_new_subflows(int fd) @@ -452,7 +496,7 @@ static void test_subflow(void) if (!ASSERT_OK_PTR(nstoken, "create_netns: mptcp_subflow")) goto skel_destroy; - if (endpoint_init("subflow") < 0) + if (endpoint_init("subflow", 2) < 0) goto close_netns; run_subflow(); From patchwork Fri Oct 18 16:00:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13842006 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 DE8D4200B93 for ; Fri, 18 Oct 2024 16:00:43 +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=1729267244; cv=none; b=uwFhdSZloyyjdj4CtBmarY23k5jhbFnHlYT5QwgpMEb1G3AGuv2+6sF4qNJOTLrEBv/uK9ERZRQ9OoEhbpI5t4QRNTItNZIxr4Zkq7NJVY4gxLysPG/td5IkbjrpcsdROcmOfscK7EIdonT3cVHVQMIA8UaKuUvImS6wHeiosUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729267244; c=relaxed/simple; bh=9cY+q8M8YhQo/6ZqA7vpVGocB5n+bdUr8nGEdtj8xw8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fxeXqyMJVlHSuLRQsqkvpeTWOOZsTOMiGp1xr/f6Duux4kNbOzrm1xk/hpG9rJslme+hl4xCZOD8MA8XvR7PqNrT8fSFON9QFn8t4fmy+2HWVEBSogJQJO/4mr/ZjI95chNG5Ns3BQCD+UxTvLFrhe3Kmo+Y6xnweXkZjYAFnmQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MeYcy0nD; 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="MeYcy0nD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5184DC4CEC3; Fri, 18 Oct 2024 16:00:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729267243; bh=9cY+q8M8YhQo/6ZqA7vpVGocB5n+bdUr8nGEdtj8xw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MeYcy0nDf/rRoO5VC7c0Uz5NRriBVUhRSKLKtjQH6x0vLGrO1py29E1HNDpKx+Iz+ LiD88ozMfEK67VSA/o/STQkhQJqrh8SWaLuyJDmWbC0zHMLgqytLIsL3SW3N4f0jzg CvOEqig7ffyjS4rhxc5bqGVQa8EXdlfmjlH04f3rTHvz8aC7g2jGS22DvRPxcHdFHw ICvtCF7GwsETre69CmlE06mrB1E3zmJmFuWPcPJO8rb1V6bScI0zoHhCwWIEJUCphT PEGS0fAOUuF1nAoODADVpwdOKB9lY2JRv2wlR43/tWP91/jwo33bHp4J8l4ukwx593 JfbgDfUEQodMA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v12 5/8] selftests/bpf: Add mptcp_subflow bpf_iter subtest Date: Sat, 19 Oct 2024 00:00:25 +0800 Message-ID: <716b9fefec475d2623b632406875a3bc8b87778a.1729267039.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 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, bpf_mptcp_sock_acquire/_release and other helpers into bpf_experimental.h. Use bpf_mptcp_sock_acquire() to acquire the msk, then 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 veriable local_ids, then invoke the kfunc bpf_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, and release the msk. 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 --- .../testing/selftests/bpf/bpf_experimental.h | 7 ++ .../testing/selftests/bpf/prog_tests/mptcp.c | 73 +++++++++++++++++++ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 9 +++ .../selftests/bpf/progs/mptcp_bpf_iters.c | 64 ++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h index b0668f29f7b3..d43690b17468 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -575,6 +575,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; +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 __ksym; +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 __ksym; extern int bpf_wq_set_callback_impl(struct bpf_wq *wq, diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 02fdff87df2d..0799a3c65188 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -11,6 +11,7 @@ #include "mptcp_sock.skel.h" #include "mptcpify.skel.h" #include "mptcp_subflow.skel.h" +#include "mptcp_bpf_iters.skel.h" #include "mptcp_bpf_first.skel.h" #include "mptcp_bpf_bkup.skel.h" #include "mptcp_bpf_rr.skel.h" @@ -40,6 +41,9 @@ #ifndef MPTCP_INFO #define MPTCP_INFO 1 #endif +#ifndef TCP_IS_MPTCP +#define TCP_IS_MPTCP 43 /* Is MPTCP being used? */ +#endif #ifndef MPTCP_INFO_FLAG_FALLBACK #define MPTCP_INFO_FLAG_FALLBACK _BITUL(0) #endif @@ -509,6 +513,73 @@ static void test_subflow(void) close(cgroup_fd); } +static void run_iters_subflow(void) +{ + int server_fd, client_fd; + int is_mptcp, err; + socklen_t len; + + server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0); + if (!ASSERT_OK_FD(server_fd, "start_mptcp_server")) + return; + + client_fd = 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); + + len = sizeof(is_mptcp); + /* mainly to trigger the BPF program */ + err = getsockopt(client_fd, SOL_TCP, TCP_IS_MPTCP, &is_mptcp, &len); + if (ASSERT_OK(err, "getsockopt(client_fd, TCP_IS_MPTCP)")) + ASSERT_EQ(is_mptcp, 1, "is_mptcp"); + + close(client_fd); +close_server: + close(server_fd); +} + +static void test_iters_subflow(void) +{ + struct mptcp_bpf_iters *skel; + struct nstoken *nstoken; + int cgroup_fd; + + cgroup_fd = test__join_cgroup("/iters_subflow"); + if (!ASSERT_OK_FD(cgroup_fd, "join_cgroup: iters_subflow")) + return; + + skel = mptcp_bpf_iters__open_and_load(); + if (!ASSERT_OK_PTR(skel, "skel_open_load: iters_subflow")) + goto close_cgroup; + + skel->links.iters_subflow = bpf_program__attach_cgroup(skel->progs.iters_subflow, + cgroup_fd); + if (!ASSERT_OK_PTR(skel->links.iters_subflow, "attach getsockopt")) + goto skel_destroy; + + nstoken = create_netns(); + if (!ASSERT_OK_PTR(nstoken, "create_netns: iters_subflow")) + goto skel_destroy; + + if (endpoint_init("subflow", 4) < 0) + goto close_netns; + + run_iters_subflow(); + + /* 1 + 2 + 3 + 4 = 10 */ + ASSERT_EQ(skel->bss->ids, 10, "subflow ids"); + +close_netns: + cleanup_netns(nstoken); +skel_destroy: + mptcp_bpf_iters__destroy(skel); +close_cgroup: + close(cgroup_fd); +} + static struct nstoken *sched_init(char *flags, char *sched) { struct nstoken *nstoken; @@ -690,6 +761,8 @@ void test_mptcp(void) test_mptcpify(); if (test__start_subtest("subflow")) test_subflow(); + if (test__start_subtest("iters_subflow")) + test_iters_subflow(); if (test__start_subtest("default")) test_default(); if (test__start_subtest("first")) diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf.h b/tools/testing/selftests/bpf/progs/mptcp_bpf.h index c3800f986ae1..3b20cfd44505 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -43,6 +43,15 @@ 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_sock *bpf_mptcp_sk(struct sock *sk) __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 new file mode 100644 index 000000000000..1bede22a7e3d --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c @@ -0,0 +1,64 @@ +// 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") = "GPL"; +int ids; + +#ifndef TCP_IS_MPTCP +#define TCP_IS_MPTCP 43 /* Is MPTCP being used? */ +#endif + +SEC("cgroup/getsockopt") +int iters_subflow(struct bpf_sockopt *ctx) +{ + struct mptcp_subflow_context *subflow; + struct bpf_sock *sk = ctx->sk; + struct sock *ssk = NULL; + struct mptcp_sock *msk; + int local_ids = 0; + + if (!sk || sk->protocol != IPPROTO_MPTCP || + ctx->level != SOL_TCP || ctx->optname != TCP_IS_MPTCP) + return 1; + + msk = bpf_mptcp_sk((struct sock *)sk); + if (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) { + /* Here MPTCP-specific packet scheduler kfunc can be called: + * this test is not doing anything really useful, only to + * verify the iteration works. + */ + + local_ids += subflow->subflow_id; + + /* only to check the following kfunc works */ + ssk = bpf_mptcp_subflow_tcp_sock(subflow); + } + + if (!ssk) + goto out; + + /* assert: if not OK, something wrong on the kernel side */ + if (ssk->sk_dport != ((struct sock *)msk)->sk_dport) + goto out; + + /* only to check the following kfunc works */ + subflow = bpf_mptcp_subflow_ctx(ssk); + if (subflow->token != msk->token) + goto out; + + ids = local_ids; + +out: + bpf_mptcp_sock_release(msk); + return 1; +} From patchwork Fri Oct 18 16:00:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13842007 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 699C24207A for ; Fri, 18 Oct 2024 16:00:45 +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=1729267245; cv=none; b=oKOfyCDqtoN9kKu1rt54BqYBrjzdT+sl/IHD9GeG8ATHc4n9eE38niBLLM8oHZ4ywAKsribr7Y4cQ10IURuT4QoUAh6gH9+v4ecJFqXTmF+vFF8IfBZ5gVOqlNsqAGK0tTHB3OIo1Pcn7ci/a0BW5TUTGXa+Nd0GjBgGmBC5Vcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729267245; c=relaxed/simple; bh=EQEWyWnu9P3fBP8ACAy6PgdqSzcBNoHCF1KWEezyb+4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O5nf5t3W3gYn8imj3ahxd++l/6F8c+JQmTr4JVSyo9HYfcFbcdWW3WE6LruI6N6uTXzO03KqkZvjeyEz2d/GIkIiJT1OSHrBTM7ijwM6ZLubkvnjpPMlL4MZilfYpyZmmQEw2kr8d/h8iqU5E8wjqFjPVSlo3NOf+8CAdHCeZh8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TT8UYeX/; 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="TT8UYeX/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECFB4C4CEC5; Fri, 18 Oct 2024 16:00:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729267245; bh=EQEWyWnu9P3fBP8ACAy6PgdqSzcBNoHCF1KWEezyb+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TT8UYeX/I5Z3dyQXgp0Hvb/ZuJaBI3SdUNP1HMU4bGSXsfYAvQ80/7rZVIJhXCqSk NmKlV+79+20MESW+XGG9/0nAqQZDVbzEKqpQkNgvzH53rze/rNmMdg8ZkNux9E8PnB 5HDHVD0oYYffMlUpkvOF3SLELie6KEllj0/uUMRQmUlIg7xp6Z6NuWrsGMQzgGOBMP KtQWKINwft3eAccDfVDy6C6QlABeHZdIWacFFIN1DpVdd9tgytRJpZY5QaFb1AlZAb sdD3urTS0tXW1WGBqy4y1PY0rRzIO9/Dzgk9GHdlB+b9ikeRoj7ZaYELtyxeg26S2a 7OcgY57zCxXTg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v12 6/8] Squash to "selftests/bpf: Add bpf scheduler test" Date: Sat, 19 Oct 2024 00:00:26 +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 Update endpoint_init() in sched_init(). Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 0799a3c65188..be746e0fc393 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -588,7 +588,7 @@ static struct nstoken *sched_init(char *flags, char *sched) if (!ASSERT_OK_PTR(nstoken, "create_netns")) return NULL; - if (endpoint_init("subflow") < 0) + if (endpoint_init("subflow", 2) < 0) goto fail; SYS(fail, "ip netns exec %s sysctl -qw net.mptcp.scheduler=%s", NS_TEST, sched); From patchwork Fri Oct 18 16:00:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13842008 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 129514207A for ; Fri, 18 Oct 2024 16:00: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=1729267247; cv=none; b=AfxrBiG2F8odOKeh7f/HOFajR64cvpQWjnpp2z5+giAEIynRJXN80MGaJuLe5T+qU6oEQu/iAp51sz2HiK6EHP8Y35pFcN5ee/H3axUpq/otmK5CAubWG/8wWVwU9mHfDtSN/e5FJXMB1uXFcPBVYHtmpCENNNGwZQs/3xYdYX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729267247; c=relaxed/simple; bh=Kbg/woWQyt8SzsP3SFPPdsPppNrlRZawsUM/d+hlE0o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GJwn6jC6E5rKc0vTJgNNpJ2jtq1iuL+c7y/mHPFCjg+pJxOPndRkZguOwpRUIHY8oW967vV4ilEpk9Pvy2O3QB8gF4mnwNoNrOm71juMPaSZXsRjJpHBtJ/+PRZu6JGkSVUErWBu+t1V+aZdC1fMAiU2QizYRuK8lY5RqqAv4Lk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eg3TedHb; 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="eg3TedHb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACB6EC4CEC3; Fri, 18 Oct 2024 16:00:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729267246; bh=Kbg/woWQyt8SzsP3SFPPdsPppNrlRZawsUM/d+hlE0o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eg3TedHb6IRLqJOjjoolmvhv06DK5YTObYMQwNsoatAg61Fms/umMDVURAOYlJZnJ CSUYy6sGIWuGxiqOz4g/bxQPb2isZjB37uNAXPtk/+MokI2bDOvREB++bJhf75ttXM DjMhwugBlLqNF+nroJ6kbQQtwDFpCgpX2ti9mjUcQbmzT5pAkw04rf93rSdAdwZdQv jqoyEW0E25iM+Pjczbuoa+d5kUpMNLqeIeeFHVKbdC2sp7bcKEpI7gmr7mAz0+N4GG t8QmSSJ46x8TgVZiZ08wJ5SxLH/2eY6YbG75niSGqgHj++1nBLRnT3d4soJomxYioD 2NrAwpmdpWbEA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v12 7/8] Revert "bpf: Export more bpf_burst related functions" Date: Sat, 19 Oct 2024 00:00:27 +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 This reverts commit 371136b55b559e2ef4d117a901b9f96ee036a175. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 11 ----------- net/mptcp/protocol.c | 4 ++-- net/mptcp/protocol.h | 3 --- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index cf660e561d7b..476620526c79 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -288,11 +288,6 @@ bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int p return data->contexts[pos]; } -__bpf_kfunc bool bpf_mptcp_subflow_queues_empty(struct sock *sk) -{ - return tcp_rtx_queue_empty(sk); -} - __bpf_kfunc_end_defs(); BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids) @@ -314,12 +309,6 @@ static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = { BTF_KFUNCS_START(bpf_mptcp_sched_kfunc_ids) 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) -BTF_ID_FLAGS(func, bpf_mptcp_subflow_queues_empty) -BTF_ID_FLAGS(func, mptcp_pm_subflow_chk_stale) BTF_KFUNCS_END(bpf_mptcp_sched_kfunc_ids) static const struct btf_kfunc_id_set bpf_mptcp_sched_kfunc_set = { diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 21bc3586c33e..b0e9a745ea62 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -50,7 +50,7 @@ DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions); static struct net_device mptcp_napi_dev; /* Returns end sequence number of the receiver's advertised window */ -u64 mptcp_wnd_end(const struct mptcp_sock *msk) +static u64 mptcp_wnd_end(const struct mptcp_sock *msk) { return READ_ONCE(msk->wnd_end); } @@ -489,7 +489,7 @@ static long mptcp_timeout_from_subflow(const struct mptcp_subflow_context *subfl inet_csk(ssk)->icsk_timeout - jiffies : 0; } -void mptcp_set_timeout(struct sock *sk) +static void mptcp_set_timeout(struct sock *sk) { struct mptcp_subflow_context *subflow; long tout = 0; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index b963e68451b1..0624de84e339 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -720,9 +720,6 @@ void __mptcp_subflow_send_ack(struct sock *ssk); void mptcp_subflow_reset(struct sock *ssk); void mptcp_subflow_queue_clean(struct sock *sk, struct sock *ssk); void mptcp_sock_graft(struct sock *sk, struct socket *parent); -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); From patchwork Fri Oct 18 16:00:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13842009 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 AD267133987 for ; Fri, 18 Oct 2024 16:00: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=1729267248; cv=none; b=c96Fgwiz9NpUDqDL7mxzaQK2kIlla6rIrLitcKkZOXEXstgJDx2YanBCi/4/gNlui6NRr/Rz6FgG+DPThZa93VgQ6NgfHafpmMdg2eNY1KuNlMLDTUUgOYHMNFru0EhhZjnD3cVKME0sL0pBj9E4Rl2m/f9XuXWswkAxBSrps9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729267248; c=relaxed/simple; bh=oLzEaoF7HhnJ/lJr3NNq07/yId5b/25FLKZSkKUO4MM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sbtoUQunpVMW5AyPb+uEnwjRAb0JwwWIYgayOiwEsYOBo93aaxzh7a0BXXExpQEFltT7UEBR0JcnrLQEZEHM7egYiox21IJbOIgCQEW+tMI14YlFFryRXx+T+SENprdVBfCn7OiHidbzd0RWlUgoHN84/ISzaRxvYe2d2K3pRyM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T1om+gRT; 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="T1om+gRT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22766C4CEC5; Fri, 18 Oct 2024 16:00:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729267248; bh=oLzEaoF7HhnJ/lJr3NNq07/yId5b/25FLKZSkKUO4MM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T1om+gRTjmGXnBKATYFfpWQ7qNtsBVm9FWf6aqJcgRAsnedH20ARH0cBKLdCbMi2i Ts+DSO47SJiGoB+utpURJpcuMMq4Upb7CbKNytAuGyb0Yhl1cNpJXkmuL1y7DKPIdF JTeXr8IwbjrvTvQfxs40zEPkPeWv1M/5MidXPNJ2Zar2Z7m97Gs0/seHg1CsOlTH2/ GyKiPq+cgDhnjmj8jeMcfYXlho1NQkHdkxcn9zuUD5yM0fRilUm8UJlrCQ8hvWk+C2 mugPk9mRWz4G+4bKjBVugYuG8UQNuHxwZQRwBOg3UlwIUke+8tkpvzeZo9IaIPbBdR a6TzhHHETgOhA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v12 8/8] Squash to "bpf: Add bpf_mptcp_sched_kfunc_set" Date: Sat, 19 Oct 2024 00:00:28 +0800 Message-ID: <69f2524080295acce68e60be8903626568e8c5c4.1729267039.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 Please update the subject to "bpf: Export mptcp packet scheduler helpers" Make bpf_mptcp_subflow_queues_empty static. Merge "bpf: Export more bpf_burst related functions" into this patch. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 11 +++++++++++ net/mptcp/protocol.c | 4 ++-- net/mptcp/protocol.h | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 476620526c79..1ad7f703abb2 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -288,6 +288,11 @@ bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int p return data->contexts[pos]; } +__bpf_kfunc static bool bpf_mptcp_subflow_queues_empty(struct sock *sk) +{ + return tcp_rtx_queue_empty(sk); +} + __bpf_kfunc_end_defs(); BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids) @@ -309,6 +314,12 @@ static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = { BTF_KFUNCS_START(bpf_mptcp_sched_kfunc_ids) 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) +BTF_ID_FLAGS(func, bpf_mptcp_subflow_queues_empty) +BTF_ID_FLAGS(func, mptcp_pm_subflow_chk_stale) BTF_KFUNCS_END(bpf_mptcp_sched_kfunc_ids) static const struct btf_kfunc_id_set bpf_mptcp_sched_kfunc_set = { diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index b0e9a745ea62..21bc3586c33e 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -50,7 +50,7 @@ DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions); static struct net_device mptcp_napi_dev; /* Returns end sequence number of the receiver's advertised window */ -static u64 mptcp_wnd_end(const struct mptcp_sock *msk) +u64 mptcp_wnd_end(const struct mptcp_sock *msk) { return READ_ONCE(msk->wnd_end); } @@ -489,7 +489,7 @@ static long mptcp_timeout_from_subflow(const struct mptcp_subflow_context *subfl inet_csk(ssk)->icsk_timeout - jiffies : 0; } -static void mptcp_set_timeout(struct sock *sk) +void mptcp_set_timeout(struct sock *sk) { struct mptcp_subflow_context *subflow; long tout = 0; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 0624de84e339..b4c72a73594f 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -720,6 +720,8 @@ void __mptcp_subflow_send_ack(struct sock *ssk); void mptcp_subflow_reset(struct sock *ssk); void mptcp_subflow_queue_clean(struct sock *sk, struct sock *ssk); void mptcp_sock_graft(struct sock *sk, struct socket *parent); +u64 mptcp_wnd_end(const struct mptcp_sock *msk); +void mptcp_set_timeout(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);