Skip to contentSkip to conversation

Squash to "Add mptcp_subflow bpf_iter support"

PATCH Superseded Geliang Tang 3 participants 7 messages Nov 21, 2024 – Nov 22, 2024

Subsystems (5)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

cover Squash to "Add mptcp_subflow bpf_iter support"

From: Geliang Tang <[email protected]>

Address Martin's comments in v1.

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

 net/mptcp/bpf.c                               | 20 ++++++++++++++-----
 .../selftests/bpf/progs/mptcp_bpf_iters.c     |  7 +++----
 2 files changed, 18 insertions(+), 9 deletions(-)
Signature · 1 line
2.45.2
author reviewer
#1 lore raw

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

From: Geliang Tang <[email protected]>

Address Martin's comments in v1:

- check IPPROTO_MPTCP in bpf_mptcp_sk.
- add null-checks for the wrappers.
- add more BPF flags for the wrappers.
- register this kfunc set to BPF_PROG_TYPE_CGROUP_SOCKOPT only, not BPF_PROG_TYPE_UNSPEC.

---
 net/mptcp/bpf.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
net/mptcp/bpf.c +13 -4
index e9db856972cb..02038db59956 100644
@@ -218,18 +218,27 @@ __bpf_kfunc_start_defs();
 
 __bpf_kfunc static struct mptcp_sock *bpf_mptcp_sk(struct sock *sk)
 {
+	if (!sk || sk->sk_protocol != IPPROTO_MPTCP)
+		return NULL;
+
 	return mptcp_sk(sk);
 }
 
 __bpf_kfunc static struct mptcp_subflow_context *
 bpf_mptcp_subflow_ctx(const struct sock *sk)
 {
+	if (!sk)
+		return NULL;
+
 	return mptcp_subflow_ctx(sk);
 }
 
 __bpf_kfunc static struct sock *
 bpf_mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
 {
+	if (!subflow)
+		return NULL;
+
 	return mptcp_subflow_tcp_sock(subflow);
 }
 
@@ -299,9 +308,9 @@ __bpf_kfunc static bool bpf_mptcp_subflow_queues_empty(struct sock *sk)
 __bpf_kfunc_end_defs();
 
 BTF_KFUNCS_START(bpf_mptcp_common_kfunc_ids)
-BTF_ID_FLAGS(func, bpf_mptcp_sk)
-BTF_ID_FLAGS(func, bpf_mptcp_subflow_ctx)
-BTF_ID_FLAGS(func, bpf_mptcp_subflow_tcp_sock)
+BTF_ID_FLAGS(func, bpf_mptcp_sk, KF_TRUSTED_ARGS | KF_RET_NULL)
+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)
@@ -335,7 +344,7 @@ 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_UNSPEC,
+	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_sched_kfunc_set);
Signature · 1 line
2.45.2
author reviewer
#2 lore raw

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

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Address Martin's comments in v1:

- bpf_iter_mptcp_subflow_new returns -EINVAL when msk socket lock isn't held.

---
 net/mptcp/bpf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/mptcp/bpf.c +2 -1
index 02038db59956..5aaeaf641f7f 100644
@@ -252,7 +252,8 @@ bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it,
 	if (!msk)
 		return -EINVAL;
 
-	msk_owned_by_me(msk);
+	if (!lockdep_sock_is_held((const struct sock *)msk))
+		return -EINVAL;
 
 	kit->pos = &msk->conn_list;
 	return 0;
Signature · 1 line
2.45.2
#3 lore raw

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

kernel test robot noticed the following build errors:

Hi Geliang,

kernel test robot noticed the following build errors:

[auto build test ERROR on mptcp/export]
[cannot apply to mptcp/export-net linus/master v6.12 next-20241121] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Geliang-Tang/Squash-to-bpf-Register-mptcp-common-kfunc-set/20241121-155947
base:   https://github.com/multipath-tcp/mptcp_net-next.git export
patch link:    https://lore.kernel.org/r/8e8c6d39d8de8ab2bb4cdd8965c1981a3920bc9e.1732172851.git.tanggeliang%40kylinos.cn
patch subject: [PATCH mptcp-next 2/3] Squash to "bpf: Add mptcp_subflow bpf_iter"
config: m68k-atari_defconfig (https://download.01.org/0day-ci/archive/20241122/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241122/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

m68k-linux-ld: net/mptcp/bpf.o: in function `bpf_iter_mptcp_subflow_new':

>> bpf.c:(.text+0x96): undefined reference to `lockdep_is_held'
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author reviewer
#4 lore raw

PATCH 3/3 Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest"

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

IPPROTO_MPTCP is checked in bpf_mptcp_sk(), no need to check it in BPF program.

bpf_mptcp_sk() and bpf_mptcp_subflow_ctx() may return NULL, need to check the return values.

---
 tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +3 -4
index 1bede22a7e3d..5e475edf37b3 100644
@@ -21,12 +21,11 @@ int iters_subflow(struct bpf_sockopt *ctx)
 	struct mptcp_sock *msk;
 	int local_ids = 0;
 
-	if (!sk || sk->protocol != IPPROTO_MPTCP ||
-	    ctx->level != SOL_TCP || ctx->optname != TCP_IS_MPTCP)
+	if (ctx->level != SOL_TCP || ctx->optname != TCP_IS_MPTCP)
 		return 1;
 
 	msk = bpf_mptcp_sk((struct sock *)sk);
-	if (msk->pm.server_side || !msk->pm.subflows)
+	if (!msk || msk->pm.server_side || !msk->pm.subflows)
 		return 1;
 
 	msk = bpf_mptcp_sock_acquire(msk);
@@ -53,7 +52,7 @@ int iters_subflow(struct bpf_sockopt *ctx)
 
 	/* only to check the following kfunc works */
 	subflow = bpf_mptcp_subflow_ctx(ssk);
-	if (subflow->token != msk->token)
+	if (!subflow || subflow->token != msk->token)
 		goto out;
 
 	ids = local_ids;
Signature · 1 line
2.45.2
#5 lore raw
In reply to Geliang Tang

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/11948563035

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

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)

#6 lore raw
In reply to Geliang Tang

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

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

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

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)