From patchwork Fri Mar 21 01:44:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 14024755 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 D6661846C for ; Fri, 21 Mar 2025 01:45: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=1742521541; cv=none; b=rGcvbp6A5S3E3NOeP3e6aEiv12aZepJTxQ9T5fQC+xeVVUplVuSYkd/u2PL++AJBZezQF6ZlHPXBqGeCLkBeT/XvlrdkAMmlhPIH5WFpqPC03eR9CJZWbvW7kHvZztNO+DOUAzOlOQDrRs6Dsmlkj6W6fFW/fHb4ody2otAJyZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742521541; c=relaxed/simple; bh=x32P4JxwbIuxroNAM9CIAKb1pewVJqP1b7gNmR79csQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VbLRg4aJH/sk2bo6Go3/WS1eLeCna9XJQFr4rMy35b5AAtxmxMqx129GYZUjKipwLjGmhziIe7BJ1m4uKhJFrFybCOKoM8nq9Sf6pnUJL0a4NMIpdEDm8dTB6PGvQDiA9GHhYQsSJaaVk9UBE2blRVOJzVGeaRyT4DT/TlbF4zI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jwpca79d; 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="Jwpca79d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1BF47C4CEEA; Fri, 21 Mar 2025 01:45:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742521540; bh=x32P4JxwbIuxroNAM9CIAKb1pewVJqP1b7gNmR79csQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jwpca79ddECu2O4zvWbVrVQYkDaWKlo1C8Co9XmcEAUIPGYYEsqSjDmCuvYrb3RWk TLG7upNbG8lOigNhk2yRqppObZ7IDpnHTDN96sVpYAwZC8kERgdUdDuLZ+wP7pCjyq VwWRlB7y462ErcKAfiNJMTcE5+H99zpsUpsKo7n40aSi9NRRRwlFExjKZbsgr8Xth4 MrfOb5l3Bst1jLNDPWys4TxKQhL+xuU5nmOHWlYhZdqJOhZ/crdIELML+nBClrpA7Q 0g3Lj674pEqZ1HxBoyGxhBIltn3BWOzPHC0y5srV6EQGjxngiGCyVojZB+tRDfYnMi xY4IckQmtiZPg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 01/10] mptcp: pm: drop redundant MPTCP_MIB_ADDADDRDROP Date: Fri, 21 Mar 2025 09:44:55 +0800 Message-ID: <4923b521502f91e89ae6f4f4e4f1d1971ce8f669.1742521397.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 MPTCP_MIB_ADDADDRDROP MIB counter is incremented from both the in-kernel PM and the userspace PM. This can be called only once to reduce redundant code. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index ba7424582ebf..4895318b94cc 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -592,6 +592,7 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk); struct mptcp_sock *msk = mptcp_sk(subflow->conn); struct mptcp_pm_data *pm = &msk->pm; + int ret = 0; pr_debug("msk=%p remote_id=%d accept=%d\n", msk, addr->id, READ_ONCE(pm->accept_addr)); @@ -605,7 +606,7 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, mptcp_pm_announce_addr(msk, addr, true); mptcp_pm_add_addr_send_ack(msk); } else { - __MPTCP_INC_STATS(sock_net((struct sock *)msk), MPTCP_MIB_ADDADDRDROP); + ret = -EINVAL; } /* id0 should not have a different address */ } else if ((addr->id == 0 && !mptcp_pm_is_init_remote_addr(msk, addr)) || @@ -615,9 +616,12 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, } else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) { pm->remote = *addr; } else { - __MPTCP_INC_STATS(sock_net((struct sock *)msk), MPTCP_MIB_ADDADDRDROP); + ret = -EINVAL; } + if (ret) + __MPTCP_INC_STATS(sock_net((struct sock *)msk), MPTCP_MIB_ADDADDRDROP); + spin_unlock_bh(&pm->lock); } From patchwork Fri Mar 21 01:44:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 14024756 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 BCEA035947 for ; Fri, 21 Mar 2025 01:45: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=1742521543; cv=none; b=PyOy/MiM6Ri7YzBGWtfkRLWeTfGBpZB68PGBG3qWZJaqhUntzwCCOMNZ6PUmYLR6Mxc6hiBRcDz1smirrSkoYTmS4lyPQKuNnNXAoacq0xcG8V5rJB3odmVcPhfgUyba+aAxhnjscvYAeWXB1iseRwwF1QPWOu4KDz8n9amyX2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742521543; c=relaxed/simple; bh=BXGTvkft48Pz1dNbiMCp+7S4/NhhiPI1UvstLtFjoHA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p+kV1NFm7l+oN3aLEnejJCrfQtQN+i5L9/HLMDX2+nZ51pryCaioSdtYYDskkQW/m4OI2EdNeGmNY6LIKYW45iC1s+CZvf0+ZSMskZgOcYkdst6EUp1Wy+n8t0cJ4uXnw/+mvIb8G9vSUoCYmd7x198UYt0U/8ANBU6/IieHOR8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hbOyS0Wn; 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="hbOyS0Wn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8579C4CEDD; Fri, 21 Mar 2025 01:45:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742521542; bh=BXGTvkft48Pz1dNbiMCp+7S4/NhhiPI1UvstLtFjoHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hbOyS0WnS7cVkCHJIg2EnrsyfouNO3OWnOAJNx/BsOzW0atnmTjVMDp9uu/oIMrGX 8fJWZJx7xMfYpk+JauAPHCCRa1gBp8zrOrtCSOy9dLOfoZmYWJnAyWIhxgm5uzR/qU 5JhRVR+PcgjNqWwqtnthVKLKhevZNdi2AFXns5jP81tJJdq2fpHqYUl6Ua918THteL 3u0SEEN6FBCRI86NEl6cYjvwaovlo5rFP2u9GWFjnmtDgKfB5KIu2sW1vYWlenYgwN UrUN1EEb0iGi+zq+6Q+Z9uEYc709eY+dm/BktJbrdt9KSXMJ5L+fpY4StNh4fUpBnh cTh3tAqzQ+xrw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 02/10] Squash to "mptcp: pm: add get_local_id() interface" Date: Fri, 21 Mar 2025 09:44:56 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 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 Add /* required */ comment for get_local_id and get_priority. Signed-off-by: Geliang Tang --- include/net/mptcp.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 6a08ac862bbe..9f28ef550e10 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -118,6 +118,7 @@ struct mptcp_sched_ops { #define MPTCP_PM_BUF_MAX (MPTCP_PM_NAME_MAX * MPTCP_PM_MAX) struct mptcp_pm_ops { + /* required */ int (*get_local_id)(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *skc); bool (*get_priority)(struct mptcp_sock *msk, From patchwork Fri Mar 21 01:44:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 14024757 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 70E951C1ADB for ; Fri, 21 Mar 2025 01:45: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=1742521545; cv=none; b=JxzoCk7jipKuTGEvmPnAE90xglxK1v3XVXBE0NBMt0fUIsHs2HabX4EqEZhaUf9n8o5XU0GF8rBEjBB+FxG+flM481cO5OJNR2tq+DFP/3OZs0lYdDLMXqindkw9ExcMf6xrMGERNJbO9EmGfI5+mg6KAH3URJqUJW1oi5uY9ow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742521545; c=relaxed/simple; bh=NUNvE9uuJa+p/x7Z3o/sW1CiTbhp8dp/ZVyOjt+mWOs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g4HGlDX89gu5q4s5XAuslM17RXw1qJ53b7l4291lzfA+ZA5FLBlSIg9n/SXyjofPOULWAyKo0wRsoS7fMcRmIMEUTBVy43sQVV++hhL0hmZTBjxmpk0odMBaSEA9hJFojGRG5KFzEU8AyBI7VR8JCIzGg70XUkyk/uptr+FAPwQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cG32Jyfr; 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="cG32Jyfr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB948C4CEEA; Fri, 21 Mar 2025 01:45:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742521543; bh=NUNvE9uuJa+p/x7Z3o/sW1CiTbhp8dp/ZVyOjt+mWOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cG32JyfrxNBXEFbLRvmmbObDJiKPX9A8fIdZ/vuGZsqMM5VAezg8atqIt9KqrONL6 0b/wdzbhiJmpUs2MRrINwhq8HP/5AA3sunl4vZ2NeZkYve+BdkgUSAsnlGHcuKXMaw O6GjIJZFRkd+XfMk5DYffYJFvbDB4cE9etgwjEONwocerF2xJP6WevYDSxHlgMEEsV nn63og049uKc7yyQ2N2EtmtdbACDBc8DKA4mFwgfR1oHBNSLyWR0SySrjY7elDm5CQ KVfNJoEfEemeRzbzKD89kllfNy2KN/AXLWGzrF2r4rwG1c/BsgUxtRujw78YOIWkQU VmY3JOkeBjk3g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 03/10] mptcp: pm: add established() interface Date: Fri, 21 Mar 2025 09:44:57 +0800 Message-ID: <3f7cfd8a8e45e26e9afacf66f0adc61b9cd9356c.1742521397.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 This patch adds a .established interface for struct mptcp_pm_ops, and calls pm->ops->established in from mptcp_pm_worker(). Then get rid of the corresponding code from __mptcp_pm_kernel_worker(). Since mptcp_pm_addr_send_ack() is a sleepable kfunc, which is invoked by mptcp_pm_create_subflow_or_signal_addr(), .established() interface of BPF PM should be invoked by __bpf_prog_enter_sleepable(), which can't be invoked under a lock. This patch unlocks the pm lock before invoking this interface in mptcp_pm_worker(), while holding this lock in mptcp_pm_kernel_established(). Signed-off-by: Geliang Tang --- include/net/mptcp.h | 3 +++ net/mptcp/pm.c | 9 ++++++++- net/mptcp/pm_kernel.c | 9 ++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 9f28ef550e10..d7410f08399e 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -124,6 +124,9 @@ struct mptcp_pm_ops { bool (*get_priority)(struct mptcp_sock *msk, struct mptcp_addr_info *skc); + /* optional */ + void (*established)(struct mptcp_sock *msk); + char name[MPTCP_PM_NAME_MAX]; struct module *owner; struct list_head list; diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 4895318b94cc..a121c08b456e 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -516,7 +516,8 @@ void mptcp_pm_fully_established(struct mptcp_sock *msk, const struct sock *ssk) * be sure to serve this event only once. */ if (READ_ONCE(pm->work_pending) && - !(pm->status & BIT(MPTCP_PM_ALREADY_ESTABLISHED))) + !(pm->status & BIT(MPTCP_PM_ALREADY_ESTABLISHED)) && + pm->ops->established) mptcp_pm_schedule_work(msk, MPTCP_PM_ESTABLISHED); if ((pm->status & BIT(MPTCP_PM_ALREADY_ESTABLISHED)) == 0) @@ -964,6 +965,12 @@ void mptcp_pm_worker(struct mptcp_sock *msk) pm->status &= ~BIT(MPTCP_PM_RM_ADDR_RECEIVED); mptcp_pm_rm_addr_recv(msk); } + if (pm->status & BIT(MPTCP_PM_ESTABLISHED)) { + pm->status &= ~BIT(MPTCP_PM_ESTABLISHED); + spin_unlock_bh(&pm->lock); + pm->ops->established(msk); + spin_lock_bh(&pm->lock); + } __mptcp_pm_kernel_worker(msk); spin_unlock_bh(&msk->pm.lock); diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c index 7ec81d5195d4..6d30d5958f0e 100644 --- a/net/mptcp/pm_kernel.c +++ b/net/mptcp/pm_kernel.c @@ -367,9 +367,11 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) mptcp_pm_nl_check_work_pending(msk); } -static void mptcp_pm_nl_fully_established(struct mptcp_sock *msk) +static void mptcp_pm_kernel_established(struct mptcp_sock *msk) { + spin_lock_bh(&msk->pm.lock); mptcp_pm_create_subflow_or_signal_addr(msk); + spin_unlock_bh(&msk->pm.lock); } static void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk) @@ -1348,10 +1350,6 @@ void __mptcp_pm_kernel_worker(struct mptcp_sock *msk) pm->status &= ~BIT(MPTCP_PM_ADD_ADDR_RECEIVED); mptcp_pm_nl_add_addr_received(msk); } - if (pm->status & BIT(MPTCP_PM_ESTABLISHED)) { - pm->status &= ~BIT(MPTCP_PM_ESTABLISHED); - mptcp_pm_nl_fully_established(msk); - } if (pm->status & BIT(MPTCP_PM_SUBFLOW_ESTABLISHED)) { pm->status &= ~BIT(MPTCP_PM_SUBFLOW_ESTABLISHED); mptcp_pm_nl_subflow_established(msk); @@ -1422,6 +1420,7 @@ static void mptcp_pm_kernel_init(struct mptcp_sock *msk) struct mptcp_pm_ops mptcp_pm_kernel = { .get_local_id = mptcp_pm_kernel_get_local_id, .get_priority = mptcp_pm_kernel_get_priority, + .established = mptcp_pm_kernel_established, .init = mptcp_pm_kernel_init, .name = "kernel", .owner = THIS_MODULE, From patchwork Fri Mar 21 01:44:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 14024758 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 4812635947 for ; Fri, 21 Mar 2025 01:45: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=1742521547; cv=none; b=JPzqtR4MpaGTTpSUq6ESbPBnv47Fnx8r7p/460bVUODBBr4YM4Wk+OaUCBK0f+Ta5lBwqvBAPoQFof40aWmbAhbfaHWyzbMncL+EC0PvsL7++lOGRezliP46FnrWBCcsObBw4TgFQ8OT4xtRs+kFoeZFPHzpEKyx6aH5xUDofTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742521547; c=relaxed/simple; bh=k2LQi3qslZfqk/987X++r2Wkmn13DH0FkjjSS5+sQEQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qfmzfZEX9o7+CcuH17QW6uMT2bQnHtmcmdX2796E1Xx4vKCL9LqpK6fGZrPd8s8p7axNIqnOn7ROwepFtEadWFUGw2bXqIGOv66/e/AQ6rOoOFO2RheDEM4oCu+q9Wmkl29SR6ZbQTvpTT29R6d/GYacBPF8BjWsVka5/baOYRA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kjjaGZRq; 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="kjjaGZRq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C26BC4CEDD; Fri, 21 Mar 2025 01:45:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742521545; bh=k2LQi3qslZfqk/987X++r2Wkmn13DH0FkjjSS5+sQEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kjjaGZRqFIa5DXWLhLksIcRLOoYSjfS2edxXcsT98GxerK28KBFX8yd3J5z/VnHv4 pQ1T4cCayNmUXV6USjegT4CnPJkq4cSzjo1imoIFj8uB6SIAsul62pv5tGBFgrBvRf 3WNZzOecJyZnPlc5/5pQlVWXEIFbzHVzejrNUMrDPiSD0dTCMURXloanA4Wv/hDguu 5dxcCTMT9fRo94Sb93fFgthLQ+u2nJaOUNcabFn9zGG91ov3YMkSqhxl5KJ1L9Tefy m3GxjhXhrjItFEnFsxsLYyuK3SA/mq/38VQDQiCGQmbniYHStQh5IfNlU/2mi41Lh7 zekKwK5bn2Q3Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 04/10] mptcp: pm: add subflow_established() interface Date: Fri, 21 Mar 2025 09:44:58 +0800 Message-ID: <0851219a7e333127fc1dbd927c5a8bd5f11efcc5.1742521397.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 This patch adds a .subflow_established interface for struct mptcp_pm_ops, and calls pm->ops->subflow_established in from mptcp_pm_worker(). Then get rid of the corresponding code from __mptcp_pm_kernel_worker(). Since mptcp_pm_addr_send_ack() is a sleepable kfunc, which is invoked by mptcp_pm_create_subflow_or_signal_addr(), .subflow_established() interface of BPF PM should be invoked by __bpf_prog_enter_sleepable(), which can't be invoked under a lock. This patch unlocks the pm lock before invoking this interface in mptcp_pm_worker(), while holding this lock in mptcp_pm_kernel_subflow_established(). Signed-off-by: Geliang Tang --- include/net/mptcp.h | 1 + net/mptcp/pm.c | 13 +++++++++++-- net/mptcp/pm_kernel.c | 9 ++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index d7410f08399e..4ac936e4ce0d 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -126,6 +126,7 @@ struct mptcp_pm_ops { /* optional */ void (*established)(struct mptcp_sock *msk); + void (*subflow_established)(struct mptcp_sock *msk); char name[MPTCP_PM_NAME_MAX]; struct module *owner; diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index a121c08b456e..35361d525101 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -544,7 +544,7 @@ void mptcp_pm_subflow_established(struct mptcp_sock *msk) pr_debug("msk=%p\n", msk); - if (!READ_ONCE(pm->work_pending)) + if (!READ_ONCE(pm->work_pending) || !pm->ops->subflow_established) return; spin_lock_bh(&pm->lock); @@ -571,6 +571,9 @@ void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, return; } + if (!pm->ops->subflow_established) + return; + if (!READ_ONCE(pm->work_pending) && !update_subflows) return; @@ -633,7 +636,7 @@ void mptcp_pm_add_addr_echoed(struct mptcp_sock *msk, pr_debug("msk=%p\n", msk); - if (!READ_ONCE(pm->work_pending)) + if (!READ_ONCE(pm->work_pending) || !pm->ops->subflow_established) return; spin_lock_bh(&pm->lock); @@ -971,6 +974,12 @@ void mptcp_pm_worker(struct mptcp_sock *msk) pm->ops->established(msk); spin_lock_bh(&pm->lock); } + if (pm->status & BIT(MPTCP_PM_SUBFLOW_ESTABLISHED)) { + pm->status &= ~BIT(MPTCP_PM_SUBFLOW_ESTABLISHED); + spin_unlock_bh(&pm->lock); + pm->ops->subflow_established(msk); + spin_lock_bh(&pm->lock); + } __mptcp_pm_kernel_worker(msk); spin_unlock_bh(&msk->pm.lock); diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c index 6d30d5958f0e..bd17b1afee2c 100644 --- a/net/mptcp/pm_kernel.c +++ b/net/mptcp/pm_kernel.c @@ -374,9 +374,11 @@ static void mptcp_pm_kernel_established(struct mptcp_sock *msk) spin_unlock_bh(&msk->pm.lock); } -static void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk) +static void mptcp_pm_kernel_subflow_established(struct mptcp_sock *msk) { + spin_lock_bh(&msk->pm.lock); mptcp_pm_create_subflow_or_signal_addr(msk); + spin_unlock_bh(&msk->pm.lock); } /* Fill all the local addresses into the array addrs[], @@ -1350,10 +1352,6 @@ void __mptcp_pm_kernel_worker(struct mptcp_sock *msk) pm->status &= ~BIT(MPTCP_PM_ADD_ADDR_RECEIVED); mptcp_pm_nl_add_addr_received(msk); } - if (pm->status & BIT(MPTCP_PM_SUBFLOW_ESTABLISHED)) { - pm->status &= ~BIT(MPTCP_PM_SUBFLOW_ESTABLISHED); - mptcp_pm_nl_subflow_established(msk); - } } static int __net_init pm_nl_init_net(struct net *net) @@ -1421,6 +1419,7 @@ struct mptcp_pm_ops mptcp_pm_kernel = { .get_local_id = mptcp_pm_kernel_get_local_id, .get_priority = mptcp_pm_kernel_get_priority, .established = mptcp_pm_kernel_established, + .subflow_established = mptcp_pm_kernel_subflow_established, .init = mptcp_pm_kernel_init, .name = "kernel", .owner = THIS_MODULE, From patchwork Fri Mar 21 01:44:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 14024759 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 963E935947 for ; Fri, 21 Mar 2025 01:45:47 +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=1742521547; cv=none; b=B3fyD0/aKrWDpqK82pFKFj6M1SLAEEU6vJDD78vVJRmP/XKXw9cjPnEsy+3C9n265jZbRwAKJs5mUg8p0NijruVu1HjFLbm6LdiiORSGlbbroa3/6dROkZcVXO8VO4eBwWs6M7r3+nrBS9vCDjxd9/K7hVHHOqCLoNiq4DHx7Z0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742521547; c=relaxed/simple; bh=0/xIY8AEkeapaK9hzqEXQ4ZYS/gJJhSpQVmnkZuW4VE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W0JLdzRW0sZ7qZzWHmUy1nAVgJYg1ZXe17uO1FZIxvgiDkX0uNrpOQjyvwyb411zn27JBPDa9X1hJmhDz8JdcV6v5+Op5x/PCDHCaahS6viwMNjiMgPVipf6/5JKJDNYE/lDzLSvwDYC4N74giJPHrmYEMIVEchnvgAZ7hRiEoI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sCPQE/ZK; 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="sCPQE/ZK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7569DC4CEE7; Fri, 21 Mar 2025 01:45:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742521547; bh=0/xIY8AEkeapaK9hzqEXQ4ZYS/gJJhSpQVmnkZuW4VE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sCPQE/ZKjH3SWiwgylPe1njm8vA08kt7UaZp71HGd2RhfGe8LJhzuuLgvR8B7jcBt ibaUrPZBc93JIxHt8/ECxPBYlKGYwrEx5YSbdGiKpH0i47/HSWLt5Ufz2s3Cag6TYC GmKo2a5WRPUQH6FTT5E7nIymxUWxrlXw8v78lMzaoxm+ppWZZ8nf9XbFgSMfcz371W 71/HFnQT7w2ll3A6ZvAzPcKWZ87lYnuPIyhqo7nSbRPSaenKRTgwxuEzVkSXi8uqi0 sz/ZhJr15bEGMWWuE6sA+6HE8PwuO0FQ68wCzPxiBg2sfkI1t3N+WOdivpyokGy3vk /lXMoasgb+VRg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 05/10] mptcp: pm: add allow_new_subflow() interface Date: Fri, 21 Mar 2025 09:44:59 +0800 Message-ID: <4d9a9346c45d11da1d04c029970e7fd6f008b45b.1742521397.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 The helper mptcp_pm_is_userspace() is used to distinguish userspace PM operations from in-kernel PM in mptcp_pm_allow_new_subflow(). It seems reasonable to add a mandatory .allow_new_subflow interface for struct mptcp_pm_ops. Signed-off-by: Geliang Tang --- include/net/mptcp.h | 3 +++ net/mptcp/pm.c | 36 +++--------------------------------- net/mptcp/pm_kernel.c | 27 +++++++++++++++++++++++++++ net/mptcp/pm_userspace.c | 14 ++++++++++++++ 4 files changed, 47 insertions(+), 33 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 4ac936e4ce0d..e15d6b5680f6 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -128,6 +128,9 @@ struct mptcp_pm_ops { void (*established)(struct mptcp_sock *msk); void (*subflow_established)(struct mptcp_sock *msk); + /* required */ + bool (*allow_new_subflow)(struct mptcp_sock *msk); + char name[MPTCP_PM_NAME_MAX]; struct module *owner; struct list_head list; diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 35361d525101..0696d58c61ac 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -452,38 +452,7 @@ void mptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, int bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk) { - struct mptcp_pm_data *pm = &msk->pm; - unsigned int subflows_max; - int ret = 0; - - if (mptcp_pm_is_userspace(msk)) { - if (mptcp_userspace_pm_active(msk)) { - spin_lock_bh(&pm->lock); - pm->subflows++; - spin_unlock_bh(&pm->lock); - return true; - } - return false; - } - - subflows_max = mptcp_pm_get_subflows_max(msk); - - pr_debug("msk=%p subflows=%d max=%d allow=%d\n", msk, pm->subflows, - subflows_max, READ_ONCE(pm->accept_subflow)); - - /* try to avoid acquiring the lock below */ - if (!READ_ONCE(pm->accept_subflow)) - return false; - - spin_lock_bh(&pm->lock); - if (READ_ONCE(pm->accept_subflow)) { - ret = pm->subflows < subflows_max; - if (ret && ++pm->subflows == subflows_max) - WRITE_ONCE(pm->accept_subflow, false); - } - spin_unlock_bh(&pm->lock); - - return ret; + return msk->pm.ops->allow_new_subflow(msk); } /* return true if the new status bit is currently cleared, that is, this event @@ -1067,7 +1036,8 @@ struct mptcp_pm_ops *mptcp_pm_find(const char *name) int mptcp_pm_validate(struct mptcp_pm_ops *pm_ops) { - if (!pm_ops->get_local_id || !pm_ops->get_priority) { + if (!pm_ops->get_local_id || !pm_ops->get_priority || + !pm_ops->allow_new_subflow) { pr_err("%s does not implement required ops\n", pm_ops->name); return -EINVAL; } diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c index bd17b1afee2c..520c1c029607 100644 --- a/net/mptcp/pm_kernel.c +++ b/net/mptcp/pm_kernel.c @@ -1395,6 +1395,32 @@ static struct pernet_operations mptcp_pm_pernet_ops = { .size = sizeof(struct pm_nl_pernet), }; +static bool mptcp_pm_kernel_allow_new_subflow(struct mptcp_sock *msk) +{ + struct mptcp_pm_data *pm = &msk->pm; + unsigned int subflows_max; + int ret = 0; + + subflows_max = mptcp_pm_get_subflows_max(msk); + + pr_debug("msk=%p subflows=%d max=%d allow=%d\n", msk, pm->subflows, + subflows_max, READ_ONCE(pm->accept_subflow)); + + /* try to avoid acquiring the lock below */ + if (!READ_ONCE(pm->accept_subflow)) + return false; + + spin_lock_bh(&pm->lock); + if (READ_ONCE(pm->accept_subflow)) { + ret = pm->subflows < subflows_max; + if (ret && ++pm->subflows == subflows_max) + WRITE_ONCE(pm->accept_subflow, false); + } + spin_unlock_bh(&pm->lock); + + return ret; +} + static void mptcp_pm_kernel_init(struct mptcp_sock *msk) { bool subflows_allowed = !!mptcp_pm_get_subflows_max(msk); @@ -1420,6 +1446,7 @@ struct mptcp_pm_ops mptcp_pm_kernel = { .get_priority = mptcp_pm_kernel_get_priority, .established = mptcp_pm_kernel_established, .subflow_established = mptcp_pm_kernel_subflow_established, + .allow_new_subflow = mptcp_pm_kernel_allow_new_subflow, .init = mptcp_pm_kernel_init, .name = "kernel", .owner = THIS_MODULE, diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 7fc19b844384..3a9962ac77b2 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -683,6 +683,19 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, return ret; } +static bool mptcp_pm_userspace_allow_new_subflow(struct mptcp_sock *msk) +{ + struct mptcp_pm_data *pm = &msk->pm; + + if (mptcp_userspace_pm_active(msk)) { + spin_lock_bh(&pm->lock); + pm->subflows++; + spin_unlock_bh(&pm->lock); + return true; + } + return false; +} + static void mptcp_pm_userspace_release(struct mptcp_sock *msk) { mptcp_userspace_pm_free_local_addr_list(msk); @@ -691,6 +704,7 @@ static void mptcp_pm_userspace_release(struct mptcp_sock *msk) static struct mptcp_pm_ops mptcp_pm_userspace = { .get_local_id = mptcp_pm_userspace_get_local_id, .get_priority = mptcp_pm_userspace_get_priority, + .allow_new_subflow = mptcp_pm_userspace_allow_new_subflow, .release = mptcp_pm_userspace_release, .name = "userspace", .owner = THIS_MODULE, From patchwork Fri Mar 21 01:45:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 14024760 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 83E7535947 for ; Fri, 21 Mar 2025 01:45:49 +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=1742521549; cv=none; b=luqdGGyJlN8yzfz9bRnfpmLdMWeE1wjbxHbYoYYBjCCOpBEhfhWAwbQhNrMqOFSjCRCC2wbD/Ld4qFkvn86q6YqodbjlJQ6IrOlEJRrkoPRYeSMMmkjwV5dbUnXLHiLgwAeQ/dSrpFJOY5q9WjkVj5EB3y6gTXeYceu0J9VdGXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742521549; c=relaxed/simple; bh=unHztUMG5SqQqvsiAB7ubVoFGJBLs0TYAUvUYPZFR3M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z8IJSDhcUYeTHmkcBrnZejp71yMKwkTY+u/rTJtZcgR4vD78e2AMjHY9AWzquFYuVcIaGAj5Mnyy0yC1MCjoZlebYtNn6P7kzGo9Y7qdQSFqbwJ4WrC/bo1EgPTdNoNFbrpu8HkxKLqLqsesPaUhI4kKQ5XfgXikbCG6Em4/xiQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uCV2ZpAV; 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="uCV2ZpAV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D4E0C4CEDD; Fri, 21 Mar 2025 01:45:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742521549; bh=unHztUMG5SqQqvsiAB7ubVoFGJBLs0TYAUvUYPZFR3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uCV2ZpAV0wpFjvKMA0olMk0oBAh6erR2DtbaKTeNvt29FBk2g8I8HdWq3VqmowHWs rakOmgVV/ENMwYlTPr2p7XUdH/jogmUuiNnPvocCXPm2MFhkA24pK11cma22VV7CuO vt4+Ntm9PeB0vekizIqdhlV6/H+/DM1on6/tkMu1lDuYQOYDpUWXrktm/8H8PhWqjk p0AcYpoTavh8MpyJk7aCuZBdCtQMco7svR3wlb+SWOYhR7VQQstNZKFNrd6tYMJqmg dcS4s0snuJYafoxE2FbsPTFwZyQhsIz1CxpH7Ix64KHeWqZldef+ZDg/olp3yjYM4c iRRB1GTYjTjKg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 06/10] mptcp: pm: add accept_new_subflow() interface Date: Fri, 21 Mar 2025 09:45:00 +0800 Message-ID: <977e479a4c82993eb89fd1b2db4142aa88e2dc33.1742521397.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 The helper mptcp_pm_is_userspace() is used to distinguish userspace PM operations from in-kernel PM in mptcp_can_accept_new_subflow(). It seems reasonable to add a mandatory .accept_new_subflow interface for struct mptcp_pm_ops. Signed-off-by: Geliang Tang --- include/net/mptcp.h | 1 + net/mptcp/pm.c | 2 +- net/mptcp/pm_kernel.c | 6 ++++++ net/mptcp/pm_userspace.c | 6 ++++++ net/mptcp/subflow.c | 4 +--- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index e15d6b5680f6..de9838ea37c4 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -130,6 +130,7 @@ struct mptcp_pm_ops { /* required */ bool (*allow_new_subflow)(struct mptcp_sock *msk); + bool (*accept_new_subflow)(const struct mptcp_sock *msk); char name[MPTCP_PM_NAME_MAX]; struct module *owner; diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 0696d58c61ac..d2e72e36d80e 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -1037,7 +1037,7 @@ struct mptcp_pm_ops *mptcp_pm_find(const char *name) int mptcp_pm_validate(struct mptcp_pm_ops *pm_ops) { if (!pm_ops->get_local_id || !pm_ops->get_priority || - !pm_ops->allow_new_subflow) { + !pm_ops->allow_new_subflow || !pm_ops->accept_new_subflow) { pr_err("%s does not implement required ops\n", pm_ops->name); return -EINVAL; } diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c index 520c1c029607..c89a8524e70e 100644 --- a/net/mptcp/pm_kernel.c +++ b/net/mptcp/pm_kernel.c @@ -1421,6 +1421,11 @@ static bool mptcp_pm_kernel_allow_new_subflow(struct mptcp_sock *msk) return ret; } +static bool mptcp_pm_kernel_accept_new_subflow(const struct mptcp_sock *msk) +{ + return READ_ONCE(msk->pm.accept_subflow); +} + static void mptcp_pm_kernel_init(struct mptcp_sock *msk) { bool subflows_allowed = !!mptcp_pm_get_subflows_max(msk); @@ -1447,6 +1452,7 @@ struct mptcp_pm_ops mptcp_pm_kernel = { .established = mptcp_pm_kernel_established, .subflow_established = mptcp_pm_kernel_subflow_established, .allow_new_subflow = mptcp_pm_kernel_allow_new_subflow, + .accept_new_subflow = mptcp_pm_kernel_accept_new_subflow, .init = mptcp_pm_kernel_init, .name = "kernel", .owner = THIS_MODULE, diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 3a9962ac77b2..4cd9a84477c8 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -696,6 +696,11 @@ static bool mptcp_pm_userspace_allow_new_subflow(struct mptcp_sock *msk) return false; } +static bool mptcp_pm_userspace_accept_new_subflow(const struct mptcp_sock *msk) +{ + return mptcp_userspace_pm_active(msk); +} + static void mptcp_pm_userspace_release(struct mptcp_sock *msk) { mptcp_userspace_pm_free_local_addr_list(msk); @@ -705,6 +710,7 @@ static struct mptcp_pm_ops mptcp_pm_userspace = { .get_local_id = mptcp_pm_userspace_get_local_id, .get_priority = mptcp_pm_userspace_get_priority, .allow_new_subflow = mptcp_pm_userspace_allow_new_subflow, + .accept_new_subflow = mptcp_pm_userspace_accept_new_subflow, .release = mptcp_pm_userspace_release, .name = "userspace", .owner = THIS_MODULE, diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 409bd415ef1d..be79940da424 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -61,9 +61,7 @@ static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2, static bool mptcp_can_accept_new_subflow(const struct mptcp_sock *msk) { return mptcp_is_fully_established((void *)msk) && - ((mptcp_pm_is_userspace(msk) && - mptcp_userspace_pm_active(msk)) || - READ_ONCE(msk->pm.accept_subflow)); + msk->pm.ops->accept_new_subflow(msk); } /* validate received token and create truncated hmac and nonce for SYN-ACK */ From patchwork Fri Mar 21 01:45:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 14024761 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 7C184846C for ; Fri, 21 Mar 2025 01:45:51 +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=1742521551; cv=none; b=Z9jyteid9iVr6pI4YbxXwo62BTPICJtZoSf5humH/ehX5q0+PC6FQkWG5qB/KBEIPW7+as/38wS9fpjdBe2k2z7Rm5ltfcDxtVT59vSdCBznS0a5TxzSBKtIFB08e1Hbv1Yf3p9IG0O50wT4E9uIC8sho/Bnq96DSKMNympIca0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742521551; c=relaxed/simple; bh=2DBIuUqvmYi/fQb5PiPsCLnmpslQP1MsqlQvZ4gn+cQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AnsYj4qZOxwutO6/dZh0hNws3OL233p5X0jDtUqPrIecw9wh0PKoQ51QUA2/RNmtc2gREjnN26WfCtff4MBjCpEHG0YltMLpXQoPiHHUt8cN5iP60wqKXqWNVn1ilJXY6mMSN6CojyC9qXcGYIeNzrKn2PR/a6wSVv7i4lhIF3Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nV23F5LL; 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="nV23F5LL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAE62C4CEDD; Fri, 21 Mar 2025 01:45:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742521551; bh=2DBIuUqvmYi/fQb5PiPsCLnmpslQP1MsqlQvZ4gn+cQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nV23F5LLA14dQ6g98E9XX3AdVtlH1wfwStJpCRsif5LIiDt13x8lcKjxSgO8W7suu XNV7S/VdyUBZ6VQdXa0fPBHfxW1pJfkxczydgQWUMa2QKPwQdc0TIxGBR62kxGy0MY 7OHr3K03Fd1Ro0ysrC5S0bsu2oDH2Qw6iNWAxKt8zLs+FkELTolXHbVk6/A1JZd0mw Rx6OaL5beOr0Ttm2e7myUoJwyn87aUXZbPJMNlSt6iQj3sTKaz5tCClnkK29xhPeDh eAQHo6gXsiF09lDKPhrRoCdw/iROzi3TKH9G2WUCokTqG5W8H6g/X27GkhxOe8TfVP PBhAhM9yaHogQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 07/10] mptcp: pm: add add_addr_received() interface Date: Fri, 21 Mar 2025 09:45:01 +0800 Message-ID: <2d7bb2ff8960c244aee00ec314f23edd0f5577df.1742521397.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 This patch adds an optional .add_addr_received interface for struct mptcp_pm_ops and invokes it in mptcp_pm_add_addr_received(). A new helper mptcp_pm_add_addr_recv() is added to allow the MPTCP_PM_ADD_ADDR_RECEIVED worker can be invoke from the in-kernel PM. Signed-off-by: Geliang Tang --- include/net/mptcp.h | 4 ++++ net/mptcp/pm.c | 9 +++++++-- net/mptcp/pm_kernel.c | 13 +++++++++++++ net/mptcp/protocol.h | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index de9838ea37c4..37a84b4c661e 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -132,6 +132,10 @@ struct mptcp_pm_ops { bool (*allow_new_subflow)(struct mptcp_sock *msk); bool (*accept_new_subflow)(const struct mptcp_sock *msk); + /* optional */ + int (*add_addr_received)(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr); + char name[MPTCP_PM_NAME_MAX]; struct module *owner; struct list_head list; diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index d2e72e36d80e..28bd91819ec1 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -559,6 +559,11 @@ void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, spin_unlock_bh(&pm->lock); } +bool mptcp_pm_add_addr_recv(struct mptcp_sock *msk) +{ + return mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED); +} + void mptcp_pm_add_addr_received(const struct sock *ssk, const struct mptcp_addr_info *addr) { @@ -586,10 +591,10 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, (addr->id > 0 && !READ_ONCE(pm->accept_addr))) { mptcp_pm_announce_addr(msk, addr, true); mptcp_pm_add_addr_send_ack(msk); - } else if (mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR_RECEIVED)) { - pm->remote = *addr; } else { ret = -EINVAL; + if (pm->ops->add_addr_received) + ret = pm->ops->add_addr_received(msk, addr); } if (ret) diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c index c89a8524e70e..314e62da84c4 100644 --- a/net/mptcp/pm_kernel.c +++ b/net/mptcp/pm_kernel.c @@ -1426,6 +1426,18 @@ static bool mptcp_pm_kernel_accept_new_subflow(const struct mptcp_sock *msk) return READ_ONCE(msk->pm.accept_subflow); } +static int mptcp_pm_kernel_add_addr_received(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr) +{ + int ret = 0; + + if (mptcp_pm_add_addr_recv(msk)) + msk->pm.remote = *addr; + else + ret = -EINVAL; + return ret; +} + static void mptcp_pm_kernel_init(struct mptcp_sock *msk) { bool subflows_allowed = !!mptcp_pm_get_subflows_max(msk); @@ -1453,6 +1465,7 @@ struct mptcp_pm_ops mptcp_pm_kernel = { .subflow_established = mptcp_pm_kernel_subflow_established, .allow_new_subflow = mptcp_pm_kernel_allow_new_subflow, .accept_new_subflow = mptcp_pm_kernel_accept_new_subflow, + .add_addr_received = mptcp_pm_kernel_add_addr_received, .init = mptcp_pm_kernel_init, .name = "kernel", .owner = THIS_MODULE, diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 64aa091cb685..ea44f552b3a4 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1014,6 +1014,7 @@ void mptcp_pm_subflow_established(struct mptcp_sock *msk); bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk); void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, const struct mptcp_subflow_context *subflow); +bool mptcp_pm_add_addr_recv(struct mptcp_sock *msk); void mptcp_pm_add_addr_received(const struct sock *ssk, const struct mptcp_addr_info *addr); void mptcp_pm_add_addr_echoed(struct mptcp_sock *msk, From patchwork Fri Mar 21 01:45:02 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 14024762 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 417631E0DBA for ; Fri, 21 Mar 2025 01:45:52 +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=1742521553; cv=none; b=oeKP8gAzxdLVl+bj5M1cThbIgXwZNjA/DzjGjo6/j6GOvXQ+Y+3sZJl4NvOzm3jZGnRDGkWKy1HuS1mO6hld1N0Kguds8sKXn51GDLQvPU/Yptjnk9dldzwMylgDvxuP0iYI8i/zsYbeH8TAw+mke8RJrJ+886zmejKL5Q3X9Ao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742521553; c=relaxed/simple; bh=5rRwKWkLHRSyJohBGWl0tg9CYF8b+D9vnOwVUa2F+p4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RC8/u/Nn+/L12LFNjepItjxYDXRDle0L3MadONrdWKL1nKZCKu7g3ZzpcziEbLqJwkyvOAcghiGVUifd/W4zXyFJe1s0BpXxs9muPeQDZxw/CyShRmOJ+fQEYimj/W6PK1ejacnLpWw2sOhjd1oEI3hP+K2ZuhkPGsFObQ3MPME= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OU2MN+cS; 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="OU2MN+cS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC7BBC4CEEA; Fri, 21 Mar 2025 01:45:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742521552; bh=5rRwKWkLHRSyJohBGWl0tg9CYF8b+D9vnOwVUa2F+p4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OU2MN+cSe434WeK8kK6IKzBDLX52E+WdfDRGutgtuGhvYWmM8UDx9u0i+pycWBjOT //eonB2CxdJXp8mu9MLD5JJ3GfmZfEI/brPNTPtu40Z1wDvrUoq3LefE4C3ZhkadQz DVzC1lf31NNCZimfvOXY5xZ5XuRWYZ9i4b6CdeXwULJ8nrEFFiBBf1EHPhI3j0fbap xEl1qKKOk+MsAq9gN1B0XoyOx6oapX7g360q/UjwvdQxR6X5NULb8P4J8jlKCAm78X jYUM70sFULgZuF5oxjtSoFIDuhfmpcAyEus01zLkbsLoxkIqoXRsKYuIS1JmDyyfwk hNGBo8rfHAFQA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 08/10] mptcp: pm: add add_addr_echo() interface Date: Fri, 21 Mar 2025 09:45:02 +0800 Message-ID: <8ba7a6e89a3ce750b19b61fbbe52c6c8c4c9cff4.1742521397.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 The helper mptcp_pm_is_userspace() is used to distinguish userspace PM operations from in-kernel PM in mptcp_pm_add_addr_received(). It seems reasonable to add a mandatory .add_addr_echo interface for struct mptcp_pm_ops. Signed-off-by: Geliang Tang --- include/net/mptcp.h | 2 ++ net/mptcp/pm.c | 18 +++++------------- net/mptcp/pm_kernel.c | 9 +++++++++ net/mptcp/pm_userspace.c | 7 +++++++ net/mptcp/protocol.h | 2 ++ 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 37a84b4c661e..90fda6d1468c 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -131,6 +131,8 @@ struct mptcp_pm_ops { /* required */ bool (*allow_new_subflow)(struct mptcp_sock *msk); bool (*accept_new_subflow)(const struct mptcp_sock *msk); + bool (*add_addr_echo)(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr); /* optional */ int (*add_addr_received)(struct mptcp_sock *msk, diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 28bd91819ec1..7b34a59977cf 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -104,8 +104,8 @@ void mptcp_remote_address(const struct sock_common *skc, #endif } -static bool mptcp_pm_is_init_remote_addr(struct mptcp_sock *msk, - const struct mptcp_addr_info *remote) +bool mptcp_pm_is_init_remote_addr(struct mptcp_sock *msk, + const struct mptcp_addr_info *remote) { struct mptcp_addr_info mpc_remote; @@ -579,16 +579,7 @@ void mptcp_pm_add_addr_received(const struct sock *ssk, spin_lock_bh(&pm->lock); - if (mptcp_pm_is_userspace(msk)) { - if (mptcp_userspace_pm_active(msk)) { - mptcp_pm_announce_addr(msk, addr, true); - mptcp_pm_add_addr_send_ack(msk); - } else { - ret = -EINVAL; - } - /* id0 should not have a different address */ - } else if ((addr->id == 0 && !mptcp_pm_is_init_remote_addr(msk, addr)) || - (addr->id > 0 && !READ_ONCE(pm->accept_addr))) { + if (pm->ops->add_addr_echo(msk, addr)) { mptcp_pm_announce_addr(msk, addr, true); mptcp_pm_add_addr_send_ack(msk); } else { @@ -1042,7 +1033,8 @@ struct mptcp_pm_ops *mptcp_pm_find(const char *name) int mptcp_pm_validate(struct mptcp_pm_ops *pm_ops) { if (!pm_ops->get_local_id || !pm_ops->get_priority || - !pm_ops->allow_new_subflow || !pm_ops->accept_new_subflow) { + !pm_ops->allow_new_subflow || !pm_ops->accept_new_subflow || + !pm_ops->add_addr_echo) { pr_err("%s does not implement required ops\n", pm_ops->name); return -EINVAL; } diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c index 314e62da84c4..1a434abcf862 100644 --- a/net/mptcp/pm_kernel.c +++ b/net/mptcp/pm_kernel.c @@ -1426,6 +1426,14 @@ static bool mptcp_pm_kernel_accept_new_subflow(const struct mptcp_sock *msk) return READ_ONCE(msk->pm.accept_subflow); } +static bool mptcp_pm_kernel_add_addr_echo(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr) +{ + /* id0 should not have a different address */ + return (addr->id == 0 && !mptcp_pm_is_init_remote_addr(msk, addr)) || + (addr->id > 0 && !READ_ONCE(msk->pm.accept_addr)); +} + static int mptcp_pm_kernel_add_addr_received(struct mptcp_sock *msk, const struct mptcp_addr_info *addr) { @@ -1465,6 +1473,7 @@ struct mptcp_pm_ops mptcp_pm_kernel = { .subflow_established = mptcp_pm_kernel_subflow_established, .allow_new_subflow = mptcp_pm_kernel_allow_new_subflow, .accept_new_subflow = mptcp_pm_kernel_accept_new_subflow, + .add_addr_echo = mptcp_pm_kernel_add_addr_echo, .add_addr_received = mptcp_pm_kernel_add_addr_received, .init = mptcp_pm_kernel_init, .name = "kernel", diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 4cd9a84477c8..6016d5669b9b 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -701,6 +701,12 @@ static bool mptcp_pm_userspace_accept_new_subflow(const struct mptcp_sock *msk) return mptcp_userspace_pm_active(msk); } +static bool mptcp_pm_userspace_add_addr_echo(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr) +{ + return mptcp_userspace_pm_active(msk); +} + static void mptcp_pm_userspace_release(struct mptcp_sock *msk) { mptcp_userspace_pm_free_local_addr_list(msk); @@ -711,6 +717,7 @@ static struct mptcp_pm_ops mptcp_pm_userspace = { .get_priority = mptcp_pm_userspace_get_priority, .allow_new_subflow = mptcp_pm_userspace_allow_new_subflow, .accept_new_subflow = mptcp_pm_userspace_accept_new_subflow, + .add_addr_echo = mptcp_pm_userspace_add_addr_echo, .release = mptcp_pm_userspace_release, .name = "userspace", .owner = THIS_MODULE, diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index ea44f552b3a4..784e787cf667 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1014,6 +1014,8 @@ void mptcp_pm_subflow_established(struct mptcp_sock *msk); bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk); void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, const struct mptcp_subflow_context *subflow); +bool mptcp_pm_is_init_remote_addr(struct mptcp_sock *msk, + const struct mptcp_addr_info *remote); bool mptcp_pm_add_addr_recv(struct mptcp_sock *msk); void mptcp_pm_add_addr_received(const struct sock *ssk, const struct mptcp_addr_info *addr); From patchwork Fri Mar 21 01:45:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 14024763 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 8AA271E376C for ; Fri, 21 Mar 2025 01:45:54 +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=1742521554; cv=none; b=GeF6FCaV+2MH02B8Pymg7+Ua/IQl6zac+tQv5eVToYZepbLEPDeaxocGO1hcgkBJFrmk5Hz3mppB0wPT7edoRrWhTuK+wwS1RMfQWW7k7XG+VAj5jZ8EP2zc5JGRDsxk/C7YKYvYE9wwNlB7roUSmWQnZHk/DPFGurDWO2sp4aY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742521554; c=relaxed/simple; bh=lqAzjRXwF0QmBhz+bESOm1UPkkw84/jF82YBP7ftVsM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rlXrtZ7MvYNdjNfE8obpAELy5hXars3qvjQedK5KwTF46rxlAGnZnvVfayV2V9PIwnfFYozYUKwqIFCm3PWpWrGs1IHm308ISu/UltBbkPvr5xXdYidjMEFeih1Y7dvCMPTZZU7vZ8kESLKZyWpzQ//hfgDZYqqa2eKS1cgsdFg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pWDkIAn9; 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="pWDkIAn9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C933C4CEEA; Fri, 21 Mar 2025 01:45:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742521554; bh=lqAzjRXwF0QmBhz+bESOm1UPkkw84/jF82YBP7ftVsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pWDkIAn919e4JwDX9+IPYM3DRie7PZOkA683hRocXPUfP9twaH4eHD1qIinjVth4N UVaqWqDwD6Tn8ihTmKOa2sgSQUDwW1mDcRiMcVBxVcWlVnxlnUNge+4v4GOUVATzaT 0FwleCG0KnQEX+ENbaHKZzA53rmaUnv5YTElF3yhhxzzXa1BOYWFnFty67xWvzajMO NDbJWMdh7foo3NvsI45iybMycBWX9GseVgORsGuZyq7/AWS+ipSY4bOEHtRmVyWrsb r0DtLd93i84LL7eCXnz+GIydJ6q6T2Dct0Fo7rYhWBofUAbd/M7LScAO24oKH5myvh OLmSTkl3vmeHQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 09/10] mptcp: pm: add rm_addr_received() interface Date: Fri, 21 Mar 2025 09:45:03 +0800 Message-ID: X-Mailer: git-send-email 2.43.0 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 This patch adds an optional .rm_addr_received interface for struct mptcp_pm_ops and invokes it in mptcp_pm_worker() without PM lock. Since mptcp_subflow_shutdown() and mptcp_close_ssk() are sleepable kfuncs, .rm_addr_received interface of BPF PM should be invoked by __bpf_prog_enter_sleepable(), which can't be invoked under a lock. This patch unlocks the pm lock before invoking this interface in mptcp_pm_worker(), while holding this lock in mptcp_pm_rm_addr_recv(). Export mptcp_pm_rm_addr_recv() is to allow the MPTCP_PM_RM_ADDR_RECEIVED worker can be invoke from the in-kernel PM. With this, mptcp_pm_is_kernel() in mptcp_pm_rm_addr_or_subflow() can be dropped. Signed-off-by: Geliang Tang --- include/net/mptcp.h | 1 + net/mptcp/pm.c | 13 ++++++++++--- net/mptcp/pm_kernel.c | 6 ++++++ net/mptcp/protocol.h | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 90fda6d1468c..bd8a20b9d02b 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -137,6 +137,7 @@ struct mptcp_pm_ops { /* optional */ int (*add_addr_received)(struct mptcp_sock *msk, const struct mptcp_addr_info *addr); + void (*rm_addr_received)(struct mptcp_sock *msk); char name[MPTCP_PM_NAME_MAX]; struct module *owner; diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 7b34a59977cf..bb456e203665 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -677,15 +677,17 @@ static void mptcp_pm_rm_addr_or_subflow(struct mptcp_sock *msk, if (rm_type == MPTCP_MIB_RMADDR) { __MPTCP_INC_STATS(sock_net(sk), rm_type); - if (removed && mptcp_pm_is_kernel(msk)) + if (removed) mptcp_pm_nl_rm_addr(msk, rm_id); } } } -static void mptcp_pm_rm_addr_recv(struct mptcp_sock *msk) +void mptcp_pm_rm_addr_recv(struct mptcp_sock *msk) { + spin_lock_bh(&msk->pm.lock); mptcp_pm_rm_addr_or_subflow(msk, &msk->pm.rm_list_rx, MPTCP_MIB_RMADDR); + spin_unlock_bh(&msk->pm.lock); } void mptcp_pm_rm_subflow(struct mptcp_sock *msk, @@ -705,6 +707,9 @@ void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, for (i = 0; i < rm_list->nr; i++) mptcp_event_addr_removed(msk, rm_list->ids[i]); + if (!pm->ops->rm_addr_received) + return; + spin_lock_bh(&pm->lock); if (mptcp_pm_schedule_work(msk, MPTCP_PM_RM_ADDR_RECEIVED)) pm->rm_list_rx = *rm_list; @@ -931,7 +936,9 @@ void mptcp_pm_worker(struct mptcp_sock *msk) } if (pm->status & BIT(MPTCP_PM_RM_ADDR_RECEIVED)) { pm->status &= ~BIT(MPTCP_PM_RM_ADDR_RECEIVED); - mptcp_pm_rm_addr_recv(msk); + spin_unlock_bh(&pm->lock); + pm->ops->rm_addr_received(msk); + spin_lock_bh(&pm->lock); } if (pm->status & BIT(MPTCP_PM_ESTABLISHED)) { pm->status &= ~BIT(MPTCP_PM_ESTABLISHED); diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c index 1a434abcf862..4f7b2e0e998d 100644 --- a/net/mptcp/pm_kernel.c +++ b/net/mptcp/pm_kernel.c @@ -1446,6 +1446,11 @@ static int mptcp_pm_kernel_add_addr_received(struct mptcp_sock *msk, return ret; } +static void mptcp_pm_kernel_rm_addr_received(struct mptcp_sock *msk) +{ + mptcp_pm_rm_addr_recv(msk); +} + static void mptcp_pm_kernel_init(struct mptcp_sock *msk) { bool subflows_allowed = !!mptcp_pm_get_subflows_max(msk); @@ -1475,6 +1480,7 @@ struct mptcp_pm_ops mptcp_pm_kernel = { .accept_new_subflow = mptcp_pm_kernel_accept_new_subflow, .add_addr_echo = mptcp_pm_kernel_add_addr_echo, .add_addr_received = mptcp_pm_kernel_add_addr_received, + .rm_addr_received = mptcp_pm_kernel_rm_addr_received, .init = mptcp_pm_kernel_init, .name = "kernel", .owner = THIS_MODULE, diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 784e787cf667..4883f786e8ea 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1031,6 +1031,7 @@ void mptcp_pm_rm_subflow(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list); void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list); +void mptcp_pm_rm_addr_recv(struct mptcp_sock *msk); void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup); void mptcp_pm_mp_fail_received(struct sock *sk, u64 fail_seq); int mptcp_pm_mp_prio_send_ack(struct mptcp_sock *msk, From patchwork Fri Mar 21 01:45:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 14024764 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 5139D15820C for ; Fri, 21 Mar 2025 01:45:56 +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=1742521556; cv=none; b=PjyBVl0VfG63JnrjQnOCCrYrnvF7sdsZmgRwLINE8b6Ts8yzIanXa8J9zlARr0vajxSPJyINSAANTu8XdIY9fQ3vLJiUb6ueCnbszxOQYCBUt2pBN+bDVNzzU++CBbON7H6Zj89cEg3i+y7dZP6hEHiEFQdnqwUmIcRO4dm0tAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742521556; c=relaxed/simple; bh=JOHxu32s2gWzOzGtnauf1ccVRaAoXi9BmLr/LYQ7R68=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NcUi/8c3+9EFxTeqfrZ/MGgOKj1l5skBYYG7iX1vtb/1+n9tIVmlWr0s58bWKznJC7N5oOCjyK6NPkz9q22hwn7OAo2KMIi4JI5yxfI7Rv6RukMsq4JlvFEiQ2EBlNELyw8wr65YachogDQs0U5VbyVgQN4kBXNEfKU6FxzJoqk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SYJ0oPyX; 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="SYJ0oPyX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2D4FC4CEDD; Fri, 21 Mar 2025 01:45:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1742521556; bh=JOHxu32s2gWzOzGtnauf1ccVRaAoXi9BmLr/LYQ7R68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SYJ0oPyXz0W+mrEDb1sw0Tox0vYxjHexvfVlDqm5H9wKrU/uGROduZgyyO2cZJxjR jp7CUoQWbQUT1Ulj/3wOO2nkbD973FC77eMZDW6dBct3KBVyizmBIZt7a14BQt9gYc mv3/Tos4ae3LJhGke99GoRDLjcKYwkTizRRDO9jCqOEOVxVWmBC+WExB1Dt8+8lJHd ttMwDTLTWQcIBhZOTbqHnF8U+5inY+HWo9RJOrlkUOHJTgH7CmtDCT7KIJZVj9XGba MQ0mTX9gxCfhhXVWRw1fgG6QJPYq1Alf1MKTb/5FzuYx0m3bou+b/+yctMLXdsDrTd wHn3BSEIPbqiQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 10/10] mptcp: pm: drop is_userspace in subflow_check_next Date: Fri, 21 Mar 2025 09:45:04 +0800 Message-ID: <7d236597235768dcf1885f317acb767840cb9e42.1742521397.git.tanggeliang@kylinos.cn> X-Mailer: git-send-email 2.43.0 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 In mptcp_pm_subflow_check_next(), instead of reducing "pm->subflows" for the in-kernel PM in __mptcp_pm_close_subflow(), this patch moves "pm->subflows--;" forward to let it be used by both the userspace PM and the in-kernel PM. Then mptcp_pm_is_userspace() here can be dropped. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index bb456e203665..a3fcb335c717 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -531,13 +531,10 @@ void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, bool update_subflows; update_subflows = subflow->request_join || subflow->mp_join; - if (mptcp_pm_is_userspace(msk)) { - if (update_subflows) { - spin_lock_bh(&pm->lock); - pm->subflows--; - spin_unlock_bh(&pm->lock); - } - return; + if (update_subflows) { + spin_lock_bh(&pm->lock); + pm->subflows--; + spin_unlock_bh(&pm->lock); } if (!pm->ops->subflow_established) @@ -547,8 +544,8 @@ void mptcp_pm_subflow_check_next(struct mptcp_sock *msk, return; spin_lock_bh(&pm->lock); - if (update_subflows) - __mptcp_pm_close_subflow(msk); + if (update_subflows && msk->pm.subflows < mptcp_pm_get_subflows_max(msk)) + WRITE_ONCE(msk->pm.accept_subflow, true); /* Even if this subflow is not really established, tell the PM to try * to pick the next ones, if possible.