Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Geliang Tang <[email protected]>
  • Loading branch information
Geliang Tang committed Nov 21, 2024
1 parent 30f3a20 commit 948069b
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 23 deletions.
19 changes: 6 additions & 13 deletions net/mptcp/bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,8 @@ bpf_iter_mptcp_userspace_pm_addr_new(struct bpf_iter_mptcp_userspace_pm_addr *it
if (!msk)
return -EINVAL;

lockdep_assert_held(&msk->pm.lock);
if (!lockdep_is_held(&msk->pm.lock))
return -EINVAL;

kit->pos = &msk->pm.userspace_pm_local_addr_list;
return 0;
Expand Down Expand Up @@ -722,14 +723,6 @@ BTF_ID_FLAGS(func, bpf_mptcp_sock_release, KF_RELEASE)
BTF_ID_FLAGS(func, bpf_spin_lock_bh)
BTF_ID_FLAGS(func, bpf_spin_unlock_bh)
BTF_ID_FLAGS(func, bpf_ipv6_addr_v4mapped)
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,
};

BTF_KFUNCS_START(bpf_mptcp_struct_ops_kfunc_ids)
BTF_ID_FLAGS(func, bpf_ipv6_addr_set_v4mapped)
BTF_ID_FLAGS(func, bpf_list_add_tail_rcu)
BTF_ID_FLAGS(func, bpf_list_del_rcu)
Expand Down Expand Up @@ -759,11 +752,11 @@ BTF_ID_FLAGS(func, mptcp_wnd_end)
BTF_ID_FLAGS(func, tcp_stream_memory_free)
BTF_ID_FLAGS(func, bpf_mptcp_subflow_queues_empty)
BTF_ID_FLAGS(func, mptcp_pm_subflow_chk_stale, KF_SLEEPABLE)
BTF_KFUNCS_END(bpf_mptcp_struct_ops_kfunc_ids)
BTF_KFUNCS_END(bpf_mptcp_common_kfunc_ids)

static const struct btf_kfunc_id_set bpf_mptcp_struct_ops_kfunc_set = {
static const struct btf_kfunc_id_set bpf_mptcp_common_kfunc_set = {
.owner = THIS_MODULE,
.set = &bpf_mptcp_struct_ops_kfunc_ids,
.set = &bpf_mptcp_common_kfunc_ids,
};

static int __init bpf_mptcp_kfunc_init(void)
Expand All @@ -774,7 +767,7 @@ static int __init bpf_mptcp_kfunc_init(void)
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_struct_ops_kfunc_set);
&bpf_mptcp_common_kfunc_set);
#ifdef CONFIG_BPF_JIT
ret = ret ?: register_bpf_struct_ops(&bpf_mptcp_pm_ops, mptcp_pm_ops);
ret = ret ?: register_bpf_struct_ops(&bpf_mptcp_sched_ops, mptcp_sched_ops);
Expand Down
8 changes: 7 additions & 1 deletion tools/testing/selftests/bpf/progs/mptcp_bpf_first.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ void BPF_PROG(mptcp_sched_first_release, struct mptcp_sock *msk)

static int bpf_first_get_subflow(struct mptcp_sock *msk)
{
mptcp_subflow_set_scheduled(bpf_mptcp_subflow_ctx(msk->first), true);
struct mptcp_subflow_context *subflow;

subflow = bpf_mptcp_subflow_ctx(msk->first);
if (!subflow)
return -1;

mptcp_subflow_set_scheduled(subflow, true);
return 0;
}

Expand Down
5 changes: 2 additions & 3 deletions tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ int iters_address(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)
if (!msk || msk->pm.server_side)
return 1;

msk = bpf_mptcp_sock_acquire(msk);
Expand Down
2 changes: 2 additions & 0 deletions tools/testing/selftests/bpf/progs/mptcp_bpf_rr.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ static int bpf_rr_get_subflow(struct mptcp_sock *msk)
return -1;

next = bpf_mptcp_subflow_ctx(msk->first);
if (!next)
return -1;
if (!ptr->last_snd)
goto out;

