Skip to contentSkip to conversation

use bpf_iter in bpf schedulers

PATCH In review Geliang Tang 3 participants 15 messages Feb 17, 2025 – Mar 20, 2025

Subsystems (5)
lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v15 cover use bpf_iter in bpf schedulers

From: Geliang Tang <[email protected]>

v15:
- patch 7, add the declaration of bpf_mptcp_subflow_tcp_sock

Depends on:
- Squash to "Add mptcp_subflow bpf_iter support", v3

Based-on: <[email protected]>

v14:
- patch 1, keep mptcp_sched_data_set_contexts() helper for future use.
- patch 2, use "sk = sk__ign" in bpf_mptcp_subflow_ctx() and bpf_sk_stream_memory_free().
- patch 8, drop "subflows" from struct mptcp_sched_data too.

v13:
- use '__ign' suffix to ignore the argument type checks of bpf_mptcp_subflow_ctx() and bpf_sk_stream_memory_free(), instead of adding a new helper bpf_mptcp_send_info_to_ssk().
- use 'bpf_for_each(mptcp_subflow, subflow, (struct sock *)msk)' instead of using 'bpf_for_each(mptcp_subflow, subflow, msk)'.
- keep struct mptcp_sched_data for future use.

v12:
- drop struct mptcp_sched_data.
- rebased on "split get_subflow interface into two" v2.

v11:
If another squash-to patchset (Squash to "Add mptcp_subflow bpf_iter support") under review is merged before this set, v10 will fail to run. v11 fixes this issue and can run regardless of whether it is merged before or after the squash-to patchset.

Compared with v10, only patches 3, 5, and 8 have been modified:
- use mptcp_subflow_tcp_sock instead of bpf_mptcp_subflow_tcp_sock in patch 3 and patch 5.
- drop bpf_mptcp_sched_kfunc_set, use bpf_mptcp_common_kfunc_set instead in patch 8.

v10:
- drop mptcp_subflow_set_scheduled() helper and WRITE_ONCE() in BPF.
- add new bpf helper bpf_mptcp_send_info_to_ssk() for burst scheduler.

v9:
- merge 'Fixes for "use bpf_iter in bpf schedulers" v8' into this set.
- rebased on "add netns helpers" v4

v8:
- address Mat's comments in v7.
- move sk_stream_memory_free check inside bpf_for_each() loop.
- implement mptcp_subflow_set_scheduled helper in BPF.
- add cleanup patches into this set again.

v7:
- move cleanup patches out of this set.
- rebased.

v6:
- rebased to "add mptcp_subflow bpf_iter" v10

v5:
- patch 2, drop mptcp_sock_type and mptcp_subflow_type.
- patch 3, revert "bpf: Export more bpf_burst related functions"
- patch 4, merge "bpf: Export more bpf_burst related functions" into it.

v4:
- patch 2, a new cleanup for "bpf: Add bpf_mptcp_sched_ops".
- patch 3 should be reverted.
- patch 8, register kfunc_set.

v3:
- rebased.
- put the "drop has_bytes_sent" squash-to patch into this set.

v2:
- update bpf_rr and bpf_burst

With the newly added mptcp_subflow bpf_iter, we can get rid of the subflows array "contexts" in struct mptcp_sched_data. This set uses bpf_for_each(mptcp_subflow) helper to update all the bpf schedules:

        bpf_for_each(mptcp_subflow, subflow, (struct sock *)msk) {
                ... ...
                mptcp_subflow_set_scheduled(subflow, true);
        }

Geliang Tang (8):
Squash to "mptcp: add sched_data helpers"
Squash to "bpf: Export mptcp packet scheduler helpers" Squash to "selftests/bpf: Add bpf_first scheduler & test" Squash to "selftests/bpf: Add bpf_bkup scheduler & test" Squash to "selftests/bpf: Add bpf_rr scheduler & test" Squash to "selftests/bpf: Add bpf_red scheduler & test" Squash to "selftests/bpf: Add bpf_burst scheduler & test"
mptcp: drop subflow contexts in mptcp_sched_data

 include/net/mptcp.h                           |  4 -
 net/mptcp/bpf.c                               | 50 ++++++------
 net/mptcp/protocol.h                          |  2 -
 net/mptcp/sched.c                             | 15 ----
 tools/testing/selftests/bpf/progs/mptcp_bpf.h |  5 +-
 .../selftests/bpf/progs/mptcp_bpf_bkup.c      | 16 +---
 .../selftests/bpf/progs/mptcp_bpf_burst.c     | 78 +++++++------------
 .../selftests/bpf/progs/mptcp_bpf_first.c     |  8 +-
 .../selftests/bpf/progs/mptcp_bpf_red.c       |  8 +-
 .../selftests/bpf/progs/mptcp_bpf_rr.c        | 31 ++++----
 10 files changed, 83 insertions(+), 134 deletions(-)
