* [PATCH mptcp-next v3 0/3] Squash to "BPF packet scheduler"
@ 2025-05-30 8:03 Geliang Tang
2025-05-30 8:03 ` [PATCH mptcp-next v3 1/3] Squash to "bpf: Register mptcp common kfunc set" Geliang Tang
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Geliang Tang @ 2025-05-30 8:03 UTC (permalink / raw)
To: mptcp; +Cc: Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
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
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH mptcp-next v3 1/3] Squash to "bpf: Register mptcp common kfunc set"
2025-05-30 8:03 [PATCH mptcp-next v3 0/3] Squash to "BPF packet scheduler" Geliang Tang
@ 2025-05-30 8:03 ` Geliang Tang
2025-05-30 8:03 ` [PATCH mptcp-next v3 2/3] Squash to "bpf: Add mptcp_subflow bpf_iter" Geliang Tang
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Geliang Tang @ 2025-05-30 8:03 UTC (permalink / raw)
To: mptcp; +Cc: Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
Define .filter as Martin suggested.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/bpf.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c
index 2b0cfb57df8c..113aad086b37 100644
--- a/net/mptcp/bpf.c
+++ b/net/mptcp/bpf.c
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH mptcp-next v3 2/3] Squash to "bpf: Add mptcp_subflow bpf_iter"
2025-05-30 8:03 [PATCH mptcp-next v3 0/3] Squash to "BPF packet scheduler" Geliang Tang
2025-05-30 8:03 ` [PATCH mptcp-next v3 1/3] Squash to "bpf: Register mptcp common kfunc set" Geliang Tang
@ 2025-05-30 8:03 ` Geliang Tang
2025-06-06 12:02 ` Matthieu Baerts
2025-05-30 8:03 ` [PATCH mptcp-next v3 3/3] Revert "selftests/bpf: Add mptcp_subflow bpf_iter subtest" Geliang Tang
` (2 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: Geliang Tang @ 2025-05-30 8:03 UTC (permalink / raw)
To: mptcp; +Cc: Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
Define .filter as Martin suggested.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/bpf.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c
index 113aad086b37..e52821bae49c 100644
--- a/net/mptcp/bpf.c
+++ b/net/mptcp/bpf.c
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH mptcp-next v3 3/3] Revert "selftests/bpf: Add mptcp_subflow bpf_iter subtest"
2025-05-30 8:03 [PATCH mptcp-next v3 0/3] Squash to "BPF packet scheduler" Geliang Tang
2025-05-30 8:03 ` [PATCH mptcp-next v3 1/3] Squash to "bpf: Register mptcp common kfunc set" Geliang Tang
2025-05-30 8:03 ` [PATCH mptcp-next v3 2/3] Squash to "bpf: Add mptcp_subflow bpf_iter" Geliang Tang
@ 2025-05-30 8:03 ` Geliang Tang
2025-05-30 9:28 ` [PATCH mptcp-next v3 0/3] Squash to "BPF packet scheduler" MPTCP CI
2025-06-06 12:02 ` Matthieu Baerts
4 siblings, 0 replies; 7+ messages in thread
From: Geliang Tang @ 2025-05-30 8:03 UTC (permalink / raw)
To: mptcp; +Cc: Geliang Tang
From: Geliang Tang <tanggeliang@kylinos.cn>
Drop this patch as Martin suggested.
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
.../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
diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
index c68827293cb9..5e512a1d09d1 100644
--- a/tools/testing/selftests/bpf/bpf_experimental.h
+++ b/tools/testing/selftests/bpf/bpf_experimental.h
@@ -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,
diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index 7c51250e7161..d75b402c7706 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -11,7 +11,6 @@
#include "mptcp_sock.skel.h"
#include "mptcpify.skel.h"
#include "mptcp_subflow.skel.h"
-#include "mptcp_bpf_iters.skel.h"
#include "mptcp_bpf_first.skel.h"
#include "mptcp_bpf_bkup.skel.h"
#include "mptcp_bpf_rr.skel.h"
@@ -41,9 +40,6 @@
#ifndef MPTCP_INFO
#define MPTCP_INFO 1
#endif
-#ifndef TCP_IS_MPTCP
-#define TCP_IS_MPTCP 43 /* Is MPTCP being used? */
-#endif
#ifndef MPTCP_INFO_FLAG_FALLBACK
#define MPTCP_INFO_FLAG_FALLBACK _BITUL(0)
#endif
@@ -495,73 +491,6 @@ static void test_subflow(void)
close(cgroup_fd);
}
-static void run_iters_subflow(void)
-{
- int server_fd, client_fd;
- int is_mptcp, err;
- socklen_t len;
-
- server_fd = start_mptcp_server(AF_INET, ADDR_1, PORT_1, 0);
- if (!ASSERT_OK_FD(server_fd, "start_mptcp_server"))
- return;
-
- client_fd = connect_to_fd(server_fd, 0);
- if (!ASSERT_OK_FD(client_fd, "connect_to_fd"))
- goto close_server;
-
- send_byte(client_fd);
- wait_for_new_subflows(client_fd);
-
- len = sizeof(is_mptcp);
- /* mainly to trigger the BPF program */
- err = getsockopt(client_fd, SOL_TCP, TCP_IS_MPTCP, &is_mptcp, &len);
- if (ASSERT_OK(err, "getsockopt(client_fd, TCP_IS_MPTCP)"))
- ASSERT_EQ(is_mptcp, 1, "is_mptcp");
-
- close(client_fd);
-close_server:
- close(server_fd);
-}
-
-static void test_iters_subflow(void)
-{
- struct mptcp_bpf_iters *skel;
- struct netns_obj *netns;
- int cgroup_fd;
-
- cgroup_fd = test__join_cgroup("/iters_subflow");
- if (!ASSERT_OK_FD(cgroup_fd, "join_cgroup: iters_subflow"))
- return;
-
- skel = mptcp_bpf_iters__open_and_load();
- if (!ASSERT_OK_PTR(skel, "skel_open_load: iters_subflow"))
- goto close_cgroup;
-
- skel->links.iters_subflow = bpf_program__attach_cgroup(skel->progs.iters_subflow,
- cgroup_fd);
- if (!ASSERT_OK_PTR(skel->links.iters_subflow, "attach getsockopt"))
- goto skel_destroy;
-
- netns = netns_new(NS_TEST, true);
- if (!ASSERT_OK_PTR(netns, "netns_new: iters_subflow"))
- goto skel_destroy;
-
- if (endpoint_init("subflow", 4) < 0)
- goto close_netns;
-
- run_iters_subflow();
-
- /* 1 + 2 + 3 + 4 = 10 */
- ASSERT_EQ(skel->bss->ids, 10, "subflow ids");
-
-close_netns:
- netns_free(netns);
-skel_destroy:
- mptcp_bpf_iters__destroy(skel);
-close_cgroup:
- close(cgroup_fd);
-}
-
static int sched_init(char *flags, char *sched)
{
if (endpoint_init(flags, 2) < 0)
@@ -754,8 +683,6 @@ void test_mptcp(void)
test_mptcpify();
if (test__start_subtest("subflow"))
test_subflow();
- if (test__start_subtest("iters_subflow"))
- test_iters_subflow();
if (test__start_subtest("default"))
test_default();
if (test__start_subtest("first"))
diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c
deleted file mode 100644
index a1d8f9b20259..000000000000
--- a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c
+++ /dev/null
@@ -1,59 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/* Copyright (c) 2024, Kylin Software */
-
-/* vmlinux.h, bpf_helpers.h and other 'define' */
-#include "bpf_tracing_net.h"
-#include "mptcp_bpf.h"
-
-char _license[] SEC("license") = "GPL";
-int ids;
-
-#ifndef TCP_IS_MPTCP
-#define TCP_IS_MPTCP 43 /* Is MPTCP being used? */
-#endif
-
-SEC("cgroup/getsockopt")
-int iters_subflow(struct bpf_sockopt *ctx)
-{
- struct mptcp_subflow_context *subflow;
- struct bpf_sock *sk = ctx->sk;
- struct sock *ssk = NULL;
- struct mptcp_sock *msk;
- int local_ids = 0;
-
- if (ctx->level != SOL_TCP || ctx->optname != TCP_IS_MPTCP)
- return 1;
-
- msk = bpf_core_cast(sk, struct mptcp_sock);
- if (!msk || msk->pm.server_side || !msk->pm.subflows)
- return 1;
-
- bpf_for_each(mptcp_subflow, subflow, (struct sock *)sk) {
- /* Here MPTCP-specific packet scheduler kfunc can be called:
- * this test is not doing anything really useful, only to
- * verify the iteration works.
- */
-
- local_ids += subflow->subflow_id;
-
- /* only to check the following helper works */
- ssk = mptcp_subflow_tcp_sock(subflow);
- }
-
- if (!ssk)
- goto out;
-
- /* assert: if not OK, something wrong on the kernel side */
- if (ssk->sk_dport != ((struct sock *)msk)->sk_dport)
- goto out;
-
- /* only to check the following kfunc works */
- subflow = bpf_mptcp_subflow_ctx(ssk);
- if (!subflow || subflow->token != msk->token)
- goto out;
-
- ids = local_ids;
-
-out:
- return 1;
-}
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH mptcp-next v3 0/3] Squash to "BPF packet scheduler"
2025-05-30 8:03 [PATCH mptcp-next v3 0/3] Squash to "BPF packet scheduler" Geliang Tang
` (2 preceding siblings ...)
2025-05-30 8:03 ` [PATCH mptcp-next v3 3/3] Revert "selftests/bpf: Add mptcp_subflow bpf_iter subtest" Geliang Tang
@ 2025-05-30 9:28 ` MPTCP CI
2025-06-06 12:02 ` Matthieu Baerts
4 siblings, 0 replies; 7+ messages in thread
From: MPTCP CI @ 2025-05-30 9:28 UTC (permalink / raw)
To: Geliang Tang; +Cc: mptcp
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)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH mptcp-next v3 0/3] Squash to "BPF packet scheduler"
2025-05-30 8:03 [PATCH mptcp-next v3 0/3] Squash to "BPF packet scheduler" Geliang Tang
` (3 preceding siblings ...)
2025-05-30 9:28 ` [PATCH mptcp-next v3 0/3] Squash to "BPF packet scheduler" MPTCP CI
@ 2025-06-06 12:02 ` Matthieu Baerts
4 siblings, 0 replies; 7+ messages in thread
From: Matthieu Baerts @ 2025-06-06 12:02 UTC (permalink / raw)
To: Geliang Tang, mptcp; +Cc: Geliang Tang
Hi Geliang,
On 30/05/2025 10:03, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> 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
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH mptcp-next v3 2/3] Squash to "bpf: Add mptcp_subflow bpf_iter"
2025-05-30 8:03 ` [PATCH mptcp-next v3 2/3] Squash to "bpf: Add mptcp_subflow bpf_iter" Geliang Tang
@ 2025-06-06 12:02 ` Matthieu Baerts
0 siblings, 0 replies; 7+ messages in thread
From: Matthieu Baerts @ 2025-06-06 12:02 UTC (permalink / raw)
To: Geliang Tang, mptcp; +Cc: Geliang Tang
Hi Geliang,
On 30/05/2025 10:03, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
>
> Define .filter as Martin suggested.
>
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
> net/mptcp/bpf.c | 30 +++++++++++++++++++++++++++---
> 1 file changed, 27 insertions(+), 3 deletions(-)
>
> diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c
> index 113aad086b37..e52821bae49c 100644
> --- a/net/mptcp/bpf.c
> +++ b/net/mptcp/bpf.c
> @@ -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)
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.
> + 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
Cheers,
Matt
--
Sponsored by the NGI0 Core fund.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-06-06 12:02 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-30 8:03 [PATCH mptcp-next v3 0/3] Squash to "BPF packet scheduler" Geliang Tang
2025-05-30 8:03 ` [PATCH mptcp-next v3 1/3] Squash to "bpf: Register mptcp common kfunc set" Geliang Tang
2025-05-30 8:03 ` [PATCH mptcp-next v3 2/3] Squash to "bpf: Add mptcp_subflow bpf_iter" Geliang Tang
2025-06-06 12:02 ` Matthieu Baerts
2025-05-30 8:03 ` [PATCH mptcp-next v3 3/3] Revert "selftests/bpf: Add mptcp_subflow bpf_iter subtest" Geliang Tang
2025-05-30 9:28 ` [PATCH mptcp-next v3 0/3] Squash to "BPF packet scheduler" MPTCP CI
2025-06-06 12:02 ` Matthieu Baerts
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.