From patchwork Thu Feb 27 06:43:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13993806 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 AA7F715B102 for ; Thu, 27 Feb 2025 06:44:17 +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=1740638658; cv=none; b=TzksbPAHiD9HrPdza+S/PuC+4uTwA5KN+ui6eiAXHz+i1VuecYhM5vjcamqsMhwmGOeL8KvHUf14jGTcEMesghqhq29Kx4WCZ0S4+Qmz0lvYsLxL/s1zyopjupGI4QocSwzmRnyDEMqjfrgI5byn8ktD1LKg5tvsxEwWpZo8ZFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740638658; c=relaxed/simple; bh=tqW2pLqpby6Lsmk545cvuFQ9KEh3v1bRWjP08sfAgzQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PusG+Fo4qaiylNqHnMS5ispYaasd7FCKB8+kViawc86RoikRRUjlexlDHmiGg4/GcsINuhEuFn7Q1HOjKZmZ5xRGG3yGL/hYKt3htE8Rzk6klWDeYmIDS4J4lsSoCdqw5FzHATxrSWwrW2XBhd1q9jEPd1aipauEISEb+zb6Rfg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Hmonc6pu; 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="Hmonc6pu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10F0EC4CEE4; Thu, 27 Feb 2025 06:44:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740638657; bh=tqW2pLqpby6Lsmk545cvuFQ9KEh3v1bRWjP08sfAgzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hmonc6puCJp67ljIQZAA+Rj7UgpRiOltQ9z94SbVMFgnkuZM4Fk75cTB23zWgfSYG SNpAdO3u72W2bf+EQirTlvFIa8XuHqSlW5+uAafPD+vzQLfZCdWpMOSd+6vlQGavVI TAqkiCGvsTQ2WPxCUvuJN8Uu9dw01Smma6K1RE6QN7wEWVTlCckFEw11yO1jmwrPg8 gRq1+9mFpymVb2puFyei3W8u/xSR6XM+1RkxLXi58qCCddeUvppOOMTDIBtp86QmPk T+MXj1osm62Zgqu3ruFzgzb+SBcBZbZkv8kbk4dhcGAFwVgu6fUO6tz606xvlPfpLn IU9TUFZowe/mQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v1 1/6] mptcp: pm: use pm variable instead of msk->pm Date: Thu, 27 Feb 2025 14:43:52 +0800 Message-ID: <98c518824741870f215f7e388ae9ee40655ec9b0.1740638334.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 variable "pm" has been defined in mptcp_pm_fully_established() and mptcp_pm_data_reset() as "sk->pm", so use "pm" directly instead of using "sk->pm". Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index ac7b39148bd3..1844107f6f93 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -139,13 +139,13 @@ 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) && - !(msk->pm.status & BIT(MPTCP_PM_ALREADY_ESTABLISHED))) + !(pm->status & BIT(MPTCP_PM_ALREADY_ESTABLISHED))) mptcp_pm_schedule_work(msk, MPTCP_PM_ESTABLISHED); - if ((msk->pm.status & BIT(MPTCP_PM_ALREADY_ESTABLISHED)) == 0) + if ((pm->status & BIT(MPTCP_PM_ALREADY_ESTABLISHED)) == 0) announce = true; - msk->pm.status |= BIT(MPTCP_PM_ALREADY_ESTABLISHED); + pm->status |= BIT(MPTCP_PM_ALREADY_ESTABLISHED); spin_unlock_bh(&pm->lock); if (announce) @@ -632,7 +632,7 @@ void mptcp_pm_data_reset(struct mptcp_sock *msk) WRITE_ONCE(pm->addr_signal, 0); WRITE_ONCE(pm->remote_deny_join_id0, false); pm->status = 0; - bitmap_fill(msk->pm.id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); + bitmap_fill(pm->id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1); } void mptcp_pm_data_init(struct mptcp_sock *msk) From patchwork Thu Feb 27 06:43:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13993807 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 312E221CC7A for ; Thu, 27 Feb 2025 06:44:19 +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=1740638659; cv=none; b=ZFCGdiiL1SQ2KN0re2AP2MEjbSZcO2iMgnguP+hzzLZ4VVgiiaLZ3L4SiV42OKDtOHl1Vs1D8b72Yfe1y9s+gwa2GNm1t1bI5ODFLlwvvkBzvVNqRO3WCSPDvyWkoX8MeMlISRnNkf2FZGCHVI2svzzypY36x2i51prNvq2izds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740638659; c=relaxed/simple; bh=gxuTkKbOCy4bu9PXasmL1Uor5onEMyuwFWhPMFeTMhQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=furX1DoQmsbQJD0p/oByBDAKkhad6W4EvSNhRG7bz3jiVkUcExnlj4B3h+qgIdR4dJd8M3VbIlTmNZq6GyKcOGjKsDtVufwhRuWKD/IxFCC2X22x2POCj0WIBF/ZWHNr5U+1GZ1HFjmVxg2j22KaMl4ZmKgIJEjKd/oZxAcdYbQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E3Dkb+qU; 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="E3Dkb+qU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5E6CC4CEDD; Thu, 27 Feb 2025 06:44:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740638659; bh=gxuTkKbOCy4bu9PXasmL1Uor5onEMyuwFWhPMFeTMhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E3Dkb+qUFi4ZFkwwh9iSiv2+yOBQqH6H9xZiGdg6TQ9FGWh9OmSS7uq04uiQK+16e CyJMt7bjBIUSjt82NYOSaXwutKf0kZxv70S22dAy5Kb5q6fD/DMEjeh2ysyq5qHnGG B+IqmE2yajfdIE6RDo6vR8yPo1dBSzSD8/b8YymxVos6YFt7VAXovP+fQDZdGZZ6mq fkethGm1nlEKdkttJCt50E+EbfGxOXf3Ovnf6fpOjOeTANPOeAFoi9LAFr5zrIO509 ed5ADghlr6xsIPgsGkd866nqSiIEkBfm267R5Cp6f8Cvpkvay/JYbEO/53rRUUEYhb 2qeEmP2CC5Z1A== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v1 2/6] mptcp: pm: userspace: drop is_userspace in free_local_addr_list Date: Thu, 27 Feb 2025 14:43:53 +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 To reduce the path manager's reliance on mptcp_pm_is_userspace() and mptcp_pm_is_kernel() helpers, this patch drops the check for mptcp_pm_is_userspace() in mptcp_free_local_addr_list() and replaces it with a check to see if userspace_pm_local_addr_list is empty. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 5b3ee43130be..98fe8808d1e1 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -18,7 +18,7 @@ void mptcp_free_local_addr_list(struct mptcp_sock *msk) struct sock *sk = (struct sock *)msk; LIST_HEAD(free_list); - if (!mptcp_pm_is_userspace(msk)) + if (list_empty(&msk->pm.userspace_pm_local_addr_list)) return; spin_lock_bh(&msk->pm.lock); From patchwork Thu Feb 27 06:43:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13993808 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 4536121CC7A for ; Thu, 27 Feb 2025 06:44:20 +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=1740638661; cv=none; b=ufuiq6nlw7R42zISoKrb1mpnnC1XqgcF6hzeGmrtp8eCnvFhT4QL9ape8uCrGAGjA6EBUGPKGvkiRuBGSeDNXFjH89gL2G2XoGg8/zFjOnLprfKN7EdvfMqDDM9hczRMYjqCP2HWBAT8/3y3fsCVry/4YP7hArcsTnB4wL2ukNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740638661; c=relaxed/simple; bh=13Ci+PPqQ1wGMtMD0uB+9jZouttPlQWwaKm9XMRx6sI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M4BCnyDQCd/q7EVG18CbL70K4RoUP8uDmBJW7wKkRam9hiQe1Bf/gYFNi0GqWlgRr8jmZkSPnOxhQMPjHUAntBj7V8l4k0EP+b1BawL8Q+TI55rLCEyJS4jNjH3oHd+0ZpRRkpYoT85Rp88YmpsxHhYzzQB0pRSF9omyD5tdcf8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VuHtqIlK; 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="VuHtqIlK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FB21C4CEE7; Thu, 27 Feb 2025 06:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740638660; bh=13Ci+PPqQ1wGMtMD0uB+9jZouttPlQWwaKm9XMRx6sI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VuHtqIlKi6AnMfUxdu0RSo9+SxwKnwXv5ofYdyYuAoq2q7DPhTun8GgLAToX9B7j7 1ibJX7MBuCsBz/9N1NR5ZLrPeMNdPfD1TfDQ/+u+oyQAwx1XX0Pc74yZiRvatCCokC QJUzO9tZLthZwe8mqU/KS4BTAqdtS04eKqKmKgD5acZ1+PKXAXS73ZZchrJzpUjW/H gIpdpgr/Khc7O6seWloFC0530KPCkM/re08vE6ZytGr6PEn/MBVNEZIYP+DPHewjg9 84uxpNoW92kSU4VoAufbFsIuhirOAkVUSlI5sRKyerWN3Z+LvJWnjKYMcsTvpifCFU NhzmnrVPD1Nqg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v1 3/6] mptcp: pm: drop is_kernel in alloc_anno_list Date: Thu, 27 Feb 2025 14:43:54 +0800 Message-ID: <353675576c206d346d952315e520f313ad0a2144.1740638334.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 To reduce the path manager's reliance on mptcp_pm_is_userspace() and mptcp_pm_is_kernel() helpers, this patch drops the check for mptcp_pm_is_kernel() in the function mptcp_pm_alloc_anno_list(). Instead, add a new parameter "reissue" for this function, pass "false" to this function in the in-kernel PM while pass "true" to it in the userspace PM. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 7 ++++--- net/mptcp/pm_userspace.c | 2 +- net/mptcp/protocol.h | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 23c28e37ab8f..0d98c2df72f7 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -358,7 +358,8 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk, } bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, - const struct mptcp_addr_info *addr) + const struct mptcp_addr_info *addr, + bool reissue) { struct mptcp_pm_add_entry *add_entry = NULL; struct sock *sk = (struct sock *)msk; @@ -369,7 +370,7 @@ bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, add_entry = mptcp_lookup_anno_list_by_saddr(msk, addr); if (add_entry) { - if (WARN_ON_ONCE(mptcp_pm_is_kernel(msk))) + if (WARN_ON_ONCE(!reissue)) return false; sk_reset_timer(sk, &add_entry->add_timer, @@ -595,7 +596,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) /* If the alloc fails, we are on memory pressure, not worth * continuing, and trying to create subflows. */ - if (!mptcp_pm_alloc_anno_list(msk, &local.addr)) + if (!mptcp_pm_alloc_anno_list(msk, &local.addr, false)) return; __clear_bit(local.addr.id, msk->pm.id_avail_bitmap); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 98fe8808d1e1..05d59ad1a0bc 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -232,7 +232,7 @@ int mptcp_pm_nl_announce_doit(struct sk_buff *skb, struct genl_info *info) lock_sock(sk); spin_lock_bh(&msk->pm.lock); - if (mptcp_pm_alloc_anno_list(msk, &addr_val.addr)) { + if (mptcp_pm_alloc_anno_list(msk, &addr_val.addr, true)) { msk->pm.add_addr_signaled++; mptcp_pm_announce_addr(msk, &addr_val.addr, false); mptcp_pm_nl_addr_send_ack(msk); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index ef1d43406f9b..0b6695fbb645 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1023,7 +1023,8 @@ int mptcp_pm_nl_mp_prio_send_ack(struct mptcp_sock *msk, struct mptcp_addr_info *rem, u8 bkup); bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, - const struct mptcp_addr_info *addr); + const struct mptcp_addr_info *addr, + bool reissue); void mptcp_pm_free_anno_list(struct mptcp_sock *msk); bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk); struct mptcp_pm_add_entry * From patchwork Thu Feb 27 06:43: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: 13993809 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 8593715B102 for ; Thu, 27 Feb 2025 06:44:22 +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=1740638662; cv=none; b=f0iVIYPp2oJ/r7hJykr1+Us3MBWPWzarketqGmMkuPRmM/yX9DNdQiyCJJ9gcm5//HGVvRzPTFiumsuVnl+jyXALP8li5DY+ZhusMydhX3Vz9b6/HsWrzj5hwVu/muGxe+yf3a4Ej5URI7TQcNKJiEJ8ZFQgAt9AkTjUV8TQ9yA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740638662; c=relaxed/simple; bh=+GxoLYkjnhoqNLbe10capEc4MTSdMJndiVl1v/9Oiz4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hKpburjHx1f4kRpmTsxS2bgqFkVVrnRlHj8QPTR/oI1GiBpQ7tmdiNo/vk4h0WsA5in3X2b73zAmzvAlaw6vdvtkNofD9AJaGENmitcoXhrE8v6Jn7LGAY9vVwm2b5ag2bT1M4btZayDSGz8ogsZRBun6UKCXGKVcWT7TlLdWcI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XaoikGta; 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="XaoikGta" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60C4CC4CEDD; Thu, 27 Feb 2025 06:44:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740638662; bh=+GxoLYkjnhoqNLbe10capEc4MTSdMJndiVl1v/9Oiz4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XaoikGtatCkQSTKAWuUdFZ7L05LzqfRCkbdDfJQtFhix82ZxsmPzhYIjSKA6aDgKH EU5zYuPw5MEG/wxsGEYnDSxZWfCSvfdfByTzW8pGmVo2bOAeFGvmhGHFLmkUqKoxIm h7jHHR8rRgrj2grKCSZWy2yxqYVa5bC3H+W4OtS3tuGUK3GbpRy7uiEI7xRsX3c4uV +aUHo+1Sy9b449snQpDz/O7JiXzmxC8svggnCaKcbAAoYW9DzFoBMpmTYcUVNgit1s EWNV1qo7D3+Vwist2r8G5dkhWwVXCyju1XsgfabmXMZ5BGviuXNU5wYOBajHwOfHHZ w4ARYqWw1n/Rg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v1 4/6] mptcp: pm: in-kernel: drop is_userspace in remove_id_zero Date: Thu, 27 Feb 2025 14:43:55 +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 There're duplicate operations in mptcp_nl_remove_subflow_and_signal_addr() and mptcp_nl_remove_id_zero_address(), both of which traverse all mptcp sockets in the net namespace. This patch drops the traversal operation in the latter and reuse the traversal loop of the former to do the removal of id zero address. An additional benefit is that the check for mptcp_pm_is_userspace() in mptcp_nl_remove_id_zero_address() is dropped, which reduces the path manager's reliance on mptcp_pm_is_userspace() and mptcp_pm_is_kernel() helpers. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 77 ++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 0d98c2df72f7..e546388070b4 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1514,6 +1514,28 @@ static void __mark_subflow_endp_available(struct mptcp_sock *msk, u8 id) msk->pm.local_addr_used--; } +static void mptcp_nl_remove_id_zero_address(struct mptcp_sock *msk, + const struct mptcp_addr_info *addr) +{ + struct mptcp_rm_list list = { .nr = 0 }; + struct mptcp_addr_info msk_local; + + if (list_empty(&msk->conn_list)) + return; + + mptcp_local_address((struct sock_common *)msk, &msk_local); + if (!mptcp_addresses_equal(&msk_local, addr, addr->port)) + return; + + list.ids[list.nr++] = 0; + + spin_lock_bh(&msk->pm.lock); + mptcp_pm_remove_addr(msk, &list); + mptcp_pm_nl_rm_subflow_received(msk, &list); + __mark_subflow_endp_available(msk, 0); + spin_unlock_bh(&msk->pm.lock); +} + static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net, const struct mptcp_pm_addr_entry *entry) { @@ -1532,6 +1554,11 @@ static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net, goto next; lock_sock(sk); + if (entry->addr.id == 0) { + mptcp_nl_remove_id_zero_address(msk, &entry->addr); + goto out; + } + remove_subflow = mptcp_lookup_subflow_by_saddr(&msk->conn_list, addr); mptcp_pm_remove_anno_addr(msk, addr, remove_subflow && !(entry->flags & MPTCP_PM_ADDR_FLAG_IMPLICIT)); @@ -1551,42 +1578,7 @@ static int mptcp_nl_remove_subflow_and_signal_addr(struct net *net, if (msk->mpc_endpoint_id == entry->addr.id) msk->mpc_endpoint_id = 0; - release_sock(sk); - -next: - sock_put(sk); - cond_resched(); - } - - return 0; -} - -static int mptcp_nl_remove_id_zero_address(struct net *net, - struct mptcp_addr_info *addr) -{ - struct mptcp_rm_list list = { .nr = 0 }; - long s_slot = 0, s_num = 0; - struct mptcp_sock *msk; - - list.ids[list.nr++] = 0; - - while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) { - struct sock *sk = (struct sock *)msk; - struct mptcp_addr_info msk_local; - - if (list_empty(&msk->conn_list) || mptcp_pm_is_userspace(msk)) - goto next; - - mptcp_local_address((struct sock_common *)msk, &msk_local); - if (!mptcp_addresses_equal(&msk_local, addr, addr->port)) - goto next; - - lock_sock(sk); - spin_lock_bh(&msk->pm.lock); - mptcp_pm_remove_addr(msk, &list); - mptcp_pm_nl_rm_subflow_received(msk, &list); - __mark_subflow_endp_available(msk, 0); - spin_unlock_bh(&msk->pm.lock); +out: release_sock(sk); next: @@ -1618,8 +1610,10 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info) * id addresses. Additionally zero id is not accounted for in id_bitmap. * Let's use an 'mptcp_rm_list' instead of the common remove code. */ - if (addr.addr.id == 0) - return mptcp_nl_remove_id_zero_address(sock_net(skb->sk), &addr.addr); + if (addr.addr.id == 0) { + entry = &addr; + goto del_addr; + } spin_lock_bh(&pernet->lock); entry = __lookup_addr_by_id(pernet, addr.addr.id); @@ -1642,9 +1636,12 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info) __clear_bit(entry->addr.id, pernet->id_bitmap); spin_unlock_bh(&pernet->lock); +del_addr: mptcp_nl_remove_subflow_and_signal_addr(sock_net(skb->sk), entry); - synchronize_rcu(); - __mptcp_pm_release_addr_entry(entry); + if (entry->addr.id) { + synchronize_rcu(); + __mptcp_pm_release_addr_entry(entry); + } return ret; } From patchwork Thu Feb 27 06:43: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: 13993810 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 7735921CC73 for ; Thu, 27 Feb 2025 06:44:24 +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=1740638664; cv=none; b=oEKAZc0a/JsFX4a0fA790I+CVDky+ePU5z6kd4cPbwI8Ye1E0HNWrDohp4mznmjjfojPSq56+MQlbE+Ssq6yQHd00RRb7Msnj2h4Q6G9BfEvyMoNYpyECkMEjHR4d6akb4Ny7lYBKlXwEMOeAHt23hgtGOSW4eh+3c8zka0639E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740638664; c=relaxed/simple; bh=NmOFtPL4yeEvDOCNQp8MUu/VLI2ehMCKyvv+2cLh6vw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MMhH95hz7h+9JmtXmnxl2CufzzQTnIL8H+ZYXy9nPTbXqn9nfgwJNACzJHe5FMbOIjFvlX8WOxZeLOAkZ5vGO+TU0DcL7iHf5BtbQu8S7SJdKBeF7Ih3FtPjGgkGiqEFRaF980yLZ0Ltxu9AIKyIKgWuqSwAakSKX0oC4zN3l2s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l3b/PoQB; 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="l3b/PoQB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09E08C4CEE4; Thu, 27 Feb 2025 06:44:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740638663; bh=NmOFtPL4yeEvDOCNQp8MUu/VLI2ehMCKyvv+2cLh6vw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l3b/PoQBLQMgEJPI/Bpm0bsPqsnIawLY065HDtSSjDKA1d/u16Dl82pQ1Ey4F5i3m zdWDQJlpbr5JhsLjf3eEUZqq3Zul9nLD53iuXK3Z7D+xrVNuSvqs6xyZN1cWT2Dwdh DVkkg6azF+yoCz5yKunzmkjI6Ap8Y8NaW3/ewRQQGYpuqUtKDzyPRTlFZMsduZdbC+ 1MA1hvc/Alpg6Bqtw9lK6/0Z/4GUSJO8gCtIzcEc9CemX+Gst6aPqJe1f6c9WEoqk9 oEugVxfQV44W5nQxm20uofYvhEeoRwSoOmrEW1vaLbx6UiZOxWDz9Z4sWuz2V+VcsK pbmG6solv1YIw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v1 5/6] mptcp: pm: add remote parameter for set_flags Date: Thu, 27 Feb 2025 14:43:56 +0800 Message-ID: <10ce66a82baec7e37fcde50554c1a0f0f2a9da6a.1740638334.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 remote address of set_flags() interface is useful for userspace PM, but unused in in-kernel PM. But an additional "changed" parameter needs to be passed to set_flags() of in-kernel PM. One option is to add a "u8 changed" parameter to set_flags() interface: set_flags(struct mptcp_pm_addr_entry *local, struct mptcp_addr_info *remote, u8 changed) A better option is to add a struct mptcp_pm_addr_entry "remote" parameter for set_flags(), so that "remote->addr" can be used for userspace PM, and "remote->flags" can be used for in-kernel PM to replace the additional "changed" parameter. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 20 ++++++++++++++++---- net/mptcp/pm_netlink.c | 1 + net/mptcp/pm_userspace.c | 21 +++------------------ net/mptcp/protocol.h | 2 ++ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 1844107f6f93..adb2735c4131 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -531,7 +531,8 @@ int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, static int mptcp_pm_set_flags(struct genl_info *info) { struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, }; - struct nlattr *attr_loc; + struct mptcp_pm_addr_entry rem = { .addr = { .family = AF_UNSPEC }, }; + struct nlattr *attr_loc, *attr_rem; int ret = -EINVAL; if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR)) @@ -542,9 +543,20 @@ static int mptcp_pm_set_flags(struct genl_info *info) if (ret < 0) return ret; - if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_set_flags(&loc, info); - return mptcp_pm_nl_set_flags(&loc, info); + if (info->attrs[MPTCP_PM_ATTR_TOKEN]) { + attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; + ret = mptcp_pm_parse_entry(attr_rem, info, false, &rem); + if (ret < 0) + return ret; + + if (rem.addr.family == AF_UNSPEC) { + NL_SET_ERR_MSG_ATTR(info->extack, attr_rem, + "invalid remote address family"); + return -EINVAL; + } + return mptcp_userspace_pm_set_flags(&loc, &rem, info); + } + return mptcp_pm_nl_set_flags(&loc, &rem, info); } int mptcp_pm_nl_set_flags_doit(struct sk_buff *skb, struct genl_info *info) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index e546388070b4..053f2bec9042 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1949,6 +1949,7 @@ static void mptcp_nl_set_flags(struct net *net, } int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *local, + struct mptcp_pm_addr_entry *remote, struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 05d59ad1a0bc..dddd2daed650 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -553,19 +553,16 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info } int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local, + struct mptcp_pm_addr_entry *remote, struct genl_info *info) { - struct mptcp_addr_info rem = { .family = AF_UNSPEC, }; struct mptcp_pm_addr_entry *entry; - struct nlattr *attr, *attr_rem; struct mptcp_sock *msk; + struct nlattr *attr; int ret = -EINVAL; struct sock *sk; u8 bkup = 0; - if (GENL_REQ_ATTR_CHECK(info, MPTCP_PM_ATTR_ADDR_REMOTE)) - return ret; - msk = mptcp_userspace_pm_get_sock(info); if (!msk) return ret; @@ -580,18 +577,6 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local, goto set_flags_err; } - attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - ret = mptcp_pm_parse_addr(attr_rem, info, &rem); - if (ret < 0) - goto set_flags_err; - - if (rem.family == AF_UNSPEC) { - NL_SET_ERR_MSG_ATTR(info->extack, attr_rem, - "invalid remote address family"); - ret = -EINVAL; - goto set_flags_err; - } - if (local->flags & MPTCP_PM_ADDR_FLAG_BACKUP) bkup = 1; @@ -606,7 +591,7 @@ int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local, spin_unlock_bh(&msk->pm.lock); lock_sock(sk); - ret = mptcp_pm_nl_mp_prio_send_ack(msk, &local->addr, &rem, bkup); + ret = mptcp_pm_nl_mp_prio_send_ack(msk, &local->addr, &remote->addr, bkup); release_sock(sk); /* mptcp_pm_nl_mp_prio_send_ack() only fails in one case */ diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 0b6695fbb645..5adb791898ec 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1038,8 +1038,10 @@ bool mptcp_lookup_subflow_by_saddr(const struct list_head *list, bool mptcp_remove_anno_list_by_saddr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr); int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *local, + struct mptcp_pm_addr_entry *remote, struct genl_info *info); int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local, + struct mptcp_pm_addr_entry *remote, struct genl_info *info); int mptcp_pm_announce_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, From patchwork Thu Feb 27 06:43: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: 13993811 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 C616A21CC73 for ; Thu, 27 Feb 2025 06:44: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=1740638665; cv=none; b=clMkrHBsbWhEPOubrcWr9lA9c7Uf93eA7lQyHokDFzw/2kAM5Tpogn9BwGz8F4U1kTSE8y0SSkSg/2QVFx2DBEiATl3j/6XADgANNWvZzZcMxmcgXlbkiFjdEw1aY+iXmNMKUUWUcoT0R/I0aUqovQ1ft2LYe+u6zzfXFefqyrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740638665; c=relaxed/simple; bh=MjLRvCPiOpwfmWzZC+qmAntgioCC/aZW3A7R6x5xR3M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GELhP+TtekLr0mj93Q9VitIxqulD7+RsyS+9MOKvvb9n9eLxLTYQBEVHuR6r6kkskvTfaizvf4k3oud8yFKnzHOtHJlLi7uYL1jlsdAPVbBmLVxnV/Y5bw+BOU9lRKmFjLNkl9PHfZa1Xvq8yyyU1UJ+BvdW4rRXyqGaGG80k1E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=R2aUCMUM; 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="R2aUCMUM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 726F1C4CEDD; Thu, 27 Feb 2025 06:44:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740638665; bh=MjLRvCPiOpwfmWzZC+qmAntgioCC/aZW3A7R6x5xR3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R2aUCMUMJ34uQHWmgyrL/59XqjUQsTdpRbpgqhUWd88oPmrsgVfH+MRiPvMYmh/2Q I7duGBsyf0V+SaNdPlnvi+Wm3JSIMItxgE90tJ5/ci0Qvkjr98F0aKg92RF0NFS9Xp +KPFjcp+MZBnc5TY3usvWihWjBZKSVPVuNTGIYQoZD/jjrwqXIjo+bTzg6K8qsnKo4 Ml5lHdzxf9gLL3WSoyroTvj7NhX6GrCOt/YoEbwja4eC39LW5NDVCfs0SMlVsiowqH bDkONmBjtwXle+iLtgCXiSxLF0S3uf08lXngq4PqO2rGZtGRp6qoHtG2oV7mz5/YV5 iTVx0PCWTFqGA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v1 6/6] mptcp: pm: in-kernel: drop changed parameter of set_flags Date: Thu, 27 Feb 2025 14:43:57 +0800 Message-ID: <1e2f2a9bcdf69bd241dec4c5455c4aa135927cb6.1740638334.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 To drop the additional "changed" parameter of mptcp_nl_set_flags(), store "entry->flags" to "remote->flags" before modifying it in mptcp_pm_nl_set_flags(), so that "changed" value can be obtained by comparing "local->flags" and "remote->flags" in mptcp_nl_set_flags(). Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 053f2bec9042..2f22c3bf88e2 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1916,13 +1916,16 @@ static void mptcp_pm_nl_fullmesh(struct mptcp_sock *msk, static void mptcp_nl_set_flags(struct net *net, struct mptcp_pm_addr_entry *local, - u8 changed) + struct mptcp_pm_addr_entry *remote) { u8 is_subflow = !!(local->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW); u8 bkup = !!(local->flags & MPTCP_PM_ADDR_FLAG_BACKUP); + u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP | + MPTCP_PM_ADDR_FLAG_FULLMESH; long s_slot = 0, s_num = 0; struct mptcp_sock *msk; + changed = (local->flags ^ remote->flags) & mask; if (changed == MPTCP_PM_ADDR_FLAG_FULLMESH && !is_subflow) return; @@ -1987,12 +1990,13 @@ int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *local, return -EINVAL; } + remote->flags = entry->flags; changed = (local->flags ^ entry->flags) & mask; entry->flags = (entry->flags & ~mask) | (local->flags & mask); *local = *entry; spin_unlock_bh(&pernet->lock); - mptcp_nl_set_flags(net, local, changed); + mptcp_nl_set_flags(net, local, remote); return 0; }