mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] mptcp: pm: lockless list traversal and cleanup
@ 2024-11-15 16:52 Matthieu Baerts (NGI0)
  2024-11-15 16:52 ` [PATCH net-next 1/2] mptcp: pm: lockless list traversal to dump endp Matthieu Baerts (NGI0)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Matthieu Baerts (NGI0) @ 2024-11-15 16:52 UTC (permalink / raw)
  To: mptcp, Mat Martineau, Geliang Tang, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman
  Cc: netdev, linux-kernel, Matthieu Baerts (NGI0), Geliang Tang

Here are two patches improving the MPTCP in-kernel path-manager.

- Patch 1: the get and dump endpoints operations are iterating over the
  endpoints list in a lockless way.

- Patch 2: reduce the code duplication to lookup an endpoint.

Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
Geliang Tang (1):
      mptcp: pm: avoid code duplication to lookup endp

Matthieu Baerts (NGI0) (1):
      mptcp: pm: lockless list traversal to dump endp

 net/mptcp/pm_netlink.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)
---
base-commit: dfc14664794a4706e0c2186a0c082386e6b14c4d
change-id: 20241115-net-next-mptcp-pm-lockless-dump-a5a00e51f819

Best regards,
-- 
Matthieu Baerts (NGI0) <matttbe@kernel.org>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 1/2] mptcp: pm: lockless list traversal to dump endp
  2024-11-15 16:52 [PATCH net-next 0/2] mptcp: pm: lockless list traversal and cleanup Matthieu Baerts (NGI0)
@ 2024-11-15 16:52 ` Matthieu Baerts (NGI0)
  2024-11-15 16:52 ` [PATCH net-next 2/2] mptcp: pm: avoid code duplication to lookup endp Matthieu Baerts (NGI0)
  2024-11-19  4:00 ` [PATCH net-next 0/2] mptcp: pm: lockless list traversal and cleanup patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Matthieu Baerts (NGI0) @ 2024-11-15 16:52 UTC (permalink / raw)
  To: mptcp, Mat Martineau, Geliang Tang, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman
  Cc: netdev, linux-kernel, Matthieu Baerts (NGI0)

To return an endpoint to the userspace via Netlink, and to dump all of
them, the endpoint list was iterated while holding the pernet->lock, but
only to read the content of the list.

In these cases, the spin locks can be replaced by RCU read ones, and use
the _rcu variants to iterate over the entries list in a lockless way.

Note that the __lookup_addr_by_id() helper has been modified to use the
_rcu variants of list_for_each_entry(), but with an extra conditions, so
it can be called either while the RCU read lock is held, or when the
associated pernet->lock is held.

