From patchwork Thu Nov 21 09:36:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13881804 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 F12781CB32F for ; Thu, 21 Nov 2024 09:36: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=1732181803; cv=none; b=I7zGIMt6aXubIFPmF9PuqDPQQk+szbIlL0XVR+aaWfnW6BkCH0O/7IO/36twnhB20olyNXRg+lEv8lqIMG1F5+aAGGD+1B/7uPSGMCpbhuz1jal3Yr93y94PWmuMxdQ/0cZX+3m6WM7J8oZd4bbuYg4/ok9AiWoJ6cyziZZZY4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732181803; c=relaxed/simple; bh=UTSmcN6aOzBKWoWmfTdjkRmeqFIiQofXOe7xIuOSwbQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mdQ0KvhbrSbB1es5CQUd12o6uARYx2GkfmC8XjgyxIPBW1vPXNpQ49lKm5cVsaRCpPoryYwmw3bQhUj0PTumizllZwfvs+Ouj9Xw+/yRIzgJUbrpbVAaNkE7LLoWQ6Gr5jV0ycbyOW7G5PaYPZCDK40Rbco/rpM2cMQKFxqWvKc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KwINKoR0; 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="KwINKoR0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52379C4CED0; Thu, 21 Nov 2024 09:36:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732181802; bh=UTSmcN6aOzBKWoWmfTdjkRmeqFIiQofXOe7xIuOSwbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KwINKoR0dkHwc1AkvtmkK378Veqn8JHjA+sT0CxEMRM1SEK5eqduxtrHoacJYPDQV Hg6y6yDh4vwipoYiew6MOgkgm2UlWx6G93vBC8hr7Q1wFt5bvsT50M3ui8aBqg56bU Hd4CZOFRQV70n2tpsX85uvZlnUB9f9kS238O/8XSLz8f358iOy4eK7tRa62QXI0lhy bt/dtPMsgpefJ12eTX724HPh1GsjRR+h2qrEN9ME+afQrx9Hbcn7dSPzaDaDs3mpFq lzZPZqp74fut/eBsqD/UEy325BLV/5zhF0mRGtsCtQKY4aRNA+RBQ5Jq1QXVQCCvae mD3GWp/kCLRUQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 1/3] Squash to "bpf: Register mptcp common kfunc set" Date: Thu, 21 Nov 2024 17:36:33 +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 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(); __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); From patchwork Thu Nov 21 09:36:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13881805 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 9745C15C120 for ; Thu, 21 Nov 2024 09:36: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=1732181804; cv=none; b=qvXBsxPh6YaSlG4E+F2DzxJhoR4cq1emD/rGJCZA4l4FnSZEmbqXgv7rULWb8L3hkP/EIUXAZrq8r8pRQiZefIse5PgFQRzuA/dl9Hu1Ss6aizg7X073ZHi3jjZGSfSs4G8L0tgTqGwPZCXgDtE+LlHBX3PvSc6HMmBk5FzfyW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732181804; c=relaxed/simple; bh=qwvlwQape1B11fqsgjhKvLt2UCBXoWhWEAXaOPQ4TLM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kN/78rqfES7EIaZl7UXsOieXFWYIzXQKsQ8JlJlVRTDJ7bdN0n+nr3opwMpOIkrpEh4fWS2K2ew7vGxjH3gdubNCV7QcoAJ0EXsAC9tlYU+tpbOZaEVdKmcVH145kPhvIF1VGXkn7eOfVJHVtUaVCnp+QnHNbsdqHGGWTGh1BHg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Fodo0xzd; 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="Fodo0xzd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1457AC4CECC; Thu, 21 Nov 2024 09:36:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732181804; bh=qwvlwQape1B11fqsgjhKvLt2UCBXoWhWEAXaOPQ4TLM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fodo0xzd4Yc62OcrAmacENiabvuAoSbUsLP+b6Ngah/IzaBZvjLygH5gatgZ8GCN+ fvSvktyJadJ+jej/ggm4KqIcsblFHASkPNk6n7ta7qabSi52nV6FUWOSa4T89ugod5 +cVYuUkey/acpSSOXhs+BNOJWqqpb8Ej4N3E+vMMzELn/3Q8xLW0wgQO1JC/VWsBS5 cUEaHO+Si523RXNiaBu131AMV3C5OUBn5rYTcR2Mr0vjbsoBjPi770lkY47gxB3KJE PbWsmqHd00DVp31759YAAy0SYSSNJVDt2x7Xb/v5IvpWb555284smL7J2RzLScron8 nltJEBsVzoITg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 2/3] Squash to "bpf: Add mptcp_subflow bpf_iter" Date: Thu, 21 Nov 2024 17:36:34 +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 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 02038db59956..89a7a482368d 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -252,7 +252,10 @@ bpf_iter_mptcp_subflow_new(struct bpf_iter_mptcp_subflow *it, if (!msk) return -EINVAL; - msk_owned_by_me(msk); +#ifdef CONFIG_LOCKDEP + if (!lockdep_sock_is_held((const struct sock *)msk)) + return -EINVAL; +#endif kit->pos = &msk->conn_list; return 0; From patchwork Thu Nov 21 09:36:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13881806 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 53F651C4A08 for ; Thu, 21 Nov 2024 09:36: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=1732181806; cv=none; b=RJkV/VwD0xf84frUJDnhclhgEbM2pIdrLnhvFhnQEFJevT0ZcUy9HMSfW9dc0NFFy6RtseSbA2kPYluvfPoISO4ZbAHdxDQiEHbCBo5lkwcQKUBlYjiM6tmRQbb7BILxJqlJEpKL4/nSRKoJ0xYkI11qO29YK1pFVJRNInlUygw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732181806; c=relaxed/simple; bh=j86koVjy9m5DQMFl9dmS/aL9/28ANwXTgkirhcoNrU8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z723/QSwMeeJCEFC8jr9/H37Ocqz/jBXr56B+G2SWz8rDZ9yVA9Vv0NE/nFT8747PBx1U1Il7AD7eh0AZdgcwHXufQkBjH7Xfwytc5rcnhpPOK221m9dae8sdXyFmW+3sfU8L7zgvIbumgBO90aZS/z5Qq9XQS5uUUdVsvsw9/g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YeK05vyz; 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="YeK05vyz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7584C4CECC; Thu, 21 Nov 2024 09:36:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732181805; bh=j86koVjy9m5DQMFl9dmS/aL9/28ANwXTgkirhcoNrU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YeK05vyzQiUQb+Lz8NkOI0Z4G0wPUHJn0gs3JJhW27k6dU2MqT8ATzFa+xfNXqlVp CROOnwyiVM7I92dBXarwPLVt7xkpzT4zYvVeWetWpd8RE/Mr9bpAjaWARFSw5q4sqt q8Nd3XHQFs/gyRmMy8QsDSTfw+1w5CThtfNNcDPhVJKXLUN+SVwLPIyND0+///Nl5l fcY3+znXHlI/GOSx/Obls9+UWBvsLY5qbdftkJdnjVGuQ0H39hggtfIKlAHvCAPXZM /871GAv8C1E09B5lyId3Eo9C3WURLC1C2kpQjFjtz4X8wHols4GnlkHcBk06fhAZTJ 8yhJKf8DRCErg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 3/3] Squash to "selftests/bpf: Add mptcp_subflow bpf_iter subtest" Date: Thu, 21 Nov 2024 17:36:35 +0800 Message-ID: <1f670acc8c3b1606609b017a4953f4ddab3b1794.1732181420.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 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/testing/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 = 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;