Skip to contentSkip to conversation

Squash to "BPF packet scheduler"

PATCH In review Geliang Tang 3 participants 7 messages May 30, 2025 – Jun 6, 2025

Subsystems (5)
lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v3 cover Squash to "BPF packet scheduler"

From: Geliang Tang <[email protected]>

v3:
- put bpt_iter kfuncs into bpf_mptcp_iter_kfunc_set.

v2:
- Drop mptcp_subflow bpf_iter subtest.

Some squash-to patches based on Martin's feedback for "bpf: Add mptcp_subflow bpf_iter support" v3.

Geliang Tang (3):
Squash to "bpf: Register mptcp common kfunc set" Squash to "bpf: Add mptcp_subflow bpf_iter" Revert "selftests/bpf: Add mptcp_subflow bpf_iter subtest"

 net/mptcp/bpf.c                               | 48 ++++++++++--
 .../testing/selftests/bpf/bpf_experimental.h  |  8 --
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 73 -------------------
 .../selftests/bpf/progs/mptcp_bpf_iters.c     | 59 ---------------
 4 files changed, 43 insertions(+), 145 deletions(-)
 delete mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c
Signature · 1 line
2.43.0
author reviewer
#1 lore raw

PATCH v3 1/3 Squash to "bpf: Register mptcp common kfunc set"

From: Geliang Tang <[email protected]>

Define .filter as Martin suggested.

---
 net/mptcp/bpf.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
net/mptcp/bpf.c +16 -2
index 2b0cfb57df8c..113aad086b37 100644
@@ -317,9 +317,25 @@ 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_common_kfunc_ids)
 
+static int bpf_mptcp_common_kfunc_filter(const struct bpf_prog *prog, u32 kfunc_id)
+{
+	if (!btf_id_set8_contains(&bpf_mptcp_common_kfunc_ids, kfunc_id))
+		return 0;
+
+	if (prog->type != BPF_PROG_TYPE_STRUCT_OPS)
+		return -EACCES;
+
+#ifdef CONFIG_BPF_JIT
+	if (prog->aux->st_ops == &bpf_mptcp_sched_ops)
+		return 0;
+#endif
+	return -EACCES;
+}
+
 static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = {
 	.owner	= THIS_MODULE,
 	.set	= &bpf_mptcp_common_kfunc_ids,
+	.filter	= bpf_mptcp_common_kfunc_filter,
 };
 
 static int __init bpf_mptcp_kfunc_init(void)
@@ -327,8 +343,6 @@ static int __init bpf_mptcp_kfunc_init(void)
 	int ret;
 
 	ret = register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set);
-	ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCKOPT,
-					       &bpf_mptcp_common_kfunc_set);
 	ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
 					       &bpf_mptcp_common_kfunc_set);
 #ifdef CONFIG_BPF_JIT
Signature · 1 line
2.43.0
author reviewer
#2 lore raw

PATCH v3 2/3 Squash to "bpf: Add mptcp_subflow bpf_iter"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Define .filter as Martin suggested.

---
 net/mptcp/bpf.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
net/mptcp/bpf.c +27 -3
index 113aad086b37..e52821bae49c 100644
@@ -305,9 +305,6 @@ __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_ID_FLAGS(func, mptcp_subflow_set_scheduled)
 BTF_ID_FLAGS(func, mptcp_subflow_active)
 BTF_ID_FLAGS(func, mptcp_set_timeout)
@@ -338,6 +335,31 @@ static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = {
 	.filter	= bpf_mptcp_common_kfunc_filter,
 };
 
