From patchwork Tue Oct 8 09:58:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13826150 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 BD35342AB1 for ; Tue, 8 Oct 2024 09:58:27 +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=1728381507; cv=none; b=I2QIl3FW33g/PuB+NdX0WpvxoGjhCMbvmYguHbn9zQ1hIRf4iJFRJUvhXC2ZxWk/YYb+xu31ZXV7mG61+SSIHhVFcEXY51WBPWDRGgO+2/pf7MHXllix62bBT7r837Z9Y1GN/G1sKxeZRPu8N5SNF54tMRLpLzlyjYcmU1aw91U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728381507; c=relaxed/simple; bh=lR8ulhf/WLrokobrcHDyYE80x2jmu30pc2zQ6/o952w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tX/ee8lsNUIbW1R/nkHShWzn6wh9nrrb4IeiN0eKCRHuxFLwvAFZtXFI4zaDDcel7u8AmYSQsWg4lkcVXs/QcpAn64+aOhhoDB3OKBlnqpYl7GjtHwnMP8mCAecDuo0uTDSsnola0DHD3RCLhMmvNIEinmnZ2pzQiBsBQQ10rlI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pCdOOlZ/; 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="pCdOOlZ/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E91B2C4CECC; Tue, 8 Oct 2024 09:58:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728381507; bh=lR8ulhf/WLrokobrcHDyYE80x2jmu30pc2zQ6/o952w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pCdOOlZ//MOyhLCZhtG8Gin1xBFiQ3Jev376p9tY7HSmo/Cdkk4FifsTQDVa36MTG 9Qq5yPl6YdsQDacvldUbVmxetSDirlZuPn2WaJ5MhvvTWqsthAz7lONxWlg4enwimQ wKFnGnIRtK+sO9Z1IfSiQXBvcSKZjANMDjcuXii42tWlFEBtgzyhkAdPEV2UlzDxYR Oz4V/e1usqQJL9Hc08nrG6pt0KeDg+QmOm9T3OhEl/UIVW1jxEOUYJDc6HDsFLeKl/ LaCziklQK8Gx7xl4ccBgqxiFbsJGsDTQPCYM4P4iPAWogGy35rhg+lnC8J75nKmCMo AYMIhOT0Zrk4g== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 01/13] mptcp: add id parameter for get_addr Date: Tue, 8 Oct 2024 17:58:05 +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 The address id is parsed both in mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr(), this makes the code somewhat repetitive. So this patch adds a new parameter "id" for all get_addr() interfaces. The address id is only parsed in mptcp_pm_nl_get_addr_doit(), then pass it to both mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr(). Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 28 ++++++++++++++++------------ net/mptcp/pm_userspace.c | 11 +++-------- net/mptcp/protocol.h | 2 +- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 778e59bfbd8e..076a11d52057 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1791,19 +1791,14 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } -static int mptcp_pm_nl_get_addr(struct genl_info *info) +static int mptcp_pm_nl_get_addr(u8 id, struct genl_info *info) { - struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet = genl_info_pm_nl(info); - struct mptcp_pm_addr_entry addr, *entry; + struct mptcp_pm_addr_entry *entry; struct sk_buff *msg; void *reply; int ret; - ret = mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - return ret; - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) return -ENOMEM; @@ -1817,7 +1812,7 @@ static int mptcp_pm_nl_get_addr(struct genl_info *info) } spin_lock_bh(&pernet->lock); - entry = __lookup_addr_by_id(pernet, addr.addr.id); + entry = __lookup_addr_by_id(pernet, id); if (!entry) { GENL_SET_ERR_MSG(info, "address not found"); ret = -EINVAL; @@ -1841,16 +1836,25 @@ static int mptcp_pm_nl_get_addr(struct genl_info *info) return ret; } -static int mptcp_pm_get_addr(struct genl_info *info) +static int mptcp_pm_get_addr(u8 id, struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_get_addr(info); - return mptcp_pm_nl_get_addr(info); + return mptcp_userspace_pm_get_addr(id, info); + return mptcp_pm_nl_get_addr(id, info); } int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { - return mptcp_pm_get_addr(info); + struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; + struct mptcp_pm_addr_entry addr; + int ret; + + ret = mptcp_pm_parse_entry(attr, info, false, &addr); + if (ret < 0) + return ret; + + ret = mptcp_pm_get_addr(addr.addr.id, info); + return ret; } static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 512260e4afb2..da617d8bcc09 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -629,10 +629,9 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, return ret; } -int mptcp_userspace_pm_get_addr(struct genl_info *info) +int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info) { - struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; - struct mptcp_pm_addr_entry addr, *entry; + struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; struct sk_buff *msg; int ret = -EINVAL; @@ -645,10 +644,6 @@ int mptcp_userspace_pm_get_addr(struct genl_info *info) sk = (struct sock *)msk; - ret = mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - goto out; - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) { ret = -ENOMEM; @@ -665,7 +660,7 @@ int mptcp_userspace_pm_get_addr(struct genl_info *info) lock_sock(sk); spin_lock_bh(&msk->pm.lock); - entry = mptcp_userspace_pm_lookup_addr_by_id(msk, addr.addr.id); + entry = mptcp_userspace_pm_lookup_addr_by_id(msk, id); if (!entry) { GENL_SET_ERR_MSG(info, "address not found"); ret = -EINVAL; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 41d01a046e27..07cb80be98cb 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1127,7 +1127,7 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_userspace_pm_get_addr(struct genl_info *info); +int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info); static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow) { From patchwork Tue Oct 8 09:58:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13826151 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 80ED018C35A for ; Tue, 8 Oct 2024 09:58:29 +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=1728381509; cv=none; b=rQYji+bJvMmuf6FHR1Sh/Q+r74jyN7RnR5iB7rGjnDR24Dbrcwf9g0nYuLKav/QJGtrCNcX4mfhFNRHimYz/fQPPDlbbzWr9DVTbUUjjNoUBIJQe0EcGFdRXdIaRO07oKwBPm9lMk+fALGxMlF52oIdcA59JG0EcOevIS3Tns9A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728381509; c=relaxed/simple; bh=R9qQz8gVzEiiFKH6i0kZ/cTPVAulJS3GlM2is5ziP9U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P5Cm5WTkLj0aOeJSuhabmtehJaILwRpP7Q6rmAcEMsEdlG+8GvLsJvLF5tadwqpCed3VCngsyA5qnDeTxLX/VG00NPwtZWDrQyBOJ0zlieupjZTGz7FVFF4zitZEqfplDXRP6krj+r3JLE7C62ccPpTHGlolyx92uETPMvrV+1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p/Gw/azZ; 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="p/Gw/azZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBFF5C4CEC7; Tue, 8 Oct 2024 09:58:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728381509; bh=R9qQz8gVzEiiFKH6i0kZ/cTPVAulJS3GlM2is5ziP9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p/Gw/azZCmrQC+fjqcnAlFKYbj8y5QSJ2DzfXqhXyvjteppxo7UI6g5CfP0Qq30sR IHJ54SoONkAu8J5knpxlHjVySUc7b2gf0xnAwXrgz/HQj+ViQVojJ1ajHn1VLZYSw5 SuBJx5dRafhWWP5JIqVEQfmGckYaRZ7fzvVvSgyzwTDo8avCA4jBtLNnqL7sazerF3 KXcJoJcM8Tz6yF4JAhzL5jZOwtK+2p/S3aOrfmipupucRDdJvRoHpv817/liUSYC5G TsNZwIo2xr5XiKT5MjYg0kSS4A6kEYa9yNdypwLPY3YV/cOVE6gxTAu6KYDcIWusNr W5ufOQ3Bl9oQw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 02/13] mptcp: add addr parameter for get_addr Date: Tue, 8 Oct 2024 17:58:06 +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 The netlink messages are sent both in mptcp_pm_nl_get_addr() and mptcp_userspace_pm_get_addr(), this makes the code somewhat repetitive. This is because the netlink PM and userspace PM use different locks to protect the address entry that needs to be sent via the netlink message. The former uses pernet->lock, and the latter uses msk->pm.lock. The current get_addr() flow looks like this: lock(); entry = get_entry(); send_nlmsg(entry); unlock(); After holding the lock, get the entry from the list, send the entry, and finally release the lock. This patch changes the process by getting the entry while holding the lock, then making a copy of the entry so that the lock can be released. Finally, the copy of the entry is sent without locking: lock(); entry = get_entry(); *copy = *entry; unlock(); send_nlmsg(copy); This way we can reuse this send_nlmsg() code between the netlink PM and userspace PM. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 33 ++++++++++++++++++--------------- net/mptcp/pm_userspace.c | 24 +++++++++++++----------- net/mptcp/protocol.h | 3 ++- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 076a11d52057..886fb7c1468d 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1791,13 +1791,14 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } -static int mptcp_pm_nl_get_addr(u8 id, struct genl_info *info) +static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info) { struct pm_nl_pernet *pernet = genl_info_pm_nl(info); struct mptcp_pm_addr_entry *entry; struct sk_buff *msg; + int ret = -EINVAL; void *reply; - int ret; msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) @@ -1813,34 +1814,36 @@ static int mptcp_pm_nl_get_addr(u8 id, struct genl_info *info) spin_lock_bh(&pernet->lock); entry = __lookup_addr_by_id(pernet, id); - if (!entry) { + if (entry) { + *addr = *entry; + ret = 0; + } + spin_unlock_bh(&pernet->lock); + + if (ret) { GENL_SET_ERR_MSG(info, "address not found"); - ret = -EINVAL; - goto unlock_fail; + goto fail; } - ret = mptcp_nl_fill_addr(msg, entry); + ret = mptcp_nl_fill_addr(msg, addr); if (ret) - goto unlock_fail; + goto fail; genlmsg_end(msg, reply); ret = genlmsg_reply(msg, info); - spin_unlock_bh(&pernet->lock); return ret; -unlock_fail: - spin_unlock_bh(&pernet->lock); - fail: nlmsg_free(msg); return ret; } -static int mptcp_pm_get_addr(u8 id, struct genl_info *info) +static int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_get_addr(id, info); - return mptcp_pm_nl_get_addr(id, info); + return mptcp_userspace_pm_get_addr(id, addr, info); + return mptcp_pm_nl_get_addr(id, addr, info); } int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) @@ -1853,7 +1856,7 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) if (ret < 0) return ret; - ret = mptcp_pm_get_addr(addr.addr.id, info); + ret = mptcp_pm_get_addr(addr.addr.id, &addr, info); return ret; } diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index da617d8bcc09..5c9f740bd9ac 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -629,7 +629,8 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, return ret; } -int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info) +int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info) { struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; @@ -661,26 +662,27 @@ int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info) lock_sock(sk); spin_lock_bh(&msk->pm.lock); entry = mptcp_userspace_pm_lookup_addr_by_id(msk, id); - if (!entry) { + if (entry) { + *addr = *entry; + ret = 0; + } + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); + + if (ret) { GENL_SET_ERR_MSG(info, "address not found"); - ret = -EINVAL; - goto unlock_fail; + goto fail; } - ret = mptcp_nl_fill_addr(msg, entry); + ret = mptcp_nl_fill_addr(msg, addr); if (ret) - goto unlock_fail; + goto fail; genlmsg_end(msg, reply); ret = genlmsg_reply(msg, info); - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); sock_put(sk); return ret; -unlock_fail: - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); fail: nlmsg_free(msg); out: diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 07cb80be98cb..4342be369914 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1127,7 +1127,8 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); -int mptcp_userspace_pm_get_addr(u8 id, struct genl_info *info); +int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, + struct genl_info *info); static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow) { From patchwork Tue Oct 8 09:58:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13826152 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 67AD618BC03 for ; Tue, 8 Oct 2024 09:58:31 +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=1728381511; cv=none; b=ZzmMSA/k5VWbfKp2TQtKyzkUSalBlptzTsJmRBOZ1I3c6edtwR8bLIZLnAqmLiLU3HVfo1nIYy0SQC0UmJXtzwAh763uyGWZYkz5g9cjiGus8sZzAWRoDD2/j3oWXyqrTaqvRnE7U2rl249497FEtqe+wWUhH0RgYT/Ht79Yycs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728381511; c=relaxed/simple; bh=PEzu/kqofVUIy99dAntCz+2sCUICoK+/v6lcaAG7pi4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ul2vbwz9mIp3kiG2abQ5S8jpyiyHwZz5QaLtp0X4PZ3hrPM8hZi0UYXODKk5bvu/vIVHourbvQAC1jDLdw4HfjrMcTn7sFGoajikJfIs4akvmBJB/EMD+m8mN3Xp6TFnRO8HAPCGK2MPgI6ZVBAbAHQ6bqdPRSx9QP2jkTt+OkY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LQsVADld; 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="LQsVADld" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B610CC4CEC7; Tue, 8 Oct 2024 09:58:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728381510; bh=PEzu/kqofVUIy99dAntCz+2sCUICoK+/v6lcaAG7pi4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LQsVADldtN5ulYeqOAzixAb0JqvyZBSIiDXdHSY3HQlH5ZR9QhZqk78j+CufNXzrI wZyVSf/MBQIcwlzA2h/ttpCjhoZj51vGB5lUeKjUMiY1GHvvp9MMcSCf0ytLhmJK+S /k+tejep3MMgKUGeqIsbH2Vveyfr6d6xHST80pEJZ0vFQvtNXU2i8JoCE5Dk8pja6K d1oZNPItGRbAwK+dC2BHvVaw3b5XkOyg2vQ/S+L0MCeVI2YWMEYwQzOczVoVKZeHG0 kcGzXOwzNC6aCGPp2j/2ir8nst45ndlflmdWR7ImJ6/QdfcnPRzrIRkdXCdP/HZBbT 6QlCnbGZEe+6Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 03/13] mptcp: reuse sending nlmsg code in get_addr Date: Tue, 8 Oct 2024 17:58:07 +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 With the previous commit, we can reuse the send_nlmsg() code in get_addr() interfaces between the netlink PM and userspace PM. They only need to implement their own get_addr() interfaces to hold the different locks, get the entry from the different lists, then release the locks. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 58 ++++++++++++++++++++-------------------- net/mptcp/pm_userspace.c | 33 ----------------------- 2 files changed, 29 insertions(+), 62 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 886fb7c1468d..8bc38a4cd278 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1796,21 +1796,7 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, { struct pm_nl_pernet *pernet = genl_info_pm_nl(info); struct mptcp_pm_addr_entry *entry; - struct sk_buff *msg; int ret = -EINVAL; - void *reply; - - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) - return -ENOMEM; - - reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0, - info->genlhdr->cmd); - if (!reply) { - GENL_SET_ERR_MSG(info, "not enough space in Netlink message"); - ret = -EMSGSIZE; - goto fail; - } spin_lock_bh(&pernet->lock); entry = __lookup_addr_by_id(pernet, id); @@ -1820,21 +1806,6 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, } spin_unlock_bh(&pernet->lock); - if (ret) { - GENL_SET_ERR_MSG(info, "address not found"); - goto fail; - } - - ret = mptcp_nl_fill_addr(msg, addr); - if (ret) - goto fail; - - genlmsg_end(msg, reply); - ret = genlmsg_reply(msg, info); - return ret; - -fail: - nlmsg_free(msg); return ret; } @@ -1850,13 +1821,42 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct mptcp_pm_addr_entry addr; + struct sk_buff *msg; + void *reply; int ret; ret = mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0, + info->genlhdr->cmd); + if (!reply) { + GENL_SET_ERR_MSG(info, "not enough space in Netlink message"); + ret = -EMSGSIZE; + goto fail; + } + ret = mptcp_pm_get_addr(addr.addr.id, &addr, info); + if (ret) { + GENL_SET_ERR_MSG(info, "address not found"); + goto fail; + } + + ret = mptcp_nl_fill_addr(msg, &addr); + if (ret) + goto fail; + + genlmsg_end(msg, reply); + ret = genlmsg_reply(msg, info); + return ret; + +fail: + nlmsg_free(msg); return ret; } diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 5c9f740bd9ac..4c4693c5aae9 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -634,10 +634,8 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, { struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; - struct sk_buff *msg; int ret = -EINVAL; struct sock *sk; - void *reply; msk = mptcp_userspace_pm_get_sock(info); if (!msk) @@ -645,20 +643,6 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, sk = (struct sock *)msk; - msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) { - ret = -ENOMEM; - goto out; - } - - reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0, - info->genlhdr->cmd); - if (!reply) { - GENL_SET_ERR_MSG(info, "not enough space in Netlink message"); - ret = -EMSGSIZE; - goto fail; - } - lock_sock(sk); spin_lock_bh(&msk->pm.lock); entry = mptcp_userspace_pm_lookup_addr_by_id(msk, id); @@ -669,23 +653,6 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, spin_unlock_bh(&msk->pm.lock); release_sock(sk); - if (ret) { - GENL_SET_ERR_MSG(info, "address not found"); - goto fail; - } - - ret = mptcp_nl_fill_addr(msg, addr); - if (ret) - goto fail; - - genlmsg_end(msg, reply); - ret = genlmsg_reply(msg, info); - sock_put(sk); - return ret; - -fail: - nlmsg_free(msg); -out: sock_put(sk); return ret; } From patchwork Tue Oct 8 09:58:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13826153 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 2C54218FDB7 for ; Tue, 8 Oct 2024 09:58:32 +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=1728381513; cv=none; b=Ep19x/zE1+7IGE7imvVYb/P3GzKUQOIdWVTKOaX5TaHXZXVLLZmj2roY8j3LWFe4TqUt0egHZS0PwApJ0hzXqu5olIZ7E9eyUkK3c/DiEP7mPB6kCNEaCix44XH0Wh+7bzGmBBUK7hf3LVi/jLuLyQ9V4I+YTaWJghBfatXLcV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728381513; c=relaxed/simple; bh=aHhY2tExyzXjbYpYfo1acXjacscqUnDaJUAFmLZfAHY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C/qQRMn7yAKidHzfmNNtXKDFnQHezPcPg/n9w0l5Q7Lar4PHhVLBIJywePxxStBGMzKm3vyCCnUHgyD9KGG84zEuEKkcNVGRFkn/SOnntDrrMp1S/0CgrwmaOeDsJldUjE6V2pIfosiPj9jYX2TR2JCAGWSDzxOuu2rNwfzzeCM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Vl+4A1Tc; 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="Vl+4A1Tc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F787C4CECC; Tue, 8 Oct 2024 09:58:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728381512; bh=aHhY2tExyzXjbYpYfo1acXjacscqUnDaJUAFmLZfAHY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vl+4A1TcD3SHV2miilW4OyrQM+E8clMvSC+V8mknwJ2yCBxarHO/VfJa8rcHufrVu cfoqOjQqPRVZdLroiVniPltI8d8uCSsHECsScrHeVrEoZbWkDJDGEn/sJd31Saen7/ 14JfyIGBdW4kb7+bg8yWYvm+nopsCazjKxekHUdyCoF0Ws9yawsF+QlQ/jNfzxdSry 9GOlMaMcyE1LxfII+l8CMKXfv5PQkAI/a5oQNXgdoFbsgdzPNhQLVTdTQM7+Uqg05f JozSpRMLKqV9Zggf4ORmJqBnubu96EBCLuvLRe/9mFmZ5DxQs4LWC+zsaw3KDhhzmY DZWcl/LgysaQA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 04/13] mptcp: change info of get_addr as const Date: Tue, 8 Oct 2024 17:58:08 +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 get_addr() interfeces will be invoked by dump_addr(), which using const parameters "info", so this patch changes "info" parameters of get_addr() as const too. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 9 ++++++--- net/mptcp/pm_userspace.c | 2 +- net/mptcp/protocol.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 8bc38a4cd278..2ab966393c55 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1792,12 +1792,15 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, } static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info) + const struct genl_info *info) { - struct pm_nl_pernet *pernet = genl_info_pm_nl(info); + struct net *net = genl_info_net(info); struct mptcp_pm_addr_entry *entry; + struct pm_nl_pernet *pernet; int ret = -EINVAL; + pernet = pm_nl_get_pernet(net); + spin_lock_bh(&pernet->lock); entry = __lookup_addr_by_id(pernet, id); if (entry) { @@ -1810,7 +1813,7 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, } static int mptcp_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info) + const struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) return mptcp_userspace_pm_get_addr(id, addr, info); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 4c4693c5aae9..373ff0186bee 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -630,7 +630,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, } int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info) + const struct genl_info *info) { struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 4342be369914..be2028ffebde 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1128,7 +1128,7 @@ bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info); + const struct genl_info *info); static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow) { From patchwork Tue Oct 8 09:58:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13826154 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 B5B2018C35A for ; Tue, 8 Oct 2024 09:58:34 +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=1728381514; cv=none; b=nAf30MfiWhBlBvO2fxRWZSqqaQGoNDkmQtlxrVnHmskAeIt6xqsMsVP4e8fun7WRZj9rpGGS+W02PxGW48cefZ6pIDlDYJ8YustNxOkGiPSmr92012cnDsCrBsOI7NUbymQqxmIR2EYbfA55MpZgmcaWdIKBAdwPetX09HlmOkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728381514; c=relaxed/simple; bh=8QCAb4ToExdilyQy6Bppll54+qw2gcRjAPPMFY8K6h0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DcBXlxEMXABThiUk6uKiPLWqTErCjm/uOeqJmvv9PQFkVnPM0nL8WloXz9yn4gGaT2dvySYLlZOD5pjHKP3/1GvRmK+ocwRxiIOCouPxfWOo9YeCdvuNUjL2QTAv8yLyfAEJHvcTv2SzJQSNt7Q+YX3JMzrZfdzINQ+0t0AG2sM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VdRCfZLn; 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="VdRCfZLn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69819C4CEC7; Tue, 8 Oct 2024 09:58:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728381514; bh=8QCAb4ToExdilyQy6Bppll54+qw2gcRjAPPMFY8K6h0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VdRCfZLnvOBtvxL8VRPQuwf8fRY8SuxH2ZJjmHg/Dgif4sLCPhZpznLVsxv5oEPUP Ilw7AMsOsQPXckEFBnC0p/Eh/z0DJoKRstW9mGB09d2qrA7tBSmoEQEuMb4saM7egr rowZJ8oweSIG7Q5D6z/p66cM4WU+3uXd1IRvzR9W8gTTULvjXLaQTiRIc7MJIgFd4X /tUMti2+Ow8nUacOFbQlV03Puwwtqny/NRjkSUMBYLpL+IU6GmyiaFYjnpmsG/xAJA La5z1vmk4Z6jVb8cK3Yfxu0r3O8Zyqb7xytUF0aVpyWKk+RhmAqzNBUPaaDEJLxHhF vJdt1YZ2lahYw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 05/13] mptcp: refactor dump_addr with id bitmap Date: Tue, 8 Oct 2024 17:58:09 +0800 Message-ID: <1e7ae17f94e8cc843e401460928b6ef24f1f50a4.1728381245.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 With the help of get_addr(), we can refactor dump_addr() interfaces to reuse send_nlmsg code between the netlink PM and userspace PM. The current dump_addr() flow looks like this: lock(); for_each_entry(entry) send_nlmsg(entry); unlock(); After holding the lock, get every entry by walking the address list, send each one looply, and finally release the lock. This set changes the process by copying the address list to an id bitmap while holding the lock, then release the lock immediately. After that, without locking, walking the copied id bitmap to get every copy of entry by using get_addr(), and send each one looply. This patch is the first part of refactoring dump_addr(). Without changing the position of the locks, the dump process is split into two parts: copying the ID bitmap first, and then traversing the ID bitmap, use lookup_addr_by_id() to get the entry, then send each one through nlmsg: lock(); for_each_entry(entry) set_bit(bitmap); for_each_bit(bitmap) { entry = lookup_addr_by_id(); send_nlmsg(entry); } unlock(); Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 6 ++++- net/mptcp/pm_userspace.c | 54 +++++++++++++++++++++++++++++----------- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 2ab966393c55..9d502ab4d91d 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1868,16 +1868,20 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, { struct net *net = sock_net(msg->sk); struct mptcp_pm_addr_entry *entry; + struct mptcp_id_bitmap *bitmap; struct pm_nl_pernet *pernet; int id = cb->args[0]; void *hdr; int i; + bitmap = (struct mptcp_id_bitmap *)cb->ctx; pernet = pm_nl_get_pernet(net); spin_lock_bh(&pernet->lock); + if (!id) + bitmap_copy(bitmap->map, pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { - if (test_bit(i, pernet->id_bitmap.map)) { + if (test_bit(i, bitmap->map)) { entry = __lookup_addr_by_id(pernet, i); if (!entry) break; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 373ff0186bee..2f1afb719ecf 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -582,6 +582,21 @@ int mptcp_userspace_pm_set_flags(struct genl_info *info) return ret; } +static int mptcp_userspace_pm_set_bitmap(struct mptcp_sock *msk, + struct mptcp_id_bitmap *bitmap) +{ + struct mptcp_pm_addr_entry *entry; + + list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + if (test_bit(entry->addr.id, bitmap->map)) + continue; + + __set_bit(entry->addr.id, bitmap->map); + } + + return 0; +} + int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { @@ -589,9 +604,11 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct mptcp_pm_addr_entry *entry; struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; + int id = cb->args[0]; int ret = -EINVAL; struct sock *sk; void *hdr; + int i; bitmap = (struct mptcp_id_bitmap *)cb->ctx; @@ -603,24 +620,33 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, lock_sock(sk); spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { - if (test_bit(entry->addr.id, bitmap->map)) - continue; + if (!id) + ret = mptcp_userspace_pm_set_bitmap(msk, bitmap); + for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { + if (test_bit(i, bitmap->map)) { + entry = mptcp_userspace_pm_lookup_addr_by_id(msk, i); + if (!entry) + break; + + if (id && entry->addr.id <= id) + continue; - hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, &mptcp_genl_family, - NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); - if (!hdr) - break; + hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, &mptcp_genl_family, + NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); + if (!hdr) + break; - if (mptcp_nl_fill_addr(msg, entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } + if (mptcp_nl_fill_addr(msg, entry) < 0) { + genlmsg_cancel(msg, hdr); + break; + } - __set_bit(entry->addr.id, bitmap->map); - genlmsg_end(msg, hdr); + id = entry->addr.id; + genlmsg_end(msg, hdr); + } } + cb->args[0] = id; spin_unlock_bh(&msk->pm.lock); release_sock(sk); ret = msg->len; From patchwork Tue Oct 8 09:58:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13826155 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 DB16A18BC03 for ; Tue, 8 Oct 2024 09:58:36 +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=1728381516; cv=none; b=h1kheECa1bRzLe7DYv3vBNLvZsDR+qy9LlLVqUJmoEH9xXxvntZ1We86cDJZFsdPBt9xWKjqFWJQMwOIqVyx8hQSjhGUTF3b7sJO0tk3jMohv7k9cbY+NR23WzzgD12k4siEmSg8z9NRHAv1O33kNmS8d1QCLtGvkURAggIJhHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728381516; c=relaxed/simple; bh=Qa09CNLFIWC3rTR+k0zQzrj9qeydL721G+2djdFNGBA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UBzdXX9EEIZBpkjCbgm+r9zVp0NAnkGVgmhBbSXtFZTTod1Yk59jUtezBfeMnYsglZ7A5xgcPgArXXOl1yuewdXWyrhb1nungYleZWuSGYLXgzJ67PKwAraDNCTmQAA6ct62cYVj6nA36oVXj/gEETJ1xA4N9PYXOQkqiWjVVzc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rcDU+tdw; 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="rcDU+tdw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42F1BC4CEC7; Tue, 8 Oct 2024 09:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728381516; bh=Qa09CNLFIWC3rTR+k0zQzrj9qeydL721G+2djdFNGBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rcDU+tdwdNOWgaCby0yt1cvt5NuLp4/p54VCSv4S0ADjN2NKwME2jHezQpydNEtV/ bj2tOAKg/vQyz67MBmAdpzV51yeRDbz6HHcUI97a9HXU+4bP4ilcvPB9/Bi6NO+nj1 cdCamfv+cJraXmMty+Ci1+zoPM6rinJQYi2QTumb4Dvw8Z/zs0K66Bgff8H/tUvvY8 f/NXzl9X6uu4igu1u/p0xelr+HPudJEv/jScsOYsCcfSSrltcg7ev7W6zPf36bsWqQ 5DQmU1BDQw7hygx6yZTRCz+ljOH8dgaYYsMyx9l6Kus7uoHGwWBCrfkegads01ILf2 QD88z/Z9feYZQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 06/13] mptcp: refactor dump_addr with get_addr Date: Tue, 8 Oct 2024 17:58:10 +0800 Message-ID: <1eff3615defa58a09e307874d3b30c6d6431d271.1728381245.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 is the second part of refactoring dump_addr(). With the help of get_addr(), only copy the address list to an id bitmap while holding the lock, then release the lock immediately. After that, without locking, walking the copied id bitmap to get every copy of entry by using get_addr(), and send each one looply: lock(); for_each_entry(entry) set_bit(bitmap); unlock(); for_each_bit(bitmap) { copy = get_addr(); send_nlmsg(copy); } Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 20 +++++++++++--------- net/mptcp/pm_userspace.c | 23 ++++++++++++----------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 9d502ab4d91d..bcee83306e40 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1866,8 +1866,9 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { + const struct genl_info *info = genl_info_dump(cb); struct net *net = sock_net(msg->sk); - struct mptcp_pm_addr_entry *entry; + struct mptcp_pm_addr_entry entry; struct mptcp_id_bitmap *bitmap; struct pm_nl_pernet *pernet; int id = cb->args[0]; @@ -1877,16 +1878,18 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, bitmap = (struct mptcp_id_bitmap *)cb->ctx; pernet = pm_nl_get_pernet(net); - spin_lock_bh(&pernet->lock); - if (!id) + if (!id) { + spin_lock_bh(&pernet->lock); bitmap_copy(bitmap->map, pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); + spin_unlock_bh(&pernet->lock); + } + for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { if (test_bit(i, bitmap->map)) { - entry = __lookup_addr_by_id(pernet, i); - if (!entry) + if (mptcp_pm_nl_get_addr(i, &entry, info)) break; - if (entry->addr.id <= id) + if (entry.addr.id <= id) continue; hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, @@ -1895,16 +1898,15 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, if (!hdr) break; - if (mptcp_nl_fill_addr(msg, entry) < 0) { + if (mptcp_nl_fill_addr(msg, &entry) < 0) { genlmsg_cancel(msg, hdr); break; } - id = entry->addr.id; + id = entry.addr.id; genlmsg_end(msg, hdr); } } - spin_unlock_bh(&pernet->lock); cb->args[0] = id; return msg->len; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 2f1afb719ecf..ad011a4fad4e 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -601,7 +601,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { const struct genl_info *info = genl_info_dump(cb); - struct mptcp_pm_addr_entry *entry; + struct mptcp_pm_addr_entry entry; struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; int id = cb->args[0]; @@ -618,17 +618,20 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, sk = (struct sock *)msk; - lock_sock(sk); - spin_lock_bh(&msk->pm.lock); - if (!id) + if (!id) { + lock_sock(sk); + spin_lock_bh(&msk->pm.lock); ret = mptcp_userspace_pm_set_bitmap(msk, bitmap); + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); + } + for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { if (test_bit(i, bitmap->map)) { - entry = mptcp_userspace_pm_lookup_addr_by_id(msk, i); - if (!entry) + if (mptcp_userspace_pm_get_addr(i, &entry, info)) break; - if (id && entry->addr.id <= id) + if (id && entry.addr.id <= id) continue; hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, @@ -637,18 +640,16 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, if (!hdr) break; - if (mptcp_nl_fill_addr(msg, entry) < 0) { + if (mptcp_nl_fill_addr(msg, &entry) < 0) { genlmsg_cancel(msg, hdr); break; } - id = entry->addr.id; + id = entry.addr.id; genlmsg_end(msg, hdr); } } cb->args[0] = id; - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); ret = msg->len; sock_put(sk); From patchwork Tue Oct 8 09:58:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13826156 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 9696818BC03 for ; Tue, 8 Oct 2024 09:58:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728381518; cv=none; b=Fi8vn5MgyfqK+wQFoLC4dgfRMQ/FGofx1wBdm2f8o2/vuccXuUBJSZFPpcB6k0wQbp+3c+nN4ag38fm7n01DDvpwGBNqz0B82rwmVCv04dXa6mtU+TkdlSP8WEy0XUB8CjQkDGXWH8pH5ZnYjJzPhYcLzNk23/5ZXpQsBbHNEMs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728381518; c=relaxed/simple; bh=yKHlvMtyNVXIKlhb728cLdgX6pfxlFojxlZbKIbyfUc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NZ3yK6M+Svuunet2gqlxcSiPaafYeFRpCS7IUxxegE3Ozj2gvTwql7vHppovjMMUmJCxpRoZtca9VENCpcFlRnA2PdG7gvDAvi5o/yyRVd9Fw/FDN8l+qGX4DlFtyU/M5LcUsBNJTbTe8FFBW3wIcAKCLSDIIKniYtKft73/raU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p2tsg/pJ; 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="p2tsg/pJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 033A8C4CECC; Tue, 8 Oct 2024 09:58:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728381518; bh=yKHlvMtyNVXIKlhb728cLdgX6pfxlFojxlZbKIbyfUc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p2tsg/pJMjcV0t0b5xatO0d7bAmaisICofIwjDAeCUY20T4dClr+HZ1TA8R6IGUTO xdBY5YlHQZZCW5RSP2qERB+4VBUCS/w6Cf3Ta3x6N5AC6TKX958FegxnjirSbOw2RU GOp7D/RWQyPP8tbAT8f0NS+rog86LbGChikk/jkfphFBQX/Dvat4fKs6OjIGqO37Xw a8kLGOnkr8GK982rRV3ltwkxNGp4eYuXEz1IBtEOAkNomR5ItMqZ3Ne/1WZYxKzLnV D/Qkv7D9SpuY+xM/72s4XwfuIrl1P/MS+9EQDYvAgbaOWlT21L/BDa+PqBPe19+/pc JrrVjjFhoDS2Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 07/13] mptcp: reuse sending nlmsg code in dump_addr Date: Tue, 8 Oct 2024 17:58:11 +0800 Message-ID: <096eb4419b3467b4fd6c8c2d164e9457eb00ae2b.1728381245.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 With the previous commit, we can reuse the send_nlmsg() code in dump_addr interfaces between the netlink PM and userspace PM. They only need to implement their own dump_addr() interfaces to hold the different locks, copy the different address lists to an id bitmap, then release the locks. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 56 +++++++++++++++++++++------------------- net/mptcp/pm_userspace.c | 50 +++++------------------------------ net/mptcp/protocol.h | 4 +-- 3 files changed, 38 insertions(+), 72 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index bcee83306e40..15ec8a193279 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1863,33 +1863,50 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) return ret; } -static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb) +static int mptcp_pm_nl_dump_addr(struct mptcp_id_bitmap *bitmap, + const struct genl_info *info) +{ + struct net *net = genl_info_net(info); + struct pm_nl_pernet *pernet; + + pernet = pm_nl_get_pernet(net); + + spin_lock_bh(&pernet->lock); + bitmap_copy(bitmap->map, pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); + spin_unlock_bh(&pernet->lock); + + return 0; +} + +static int mptcp_pm_dump_addr(struct mptcp_id_bitmap *bitmap, + const struct genl_info *info) +{ + if (info->attrs[MPTCP_PM_ATTR_TOKEN]) + return mptcp_userspace_pm_dump_addr(bitmap, info); + return mptcp_pm_nl_dump_addr(bitmap, info); +} + +int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, + struct netlink_callback *cb) { const struct genl_info *info = genl_info_dump(cb); - struct net *net = sock_net(msg->sk); struct mptcp_pm_addr_entry entry; struct mptcp_id_bitmap *bitmap; - struct pm_nl_pernet *pernet; int id = cb->args[0]; void *hdr; int i; bitmap = (struct mptcp_id_bitmap *)cb->ctx; - pernet = pm_nl_get_pernet(net); - if (!id) { - spin_lock_bh(&pernet->lock); - bitmap_copy(bitmap->map, pernet->id_bitmap.map, MPTCP_PM_MAX_ADDR_ID + 1); - spin_unlock_bh(&pernet->lock); - } + if (!id) + mptcp_pm_dump_addr(bitmap, info); for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { if (test_bit(i, bitmap->map)) { - if (mptcp_pm_nl_get_addr(i, &entry, info)) + if (mptcp_pm_get_addr(i, &entry, info)) break; - if (entry.addr.id <= id) + if (id && entry.addr.id <= id) continue; hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, @@ -1912,21 +1929,6 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, return msg->len; } -static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) -{ - const struct genl_info *info = genl_info_dump(cb); - - if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_dump_addr(msg, cb); - return mptcp_pm_nl_dump_addr(msg, cb); -} - -int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, - struct netlink_callback *cb) -{ - return mptcp_pm_dump_addr(msg, cb); -} - static int parse_limit(struct genl_info *info, int id, unsigned int *limit) { struct nlattr *attr = info->attrs[id]; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index ad011a4fad4e..8858877d82b0 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -597,20 +597,12 @@ static int mptcp_userspace_pm_set_bitmap(struct mptcp_sock *msk, return 0; } -int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb) +int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap, + const struct genl_info *info) { - const struct genl_info *info = genl_info_dump(cb); - struct mptcp_pm_addr_entry entry; - struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; - int id = cb->args[0]; int ret = -EINVAL; struct sock *sk; - void *hdr; - int i; - - bitmap = (struct mptcp_id_bitmap *)cb->ctx; msk = mptcp_userspace_pm_get_sock(info); if (!msk) @@ -618,39 +610,11 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, sk = (struct sock *)msk; - if (!id) { - lock_sock(sk); - spin_lock_bh(&msk->pm.lock); - ret = mptcp_userspace_pm_set_bitmap(msk, bitmap); - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); - } - - for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { - if (test_bit(i, bitmap->map)) { - if (mptcp_userspace_pm_get_addr(i, &entry, info)) - break; - - if (id && entry.addr.id <= id) - continue; - - hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid, - cb->nlh->nlmsg_seq, &mptcp_genl_family, - NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); - if (!hdr) - break; - - if (mptcp_nl_fill_addr(msg, &entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } - - id = entry.addr.id; - genlmsg_end(msg, hdr); - } - } - cb->args[0] = id; - ret = msg->len; + lock_sock(sk); + spin_lock_bh(&msk->pm.lock); + ret = mptcp_userspace_pm_set_bitmap(msk, bitmap); + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); sock_put(sk); return ret; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index be2028ffebde..0a4edb7ee1ed 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1125,8 +1125,8 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_in bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); -int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, - struct netlink_callback *cb); +int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap, + const struct genl_info *info); int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, const struct genl_info *info); From patchwork Tue Oct 8 09:58:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13826157 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 70F73175D32 for ; Tue, 8 Oct 2024 09:58: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=1728381520; cv=none; b=od+V9Wq3CHrwE2kXKQEvlPUXpqL1KpxA5qFmqCVpRof1uuuvBGhSVP1DIKwkxs8rRK8Vyrg80Cju6vyGBafPv0Ec9rtnapAr4tPqAlCpX9nIWWSpOTt5tu4fOD0uzRxcCev16vskj+qBjIxxb7pjyX4+1W2wl3iJj1Q2gBHKqLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728381520; c=relaxed/simple; bh=qLb7lc0Dkl+HmK7OhQ/VpkagzD4Mzq0RXcLwu3voLRI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GbdFva3nctvqSnnR+TwIypGtF+7cM5b+7fuxbzRuCzzwaGB4OhOqpvTrQ8YVoEaGZTKVJaAbOOb1YvBCe5S6nxLecNLH0TuEPc9yG7wPnxf3q47S/6WmnCHBX4pzILzMsdE20+hXb2TlTfBjSDw07zBjZS7C6Ah6REK8Feqc4F4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nVKpSURe; 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="nVKpSURe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2CEEC4CEC7; Tue, 8 Oct 2024 09:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728381520; bh=qLb7lc0Dkl+HmK7OhQ/VpkagzD4Mzq0RXcLwu3voLRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nVKpSURe30b6Jr2PShq6/sT36xhOeV3oOCTSZiQDvBpYZdsZpwiYNSYINEdOmFkzp VElgjdGvDqibgJiFCWxd27tD903NKVnwBfvEow01mnqO1S/Nc02mGXPV49hkue5pWY mqC+UKsnLpAlYlDPNYpbW1KmejOGQAWJUiDvYR3CFIV6ZhGIGjAAO0wHxf5EGbAs4G qp2/ZCOgR23XyrxV08cd8HfQjkd+CaYgGRdYjE9b0Fbwi9jvSg/1ia0/ejklp4jba+ EYOKmzRtI8IfRDeY5tPU5mwrcDvs86ofHXQoKafsMniC7glByLgenEsqtG6iNNbc7A VzzDRMoYVkV0Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 08/13] mptcp: add loc and rem for set_flags Date: Tue, 8 Oct 2024 17:58:12 +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 updates the interfaces set_flags to reduce repetitive code, adds two more parameters "loc" and "rem" for them. These addresses are parsed in public helper mptcp_pm_nl_set_flags_doit(), then pass them to mptcp_pm_nl_set_flags() and mptcp_userspace_pm_set_flags(). Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 38 ++++++++++++++++++++++++++------------ net/mptcp/pm_userspace.c | 26 +++++++------------------- net/mptcp/protocol.h | 4 +++- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 15ec8a193279..2a995e60ce87 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -2044,25 +2044,21 @@ static int mptcp_nl_set_flags(struct net *net, return ret; } -static int mptcp_pm_nl_set_flags(struct genl_info *info) +static int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *loc, + struct mptcp_addr_info *rem, + struct genl_info *info) { - struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, }; - struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; u8 changed, mask = MPTCP_PM_ADDR_FLAG_BACKUP | MPTCP_PM_ADDR_FLAG_FULLMESH; + struct mptcp_pm_addr_entry addr = *loc; struct net *net = genl_info_net(info); struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; u8 lookup_by_id = 0; u8 bkup = 0; - int ret; pernet = pm_nl_get_pernet(net); - ret = mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - return ret; - if (addr.addr.family == AF_UNSPEC) { lookup_by_id = 1; if (!addr.addr.id) { @@ -2098,16 +2094,34 @@ static int mptcp_pm_nl_set_flags(struct genl_info *info) return 0; } -static int mptcp_pm_set_flags(struct genl_info *info) +static int mptcp_pm_set_flags(struct mptcp_pm_addr_entry *loc, + struct mptcp_addr_info *rem, + struct genl_info *info) { if (info->attrs[MPTCP_PM_ATTR_TOKEN]) - return mptcp_userspace_pm_set_flags(info); - return mptcp_pm_nl_set_flags(info); + 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) { - return mptcp_pm_set_flags(info); + struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, }; + struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; + struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; + struct mptcp_addr_info rem = { .family = AF_UNSPEC, }; + int ret; + + ret = mptcp_pm_parse_entry(attr, info, false, &loc); + if (ret < 0) + return ret; + + if (attr_rem) { + ret = mptcp_pm_parse_addr(attr_rem, info, &rem); + if (ret < 0) + return ret; + } + + return mptcp_pm_set_flags(&loc, &rem, info); } static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gfp_t gfp) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 8858877d82b0..5175c30bcd64 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -536,12 +536,10 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *skb, struct genl_info *info return err; } -int mptcp_userspace_pm_set_flags(struct genl_info *info) +int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc, + struct mptcp_addr_info *rem, + struct genl_info *info) { - struct mptcp_pm_addr_entry loc = { .addr = { .family = AF_UNSPEC }, }; - struct nlattr *attr_rem = info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; - struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR]; - struct mptcp_addr_info rem = { .family = AF_UNSPEC, }; struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; @@ -553,28 +551,18 @@ int mptcp_userspace_pm_set_flags(struct genl_info *info) sk = (struct sock *)msk; - ret = mptcp_pm_parse_entry(attr, info, false, &loc); - if (ret < 0) - goto set_flags_err; - - if (attr_rem) { - ret = mptcp_pm_parse_addr(attr_rem, info, &rem); - if (ret < 0) - goto set_flags_err; - } - - if (loc.addr.family == AF_UNSPEC || - rem.family == AF_UNSPEC) { + if (loc->addr.family == AF_UNSPEC || + rem->family == AF_UNSPEC) { GENL_SET_ERR_MSG(info, "invalid address families"); ret = -EINVAL; goto set_flags_err; } - if (loc.flags & MPTCP_PM_ADDR_FLAG_BACKUP) + if (loc->flags & MPTCP_PM_ADDR_FLAG_BACKUP) bkup = 1; lock_sock(sk); - ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem, bkup); + ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc->addr, rem, bkup); release_sock(sk); set_flags_err: diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 0a4edb7ee1ed..3dc113ced4e8 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1035,7 +1035,9 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk, struct mptcp_pm_add_entry * mptcp_lookup_anno_list_by_saddr(const struct mptcp_sock *msk, const struct mptcp_addr_info *addr); -int mptcp_userspace_pm_set_flags(struct genl_info *info); +int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *loc, + struct mptcp_addr_info *rem, + struct genl_info *info); int mptcp_pm_announce_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, bool echo); From patchwork Tue Oct 8 09:58:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13826158 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 C603D18C35A for ; Tue, 8 Oct 2024 09:58:41 +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=1728381521; cv=none; b=MJR8YHZoO++Jow0RzxFy8XzigVfTqeDESkH+QWKW96Yd7cavwmy70LM4vPwBY0hwKMF/RwVRiesxthvjC3US6nbk8CHyY+isKCBW+itBooPD36KnLKOgRrGz1WpnloSCfWUZlZDzDO4/GYqxb1SmEKFHgW/RXcuRZAyjNb4CXNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728381521; c=relaxed/simple; bh=IrXmD0EwwQZH9xAQZuaDk1MAKZOn7dma1hhi1zlHJug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bxMl4dMQDIP9C7oj2XvLH4/UdoqhbL+XzPL62oNbeq5U6bCaeOI6m77UVVh/7uQ61AdIL0pT6YZwoON/Qc2suc6GBdHpVcirkp27THXU808b7LQvHurG50CaaMRQmOXixQ6HjpGgX4wRuPvq0EuS9pNLanPboPXY1gavXAfQ7Z4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XlaL3d23; 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="XlaL3d23" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAC4EC4CEC7; Tue, 8 Oct 2024 09:58:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728381521; bh=IrXmD0EwwQZH9xAQZuaDk1MAKZOn7dma1hhi1zlHJug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XlaL3d231lErn40FWWdRVS+sAVGEtsiJ7tHVG6F2nIhXEkzlRTQeefom+HODqBiKR gjAFrmPr1VLLsGUMWFcc4mCFcC1LcWIlAxizReFqFSOBESZB2+xD2cT/w8jRMbbX56 yJ8F9q9P3YylL5iSE0DFkgRgJ1t1ly+zh3T+qvqxO7pu4up8+YfRv2pC3119S8XKu3 g147mGqUIbi+OtGi6G52/UHbYFJC1Z5By4/N1h7t+eQFGVw94xi/q/lhdloqn2mwc3 MK4ocrwP+Negi+gYuD25rJIyDFzDIs4WuPH1T1qJUiSz3HbBkkGJHsNHEJPiEeXKmu b0zIKGk2Mg8ZQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 09/13] mptcp: update address type of get_local_id Date: Tue, 8 Oct 2024 17:58:13 +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 The following code in mptcp_userspace_pm_get_local_id() that assigns "skc" to "new_entry" is not allowed in BPF: memset(&new_entry, 0, sizeof(struct mptcp_pm_addr_entry)); new_entry.addr = *skc; new_entry.addr.id = 0; new_entry.flags = MPTCP_PM_ADDR_FLAG_IMPLICIT; To solve the issue, this patch moves this assignment to "new_entry" forward to mptcp_pm_get_local_id(), and then passing "new_entry" as a parameter to both mptcp_pm_nl_get_local_id() and mptcp_userspace_pm_get_local_id(). Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 10 ++++++++-- net/mptcp/pm_netlink.c | 11 +++-------- net/mptcp/pm_userspace.c | 17 ++++++----------- net/mptcp/protocol.h | 4 ++-- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index c051c1ec4de4..4046e6727cb6 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -404,6 +404,7 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) { struct mptcp_addr_info skc_local; struct mptcp_addr_info msk_local; + struct mptcp_pm_addr_entry local; if (WARN_ON_ONCE(!msk)) return -1; @@ -416,9 +417,14 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) if (mptcp_addresses_equal(&msk_local, &skc_local, false)) return 0; + memset(&local, 0, sizeof(struct mptcp_pm_addr_entry)); + local.addr = skc_local; + local.addr.id = 0; + local.flags = MPTCP_PM_ADDR_FLAG_IMPLICIT; + if (mptcp_pm_is_userspace(msk)) - return mptcp_userspace_pm_get_local_id(msk, &skc_local); - return mptcp_pm_nl_get_local_id(msk, &skc_local); + return mptcp_userspace_pm_get_local_id(msk, &local); + return mptcp_pm_nl_get_local_id(msk, &local); } bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 2a995e60ce87..e73afb1e406d 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1136,7 +1136,7 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk, return err; } -int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc) +int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local) { struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; @@ -1145,7 +1145,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc pernet = pm_nl_get_pernet_from_msk(msk); rcu_read_lock(); - entry = __lookup_addr(pernet, skc); + entry = __lookup_addr(pernet, &local->addr); if (entry) ret = entry->addr.id; rcu_read_unlock(); @@ -1157,12 +1157,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc if (!entry) return -ENOMEM; - entry->addr = *skc; - entry->addr.id = 0; - entry->addr.port = 0; - entry->ifindex = 0; - entry->flags = MPTCP_PM_ADDR_FLAG_IMPLICIT; - entry->lsk = NULL; + *entry = *local; ret = mptcp_pm_nl_append_new_local_addr(pernet, entry, true); if (ret < 0) kfree(entry); diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 5175c30bcd64..6685c76fe151 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -131,27 +131,22 @@ mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int id) } int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, - struct mptcp_addr_info *skc) + struct mptcp_pm_addr_entry *local) { - struct mptcp_pm_addr_entry *entry = NULL, new_entry; + struct mptcp_pm_addr_entry *entry = NULL; __be16 msk_sport = ((struct inet_sock *) inet_sk((struct sock *)msk))->inet_sport; spin_lock_bh(&msk->pm.lock); - entry = mptcp_userspace_pm_lookup_addr(msk, skc); + entry = mptcp_userspace_pm_lookup_addr(msk, &local->addr); spin_unlock_bh(&msk->pm.lock); if (entry) return entry->addr.id; - memset(&new_entry, 0, sizeof(struct mptcp_pm_addr_entry)); - new_entry.addr = *skc; - new_entry.addr.id = 0; - new_entry.flags = MPTCP_PM_ADDR_FLAG_IMPLICIT; - - if (new_entry.addr.port == msk_sport) - new_entry.addr.port = 0; + if (local->addr.port == msk_sport) + local->addr.port = 0; - return mptcp_userspace_pm_append_new_local_addr(msk, &new_entry, true); + return mptcp_userspace_pm_append_new_local_addr(msk, local, true); } bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 3dc113ced4e8..da6341008aa9 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1122,8 +1122,8 @@ bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, const struct sk_buff *skb, bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining, struct mptcp_rm_list *rm_list); int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); -int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc); -int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc); +int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local); +int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local); bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); From patchwork Tue Oct 8 09:58:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13826159 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 1A191175D32 for ; Tue, 8 Oct 2024 09:58:43 +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=1728381524; cv=none; b=Gw9LWqfJTAQppMx197zeTebdSdIpVQi0SZbuYY4Vf8jVWs9eGmLL0l4OAx2tYP+bZ8qlBNC+XwlEiCyuf7R3/ZWq7PGMFoWYWohDVlTrRrX9RD8qtE0ll3rz6DQx316mqU20uhwXFKvDNMyZrz2uM8z31QfJvrWfKce+4WCiPYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728381524; c=relaxed/simple; bh=sqvsGb9jlB9GIFEuQkxJkFlXXAUn3U/WBE17ShcHNiE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MSKus82Q7Mo7yBQm6ml9WLz7K4tfSz9NXuKf84aXRWRdCqpZtOcmUZGJbnDOHS4dpt19mlRutztiB8IZ69/MsIB5oV//iqWzK+aE/VnQtMaV2kdu9nrCAvLMVRhUk1YpdQXjgm46Zk7adNbsu5QCxhIjZHwoGUvih7ix893izV8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jfvL0X5N; 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="jfvL0X5N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 530ECC4CEC7; Tue, 8 Oct 2024 09:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728381523; bh=sqvsGb9jlB9GIFEuQkxJkFlXXAUn3U/WBE17ShcHNiE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jfvL0X5Nz6WmRZFsZru4V+7NOYXPvFdNjwRONMtH9lPi2num0XSzpzYWvV/C26Mo7 H8VDQuhHWno4Wwb0nF2t3H9gbrxzQIIvqdmTdg4raHUJJvgNaV41GNLy48FTGvRp04 7qPGAbgR3UISZAYiSX+AkI8/lVW2F7Bpx/GdjobklXgpvEKrC5rB7i5k0kVlpITBoD vKYBNw2jPx7MU8P/o0dWSq//M3Vz/irRar/ryn6YC14GOAWy4aVC1jF04EJhQbEDhF YVm3cGtePcAbHI/dN4BGYJlPSeHZWCeLWJoXk4tgVOhinLS57jV8f44+vR+FSKyjTA 02laLZnc2aTDQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 10/13] mptcp: change is_backup interfaces as get_flags Date: Tue, 8 Oct 2024 17:58:14 +0800 Message-ID: <4c31526f9c517d3a551451e2f2be5ae51f2244dd.1728381245.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 is_backup() interface of path manager is not very common. A more common approach is to add a get_flags() interface to obtain the flags value of a given address. Then is_backup() can be implemented through get_flags() by test whether backup flag is set in the flags value. Signed-off-by: Geliang Tang --- net/mptcp/pm.c | 7 +++++-- net/mptcp/pm_netlink.c | 8 ++++---- net/mptcp/pm_userspace.c | 10 +++++----- net/mptcp/protocol.h | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c index 4046e6727cb6..d2ddf467dcce 100644 --- a/net/mptcp/pm.c +++ b/net/mptcp/pm.c @@ -430,13 +430,16 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc) bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc) { struct mptcp_addr_info skc_local; + u8 flags; mptcp_local_address((struct sock_common *)skc, &skc_local); if (mptcp_pm_is_userspace(msk)) - return mptcp_userspace_pm_is_backup(msk, &skc_local); + flags = mptcp_userspace_pm_get_flags(msk, &skc_local); + else + flags = mptcp_pm_nl_get_flags(msk, &skc_local); - return mptcp_pm_nl_is_backup(msk, &skc_local); + return !!(flags & MPTCP_PM_ADDR_FLAG_BACKUP); } void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index e73afb1e406d..4de3e0060af1 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1165,19 +1165,19 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry return ret; } -bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc) +u8 mptcp_pm_nl_get_flags(struct mptcp_sock *msk, struct mptcp_addr_info *skc) { struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk); struct mptcp_pm_addr_entry *entry; - bool backup = false; + u8 flags = 0; rcu_read_lock(); entry = __lookup_addr(pernet, skc); if (entry) - backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); + flags = entry->flags; rcu_read_unlock(); - return backup; + return flags; } #define MPTCP_PM_CMD_GRP_OFFSET 0 diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 6685c76fe151..50b1aea7a719 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -149,19 +149,19 @@ int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, return mptcp_userspace_pm_append_new_local_addr(msk, local, true); } -bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, - struct mptcp_addr_info *skc) +u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, + struct mptcp_addr_info *skc) { struct mptcp_pm_addr_entry *entry; - bool backup = false; + u8 flags = 0; spin_lock_bh(&msk->pm.lock); entry = mptcp_userspace_pm_lookup_addr(msk, skc); if (entry) - backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP); + flags = entry->flags; spin_unlock_bh(&msk->pm.lock); - return backup; + return flags; } static struct mptcp_sock *mptcp_userspace_pm_get_sock(const struct genl_info *info) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index da6341008aa9..16a51eb4c585 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1125,8 +1125,8 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local); int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *local); bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc); -bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); -bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc); +u8 mptcp_pm_nl_get_flags(struct mptcp_sock *msk, struct mptcp_addr_info *skc); +u8 mptcp_userspace_pm_get_flags(struct mptcp_sock *msk, struct mptcp_addr_info *skc); int mptcp_userspace_pm_dump_addr(struct mptcp_id_bitmap *bitmap, const struct genl_info *info); int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, From patchwork Tue Oct 8 09:58:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13826160 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 60FD717C21E for ; Tue, 8 Oct 2024 09:58: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=1728381525; cv=none; b=ExjfV4i6aRjB/wIBjHukDgcc/5fTDbZoHOGssmO15sE6gCjY0Dal/PLozwC+sdZF9/dDxRLexB/9X4LftM2U4bwspdc+NPTBq9qV4yDIMhKF7g827jc0ner2ZEUWb5MIRwu8sAgMhH4TpnaTVxPr1ruDvaGnZ8Vg6C1X3D4HDRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728381525; c=relaxed/simple; bh=Vgmg8a6K8iVpjllsRYvZXr5hm6ZiY+oZFMBddg6YNeo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LGWPG+Mp9KcQ97TFWzB8TI/Z+rGI0PsM7FfAhNJrJ9yVGKRUxUZfAx6dtzN3wyOoB10T1wrQufTSB71DYH+ZLwrKtnSnaJZkWDy1MmkZUwK4tIXpXJNGN29/RzomdXSkSlYJiPg7gJPz2AhO1TpP1Upzw6jjFWQLu5lP3LvreJo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uQ6NidVo; 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="uQ6NidVo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CBF8C4CECD; Tue, 8 Oct 2024 09:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728381525; bh=Vgmg8a6K8iVpjllsRYvZXr5hm6ZiY+oZFMBddg6YNeo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uQ6NidVojKn2REAazzAdplKxy7XThnum9cdABlZw/Yhx8Yi2JR6Ht8nXLj+QwIwiv vQx7d8YNZqSySmduzvzcqrxyuY//U2+3gf2viuEHR7w1pw8k0imhFK4HSFjaIlyGr8 lQkXbHdVWBP9aeJe2Lh78jPgsa6SQf4qkcxgBG4Kalz6aGujFFVh1BBItu5sQGkAf/ ZI0DKfNt3/6R1PxMVrnQQD7Q1r62zaP/6RiAGrSzq3ZF/kHLhRWUBfDvCipbZU8n6p r21UEh/UZEd5Q8qRyZudsPRg+gqJlOtff3NCOn1oa/f2AFMNxdxtySRLCOyiX7niLC aYSWS5TrI0FQw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 11/13] mptcp: hold pm lock when deleting entry Date: Tue, 8 Oct 2024 17:58:15 +0800 Message-ID: <0d59dc868a22ce07619ffa503b489a6ccf179fc6.1728381245.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 When traversing userspace_pm_local_addr_list and deleting an entry from it in mptcp_pm_nl_remove_doit(), msk->pm.lock should be held. Fixes: d9a4594edabf ("mptcp: netlink: Add MPTCP_PM_CMD_REMOVE") Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 50b1aea7a719..05ad0d17ea81 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -310,14 +310,17 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) lock_sock(sk); + spin_lock_bh(&msk->pm.lock); match = mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); if (!match) { GENL_SET_ERR_MSG(info, "address with specified id not found"); + spin_unlock_bh(&msk->pm.lock); release_sock(sk); goto out; } list_move(&match->list, &free_list); + spin_unlock_bh(&msk->pm.lock); mptcp_pm_remove_addrs(msk, &free_list); From patchwork Tue Oct 8 09:58:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13826161 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 2DC8A18C922 for ; Tue, 8 Oct 2024 09:58: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=1728381527; cv=none; b=Nl+AuPD+vh7A+XJd3q98Dbkdkl28mYr+VwdqTvGO4qfWFJqAkpQKGxuA9KuMJIKlXlxzaxP3yXZFXbR+Oj8dENZICxQn4PFxn+lNleCe3GmTW8PuwT8eowRJ7lWVHg7E3LQN4oEORcgiMaUXebdJsnT32RcLRtTxdmieLtyjemY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728381527; c=relaxed/simple; bh=3TEaDCpeIFOzPpIRF2HS5WqzoIr5eq6TGeiwz9Ynfvs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fEd/WxArPaVipvwWZ5ajK33vhzk5T179AsfO2Mzxw+NQSvXwol5mVDbtGwFyqfFDjyriIbIu6nBEc1wkyLnLud0nX2FIn8oTpsgkpzom7BKv7zXQoz+yqRXX2IDdkEv0xzggJgDjBvL7ffhHJwZiYDna1FrkcczbZ1bVMjzV/XQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J4MgN9Ba; 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="J4MgN9Ba" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5679C4CECC; Tue, 8 Oct 2024 09:58:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728381527; bh=3TEaDCpeIFOzPpIRF2HS5WqzoIr5eq6TGeiwz9Ynfvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J4MgN9BaefY2N2AtZybHFazU8yCSA/L/hBPj5BfSaiMhFRGYzJ458R2oJ4Les69I/ EsWOaRoy0p0g04qAv3uIPfYDfYoSR19PjeFFCuOipssBJXRf5hbrpI95BmJOyLX+c2 Mo5q37wWtirF+7QGahcHGzYgxv9/1bRG7/uVzeyybaT3mQ5jBXXYynZ5zFMYSAb/gM ZdmPEJd6EMd+9HbTvfJfq2zC9FayUfumBPr/DMCTj+uQLgZzmGEkJSK6YyzzQJwnWk 9c3XFaQEwjxX8n/Dg2dIOKh+TGWHCoFUD+ZO7gN47eAsi+yG1nbWVPxq1Ktm3xJmRK 3cPY3sZF6w0xw== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 12/13] mptcp: rename mptcp_pm_remove_addrs Date: Tue, 8 Oct 2024 17:58:16 +0800 Message-ID: <0f3f63d984ac169f1587c0dc13b8c2fd66ed72d1.1728381245.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_pm_remove_addrs() actually only deletes one address, which does not match its name. This patch renames it to mptcp_pm_remove_addr_entry() and changes the parameter "rm_list" to "entry". Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 24 ++++++++++-------------- net/mptcp/pm_userspace.c | 2 +- net/mptcp/protocol.h | 3 ++- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 4de3e0060af1..b7effacb5043 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1628,26 +1628,22 @@ int mptcp_pm_nl_del_addr_doit(struct sk_buff *skb, struct genl_info *info) } /* Called from the userspace PM only */ -void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_list) +void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *entry) { struct mptcp_rm_list alist = { .nr = 0 }; - struct mptcp_pm_addr_entry *entry; int anno_nr = 0; - list_for_each_entry(entry, rm_list, list) { - if (alist.nr >= MPTCP_RM_IDS_MAX) - break; - - /* only delete if either announced or matching a subflow */ - if (remove_anno_list_by_saddr(msk, &entry->addr)) - anno_nr++; - else if (!lookup_subflow_by_saddr(&msk->conn_list, - &entry->addr)) - continue; + /* only delete if either announced or matching a subflow */ + if (remove_anno_list_by_saddr(msk, &entry->addr)) + anno_nr++; + else if (!lookup_subflow_by_saddr(&msk->conn_list, + &entry->addr)) + goto out; - alist.ids[alist.nr++] = entry->addr.id; - } + alist.ids[alist.nr++] = entry->addr.id; +out: if (alist.nr) { spin_lock_bh(&msk->pm.lock); msk->pm.add_addr_signaled -= anno_nr; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 05ad0d17ea81..9477c36d3284 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -322,7 +322,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) list_move(&match->list, &free_list); spin_unlock_bh(&msk->pm.lock); - mptcp_pm_remove_addrs(msk, &free_list); + mptcp_pm_remove_addr_entry(msk, match); release_sock(sk); diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 16a51eb4c585..9bbc105771e1 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1042,7 +1042,8 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk, const struct mptcp_addr_info *addr, bool echo); int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list); -void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_list); +void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *entry); void mptcp_free_local_addr_list(struct mptcp_sock *msk); From patchwork Tue Oct 8 09:58:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13826162 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 EEB4518C922 for ; Tue, 8 Oct 2024 09:58:48 +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=1728381529; cv=none; b=JoaXOeoF/qg2dJF6vUZLmAZVQPOmoiwx5YzxiD3u3qserNLGTM30WgaHvgX6H8aJUr9k5hdryW+SPTgA0zIKmq81H00c5LCiNEFbAIYFoOgChjEOczQmq+UHzX/hXuNy8yMzaDV14R4JtW5zibr1V/IfZXorKQ0DvAOQFBDOUNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728381529; c=relaxed/simple; bh=zRrDYSrsKOnxGUDLUv6SHHsyzHqehx5WeHxuztEZX9k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BDlv8FKULU97wiOSYWyEYbe6DBC0RH02YUCRfGSMZS+Ji2RK5Wvq9zd7l5//ZbSiLJh5WNkREVhHhhoJFlL7an0tKAtiAxP4AL8khi3QM3o6c/4tUuPFg0R+apcGOs5aPR3JVppc6ur9leUyEeZX5wPHZCd6R4ju/sxN8/ZmLRo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Q94nAM2H; 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="Q94nAM2H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5753C4CECC; Tue, 8 Oct 2024 09:58:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728381528; bh=zRrDYSrsKOnxGUDLUv6SHHsyzHqehx5WeHxuztEZX9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q94nAM2H403vjQ/k6wj/Js4Df3zroTUzU5kgg9ScB7pis/7v6vPA+yjWX7Fm4qh32 gxSxFb8Liov1y1jQX0ikWtEaetwvzbQXV8GVae+cX/5boUbfDeTxrWQSb7lpT0h0cZ HnevGf0eA0y/mKjHj33eZtGgb0nGa8nPIe+o/Y26dZuQa/xpXakKEPlpHNXIFvF6N0 Yh6oBxi/sd2KKAtKKkfYu/6iGLj21dtK6lMrAx2FAHTyOgl5bBpjl/yFUfGGOShVGb 1vqephuXyw0IJj+jLhVu9xc+syJNOTVBZkePKWsmE7pZMvHh6pMK6amD+4jt0SHZb4 LtpgHMKLR3SZA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v2 13/13] mptcp: drop free_list for deleting entries Date: Tue, 8 Oct 2024 17:58:17 +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 With the help of mptcp_pm_remove_addr_entry(), it's no longer necessary to move the entry to be deleted to free_list and then traverse the list to delete the entry, which is not allowed in BPF. The entry can be directly deleted through list_del_rcu() and sock_kfree_s() now. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 9477c36d3284..4b2c3d0f685e 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -283,9 +283,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID]; struct mptcp_pm_addr_entry *match; - struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; - LIST_HEAD(free_list); int err = -EINVAL; struct sock *sk; u8 id_val; @@ -312,23 +310,21 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info) spin_lock_bh(&msk->pm.lock); match = mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); + spin_unlock_bh(&msk->pm.lock); if (!match) { GENL_SET_ERR_MSG(info, "address with specified id not found"); - spin_unlock_bh(&msk->pm.lock); release_sock(sk); goto out; } - list_move(&match->list, &free_list); - spin_unlock_bh(&msk->pm.lock); - mptcp_pm_remove_addr_entry(msk, match); release_sock(sk); - list_for_each_entry_safe(match, entry, &free_list, list) { - sock_kfree_s(sk, match, sizeof(*match)); - } + spin_lock_bh(&msk->pm.lock); + list_del_rcu(&match->list); + sock_kfree_s(sk, match, sizeof(*match)); + spin_unlock_bh(&msk->pm.lock); err = 0; out: