Squash to "Add mptcp_subflow bpf_iter support"
Subsystems (6)
Geliang Tang
reviewerv2 cover Squash to "Add mptcp_subflow bpf_iter support"
From: Geliang Tang <[email protected]>
v2:
- Drop bpf_skc_to_mptcp_sock
- Check the owner before assigning the msk as Mat suggested.
- Use bpf_core_cast() in mptcp_subflow bpf_iter subtest instead of
using bpf_skc_to_mptcp_sock().
Address Martin's suggestions for v2.
Geliang Tang (5):
Revert "bpf: Extend bpf_skc_to_mptcp_sock to MPTCP sock" Revert "bpf: Allow use of skc_to_mptcp_sock in cg_sockopt" Squash to "bpf: Add mptcp_subflow bpf_iter"
Revert "bpf: Acquire and release mptcp socket" Squash to "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 | 43 +++++-------------- .../testing/selftests/bpf/bpf_experimental.h | 2 +- tools/testing/selftests/bpf/progs/mptcp_bpf.h | 3 -- .../selftests/bpf/progs/mptcp_bpf_iters.c | 8 +--- 7 files changed, 16 insertions(+), 48 deletions(-)
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v2 1/5 Revert "bpf: Extend bpf_skc_to_mptcp_sock to MPTCP sock"
From: Geliang Tang <[email protected]>
bpf_core_cast() can be used in mptcp_subflow bpf_iter selftests to get the msk, instead of using bpf_skc_to_mptcp_sock(). No need to add this patch anymore, revert it.
--- include/net/mptcp.h | 4 ++-- net/core/filter.c | 2 +- net/mptcp/bpf.c | 10 ++-------- 3 files changed, 5 insertions(+), 11 deletions(-)
include/net/mptcp.h +2 -2
@@ -323,9 +323,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_sock (struct sock *sk); +struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk);#else -static inline struct mptcp_sock *bpf_mptcp_sock_from_sock (struct sock *sk) {return NULL ; } +static inline struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *sk) {return NULL ; }#endif #if !IS_ENABLED (CONFIG_MPTCP )
net/core/filter.c +1 -1
@@ -11843,7 +11843,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_sock (sk); +return (unsigned long )bpf_mptcp_sock_from_subflow (sk); }const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto = {
net/mptcp/bpf.c +2 -8
@@ -195,15 +195,9 @@ static struct bpf_struct_ops bpf_mptcp_sched_ops = { };#endif /* CONFIG_BPF_JIT */ -struct mptcp_sock *bpf_mptcp_sock_from_sock (struct sock *sk) +struct mptcp_sock *bpf_mptcp_sock_from_subflow (struct sock *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)) +if (sk &&sk_fullsock (sk) && sk->sk_protocol ==IPPROTO_TCP &&sk_is_mptcp (sk))return mptcp_sk (mptcp_subflow_ctx (sk)->conn);return NULL ;
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v2 2/5 Revert "bpf: Allow use of skc_to_mptcp_sock in cg_sockopt"
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
bpf_core_cast() can be used in mptcp_subflow bpf_iter selftests to get the msk, instead of using bpf_skc_to_mptcp_sock(). No need to add this patch anymore, revert it.
This reverts commit d8d42f5a4542c2dc31e4e00c58508a821c6ab789.
--- kernel/bpf/cgroup.c | 2 -- 1 file changed, 2 deletions(-)
kernel/bpf/cgroup.c +0 -2
@@ -2358,8 +2358,6 @@ 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.43.0
Geliang Tang
reviewerPATCH v2 3/5 Squash to "bpf: Add mptcp_subflow bpf_iter"
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Drop the NULL check as Martin suggested.
Use the "struct sock *sk" instead of "struct mptcp-sock *msk" as the argument in the bpf_iter_mptcp_subflow_new as Martin suggested.
Use msk_owned_by_me().
v2:
- check the owner before assigning the msk as Mat suggested.
--- net/mptcp/bpf.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
net/mptcp/bpf.c +8 -6
@@ -235,24 +235,26 @@ bpf_mptcp_subflow_ctx(const struct sock *sk) __bpf_kfunc static intbpf_iter_mptcp_subflow_new (struct bpf_iter_mptcp_subflow *it, -struct mptcp_sock *msk) +struct sock *sk) {struct bpf_iter_mptcp_subflow_kern *kit = (void *)it; -struct sock *sk = (struct sock *)msk; +struct mptcp_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) +if (unlikely (!sk || !sk_fullsock (sk)))return -EINVAL ; -if (!sock_owned_by_user_nocheck (sk) && - !spin_is_locked (&sk->sk_lock.slock)) +if (sk->sk_protocol !=IPPROTO_MPTCP )return -EINVAL ; + msk =mptcp_sk (sk); +msk_owned_by_me (msk); + + kit->msk = msk; kit->pos = &msk->conn_list;return 0 ; }
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH v2 4/5 Revert "bpf: Acquire and release mptcp socket"
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Drop this patch as Martin suggested.
--- net/mptcp/bpf.c | 19 ------------------- 1 file changed, 19 deletions(-)
net/mptcp/bpf.c +0 -19
@@ -276,23 +276,6 @@ 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 struct mptcp_subflow_context *bpf_mptcp_subflow_ctx_by_pos (const struct mptcp_sched_data *data,unsigned int pos) {
@@ -313,8 +296,6 @@ 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.43.0
Geliang Tang
reviewerPATCH v2 5/5 Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest"
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Use bpf_core_cast() instead of bpf_skc_to_mptcp_sock(). Change the 2nd parameter type of bpf_for_each() as 'struct sock'. Drop bpf_mptcp_sock_acquire/release.
--- tools/testing/selftests/bpf/bpf_experimental.h | 2 +- tools/testing/selftests/bpf/progs/mptcp_bpf.h | 3 --- tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c | 8 ++------ 3 files changed, 3 insertions(+), 10 deletions(-)
tools/testing/selftests/bpf/bpf_experimental.h +1 -1
@@ -577,7 +577,7 @@ 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; + 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
tools/testing/selftests/bpf/progs/mptcp_bpf.h +0 -3
@@ -43,9 +43,6 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) }/* 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 *
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +2 -6
@@ -24,14 +24,11 @@ int iters_subflow(struct bpf_sockopt *ctx)if (ctx->level !=SOL_TCP || ctx->optname !=TCP_IS_MPTCP )return 1 ; - msk =bpf_skc_to_mptcp_sock (sk); + msk = bpf_core_cast(sk, struct mptcp_sock);if (!msk || msk->pm.server_side || !msk->pm.subflows)return 1 ; - msk =bpf_mptcp_sock_acquire (msk); -if (!msk) -return 1 ; -bpf_for_each (mptcp_subflow, subflow, msk) { +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.
@@ -58,6 +55,5 @@ int iters_subflow(struct bpf_sockopt *ctx) ids = local_ids; out: -bpf_mptcp_sock_release (msk);return 1 ; }
Signature · 1 line
2.43.0
Mat Martineau
maintainerRe: [PATCH mptcp-next v2 5/5] Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest"
Quoted 45 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Use
bpf_core_cast()instead ofbpf_skc_to_mptcp_sock(). Change the 2nd parameter type ofbpf_for_each()as 'struct sock'. Drop bpf_mptcp_sock_acquire/release.Signed-off-by Geliang Tang <[email protected]>---
tools/testing/selftests/bpf/bpf_experimental.h | 2 +- tools/testing/selftests/bpf/progs/mptcp_bpf.h | 3 --- tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c | 8 ++------ 3 files changed, 3 insertions(+), 10 deletions(-)tools/testing/selftests/bpf/bpf_experimental.h +1
-1@@ -577,7 +577,7 @@ 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; + struct sock *sk) __weak __ksym;extern struct
mptcp_subflow_context*bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subflow *it)__weak__ksym; extern voidtools/testing/selftests/bpf/progs/mptcp_bpf.h +0
-3@@ -43,9 +43,6 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) }/* 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 *tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +0
-0
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c int iters_subflow(struct bpf_sockopt *ctx) · line 31
Quoted 9 lines
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +1
-2@@ -24,14 +24,11 @@ int iters_subflow(struct bpf_sockopt *ctx)if (ctx->level !=SOL_TCP || ctx->optname !=TCP_IS_MPTCP )return 1 ; - msk =bpf_skc_to_mptcp_sock (sk); + msk = bpf_core_cast(sk, struct mptcp_sock);if (!msk || msk->pm.server_side || !msk->pm.subflows)return 1 ; - msk =bpf_mptcp_sock_acquire (msk);
Hi Geliang -
Why is the locking removed? The squashed commit will still have a commit message referring to the acquire/release, so that isn't consistent with the modified code.
bpf_iter_mptcp_subflow_new() does have the msk_owned_by_me() check, but on a kernel without CONFIG_LOCKDEP it doesn't do anything.
- Mat
Quoted 19 lines
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +1
-3-if (!msk) -return 1 ; -bpf_for_each (mptcp_subflow, subflow, msk) { +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. @@ -58,6 +55,5 @@ int iters_subflow(struct bpf_sockopt *ctx) ids = local_ids;out:
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +0
-1-bpf_mptcp_sock_release (msk);return 1; }Signature · 1 line
2.43.0
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v2 5/5] Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest"
Hi Mat, Geliang,
Quoted 62 lines · Mat Martineau
Quoted 60 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Use
bpf_core_cast()instead ofbpf_skc_to_mptcp_sock(). Change the 2nd parameter type ofbpf_for_each()as 'struct sock'. Drop bpf_mptcp_sock_acquire/release.Signed-off-by Geliang Tang <[email protected]>---
tools/testing/selftests/bpf/bpf_experimental.h | 2 +- tools/testing/selftests/bpf/progs/mptcp_bpf.h | 3 ---tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c| 8 ++------3 files changed, 3 insertions(+), 10 deletions(-)tools/ renamed from tools/testing/selftests/bpf/bpf_experimental.h +0
-0
testing/selftests/bpf/bpf_experimental.h
index2ab3f0063c0f..6a96c56f0725100644tools/testing/selftests/bpf/bpf_experimental.h +1
-1@@ -577,7 +577,7 @@ 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; + struct sock *sk) __weak __ksym;extern struct
mptcp_subflow_context*bpf_iter_mptcp_subflow_next(struct bpf_iter_mptcp_subflow *it)__weak__ksym;
extern voidtools/ renamed from tools/testing/selftests/bpf/progs/mptcp_bpf.h +0
-0
testing/selftests/bpf/progs/mptcp_bpf.h
indexb1f6e1fb467e..ede9111ee597100644tools/testing/selftests/bpf/progs/mptcp_bpf.h +0
-3@@ -43,9 +43,6 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) }/* 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 *(quoted diff) renamed from tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +0
-0
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.cindexfd5691a4073b..2c0d11cb9864100644tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +1
-1@@ -24,14 +24,11 @@ int iters_subflow(struct bpf_sockopt *ctx) if (ctx->level != SOL_TCP || ctx->optname != TCP_IS_MPTCP) return 1; - msk = bpf_skc_to_mptcp_sock(sk); + msk = bpf_core_cast(sk, struct mptcp_sock); if (!msk || msk->pm.server_side || !msk->pm.subflows) return 1;
Quoted 7 lines
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c int iters_subflow(struct bpf_sockopt *ctx) · line 31
Quoted 1 line
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +0
-1- msk = bpf_mptcp_sock_acquire(msk);Hi Geliang -
Why is the locking removed? The squashed commit will still have a commit message referring to the acquire/release, so that isn't consistent with the modified code.
From what I understood from Martin's review [1], this mptcp_sock_acquire helper was a workaround only to please the verifier, but they were not needed
@Geliang: is this correct? (if yes, do not hesitate to add such info in the commit message removing such helpers because without the context, "Drop this patch as Martin suggested" is hard to understand :) )
1 https://lore.kernel.org/[email protected]
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Critical: 1 Call Trace(s) - Critical: Global Timeout ❌
- KVM Validation: debug: Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Critical: 1 Call Trace(s) - Critical: Global Timeout ❌
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/13095733327
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/36253da54a75
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=929774
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)
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/13113192213
Initiator: Matthieu Baerts (NGI0)
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/05f282a539fa
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=929774
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)