From nobody Thu Nov 21 18:23:00 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 2F637BA3D for ; Thu, 21 Nov 2024 07:10:25 +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=1732173025; cv=none; b=Oo5L5xq6fqZhBwUDwma0/tdPUPXmnOxD99I7XLe17NbsIOVHTjRihjwuoWN/vxutADQRpzJw+it5VS23TxDPfKpX2dMpyWAMf/TWN3lN/0SR1FmeXQLC20vKBvXHKNZptxhwjacxDCT0ct1+slIwDL8vJYhN28UyMGw2cYJ7ww4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732173025; c=relaxed/simple; bh=UTSmcN6aOzBKWoWmfTdjkRmeqFIiQofXOe7xIuOSwbQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kfM4FUXuWX4SMAlw/KepVyOKtxyNk0OKPfZjhOWtkg1AtltZxdnHZk0qeb/gMSZ96EaUkjJAldXJ60gKtCSmc75+D9Au++foA6qqWqrIs+5q/xbcdp0n7al7Ex6acnbBL+zcXuswziSdhgfr/jfKrNVZf8uXcLkQpSA7A8WIm7k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Op2nJckf; 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="Op2nJckf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAD3FC4CED0; Thu, 21 Nov 2024 07:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732173025; bh=UTSmcN6aOzBKWoWmfTdjkRmeqFIiQofXOe7xIuOSwbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Op2nJckfhGjNKiii6gbysuVE+O2T6f3KJQpWoEEhyxEu6nzlpeH1+YdTNU1gQougE ZBGZqzO59XFnUMzoSFsP1oJGg6AaYfagZTCkmwM2Pd97QSyriPEsyk3DfLsTjJ3Y+W jsWquH16+D1S4o1sNt9BoDnBUK9rrPycvjXjfSBnH2+i+31aPiECpsgd+dv+4bqTQD po5KZygvH7+eJdK6BC3YVOLhrLXHQveZlxW5V0GB/HsJ7prjlpsQD0Pr8wZaEsiCwI nO9onRXMXNMo9W+0KcG9Ezx3oNGAYEaPGa2kvCZM9hcVC3zpy6tbFLbCQZl/qUEDnZ 9/Jx8pEhICCWQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 1/3] Squash to "bpf: Register mptcp common kfunc set" Date: Thu, 21 Nov 2024 15:10:06 +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 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. Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index e9db856972cb..02038db59956 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -218,18 +218,27 @@ __bpf_kfunc_start_defs(); =20 __bpf_kfunc static struct mptcp_sock *bpf_mptcp_sk(struct sock *sk) { + if (!sk || sk->sk_protocol !=3D IPPROTO_MPTCP) + return NULL; + return mptcp_sk(sk); } =20 __bpf_kfunc static struct mptcp_subflow_context * bpf_mptcp_subflow_ctx(const struct sock *sk) { + if (!sk) + return NULL; + return mptcp_subflow_ctx(sk); } =20 __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); } =20 @@ -299,9 +308,9 @@ __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_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_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) @@ -335,7 +344,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 Thu Nov 21 18:23:00 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 20B7CBA3D for ; Thu, 21 Nov 2024 07:10:26 +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=1732173028; cv=none; b=hy9+xHQTE1L9dhJY95W3UOm7sbhAIsNDS/hzCCujXr6SQFzuQsT07edVZMsU0gTzpVkm5VRQ80cJn00CRjglEjaNSF7VDRfLwEuhyQC8GzemSqizWuseQc5j58DGQw0n9g+/reztQwOe82ICS36tg2VLm+2nmpeed/d/7T8P5y0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732173028; c=relaxed/simple; bh=jaojZ4XPGoRvBnyn40YqwV4zgput8Ga9ZsKyjBdpRbI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IT4dXHqtEKl3fOo6AZdNaWYOPsVskWRUJaRLraGBCyDJfAduZnbVR4khf3hfHu7WzsTuGqKa1Io3mjxmkZmnYgefATf+4ovNrwxKmi9/9oiCDP/7wcGwvYDYNbSR2mU8tHsJHVj1/v8xVQwMm7y0w5JcRYMqloU9KHLYkuizty0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bH8oV2we; 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="bH8oV2we" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D747C4CECC; Thu, 21 Nov 2024 07:10:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732173026; bh=jaojZ4XPGoRvBnyn40YqwV4zgput8Ga9ZsKyjBdpRbI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bH8oV2weCDAPMfirME2z6zK9nmdxVbVQ86Q23amiKcAb6GVxMkPHy3gYDs4RwZvIR uz5viQzIK6QEV2M2Klx2bEMLIaJFUlCkDZXevNzICmHEQryPGzcFsg4RrNPZKCdc04 iEgL3S62Xg6cGKkFuG1hYN5+j3tcG5ZYMmPQQKhe0pHr7/QlmwKGNlbtz+Schzf4Xa wPaW8rRHQYyl8JBnRZYVSTb+AxCJM78CNNlMnF/qV4JZs44tWlFyKCgmnaVqfxwWXd u/a39QFe6FONGDsBbBVVhGD1+c8ZeRE1Y/sEWO8pC/ojc6JQuCxeYexc5aCPIRb/pu 0aqk9jByB62ew== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 2/3] Squash to "bpf: Add mptcp_subflow bpf_iter" Date: Thu, 21 Nov 2024 15:10:07 +0800 Message-ID: <8e8c6d39d8de8ab2bb4cdd8965c1981a3920bc9e.1732172851.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 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 02038db59956..5aaeaf641f7f 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -252,7 +252,8 @@ bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflo= w *it, if (!msk) return -EINVAL; =20 - msk_owned_by_me(msk); + if (!lockdep_sock_is_held((const struct sock *)msk)) + return -EINVAL; =20 kit->pos =3D &msk->conn_list; return 0; --=20 2.45.2 From nobody Thu Nov 21 18:23:00 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 E8E99BA3D for ; Thu, 21 Nov 2024 07:10:28 +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=1732173029; cv=none; b=G8L3k/Uty11VlAP6gXp+GrId70oaT/SoL4xKn50vfzDIhtGYyQOOVvtTygBi9j29sq/Y/AGceMla3NVRpqIhvEEvRdVI6MfAo/WnsmZTs9SWVfFWcDSlvJKETcl0Z5tH3IhPvCRGRfJDL2JmVH1f/Q/fYK5tPixYHeWFWSlDV1c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732173029; c=relaxed/simple; bh=j86koVjy9m5DQMFl9dmS/aL9/28ANwXTgkirhcoNrU8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h33+H8nnPxVQNFKPVlbUvsAncaEbZpkYJlJ/aNMA5HEL67aPbIUXmBKROFAmYovrEzd/GOVTnukEyh6n1D0UNTSC47AaR7gOb87EEGCt933NPcwn0hjqS8Q1V+kH1M3HxRe/WgV6pas8/kdhyFSytYRaX5JE9ZcAIIDp9nXZ4OU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gGzHWiCM; 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="gGzHWiCM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46201C4CECE; Thu, 21 Nov 2024 07:10:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732173028; bh=j86koVjy9m5DQMFl9dmS/aL9/28ANwXTgkirhcoNrU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gGzHWiCMbIYuJYZ4bv+4aUON9zeB8ssJfQuNVb91szbzoEG+1mZ46AB4P3lyj0mtE +2q+UiyMmcGOCf6gZyahKdfPCMf00he9Spax7lM3d+xO/0gftiuzRxBfEIaEQ4Y/so hnDorQHJ/JFwnd2ZsbDpSxv4fr70ZT87IfGhbHe1YQkWc+czkvqckmMTn0C8JRSIId +t2GN/0/LR2B0c6sqs6P5QHfutJG+hzfs4fIiGAXENoSI9pa9hO4Wlwq3dktm9SOqS aSIXjpqoqPsQP5jr288G9zYXoscSDSmsEKlpMe0bmOtOTGzUZ2VikrCbE7LhLKl9tW I4E4Y/Xb+jjRA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 3/3] Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest" Date: Thu, 21 Nov 2024 15:10:08 +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 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. Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/progs/mptcp_bpf_iters.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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..5e475edf37b3 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) + if (!msk || msk->pm.server_side || !msk->pm.subflows) return 1; =20 msk =3D bpf_mptcp_sock_acquire(msk); @@ -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