add mptcp_subflow bpf_iter
Subsystems (5)
Geliang Tang
reviewercover add mptcp_subflow bpf_iter
From: Geliang Tang <[email protected]>
This patch set adds a mptcp_subflow type bpf_iter, and self tests.
Geliang Tang (4):
bpf: Add mptcp_subflow bpf_iter
bpf: Register mptcp tracing kfunc set selftests/bpf: Add mptcp_subflow bpf_iter test prog selftests/bpf: Add mptcp_subflow bpf_iter subtest
kernel/bpf/helpers.c | 3 + net/mptcp/bpf.c | 59 +++++++++++++++++++ .../testing/selftests/bpf/bpf_experimental.h | 7 +++ .../testing/selftests/bpf/prog_tests/mptcp.c | 55 +++++++++++++++++ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 3 + .../selftests/bpf/progs/mptcp_bpf_iter.c | 38 ++++++++++++ 6 files changed, 165 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_iter.c
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH 1/4 bpf: Add mptcp_subflow bpf_iter
From: Geliang Tang <[email protected]>
It's necessary to traverse all subflows on the conn_list of an MPTCP socket and then call kfunc to modify the fields of each subflow. In kernel space, mptcp_for_each_subflow() helper is used for this:
mptcp_for_each_subflow(msk, subflow)
kfunc(subflow);
But in the MPTCP BPF program, this has not yet been implemented. As Martin suggested recently, this conn_list walking + modify-by-kfunc usage fits the bpf_iter use case.
This patch adds a new bpf_iter type named "mptcp_subflow" to do this.
--- kernel/bpf/helpers.c | 3 +++ net/mptcp/bpf.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+)
kernel/bpf/helpers.c +3 -0
@@ -3023,6 +3023,9 @@ BTF_ID_FLAGS(func, bpf_preempt_enable) BTF_ID_FLAGS(func, bpf_iter_bits_new, KF_ITER_NEW) BTF_ID_FLAGS(func, bpf_iter_bits_next, KF_ITER_NEXT | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_iter_bits_destroy, KF_ITER_DESTROY) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy)BTF_KFUNCS_END (common_btf_ids) static const struct btf_kfunc_id_set common_kfunc_set = {
net/mptcp/bpf.c +57 -0
63 lines not on this page · raw message
Signature · 1 line
2.43.0
Martin KaFai Lau
reviewerRe: [PATCH mptcp-next 1/4] bpf: Add mptcp_subflow bpf_iter
Quoted 62 lines · Geliang Tang
From: Geliang Tang <[email protected]>
It's necessary to traverse all subflows on the
conn_listof an MPTCP socket and then call kfunc to modify the fields of each subflow. In kernel space,mptcp_for_each_subflow()helper is used for this:mptcp_for_each_subflow(msk, subflow) kfunc(subflow);But in the MPTCP BPF program, this has not yet been implemented. As Martin suggested recently, this
conn_listwalking + modify-by-kfunc usage fits thebpf_iteruse case.This patch adds a new
bpf_itertype named "mptcp_subflow" to do this.Suggested-by Martin KaFai Lau <[email protected]>Signed-off-by Geliang Tang <[email protected]>--- kernel/bpf/helpers.c | 3 +++ net/mptcp/bpf.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+)kernel/bpf/helpers.c +3
-0@@ -3023,6 +3023,9 @@ BTF_ID_FLAGS(func, bpf_preempt_enable) BTF_ID_FLAGS(func, bpf_iter_bits_new, KF_ITER_NEW) BTF_ID_FLAGS(func, bpf_iter_bits_next, KF_ITER_NEXT | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_iter_bits_destroy, KF_ITER_DESTROY) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy)BTF_KFUNCS_END (common_btf_ids) static const struct btf_kfunc_id_set common_kfunc_set = {net/mptcp/bpf.c +18
-0@@ -204,6 +204,63 @@ static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { .set = &bpf_mptcp_fmodret_ids, }; +struct bpf_iter__mptcp_subflow { + __bpf_md_ptr(struct bpf_iter_meta *, meta); + __bpf_md_ptr(struct mptcp_sock *, msk); + __bpf_md_ptr(struct list_head *, pos); +}; + +DEFINE_BPF_ITER_FUNC(mptcp_subflow, struct bpf_iter_meta *meta, + struct mptcp_sock *msk, struct list_head *pos) + +struct bpf_iter_mptcp_subflow { +__u64 __opaque[3 ]; +} __attribute__((aligned (8 ))); + +struct bpf_iter_mptcp_subflow_kern { +struct mptcp_sock *msk; +struct list_head *pos; +} __attribute__((aligned (8 ))); +
net/mptcp/bpf.c static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { · line 234
Quoted 10 lines
net/mptcp/bpf.c +10
-0+__bpf_kfunc_start_defs (); + +__bpf_kfunc int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it, +struct mptcp_sock *msk) +{ +struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + + kit->msk = msk; + kit->pos = &msk->conn_list; +spin_lock_bh (&msk->pm.lock);
I don't think spin_lock here without unlock can be used. e.g. What if bpf_iter_mptcp_subflow_new() is called twice back-to-back.
I haven't looked at the mptcp details, some questions:
The list is protected by msk->pm.lock?
What happen to the sk_lock of the msk?
Can this be rcu-ify? or it needs some cares when walking the established TCP subflow?
[ Please cc the bpf list. Helping to review patches is a good way to contribute back to the mailing list. ]
Quoted 32 lines
net/mptcp/bpf.c +29
-0+ +return 0 ; +} + +__bpf_kfunc struct mptcp_subflow_context * +bpf_iter_mptcp_subflow_next (struct bpf_iter_mptcp_subflow *it) +{ +struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; +struct mptcp_subflow_context *subflow; +struct mptcp_sock *msk = kit->msk; + + subflow = list_entry((kit->pos)->next, struct mptcp_subflow_context, node); +if (list_entry_is_head (subflow, &msk->conn_list, node)) +return NULL ; + + kit->pos = &subflow->node; +return subflow; +} + +__bpf_kfunc void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it) +{ +struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; +struct mptcp_sock *msk = kit->msk; + +spin_unlock_bh (&msk->pm.lock); +} + +__bpf_kfunc_end_defs (); +__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"kfuncs which will be used in BPF programs" );
Geliang Tang
reviewerRe: [PATCH mptcp-next 1/4] bpf: Add mptcp_subflow bpf_iter
Hi Martin,
Quoted 83 lines · Martin KaFai Lau
Quoted 72 lines · Geliang Tang
From: Geliang Tang <[email protected]>
It's necessary to traverse all subflows on the
conn_listof an MPTCP
socket and then call kfunc to modify the fields of each subflow. In kernel space,mptcp_for_each_subflow()helper is used for this:
mptcp_for_each_subflow(msk, subflow)
kfunc(subflow);But in the MPTCP BPF program, this has not yet been implemented. As Martin suggested recently, this
conn_listwalking + modify-by-kfunc usage fits thebpf_iteruse case.This patch adds a new
bpf_itertype named "mptcp_subflow" to do this.Suggested-by Martin KaFai Lau <[email protected]>Signed-off-by Geliang Tang <[email protected]>---
kernel/bpf/helpers.c| 3 +++
net/mptcp/bpf.c | 57
++++++++++++++++++++++++++++++++++++++++++++2 files changed, 60 insertions(+)kernel/bpf/helpers.c +0
-0@@ -3023,6 +3023,9 @@ BTF_ID_FLAGS(func, bpf_preempt_enable) BTF_ID_FLAGS(func, bpf_iter_bits_new, KF_ITER_NEW)
BTF_ID_FLAGS(func, bpf_iter_bits_next, KF_ITER_NEXT | KF_RET_NULL)
BTF_ID_FLAGS(func, bpf_iter_bits_destroy, KF_ITER_DESTROY)kernel/bpf/helpers.c +3
-0+BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next) +BTF_ID_FLAGS (func, bpf_iter_mptcp_subflow_destroy)
BTF_KFUNCS_END(common_btf_ids)
static const structbtf_kfunc_id_setcommon_kfunc_set= {net/mptcp/bpf.c +0
-0@@ -204,6 +204,63 @@ static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { .set = &bpf_mptcp_fmodret_ids, };net/mptcp/bpf.c +21
-0+struct bpf_iter__mptcp_subflow { + __bpf_md_ptr(struct bpf_iter_meta *, meta); + __bpf_md_ptr(struct mptcp_sock *, msk); + __bpf_md_ptr(struct list_head *, pos); +}; + +DEFINE_BPF_ITER_FUNC(mptcp_subflow, struct bpf_iter_meta *meta, + struct mptcp_sock *msk, struct list_head *pos) + +struct bpf_iter_mptcp_subflow { +__u64 __opaque[3 ]; +} __attribute__((aligned (8 ))); + +struct bpf_iter_mptcp_subflow_kern { +struct mptcp_sock *msk; +struct list_head *pos; +} __attribute__((aligned (8 ))); + +__bpf_kfunc_start_defs (); + +__bpf_kfunc int bpf_iter_mptcp_subflow_new(struct
bpf_iter_mptcp_subflow*it,
+ structmptcp_sock*msk)net/mptcp/bpf.c static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { · line 234
Quoted 6 lines
net/mptcp/bpf.c +6
-0+{ +struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + + kit->msk = msk; + kit->pos = &msk->conn_list; +spin_lock_bh (&msk->pm.lock);I don't think
spin_lockhere without unlock can be used. e.g. What ifbpf_iter_mptcp_subflow_new()is called twice back-to-back.
Quoted 6 lines
I haven't looked at the mptcp details, some questions:
The list is protected bymsk->pm.lock?
What happen to thesk_lockof the msk?
Can this be rcu-ify? or it needs some cares when walking the established TCP
subflow?
Thank you for your review. msk->pm.lock shouldn't be used here. The conn_list is not protected by msk->pm.lock. I will remove it in v2.
Quoted 5 lines
[ Please cc the bpf list. Helping to review patches is a good way to contribute
back to the mailing list. ]
This patch is for "mptcp-next", it depends on the "new MPTCP subflow subtest" which is under review on the bpf list. We will send it to the bpf list very soon.
Thanks,
-Geliang
Quoted 36 lines
Quoted 35 lines
net/mptcp/bpf.c +12
-0+ +return 0 ; +} + +__bpf_kfunc struct mptcp_subflow_context * +bpf_iter_mptcp_subflow_next (struct bpf_iter_mptcp_subflow *it) +{ +struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; +struct mptcp_subflow_context *subflow; +struct mptcp_sock *msk = kit->msk; + + subflow = list_entry((kit->pos)->next, struct
mptcp_subflow_context, node);
+ if (list_entry_is_head(subflow, &msk->conn_list, node))
+ return NULL;net/mptcp/bpf.c +6
-0+ + kit->pos = &subflow->node; +return subflow; +} + +__bpf_kfunc void bpf_iter_mptcp_subflow_destroy(struct
bpf_iter_mptcp_subflow*it)net/mptcp/bpf.c +9
-0+{ +struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; +struct mptcp_sock *msk = kit->msk; + +spin_unlock_bh (&msk->pm.lock); +} + +__bpf_kfunc_end_defs (); +
__diag_push();__diag_ignore_all("-Wmissing-prototypes", "kfuncs which will be used in BPF programs");
Re: [PATCH mptcp-next 1/4] bpf: Add mptcp_subflow bpf_iter
In reply to Martin KaFai LauQuoted 46 lines · Martin KaFai Lau
Quoted 44 lines · Geliang Tang
From: Geliang Tang <[email protected]>
It's necessary to traverse all subflows on the
conn_listof an MPTCP socket and then call kfunc to modify the fields of each subflow. In kernel space,mptcp_for_each_subflow()helper is used for this:mptcp_for_each_subflow(msk, subflow) kfunc(subflow);But in the MPTCP BPF program, this has not yet been implemented. As Martin suggested recently, this
conn_listwalking + modify-by-kfunc usage fits thebpf_iteruse case.This patch adds a new
bpf_itertype named "mptcp_subflow" to do this.Suggested-by Martin KaFai Lau <[email protected]>Signed-off-by Geliang Tang <[email protected]>--- kernel/bpf/helpers.c | 3 +++ net/mptcp/bpf.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+)kernel/bpf/helpers.c +3
-0@@ -3023,6 +3023,9 @@ BTF_ID_FLAGS(func, bpf_preempt_enable) BTF_ID_FLAGS(func, bpf_iter_bits_new, KF_ITER_NEW) BTF_ID_FLAGS(func, bpf_iter_bits_next, KF_ITER_NEXT | KF_RET_NULL) BTF_ID_FLAGS(func, bpf_iter_bits_destroy, KF_ITER_DESTROY) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_destroy)BTF_KFUNCS_END (common_btf_ids) static const struct btf_kfunc_id_set common_kfunc_set = {net/mptcp/bpf.c +0
-0@@ -204,6 +204,63 @@ static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { .set = &bpf_mptcp_fmodret_ids, };
Quoted 8 lines
net/mptcp/bpf.c static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { · line 214
Quoted 8 lines
net/mptcp/bpf.c +8
-0+struct bpf_iter__mptcp_subflow { + __bpf_md_ptr(struct bpf_iter_meta *, meta); + __bpf_md_ptr(struct mptcp_sock *, msk); + __bpf_md_ptr(struct list_head *, pos); +}; + +DEFINE_BPF_ITER_FUNC(mptcp_subflow, struct bpf_iter_meta *meta, + struct mptcp_sock *msk, struct list_head *pos)
this is defining BPF iterator *program type* (effectively), which is different from open-coded iterator. Do you need a BPF iterator program type for this? Or open-coded iterator called from other BPF program types would be sufficient?
Quoted 9 lines
net/mptcp/bpf.c static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { · line 223
Quoted 9 lines
net/mptcp/bpf.c +9
-0+ +struct bpf_iter_mptcp_subflow { +__u64 __opaque[3 ]; +} __attribute__((aligned (8 ))); + +struct bpf_iter_mptcp_subflow_kern { +struct mptcp_sock *msk; +struct list_head *pos; +} __attribute__((aligned (8 )));
opaque[3], but you are using two pointers here. Why the difference?
Quoted 59 lines
net/mptcp/bpf.c static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { · line 234
Quoted 11 lines
net/mptcp/bpf.c +11
-0+ +__bpf_kfunc_start_defs (); + +__bpf_kfunc int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it, +struct mptcp_sock *msk) +{ +struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + + kit->msk = msk; + kit->pos = &msk->conn_list; +spin_lock_bh (&msk->pm.lock);I don't think
spin_lockhere without unlock can be used. e.g. What ifbpf_iter_mptcp_subflow_new()is called twice back-to-back.I haven't looked at the mptcp details, some questions:
The list is protected bymsk->pm.lock?
What happen to thesk_lockof the msk?
Can this be rcu-ify? or it needs some cares when walking the established TCP subflow?[ Please cc the bpf list. Helping to review patches is a good way to contribute back to the mailing list. ]
Quoted 32 lines
net/mptcp/bpf.c +29
-0+ +return 0 ; +} + +__bpf_kfunc struct mptcp_subflow_context * +bpf_iter_mptcp_subflow_next (struct bpf_iter_mptcp_subflow *it) +{ +struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; +struct mptcp_subflow_context *subflow; +struct mptcp_sock *msk = kit->msk; + + subflow = list_entry((kit->pos)->next, struct mptcp_subflow_context, node); +if (list_entry_is_head (subflow, &msk->conn_list, node)) +return NULL ; + + kit->pos = &subflow->node; +return subflow; +} + +__bpf_kfunc void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it) +{ +struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; +struct mptcp_sock *msk = kit->msk; + +spin_unlock_bh (&msk->pm.lock); +} + +__bpf_kfunc_end_defs (); +__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"kfuncs which will be used in BPF programs" );
Geliang Tang
reviewerRe: [PATCH mptcp-next 1/4] bpf: Add mptcp_subflow bpf_iter
Hi Andrii,
Quoted 56 lines · Andrii Nakryiko
Quoted 54 lines · Martin KaFai Lau
Quoted 52 lines · Geliang Tang
From: Geliang Tang <[email protected]>
It's necessary to traverse all subflows on the
conn_listof an MPTCP
socket and then call kfunc to modify the fields of each subflow. In
kernel space,mptcp_for_each_subflow()helper is used for this:
mptcp_for_each_subflow(msk, subflow)
kfunc(subflow);But in the MPTCP BPF program, this has not yet been implemented. As
Martin suggested recently, thisconn_listwalking + modify-by- kfunc
usage fits thebpf_iteruse case.This patch adds a new
bpf_itertype named "mptcp_subflow" to do this.Suggested-by Martin KaFai Lau <[email protected]>Signed-off-by Geliang Tang <[email protected]>---
kernel/bpf/helpers.c| 3 +++
net/mptcp/bpf.c | 57
++++++++++++++++++++++++++++++++++++++++++++2 files changed, 60 insertions(+)kernel/bpf/helpers.c +0
-0@@ -3023,6 +3023,9 @@ BTF_ID_FLAGS(func, bpf_preempt_enable) BTF_ID_FLAGS(func, bpf_iter_bits_new, KF_ITER_NEW)
BTF_ID_FLAGS(func, bpf_iter_bits_next, KF_ITER_NEXT | KF_RET_NULL)
BTF_ID_FLAGS(func, bpf_iter_bits_destroy, KF_ITER_DESTROY)kernel/bpf/helpers.c +3
-0+BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new) +BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_next) +BTF_ID_FLAGS (func, bpf_iter_mptcp_subflow_destroy)
BTF_KFUNCS_END(common_btf_ids)static const struct
btf_kfunc_id_setcommon_kfunc_set= {net/mptcp/bpf.c +0
-0@@ -204,6 +204,63 @@ static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { .set = &bpf_mptcp_fmodret_ids, };
Quoted 14 lines
Quoted 8 lines
net/mptcp/bpf.c static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { · line 214
Quoted 8 lines
net/mptcp/bpf.c +8
-0+struct bpf_iter__mptcp_subflow { + __bpf_md_ptr(struct bpf_iter_meta *, meta); + __bpf_md_ptr(struct mptcp_sock *, msk); + __bpf_md_ptr(struct list_head *, pos); +}; + +DEFINE_BPF_ITER_FUNC(mptcp_subflow, struct bpf_iter_meta *meta, + struct mptcp_sock *msk, struct list_head *pos)this is defining BPF iterator *program type* (effectively), which is different from open-coded iterator. Do you need a BPF iterator program
type for this? Or open-coded iterator called from other BPF program types would be sufficient?
Yes, no need to define DEFINE_BPF_ITER_FUNC here, will drop it in v2.
Quoted 12 lines
Quoted 10 lines
net/mptcp/bpf.c static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { · line 223
Quoted 10 lines
net/mptcp/bpf.c +9
-0+ +struct bpf_iter_mptcp_subflow { + __u64 __opaque[3]; +} __attribute__((aligned (8 ))); + +struct bpf_iter_mptcp_subflow_kern { + struct mptcp_sock *msk; + struct list_head *pos; +} __attribute__((aligned (8 )));opaque[3], but you are using two pointers here. Why the difference?
Should be 2, not 3. will update in v2.
Thanks,
-Geliang
Quoted 66 lines
Quoted 66 lines
net/mptcp/bpf.c static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { · line 234
Quoted 13 lines
net/mptcp/bpf.c +11
-0+ +__bpf_kfunc_start_defs (); + +__bpf_kfunc int bpf_iter_mptcp_subflow_new(structbpf_iter_mptcp_subflow *it, + struct mptcp_sock *msk) +{ + struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + + kit->msk = msk; + kit->pos = &msk->conn_list; + spin_lock_bh(&msk->pm.lock);I don't think
spin_lockhere without unlock can be used. e.g. What ifbpf_iter_mptcp_subflow_new()is called twice back-to-back.I haven't looked at the mptcp details, some questions:
The list is protected bymsk->pm.lock?
What happen to thesk_lockof the msk?
Can this be rcu-ify? or it needs some cares when walking the established TCP
subflow?[ Please cc the bpf list. Helping to review patches is a good way to contribute
back to the mailing list. ]Quoted 34 lines
net/mptcp/bpf.c +20
-0+ + return 0; +} + +__bpf_kfunc struct mptcp_subflow_context * +bpf_iter_mptcp_subflow_next (struct bpf_iter_mptcp_subflow *it) +{ + struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + struct mptcp_subflow_context *subflow; + struct mptcp_sock *msk = kit->msk; + + subflow = list_entry((kit->pos)->next, struct mptcp_subflow_context, node); + if (list_entry_is_head(subflow, &msk->conn_list, node)) + return NULL; + + kit->pos = &subflow->node; + return subflow; +} + +__bpf_kfunc void bpf_iter_mptcp_subflow_destroy(struct
bpf_iter_mptcp_subflow*it)net/mptcp/bpf.c +9
-0+{ + struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + struct mptcp_sock *msk = kit->msk; + + spin_unlock_bh(&msk->pm.lock); +} + +__bpf_kfunc_end_defs (); +
__diag_push(); __diag_ignore_all("-Wmissing-prototypes",
"kfuncs which will be used in BPF programs");
Geliang Tang
reviewerPATCH 2/4 bpf: Register mptcp tracing kfunc set
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Since the kfuncs mptcp_subflow_active() and mptcp_subflow_set_scheduled() are invoked in the mptcp_subflow bpf_iter test in a trace for mptcp_subflow_get_send(), it's necessary to register them into a BPF_PROG_TYPE_TRACING type kfunc set.
Note:
BTF_KFUNCS_START(bpf_mptcp_sched_kfunc_ids)
BTF_ID_FLAGS(func, mptcp_subflow_set_scheduled)
BTF_ID_FLAGS(func, mptcp_subflow_active)
BTF_KFUNCS_END(bpf_mptcp_sched_kfunc_ids)
--- net/mptcp/bpf.c | 2 ++ 1 file changed, 2 insertions(+)
net/mptcp/bpf.c +2 -0
@@ -301,6 +301,8 @@ static int __init bpf_mptcp_kfunc_init(void)int ret; ret =register_btf_fmodret_id_set (&bpf_mptcp_fmodret_set); + ret = ret ?:register_btf_kfunc_id_set (BPF_PROG_TYPE_TRACING , + &bpf_mptcp_sched_kfunc_set); ret = ret ?:register_btf_kfunc_id_set (BPF_PROG_TYPE_STRUCT_OPS , &bpf_mptcp_sched_kfunc_set);#ifdef CONFIG_BPF_JIT
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH 3/4 selftests/bpf: Add mptcp_subflow bpf_iter test prog
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch adds a new mptcp bpf selftest program for the newly added mptcp_subflow bpf_iter.
Export bpf_iter_mptcp_subflow_new/_next/_destroy into bpf_experimental.h then use bpf_for_each(mptcp_subflow, subflow, msk) to walk the mptcp subflow list.
Add a trace for mptcp_subflow_get_send() to do this test and invoke kfuncs mptcp_subflow_active() and mptcp_subflow_set_scheduled() in the loop.
--- .../testing/selftests/bpf/bpf_experimental.h | 7 ++++ tools/testing/selftests/bpf/progs/mptcp_bpf.h | 3 ++ .../selftests/bpf/progs/mptcp_bpf_iter.c | 38 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcp_bpf_iter.c
tools/testing/selftests/bpf/bpf_experimental.h +7 -0
@@ -549,6 +549,13 @@ extern int bpf_iter_css_new(struct bpf_iter_css *it,extern struct cgroup_subsys_state *bpf_iter_css_next (struct bpf_iter_css *it)__weak __ksym; extern void bpf_iter_css_destroy(struct bpf_iter_css *it) __weak __ksym; +struct bpf_iter_mptcp_subflow ; +extern int bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it, + struct mptcp_sock *msk) __weak __ksym; +extern struct mptcp_subflow_context * +bpf_iter_mptcp_subflow_next (struct bpf_iter_mptcp_subflow *it)__weak __ksym; +extern void bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it) __weak __ksym; + extern int bpf_wq_init(struct bpf_wq *wq, void *p__map, unsigned int flags) __weak __ksym; extern int bpf_wq_start(struct bpf_wq *wq, unsigned int flags) __weak __ksym; extern int bpf_wq_set_callback_impl(struct bpf_wq *wq,
tools/testing/selftests/bpf/progs/mptcp_bpf.h +3 -0
@@ -46,6 +46,9 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) extern void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow, bool scheduled) __ksym; +extern void bpf_rcu_read_lock(void) __ksym; +extern void bpf_rcu_read_unlock(void) __ksym; +extern struct mptcp_subflow_context *bpf_mptcp_subflow_ctx_by_pos (const struct mptcp_sched_data *data,unsigned int pos) __ksym;
tools/testing/selftests/bpf/progs/mptcp_bpf_iter.c new file +38 -0
@@ -0,0 +1,38 @@ +// 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 pid; + +extern bool mptcp_subflow_active(struct mptcp_subflow_context *subflow) __ksym; + +SEC("fentry/mptcp_subflow_get_send") +struct sock *BPF_PROG (trace_mptcp_subflow_get_send ,struct mptcp_sock *msk) +{ +struct mptcp_subflow_context *subflow; +int i =0 ; + +if (bpf_get_current_pid_tgid () >>32 != pid) +return NULL ; + +bpf_rcu_read_lock (); +bpf_for_each (mptcp_subflow, subflow, msk) { +if (i++ >MPTCP_SUBFLOWS_MAX ) +break ; + +if (subflow->token != msk->token) +break ; + +if (!mptcp_subflow_active (subflow)) +continue ; + +mptcp_subflow_set_scheduled (subflow, false); + } +bpf_rcu_read_unlock (); + +return NULL ; +}
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH 4/4 selftests/bpf: Add mptcp_subflow bpf_iter subtest
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch adds a subtest named test_bpf_iter to load and verify the newly added mptcp_subflow type bpf_iter example in test_mptcp. Use endpoint_init() to add a new subflow endpoint. Use send_byte() to trigger the tracing program for mptcp_subflow_get_send.
--- .../testing/selftests/bpf/prog_tests/mptcp.c | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+)
tools/testing/selftests/bpf/prog_tests/mptcp.c +55 -0
@@ -10,6 +10,7 @@#include "mptcp_sock.skel.h" #include "mptcpify.skel.h" #include "mptcp_subflow.skel.h" +#include "mptcp_bpf_iter.skel.h" #include "mptcp_bpf_first.skel.h" #include "mptcp_bpf_bkup.skel.h" #include "mptcp_bpf_rr.skel.h"
@@ -470,6 +471,58 @@ static void test_subflow(void)close (cgroup_fd); } +static void run_bpf_iter (void ) +{ +int server_fd, client_fd; + + server_fd =start_mptcp_server (AF_INET ,ADDR_1 ,PORT_1 ,0 ); +if (!ASSERT_GE (server_fd,0 ,"start_mptcp_server" )) +return ; + + client_fd =connect_to_fd (server_fd,0 ); +if (!ASSERT_GE (client_fd,0 ,"connect to fd" )) + goto close_server; + +send_byte (client_fd); +wait_for_new_subflows (client_fd); +send_byte (client_fd); + +close (client_fd); +close_server: +close (server_fd); +} + +static void test_bpf_iter (void ) +{ +struct mptcp_bpf_iter *skel; +struct nstoken *nstoken; +int err; + + skel =mptcp_bpf_iter__open_and_load (); +if (!ASSERT_OK_PTR (skel,"skel_open_load: mptcp_iter" )) +return ; + + skel->bss->pid =getpid (); + + err =mptcp_bpf_iter__attach (skel); +if (!ASSERT_OK (err,"skel_attach: mptcp_iter" )) + goto skel_destroy; + + nstoken =create_netns (); +if (!ASSERT_OK_PTR (nstoken,"create_netns: mptcp_iter" )) + goto skel_destroy; + +if (endpoint_init ("subflow" ) <0 ) + goto close_netns; + +run_bpf_iter (); + +close_netns: +cleanup_netns (nstoken); +skel_destroy: +mptcp_bpf_iter__destroy (skel); +} +static struct nstoken *sched_init (char *flags,char *sched) {struct nstoken *nstoken;
@@ -651,6 +704,8 @@ void test_mptcp(void)test_mptcpify ();if (test__start_subtest ("subflow" ))test_subflow (); +if (test__start_subtest ("bpf_iter" )) +test_bpf_iter ();if (test__start_subtest ("default" ))test_default ();if (test__start_subtest ("first" ))
Signature · 1 line
2.43.0
Hi Geliang,
Thank you for your modifications, that's great!
But sadly, our CI spotted some issues with it when trying to build it.
You can find more details there:
https://github.com/multipath-tcp/mptcp_net-next/actions/runs/10721986850
Status: failure
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/88ad9420470b
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=887267
Feel free to reply to this email if you cannot access logs, if you need some support to fix the error, if this doesn't seem to be caused by your modifications or if the error is a false positive one.
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)
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 (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/10721986852
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/88ad9420470b
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=887267
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-normalFor 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)