Expand Down
20 changes: 16 additions & 4 deletions tools/testing/selftests/bpf/progs/mptcp_bpf_sockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ static int mptcp_setsockopt_mark(struct bpf_sock *sk, struct bpf_sockopt *ctx)

mark = *optval;

msk = bpf_mptcp_sock_acquire(bpf_mptcp_sk((struct sock *)sk));
msk = bpf_mptcp_sk((struct sock *)sk);
if (!msk)
return 1;
msk = bpf_mptcp_sock_acquire(msk);
if (!msk)
return 1;

Expand Down Expand Up @@ -54,7 +57,10 @@ static int mptcp_setsockopt_cc(struct bpf_sock *sk, struct bpf_sockopt *ctx)

__builtin_memcpy(cc, optval, TCP_CA_NAME_MAX);

msk = bpf_mptcp_sock_acquire(bpf_mptcp_sk((struct sock *)sk));
msk = bpf_mptcp_sk((struct sock *)sk);
if (!msk)
return 1;
msk = bpf_mptcp_sock_acquire(msk);
if (!msk)
return 1;

Expand Down Expand Up @@ -96,7 +102,10 @@ static int mptcp_getsockopt_mark(struct bpf_sock *sk, struct bpf_sockopt *ctx)
struct mptcp_sock *msk;
int i = 0;

msk = bpf_mptcp_sock_acquire(bpf_mptcp_sk((struct sock *)sk));
msk = bpf_mptcp_sk((struct sock *)sk);
if (!msk)
return 1;
msk = bpf_mptcp_sock_acquire(msk);
if (!msk)
return 1;

Expand All @@ -121,7 +130,10 @@ static int mptcp_getsockopt_cc(struct bpf_sock *sk, struct bpf_sockopt *ctx)
struct mptcp_sock *msk;
int i = 0;

msk = bpf_mptcp_sock_acquire(bpf_mptcp_sk((struct sock *)sk));
msk = bpf_mptcp_sk((struct sock *)sk);
if (!msk)
return 1;
msk = bpf_mptcp_sock_acquire(msk);
if (!msk)
return 1;

Expand Down
5 changes: 4 additions & 1 deletion tools/testing/selftests/bpf/progs/mptcp_bpf_stale.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ static int bpf_stale_get_subflow(struct mptcp_sock *msk)
int i;

if (!msk->pm.subflows) {
mptcp_subflow_set_scheduled(bpf_mptcp_subflow_ctx(msk->first), true);
subflow = bpf_mptcp_subflow_ctx(msk->first);
if (!subflow)
return -1;
mptcp_subflow_set_scheduled(subflow, true);
return 0;
}

Expand Down
7 changes: 6 additions & 1 deletion tools/testing/selftests/bpf/progs/mptcp_bpf_userspace_pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ static struct sock *mptcp_pm_find_ssk(struct mptcp_sock *msk,
struct sock *ssk;

ssk = bpf_mptcp_subflow_tcp_sock(subflow);
if (!ssk)
continue;

if (local->family != ssk->sk_family)
continue;
Expand Down Expand Up @@ -295,6 +297,7 @@ SEC("struct_ops")
int BPF_PROG(mptcp_pm_subflow_destroy, struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *local, struct mptcp_addr_info *remote)
{
struct mptcp_subflow_context *subflow;
struct sock *sk = (struct sock *)msk;
struct sock *ssk;
int err = 0;
Expand Down Expand Up @@ -330,7 +333,9 @@ int BPF_PROG(mptcp_pm_subflow_destroy, struct mptcp_sock *msk,
err = mptcp_userspace_pm_delete_local_addr(msk, local);
bpf_spin_unlock_bh(&msk->pm.lock);
mptcp_subflow_shutdown(sk, ssk, RCV_SHUTDOWN | SEND_SHUTDOWN);
mptcp_close_ssk(sk, ssk, bpf_mptcp_subflow_ctx(ssk));
subflow = bpf_mptcp_subflow_ctx(ssk);
if (subflow)
mptcp_close_ssk(sk, ssk, subflow);
BPF_MPTCP_INC_STATS(sk, MPTCP_MIB_RMSUBFLOW);

bpf_printk("mptcp_pm_subflow_destroy done");
Expand Down

0 comments on commit 948069b

Please sign in to comment.