Skip to content

Commit 5b7cfe0

Browse files
committed
Merge branch 'mptcp-pm-lockless-list-traversal-and-cleanup'
Matthieu Baerts says: ==================== mptcp: pm: lockless list traversal and cleanup 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. ==================== Link: https://patch.msgid.link/20241115-net-next-mptcp-pm-lockless-dump-v1-0-f4a1bcb4ca2c@kernel.org Signed-off-by: Jakub Kicinski <[email protected]>
2 parents cc84d89 + 1d7fa6c commit 5b7cfe0

File tree

1 file changed

+13
-20
lines changed

1 file changed

+13
-20
lines changed

net/mptcp/pm_netlink.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ __lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned int id)
512512
{
513513
struct mptcp_pm_addr_entry *entry;
514514

515-
list_for_each_entry(entry, &pernet->local_addr_list, list) {
515+
list_for_each_entry_rcu(entry, &pernet->local_addr_list, list,
516+
lockdep_is_held(&pernet->lock)) {
516517
if (entry->addr.id == id)
517518
return entry;
518519
}
@@ -1142,17 +1143,13 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc
11421143
{
11431144
struct mptcp_pm_addr_entry *entry;
11441145
struct pm_nl_pernet *pernet;
1145-
int ret = -1;
1146+
int ret;
11461147

11471148
pernet = pm_nl_get_pernet_from_msk(msk);
11481149

11491150
rcu_read_lock();
1150-
list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
1151-
if (mptcp_addresses_equal(&entry->addr, skc, entry->addr.port)) {
1152-
ret = entry->addr.id;
1153-
break;
1154-
}
1155-
}
1151+
entry = __lookup_addr(pernet, skc);
1152+
ret = entry ? entry->addr.id : -1;
11561153
rcu_read_unlock();
11571154
if (ret >= 0)
11581155
return ret;
@@ -1179,15 +1176,11 @@ bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc)
11791176
{
11801177
struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
11811178
struct mptcp_pm_addr_entry *entry;
1182-
bool backup = false;
1179+
bool backup;
11831180

11841181
rcu_read_lock();
1185-
list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
1186-
if (mptcp_addresses_equal(&entry->addr, skc, entry->addr.port)) {
1187-
backup = !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP);
1188-
break;
1189-
}
1190-
}
1182+
entry = __lookup_addr(pernet, skc);
1183+
backup = entry && !!(entry->flags & MPTCP_PM_ADDR_FLAG_BACKUP);
11911184
rcu_read_unlock();
11921185

11931186
return backup;
@@ -1824,7 +1817,7 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
18241817
goto fail;
18251818
}
18261819

1827-
spin_lock_bh(&pernet->lock);
1820+
rcu_read_lock();
18281821
entry = __lookup_addr_by_id(pernet, addr.addr.id);
18291822
if (!entry) {
18301823
GENL_SET_ERR_MSG(info, "address not found");
@@ -1838,11 +1831,11 @@ int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info)
18381831

18391832
genlmsg_end(msg, reply);
18401833
ret = genlmsg_reply(msg, info);
1841-
spin_unlock_bh(&pernet->lock);
1834+
rcu_read_unlock();
18421835
return ret;
18431836

18441837
unlock_fail:
1845-
spin_unlock_bh(&pernet->lock);
1838+
rcu_read_unlock();
18461839

18471840
fail:
18481841
nlmsg_free(msg);
@@ -1866,7 +1859,7 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
18661859

18671860
pernet = pm_nl_get_pernet(net);
18681861

1869-
spin_lock_bh(&pernet->lock);
1862+
rcu_read_lock();
18701863
for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) {
18711864
if (test_bit(i, pernet->id_bitmap)) {
18721865
entry = __lookup_addr_by_id(pernet, i);
@@ -1891,7 +1884,7 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
18911884
genlmsg_end(msg, hdr);
18921885
}
18931886
}
1894-
spin_unlock_bh(&pernet->lock);
1887+
rcu_read_unlock();
18951888

18961889
cb->args[0] = id;
18971890
return msg->len;

0 commit comments

Comments
 (0)