From patchwork Wed Oct 23 09:40:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13846824 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 D06E018953D for ; Wed, 23 Oct 2024 09:40:32 +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=1729676432; cv=none; b=o/0+ezc7WUwsmLhV6l7mrA/NMMeZFz6Om18hbpdAN20DvRDx7YN8BR1BnRQ+FxRj5wDSqwMJsa8rw2fYiaPi+mT2aKBrpQp1RaTJ489Dk64JsttW6USJZDCABGpILBjttHO1+ZeasWxgotLWIMYQJ7Rz5VcKMnr/kyMQ67MBSl4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729676432; c=relaxed/simple; bh=fkwQLcs6tzUrO+f5yBEU0KgcCzgzMniTdPsOx0v8dAc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YchGcPCGxS7bzfc1TlZe58e4Is8ddsEIEcJiLr3LrzXHjmspx+Kb5UHecq89L9A74YqoRd73QQfraD+9GAhgye+YBxNybsxfFCJsggOMkd9EG3OP9yEfS2VZsR+lCFPBjMJL0h2sHEFhmYJBbWZzui8klVtNYtunb7tvN7bC2Jw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NuuObrhq; 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="NuuObrhq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D586C4CEC6; Wed, 23 Oct 2024 09:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729676432; bh=fkwQLcs6tzUrO+f5yBEU0KgcCzgzMniTdPsOx0v8dAc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NuuObrhqA18txJRCx8rlYabL43z3fXHw08hatkXk0XO8h5dom/87C6uvl7LP6ZulU E6Fu69iMVq603d11Hylb74OU4VTyN1qjsWkLEldhViBalKI82KI9llk3EfRQisk2Ir fA6OBUF8xCg1VfggHvHBuIU5jQkeKASMgMtymPjGyek9YwqtWudh1d2aTbiaCyuvfM SR1J/kAXY4vdQ1+X6g+y4arp92kaVnDXI4Zoa2WvA1F2oUiCWkD6N6LCrVzTe65MHV NVpZBx7zKlYg7Dm9iIzze0k8Zj8wBydKnsRv4Ph1pkX93+X6U4LJnm7Dg8UtlNdCwF rpauWsHJnpvKw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v8 01/13] mptcp: check sk_stream_memory_free in loop Date: Wed, 23 Oct 2024 17:40:11 +0800 Message-ID: <0c7d7cc7882ed66112656bca6031e6436ddbf250.1729676320.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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 In order to make it easier to implement similar logic to the burst scheduler in BPF program, the sk_stream_memory_free() check is moved forward into mptcp_for_each_subflow loop. Assignment like "ssk = send_info[SSK_MODE_ACTIVE].ssk" is not allowed in BPF, so bpf_core_cast() is used to cast it. But a casted pointer can't pass to a kfunc (sk_stream_memory_free). To solve this, In BPF burst scheduler sk_stream_memory_free check is moved forward to the position of mptcp_subflow_active() in bpf_for_each() loop. To keep mptcp_subflow_get_send() and BPF burst scheduler code consistent, this patch also synchronizes the change in BPF burst scheduler into mptcp_subflow_get_send(). Signed-off-by: Geliang Tang --- net/mptcp/protocol.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 21bc3586c33e..f36e63b84b88 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1444,7 +1444,8 @@ struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk) trace_mptcp_subflow_get_send(subflow); ssk = mptcp_subflow_tcp_sock(subflow); - if (!mptcp_subflow_active(subflow)) + if (!mptcp_subflow_active(subflow) || + !sk_stream_memory_free(ssk)) continue; tout = max(tout, mptcp_timeout_from_subflow(subflow)); @@ -1482,7 +1483,7 @@ struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk) * to check that subflow has a non empty cwin. */ ssk = send_info[SSK_MODE_ACTIVE].ssk; - if (!ssk || !sk_stream_memory_free(ssk)) + if (!ssk) return NULL; burst = min_t(int, MPTCP_SEND_BURST_SIZE, mptcp_wnd_end(msk) - msk->snd_nxt); From patchwork Wed Oct 23 09:40:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13846825 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 1AEAD18953D for ; Wed, 23 Oct 2024 09:40:34 +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=1729676435; cv=none; b=blG1T3qphyPcgasYaxJutb0Mmnm2fP2kIqFVf/CpvcfzBNOH0KwJuj3BC666YEs3ArW2RQEGMWHRLrfMEl1g3nc2MSfsDBA2P+sArBP1f7t8cvdRY8TNbT5NpWnBVQLNsACkeRDu7JXuC/A5NvY6JfVz2Ht5Bx5sJimqek8X7qg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729676435; c=relaxed/simple; bh=7QjwmySbNnrWKYeba8wvxYopSKW9+212Gx9lZ73qJvc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PV4Z//t6LobxR+xkmHMWJ/3Lb7ZdwnTiN91e4lrCql7kTmA2y3d+uTIp5Qhnq3bSgJqLCG7wClH6wMG/j/1vbgm89bUB4Y/L8nq9lPXoSKWUGd+a9l4z7GUpVAhqrQx/JZndqz7ljn+ZJaL5BYX6cT/okDDZ+L2mvvXwh3SnM4k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ByYDpmCS; 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="ByYDpmCS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 025E7C4CEC6; Wed, 23 Oct 2024 09:40:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729676434; bh=7QjwmySbNnrWKYeba8wvxYopSKW9+212Gx9lZ73qJvc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ByYDpmCStUBZTtfncO+iyYAFfkR5xipyGAZ0u5LlM1wt42HsuYbmyDIpbw2PbMA4b JvKAS78U3Rwk4tZDE/mObEAMTAbC4UpRRvq+v4Ooa796HBh1xpLURcVRX2i9laOoIr iJnlyH0zEyvowXJUDx0k7GoipttYu0Tn9yt5YEIJM6JuHgRITZ+qenA8LRqmuEY+Ex 4AfVgPeK3lbRiV9Sjw7x7qfY5TIJ6rgJ3GEplA2iqsPJ1XV0/GU8toq93WMhkp6jsF uicddZToV334uNqAPFk7Th4rJmPt8aOxnCUcmUgn5Hvp6GWUw6QaKqFPAJxntxVvAW f9GflcV7boMjw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v8 02/13] mptcp: make mptcp_subflow_set_scheduled inline Date: Wed, 23 Oct 2024 17:40:12 +0800 Message-ID: <9a923def3da410c97d08af04c42ca9863bd1f4db.1729676320.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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 Now mptcp_subflow_set_scheduled is no longer used in BPF, but only in kernel. A new mptcp_subflow_set_scheduled helper has been implemented in BPF specifically for use with BPF. To avoid compilation errors due to duplicate names, this function has been made inline in kernel and moved to protocol.h. Signed-off-by: Geliang Tang --- net/mptcp/protocol.h | 9 +++++++-- net/mptcp/sched.c | 6 ------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index b4c72a73594f..ab4e88b40efc 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -750,13 +750,18 @@ void mptcp_sched_init(void); int mptcp_init_sched(struct mptcp_sock *msk, struct mptcp_sched_ops *sched); void mptcp_release_sched(struct mptcp_sock *msk); -void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, - bool scheduled); struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk); struct sock *mptcp_subflow_get_retrans(struct mptcp_sock *msk); int mptcp_sched_get_send(struct mptcp_sock *msk); int mptcp_sched_get_retrans(struct mptcp_sock *msk); +static inline void +mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, + bool scheduled) +{ + WRITE_ONCE(subflow->scheduled, scheduled); +} + static inline u64 mptcp_data_avail(const struct mptcp_sock *msk) { return READ_ONCE(msk->bytes_received) - READ_ONCE(msk->bytes_consumed); diff --git a/net/mptcp/sched.c b/net/mptcp/sched.c index 6da60e35932f..73a24b9c96ff 100644 --- a/net/mptcp/sched.c +++ b/net/mptcp/sched.c @@ -135,12 +135,6 @@ void mptcp_release_sched(struct mptcp_sock *msk) bpf_module_put(sched, sched->owner); } -void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, - bool scheduled) -{ - WRITE_ONCE(subflow->scheduled, scheduled); -} - static void mptcp_sched_data_set_contexts(const struct mptcp_sock *msk, struct mptcp_sched_data *data) { From patchwork Wed Oct 23 09:40:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13846826 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 7A9E818953D for ; Wed, 23 Oct 2024 09:40: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=1729676436; cv=none; b=giFCwt6JwZwFDNVYu9hKiQgsrccsPchhDXR+M5RQIg4dgbYTZlrGSrjTVIntEhPPpk+am9EAc45Hcf8DsCH1b0KT994nBTVRiUfILEjw7X15rVQk2WFWppND0SXirqHz72PD70v9dsy+4UvQlGUid8blRldkHjHwVxp5a8AVQho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729676436; c=relaxed/simple; bh=Noo+9IDt1f2aQe6unlkVcJwLsr3XofXTxLxDAt0rp3g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jartj/LHjD2BIwoG20mOkGAp+Pc2mzjqxaQObl1SXDgIicEt1vMGCgYKflAZwzHLxSXAUTZsm6lR3DHig/82CG4a2MF7jCS59QBWXHDylL8sBwilybwLhD0dK8i4YyVPa+3C0iE/BULGYwrV8yaymjyXFFa7XW9ypRF4LCE0Fxs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sRqOaDGk; 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="sRqOaDGk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AD37C4CEC6; Wed, 23 Oct 2024 09:40:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729676436; bh=Noo+9IDt1f2aQe6unlkVcJwLsr3XofXTxLxDAt0rp3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sRqOaDGkeH/g8uXjir5HIUBkvsF03GR0++igklzbwfC3SxdeLuwqOIBUBOCuMokO+ 4LqOv4jplqK+/5Xvs7X0TWwLqjNHkxEkMK1boeODnUPgTnB6qXqdx78WpyR2PqxF0N uXI8Cy5EH0sUgIA6xp/gRTRmQAr+w15iwsaOhu06GGw+c9ENwbYLAk1vsG/RDWEQjM JcZ44CMoSu9cYRdr8AeEXz8HXmHWACp7EWTLXtb86bzFfD847WW8BsJXxAg7vzkJrc CRZQqTevkD06BUay0BJ/xFhjZm8HpDoFDHWIFZ+kmPMT9K45EqP5Ln7NKSCni5ufCB 8P7v8EIxgK0YQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v8 03/13] mptcp: add mptcp_validate_scheduler helper Date: Wed, 23 Oct 2024 17:40:13 +0800 Message-ID: <9b98ae2d97757792f42a4d4f660c07dc509b2c00.1729676320.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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 New interface .validate is added in bpf_struct_ops recently, implement .validate as mptcp_validate_scheduler() for struct mptcp_sched_ops. In it check whether the required ops "get_subflow" of struct mptcp_sched_ops is implemented. Signed-off-by: Geliang Tang --- net/mptcp/protocol.h | 1 + net/mptcp/sched.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index ab4e88b40efc..46bc7adb4763 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -744,6 +744,7 @@ void mptcp_info2sockaddr(const struct mptcp_addr_info *info, struct sockaddr_storage *addr, unsigned short family); struct mptcp_sched_ops *mptcp_sched_find(const char *name); +int mptcp_validate_scheduler(struct mptcp_sched_ops *sched); int mptcp_register_scheduler(struct mptcp_sched_ops *sched); void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched); void mptcp_sched_init(void); diff --git a/net/mptcp/sched.c b/net/mptcp/sched.c index 73a24b9c96ff..d7be9c453488 100644 --- a/net/mptcp/sched.c +++ b/net/mptcp/sched.c @@ -71,10 +71,23 @@ void mptcp_get_available_schedulers(char *buf, size_t maxlen) rcu_read_unlock(); } -int mptcp_register_scheduler(struct mptcp_sched_ops *sched) +int mptcp_validate_scheduler(struct mptcp_sched_ops *sched) { - if (!sched->get_subflow) + if (!sched->get_subflow) { + pr_err("%s does not implement required ops\n", sched->name); return -EINVAL; + } + + return 0; +} + +int mptcp_register_scheduler(struct mptcp_sched_ops *sched) +{ + int ret; + + ret = mptcp_validate_scheduler(sched); + if (ret) + return ret; spin_lock(&mptcp_sched_list_lock); if (mptcp_sched_find(sched->name)) { From patchwork Wed Oct 23 09:40:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13846827 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 9586518953D for ; Wed, 23 Oct 2024 09:40: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=1729676438; cv=none; b=X20kHvXeSsaX2m1hvzkdE7p+QVYzOCvY3EQP/kHZGSRsHLrkUmhLT3hSIHnpCiTSyxbz0gMAVlbWfMw+WWttlyoy9dGZg4mLWYlWxdzs6N6m49jkSAZT9d3hY38gBbm71B833/m9xCep8Y30P7yRwzBcxhA/agdRs3EjyTCJKnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729676438; c=relaxed/simple; bh=dJcPCgbGiTa4yy5psNCb78HvU99dRnZgn8tP3b+U/b0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=twZu1c7KTzNMAQd8pPozHU2EVm67uWnw5Jp0k5kS+OO0JWJd01KvrsCk/QxSJ/jtxKD1/gqoWdM4XXeihZe5fyYp6/DUSud1H5lJjEWz9KIufrOFsr0VuXGTlHLGWb9ErEgByU7/EZAoM8cKVxvF6A/B8XAfdkoXdYTiqu5lghc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fWIWvdOa; 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="fWIWvdOa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00973C4CEC6; Wed, 23 Oct 2024 09:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729676438; bh=dJcPCgbGiTa4yy5psNCb78HvU99dRnZgn8tP3b+U/b0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fWIWvdOaoCuBkGTPxAg6TCiTNW6KDqef/ythPMNip7950S4MbrhtOrxyFoUcoczSj C60yorypT+i1XUdL4Q11GIwsP0S7/K3Q73Jzk7T9RBQJySaN2NnyKEe0oaMzloMoTH GL+F9RUgK9h38rPt1EOlyvK1G0uHqA3I1nmxGBSYab5EK53iib7CYn1sxNc4sUA9I4 4f+m7GRem4npir+K5p7uZUpihSUNqzdVkA0Pm0NW4EptxgTQLJ11BwUWrGyaEdVhFB sHB7QMPRjlhHwuDVT4Kd8yzRXJR/Cap0WKcxkljdQhqFUBnVhVRlz9oqy2LtPuqEZu cza10DGZP6oog== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v8 04/13] Squash to "bpf: Add bpf_mptcp_sched_ops" Date: Wed, 23 Oct 2024 17:40:14 +0800 Message-ID: X-Mailer: git-send-email 2.45.2 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: Add mptcp packet scheduler struct_ops 1. validate interface is added in bpf_struct_ops by commit 68b04864ca42 ("bpf: Create links for BPF struct_ops maps."), implement it in mptcp_sched_ops. 2. Drop mptcp_sched_find. This part of mptcp_sched_find() code comes from bpf_tcp_ca_init_member, but it was recently deleted by commit 68b04864ca42. 3. Add write access for scheduled of mptcp_subflow_context. 4. Drop mptcp_sock_type and mptcp_subflow_type. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index e9db856972cb..c6d2efc6cf0e 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -18,8 +18,10 @@ #ifdef CONFIG_BPF_JIT static struct bpf_struct_ops bpf_mptcp_sched_ops; -static const struct btf_type *mptcp_sock_type, *mptcp_subflow_type __read_mostly; -static u32 mptcp_sock_id, mptcp_subflow_id; +static u32 mptcp_sock_id, + mptcp_subflow_id; + +/* MPTCP BPF packet scheduler */ static const struct bpf_func_proto * bpf_mptcp_sched_get_func_proto(enum bpf_func_id func_id, @@ -43,12 +45,10 @@ static int bpf_mptcp_sched_btf_struct_access(struct bpf_verifier_log *log, const struct bpf_reg_state *reg, int off, int size) { - const struct btf_type *t; + u32 id = reg->btf_id; size_t end; - t = btf_type_by_id(reg->btf, reg->btf_id); - - if (t == mptcp_sock_type) { + if (id == mptcp_sock_id) { switch (off) { case offsetof(struct mptcp_sock, snd_burst): end = offsetofend(struct mptcp_sock, snd_burst); @@ -58,11 +58,14 @@ static int bpf_mptcp_sched_btf_struct_access(struct bpf_verifier_log *log, off); return -EACCES; } - } else if (t == mptcp_subflow_type) { + } else if (id == mptcp_subflow_id) { switch (off) { case offsetof(struct mptcp_subflow_context, avg_pacing_rate): end = offsetofend(struct mptcp_subflow_context, avg_pacing_rate); break; + case offsetof(struct mptcp_subflow_context, scheduled): + end = offsetofend(struct mptcp_subflow_context, scheduled); + break; default: bpf_log(log, "no write support to mptcp_subflow_context at off %d\n", off); @@ -75,7 +78,7 @@ static int bpf_mptcp_sched_btf_struct_access(struct bpf_verifier_log *log, if (off + size > end) { bpf_log(log, "access beyond %s at off %u size %u ended at %zu", - t == mptcp_sock_type ? "mptcp_sock" : "mptcp_subflow_context", + id == mptcp_sock_id ? "mptcp_sock" : "mptcp_subflow_context", off, size, end); return -EACCES; } @@ -113,7 +116,6 @@ static int bpf_mptcp_sched_init_member(const struct btf_type *t, const struct mptcp_sched_ops *usched; struct mptcp_sched_ops *sched; u32 moff; - int ret; usched = (const struct mptcp_sched_ops *)udata; sched = (struct mptcp_sched_ops *)kdata; @@ -124,12 +126,7 @@ static int bpf_mptcp_sched_init_member(const struct btf_type *t, if (bpf_obj_name_cpy(sched->name, usched->name, sizeof(sched->name)) <= 0) return -EINVAL; - - rcu_read_lock(); - ret = mptcp_sched_find(usched->name) ? -EEXIST : 1; - rcu_read_unlock(); - - return ret; + return 1; } return 0; @@ -144,18 +141,21 @@ static int bpf_mptcp_sched_init(struct btf *btf) if (type_id < 0) return -EINVAL; mptcp_sock_id = type_id; - mptcp_sock_type = btf_type_by_id(btf, mptcp_sock_id); type_id = btf_find_by_name_kind(btf, "mptcp_subflow_context", BTF_KIND_STRUCT); if (type_id < 0) return -EINVAL; mptcp_subflow_id = type_id; - mptcp_subflow_type = btf_type_by_id(btf, mptcp_subflow_id); return 0; } +static int bpf_mptcp_sched_validate(void *kdata) +{ + return mptcp_validate_scheduler(kdata); +} + static int __bpf_mptcp_sched_get_subflow(struct mptcp_sock *msk, struct mptcp_sched_data *data) { @@ -183,6 +183,7 @@ static struct bpf_struct_ops bpf_mptcp_sched_ops = { .check_member = bpf_mptcp_sched_check_member, .init_member = bpf_mptcp_sched_init_member, .init = bpf_mptcp_sched_init, + .validate = bpf_mptcp_sched_validate, .name = "mptcp_sched_ops", .cfi_stubs = &__bpf_mptcp_sched_ops, }; From patchwork Wed Oct 23 09:40:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13846828 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 D169D18953D for ; Wed, 23 Oct 2024 09:40: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=1729676439; cv=none; b=Hj5S5ZVtkkZFSNIhZmgT0vns5M5yw04c/H9VFGD8JnlUgCuMl248ahsUa6zG4mJDogaKvVo55cgSm2+SDNMKOG0to5xRzyErQm08h8aUc563W69JwQ5IkloVTO9fiyCRqWRgWg1FQzN/yAx5q3LuwL2/n5Ff2yZAiiSFkalkpNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729676439; c=relaxed/simple; bh=DoURruBuepegnGa58PbLvdXlpX+zM0NSIkV436otezQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hK7yBADO9nZn0i7a3lEmDj97OPgrEyxHXOke1VZvTgP13BQ6sGYJBaWuPdfaUm7gXicYgsH1WeY4RBdMHcpLHej0aOxMQI9K8VtORxWJch+tvppnvRX4EDXImqKl9soI6Lp+shvSCUcqDs0FW19SGeLMlMosvwV99GjT3lMTYb8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gM1+EtX3; 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="gM1+EtX3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7870C4CEC6; Wed, 23 Oct 2024 09:40:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729676439; bh=DoURruBuepegnGa58PbLvdXlpX+zM0NSIkV436otezQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gM1+EtX3UOx7sUp8tW2CQe5K84FzwHRW+/6Eg5DRuCteFi5KFF8m71Gb6WZMpQAYs FzWujeQrXY8il7u2OUXq7U4KtbdIns606Og2iQsC4SkCeMgpUbdvLh/mPc5P4jGyso eCLSMZMJbcoll6yrYzExK7sMgSaQfZbeqBbFP535ahny7zHyiqypaklYmcaUnjDJrV 9lhY31wEzSu/6bFi18ef119MgVwe24gdX6XspnrAhfrzwhvISbGSzkmav16gQLVEqt MhpioKIzpwmiOZe3HzEegfl27slB+bxz5wsES72xAEvTaCPZ/eX/BlEY02yWbqsIdH R71KxhKLQLX7g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v8 05/13] Squash to "selftests/bpf: Add bpf scheduler test" Date: Wed, 23 Oct 2024 17:40:15 +0800 Message-ID: <0eab9060d945d4b3150fabb7bf61e2748192703f.1729676320.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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 A cleanup, move create_netns() out of sched_init(). Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index be746e0fc393..9758ee83c81f 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -580,23 +580,16 @@ static void test_iters_subflow(void) close(cgroup_fd); } -static struct nstoken *sched_init(char *flags, char *sched) +static int sched_init(char *flags, char *sched) { - struct nstoken *nstoken; - - nstoken = create_netns(); - if (!ASSERT_OK_PTR(nstoken, "create_netns")) - return NULL; - - if (endpoint_init("subflow", 2) < 0) + if (endpoint_init(flags, 2) < 0) goto fail; SYS(fail, "ip netns exec %s sysctl -qw net.mptcp.scheduler=%s", NS_TEST, sched); - return nstoken; + return 0; fail: - cleanup_netns(nstoken); - return NULL; + return -1; } static int ss_search(char *src, char *dst, char *port, char *keyword) @@ -654,11 +647,16 @@ static void send_data_and_verify(char *sched, bool addr1, bool addr2) static void test_default(void) { struct nstoken *nstoken; + int err; - nstoken = sched_init("subflow", "default"); + nstoken = create_netns(); if (!nstoken) goto fail; + err = sched_init("subflow", "default"); + if (!ASSERT_OK(err, "sched_init")) + goto fail; + send_data_and_verify("default", WITH_DATA, WITH_DATA); fail: From patchwork Wed Oct 23 09:40:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13846829 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 087B719AA46 for ; Wed, 23 Oct 2024 09:40: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=1729676442; cv=none; b=pICKsiXNcEQEdidvPP4xtrjuLn3VvD+yXsWHjK5y+LNE41wE3QcZihp/nYP64EN6/Y9ofdsWmsu8uA7QvYAWy+xxKlMue9ohREE47tvkSJkfuCg+Qh233b0/2sOF2QMr4jZTVLCvVILyJDIAu5VjuZVaLEt6sgQaHNO68TbWyx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729676442; c=relaxed/simple; bh=Xgm8DMyGUevxbQhlUHWB9lrRYhoSP1Ninc5C+Qg/FvE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dDOx6gQ6SSSCKSrCshIe6bhXHNyy3D9uE8DhgkX7qpNCbi2pGZk0MeXiCzR2ccf3XhzmJ1cULyBZU/tKQgASGQG1z8QvaHj1rAHUlDT6Rp0XdWCZpdbfgMyuVbUSH5/rFWdwQeC/2uDz+SpWMPS+caKMY/QScn3LzC6vo7vM0L4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZMxBQCFI; 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="ZMxBQCFI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F006C4CEC7; Wed, 23 Oct 2024 09:40:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729676441; bh=Xgm8DMyGUevxbQhlUHWB9lrRYhoSP1Ninc5C+Qg/FvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZMxBQCFIN3m5jsay9Dl5lQwRoX5GbZRq5BopvYCkJ+OOp08D21xOT+/s1JQrfusFh 0qnnPfUIfugxCRSS1gmIYWjzf62SX66AinCSO3+cYsjmv1mJGUDlihFUzMYeABTuSA yEnFymtuZSNQZ7AKiLW7sgo0WidUgnIRMBwhRdqpK6LchuUV1rpsXFXEaR5iOjve44 sTgbKWdCJaIzesQusblKzlisLya+mdNKfnf1QipvWEU8ZIlKAMf+SlgwIjjXTagN5+ WJBmnn6SlY43SeV28IfZhA8+kwqp1GY00QND4WQlfesRP07DTTtH70JZASrU5H1OfW Tqjn/CAWnF1wA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v8 06/13] Squash to "selftests/bpf: Add bpf_first scheduler & test" Date: Wed, 23 Oct 2024 17:40:16 +0800 Message-ID: <4329419175bacbba46793ccb502f5924d35d2931.1729676320.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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 1. Update sched_init. 2. For drop bpf_object__find_map_by_name in test_bpf_sched(), change the first parameter of it as bpf_map. 3. Implement mptcp_subflow_set_scheduled in BPF. 4. Drop bpf_mptcp_subflow_ctx_by_pos. 5. Use the newly added bpf_for_each() helper to walk the conn_list. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 15 +++++++++------ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 14 ++++++++------ .../testing/selftests/bpf/progs/mptcp_bpf_first.c | 4 ++-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 9758ee83c81f..1c63396e1eba 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -663,27 +663,30 @@ static void test_default(void) cleanup_netns(nstoken); } -static void test_bpf_sched(struct bpf_object *obj, char *sched, +static void test_bpf_sched(struct bpf_map *map, char *sched, bool addr1, bool addr2) { char bpf_sched[MPTCP_SCHED_NAME_MAX] = "bpf_"; struct nstoken *nstoken; struct bpf_link *link; - struct bpf_map *map; + int err; if (!ASSERT_LT(strlen(bpf_sched) + strlen(sched), MPTCP_SCHED_NAME_MAX, "Scheduler name too long")) return; - map = bpf_object__find_map_by_name(obj, sched); link = bpf_map__attach_struct_ops(map); - if (CHECK(!link, sched, "attach_struct_ops: %d\n", errno)) + if (!ASSERT_OK_PTR(link, "attach_struct_ops")) return; - nstoken = sched_init("subflow", strcat(bpf_sched, sched)); + nstoken = create_netns(); if (!nstoken) goto fail; + err = sched_init("subflow", strcat(bpf_sched, sched)); + if (!ASSERT_OK(err, "sched_init")) + goto fail; + send_data_and_verify(sched, addr1, addr2); fail: @@ -699,7 +702,7 @@ static void test_first(void) if (!ASSERT_OK_PTR(skel, "open_and_load: first")) return; - test_bpf_sched(skel->obj, "first", WITH_DATA, WITHOUT_DATA); + test_bpf_sched(skel->maps.first, "first", WITH_DATA, WITHOUT_DATA); mptcp_bpf_first__destroy(skel); } diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf.h b/tools/testing/selftests/bpf/progs/mptcp_bpf.h index 3b20cfd44505..f8c917dc2c1c 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -42,6 +42,14 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) return subflow->tcp_sock; } +#define WRITE_ONCE(x, val) ((*(volatile typeof(x) *) &(x)) = (val)) + +static __always_inline void +mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, bool scheduled) +{ + WRITE_ONCE(subflow->scheduled, scheduled); +} + /* 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; @@ -52,10 +60,4 @@ 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; - -extern struct mptcp_subflow_context * -bpf_mptcp_subflow_ctx_by_pos(const struct mptcp_sched_data *data, unsigned int pos) __ksym; - #endif diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_first.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_first.c index d57399b407a7..5d0f89c636f0 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_first.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_first.c @@ -20,11 +20,11 @@ SEC("struct_ops") int BPF_PROG(bpf_first_get_subflow, struct mptcp_sock *msk, struct mptcp_sched_data *data) { - mptcp_subflow_set_scheduled(bpf_mptcp_subflow_ctx_by_pos(data, 0), true); + mptcp_subflow_set_scheduled(bpf_mptcp_subflow_ctx(msk->first), true); return 0; } -SEC(".struct_ops") +SEC(".struct_ops.link") struct mptcp_sched_ops first = { .init = (void *)mptcp_sched_first_init, .release = (void *)mptcp_sched_first_release, From patchwork Wed Oct 23 09:40:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13846830 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 863E7189F42 for ; Wed, 23 Oct 2024 09:40: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=1729676443; cv=none; b=canggBQ49bgQnUUQAx8IJB0QFSHLKOD2sHWdlubDzQEyEmzlIq22v2eZhpdo6zP03bofFfkMsum5EVUkmBaOMgxxWNMcPYYw1iCLUf1N9BHvOGScuyO1xaeJHYnodHhW+X42YQN6mYzl/3gSSSmZvtDbGj35VE6CU8sCaolj0Vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729676443; c=relaxed/simple; bh=xzK8jOvJ5JqUfgJxJ2WcAObJtneK7GeE7sjTE+kiURY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IFF0OwjwIr0/lE1oKWogsPVh0HKwfpF0XjpXJtJjA6CPai1opYhcTeWIMY1ddE5CoQE1kZvoECWipbPNoD2DB7LiZ4RRnhia6Qgohx7pCQb2oVy7irT2BJsHeQHH6jNewLLxZs6YV96kb4gqQ2PeWc1OTOdP1SrOXrwoz6a0/uU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EVIpioPU; 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="EVIpioPU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F3BAC4CEE5; Wed, 23 Oct 2024 09:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729676443; bh=xzK8jOvJ5JqUfgJxJ2WcAObJtneK7GeE7sjTE+kiURY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EVIpioPUdsgbV392QSideniWLyfoNldhvuGAr3VHR2MUio5LO3/XFHiDQD8Eqlb9i LgztcpGHGhEWyHHwH+de9bMKkcItDQn9dN0ku867SZxDbncrRu1/zit3ykbygZ+U2f bU0CrTbURPsXLeFQZCBZ2WadgJ2FQ3+lZc1NHaXKas9MW/GevOunRuhKGV09rP3Y4U /CQkNONKNFpH/oaDy39C2Vbn46O5v+nYy9vnc4SsYAaiC6AiXBCR+/uPsn4Ni7WveX YxviZ2SMalnRHI2pPaStg8JPKDmAT7liG8XfEaT/JK8dBMS5sAF2bDmWDzmqajPHNt fte7exbinEquA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v8 07/13] Squash to "selftests/bpf: Add bpf_bkup scheduler & test" Date: Wed, 23 Oct 2024 17:40:17 +0800 Message-ID: <28803269a2038b188007e8e1caffdd6d95d3c4fb.1729676320.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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 test_bpf_sched(). Use the newly added bpf_for_each() helper to walk the conn_list. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 2 +- .../selftests/bpf/progs/mptcp_bpf_bkup.c | 18 ++++-------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 1c63396e1eba..cb0090bafe57 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -714,7 +714,7 @@ static void test_bkup(void) if (!ASSERT_OK_PTR(skel, "open_and_load: bkup")) return; - test_bpf_sched(skel->obj, "bkup", WITH_DATA, WITHOUT_DATA); + test_bpf_sched(skel->maps.bkup, "bkup", WITH_DATA, WITHOUT_DATA); mptcp_bpf_bkup__destroy(skel); } diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c index 296f0318d843..0c32ce623bab 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c @@ -20,30 +20,20 @@ SEC("struct_ops") int BPF_PROG(bpf_bkup_get_subflow, struct mptcp_sock *msk, struct mptcp_sched_data *data) { - int nr = -1; - - for (int i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) { - struct mptcp_subflow_context *subflow; - - subflow = bpf_mptcp_subflow_ctx_by_pos(data, i); - if (!subflow) - break; + struct mptcp_subflow_context *subflow; + bpf_for_each(mptcp_subflow, subflow, msk) { if (!BPF_CORE_READ_BITFIELD_PROBED(subflow, backup) || !BPF_CORE_READ_BITFIELD_PROBED(subflow, request_bkup)) { - nr = i; + mptcp_subflow_set_scheduled(subflow, true); break; } } - if (nr != -1) { - mptcp_subflow_set_scheduled(bpf_mptcp_subflow_ctx_by_pos(data, nr), true); - return -1; - } return 0; } -SEC(".struct_ops") +SEC(".struct_ops.link") struct mptcp_sched_ops bkup = { .init = (void *)mptcp_sched_bkup_init, .release = (void *)mptcp_sched_bkup_release, From patchwork Wed Oct 23 09:40:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13846831 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 507B319DF45 for ; Wed, 23 Oct 2024 09:40: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=1729676445; cv=none; b=aQ7Yqaa91DE9huTl31YseKdOWufPiUnEiRzQPsHHEdHym0CRVyb2TgdV2uIEEcSR29FMCQQQ6qrjMXTxh8lDMshey7T0yoLGASfOn3bQdUpoxzwDp36kCS7U1aN6wl0fzCHrA7UmgMk2ErrBCP/O8Lsvs9cdvAvS+0w0IvnZAXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729676445; c=relaxed/simple; bh=xstGsLWkRX78HXPUtsHSW/9ilKSi2k8OOPzhf0416bk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EIxZap9kFDfx49Sw5l8wl2isom29aPwoc8gF4X+u0we9Y3erfRfqsZ+oSHp91cKq92ds3yWfbrtf8ku7qa6rFILxzaJfTEX+NRjxINHP5/NFf/S+1UR1iCh7WcuOdX4Ls85T8iOHFaa3Kqv5acypd0GIyzxnLEW7R6OR1mmJKDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aREUchFP; 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="aREUchFP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10E12C4CEE5; Wed, 23 Oct 2024 09:40:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729676445; bh=xstGsLWkRX78HXPUtsHSW/9ilKSi2k8OOPzhf0416bk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aREUchFP8qESpCi9gQxEyZDwYFIDeo/EiptSMTAnm94fzwYlOQ8u4Im5f35v0eqn4 fiO2cxWC/EZJWIICAktIu8Hr/6RtiYXqrtErMJv1+1K/ktKUKx0V4SrPrS5ZJFrOQm vT2QiwchksSZJ20lFTRpWpmvoJ/nJXIZV9LTYDkB+VpMPzYUD7n+xjKrg/ax+naCAL YYwxkCtWnskVgdBtDdqhCcqIuKttJjH6x/fWSuBOjbqLnMTiAZ14t2r7dI9cSkRmJu rrBKJmCKbYYLjgmfyuqlkP+fm8BGFxsR+SMcUnHWzhjLOrueZphJIOuX0GlUarhnXW EMNOSlD8MEChg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v8 08/13] Squash to "selftests/bpf: Add bpf_rr scheduler & test" Date: Wed, 23 Oct 2024 17:40:18 +0800 Message-ID: <8c1f637783212ae2f764bfeed58ca96a4f2c1ca5.1729676320.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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 test_bpf_sched(). Use the newly added bpf_for_each() helper to walk the conn_list. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 2 +- .../selftests/bpf/progs/mptcp_bpf_rr.c | 33 ++++++++----------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index cb0090bafe57..3d5290b48084 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -726,7 +726,7 @@ static void test_rr(void) if (!ASSERT_OK_PTR(skel, "open_and_load: rr")) return; - test_bpf_sched(skel->obj, "rr", WITH_DATA, WITH_DATA); + test_bpf_sched(skel->maps.rr, "rr", WITH_DATA, WITH_DATA); mptcp_bpf_rr__destroy(skel); } diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c index 638ea6aa63b7..c901ed045fdc 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c @@ -34,42 +34,37 @@ SEC("struct_ops") int BPF_PROG(bpf_rr_get_subflow, struct mptcp_sock *msk, struct mptcp_sched_data *data) { - struct mptcp_subflow_context *subflow; + struct mptcp_subflow_context *subflow, *next; struct mptcp_rr_storage *ptr; - struct sock *last_snd = NULL; - int nr = 0; ptr = bpf_sk_storage_get(&mptcp_rr_map, msk, 0, BPF_LOCAL_STORAGE_GET_F_CREATE); if (!ptr) return -1; - last_snd = ptr->last_snd; + next = bpf_mptcp_subflow_ctx(msk->first); + if (!ptr->last_snd) + goto out; - for (int i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) { - subflow = bpf_mptcp_subflow_ctx_by_pos(data, i); - if (!last_snd || !subflow) - break; - - if (mptcp_subflow_tcp_sock(subflow) == last_snd) { - if (i + 1 == MPTCP_SUBFLOWS_MAX || - !bpf_mptcp_subflow_ctx_by_pos(data, i + 1)) + bpf_for_each(mptcp_subflow, subflow, msk) { + if (mptcp_subflow_tcp_sock(subflow) == ptr->last_snd) { + subflow = bpf_iter_mptcp_subflow_next(&___it); + if (!subflow) break; - nr = i + 1; + next = subflow; break; } } - subflow = bpf_mptcp_subflow_ctx_by_pos(data, nr); - if (!subflow) - return -1; - mptcp_subflow_set_scheduled(subflow, true); - ptr->last_snd = mptcp_subflow_tcp_sock(subflow); +out: + next = bpf_core_cast(next, struct mptcp_subflow_context); + mptcp_subflow_set_scheduled(next, true); + ptr->last_snd = mptcp_subflow_tcp_sock(next); return 0; } -SEC(".struct_ops") +SEC(".struct_ops.link") struct mptcp_sched_ops rr = { .init = (void *)mptcp_sched_rr_init, .release = (void *)mptcp_sched_rr_release, From patchwork Wed Oct 23 09:40:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13846832 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 D720B18953D for ; Wed, 23 Oct 2024 09:40: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=1729676446; cv=none; b=cDqajwqRQE3Cd89KQ4q3dD4gLlQ+dRIiey2KREPQswvoXDuyJHAP1MIumuTs2e3JyBWo1TAQxb1OM2Azsyzd4Y7EATG/9nQtVY7WN2fxTE88o/tZVZdcnd+zWHCNf/QweNAgwDknqbQrMj8GwFMGLp3hWJixniWXrKigf9G+OJM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729676446; c=relaxed/simple; bh=lqSujFGuRuYfmfl4nwRJ4/W/eXxkgKVZeHZwO6F028Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TWH/e1DNcKSNeALEVxCJRP3BgeJsfriejBfXKH32eueqj0pEMzLfrc18bqTHNL4+Oi76q+qelQEGni8ssN28DI3nyunRRqjyYfomX/lgQwRBki4UghMeKjr+6UPst6du8qfkeF/miGKwAFORH0YpfBEesB4/lHOSfGOCNFweHcM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mz9SXmbV; 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="mz9SXmbV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2557C4CEC6; Wed, 23 Oct 2024 09:40:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729676446; bh=lqSujFGuRuYfmfl4nwRJ4/W/eXxkgKVZeHZwO6F028Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mz9SXmbVYyuIKUnTpBtzedGVLLEMYEpXrzTNgH1m43JZFwq3ddHkaunuEpBv9shwQ 1q1ORXtC9PtBfAvwF/Cw8xABNPSQu+lCQLXm+480hDbd5k+db1st93YzvZd7N77LVe Kja4ThcHxkU1Gfuqx8pcU+lciDr6MSGksTazHClksV6rTkjPWYtn82GpgJJsyCF/YG PohiRkuDwqXuktN2eSOjBLzCa0Ry5i5iech6NreysHY11vMQ4PLIv0xvo5b8ZybPwp 3XLnzlCFtLuPhTqYLMfYszBtRCSbOZjrmIDt/LM0UdeaQ9qsgHIXTukY/SIyJkGpwJ 6x7UHq9fTqulw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v8 09/13] Squash to "selftests/bpf: Add bpf_red scheduler & test" Date: Wed, 23 Oct 2024 17:40:19 +0800 Message-ID: <2095b570f23db6afa742abd883176d2517423100.1729676320.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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 test_bpf_sched(). Use the newly added bpf_for_each() helper to walk the conn_list. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 2 +- tools/testing/selftests/bpf/progs/mptcp_bpf_red.c | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 3d5290b48084..03eacae01b8d 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -738,7 +738,7 @@ static void test_red(void) if (!ASSERT_OK_PTR(skel, "open_and_load: red")) return; - test_bpf_sched(skel->obj, "red", WITH_DATA, WITH_DATA); + test_bpf_sched(skel->maps.red, "red", WITH_DATA, WITH_DATA); mptcp_bpf_red__destroy(skel); } diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_red.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_red.c index cc0aab732fc4..35150771e174 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_red.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_red.c @@ -20,17 +20,15 @@ SEC("struct_ops") int BPF_PROG(bpf_red_get_subflow, struct mptcp_sock *msk, struct mptcp_sched_data *data) { - for (int i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) { - if (!bpf_mptcp_subflow_ctx_by_pos(data, i)) - break; + struct mptcp_subflow_context *subflow; - mptcp_subflow_set_scheduled(bpf_mptcp_subflow_ctx_by_pos(data, i), true); - } + bpf_for_each(mptcp_subflow, subflow, msk) + mptcp_subflow_set_scheduled(subflow, true); return 0; } -SEC(".struct_ops") +SEC(".struct_ops.link") struct mptcp_sched_ops red = { .init = (void *)mptcp_sched_red_init, .release = (void *)mptcp_sched_red_release, From patchwork Wed Oct 23 09:40:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13846833 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 CD33C18953D for ; Wed, 23 Oct 2024 09:40: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=1729676448; cv=none; b=Sj3xddCf5DeabkQNHl+a9W1HNfdkx4Py1fdYU8xFChprrw7tyPI37P5ElFhbnl/zQFfQjU1zrhxpdotxDHvWfl5yb33WHY7BVH7slCphr642qgdE584za9TRdgBEVZLH+kxjHrhDZ0nd5j1pwW0WeCWursQbJ5xh40j97i8riu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729676448; c=relaxed/simple; bh=u5wQJEaQSiZvDWYLH/rv/j1uxC/npMherkaK5E8eyr8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eCI0riw6qC/F/zzASYxcWPifkl97oRuHugcRHeIuK6fg351qiexstIvhFGTUxYM7AMoe4ksx+4TQOxDgqbnDCd3wnJ+WOTrxtvcrOyI2ZkIpL86cQWOV0WinncR24SuT/xgyM8HSQMLzI5Al6Ok6j6n6oErvhW/9/RSSJGneHz0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f6sYTmIX; 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="f6sYTmIX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6EDFEC4CECD; Wed, 23 Oct 2024 09:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729676448; bh=u5wQJEaQSiZvDWYLH/rv/j1uxC/npMherkaK5E8eyr8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f6sYTmIXeL1Q5HTKn1g2D+61tY+1p2TMY6ftM6Tghpn2eVk7tQrUrNtDcV7gWGs// Bw70iVV+VR5ucoMQ5ra1cHw7iI4ZmA8jLg9hOMoGVlSw2Chhw/N3g1C8muIao10VbT YfwK/lRBZE1w+qbHrh727hYzhsB6C7daJ81dBAt6JzI2f95dPiix/dFtj5Apu1HJLb GABd6jMutJttSszSxytlhjEcEN8QwwuJWxijpcx7N+JN1r3Rt5kO9ZpsmvDYwWRPDb y5mlMvAI9l6i3p7fe1XH/70cOOm2eLe6V3ek1opEQIVaKxOIAXSv6M6lAaojUTgp2T R80Oem7QUyy3w== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v8 10/13] Squash to "selftests/bpf: Add bpf_burst scheduler & test" Date: Wed, 23 Oct 2024 17:40:20 +0800 Message-ID: X-Mailer: git-send-email 2.45.2 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 test_bpf_sched(). Use the newly added bpf_for_each() helper to walk the conn_list. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 2 +- .../selftests/bpf/progs/mptcp_bpf_burst.c | 74 ++++++++----------- 2 files changed, 33 insertions(+), 43 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 03eacae01b8d..bee6ca62bb8a 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -750,7 +750,7 @@ static void test_burst(void) if (!ASSERT_OK_PTR(skel, "open_and_load: burst")) return; - test_bpf_sched(skel->obj, "burst", WITH_DATA, WITH_DATA); + test_bpf_sched(skel->maps.burst, "burst", WITH_DATA, WITH_DATA); mptcp_bpf_burst__destroy(skel); } diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c index eb21119aa8f7..6242430d0330 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c @@ -9,10 +9,14 @@ char _license[] SEC("license") = "GPL"; #define MPTCP_SEND_BURST_SIZE 65428 +#define SSK_MODE_ACTIVE 0 +#define SSK_MODE_BACKUP 1 +#define SSK_MODE_MAX 2 + #define min(a, b) ((a) < (b) ? (a) : (b)) struct bpf_subflow_send_info { - __u8 subflow_id; + struct mptcp_subflow_context *subflow; __u64 linger_time; }; @@ -23,10 +27,6 @@ extern bool tcp_stream_memory_free(const struct sock *sk, int wake) __ksym; extern bool bpf_mptcp_subflow_queues_empty(struct sock *sk) __ksym; extern void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) __ksym; -#define SSK_MODE_ACTIVE 0 -#define SSK_MODE_BACKUP 1 -#define SSK_MODE_MAX 2 - static __always_inline __u64 div_u64(__u64 dividend, __u32 divisor) { return dividend / divisor; @@ -67,8 +67,7 @@ void BPF_PROG(mptcp_sched_burst_release, struct mptcp_sock *msk) { } -static int bpf_burst_get_send(struct mptcp_sock *msk, - struct mptcp_sched_data *data) +static int bpf_burst_get_send(struct mptcp_sock *msk) { struct bpf_subflow_send_info send_info[SSK_MODE_MAX]; struct mptcp_subflow_context *subflow; @@ -80,21 +79,16 @@ static int bpf_burst_get_send(struct mptcp_sock *msk, /* pick the subflow with the lower wmem/wspace ratio */ for (i = 0; i < SSK_MODE_MAX; ++i) { - send_info[i].subflow_id = MPTCP_SUBFLOWS_MAX; + send_info[i].subflow = NULL; send_info[i].linger_time = -1; } - for (i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) { - bool backup; - - subflow = bpf_mptcp_subflow_ctx_by_pos(data, i); - if (!subflow) - break; - - backup = subflow->backup || subflow->request_bkup; + bpf_for_each(mptcp_subflow, subflow, msk) { + bool backup = subflow->backup || subflow->request_bkup; ssk = mptcp_subflow_tcp_sock(subflow); - if (!mptcp_subflow_active(subflow)) + if (!mptcp_subflow_active(subflow) || + !sk_stream_memory_free(ssk)) continue; nr_active += !backup; @@ -109,7 +103,7 @@ static int bpf_burst_get_send(struct mptcp_sock *msk, linger_time = div_u64((__u64)ssk->sk_wmem_queued << 32, pace); if (linger_time < send_info[backup].linger_time) { - send_info[backup].subflow_id = i; + send_info[backup].subflow = subflow; send_info[backup].linger_time = linger_time; } } @@ -117,13 +111,14 @@ static int bpf_burst_get_send(struct mptcp_sock *msk, /* pick the best backup if no other subflow is active */ if (!nr_active) - send_info[SSK_MODE_ACTIVE].subflow_id = send_info[SSK_MODE_BACKUP].subflow_id; + send_info[SSK_MODE_ACTIVE].subflow = send_info[SSK_MODE_BACKUP].subflow; - subflow = bpf_mptcp_subflow_ctx_by_pos(data, send_info[SSK_MODE_ACTIVE].subflow_id); + subflow = bpf_core_cast(send_info[SSK_MODE_ACTIVE].subflow, + struct mptcp_subflow_context); if (!subflow) return -1; ssk = mptcp_subflow_tcp_sock(subflow); - if (!ssk || !sk_stream_memory_free(ssk)) + if (!ssk) return -1; burst = min(MPTCP_SEND_BURST_SIZE, mptcp_wnd_end(msk) - msk->snd_nxt); @@ -141,23 +136,18 @@ static int bpf_burst_get_send(struct mptcp_sock *msk, return 0; } -static int bpf_burst_get_retrans(struct mptcp_sock *msk, - struct mptcp_sched_data *data) +static int bpf_burst_get_retrans(struct mptcp_sock *msk) { - int backup = MPTCP_SUBFLOWS_MAX, pick = MPTCP_SUBFLOWS_MAX, subflow_id; + struct sock *backup = NULL, *pick = NULL; struct mptcp_subflow_context *subflow; int min_stale_count = INT_MAX; - struct sock *ssk; - for (int i = 0; i < data->subflows && i < MPTCP_SUBFLOWS_MAX; i++) { - subflow = bpf_mptcp_subflow_ctx_by_pos(data, i); - if (!subflow) - break; + bpf_for_each(mptcp_subflow, subflow, msk) { + struct sock *ssk = mptcp_subflow_tcp_sock(subflow); if (!mptcp_subflow_active(subflow)) continue; - ssk = mptcp_subflow_tcp_sock(subflow); /* still data outstanding at TCP level? skip this */ if (!tcp_rtx_and_write_queues_empty(ssk)) { mptcp_pm_subflow_chk_stale(msk, ssk); @@ -166,23 +156,23 @@ static int bpf_burst_get_retrans(struct mptcp_sock *msk, } if (subflow->backup || subflow->request_bkup) { - if (backup == MPTCP_SUBFLOWS_MAX) - backup = i; + if (!backup) + backup = ssk; continue; } - if (pick == MPTCP_SUBFLOWS_MAX) - pick = i; + if (!pick) + pick = ssk; } - if (pick < MPTCP_SUBFLOWS_MAX) { - subflow_id = pick; + if (pick) goto out; - } - subflow_id = min_stale_count > 1 ? backup : MPTCP_SUBFLOWS_MAX; + pick = min_stale_count > 1 ? backup : NULL; out: - subflow = bpf_mptcp_subflow_ctx_by_pos(data, subflow_id); + if (!pick) + return -1; + subflow = bpf_mptcp_subflow_ctx(pick); if (!subflow) return -1; mptcp_subflow_set_scheduled(subflow, true); @@ -194,11 +184,11 @@ int BPF_PROG(bpf_burst_get_subflow, struct mptcp_sock *msk, struct mptcp_sched_data *data) { if (data->reinject) - return bpf_burst_get_retrans(msk, data); - return bpf_burst_get_send(msk, data); + return bpf_burst_get_retrans(msk); + return bpf_burst_get_send(msk); } -SEC(".struct_ops") +SEC(".struct_ops.link") struct mptcp_sched_ops burst = { .init = (void *)mptcp_sched_burst_init, .release = (void *)mptcp_sched_burst_release, From patchwork Wed Oct 23 09:40: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: 13846834 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 2756818953D for ; Wed, 23 Oct 2024 09:40:49 +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=1729676450; cv=none; b=tSnDK+7uFqxKtJzXqcoRm5xl60vhIcu7MywWDHdY+VTyL9CoPEmXHRTk2EaIz7CAhmXslgZ08Kbav1DAtuEwstOSPsSNFzs+cQHWVtNPyeDdw4lM7fnEtWb7f9S4NpiG/VQ/aY138sNbjEzM4sq+IyMBgRU+3yzVXzSDO0ntDq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729676450; c=relaxed/simple; bh=1/XmonfNcS3aYrR3v6jWSV3X9hDxjUcdOYCh1phGiIA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ory423YpTdTW5Wv0EowCRBK9XYJ0KUjhqp25ErFHBy+5ySTw2FTQut713PVk7uVEa4Oo6Luv3gOcrgEOQUe2IIiEukKCrs4gZnYRkDcJ5oBuBdBrMV2Nm1ZIADKMPUHCsbln0iSFG+o6skL9lI47PafkXFgXUMMwF6MdrAunVDw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k4E8Tn3t; 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="k4E8Tn3t" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BD76C4CEC6; Wed, 23 Oct 2024 09:40:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729676449; bh=1/XmonfNcS3aYrR3v6jWSV3X9hDxjUcdOYCh1phGiIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k4E8Tn3tWNoIDOToz8JNKkUKYqYAKI0wzTv63kks3TFbheJ/MpAYbkb8YhfgxUkI9 ISQMyQEC9bqXeEqRe12NJZjPKLw67UuBzckvlfRHzxf4GH5MH4cABXfd0j0lGUNShV +YzM/9RKaFCXGm3BryjZrfPOOW+7PoFQrDDCWTLfn7AqyRJ+QROd7OoVvHVMnTG5qr l8IVdNsiGWg+vSZdhVq0jcdYLKZ1avYg7oOaZKcpFhC7P3JF2lGJy9jDp3ixh/2rc8 AgoAQYk5k8goRA+Nz24Gt/hrT4FpAwYANPTFTc5elUsawypTtM3jnl0bvDAd94d4TH GFmO5nsiD1FhA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v8 11/13] Squash to "bpf: Export mptcp packet scheduler helpers" Date: Wed, 23 Oct 2024 17:40:21 +0800 Message-ID: X-Mailer: git-send-email 2.45.2 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 Remove mptcp_subflow_set_scheduled and bpf_mptcp_subflow_ctx_by_pos from BPF kfunc set. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index c6d2efc6cf0e..4aee81814c82 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -316,8 +316,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) From patchwork Wed Oct 23 09:40: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: 13846835 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 99FC518953D for ; Wed, 23 Oct 2024 09:40: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=1729676451; cv=none; b=kymID1Wz5TUieg8CFWeAdLTaKKUXWYtIL9N8In1uBs91NnSMperCnVxvg2Iwz+zZEFOxZN0A+VB1iNAtOvDBpVUwj2dZuyKmUVKDbuT5fT2sfwiqceGiiC03h7W+7ZVzJk/BFx+pj/s75DvVj/7nIZTz6Ro2oQ04DWYJOfQTV5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729676451; c=relaxed/simple; bh=nwOv9/U6zYgGffloFt06J2kTn5sP+ujGZmTojwCBnmY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dZHejW6Ij0ZDQl8h5PguQRTc53NcVrqE6gjKEtTKwJW307DUlgcODg/MmRQkhmqabO/zPwq2zdKcM3NJQ43gv2jNKC8VGQpAFROC1iJ8myOgclsIIYbYT5dvjQ8c6GU8Ym7BY2c1KYk+1bGJrUuuiPFN6vMqc9Z4dWUu84SYRRU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aykAraqP; 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="aykAraqP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 535F3C4CEC6; Wed, 23 Oct 2024 09:40:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729676451; bh=nwOv9/U6zYgGffloFt06J2kTn5sP+ujGZmTojwCBnmY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aykAraqPfZIPgnRn0sDoCPlXrY0nrT7zxjSGqapOwIK8388HuH2+B+O/epuMbuFhL fxebVWHJl475IOXnwf0aGVivFiiwsejp1Ig3fKTp0tY1WHs9+FFB1711XV2447Q/di 1kRto8dhhVtrcsRlyj8VVDEVCqlrtWQPbp4qtES777G7fTkF2aKl2OpdXl5zE7ozXB F/26Hhtf+1kAWN1tUzy+2ZwxZWpFm4jTN/mpV7n1jxC8va8CsVONYDrQ8tH4Mp99Z2 XxrrRUw9Ugu05MJHLp3cTs6+vl7ipPwqBvO4DFgFSbEVAdE9fhD/ueDmIj4Lj8ESWD fW3Q7W4KxKYQA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v8 12/13] Revert "mptcp: add sched_data helpers" Date: Wed, 23 Oct 2024 17:40:22 +0800 Message-ID: X-Mailer: git-send-email 2.45.2 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. bpf_mptcp_subflow_ctx_by_pos and mptcp_sched_data_set_contexts are uesless now. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 8 -------- net/mptcp/protocol.h | 2 -- net/mptcp/sched.c | 22 ---------------------- 3 files changed, 32 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 4aee81814c82..13bdcbe34e1f 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -284,14 +284,6 @@ __bpf_kfunc static void bpf_mptcp_sock_release(struct mptcp_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) -{ - if (pos >= MPTCP_SUBFLOWS_MAX) - return NULL; - return data->contexts[pos]; -} - __bpf_kfunc static bool bpf_mptcp_subflow_queues_empty(struct sock *sk) { return tcp_rtx_queue_empty(sk); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 46bc7adb4763..1656686b98a3 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -722,8 +722,6 @@ 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); bool __mptcp_close(struct sock *sk, long timeout); void mptcp_cancel_work(struct sock *sk); diff --git a/net/mptcp/sched.c b/net/mptcp/sched.c index d7be9c453488..d8ab234f4410 100644 --- a/net/mptcp/sched.c +++ b/net/mptcp/sched.c @@ -148,26 +148,6 @@ void mptcp_release_sched(struct mptcp_sock *msk) bpf_module_put(sched, sched->owner); } -static void mptcp_sched_data_set_contexts(const struct mptcp_sock *msk, - struct mptcp_sched_data *data) -{ - struct mptcp_subflow_context *subflow; - int i = 0; - - mptcp_for_each_subflow(msk, subflow) { - if (i == MPTCP_SUBFLOWS_MAX) { - pr_warn_once("too many subflows"); - break; - } - mptcp_subflow_set_scheduled(subflow, false); - data->contexts[i++] = subflow; - } - data->subflows = i; - - for (; i < MPTCP_SUBFLOWS_MAX; i++) - data->contexts[i] = NULL; -} - int mptcp_sched_get_send(struct mptcp_sock *msk) { struct mptcp_subflow_context *subflow; @@ -194,7 +174,6 @@ int mptcp_sched_get_send(struct mptcp_sock *msk) data.reinject = false; if (msk->sched == &mptcp_sched_default || !msk->sched) return mptcp_sched_default_get_subflow(msk, &data); - mptcp_sched_data_set_contexts(msk, &data); return msk->sched->get_subflow(msk, &data); } @@ -217,6 +196,5 @@ int mptcp_sched_get_retrans(struct mptcp_sock *msk) data.reinject = true; if (msk->sched == &mptcp_sched_default || !msk->sched) return mptcp_sched_default_get_subflow(msk, &data); - mptcp_sched_data_set_contexts(msk, &data); return msk->sched->get_subflow(msk, &data); } From patchwork Wed Oct 23 09:40: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: 13846836 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 10CB618953D for ; Wed, 23 Oct 2024 09:40: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=1729676453; cv=none; b=gebDrcjKLrpm2iaQ30Qo6/X6HiUUgeBfHFXmTSfLkWLBHkwRUq/cWRkcLstitoVUopaS/rGQKYMvWVaA06//bXoqwQX80cBEgfr3lA8ROt3Ayb5Aa9h958WnYgNX5HTchnNU3zHmOcnj6h2JJbuuBYjOu1RSgV00KTsDTwg0jwI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729676453; c=relaxed/simple; bh=6bhndwaaGpAVAk7F3FGG00oCg3g2+1FwNFY5REvMeE4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZFwrs8hWp7OKliJLv1pLrXWC84hLCsS2+MS2ejec63lRCoLaPnHnTUfFM2WX0ybyHP5rEz7ohkXF2Ew6/yeAxRgjpO1Mp1kGAv2vTdj1Bezz1X99FckgNWOk1ZQo3ZYtjZhfk1DB7JptlTvxyEaFDW09y5jtsSuP//1y7zpik48= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uRJnQ9XL; 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="uRJnQ9XL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D61DEC4CEC6; Wed, 23 Oct 2024 09:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729676452; bh=6bhndwaaGpAVAk7F3FGG00oCg3g2+1FwNFY5REvMeE4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uRJnQ9XLVjWoIoPKiGgdrNdCVqChWhblxjS5//B2GLU5xtlDx7YP1GHDqiEBaNmWw Xv2jTJBElOpg3Nos8dlXWf82+k3kLMPDL4/p2yuRbhoO50P3dUNOpBxyrg6phFqhER zlwNnap83fwmxG9nFQlXqREItyIDcGEWRea7uEN7uUslPitvLFuaLlm6XUglMTbJ2x WYfH8Vc/JOMu2K+T//MbsyjsXHS0MBFUPaKTAfDPqEEqRwAxIdUUgePQN42sIViZzE Pzb1MNUomj6svl9ow2wa4AgbJRLQ1zf/cKG/IyPYSMPpQ5uKfdjosXWvH1BBjAa1eJ vaDZvxsGYXgGA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v8 13/13] mptcp: drop subflow contexts in mptcp_sched_data Date: Wed, 23 Oct 2024 17:40:23 +0800 Message-ID: <88ab66c999b73b58f7de60e560adf9eefaf66959.1729676320.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 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 mptcp_subflow bpf_iter is added now, it's better to use the helper bpf_for_each(mptcp_subflow) to traverse all subflows on the conn_list of an MPTCP socket and then call kfunc to modify the fields of each subflow in the WIP MPTCP BPF packet scheduler examples, instead of converting them to a fixed array. With this helper, we can get rid of this subflow array "contexts" and the size of it "subflows" in struct mptcp_sched_data. Signed-off-by: Geliang Tang --- include/net/mptcp.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 814b5f2e3ed5..84d67947a517 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -104,8 +104,6 @@ struct mptcp_out_options { struct mptcp_sched_data { bool reinject; - u8 subflows; - struct mptcp_subflow_context *contexts[MPTCP_SUBFLOWS_MAX]; }; struct mptcp_sched_ops {