Reviewed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/pm_netlink.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 758a0dbfcf78e545d840c0b580c0b12bd042d7a4..2b005ddfd2d365b66abf42065289d74630e604f6 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -512,7 +512,8 @@ __lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned int id)
 {
 	struct mptcp_pm_addr_entry *entry;
 
-	list_for_each_entry(entry, &pernet->local_addr_list, list) {
+	list_for_each_entry_rcu(entry, &pernet->local_addr_list, list,
+				lockdep_is_held(&pernet->lock)) {
 		if (entry->addr.id == id)
 			return entry;
 	}
@@ -1824,7 +1825,7 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
 		goto fail;
 	}
 
-	spin_lock_bh(&pernet->lock);
+	rcu_read_lock();
 	entry = __lookup_addr_by_id(pernet, addr.addr.id);
 	if (!entry) {
 		GENL_SET_ERR_MSG(info, "address not found");
@@ -1838,11 +1839,11 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
 
 	genlmsg_end(msg, reply);
 	ret = genlmsg_reply(msg, info);
-	spin_unlock_bh(&pernet->lock);
+	rcu_read_unlock();
 	return ret;
 
 unlock_fail:
-	spin_unlock_bh(&pernet->lock);
+	rcu_read_unlock();
 
 fail:
 	nlmsg_free(msg);
@@ -1866,7 +1867,7 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
 
 	pernet = pm_nl_get_pernet(net);
 
-	spin_lock_bh(&pernet->lock);
+	rcu_read_lock();
 	for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) {
 		if (test_bit(i, pernet->id_bitmap)) {
 			entry = __lookup_addr_by_id(pernet, i);
@@ -1891,7 +1892,7 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
 			genlmsg_end(msg, hdr);
 		}
 	}
-	spin_unlock_bh(&pernet->lock);
+	rcu_read_unlock();
 
 	cb->args[0] = id;
 	return msg->len;

-- 
2.45.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 2/2] mptcp: pm: avoid code duplication to lookup endp
  2024-11-15 16:52 [PATCH net-next 0/2] mptcp: pm: lockless list traversal and cleanup Matthieu Baerts (NGI0)
  2024-11-15 16:52 ` [PATCH net-next 1/2] mptcp: pm: lockless list traversal to dump endp Matthieu Baerts (NGI0)
@ 2024-11-15 16:52 ` Matthieu Baerts (NGI0)
  2024-11-19  4:00 ` [PATCH net-next 0/2] mptcp: pm: lockless list traversal and cleanup patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Matthieu Baerts (NGI0) @ 2024-11-15 16:52 UTC (permalink / raw)
  To: mptcp, Mat Martineau, Geliang Tang, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman
  Cc: netdev, linux-kernel, Matthieu Baerts (NGI0), Geliang Tang

From: Geliang Tang <tanggeliang@kylinos.cn>

The helper __lookup_addr() can be used in mptcp_pm_nl_get_local_id()
and mptcp_pm_nl_is_backup() to simplify the code, and avoid code
duplication.

Co-developed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/pm_netlink.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 2b005ddfd2d365b66abf42065289d74630e604f6..7a0f7998376a5bb73a37829f9a6b3cdb9a3236a2 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1143,17 +1143,13 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc
 {
 	struct mptcp_pm_addr_entry *entry;
 	struct pm_nl_pernet *pernet;
-	int ret = -1;
+	int ret;
 
 	pernet = pm_nl_get_pernet_from_msk(msk);
 
 	rcu_read_lock();
-	list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
-		if (mptcp_addresses_equal(&entry->addr, skc, entry->addr.port)) {
-			ret = entry->addr.id;
-			break;
-		}
-	}
+	entry = __lookup_addr(pernet, skc);
+	ret = entry ? entry->addr.id : -1;
 	rcu_read_unlock();
 	if (ret >= 0)
 		return ret;
@@ -1180,15 +1176,11 @@ bool mptcp_pm_nl_is_backup(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;
+	bool backup;
 
 	rcu_read_lock();
-	list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
-		if (mptcp_addresses_equal(&entry->addr, skc, entry->addr.port)) {
-			backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP);
-			break;
-		}
-	}
+	entry = __lookup_addr(pernet, skc);
+	backup = entry && !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP);
 	rcu_read_unlock();
 
 	return backup;

-- 
2.45.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 0/2] mptcp: pm: lockless list traversal and cleanup
  2024-11-15 16:52 [PATCH net-next 0/2] mptcp: pm: lockless list traversal and cleanup Matthieu Baerts (NGI0)
  2024-11-15 16:52 ` [PATCH net-next 1/2] mptcp: pm: lockless list traversal to dump endp Matthieu Baerts (NGI0)
  2024-11-15 16:52 ` [PATCH net-next 2/2] mptcp: pm: avoid code duplication to lookup endp Matthieu Baerts (NGI0)
@ 2024-11-19  4:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-11-19  4:00 UTC (permalink / raw)
  To: Matthieu Baerts
  Cc: mptcp, martineau, geliang, davem, edumazet, kuba, pabeni, horms,
	netdev, linux-kernel

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Fri, 15 Nov 2024 17:52:33 +0100 you wrote:
> Here are two patches improving the MPTCP in-kernel path-manager.
> 
> - Patch 1: the get and dump endpoints operations are iterating over the
>   endpoints list in a lockless way.
> 
> - Patch 2: reduce the code duplication to lookup an endpoint.
> 
> [...]

Here is the summary with links:
  - [net-next,1/2] mptcp: pm: lockless list traversal to dump endp
    https://git.kernel.org/netdev/net-next/c/3fbb27b7f87e
  - [net-next,2/2] mptcp: pm: avoid code duplication to lookup endp
    https://git.kernel.org/netdev/net-next/c/1d7fa6ceb91f

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-11-19  4:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-15 16:52 [PATCH net-next 0/2] mptcp: pm: lockless list traversal and cleanup Matthieu Baerts (NGI0)
2024-11-15 16:52 ` [PATCH net-next 1/2] mptcp: pm: lockless list traversal to dump endp Matthieu Baerts (NGI0)
2024-11-15 16:52 ` [PATCH net-next 2/2] mptcp: pm: avoid code duplication to lookup endp Matthieu Baerts (NGI0)
2024-11-19  4:00 ` [PATCH net-next 0/2] mptcp: pm: lockless list traversal and cleanup patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome