bpf: Add mptcp_subflow bpf_iter support
Subsystems (7)
Matthieu Baerts (NGI0)
maintainerv2 cover bpf: Add mptcp_subflow bpf_iter support
Here is a series from Geliang, adding mptcp_subflow bpf_iter support.
We are working on extending MPTCP with BPF, e.g. to control the path manager -- in charge of the creation, deletion, and announcements of subflows (paths) -- and the packet scheduler -- in charge of selecting which available path the next data will be sent to. These extensions need to iterate over the list of subflows attached to an MPTCP connection, and do some specific actions via some new kfunc that will be added later on.
This preparation work is split in different patches:
- Patch 1: extend bpf_skc_to_mptcp_sock() to be called with msk.
- Patch 2: allow using skc_to_mptcp_sock() in CGroup sockopt hooks.
- Patch 3: register some "basic" MPTCP kfunc.
- Patch 4: add mptcp_subflow bpf_iter support. Note that previous versions of this single patch have already been shared to the BPF mailing list. The changelog has been kept with a comment, but the version number has been reset to avoid confusions.
- Patch 5: add kfunc to make sure the msk is valid
- Patch 6: add more MPTCP endpoints in the selftests, in order to create more than 2 subflows.
- Patch 7: add a very simple test validating mptcp_subflow bpf_iter support. This test could be written without the new bpf_iter, but it is there only to make sure this specific feature works as expected.
---
Changes in v2:
- Patches 1-2: new ones.
- Patch 3: remove two kfunc, more restrictions. (Martin)
- Patch 4: add BUILD_BUG_ON(), more restrictions. (Martin)
- Patch 7: adaptations due to modifications in patches 1-4.
- Link to v1: https://lore.kernel.org/r/20241108-bpf-next-net-mptcp-bpf_iter-subflows-v1-0-cf16953035c1@kernel.org
---
Geliang Tang (7):
bpf: Extend bpf_skc_to_mptcp_sock to MPTCP sock
bpf: Allow use of skc_to_mptcp_sock in cg_sockopt
bpf: Register mptcp common kfunc set
bpf: Add mptcp_subflow bpf_iter
bpf: Acquire and release mptcp socket selftests/bpf: More endpoints for endpoint_init selftests/bpf: Add mptcp_subflow bpf_iter subtest
include/net/mptcp.h | 4 +- kernel/bpf/cgroup.c | 2 + net/core/filter.c | 2 +- net/mptcp/bpf.c | 113 +++++++++++++++++- tools/testing/selftests/bpf/bpf_experimental.h | 8 ++ tools/testing/selftests/bpf/prog_tests/mptcp.c | 129 ++++++++++++++++++++- tools/testing/selftests/bpf/progs/mptcp_bpf.h | 9 ++ .../testing/selftests/bpf/progs/mptcp_bpf_iters.c | 63 ++++++++++ 8 files changed, 318 insertions(+), 12 deletions(-)
---
base-commit: dad704ebe38642cd405e15b9c51263356391355c
change-id: 20241108-bpf-next-net-mptcp-bpf_iter-subflows-027f6d87770e
Best regards,
Signature · 1 line
Matthieu Baerts (NGI0) <[email protected]>
Matthieu Baerts (NGI0)
maintainerPATCH v2 1/7 bpf: Extend bpf_skc_to_mptcp_sock to MPTCP sock
From: Geliang Tang <[email protected]>
Currently, bpf_skc_to_mptcp_sock() can only be used with sockets that are MPTCP subflows: TCP sockets with tp->is_mptcp, created by the kernel from an MPTCP socket (IPPROTO_MPTCP). Typically used with BPF sock_ops operators.
Here, this helper is extended to support MPTCP sockets, the ones created by the userspace (IPPROTO_MPTCP). This is useful for BPF hooks involving these sockets, e.g. [gs]etsocktopt.
bpf_skc_to_mptcp_sock() uses bpf_mptcp_sock_from_subflow(). The former suggests any MPTCP type/subtype can be used, but the latter only accepts subflow ones. So bpf_mptcp_sock_from_subflow is modified here to support MPTCP socket, and renamed to avoid confusions.
---
Notes:
- v2: new patch.
--- include/net/mptcp.h | 4 ++-- net/core/filter.c | 2 +- net/mptcp/bpf.c | 10 ++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-)
include/net/mptcp.h +2 -2
@@ -322,9 +322,9 @@ static inline void mptcpv6_handle_mapped(struct sock *sk, bool mapped) { }#endif #if defined(CONFIG_MPTCP ) && defined(CONFIG_BPF_SYSCALL ) -struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk); +struct mptcp_sock *bpf_mptcp_sock_from_sock (struct sock *sk);#else -static inline struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk) {return NULL ; } +static inline struct mptcp_sock *bpf_mptcp_sock_from_sock (struct sock *sk) {return NULL ; }#endif #if !IS_ENABLED (CONFIG_MPTCP )
net/core/filter.c +1 -1
@@ -11833,7 +11833,7 @@ const struct bpf_func_proto bpf_skc_to_unix_sock_proto = { BPF_CALL_1(bpf_skc_to_mptcp_sock, struct sock *, sk) {BTF_TYPE_EMIT (struct mptcp_sock ); -return (unsigned long )bpf_mptcp_sock_from_subflow (sk); +return (unsigned long )bpf_mptcp_sock_from_sock (sk); }const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto = {
net/mptcp/bpf.c +8 -2
@@ -12,9 +12,15 @@#include <linux/bpf.h> #include "protocol.h" -struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk) +struct mptcp_sock *bpf_mptcp_sock_from_sock (struct sock *sk) { -if (sk &&sk_fullsock (sk) && sk->sk_protocol ==IPPROTO_TCP &&sk_is_mptcp (sk)) +if (unlikely (!sk || !sk_fullsock (sk))) +return NULL ; + +if (sk->sk_protocol ==IPPROTO_MPTCP ) +return mptcp_sk (sk); + +if (sk->sk_protocol ==IPPROTO_TCP &&sk_is_mptcp (sk))return mptcp_sk (mptcp_subflow_ctx (sk)->conn);return NULL ;
Signature · 1 line
2.47.1
Matthieu Baerts (NGI0)
maintainerPATCH v2 2/7 bpf: Allow use of skc_to_mptcp_sock in cg_sockopt
In reply to Matthieu Baerts (NGI0)From: Geliang Tang <[email protected]>
Currently, bpf_skc_to_mptcp_sock() helper is not allowed to be used in cg_sockopt. This patch adds this permission.
Thanks to the previous patch allowing skc_to_mptcp_sock() to be used with MPTCP sockets, this permission allows this helper to be use it in CGroup BPF hooks, e.g. [gs]etsocktopt.
---
Notes:
- v2: new patch.
--- kernel/bpf/cgroup.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/bpf/cgroup.c +2 -0
@@ -2358,6 +2358,8 @@ cg_sockopt_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)#ifdef CONFIG_INET case BPF_FUNC_tcp_sock:return &bpf_tcp_sock_proto; +case BPF_FUNC_skc_to_mptcp_sock: +return &bpf_skc_to_mptcp_sock_proto;#endif case BPF_FUNC_perf_event_output:return &bpf_event_output_data_proto;
Signature · 1 line
2.47.1
Matthieu Baerts (NGI0)
maintainerPATCH v2 3/7 bpf: Register mptcp common kfunc set
In reply to Matthieu Baerts (NGI0)From: Geliang Tang <[email protected]>
MPTCP helper mptcp_sk() is used to convert struct sock to mptcp_sock. Helpers mptcp_subflow_ctx() and mptcp_subflow_tcp_sock() are used to convert between struct mptcp_subflow_context and sock. They all will be used in MPTCP BPF programs too.
This patch defines corresponding wrappers of them, and put the wrappers into mptcp common kfunc set and register the set with the flag BPF_PROG_TYPE_UNSPEC to let them accessible to all types of BPF programs.
---
Notes:
- v2:
- Thanks to the two new previous patches, bpf_mptcp_sk() and bpf_mptcp_subflow_tcp_sock() are no longer needed.
- bpf_mptcp_subflow_ctx(): make sure the socket is an MPTCP subflow, and add KF_RET_NULL (Martin).
- Restrict this kfunc to BPF_PROG_TYPE_CGROUP_SOCKOPT for the moment.
--- net/mptcp/bpf.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
net/mptcp/bpf.c +30 -1
@@ -35,8 +35,37 @@ static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { .set = &bpf_mptcp_fmodret_ids, }; +__bpf_kfunc_start_defs (); + +__bpf_kfunc static struct mptcp_subflow_context * +bpf_mptcp_subflow_ctx (const struct sock *sk) +{ +if (sk &&sk_fullsock (sk) && + sk->sk_protocol ==IPPROTO_TCP &&sk_is_mptcp (sk)) +return mptcp_subflow_ctx (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_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, +}; +static int __init bpf_mptcp_kfunc_init (void ) { -return register_btf_fmodret_id_set (&bpf_mptcp_fmodret_set); +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); + +return ret; }late_initcall (bpf_mptcp_kfunc_init);
Signature · 1 line
2.47.1
Matthieu Baerts (NGI0)
maintainerPATCH v2 4/7 bpf: Add mptcp_subflow bpf_iter
In reply to Matthieu Baerts (NGI0)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.
So this patch adds a new bpf_iter type named "mptcp_subflow" to do this and implements its helpers bpf_iter_mptcp_subflow_new()/_next()/ _destroy(). And register these bpf_iter mptcp_subflow into mptcp common kfunc set. Then bpf_for_each() for mptcp_subflow can be used in BPF program like this:
bpf_for_each(mptcp_subflow, subflow, msk) kfunc(subflow);
---
Notes:
- v2:
- Add BUILD_BUG_ON() checks, similar to the ones done with other
bpf_iter_(...) helpers.
- Replace msk_owned_by_me() by sock_owned_by_user_nocheck() and
!spin_is_locked() (Martin).A few versions of this single patch have been previously posted to the BPF mailing list by Geliang, before continuing to the MPTCP mailing list only, with other patches of this series. The version of the whole series has been reset to 1, but here is the ChangeLog for the previous ones:
- v2: remove msk->pm.lock in _new() and _destroy() (Martin) drop DEFINE_BPF_ITER_FUNC, change opaque[3] to opaque[2] (Andrii)
- v3: drop bpf_iter__mptcp_subflow
- v4: if msk is NULL, initialize kit->msk to NULL in _new() and check it in _next() (Andrii)
- v5: use list_is_last() instead of list_entry_is_head() add KF_ITER_NEW/NEXT/DESTROY flags add msk_owned_by_me in _new()
- v6: add KF_TRUSTED_ARGS flag (Andrii, Martin)
--- net/mptcp/bpf.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
net/mptcp/bpf.c +53 -0
@@ -35,6 +35,15 @@ static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { .set = &bpf_mptcp_fmodret_ids, }; +struct bpf_iter_mptcp_subflow { +__u64 __opaque[2 ]; +}__aligned(8) ; + +struct bpf_iter_mptcp_subflow_kern { +struct mptcp_sock *msk; +struct list_head *pos; +}__aligned(8) ; +__bpf_kfunc_start_defs (); __bpf_kfunc static struct mptcp_subflow_context *
@@ -47,10 +56,54 @@ bpf_mptcp_subflow_ctx(const struct sock *sk)return NULL ; } +__bpf_kfunc static 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; +struct sock *sk = (struct sock *)msk; + +BUILD_BUG_ON (sizeof (struct bpf_iter_mptcp_subflow_kern ) > +sizeof (struct bpf_iter_mptcp_subflow )); +BUILD_BUG_ON (__alignof__(struct bpf_iter_mptcp_subflow_kern ) != + __alignof__(struct bpf_iter_mptcp_subflow )); + + kit->msk = msk; +if (!msk) +return -EINVAL ; + +if (!sock_owned_by_user_nocheck (sk) && + !spin_is_locked (&sk->sk_lock.slock)) +return -EINVAL ; + + kit->pos = &msk->conn_list; +return 0 ; +} + +__bpf_kfunc static struct mptcp_subflow_context * +bpf_iter_mptcp_subflow_next (struct bpf_iter_mptcp_subflow *it) +{ +struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + +if (!kit->msk ||list_is_last (kit->pos, &kit->msk->conn_list)) +return NULL ; + + kit->pos = kit->pos->next; + return list_entry(kit->pos, struct mptcp_subflow_context, node); +} + +__bpf_kfunc static void +bpf_iter_mptcp_subflow_destroy (struct bpf_iter_mptcp_subflow *it) +{ +} +__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_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 = {
Signature · 1 line
2.47.1
Martin KaFai Lau
reviewerRe: [PATCH bpf-next/net v2 4/7] bpf: Add mptcp_subflow bpf_iter
Quoted 78 lines · On 12/19/24 7:46 AM, Matthieu Baerts (NGI0) wrote:
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.So this patch adds a new
bpf_itertype named "mptcp_subflow" to do this and implements its helpers bpf_iter_mptcp_subflow_new()/_next()/_destroy(). And register thesebpf_itermptcp_subflowinto mptcp common kfunc set. Thenbpf_for_each()formptcp_subflowcan be used in BPF program like this:bpf_for_each(mptcp_subflow, subflow, msk) kfunc(subflow);Suggested-by Martin KaFai Lau <[email protected]>Signed-off-by Geliang Tang <[email protected]>Reviewed-by Mat Martineau <[email protected]>Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
Notes:
- v2:
- AddBUILD_BUG_ON()checks, similar to the ones done with otherbpf_iter_(...)helpers.
- Replacemsk_owned_by_me()bysock_owned_by_user_nocheck()and !spin_is_locked() (Martin).A few versions of this single patch have been previously posted to the BPF mailing list by Geliang, before continuing to the MPTCP mailing list only, with other patches of this series. The version of the whole series has been reset to 1, but here is the ChangeLog for the previous ones:
- v2: removemsk->pm.lockin_new()and_destroy()(Martin) dropDEFINE_BPF_ITER_FUNC, change opaque[3] to opaque[2] (Andrii)
- v3: dropbpf_iter__mptcp_subflow
- v4: if msk is NULL, initializekit->mskto NULL in_new()and check it in_next()(Andrii)
- v5: uselist_is_last()instead oflist_entry_is_head()add KF_ITER_NEW/NEXT/DESTROY flags addmsk_owned_by_mein_new()
- v6: addKF_TRUSTED_ARGSflag (Andrii, Martin)--- net/mptcp/bpf.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)net/mptcp/bpf.c +13
-0@@ -35,6 +35,15 @@ static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { .set = &bpf_mptcp_fmodret_ids, }; +struct bpf_iter_mptcp_subflow { +__u64 __opaque[2 ]; +}__aligned(8) ; + +struct bpf_iter_mptcp_subflow_kern { +struct mptcp_sock *msk; +struct list_head *pos; +}__aligned(8) ; +__bpf_kfunc_start_defs (); __bpf_kfunc static struct mptcp_subflow_context *@@ -47,10 +56,54 @@ bpf_mptcp_subflow_ctx(const struct sock *sk)return NULL ; } +__bpf_kfunc static int +bpf_iter_mptcp_subflow_new (struct bpf_iter_mptcp_subflow *it, +struct mptcp_sock *msk) +{
net/mptcp/bpf.c bpf_mptcp_subflow_ctx(const struct sock *sk) · line 72
Quoted 10 lines
net/mptcp/bpf.c +10
-0+struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; +struct sock *sk = (struct sock *)msk; + +BUILD_BUG_ON (sizeof (struct bpf_iter_mptcp_subflow_kern ) > +sizeof (struct bpf_iter_mptcp_subflow )); +BUILD_BUG_ON (__alignof__(struct bpf_iter_mptcp_subflow_kern ) != + __alignof__(struct bpf_iter_mptcp_subflow )); + + kit->msk = msk; +if (!msk)
NULL check is not needed. verifier should have rejected it for KF_TRUSTED_ARGS.
net/mptcp/bpf.c bpf_mptcp_subflow_ctx(const struct sock *sk) · line 76
Quoted 4 lines
net/mptcp/bpf.c +4
-0+return -EINVAL ; + +if (!sock_owned_by_user_nocheck (sk) && + !spin_is_locked (&sk->sk_lock.slock))
I could have missed something. If it is to catch bug, should it be sock_owned_by_me() that has the lockdep splat? For the cg get/setsockopt hook here, the lock should have already been held earlier in the kernel.
This set is only showing the cg sockopt bpf prog but missing the major struct_ops piece. It is hard to comment. I assumed the lock situation is the same for the struct_ops where the lock will be held before calling the struct_ops prog?
Quoted 34 lines
net/mptcp/bpf.c +26
-0+return -EINVAL ; + + kit->pos = &msk->conn_list; +return 0 ; +} + +__bpf_kfunc static struct mptcp_subflow_context * +bpf_iter_mptcp_subflow_next (struct bpf_iter_mptcp_subflow *it) +{ +struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + +if (!kit->msk ||list_is_last (kit->pos, &kit->msk->conn_list)) +return NULL ; + + kit->pos = kit->pos->next; + return list_entry(kit->pos, struct mptcp_subflow_context, node); +} + +__bpf_kfunc static void +bpf_iter_mptcp_subflow_destroy (struct bpf_iter_mptcp_subflow *it) +{ +} +__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_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 = {
Matthieu Baerts
maintainerRe: [PATCH bpf-next/net v2 4/7] bpf: Add mptcp_subflow bpf_iter
Hi Geliang,
(only with the MPTCP list)
Quoted 93 lines · Martin KaFai Lau
Quoted 78 lines · On 12/19/24 7:46 AM, Matthieu Baerts (NGI0) wrote:
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.So this patch adds a new
bpf_itertype named "mptcp_subflow" to do this and implements its helpers bpf_iter_mptcp_subflow_new()/_next()/_destroy(). And register thesebpf_itermptcp_subflowinto mptcp common kfunc set. Thenbpf_for_each()formptcp_subflowcan be used in BPF program like this:bpf_for_each(mptcp_subflow, subflow, msk)
kfunc(subflow);Suggested-by Martin KaFai Lau <[email protected]>Signed-off-by Geliang Tang <[email protected]>Reviewed-by Mat Martineau <[email protected]>Signed-off-by Matthieu Baerts (NGI0) <[email protected]>---
Notes:
- v2:
- AddBUILD_BUG_ON()checks, similar to the ones done with otherbpf_iter_(...)helpers.
- Replacemsk_owned_by_me()bysock_owned_by_user_nocheck()and !spin_is_locked() (Martin).A few versions of this single patch have been previously posted to the BPF mailing list by Geliang, before continuing to the MPTCP mailing list only, with other patches of this series. The version of the whole series has been reset to 1, but here is the ChangeLog for the previous ones:
- v2: removemsk->pm.lockin_new()and_destroy()(Martin) dropDEFINE_BPF_ITER_FUNC, change opaque[3] to opaque[2] (Andrii)
- v3: dropbpf_iter__mptcp_subflow
- v4: if msk is NULL, initializekit->mskto NULL in_new()and check it in_next()(Andrii)
- v5: uselist_is_last()instead oflist_entry_is_head()add KF_ITER_NEW/NEXT/DESTROY flags addmsk_owned_by_mein_new()
- v6: addKF_TRUSTED_ARGSflag (Andrii, Martin)
---
net/mptcp/bpf.c| 53 +++++++++++++++++++++++++++++++++++++++++++++++
++++++1 file changed, 53 insertions(+)net/mptcp/bpf.c +0
-0index
c5bfd84c16c43230d9d8e1fd8ff781a767e647b5..e39f0e4fb683c1aa31ee075281daee218dac5878100644net/mptcp/bpf.c +8
-0@@ -35,6 +35,15 @@ static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { .set = &bpf_mptcp_fmodret_ids, }; +struct bpf_iter_mptcp_subflow { + __u64 __opaque[2]; +}__aligned(8) ; + +struct bpf_iter_mptcp_subflow_kern { + struct mptcp_sock *msk; + struct list_head *pos; +}__aligned(8) ; + __bpf_kfunc_start_defs();
__bpf_kfuncstatic structmptcp_subflow_context*net/mptcp/bpf.c +0
-0@@ -47,10 +56,54 @@ bpf_mptcp_subflow_ctx(const struct sock *sk) return NULL; }+__bpf_kfunc static int
net/mptcp/bpf.c +3
-0+bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it, + struct mptcp_sock *msk) +{net/mptcp/bpf.c bpf_mptcp_subflow_ctx(const struct sock *sk) · line 72
Quoted 10 lines
net/mptcp/bpf.c +10
-0+ struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + struct sock *sk = (struct sock *)msk; + + BUILD_BUG_ON(sizeof(struct bpf_iter_mptcp_subflow_kern) > + sizeof(struct bpf_iter_mptcp_subflow)); + BUILD_BUG_ON(__alignof__(struct bpf_iter_mptcp_subflow_kern) != + __alignof__(struct bpf_iter_mptcp_subflow)); + + kit->msk = msk; + if (!msk)NULL check is not needed. verifier should have rejected it for
KF_TRUSTED_ARGS.
Quoted 8 lines
Quoted 4 lines
+ return
-EINVAL;
+
+ if (!sock_owned_by_user_nocheck(sk) &&
+ !spin_is_locked(&sk->sk_lock.slock))I could have missed something. If it is to catch bug, should it be
sock_owned_by_me()that has the lockdep splat? For the cg get/setsockopt hook here, the lock should have already been held earlier in the kernel.
:)
So from what I understand: either we need these checks because this helper could technically be called when these conditions are not met. Or we don't need them, and we can have sock_owned_by_me() (without the return that was in the v1) for lockdep.
Quoted 4 lines
This set is only showing the cg sockopt bpf prog but missing the major
struct_opspiece. It is hard to comment. I assumed the lock situation is the same for thestruct_opswhere the lock will be held before calling thestruct_opsprog?
Can we restrict the use of this helper only for some specific callbacks? Or for only some specific struct_ops?
Last time I looked, I thought that you could only restrict it like that:
"this helper can be used by (any) struct_ops". But then does it mean this helper could be called from a TCP BPF CC ops or another unrelated one for example? How can we avoid that?
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerRe: [PATCH bpf-next/net v2 4/7] bpf: Add mptcp_subflow bpf_iter
In reply to Martin KaFai LauHi Martin,
Thank you for your review!
Sorry for the delay here, Geliang started to work on a new version, but it might take a bit of time as he is currently off for a few days.
Quoted 22 lines · Martin KaFai Lau
Quoted 21 lines · On 12/19/24 7:46 AM, Matthieu Baerts (NGI0) wrote:
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.So this patch adds a new
bpf_itertype named "mptcp_subflow" to do this and implements its helpers bpf_iter_mptcp_subflow_new()/_next()/_destroy(). And register thesebpf_itermptcp_subflowinto mptcp common kfunc set. Thenbpf_for_each()formptcp_subflowcan be used in BPF program like this:bpf_for_each(mptcp_subflow, subflow, msk)
kfunc(subflow);
(...)
Quoted 5 lines
Quoted 5 lines
net/mptcp/bpf.c +0
-0index
c5bfd84c16c43230d9d8e1fd8ff781a767e647b5..e39f0e4fb683c1aa31ee075281daee218dac5878100644net/mptcp/bpf.c +0
-0
(...)
Quoted 21 lines
Quoted 7 lines
net/mptcp/bpf.c +0
-0@@ -47,10 +56,54 @@ bpf_mptcp_subflow_ctx(const struct sock *sk) return NULL; }+__bpf_kfunc static int
net/mptcp/bpf.c +3
-0+bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it, + struct mptcp_sock *msk) +{net/mptcp/bpf.c bpf_mptcp_subflow_ctx(const struct sock *sk) · line 72
Quoted 10 lines
net/mptcp/bpf.c +10
-0+ struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; + struct sock *sk = (struct sock *)msk; + + BUILD_BUG_ON(sizeof(struct bpf_iter_mptcp_subflow_kern) > + sizeof(struct bpf_iter_mptcp_subflow)); + BUILD_BUG_ON(__alignof__(struct bpf_iter_mptcp_subflow_kern) != + __alignof__(struct bpf_iter_mptcp_subflow)); + + kit->msk = msk; + if (!msk)NULL check is not needed. verifier should have rejected it for
KF_TRUSTED_ARGS.
Quoted 8 lines
Quoted 4 lines
+ return
-EINVAL;
+
+ if (!sock_owned_by_user_nocheck(sk) &&
+ !spin_is_locked(&sk->sk_lock.slock))I could have missed something. If it is to catch bug, should it be
sock_owned_by_me()that has the lockdep splat? For the cg get/setsockopt hook here, the lock should have already been held earlier in the kernel.
Good point. Because in this series, the kfunc is currently restricted to CG [gs]etsockopt hooks, we should use msk_owned_by_me(msk) here.
Quoted 4 lines
This set is only showing the cg sockopt bpf prog but missing the major
struct_opspiece. It is hard to comment. I assumed the lock situation is the same for thestruct_opswhere the lock will be held before calling thestruct_opsprog?
I understand it is hard to comment on that point. In the 'struct_ops' we are designing, the lock will indeed be held before calling the stuct_ops program. So we will just need to make sure this assumption is correct for all callbacks of our struct_ops.
Also, if I understood correctly, it is possible to restrict a kfunc to some specific struct_ops, e.g. not to call this kfunc for the TCP CA struct_ops. So these checks should indeed not be needed, but I will double-check that with Geliang.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts (NGI0)
maintainerPATCH v2 5/7 bpf: Acquire and release mptcp socket
In reply to Matthieu Baerts (NGI0)From: Geliang Tang <[email protected]>
The KF_TRUSTED_ARGS flag is used for bpf_iter_mptcp_subflow_new, it indicates that the all pointer arguments are valid. It's necessary to add a KF_ACQUIRE helper to get valid "msk".
This patch adds bpf_mptcp_sock_acquire() and bpf_mptcp_sock_release() helpers for this. Increase sk->sk_refcnt in _acquire() and decrease it in _release(). Register them with KF_ACQUIRE flag and KF_RELEASE flag.
--- net/mptcp/bpf.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
net/mptcp/bpf.c +19 -0
@@ -97,6 +97,23 @@ bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it) { } +__bpf_kfunc static struct +mptcp_sock *bpf_mptcp_sock_acquire (struct mptcp_sock *msk) +{ +struct sock *sk = (struct sock *)msk; + +if (sk &&refcount_inc_not_zero (&sk->sk_refcnt)) +return msk; +return NULL ; +} + +__bpf_kfunc static void bpf_mptcp_sock_release(struct mptcp_sock *msk) +{ +struct sock *sk = (struct sock *)msk; + +WARN_ON_ONCE (!sk || !refcount_dec_not_one (&sk->sk_refcnt)); +} +__bpf_kfunc_end_defs ();BTF_KFUNCS_START (bpf_mptcp_common_kfunc_ids)
@@ -104,6 +121,8 @@ BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx, 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, bpf_mptcp_sock_acquire, KF_ACQUIRE | KF_RET_NULL) +BTF_ID_FLAGS(func, bpf_mptcp_sock_release, KF_RELEASE)BTF_KFUNCS_END (bpf_mptcp_common_kfunc_ids) static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = {
Signature · 1 line
2.47.1
Martin KaFai Lau
reviewerRe: [PATCH bpf-next/net v2 5/7] bpf: Acquire and release mptcp socket
Quoted 5 lines · On 12/19/24 7:46 AM, Matthieu Baerts (NGI0) wrote:
From: Geliang Tang <[email protected]>
The
KF_TRUSTED_ARGSflag is used forbpf_iter_mptcp_subflow_new, it indicates that the all pointer arguments are valid. It's necessary to add aKF_ACQUIREhelper to get valid "msk".
This feels wrong. It forces an unnecessary acquire to get around the verifier. bpf_sockopt->sk should be in "trusted". From looking at patch 7, the issue should be the return value of bpf_skc_to_mptcp_sock().
Quoted 41 lines
This patch adds
bpf_mptcp_sock_acquire()andbpf_mptcp_sock_release()helpers for this. Increasesk->sk_refcntin_acquire()and decrease it in_release(). Register them withKF_ACQUIREflag andKF_RELEASEflag.Signed-off-by Geliang Tang <[email protected]>Reviewed-by Mat Martineau <[email protected]>Signed-off-by Matthieu Baerts (NGI0) <[email protected]>--- net/mptcp/bpf.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)net/mptcp/bpf.c +17
-0@@ -97,6 +97,23 @@ bpf_iter_mptcp_subflow_destroy(struct bpf_iter_mptcp_subflow *it) { } +__bpf_kfunc static struct +mptcp_sock *bpf_mptcp_sock_acquire (struct mptcp_sock *msk) +{ +struct sock *sk = (struct sock *)msk; + +if (sk &&refcount_inc_not_zero (&sk->sk_refcnt)) +return msk; +return NULL ; +} + +__bpf_kfunc static void bpf_mptcp_sock_release(struct mptcp_sock *msk) +{ +struct sock *sk = (struct sock *)msk; + +WARN_ON_ONCE (!sk || !refcount_dec_not_one (&sk->sk_refcnt)); +} +__bpf_kfunc_end_defs ();BTF_KFUNCS_START (bpf_mptcp_common_kfunc_ids)
net/mptcp/bpf.c BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx, KF_RET_NULL) · line 124
Quoted 4 lines
net/mptcp/bpf.c +1
-0@@ -104,6 +121,8 @@ BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx, 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, bpf_mptcp_sock_acquire,KF_ACQUIRE |KF_RET_NULL )
It should need a KF_TRUSTED_ARGS here but then it will hit the same problem described in the commit message.
Instead of changing the verifier to get this work, one option is to use the "struct sock *sk" instead of "struct mptcp-sock *msk" as the argument in the bpf_iter_mptcp_subflow_new, and do the bpf_mptcp_sock_from_sock check in the bpf_iter_mptcp_subflow_new.
Quoted 5 lines
net/mptcp/bpf.c +1
-0+BTF_ID_FLAGS(func, bpf_mptcp_sock_release, KF_RELEASE)BTF_KFUNCS_END (bpf_mptcp_common_kfunc_ids) static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = {
Matthieu Baerts (NGI0)
maintainerPATCH v2 6/7 selftests/bpf: More endpoints for endpoint_init
In reply to Matthieu Baerts (NGI0)From: Geliang Tang <[email protected]>
This patch changes ADDR_2 from "10.0.1.2" to "10.0.2.1", and adds two more IPv4 test addresses ADDR_3 - ADDR_4, four IPv6 addresses ADDR6_1 - ADDR6_4. Add a new helper address_init() to initialize all these addresses.
Add a new parameter "endpoints" for endpoint_init() to control how many endpoints are used for the tests. This makes it more flexible. Update the parameters of endpoint_init() in test_subflow().
--- tools/testing/selftests/bpf/prog_tests/mptcp.c | 56 +++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 6 deletions(-)
tools/testing/selftests/bpf/prog_tests/mptcp.c +50 -6
@@ -14,7 +14,13 @@#define NS_TEST "mptcp_ns"#define ADDR_1 "10.0.1.1" -#define ADDR_2 "10.0.1.2" +#define ADDR_2 "10.0.2.1" +#define ADDR_3 "10.0.3.1" +#define ADDR_4 "10.0.4.1" +#define ADDR6_1 "dead:beef:1::1" +#define ADDR6_2 "dead:beef:2::1" +#define ADDR6_3 "dead:beef:3::1" +#define ADDR6_4 "dead:beef:4::1"#define PORT_1 10001#ifndef IPPROTO_MPTCP
@@ -322,22 +328,60 @@ static void test_mptcpify(void)close (cgroup_fd); } -static int endpoint_init (char *flags) +static int address_init (void ) {SYS (fail,"ip -net %s link add veth1 type veth peer name veth2" ,NS_TEST );SYS (fail,"ip -net %s addr add %s/24 dev veth1" ,NS_TEST ,ADDR_1 ); +SYS (fail,"ip -net %s addr add %s/64 dev veth1 nodad" ,NS_TEST ,ADDR6_1 );SYS (fail,"ip -net %s link set dev veth1 up" ,NS_TEST );SYS (fail,"ip -net %s addr add %s/24 dev veth2" ,NS_TEST ,ADDR_2 ); +SYS (fail,"ip -net %s addr add %s/64 dev veth2 nodad" ,NS_TEST ,ADDR6_2 );SYS (fail,"ip -net %s link set dev veth2 up" ,NS_TEST ); -if (SYS_NOFAIL ("ip -net %s mptcp endpoint add %s %s" ,NS_TEST ,ADDR_2 , flags)) { + +SYS (fail,"ip -net %s link add veth3 type veth peer name veth4" ,NS_TEST ); +SYS (fail,"ip -net %s addr add %s/24 dev veth3" ,NS_TEST ,ADDR_3 ); +SYS (fail,"ip -net %s addr add %s/64 dev veth3 nodad" ,NS_TEST ,ADDR6_3 ); +SYS (fail,"ip -net %s link set dev veth3 up" ,NS_TEST ); +SYS (fail,"ip -net %s addr add %s/24 dev veth4" ,NS_TEST ,ADDR_4 ); +SYS (fail,"ip -net %s addr add %s/64 dev veth4 nodad" ,NS_TEST ,ADDR6_4 ); +SYS (fail,"ip -net %s link set dev veth4 up" ,NS_TEST ); + +return 0 ; +fail: +return -1 ; +} + +static int endpoint_add (char *addr,char *flags) +{ +return SYS_NOFAIL ("ip -net %s mptcp endpoint add %s %s" ,NS_TEST , addr, flags); +} + +static int endpoint_init (char *flags,u8 endpoints) +{ +int ret =-1 ; + +if (!endpoints || endpoints >4 ) + goto fail; + +if (address_init ()) + goto fail; + +if (SYS_NOFAIL ("ip -net %s mptcp limits set add_addr_accepted 4 subflows 4" , +NS_TEST )) {printf ("'ip mptcp' not supported, skip this test.\n" );test__skip (); goto fail; } -return 0 ; +if (endpoints >1 ) + ret =endpoint_add (ADDR_2 , flags); +if (endpoints >2 ) + ret = ret ?:endpoint_add (ADDR_3 , flags); +if (endpoints >3 ) + ret = ret ?:endpoint_add (ADDR_4 , flags); + fail: -return -1 ; +return ret; }static void wait_for_new_subflows (int fd)
@@ -423,7 +467,7 @@ static void test_subflow(void)if (!ASSERT_OK_PTR (netns,"netns_new: mptcp_subflow" )) goto skel_destroy; -if (endpoint_init ("subflow" ) <0 ) +if (endpoint_init ("subflow" ,2 ) <0 ) goto close_netns;run_subflow ();
Signature · 1 line
2.47.1
Matthieu Baerts (NGI0)
maintainerPATCH v2 7/7 selftests/bpf: Add mptcp_subflow bpf_iter subtest
In reply to Matthieu Baerts (NGI0)From: Geliang Tang <[email protected]>
This patch adds a "cgroup/getsockopt" program "iters_subflow" to test the newly added mptcp_subflow bpf_iter.
Export mptcp_subflow helpers bpf_iter_mptcp_subflow_new/_next/_destroy, bpf_mptcp_sock_acquire/_release and other helpers into bpf_experimental.h.
Use bpf_mptcp_sock_acquire() to acquire the msk, then use bpf_for_each() to walk the subflow list of this msk. From there, future MPTCP-specific kfunc can be called in the loop. Because they are not there yet, this test doesn't do anything very useful for the moment, but it focuses on validating the 'bpf_iter' part and the basic MPTCP kfunc. That's why it simply adds all subflow ids to local variable local_ids to make sure all subflows have been seen, then invoke mptcp_subflow_tcp_sock() in the loop to pick the subflow context.
Out of the loop, use bpf_mptcp_subflow_ctx() to get the subflow context of the picked subflow context and do some verifications. Finally, assign local_ids to global variable ids so that the application can obtain this value, and release the msk.
A related subtest called test_iters_subflow is added to load and verify the newly added mptcp_subflow type bpf_iter example in test_mptcp. The endpoint_init() helper is used to add 3 new subflow endpoints. Then one byte of message is sent to trigger the creation of new subflows. getsockopt() is invoked once the subflows have been created to trigger the "cgroup/getsockopt" test program "iters_subflow". skel->bss->ids is then checked to make sure it equals 10, the sum of each subflow ID: we should have 4 subflows: 1 + 2 + 3 + 4 = 10. If that's the case, the bpf_iter loop did the job as expected.
---
Notes:
- v2:
- explicit sk protocol checks are no longer needed, implicitly done
in bpf_skc_to_mptcp_sock().
- use bpf_skc_to_mptcp_sock() instead of bpf_mptcp_sk(), and
mptcp_subflow_tcp_sock() instead of bpf_mptcp_subflow_tcp_sock().
- bpf_mptcp_subflow_ctx() can now return NULL.
---
tools/testing/selftests/bpf/bpf_experimental.h | 8 +++
tools/testing/selftests/bpf/prog_tests/mptcp.c | 73 ++++++++++++++++++++++
tools/testing/selftests/bpf/progs/mptcp_bpf.h | 9 +++
.../testing/selftests/bpf/progs/mptcp_bpf_iters.c | 63 +++++++++++++++++++
4 files changed, 153 insertions(+)tools/testing/selftests/bpf/bpf_experimental.h +8 -0
@@ -575,6 +575,14 @@ 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/prog_tests/mptcp.c +73 -0
95 lines not on this page · raw message
tools/testing/selftests/bpf/progs/mptcp_bpf.h +9 -0
@@ -39,4 +39,13 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)return subflow->tcp_sock; } +/* ksym */ +extern struct mptcp_sock *bpf_mptcp_sock_acquire (struct mptcp_sock *msk) __ksym; +extern void bpf_mptcp_sock_release(struct mptcp_sock *msk) __ksym; + +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; +#endif
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.47.1
Martin KaFai Lau
reviewerRe: [PATCH bpf-next/net v2 7/7] selftests/bpf: Add mptcp_subflow bpf_iter subtest
Quoted 19 lines · On 12/19/24 7:46 AM, Matthieu Baerts (NGI0) wrote:
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c new file +19
-0+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_skc_to_mptcp_sock (sk); +if (!msk || msk->pm.server_side || !msk->pm.subflows) +return 1 ; + + msk =bpf_mptcp_sock_acquire (msk); +if (!msk) +return 1 ;
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c line 43
Quoted 10 lines
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c new file +10
-0+bpf_for_each (mptcp_subflow, subflow, msk) { +/* 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 kfunc works */ + ssk =mptcp_subflow_tcp_sock (subflow);
It is good to have test cases to exercise the new iter and kfunc. Thanks.
However, it seems not useful to show how it will be used in the future packet/subflow scheduler. iiuc, the core piece is in bpf_struct_ops. Without it, it is hard to comment. Any RFC patches ready to be posted?
Quoted 20 lines
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c new file +20
-0+ } + +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: +bpf_mptcp_sock_release (msk); +return 1 ; +}
Matthieu Baerts
maintainerRe: [PATCH bpf-next/net v2 7/7] selftests/bpf: Add mptcp_subflow bpf_iter subtest
Hi Geliang,
(only with the MPTCP list)
Quoted 33 lines · Martin KaFai Lau
Quoted 19 lines · On 12/19/24 7:46 AM, Matthieu Baerts (NGI0) wrote:
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c new file +19
-0+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_skc_to_mptcp_sock(sk); + if (!msk || msk->pm.server_side || !msk->pm.subflows) + return 1; + + msk = bpf_mptcp_sock_acquire(msk); + if (!msk) + return 1;tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c line 43
Quoted 10 lines
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c new file +10
-0+ bpf_for_each(mptcp_subflow, subflow, msk) { + /* 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 kfunc works */ + ssk = mptcp_subflow_tcp_sock(subflow);It is good to have test cases to exercise the new iter and kfunc. Thanks.
Quoted 3 lines
However, it seems not useful to show how it will be used in the future packet/subflow scheduler. iiuc, the core piece is in
bpf_struct_ops. Without it, it is hard to comment. Any RFC patches ready to be posted?
If it is easier, we can probably share a link to your git repo containing the WIP patches.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Matthieu Baerts
maintainerHello BPF maintainers and reviewers,
Quoted 9 lines · On 19/12/2024 16:46, Matthieu Baerts (NGI0) wrote:
Here is a series from Geliang, adding
mptcp_subflowbpf_itersupport.We are working on extending MPTCP with BPF, e.g. to control the path manager -- in charge of the creation, deletion, and announcements of subflows (paths) -- and the packet scheduler -- in charge of selecting which available path the next data will be sent to. These extensions need to iterate over the list of subflows attached to an MPTCP connection, and do some specific actions via some new kfunc that will be added later on.
(...)
Quoted 6 lines
Changes in v2:
- Patches 1-2: new ones.
- Patch 3: remove two kfunc, more restrictions. (Martin)
- Patch 4: addBUILD_BUG_ON(), more restrictions. (Martin)
- Patch 7: adaptations due to modifications in patches 1-4.
- Link to v1: https://lore.kernel.org/r/20241108-bpf-next-net-mptcp-bpf_iter-subflows-v1-0-cf16953035c1@kernel.org
The v2 of this series didn't get any reviews, probably because it has been sent the week before Xmas. Do you prefer if I resend it?
There is no hurry, I can also re-send it later if "now" is not a good time.
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Martin KaFai Lau
reviewerQuoted 19 lines · Matthieu Baerts
Quoted 9 lines
Here is a series from Geliang, adding
mptcp_subflowbpf_itersupport.We are working on extending MPTCP with BPF, e.g. to control the path manager -- in charge of the creation, deletion, and announcements of subflows (paths) -- and the packet scheduler -- in charge of selecting which available path the next data will be sent to. These extensions need to iterate over the list of subflows attached to an MPTCP connection, and do some specific actions via some new kfunc that will be added later on.
(...)
Quoted 6 lines
Changes in v2:
- Patches 1-2: new ones.
- Patch 3: remove two kfunc, more restrictions. (Martin)
- Patch 4: addBUILD_BUG_ON(), more restrictions. (Martin)
- Patch 7: adaptations due to modifications in patches 1-4.
- Link to v1: https://lore.kernel.org/r/20241108-bpf-next-net-mptcp-bpf_iter-subflows-v1-0-cf16953035c1@kernel.org
Quoted 2 lines
The v2 of this series didn't get any reviews, probably because it has been sent the week before Xmas. Do you prefer if I resend it?
No need to resend. will get to it.