+/* .filter is called sometimes before prog->aux->st_ops is set,
+ * then prog->aux->st_ops is NULL. If return -EACCES in this case,
+ * an error occur:
+ * 	bug: bad parent state for iter next call
+ */
+BTF_KFUNCS_START(bpf_mptcp_iter_kfunc_ids)
+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_iter_kfunc_ids)
+
+static int bpf_mptcp_iter_kfunc_filter(const struct bpf_prog *prog, u32 kfunc_id)
+{
+	if (btf_id_set8_contains(&bpf_mptcp_iter_kfunc_ids, kfunc_id) &&
+	    prog->type != BPF_PROG_TYPE_STRUCT_OPS)
+		return -EACCES;
+	return 0;
+}
+
+static const struct btf_kfunc_id_set bpf_mptcp_iter_kfunc_set = {
+	.owner	= THIS_MODULE,
+	.set	= &bpf_mptcp_iter_kfunc_ids,
+	.filter	= bpf_mptcp_iter_kfunc_filter,
+};
+
 static int __init bpf_mptcp_kfunc_init(void)
 {
 	int ret;
@@ -345,6 +367,8 @@ static int __init bpf_mptcp_kfunc_init(void)
 	ret = register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set);
 	ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
 					       &bpf_mptcp_common_kfunc_set);
+	ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
+					       &bpf_mptcp_iter_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
maintainer
#3 lore raw

Re: [PATCH mptcp-next v3 2/3] Squash to "bpf: Add mptcp_subflow bpf_iter"

Hi Geliang,

Quoted 32 lines · Geliang Tang

From: Geliang Tang <[email protected]>

Define .filter as Martin suggested.

---
 net/mptcp/bpf.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
net/mptcp/bpf.c +5 -3
index 113aad086b37..e52821bae49c 100644
@@ -305,9 +305,6 @@ __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_ID_FLAGS(func, mptcp_subflow_set_scheduled)
 BTF_ID_FLAGS(func, mptcp_subflow_active)
 BTF_ID_FLAGS(func, mptcp_set_timeout)
@@ -338,6 +335,31 @@ static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = {
 	.filter	= bpf_mptcp_common_kfunc_filter,
 };
 
+/* .filter is called sometimes before prog->aux->st_ops is set,
+ * then prog->aux->st_ops is NULL. If return -EACCES in this case,
+ * an error occur:
+ * 	bug: bad parent state for iter next call
+ */

net/mptcp/bpf.c static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = { · line 352

Quoted 10 lines
net/mptcp/bpf.c +10 -0
+BTF_KFUNCS_START(bpf_mptcp_iter_kfunc_ids)
+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_iter_kfunc_ids)
+
+static int bpf_mptcp_iter_kfunc_filter(const struct bpf_prog *prog, u32 kfunc_id)
+{
+	if (btf_id_set8_contains(&bpf_mptcp_iter_kfunc_ids, kfunc_id) &&
+	    prog->type != BPF_PROG_TYPE_STRUCT_OPS)

Correct me if I'm wrong, but I think this filter is not needed: it simply restricts to (any) BPF_PROG_TYPE_STRUCT_OPS, which is already the case without this filter because this kfunc set is only registered for this program type, no?

When applying the patches, I removed this function, the corresponding .filter, and the comment explaining the error with .filter (at the end, this iterator can be used elsewhere, and it is cleaner like that). Please tell me if that was not correct.

Quoted 14 lines
net/mptcp/bpf.c +10 -0
+		return -EACCES;
+	return 0;
+}
+
+static const struct btf_kfunc_id_set bpf_mptcp_iter_kfunc_set = {
+	.owner	= THIS_MODULE,
+	.set	= &bpf_mptcp_iter_kfunc_ids,
+	.filter	= bpf_mptcp_iter_kfunc_filter,
+};
+
 static int __init bpf_mptcp_kfunc_init(void)
 {
 	int ret;

net/mptcp/bpf.c static int __init bpf_mptcp_kfunc_init(void) · line 374

Quoted 8 lines
net/mptcp/bpf.c +2 -0
@@ -345,6 +367,8 @@ static int __init bpf_mptcp_kfunc_init(void)
 	ret = register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set);
 	ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
 					       &bpf_mptcp_common_kfunc_set);
+	ret = ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS,
+					       &bpf_mptcp_iter_kfunc_set);
 #ifdef CONFIG_BPF_JIT
 	ret = ret ?: register_bpf_struct_ops(&bpf_mptcp_sched_ops, mptcp_sched_ops);
 #endif

Cheers,
Matt

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

PATCH v3 3/3 Revert "selftests/bpf: Add mptcp_subflow bpf_iter subtest"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Drop this patch as Martin suggested.

---
 .../testing/selftests/bpf/bpf_experimental.h  |  8 --
 .../testing/selftests/bpf/prog_tests/mptcp.c  | 73 -------------------
 .../selftests/bpf/progs/mptcp_bpf_iters.c     | 59 ---------------
 3 files changed, 140 deletions(-)
 delete mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c
tools/testing/selftests/bpf/bpf_experimental.h +0 -8
index c68827293cb9..5e512a1d09d1 100644
@@ -578,14 +578,6 @@ extern int bpf_iter_css_new(struct bpf_iter_css *it,
 extern struct cgroup_subsys_state *bpf_iter_css_next(struct bpf_iter_css *it) __weak __ksym;
 extern void bpf_iter_css_destroy(struct bpf_iter_css *it) __weak __ksym;
 
-struct bpf_iter_mptcp_subflow;
-extern int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it,
-				      struct sock *sk) __weak __ksym;
-extern struct mptcp_subflow_context *
-bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subflow *it) __weak __ksym;
-extern void
-bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it) __weak __ksym;
-
 extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym;
 extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym;
 extern int bpf_wq_set_callback_impl(struct bpf_wq *wq,
tools/testing/selftests/bpf/prog_tests/mptcp.c +0 -73

97 lines not on this page · raw message

tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c deleted +0 -59

59 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw
In reply to Geliang Tang

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/15342501617

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/abd8fe632270
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=967524

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

maintainer
#6 lore raw
In reply to Geliang Tang

Hi Geliang,

Quoted 4 lines · Geliang Tang

From: Geliang Tang <[email protected]>

v3:
- put bpt_iter kfuncs into bpf_mptcp_iter_kfunc_set.

Thank you for this new version! The modifications in the code look good to me, but applying them like that would cause issues in the code. Your first squash-to patch for "bpf: Register mptcp common kfunc set" would add a dependence on a later patch introducing bpf_mptcp_sched_ops.

I did the following modifications directly in the tree:
- Revert "bpf: Register mptcp common kfunc set".
- Add its content to "bpf: Add mptcp_subflow bpf_iter" & "bpf: Export mptcp packet scheduler helpers".
- Remove the filter for the mptcp subflow iter.

Feel free to check the modifications I did and suggest any changes if needed.

New patches for t/upstream:
- 7464c07e0b21: Revert "bpf: Register mptcp common kfunc set"
- 7a67a1f3a43d: tgupdate: merge t/bpf-Add-mptcp_subflow-bpf_iter base into t/bpf-Add-mptcp_subflow-bpf_iter
- 6a9ee240a5f5: "squashed" (with conflicts) in "bpf: Add mptcp_subflow bpf_iter"
- a3557639df4e: "squashed" (with conflicts) in "selftests/bpf: Add mptcp_subflow bpf_iter subtest"
- 4bb0a3a3a05f: tgupdate: merge t/mptcp-add-bpf_mptcp_sched_ops base into t/mptcp-add-bpf_mptcp_sched_ops
- e43d77b0c6aa: tgupdate: merge t/bpf-Add-bpf_mptcp_sched_kfunc_set base into t/bpf-Add-bpf_mptcp_sched_kfunc_set
- 3f5d496d0334: conflict in t/selftests-bpf-Add-bpf-scheduler-test
- f89d0256f95f: conflict in t/selftests-bpf-add-bpf_first-scheduler
- Results: 226663e50465..8df73de5f995 (export)

Tests are now in progress:

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

Note: I will monitor the CI and hopefully fix new issues if any.

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.