Signature · 1 line
2.43.0
author reviewer
#1 lore raw

PATCH v15 1/8 Squash to "mptcp: add sched_data helpers"

From: Geliang Tang <[email protected]>

Drop bpf_mptcp_subflow_ctx_by_pos.
Keep mptcp_sched_data_set_contexts for future use.

---
 net/mptcp/bpf.c      |  8 --------
 net/mptcp/protocol.h |  2 --
 net/mptcp/sched.c    | 15 ---------------
 3 files changed, 25 deletions(-)
net/mptcp/bpf.c +0 -8
index 2256d4de1e20..2d2ad38ab1c1 100644
@@ -278,14 +278,6 @@ 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)
-{
-	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);
net/mptcp/protocol.h +0 -2
index bac5c925a72f..a1d6d996aa93 100644
@@ -718,8 +718,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);
net/mptcp/sched.c +0 -15
index 37d86aadaeaa..ef3f0250ae1f 100644
@@ -157,21 +157,6 @@ void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
 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)
Signature · 1 line
2.43.0
author reviewer
#2 lore raw

PATCH v15 2/8 Squash to "bpf: Export mptcp packet scheduler helpers"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Instead of adding a new BPF function bpf_mptcp_send_info_to_ssk() in v12, this patch uses a much more simpler approach, which using '__ign' suffix for the argument of bpf_mptcp_subflow_ctx() to let BPF to ignore the type check of this argument.

Remove bpf_mptcp_subflow_ctx_by_pos from BPF kfunc set.
Drop bpf_mptcp_sched_kfunc_set, use bpf_mptcp_common_kfunc_set instead. Add new helpers bpf_mptcp_subflow_tcp_sock() and bpf_sk_stream_memory_free().

---
 net/mptcp/bpf.c | 44 +++++++++++++++++++++++++++++---------------
 1 file changed, 29 insertions(+), 15 deletions(-)
net/mptcp/bpf.c +29 -15
index 2d2ad38ab1c1..80fb1799b067 100644
@@ -224,8 +224,10 @@ struct bpf_iter_mptcp_subflow_kern {
 __bpf_kfunc_start_defs();
 
 __bpf_kfunc static struct mptcp_subflow_context *
-bpf_mptcp_subflow_ctx(const struct sock *sk)
+bpf_mptcp_subflow_ctx(const struct sock *sk__ign)
 {
+	const struct sock *sk = sk__ign;
+
 	if (sk && sk_fullsock(sk) &&
 	    sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk))
 		return mptcp_subflow_ctx(sk);
@@ -233,6 +235,15 @@ bpf_mptcp_subflow_ctx(const struct sock *sk)
 	return NULL;
 }
 
+__bpf_kfunc static struct sock *
+bpf_mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
+{
+	if (!subflow)
+		return NULL;
+
+	return mptcp_subflow_tcp_sock(subflow);
+}
+
 __bpf_kfunc static int
 bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it,
 			   struct sock *sk)
@@ -283,34 +294,37 @@ __bpf_kfunc static bool bpf_mptcp_subflow_queues_empty(struct sock *sk)
 	return tcp_rtx_queue_empty(sk);
 }
 
+__bpf_kfunc static bool bpf_sk_stream_memory_free(const struct sock *sk__ign)
+{
+	const struct sock *sk = sk__ign;
+
+	if (sk && sk_fullsock(sk) &&
+	    sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk))
+		return sk_stream_memory_free(sk);
+
+	return NULL;
+}
+
 __bpf_kfunc_end_defs();
 
 BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids)
 BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx, KF_RET_NULL)
+BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock, KF_RET_NULL)
 BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new, KF_ITER_NEW | KF_TRUSTED_ARGS)
 BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next, KF_ITER_NEXT | KF_RET_NULL)
 BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy, KF_ITER_DESTROY)
-BTF_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)
 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_sk_stream_memory_free, KF_RET_NULL)
 BTF_ID_FLAGS(func, bpf_mptcp_subflow_queues_empty)
 BTF_ID_FLAGS(func, mptcp_pm_subflow_chk_stale, KF_SLEEPABLE)
-BTF_KFUNCS_END(bpf_mptcp_sched_kfunc_ids)
+BTF_KFUNCS_END(bpf_mptcp_common_kfunc_ids)
 
-static const struct btf_kfunc_id_set bpf_mptcp_sched_kfunc_set = {
+static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = {
 	.owner	= THIS_MODULE,
-	.set	= &bpf_mptcp_sched_kfunc_ids,
+	.set	= &bpf_mptcp_common_kfunc_ids,
 };
 
 static int __init bpf_mptcp_kfunc_init(void)
@@ -321,7 +335,7 @@ static int __init bpf_mptcp_kfunc_init(void)
 	ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCKOPT,
 					       &bpf_mptcp_common_kfunc_set);
 	ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
-					       &bpf_mptcp_sched_kfunc_set);
+					       &bpf_mptcp_common_kfunc_set);
 #ifdef CONFIG_BPF_JIT
 	ret = ret ?: register_bpf_struct_ops(&bpf_mptcp_sched_ops, mptcp_sched_ops);
 #endif
Signature · 1 line
2.43.0
author reviewer
#3 lore raw

PATCH v15 3/8 Squash to "selftests/bpf: Add bpf_first scheduler & test"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Use the newly added bpf_for_each() helper to walk the conn_list. Drop bpf_mptcp_subflow_ctx_by_pos declaration.

---
 tools/testing/selftests/bpf/progs/mptcp_bpf.h       | 3 ---
 tools/testing/selftests/bpf/progs/mptcp_bpf_first.c | 8 +++++++-
 2 files changed, 7 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/progs/mptcp_bpf.h +0 -3
index 72263672510a..2eb2c1c3bffb 100644
@@ -49,7 +49,4 @@ bpf_mptcp_subflow_ctx(const struct sock *sk) __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
tools/testing/selftests/bpf/progs/mptcp_bpf_first.c +7 -1
index ab71ae3c6506..73b18eeeb62f 100644
@@ -20,7 +20,13 @@ SEC("struct_ops")
 int BPF_PROG(bpf_first_get_send, struct mptcp_sock *msk,
 	     struct mptcp_sched_data *data)
 {
-	mptcp_subflow_set_scheduled(bpf_mptcp_subflow_ctx_by_pos(data, 0), true);
+	struct mptcp_subflow_context *subflow;
+
+	subflow = bpf_mptcp_subflow_ctx(msk->first);
+	if (!subflow)
+		return -1;
+
+	mptcp_subflow_set_scheduled(subflow, true);
 	return 0;
 }
 
Signature · 1 line
2.43.0
author reviewer
#4 lore raw

PATCH v15 4/8 Squash to "selftests/bpf: Add bpf_bkup scheduler & test"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Use the newly added bpf_for_each() helper to walk the conn_list.

---
 .../testing/selftests/bpf/progs/mptcp_bpf_bkup.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
tools/testing/selftests/bpf/progs/mptcp_bpf_bkup.c +3 -13
index 29be67e2f2ef..b7212101705d 100644
@@ -20,26 +20,16 @@ SEC("struct_ops")
 int BPF_PROG(bpf_bkup_get_send, 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, (struct sock *)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;
 }
 
Signature · 1 line
2.43.0
author reviewer
#5 lore raw

PATCH v15 5/8 Squash to "selftests/bpf: Add bpf_rr scheduler & test"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Use the newly added bpf_for_each() helper to walk the conn_list.

---
 .../selftests/bpf/progs/mptcp_bpf_rr.c        | 31 +++++++++----------
 1 file changed, 14 insertions(+), 17 deletions(-)
tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c +14 -17
index 405e96c116d5..4b109adc3602 100644
@@ -34,38 +34,35 @@ SEC("struct_ops")
 int BPF_PROG(bpf_rr_get_send, 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 (!next)
+		return -1;
 
-	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 (!ptr->last_snd)
+		goto out;
 
-		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, (struct sock *)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:
+	mptcp_subflow_set_scheduled(next, true);
+	ptr->last_snd = mptcp_subflow_tcp_sock(next);
 	return 0;
 }
 
Signature · 1 line
2.43.0
author reviewer
#6 lore raw

PATCH v15 6/8 Squash to "selftests/bpf: Add bpf_red scheduler & test"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Use the newly added bpf_for_each() helper to walk the conn_list.

---
 tools/testing/selftests/bpf/progs/mptcp_bpf_red.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
tools/testing/selftests/bpf/progs/mptcp_bpf_red.c +3 -5
index 627502e3c851..9f2cab4ba3f7 100644
@@ -20,12 +20,10 @@ SEC("struct_ops")
 int BPF_PROG(bpf_red_get_send, 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, (struct sock *)msk)
+		mptcp_subflow_set_scheduled(subflow, true);
 
 	return 0;
 }
Signature · 1 line
2.43.0
author reviewer
#7 lore raw

PATCH v15 7/8 Squash to "selftests/bpf: Add bpf_burst scheduler & test"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Use the newly added bpf_for_each() helper to walk the conn_list. Drop bpf_subflow_send_info, use subflow_send_info instead.

---
 tools/testing/selftests/bpf/progs/mptcp_bpf.h |  2 +
 .../selftests/bpf/progs/mptcp_bpf_burst.c     | 78 +++++++------------
 2 files changed, 28 insertions(+), 52 deletions(-)
