From nobody Sun Dec 22 01:51:05 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A91E14AD0E for ; Mon, 9 Dec 2024 06:12:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733724759; cv=none; b=FHVAqH9TaxIty19I7y0Zosv0feILa7UsAhICDoqXczYhXwUGM1eosdb6lHb5R2dyv6l+0ifvttrXm5JlNAeGcLm31eZuqi/09Rb4Ctq7YBkCqKCb2q70S3D+wx2KabuQv+ARtDKrrXZ1u8zEJrqdDxQcvx3FgEHWL/b6WPqiSQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733724759; c=relaxed/simple; bh=64HULWyzXDYk7pnekHwq+De85X3l90hy6SwEMfu9TR0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WQOPU1vuWOEZxmI8+6MUWnl2beTzVD5Vi2FLnzF6I2hjvjK8rUQx2YvJOsA331/6bz9UNqtFJvTtwmHXiDq/HFzQnOYugP0yggSWiPokCRwo8C5WH5ZbbHWzsRJWL6IzcpagtkDnEe1i2cM+O5Rbd0GrMj9vGl/YizRxpG+OEbQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fIBABJO1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fIBABJO1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7810AC4CED1; Mon, 9 Dec 2024 06:12:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733724758; bh=64HULWyzXDYk7pnekHwq+De85X3l90hy6SwEMfu9TR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fIBABJO1Ol2GXd/ekgxKgEfpDpf4QF4SFS/JJRjdaRkJq/CPp6Vb929bRTjz0GfJt bySt+Te/T2zKBXJ+oTRpAqe+iV2CcHuq1gqVdbEJj38gBvyS9m8sa8iL2pQgsPhPwx NC64M5dlC+7Xyh6tAjbrnFgqnlfF01v9z55aPuurQbLDPxvsJ/MbEtGMveZXTqzy/C SlCglGHW2xj3hncl4sXZVMKH/8vN+cPGITYGXhFiGTZHZJvZyFvwDO9rPiIGpYqVo7 BbfgJGJuOU5NWcm4mO/MNiDkafeiuaBSs6Ppd+8Y+YoEJ4w3G/xkJaAL8IUt3EWGfU y2+yi6iJJFSew== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 1/5] mptcp: update bpf_mptcp_sock_from_subflow Date: Mon, 9 Dec 2024 14:12:26 +0800 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang The input parameter of bpf_mptcp_sock_from_subflow() is an msk subsocket of type IPPROTO_TCP. This patch extends it to accept an IPPROTO_MPTCP socket. With this change, the function name bpf_mptcp_sock_from_subflow is no longer appropriate, and it is renamed to bpf_mptcp_sock_from_sock. Signed-off-by: Geliang Tang --- include/net/mptcp.h | 4 ++-- net/core/filter.c | 2 +- net/mptcp/bpf.c | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 814b5f2e3ed5..94d5976f7b8d 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -322,9 +322,9 @@ static inline void mptcpv6_handle_mapped(struct sock *s= k, bool mapped) { } #endif =20 #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 =20 #if !IS_ENABLED(CONFIG_MPTCP) diff --git a/net/core/filter.c b/net/core/filter.c index fac245065b0a..9ac048f0c5dd 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -11836,7 +11836,7 @@ const struct bpf_func_proto bpf_skc_to_unix_sock_pr= oto =3D { 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); } =20 const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto =3D { diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index e9db856972cb..a0f49af85d57 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -188,8 +188,10 @@ static struct bpf_struct_ops bpf_mptcp_sched_ops =3D { }; #endif /* CONFIG_BPF_JIT */ =20 -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 =3D=3D IPPROTO_MPTCP) + return mptcp_sk(sk); if (sk && sk_fullsock(sk) && sk->sk_protocol =3D=3D IPPROTO_TCP && sk_is_= mptcp(sk)) return mptcp_sk(mptcp_subflow_ctx(sk)->conn); =20 --=20 2.45.2 From nobody Sun Dec 22 01:51:05 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC9D014AD0E for ; Mon, 9 Dec 2024 06:12:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733724760; cv=none; b=Js1md5/fiTKwvrG6lg4QkcavfqgKMmurDhaCu/yCSfWlfeGjOT4tWSjPTlVz7bHYAx8TMPIVO+UQcFfwYav0CWMv/+4LadxkF9ymlkNAfG49KoeI74E61q/2AX/74oaiL2GRlRDOAIzzNCtun9MXGc1VwUhIa++jczHL711sDaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733724760; c=relaxed/simple; bh=PDPl9RB/6dCKKUJchPq9UX9loOsc2k2o0XbbZp0CIYM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aCAHpS9K7kSlJpjbvuxXMeex4qnfem4HWW8F8xLpxsBqoCP9znpdTqLWKCfCNwTJ4Xr3UybpXSFNeJiCANrGlhqU68XkXgV/8iom3JlcGParuNGwNsXLQFgHipo4aI5y9/iIV9tN03cYU4+XyzcuqovC1y6miDiTV6kYvk1woV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YO2YMdv1; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YO2YMdv1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52AD0C4CED1; Mon, 9 Dec 2024 06:12:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733724760; bh=PDPl9RB/6dCKKUJchPq9UX9loOsc2k2o0XbbZp0CIYM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YO2YMdv1qvDyHHuXgqRnenuIjg3VezQiwIrMx7KxfVCxWTFMV6ETim8PMqSfvMXtM W0+XHXzcRpKV2mp9KQHeIgmzNusUT2hsuX0Cw/Gbx/zG+ZZr/CyHoSMPb8g5KOMOjF +ajVbyy0EzrOMYug9x3MlgUaXe+Ievyec8QunpQxFRoOjOZ4aGeORkOnEKJkbY3hFk BYuLT3jmf/XagGw6E3gr5PhqKLYrSf2pMklMkfm/enGgK4uwash0qIOsjA5VGq0tM/ 8+k0YgAqB22nE01zj/D676GokAXY0FekaJwLNqJdGSIhR0OuVVN0+2T0ePMnFpABvn rubOGX6RTkOsg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 2/5] bpf: Allow use of skc_to_mptcp_sock in cg_sockopt Date: Mon, 9 Dec 2024 14:12:27 +0800 Message-ID: <6ccf3f9179e820ac477702bae8a88bdb8f0cc93a.1733724383.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Currently, bpf_skc_to_mptcp_sock() helper is not allowed to be used in cg_sockopt. This patch adds this permission. Signed-off-by: Geliang Tang --- kernel/bpf/cgroup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index 46e5db65dbc8..1ca22e4842cf 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -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; --=20 2.45.2 From nobody Sun Dec 22 01:51:05 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E405F14AD0E for ; Mon, 9 Dec 2024 06:12:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733724763; cv=none; b=raztFwmoAnllpNo65p7t0c5lU01QykFWX+VAQdtlJM9NZFkjt6WvbBht7SzhaJMYIeRYbKNDAhKRpt/Z2i4GLm8WbaUHp6yOVK4TopcHp5Uyh2OCr2f22KssohW7DGXsJkWhE032oeljalfGIitOd7SNSPuiNXwBCD7PFaaebes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733724763; c=relaxed/simple; bh=EKbFdwz3S9dXyILkw0Qq2CPn84MHoOZ5plQHQU1nvrE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cSSXzdAhYYj6DQqrT1aGxghF/4nl2ODYs9cza9AW3X1quZofLJHiVVxXL3MR4FYOS244IMeoxpK5ViSt/1a6ruGtoiASMlo5EAlUIDykgZEZX4qWEx+XQ7rElepC7mwjuLLZsrgtP8j4PBYMBCbeFejhPJnivoYiqh6ERslZAW0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tMqvkmbz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tMqvkmbz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CA56C4CED1; Mon, 9 Dec 2024 06:12:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733724762; bh=EKbFdwz3S9dXyILkw0Qq2CPn84MHoOZ5plQHQU1nvrE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tMqvkmbzP9WoZhc6mPff++BV1sTCU8zBn5HZmj5Wr2Wty0N6Q/1HN182AN+W4BJlw WuurWsANGIoGHorZW7T75YctbV+H1JQX5xcKhkr/dv+OBti4kixsKOKHWvz/UwLUFD kdib6jWmG/BOkuGciCCItmkN4oljrdWnC5tZlcPfTjqaA2DuDhKdpZOIEfCgQaHv5N nvUQvWoupCz0YklumoJQ3YYT0jv5O9aBOja52qG4CPlLbNh0mu6/EeK7Wn5NsqZl2x PHiEvaWRiz0cT59JN/wUE1MMhru6l4DsCpQKLL1gWh8U06vKAj7KOcHAOHfZcgZBiz R9xYpQHg67WQA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 3/5] Squash to "bpf: Register mptcp common kfunc set" Date: Mon, 9 Dec 2024 14:12:28 +0800 Message-ID: <32f730106c25cd3b2f3d63b664efb144161952cd.1733724383.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Drop bpf_mptcp_sk() and bpf_mptcp_subflow_tcp_sock() definitions. Use bpf_skc_to_mptcp_sock() and mptcp_subflow_tcp_sock() in mptcp_subflow bpf_iter selftests instead. Address Martin's comments in v1: - add null-check for bpf_mptcp_subflow_ctx. - add KF_RET_NULL flags for bpf_mptcp_subflow_ctx. - register this kfunc set to BPF_PROG_TYPE_CGROUP_SOCKOPT only, not BPF_PROG_TYPE_UNSPEC. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index a0f49af85d57..f9ba0a46a9f1 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -218,21 +218,13 @@ struct bpf_iter_mptcp_subflow_kern { =20 __bpf_kfunc_start_defs(); =20 -__bpf_kfunc static struct mptcp_sock *bpf_mptcp_sk(struct sock *sk) -{ - return mptcp_sk(sk); -} - __bpf_kfunc static struct mptcp_subflow_context * bpf_mptcp_subflow_ctx(const struct sock *sk) { - return mptcp_subflow_ctx(sk); -} + if (!sk) + return NULL; =20 -__bpf_kfunc static struct sock * -bpf_mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow) -{ - return mptcp_subflow_tcp_sock(subflow); + return mptcp_subflow_ctx(sk); } =20 __bpf_kfunc static int @@ -301,9 +293,7 @@ __bpf_kfunc static bool bpf_mptcp_subflow_queues_empty(= struct sock *sk) __bpf_kfunc_end_defs(); =20 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_subflow_ctx, KF_RET_NULL) BTF_ID_FLAGS(func, bpf_iter_mptcp_subflow_new, KF_ITER_NEW | KF_TRUSTED_AR= GS) 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) @@ -337,7 +327,7 @@ static int __init bpf_mptcp_kfunc_init(void) int ret; =20 ret =3D register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set); - ret =3D ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_UNSPEC, + ret =3D ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_CGROUP_SOCKOPT, &bpf_mptcp_common_kfunc_set); ret =3D ret ?: register_btf_kfunc_id_set(BPF_PROG_TYPE_STRUCT_OPS, &bpf_mptcp_sched_kfunc_set); --=20 2.45.2 From nobody Sun Dec 22 01:51:05 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85C3A14AD0E for ; Mon, 9 Dec 2024 06:12:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733724764; cv=none; b=eyjJQAU8Le2lqpxtuJr2hnMaslWcukA86OYCeOPA2WlopSRmJo82wY3ih1uzjCsGtzkmD5zmGwVCMG2dnb9YdHJ34zDwpZ9GEvocq6AWmOnjtuCuiz0tFO9903/wrEqAqE7YzuL6wy3BIO8iEhyvpi5aiB5Yg4KkTvgOLLL6Gj8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733724764; c=relaxed/simple; bh=p9RhqciZ4Ay9md7Mm0qZn/e1aU0ZbpK8cJuhkq4chxs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kiI/8iijhmwKhgpMObn86rT2kGI6is2I8MGWtPzFTrPCT8nEodQ6VhjlfHZyUbugknk1tVlmFv/CmYYNT3ozsJmx5kyVECAP/dL8+9sJk2vH0uAF20K8apoSci0TV/xmVImOZMAGX3fS8UPrbuTH0JYjpsn0vwvN4JJt6MW6jY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tn2g2y2z; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tn2g2y2z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2017C4CEDF; Mon, 9 Dec 2024 06:12:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733724764; bh=p9RhqciZ4Ay9md7Mm0qZn/e1aU0ZbpK8cJuhkq4chxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tn2g2y2z/THqgwDOPgy9jJYEO3HNStqtga+CYzN8InphC83kBPu5sgnFVFOarzpy3 yRQUsE6klA2vZ+yOgF1/ycGrK6bm64TUYwRoSgghCFVxMUZVrXlWh51WO6HeudywZ+ xq8+UYf50vrZFsfgDHWCu3R17SQ2WvSQLZBFEB9KYHtE4RqRVqRRXiRqWTuUV1CSwG /Vu5/vI5P4mK57LyRmg3Xo2d2noW4/sISW/xWJ4eMEwrE6yeZaknAPpkZMFFEhqkXP Z/yeW43HuVPojUpTU0lWt0Sa2NVBPi4ibkaEyySRPmOkbg6gOJ39VOaoS7grYZo0Ag kh/ALC38GcPrA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 4/5] Squash to "bpf: Add mptcp_subflow bpf_iter" Date: Mon, 9 Dec 2024 14:12:29 +0800 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Add "sizeof" and "alignof" checks. Address Martin's comments in v1: - bpf_iter_mptcp_subflow_new returns -EINVAL when msk socket lock isn't held. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index f9ba0a46a9f1..566c3a32ab73 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -232,12 +232,20 @@ bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subf= low *it, struct mptcp_sock *msk) { struct bpf_iter_mptcp_subflow_kern *kit =3D (void *)it; + struct sock *sk =3D (struct sock *)msk; + + BUILD_BUG_ON(sizeof(struct bpf_iter_mptcp_subflow_kern) !=3D + sizeof(struct bpf_iter_mptcp_subflow)); + BUILD_BUG_ON(__alignof__(struct bpf_iter_mptcp_subflow_kern) !=3D + __alignof__(struct bpf_iter_mptcp_subflow)); =20 kit->msk =3D msk; if (!msk) return -EINVAL; =20 - msk_owned_by_me(msk); + if (!sock_owned_by_user_nocheck(sk) && + !spin_is_locked(&sk->sk_lock.slock)) + return -EINVAL; =20 kit->pos =3D &msk->conn_list; return 0; --=20 2.45.2 From nobody Sun Dec 22 01:51:05 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3763514AD0E for ; Mon, 9 Dec 2024 06:12:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733724766; cv=none; b=IGEtok96OkuGilBH2sh1RnpZOCbf8Ah6QpAEYr2F/17/KealiZxZBfGF4aj4Jmgy3ntyfj/oBZKJU0mzoE+uim35rNSnaTV2R9yDaL9bi9Ah46YzJSnov9Dpaa17KFLP7dtDmXugVl8v1Qg/o8f0n4mFEPMej6eFqHwPzUM2fYU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733724766; c=relaxed/simple; bh=SQV9nesIDZg3IV89hJf9DcNukyegI2kFcLBPZJpMrJg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EPq8VZV60P90zghi6HM7/oDDv+OD1hYdYUEfAV3inS0TnQ6oQeHTmLwo2u7ddVprOoDKyzSXuotF9FBpTSKP3unyCsrmmqjkLTG4wazLlbYZ8W2glqPIC8moH0WpUsxe9+VHjy3gTIK88n+EcwC9/NWCWUt57FGSHi2H+jXYFtQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U+m9xGy6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U+m9xGy6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0E33C4CED1; Mon, 9 Dec 2024 06:12:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733724765; bh=SQV9nesIDZg3IV89hJf9DcNukyegI2kFcLBPZJpMrJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U+m9xGy67WH1CvIDhmyB8LOZnshhNm6rNTnxCayFxwrnC0FXzlcrNSZPF53MlYSgB oDoA/HDV7V4m6gMrwtEbSiWTxI2OEoEL+3q5mh2NnrrbOlBCvrONKM7fRGjFghLpMq Fl3WozkpGI6js8oZkk7hEl1No7q8x+sxCRX7rMv6EVGcnDCYsfT148lDViE/4SoMY7 XvTneOyi5LEdDNmtle1LkxHUWHuo+o10dXq9B9hx+YBrqVqMrZVb3igYeOckmKZYP2 cqxMjQ+QhTvJpYjDzPjV7mJBmUav68sn9xiH7RkCKgVt9cpvOhsBvrwhd03F6EYamJ GYRwDoxX6cQ2w== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 5/5] Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest" Date: Mon, 9 Dec 2024 14:12:30 +0800 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang Use bpf_skc_to_mptcp_sock() and mptcp_subflow_tcp_sock() instead of bpf_mptcp_sk() and bpf_mptcp_subflow_tcp_sock(). IPPROTO_MPTCP is checked in bpf_skc_to_mptcp_sock(), no need to check it in BPF program. bpf_skc_to_mptcp_sock() and bpf_mptcp_subflow_ctx() may return NULL, need to check the return values. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/progs/mptcp_bpf.h | 1 - tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf.h b/tools/testing/= selftests/bpf/progs/mptcp_bpf.h index 3b20cfd44505..b1f6e1fb467e 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf.h +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf.h @@ -46,7 +46,6 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context= *subflow) extern struct mptcp_sock *bpf_mptcp_sock_acquire(struct mptcp_sock *msk) _= _ksym; extern void bpf_mptcp_sock_release(struct mptcp_sock *msk) __ksym; =20 -extern struct mptcp_sock *bpf_mptcp_sk(struct sock *sk) __ksym; extern struct mptcp_subflow_context * bpf_mptcp_subflow_ctx(const struct sock *sk) __ksym; extern struct sock * diff --git a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c b/tools/te= sting/selftests/bpf/progs/mptcp_bpf_iters.c index 1bede22a7e3d..fd5691a4073b 100644 --- a/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c +++ b/tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c @@ -21,12 +21,11 @@ int iters_subflow(struct bpf_sockopt *ctx) struct mptcp_sock *msk; int local_ids =3D 0; =20 - if (!sk || sk->protocol !=3D IPPROTO_MPTCP || - ctx->level !=3D SOL_TCP || ctx->optname !=3D TCP_IS_MPTCP) + if (ctx->level !=3D SOL_TCP || ctx->optname !=3D TCP_IS_MPTCP) return 1; =20 - msk =3D bpf_mptcp_sk((struct sock *)sk); - if (msk->pm.server_side || !msk->pm.subflows) + msk =3D bpf_skc_to_mptcp_sock(sk); + if (!msk || msk->pm.server_side || !msk->pm.subflows) return 1; =20 msk =3D bpf_mptcp_sock_acquire(msk); @@ -41,7 +40,7 @@ int iters_subflow(struct bpf_sockopt *ctx) local_ids +=3D subflow->subflow_id; =20 /* only to check the following kfunc works */ - ssk =3D bpf_mptcp_subflow_tcp_sock(subflow); + ssk =3D mptcp_subflow_tcp_sock(subflow); } =20 if (!ssk) @@ -53,7 +52,7 @@ int iters_subflow(struct bpf_sockopt *ctx) =20 /* only to check the following kfunc works */ subflow =3D bpf_mptcp_subflow_ctx(ssk); - if (subflow->token !=3D msk->token) + if (!subflow || subflow->token !=3D msk->token) goto out; =20 ids =3D local_ids; --=20 2.45.2