From nobody Sat Dec 21 14:39:02 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B61E183094 for ; Mon, 30 Sep 2024 09:45:09 +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=1727689510; cv=none; b=I+38qOls6slNkKJxpzFNleGNghDe5IOTjdnJPlk1NZHrEmw+tm6fk6ITDk8ux15bhvV5fU3Lbfd1lhiIVYE8rVEFpL2pPjTQ3Uz63mb9QvG8AzgmuGdYew3yakVay/H/btIQ4MhCeOVF+O6HLKfIjPMFm7+wgRo6R+8rv8ttLc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727689510; c=relaxed/simple; bh=sxJS1FyqJyyN68VI6S7BHgGdcimwlwVLTCn0MRa9MZo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=puERw/FZc08W0iK39q8glZT/x0rqzRMz4Xlt+t7/nvUsW92gTzkpM3BSDZeBBPifjVj1BztIEclO6K2schs9h2Ejg80evc5qvQ4Y6pLPSHcSJJIIy8keSTlNvWURy0LI6BkGQVbjk9NyoKvmGSNmnMyR/jNBQJu30FQoGVlgZMg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I5l72q9N; 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="I5l72q9N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6FB2C4CEC7; Mon, 30 Sep 2024 09:45:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727689509; bh=sxJS1FyqJyyN68VI6S7BHgGdcimwlwVLTCn0MRa9MZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I5l72q9NoJpJO6D9eBbw9l6VebypOCROCTwicyU0UlH5r8nXZYz74yWtRbD63cdn/ iRd1dCmdBHZtbLW2bxis2S2mIc11uZQEb9cP3pkr4Z+whvGAeenhcRj6KA0r6gzzPN 3eiNGsp1yZz4KPdImTZsDgLuYgzxuf44pgaw3HrPivHeqDdIAq6eqOG6l6a7aTIGtB McNywQtNuPLWYz3V8zDghTFAST6CDmmJBqHmimcKXDHxoRHGBrfLBxRpUAh9TiOixR GtOpk0Yq4FPdZRo0LegD2t+j87zmpsBoA4RwZqEdVPES/YH3Gudx/KeHJiCvxZiHNR 86186qnWTKG2A== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 1/7] mptcp: add id parameter for get_addr Date: Mon, 30 Sep 2024 17:44:56 +0800 Message-ID: <8d989e26c6152d643da02fbac764bc415f3f2404.1727689369.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 0f2fe64fd568..9b09ec22eeca 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1790,19 +1790,14 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } =20 -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 =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet =3D 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; =20 - ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - return ret; - msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) return -ENOMEM; @@ -1816,7 +1811,7 @@ static int mptcp_pm_nl_get_addr(struct genl_info *inf= o) } =20 spin_lock_bh(&pernet->lock); - entry =3D __lookup_addr_by_id(pernet, addr.addr.id); + entry =3D __lookup_addr_by_id(pernet, id); if (!entry) { GENL_SET_ERR_MSG(info, "address not found"); ret =3D -EINVAL; @@ -1840,16 +1835,25 @@ static int mptcp_pm_nl_get_addr(struct genl_info *i= nfo) return ret; } =20 -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); } =20 int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) { - return mptcp_pm_get_addr(info); + struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; + struct mptcp_pm_addr_entry addr; + int ret; + + ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); + if (ret < 0) + return ret; + + ret =3D mptcp_pm_get_addr(addr.addr.id, info); + return ret; } =20 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 703d13ef50ad..22ea1b8a11e3 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -668,12 +668,11 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, return ret; } =20 -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 =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; - struct mptcp_pm_addr_entry addr, *entry; struct net *net =3D genl_info_net(info); + struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; struct sk_buff *msg; int ret =3D -EINVAL; @@ -693,10 +692,6 @@ int mptcp_userspace_pm_get_addr(struct genl_info *info) goto out; } =20 - ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - goto out; - msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) { ret =3D -ENOMEM; @@ -713,7 +708,7 @@ int mptcp_userspace_pm_get_addr(struct genl_info *info) =20 lock_sock(sk); spin_lock_bh(&msk->pm.lock); - entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, addr.addr.id); + entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id); if (!entry) { GENL_SET_ERR_MSG(info, "address not found"); ret =3D -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, st= ruct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_add= r_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); =20 static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *= subflow) { --=20 2.43.0 From nobody Sat Dec 21 14:39:02 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03F8117BB32 for ; Mon, 30 Sep 2024 09:45:11 +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=1727689512; cv=none; b=jbSzcgWyEARnLKyoFG0fJyAJj7RvEB59E9MCP8bZnWsKzbnITetiN8V1pMlRBAfrzWhUmteQexnrgBFKd02SqARv+4w4a5LTEreqOxqgvRv9hlv7PwcoM9QA0nDpK7DMv+57ol6yrTEtrCnXvaf0OMrXdSk4fG/gc67vttjLM2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727689512; c=relaxed/simple; bh=nNRqH34t9uBqY9IuvhgW93di59EvStO48hyQNz05ORk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Mgcxfo73tTUwTqz1Oo3cGUqev3xjGuvQKMcxg42+ZlrWcOWVCPlxfVKyWuY7eH/61EjbNyvWYIvxxEN+K3jjV/PiOQ1ncYWDgRuV1sy7RYePAcSWxJxcnBhxtOuClPLvhVKav5wYDDVhQMTgEf7wUcNwvf1rOD08U+H0+Axfb9k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eCyj3Gi+; 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="eCyj3Gi+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67B07C4CEC7; Mon, 30 Sep 2024 09:45:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727689511; bh=nNRqH34t9uBqY9IuvhgW93di59EvStO48hyQNz05ORk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eCyj3Gi+6uxPXeV202Pmbhb+NXNGtq/UvWRWbXFNs7CZw1O/2Hj+160Snr8Vj+A59 JivucvTM3FBLZDlxoTtunRdln68UFqfPEvdomaMgV5miWcAvbe2zksJKx6+h7BI1ea gFthv50rVpoYuYG7w0EuDVeTfCCFNbckJ8UMJ1xBDoCZyww1o3NNXnMaZ+f2juEHmT OWMI0zzpzW5iKwc0qfnzWhtdwahO3bp362u9pzkfYpbebq9n67MSPSQCwKnDN8SKSw HHUTdauMGSb9iAQgJKnD+W4+1GPt2rf1e6myeQ9lnLobfgeTP14DQbpTQvkK9TZ2gT 4D/Di6IJlS/dA== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 2/7] mptcp: add addr parameter for get_addr Date: Mon, 30 Sep 2024 17:44:57 +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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D 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 =3D get_entry(); *copy =3D *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 9b09ec22eeca..b646f97f6afe 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1790,13 +1790,14 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } =20 -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 =3D genl_info_pm_nl(info); struct mptcp_pm_addr_entry *entry; struct sk_buff *msg; + int ret =3D -EINVAL; void *reply; - int ret; =20 msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) @@ -1812,34 +1813,36 @@ static int mptcp_pm_nl_get_addr(u8 id, struct genl_= info *info) =20 spin_lock_bh(&pernet->lock); entry =3D __lookup_addr_by_id(pernet, id); - if (!entry) { + if (entry) { + *addr =3D *entry; + ret =3D 0; + } + spin_unlock_bh(&pernet->lock); + + if (ret) { GENL_SET_ERR_MSG(info, "address not found"); - ret =3D -EINVAL; - goto unlock_fail; + goto fail; } =20 - ret =3D mptcp_nl_fill_addr(msg, entry); + ret =3D mptcp_nl_fill_addr(msg, addr); if (ret) - goto unlock_fail; + goto fail; =20 genlmsg_end(msg, reply); ret =3D genlmsg_reply(msg, info); - spin_unlock_bh(&pernet->lock); return ret; =20 -unlock_fail: - spin_unlock_bh(&pernet->lock); - fail: nlmsg_free(msg); return ret; } =20 -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); } =20 int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) @@ -1852,7 +1855,7 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, st= ruct genl_info *info) if (ret < 0) return ret; =20 - ret =3D mptcp_pm_get_addr(addr.addr.id, info); + ret =3D mptcp_pm_get_addr(addr.addr.id, &addr, info); return ret; } =20 diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 22ea1b8a11e3..80cb2c6508ba 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -668,7 +668,8 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, return ret; } =20 -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 nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct net *net =3D genl_info_net(info); @@ -709,26 +710,27 @@ int mptcp_userspace_pm_get_addr(u8 id, struct genl_in= fo *info) lock_sock(sk); spin_lock_bh(&msk->pm.lock); entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id); - if (!entry) { + if (entry) { + *addr =3D *entry; + ret =3D 0; + } + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); + + if (ret) { GENL_SET_ERR_MSG(info, "address not found"); - ret =3D -EINVAL; - goto unlock_fail; + goto fail; } =20 - ret =3D mptcp_nl_fill_addr(msg, entry); + ret =3D mptcp_nl_fill_addr(msg, addr); if (ret) - goto unlock_fail; + goto fail; =20 genlmsg_end(msg, reply); ret =3D genlmsg_reply(msg, info); - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); sock_put(sk); return ret; =20 -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, st= ruct mptcp_addr_info *skc); bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_add= r_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); =20 static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *= subflow) { --=20 2.43.0 From nobody Sat Dec 21 14:39:02 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DCD0170A23 for ; Mon, 30 Sep 2024 09:45:13 +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=1727689513; cv=none; b=lqEJiCntkfFehttg4D4duDM6II75r4gkkcZtFuuBD6KjRI5ieidSh3JPMMeHV467N7pMU8zSUx9HN4mAtoxtIFINoV04p/h639ZlPT0/5P9ITYeArG0JQeDuDM+F2OsrTZmRddB5ussWIkjXb1F7zRZlHrTQ4zd7jMu6PGKmK2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727689513; c=relaxed/simple; bh=OdtqH+EW79DCjVhPSxD2MusBhrNH29iJNbInAeS7LRM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hclbh0B7T3R8Vy/L/aWpF67uLqFTj35h5KuYCA84xoYna7UrXOSygvHB3hZVrQ+h8cESO6yXHimQiQwoXIufT5221Pnv8M09xqEGhA0BVboy3uNjOyd1IV6p+lWW4xtFHDYTA3wxuVdU9SxDKEQ7Hn2YjLPzSesinyOkP9ZkO5I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cBMGJ7Mu; 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="cBMGJ7Mu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C31BC4CEC7; Mon, 30 Sep 2024 09:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727689513; bh=OdtqH+EW79DCjVhPSxD2MusBhrNH29iJNbInAeS7LRM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cBMGJ7MutKNWu9rohewnjOT9wHIKNCboo0aNUC7qpCKcFzqfidrxN0+yDPWrSwlwo +K9+HNMlFP4EHN+G99aptbmSaD/LmcHTZCpH+blZhl9GLY3jzRxSVMvpkKozU7AnUr afB8+YUWUy72+/QBx+7DC1DUlPAGdYBIFGzjNrLquJffEGox4IHqs032vYrM8ekuGy /NO14d16cwBWQkN52ZUwd91nwg4c1YvA2M8QOphTzoRLsIkqgLaRNWQgzlalLnaUQ7 B9vkB46G5LJpHEB6OXKr7TkIxwkWWO3xfPRCfyYX1URe66mE5nuDxcJ/sJULtOjHot ymCwCl5caea0Q== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 3/7] mptcp: reuse sending nlmsg code in get_addr Date: Mon, 30 Sep 2024 17:44:58 +0800 Message-ID: <7d7f1396fc257ea68fbb8a2c41413c98257ac6e6.1727689369.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 32 ---------------------- 2 files changed, 29 insertions(+), 61 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index b646f97f6afe..ef47b54d8328 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1795,21 +1795,7 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_= pm_addr_entry *addr, { struct pm_nl_pernet *pernet =3D genl_info_pm_nl(info); struct mptcp_pm_addr_entry *entry; - struct sk_buff *msg; int ret =3D -EINVAL; - void *reply; - - msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) - return -ENOMEM; - - reply =3D 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 =3D -EMSGSIZE; - goto fail; - } =20 spin_lock_bh(&pernet->lock); entry =3D __lookup_addr_by_id(pernet, id); @@ -1819,21 +1805,6 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_= pm_addr_entry *addr, } spin_unlock_bh(&pernet->lock); =20 - if (ret) { - GENL_SET_ERR_MSG(info, "address not found"); - goto fail; - } - - ret =3D mptcp_nl_fill_addr(msg, addr); - if (ret) - goto fail; - - genlmsg_end(msg, reply); - ret =3D genlmsg_reply(msg, info); - return ret; - -fail: - nlmsg_free(msg); return ret; } =20 @@ -1849,13 +1820,42 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, = struct genl_info *info) { struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct mptcp_pm_addr_entry addr; + struct sk_buff *msg; + void *reply; int ret; =20 ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; =20 + msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + reply =3D 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 =3D -EMSGSIZE; + goto fail; + } + ret =3D mptcp_pm_get_addr(addr.addr.id, &addr, info); + if (ret) { + GENL_SET_ERR_MSG(info, "address not found"); + goto fail; + } + + ret =3D mptcp_nl_fill_addr(msg, &addr); + if (ret) + goto fail; + + genlmsg_end(msg, reply); + ret =3D genlmsg_reply(msg, info); + return ret; + +fail: + nlmsg_free(msg); return ret; } =20 diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 80cb2c6508ba..7c0bb084303b 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -675,10 +675,8 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm= _addr_entry *addr, struct net *net =3D genl_info_net(info); struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; - struct sk_buff *msg; int ret =3D -EINVAL; struct sock *sk; - void *reply; =20 msk =3D mptcp_token_get_sock(net, nla_get_u32(token)); if (!msk) { @@ -693,20 +691,6 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm= _addr_entry *addr, goto out; } =20 - msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); - if (!msg) { - ret =3D -ENOMEM; - goto out; - } - - reply =3D 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 =3D -EMSGSIZE; - goto fail; - } - lock_sock(sk); spin_lock_bh(&msk->pm.lock); entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id); @@ -717,22 +701,6 @@ int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm= _addr_entry *addr, spin_unlock_bh(&msk->pm.lock); release_sock(sk); =20 - if (ret) { - GENL_SET_ERR_MSG(info, "address not found"); - goto fail; - } - - ret =3D mptcp_nl_fill_addr(msg, addr); - if (ret) - goto fail; - - genlmsg_end(msg, reply); - ret =3D genlmsg_reply(msg, info); - sock_put(sk); - return ret; - -fail: - nlmsg_free(msg); out: sock_put(sk); return ret; --=20 2.43.0 From nobody Sat Dec 21 14:39:02 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04D0B5464B for ; Mon, 30 Sep 2024 09:45:15 +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=1727689515; cv=none; b=DljmpL+Wc2BSvFYVXt15P6ObEJ3lTZ5LunYjukKJIrRIXu9kv6xCj2PvCnlCi6qKjlIrMHqWzfMbGI8s6tYEuhd4C+2uE4oA6twHoXoiUxuOliOB/NXA5Kp3T82DwO+4TJpQsMefUvYsN8f3xYP8kMOyn28CXB+6uBTalZPKqvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727689515; c=relaxed/simple; bh=OScfSMpWwzSstn+h6M1iHWK9BPdMbz78Gq4Jb84ji7s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eQHuOiBVXmt9eFWVnzhZuthq0oZ9tSU/GKWxwRmKxlJVkv3mExwH1C5k3wveL7xQEViuPVUf2k2GGRw0pFBLVH2cmdaz2Ps5i+M3/kjj9X9kICfSOD5UFuvm2a5zK2ytUQK1w5z+YQERKP2Kq2TkEoGZFsDS1DspLi7GnHTio+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m/iHzaEv; 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="m/iHzaEv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBBCFC4CEC7; Mon, 30 Sep 2024 09:45:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727689514; bh=OScfSMpWwzSstn+h6M1iHWK9BPdMbz78Gq4Jb84ji7s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m/iHzaEvJ48rIUxIsyMILOBuNacxe9KaIUhqWjBnAcipYFjU7tKyChUXOU5Dz0SDg h+QM0EeryydJ8M6WY8d8D+Xw5fhC+X/yfAJJXxMoQ6Lvp5gdwe5usJHIyNGoW7Fz4J fpmKKiG8/ZNKOtV+qVpwDntqGGtS9SutWfhtpXaiFUCE8Rf0fdOFr5rHMxpYoAm1le U1eNtvZ3hbtKPKFPePLc1AN0ZkeZbUCGAeGKrLVmTj6/PeTF6ng46kf6EYdR10jpPP 6WnfksDb877XVyzOBu03QRonlYko+hr3pYw961SGhxAL6eAY4V3+44/9yU7g+YoobY dRGbANxPGBwDg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 4/7] mptcp: change info of get_addr as const Date: Mon, 30 Sep 2024 17:44:59 +0800 Message-ID: <50d8817698e3063629c509178e6451548caa36eb.1727689369.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang get_addr() interfece will be invoked by dump_addr(), which using a const parameter "info", so this patch change "info" parameter 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 ef47b54d8328..dc87f9ee9000 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1791,12 +1791,15 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, } =20 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 =3D genl_info_pm_nl(info); + struct net *net =3D genl_info_net(info); struct mptcp_pm_addr_entry *entry; + struct pm_nl_pernet *pernet; int ret =3D -EINVAL; =20 + pernet =3D pm_nl_get_pernet(net); + spin_lock_bh(&pernet->lock); entry =3D __lookup_addr_by_id(pernet, id); if (entry) { @@ -1809,7 +1812,7 @@ static int mptcp_pm_nl_get_addr(u8 id, struct mptcp_p= m_addr_entry *addr, } =20 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 7c0bb084303b..95c7cb56e9b4 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -669,7 +669,7 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, } =20 int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr, - struct genl_info *info) + const struct genl_info *info) { struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct net *net =3D genl_info_net(info); 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); =20 static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *= subflow) { --=20 2.43.0 From nobody Sat Dec 21 14:39:02 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 025075464B for ; Mon, 30 Sep 2024 09:45:16 +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=1727689517; cv=none; b=q5YmZ/ailNvtjXZ0Gx8RkNQEFAn1k0zFIJSlnXAjRL1mT8Z+0RwXDbhmTfmVjCHxIM8cnuSvSdu3neZ2LmSqcCwOoT6affsyB23chGiDCHKma0x4gUkszyHUkmsNvIMJ7a3dmtZJF0z9ewT/W3U1Ey/n/zBWmrZ8tp0axLvqzww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727689517; c=relaxed/simple; bh=lBnJaIToLZgNON5tuGwj6XyXMb5nB7KJ3LKHiyuhQ6Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qao/lylpR3lNFlGVV78EZbJoWlMjSEFcA8IrkYTGNKyAnJemxqp1Lz+bEZExxNzS5/N5YJs1zTrwGjDU1c9twTMxuAjfen+MSRQwczUizktlwHFKFdbl9GWySkMuJbLOfinWFakTSfgVpZP0iLkxUzefdQldtqDUoIPmPwTVCUs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AZH5efdv; 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="AZH5efdv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BB32C4CEC7; Mon, 30 Sep 2024 09:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727689516; bh=lBnJaIToLZgNON5tuGwj6XyXMb5nB7KJ3LKHiyuhQ6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AZH5efdv4+8W9NEQ5iJpe1AVKjQcmGBMyBWl9Mkg2GIf1ubwuhYixlJWoPww0p64H 5KYxzVjQ1bMeConuO+PWpMr4VCmRM1hBK3VZfdaQYPNsbh8kXd2g1VsU5TVjY/1Ffu XU+WCjTewhF2l7E00P6aYOhmSYd0MbJkyahcEI4Ne9ATS3CdeAQOCFB/aBSJ+5pDL1 Isp3KjlbRtp8OMyoAGDiqjhfIcdKLvlfNqMKjNhqOBO9K6Y5q43SRxDh2nyvtAHjJa mBrzzR60LNB3AxKyw899TIWstH5GesyI2bR9Db3ixOo4KG2+mnLPlj6XUiXEzV20GB Ayy/37O95pErQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 5/7] mptcp: refactor dump_addr with id bitmap Date: Mon, 30 Sep 2024 17:45:00 +0800 Message-ID: <8c8a23df0610ab51f5264069408118a6bfb36aaf.1727689369.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 patch 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: lock(); for_each_entry(entry) set_bit(bitmap); unlock(); for_each_bit(bitmap) { copy =3D get_addr(); send_nlmsg(copy); } Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 30 +++++++++++------- net/mptcp/pm_userspace.c | 67 ++++++++++++++++++++++++++++------------ 2 files changed, 67 insertions(+), 30 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index dc87f9ee9000..d921d1bc0682 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1865,23 +1865,32 @@ 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 =3D genl_info_dump(cb); struct net *net =3D sock_net(msg->sk); - struct mptcp_pm_addr_entry *entry; - struct pm_nl_pernet *pernet; + struct mptcp_pm_addr_entry entry; + struct mptcp_id_bitmap *bitmap; int id =3D cb->args[0]; void *hdr; int i; =20 - pernet =3D pm_nl_get_pernet(net); + bitmap =3D (struct mptcp_id_bitmap *)cb->ctx; + + if (!id) { + struct pm_nl_pernet *pernet =3D 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); + } =20 - spin_lock_bh(&pernet->lock); for (i =3D id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { - if (test_bit(i, pernet->id_bitmap.map)) { - entry =3D __lookup_addr_by_id(pernet, i); - if (!entry) + if (test_bit(i, bitmap->map)) { + if (mptcp_pm_get_addr(i, &entry, info)) { + GENL_SET_ERR_MSG(info, "address not found"); break; + } =20 - if (entry->addr.id <=3D id) + if (entry.addr.id <=3D id) continue; =20 hdr =3D genlmsg_put(msg, NETLINK_CB(cb->skb).portid, @@ -1890,16 +1899,15 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *ms= g, if (!hdr) break; =20 - if (mptcp_nl_fill_addr(msg, entry) < 0) { + if (mptcp_nl_fill_addr(msg, &entry) < 0) { genlmsg_cancel(msg, hdr); break; } =20 - id =3D entry->addr.id; + id =3D entry.addr.id; genlmsg_end(msg, hdr); } } - spin_unlock_bh(&pernet->lock); =20 cb->args[0] =3D id; return msg->len; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 95c7cb56e9b4..de552ba542f6 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -38,6 +38,21 @@ mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk, c= onst struct mptcp_addr_i return NULL; } =20 +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; +} + static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk, struct mptcp_pm_addr_entry *entry, bool needs_id) @@ -615,13 +630,15 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, { const struct genl_info *info =3D genl_info_dump(cb); struct net *net =3D sock_net(msg->sk); - struct mptcp_pm_addr_entry *entry; + struct mptcp_pm_addr_entry entry; struct mptcp_id_bitmap *bitmap; struct mptcp_sock *msk; struct nlattr *token; + int id =3D cb->args[0]; int ret =3D -EINVAL; struct sock *sk; void *hdr; + int i; =20 bitmap =3D (struct mptcp_id_bitmap *)cb->ctx; token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; @@ -639,28 +656,40 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, goto out; } =20 - 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) { + lock_sock(sk); + spin_lock_bh(&msk->pm.lock); + ret =3D mptcp_userspace_pm_set_bitmap(msk, bitmap); + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); + } =20 - hdr =3D 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; + for (i =3D id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { + if (test_bit(i, bitmap->map)) { + if (mptcp_userspace_pm_get_addr(i, &entry, info)) { + GENL_SET_ERR_MSG(info, "address not found"); + break; + } =20 - if (mptcp_nl_fill_addr(msg, entry) < 0) { - genlmsg_cancel(msg, hdr); - break; - } + if (id && entry.addr.id <=3D id) + continue; =20 - __set_bit(entry->addr.id, bitmap->map); - genlmsg_end(msg, hdr); + hdr =3D 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 =3D entry.addr.id; + genlmsg_end(msg, hdr); + } } - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); + cb->args[0] =3D id; ret =3D msg->len; =20 out: --=20 2.43.0 From nobody Sat Dec 21 14:39:02 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CC51183063 for ; Mon, 30 Sep 2024 09:45:18 +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=1727689518; cv=none; b=mwUY5Uo+9hqbWQ5y+jlq4gHisAyKpSuCOdstOr0Y28nyu/K8Z8qXHGI6js3cVl+UfO19ApHrVwUb8t2/un34p9WCwqdzFUEwqGq2EDBHaTpjy3dm4TAd9cfDVio0YqJbtvD+r8whU9DiUMbgjmu7x7FJ5IBXoYdKmDNRxjlcbkc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727689518; c=relaxed/simple; bh=UrfiO/BI+wNhUFfeuFbMb2KQPnT6X3XTPdXmHWVGqf4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=asZ6rv8ICgTcoN0N/lxJk5vXmOk+4RnubgKeAr9T6fghs0pCS7Uxntbud97cbOBcbIRXQZN3SVBffnVq+vBXLcC6vYZbddTgaBlldMcuJmHFPomK1ulzokXZ3dX3rXtS3Hae8q7udqEBOPq36LTsrpClWeWPEKCqaCEbZZZ359Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XVMW5uQU; 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="XVMW5uQU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45E66C4CED2; Mon, 30 Sep 2024 09:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727689518; bh=UrfiO/BI+wNhUFfeuFbMb2KQPnT6X3XTPdXmHWVGqf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XVMW5uQUQnI7SGS5U6mc7kwBnsPZUuIhGc27oGTKVRAdfUAyucO3Ip51seXi8jpvW xynSautZsKkrhbSYWmjnEIMGPLXiRhbWQpmjPUoIm4DwN9vmPphH5Rw8PMb6Io496z wVCPiPsrge4YjVnhyl30r4KpBr7E40FvBU6TeYIHuS19zMRFuRW767RNwIS0joOV/t vzSsKtJw01Uwu8eN/TY6K+x8XMUSTa9uBMct0PcVvPGtgDJ4xndMNRf34FdwizGDKX atH/ze2xaL2sDHR6KPeLGOUWoX1NOGYW4g2sHMf1oruUw9B1tnw8werB1TUXO4OOwE enquB3LdwzeEg== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 6/7] mptcp: reuse sending nlmsg code in dump_addr Date: Mon, 30 Sep 2024 17:45:01 +0800 Message-ID: <4a02fcd8efa3b13389bc7211f0c75ca335f1755f.1727689369.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 51 +++++++++++++++++++------------------- net/mptcp/pm_userspace.c | 53 ++++++---------------------------------- net/mptcp/protocol.h | 4 +-- 3 files changed, 35 insertions(+), 73 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index d921d1bc0682..777d84a4e0cd 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1862,11 +1862,30 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, = struct genl_info *info) return ret; } =20 -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 pm_nl_pernet *pernet =3D pm_nl_get_pernet(genl_info_net(info)); + + 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 =3D genl_info_dump(cb); - struct net *net =3D sock_net(msg->sk); struct mptcp_pm_addr_entry entry; struct mptcp_id_bitmap *bitmap; int id =3D cb->args[0]; @@ -1875,13 +1894,8 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, =20 bitmap =3D (struct mptcp_id_bitmap *)cb->ctx; =20 - if (!id) { - struct pm_nl_pernet *pernet =3D 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); - } + if (!id) + mptcp_pm_dump_addr(bitmap, info); =20 for (i =3D id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { if (test_bit(i, bitmap->map)) { @@ -1890,7 +1904,7 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, break; } =20 - if (entry.addr.id <=3D id) + if (id && entry.addr.id <=3D id) continue; =20 hdr =3D genlmsg_put(msg, NETLINK_CB(cb->skb).portid, @@ -1913,21 +1927,6 @@ static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, return msg->len; } =20 -static int mptcp_pm_dump_addr(struct sk_buff *msg, struct netlink_callback= *cb) -{ - const struct genl_info *info =3D 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 =3D info->attrs[id]; diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index de552ba542f6..b17cf8cd698c 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -625,22 +625,15 @@ int mptcp_userspace_pm_set_flags(struct genl_info *in= fo) return ret; } =20 -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 =3D genl_info_dump(cb); - struct net *net =3D sock_net(msg->sk); - struct mptcp_pm_addr_entry entry; - struct mptcp_id_bitmap *bitmap; + struct net *net =3D genl_info_net(info); struct mptcp_sock *msk; struct nlattr *token; - int id =3D cb->args[0]; int ret =3D -EINVAL; struct sock *sk; - void *hdr; - int i; =20 - bitmap =3D (struct mptcp_id_bitmap *)cb->ctx; token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; =20 msk =3D mptcp_token_get_sock(net, nla_get_u32(token)); @@ -656,41 +649,11 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, goto out; } =20 - if (!id) { - lock_sock(sk); - spin_lock_bh(&msk->pm.lock); - ret =3D mptcp_userspace_pm_set_bitmap(msk, bitmap); - spin_unlock_bh(&msk->pm.lock); - release_sock(sk); - } - - for (i =3D id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) { - if (test_bit(i, bitmap->map)) { - if (mptcp_userspace_pm_get_addr(i, &entry, info)) { - GENL_SET_ERR_MSG(info, "address not found"); - break; - } - - if (id && entry.addr.id <=3D id) - continue; - - hdr =3D 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 =3D entry.addr.id; - genlmsg_end(msg, hdr); - } - } - cb->args[0] =3D id; - ret =3D msg->len; + lock_sock(sk); + spin_lock_bh(&msk->pm.lock); + ret =3D mptcp_userspace_pm_set_bitmap(msk, bitmap); + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); =20 out: sock_put(sk); 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_add= r_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); =20 --=20 2.43.0 From nobody Sat Dec 21 14:39:02 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A448127E18 for ; Mon, 30 Sep 2024 09:45: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=1727689520; cv=none; b=g48hgXqzCys/jPGF9lMdeSkhTV23G9Ev/A80vNdK6FizqJgCPY2OXkUCDj8ttrQvZZmJBztyWNxqCQAiFJk0t6pBAlWdArdpIRwNRoUDMOlv7Gavn2jNrvZFHf5aRvhLV0282NZd7pkm22X/j5wDhzvPg7ESjEBaxMv8u2Qu+GE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727689520; c=relaxed/simple; bh=DsrhmmX3Drrv+k+NuVr7cE9h0l3p0oHv7i0inLwZ4yA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=on1q2/e7urBBJy2tthiNRNdvxaFq1Phz2jT45t3GcjkNC74G0jW4gJYZleXBaSrmL1fuE5gaLwmWEhw1/d9paqBfVOLTeIHwa4IV+ZcKmTMn+n02+lVftaREQzBlnhht9NhwgANDoAK2369ZCJYMZLEe+pg53AVIyKDK9SAaHOU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i5j+sd5P; 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="i5j+sd5P" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06310C4CECD; Mon, 30 Sep 2024 09:45:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727689520; bh=DsrhmmX3Drrv+k+NuVr7cE9h0l3p0oHv7i0inLwZ4yA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i5j+sd5PsgPiiSNNPV3cdFOUPtiboWMDHpMVomkwj194XLsIAQBdTBBp2CBjH1HWt mO3pfPIUHIoxXG3oyETc7tKV1JtxV3FyhjKpO2gJS4RXlRvYC0RlsmA4tDgRgV613x pDtJ1YvsIVOHXMTKzoYL/JxsQyujaG0Sezw+Nv43gU/2dgreps64jrR3RXfCTvJeav ittMfMG66MUyEIqr+prV8y0rS1pHYiayOq4PEwlWH/hdj46YLkKBAzrdUkrhZsYYpu bcgUCbRcOb6sb37eL3L/j3yndcqjuLimlbsnIiFZFy0g/b2Bfd1BI3Xf3dn/6078GW 9D+iTs+lxwhmQ== From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next 7/7] mptcp: add loc and rem for set_flags Date: Mon, 30 Sep 2024 17:45:02 +0800 Message-ID: <9e85d9941dfce9866badaf6eac6b2c17fcf4a249.1727689369.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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 777d84a4e0cd..d522d381f23c 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -2042,25 +2042,21 @@ static int mptcp_nl_set_flags(struct net *net, return ret; } =20 -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 =3D { .addr =3D { .family =3D AF_UNSPEC }= , }; - struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; u8 changed, mask =3D MPTCP_PM_ADDR_FLAG_BACKUP | MPTCP_PM_ADDR_FLAG_FULLMESH; + struct mptcp_pm_addr_entry addr =3D *loc; struct net *net =3D genl_info_net(info); struct mptcp_pm_addr_entry *entry; struct pm_nl_pernet *pernet; u8 lookup_by_id =3D 0; u8 bkup =3D 0; - int ret; =20 pernet =3D pm_nl_get_pernet(net); =20 - ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); - if (ret < 0) - return ret; - if (addr.addr.family =3D=3D AF_UNSPEC) { lookup_by_id =3D 1; if (!addr.addr.id) { @@ -2096,16 +2092,34 @@ static int mptcp_pm_nl_set_flags(struct genl_info *= info) return 0; } =20 -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); } =20 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 =3D { .addr =3D { .family =3D AF_UNSPEC },= }; + struct nlattr *attr_rem =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; + struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; + struct mptcp_addr_info rem =3D { .family =3D AF_UNSPEC, }; + int ret; + + ret =3D mptcp_pm_parse_entry(attr, info, false, &loc); + if (ret < 0) + return ret; + + if (attr_rem) { + ret =3D mptcp_pm_parse_addr(attr_rem, info, &rem); + if (ret < 0) + return ret; + } + + return mptcp_pm_set_flags(&loc, &rem, info); } =20 static void mptcp_nl_mcast_send(struct net *net, struct sk_buff *nlskb, gf= p_t gfp) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index b17cf8cd698c..c20eb72e2fdc 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -567,13 +567,11 @@ int mptcp_pm_nl_subflow_destroy_doit(struct sk_buff *= skb, struct genl_info *info return err; } =20 -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 =3D { .addr =3D { .family =3D AF_UNSPEC },= }; - struct nlattr *attr_rem =3D info->attrs[MPTCP_PM_ATTR_ADDR_REMOTE]; struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; - struct nlattr *attr =3D info->attrs[MPTCP_PM_ATTR_ADDR]; - struct mptcp_addr_info rem =3D { .family =3D AF_UNSPEC, }; struct net *net =3D genl_info_net(info); struct mptcp_sock *msk; int ret =3D -EINVAL; @@ -596,28 +594,18 @@ int mptcp_userspace_pm_set_flags(struct genl_info *in= fo) goto set_flags_err; } =20 - ret =3D mptcp_pm_parse_entry(attr, info, false, &loc); - if (ret < 0) - goto set_flags_err; - - if (attr_rem) { - ret =3D mptcp_pm_parse_addr(attr_rem, info, &rem); - if (ret < 0) - goto set_flags_err; - } - - if (loc.addr.family =3D=3D AF_UNSPEC || - rem.family =3D=3D AF_UNSPEC) { + if (loc->addr.family =3D=3D AF_UNSPEC || + rem->family =3D=3D AF_UNSPEC) { GENL_SET_ERR_MSG(info, "invalid address families"); ret =3D -EINVAL; goto set_flags_err; } =20 - if (loc.flags & MPTCP_PM_ADDR_FLAG_BACKUP) + if (loc->flags & MPTCP_PM_ADDR_FLAG_BACKUP) bkup =3D 1; =20 lock_sock(sk); - ret =3D mptcp_pm_nl_mp_prio_send_ack(msk, &loc.addr, &rem, bkup); + ret =3D mptcp_pm_nl_mp_prio_send_ack(msk, &loc->addr, rem, bkup); release_sock(sk); =20 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); --=20 2.43.0