tools/testing/selftests/bpf/progs/mptcp_bpf.h +2 -0
index 2eb2c1c3bffb..badcffe0942c 100644
@@ -45,6 +45,8 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
 /* 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;
tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c +26 -52

151 lines not on this page · raw message

Signature · 1 line
2.43.0
author reviewer
#8 lore raw

PATCH v15 8/8 mptcp: drop subflow contexts in mptcp_sched_data

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

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. And keep struct mptcp_sched_data for future use.

---
 include/net/mptcp.h | 4 ----
 1 file changed, 4 deletions(-)
include/net/mptcp.h +0 -4
index 2c85ca92bb1c..df87114deb1c 100644
@@ -100,11 +100,7 @@ struct mptcp_out_options {
 #define MPTCP_SCHED_MAX		128
 #define MPTCP_SCHED_BUF_MAX	(MPTCP_SCHED_NAME_MAX * MPTCP_SCHED_MAX)
 
-#define MPTCP_SUBFLOWS_MAX	8
-
 struct mptcp_sched_data {
-	u8	subflows;
-	struct mptcp_subflow_context *contexts[MPTCP_SUBFLOWS_MAX];
 };
 
 struct mptcp_sched_ops {
Signature · 1 line
2.43.0
maintainer Reviewed-by on the v15 series
#9 lore raw
In reply to Geliang Tang
Quoted 9 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v15:
- patch 7, add the declaration of bpf_mptcp_subflow_tcp_sock

Depends on:
- Squash to "Add mptcp_subflow bpf_iter support", v3

Based-on: <[email protected]>

Hi Geliang -

I don't have any changes to suggest to this series, so I'll add my reviewed tag even though this can't be applied to the export branch yet (until the bpf_iter series is updated):

Quoted 106 lines

v14:
- patch 1, keep mptcp_sched_data_set_contexts() helper for future use.
- patch 2, use "sk = sk__ign" in bpf_mptcp_subflow_ctx() and bpf_sk_stream_memory_free().
- patch 8, drop "subflows" from struct mptcp_sched_data too.

v13:
- use '__ign' suffix to ignore the argument type checks of bpf_mptcp_subflow_ctx() and bpf_sk_stream_memory_free(), instead of adding a new helper bpf_mptcp_send_info_to_ssk().
- use 'bpf_for_each(mptcp_subflow, subflow, (struct sock *)msk)' instead of using 'bpf_for_each(mptcp_subflow, subflow, msk)'.
- keep struct mptcp_sched_data for future use.

v12:
- drop struct mptcp_sched_data.
- rebased on "split get_subflow interface into two" v2.

v11:
If another squash-to patchset (Squash to "Add mptcp_subflow bpf_iter support") under review is merged before this set, v10 will fail to run. v11 fixes this issue and can run regardless of whether it is merged before or after the squash-to patchset.

Compared with v10, only patches 3, 5, and 8 have been modified:
- use mptcp_subflow_tcp_sock instead of bpf_mptcp_subflow_tcp_sock in patch 3 and patch 5.
- drop bpf_mptcp_sched_kfunc_set, use bpf_mptcp_common_kfunc_set instead in patch 8.

v10:
- drop mptcp_subflow_set_scheduled() helper and WRITE_ONCE() in BPF.
- add new bpf helper bpf_mptcp_send_info_to_ssk() for burst scheduler.

v9:
- merge 'Fixes for "use bpf_iter in bpf schedulers" v8' into this set.
- rebased on "add netns helpers" v4

v8:
- address Mat's comments in v7.
- move sk_stream_memory_free check inside bpf_for_each() loop.
- implement mptcp_subflow_set_scheduled helper in BPF.
- add cleanup patches into this set again.

v7:
- move cleanup patches out of this set.
- rebased.

v6:
- rebased to "add mptcp_subflow bpf_iter" v10

v5:
- patch 2, drop mptcp_sock_type and mptcp_subflow_type.
- patch 3, revert "bpf: Export more bpf_burst related functions"
- patch 4, merge "bpf: Export more bpf_burst related functions" into it.

v4:
- patch 2, a new cleanup for "bpf: Add bpf_mptcp_sched_ops".
- patch 3 should be reverted.
- patch 8, register kfunc_set.

v3:
- rebased.
- put the "drop has_bytes_sent" squash-to patch into this set.

v2:
- update bpf_rr and bpf_burst

With the newly added mptcp_subflow bpf_iter, we can get rid of the subflows array "contexts" in struct mptcp_sched_data. This set uses bpf_for_each(mptcp_subflow) helper to update all the bpf schedules:

       bpf_for_each(mptcp_subflow, subflow, (struct sock *)msk) {
               ... ...
               mptcp_subflow_set_scheduled(subflow, true);
       }

Geliang Tang (8):
Squash to "mptcp: add sched_data helpers"
Squash to "bpf: Export mptcp packet scheduler helpers" Squash to "selftests/bpf: Add bpf_first scheduler & test" Squash to "selftests/bpf: Add bpf_bkup scheduler & test" Squash to "selftests/bpf: Add bpf_rr scheduler & test" Squash to "selftests/bpf: Add bpf_red scheduler & test" Squash to "selftests/bpf: Add bpf_burst scheduler & test"
mptcp: drop subflow contexts in mptcp_sched_data

include/net/mptcp.h                           |  4 -
net/mptcp/bpf.c                               | 50 ++++++------
net/mptcp/protocol.h                          |  2 -
net/mptcp/sched.c                             | 15 ----
tools/testing/selftests/bpf/progs/mptcp_bpf.h |  5 +-
.../selftests/bpf/progs/mptcp_bpf_bkup.c      | 16 +---
.../selftests/bpf/progs/mptcp_bpf_burst.c     | 78 +++++++------------
.../selftests/bpf/progs/mptcp_bpf_first.c     |  8 +-
.../selftests/bpf/progs/mptcp_bpf_red.c       |  8 +-
.../selftests/bpf/progs/mptcp_bpf_rr.c        | 31 ++++----
10 files changed, 83 insertions(+), 134 deletions(-)
Signature · 1 line
2.43.0
maintainer
#10 lore raw
In reply to Geliang Tang

Hi Geliang, Mat,

Quoted 4 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v15:
- patch 7, add the declaration of bpf_mptcp_subflow_tcp_sock

Thank you for the patches and the reviews!

Now in our tree:

- 07aa0978f6c6: "squashed" (with conflicts) patch 1/8 in "mptcp: add sched_data helpers"
- fa29b1f91c26: conflict in t/bpf-Add-bpf_mptcp_sched_kfunc_set

- 311895dc3441: "squashed" patch 2/8 in "bpf: Export mptcp packet scheduler helpers"
- 3c6796421a18: "squashed" patch 3/8 in "selftests/bpf: Add bpf_first scheduler & test"
- 86c995604f64: "squashed" patch 4/8 in "selftests/bpf: Add bpf_bkup scheduler & test"
- 0b70cc3bdfe5: "squashed" patch 5/8 in "selftests/bpf: Add bpf_rr scheduler & test"
- 8213e7e2d049: "squashed" patch 6/8 in "selftests/bpf: Add bpf_red scheduler & test"
- 3fe124ac24c8: "squashed" patch 7/8 in "selftests/bpf: Add bpf_burst scheduler & test"
- Results: 3161a41b78f4..a37b7ba9c462 (export)

While at it, I added two patches, as a follow-up of b68b106b0f15 ("mptcp: sched: reduce size for unused data") instead of patch 8/8:
- e74f811b4626: Revert: "mptcp: add sched_data helpers"
- Results: a37b7ba9c462..a44778c76bc6 (export)

- fe2716bcac00: mptcp: sched: remove mptcp_sched_data
- Results: a44778c76bc6..516dcfe47eed (export)

And the adaptation in the BPF code and selftests:
- 0228f6dcc40b: Squash to "bpf: Add bpf_mptcp_sched_ops"
- 145b54903251: Squash to "selftests/bpf: Add bpf_first scheduler & test"
- 4ebb90f81181: Squash to "selftests/bpf: Add bpf_bkup scheduler & test"
- 2af0575eda92: Squash to "selftests/bpf: Add bpf_rr scheduler & test"
- 1dd84d973730: Squash to "selftests/bpf: Add bpf_red scheduler & test"
- fff0e60b0834: Squash to "selftests/bpf: Add bpf_burst scheduler & test"
- Results: 516dcfe47eed..62dab9e8d979 (export)

Tests are now in progress:

- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/a5cceef4fc35169482ecfd086c3d19c15d23e7e6/checks

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#11 lore raw

Hi Matt, Mat,

Quoted 16 lines · Matthieu Baerts

Hi Geliang, Mat,

Quoted 4 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v15:
 - patch 7, add the declaration of bpf_mptcp_subflow_tcp_sock

Thank you for the patches and the reviews!

Now in our tree:

- 07aa0978f6c6: "squashed" (with conflicts) patch 1/8 in "mptcp: add sched_data helpers"
- fa29b1f91c26: conflict in t/bpf-Add-bpf_mptcp_sched_kfunc_set

Quoted 13 lines

- 311895dc3441: "squashed" patch 2/8 in "bpf: Export mptcp packet scheduler helpers"
- 3c6796421a18: "squashed" patch 3/8 in "selftests/bpf: Add bpf_first scheduler & test"
- 86c995604f64: "squashed" patch 4/8 in "selftests/bpf: Add bpf_bkup scheduler & test"
- 0b70cc3bdfe5: "squashed" patch 5/8 in "selftests/bpf: Add bpf_rr scheduler & test"
- 8213e7e2d049: "squashed" patch 6/8 in "selftests/bpf: Add bpf_red scheduler & test"
- 3fe124ac24c8: "squashed" patch 7/8 in "selftests/bpf: Add bpf_burst scheduler & test"
- Results: 3161a41b78f4..a37b7ba9c462 (export)

Thanks for applying this set.

Quoted 8 lines

While at it, I added two patches, as a follow-up of b68b106b0f15 ("mptcp: sched: reduce size for unused data") instead of patch 8/8:
- e74f811b4626: Revert: "mptcp: add sched_data helpers"
- Results: a37b7ba9c462..a44778c76bc6 (export)

- fe2716bcac00: mptcp: sched: remove mptcp_sched_data
- Results: a44778c76bc6..516dcfe47eed (export)

I think we need to keep mptcp scheduler API unchanged. We can keep struct mptcp_sched_data and mptcp_sched_data_set_contexts helper for future use, as I said in patch 8.

The bpf_iter_task [1] that I am adding recently can actually use them.

I've been thinking about this recently. It's not a good idea to add bpf_iter_task to struct mptcp_sock. It's better to add it to struct mptcp_sched_data instead since it's more related to mptcp scheduler.

1. Add bpf_iter_task in mptcp_sched_data.

struct mptcp_sched_data {
        struct task_struct *bpf_iter_task;
};

2. Set bpf_iter_task as "current" in mptcp_sched_data_set_contexts:

void mptcp_sched_data_set_contexts(const struct mptcp_sock *msk,
struct mptcp_sched_data *data)

{
        WRITE_ONCE(data->bpf_iter_task, current);
}

3. Add a struct mptcp_sched_data parameter for
bpf_iter_mptcp_subflow_new:

__bpf_kfunc static int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow1 *it,
struct sock *sk,
struct mptcp_sched_data *data)

4. Check data->bpf_iter_task in bpf_iter_mptcp_subflow_new:

        msk = mptcp_sk(sk);
        task = READ_ONCE(data->bpf_iter_task);
        if (!task || task != current)
                return -EINVAL;

        WRITE_ONCE(data->bpf_iter_task, NULL);

        msk_owned_by_me(msk);

        kit->msk = msk;
        kit->pos = &msk->conn_list;

5. Use bpf_for_each() with "data" parameter in bpf:

SEC("struct_ops")
int BPF_PROG(bpf_red_get_send, struct mptcp_sock *msk,
struct mptcp_sched_data *data)

{
        struct mptcp_subflow_context *subflow;

        bpf_for_each(mptcp_subflow, subflow, (struct sock *)msk, data)
                mptcp_subflow_set_scheduled(subflow, true);

        return 0;
}

WDYT?

Anyway, we can put the patch "mptcp: sched: remove mptcp_sched_data" on the export branch and wait for a while, don't send it upstream recently, and wait for me to send some squash-to patches to modify them.

Thanks,
-Geliang

[1]
https://patchwork.kernel.org/project/mptcp/patch/7ff2760dcee1532f624e2ccf4fd67e83ec09a01b.1740997925.git.tanggeliang@kylinos.cn/

Quoted 22 lines

And the adaptation in the BPF code and selftests:
- 0228f6dcc40b: Squash to "bpf: Add bpf_mptcp_sched_ops"
- 145b54903251: Squash to "selftests/bpf: Add bpf_first scheduler & test"
- 4ebb90f81181: Squash to "selftests/bpf: Add bpf_bkup scheduler & test"
- 2af0575eda92: Squash to "selftests/bpf: Add bpf_rr scheduler & test"
- 1dd84d973730: Squash to "selftests/bpf: Add bpf_red scheduler & test"
- fff0e60b0834: Squash to "selftests/bpf: Add bpf_burst scheduler & test"
- Results: 516dcfe47eed..62dab9e8d979 (export)

Tests are now in progress:

- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/a5cceef4fc35169482ecfd086c3d19c15d23e7e6/checks

Cheers,
Matt

maintainer
#12 lore raw

Hi Geliang,

Quoted 1 line · Geliang Tang

On Wed, 2025-03-05 at 17:14 +0100, Matthieu Baerts wrote:

(...)

Quoted 11 lines
Quoted 7 lines

While at it, I added two patches, as a follow-up of b68b106b0f15 ("mptcp: sched: reduce size for unused data") instead of patch 8/8:
- e74f811b4626: Revert: "mptcp: add sched_data helpers"
- Results: a37b7ba9c462..a44778c76bc6 (export)

- fe2716bcac00: mptcp: sched: remove mptcp_sched_data
- Results: a44778c76bc6..516dcfe47eed (export)

I think we need to keep mptcp scheduler API unchanged. We can keep struct mptcp_sched_data and mptcp_sched_data_set_contexts helper for future use, as I said in patch 8.

While this code has not been upstreamed, I think it is important to clean what is not being used. If we need to add an extra parameter, we will still be able to do so.

Quoted 5 lines

The bpf_iter_task [1] that I am adding recently can actually use them.

I've been thinking about this recently. It's not a good idea to add bpf_iter_task to struct mptcp_sock. It's better to add it to struct mptcp_sched_data instead since it's more related to mptcp scheduler.

Why is it not a good idea to add it to the msk? Will you not check it from bpf_iter kfunc where you have access to the msk, but not the data? Also, will you not need such check also for the BPF PM, so it will not be only dedicated to the scheduler?

Quoted 15 lines

1. Add bpf_iter_task in mptcp_sched_data.

struct mptcp_sched_data {
        struct task_struct *bpf_iter_task;
};

2. Set bpf_iter_task as "current" in mptcp_sched_data_set_contexts:

void mptcp_sched_data_set_contexts(const struct mptcp_sock *msk,
struct mptcp_sched_data *data)

{
        WRITE_ONCE(data->bpf_iter_task, current);
}
Quoted 7 lines

3. Add a struct mptcp_sched_data parameter for
bpf_iter_mptcp_subflow_new:

__bpf_kfunc static int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow1 *it,
struct sock *sk,
struct mptcp_sched_data *data)

That means that this kfunc will only be used for the scheduler API, then no longer for the [gs]etsockopt and BPF PM, no?

Quoted 8 lines

4. Check data->bpf_iter_task in bpf_iter_mptcp_subflow_new:

        msk = mptcp_sk(sk);
        task = READ_ONCE(data->bpf_iter_task);
        if (!task || task != current)
                return -EINVAL;

        WRITE_ONCE(data->bpf_iter_task, NULL);

I think it would make more sense to do that from sched.c, similar to a lock.

  WRITE_ONCE(data->bpf_iter_task, current);
  ret = msk->sched->get_send(msk, data);
  WRITE_ONCE(data->bpf_iter_task, NULL);

return ret;

Quoted 20 lines
        msk_owned_by_me(msk);

        kit->msk = msk;
        kit->pos = &msk->conn_list;

5. Use bpf_for_each() with "data" parameter in bpf:

SEC("struct_ops")
int BPF_PROG(bpf_red_get_send, struct mptcp_sock *msk,
struct mptcp_sched_data *data)

{
        struct mptcp_subflow_context *subflow;

        bpf_for_each(mptcp_subflow, subflow, (struct sock *)msk, data)
                mptcp_subflow_set_scheduled(subflow, true);

        return 0;
}
Quoted 6 lines

WDYT?

Anyway, we can put the patch "mptcp: sched: remove mptcp_sched_data" on the export branch and wait for a while, don't send it upstream recently, and wait for me to send some squash-to patches to modify them.

Sure. There are some other patches to send first anyway.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
maintainer
#13 lore raw

Hi Geliang,

Quoted 1 line · Matthieu Baerts

On 07/03/2025 04:08, Geliang Tang wrote:

(...)

Quoted 6 lines
Quoted 4 lines

Anyway, we can put the patch "mptcp: sched: remove mptcp_sched_data" on the export branch and wait for a while, don't send it upstream recently, and wait for me to send some squash-to patches to modify them.

Sure. There are some other patches to send first anyway.

If I have the opportunity to send more patches for net-next this week, is it OK for you if I add "mptcp: sched: remove mptcp_sched_data"?

If we need to re-introduce the mptcp_sched_data structure later, we can still do it. Currently, we don't use it in net-next or in our tree, so I think it is better to drop it for the moment to save some bytes and avoid confusions, no?

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author reviewer
#14 lore raw

Hi Matt,

Quoted 14 lines · Matthieu Baerts

Hi Geliang,

Quoted 1 line · Matthieu Baerts

On 07/03/2025 04:08, Geliang Tang wrote:

(...)

Quoted 7 lines
Quoted 6 lines

Anyway, we can put the patch "mptcp: sched: remove mptcp_sched_data" on
the export branch and wait for a while, don't send it upstream recently, and wait for me to send some squash-to patches to modify
them.

Quoted 5 lines
Quoted 1 line

Sure. There are some other patches to send first anyway.

If I have the opportunity to send more patches for net-next this week,
is it OK for you if I add "mptcp: sched: remove mptcp_sched_data"?

Sure, I agree. Please send this patch upstream.

Thanks,
-Geliang

Quoted 10 lines

If we need to re-introduce the mptcp_sched_data structure later, we can
still do it. Currently, we don't use it in net-next or in our tree, so I
think it is better to drop it for the moment to save some bytes and avoid confusions, no?

Cheers,
Matt