From dcb329ce8a38742b9efc1930d51651eb6f989a29 Mon Sep 17 00:00:00 2001 From: Geliang Tang Date: Thu, 28 Nov 2024 11:13:08 +0800 Subject: [PATCH] Revert "fix" This reverts commit 404d384a3c4f77b5189142d5856e3b2d845621a0. --- include/uapi/linux/bpf.h | 6 +++--- net/mptcp/bpf.c | 21 +++---------------- tools/include/uapi/linux/bpf.h | 6 +++--- .../selftests/bpf/progs/mptcp_bpf_burst.c | 8 +++---- 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 0039d56cb287..0f105ff47ca0 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -5796,11 +5796,11 @@ union bpf_attr { * * **-ENOENT** if the bpf_local_storage cannot be found. * - * void *bpf_mptcp_ssk_cast(void *s, int type) + * void *bpf_mptcp_ssk_cast(void *sk) * Description - * Dynamically cast a *s* pointer to a *sock* pointer. + * Dynamically cast a *sk* pointer to a *sock* pointer. * Return - * *s* if casting is valid, or **NULL** otherwise. + * *sk* if casting is valid, or **NULL** otherwise. */ #define ___BPF_FUNC_MAPPER(FN, ctx...) \ FN(unspec, 0, ##ctx) \ diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 5e14e685fcaa..7ef85d1c78b0 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -281,25 +281,11 @@ static struct bpf_struct_ops bpf_mptcp_pm_ops = { /* MPTCP BPF packet scheduler */ -enum mptcp_cast_type { - MPTCP_TYPE_SUBSOCKET = 1, - MPTCP_TYPE_SUBFLOW, -}; - -BPF_CALL_2(bpf_mptcp_ssk_cast, void *, s, enum mptcp_cast_type, type) +BPF_CALL_1(bpf_mptcp_ssk_cast, struct sock *, sk) { BTF_TYPE_EMIT(struct sock); - - if (type == MPTCP_TYPE_SUBSOCKET) { - struct sock *sk = (struct sock *)s; - - if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk)) - return (unsigned long)sk; - } else if (type == MPTCP_TYPE_SUBFLOW) { - struct mptcp_subflow_context *subflow = (struct mptcp_subflow_context *)s; - - return (unsigned long)mptcp_subflow_tcp_sock(subflow); - } + if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk)) + return (unsigned long)sk; return (unsigned long)NULL; } @@ -308,7 +294,6 @@ static const struct bpf_func_proto bpf_mptcp_ssk_cast_proto = { .gpl_only = false, .ret_type = RET_PTR_TO_BTF_ID_OR_NULL, .arg1_type = ARG_ANYTHING, - .arg2_type = ARG_ANYTHING, .ret_btf_id = &btf_sock_ids[BTF_SOCK_TYPE_SOCK], }; diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 0039d56cb287..0f105ff47ca0 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -5796,11 +5796,11 @@ union bpf_attr { * * **-ENOENT** if the bpf_local_storage cannot be found. * - * void *bpf_mptcp_ssk_cast(void *s, int type) + * void *bpf_mptcp_ssk_cast(void *sk) * Description - * Dynamically cast a *s* pointer to a *sock* pointer. + * Dynamically cast a *sk* pointer to a *sock* pointer. * Return - * *s* if casting is valid, or **NULL** otherwise. + * *sk* if casting is valid, or **NULL** otherwise. */ #define ___BPF_FUNC_MAPPER(FN, ctx...) \ FN(unspec, 0, ##ctx) \ diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c b/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c index 3162f1c2ad68..9d826e35551d 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_burst.c @@ -82,8 +82,8 @@ int BPF_PROG(bpf_burst_get_send, struct mptcp_sock *msk) bpf_for_each(mptcp_subflow, subflow, msk) { bool backup = subflow->backup || subflow->request_bkup; - ssk = bpf_mptcp_ssk_cast(subflow, MPTCP_TYPE_SUBFLOW); - if (!ssk || !mptcp_subflow_active(subflow)) + ssk = mptcp_subflow_tcp_sock(subflow); + if (!mptcp_subflow_active(subflow)) continue; nr_active += !backup; @@ -108,7 +108,7 @@ int BPF_PROG(bpf_burst_get_send, struct mptcp_sock *msk) if (!nr_active) send_info[SSK_MODE_ACTIVE].ssk = send_info[SSK_MODE_BACKUP].ssk; - ssk = bpf_mptcp_ssk_cast(send_info[SSK_MODE_ACTIVE].ssk, MPTCP_TYPE_SUBSOCKET); + ssk = bpf_mptcp_ssk_cast(send_info[SSK_MODE_ACTIVE].ssk); if (!ssk || !sk_stream_memory_free(ssk)) return -1; @@ -139,7 +139,7 @@ int BPF_PROG(bpf_burst_get_retrans, struct mptcp_sock *msk) int min_stale_count = INT_MAX; bpf_for_each(mptcp_subflow, subflow, msk) { - struct sock *ssk = bpf_mptcp_ssk_cast(subflow, MPTCP_TYPE_SUBFLOW); + struct sock *ssk = bpf_mptcp_subflow_tcp_sock(subflow); if (!ssk || !mptcp_subflow_active(subflow)) continue;