Skip to contentSkip to conversation

mptcp: pm: Defer freeing of MPTCP userspace path manager entries

PATCH In review Mat Martineau 3 participants 5 messages Apr 10, 2025 – Apr 14, 2025

Subsystems (2)
lore
Share & tools
lore

Mat Martineau

author maintainer
#0 lore raw

PATCH v2 1/1 mptcp: pm: Defer freeing of MPTCP userspace path manager entries

When path manager entries are deleted from the local address list, they are first unlinked from the address list using list_del_rcu(). The entries must not be freed until after the RCU grace period, but the existing code immediately frees the entry.

Use kfree_rcu_mightsleep() and adjust sk_omem_alloc in open code instead of using the sock_kfree_s() helper. This code path is only called in a netlink handler, so the "might sleep" function is preferable to adding a rarely-used rcu_head member to struct mptcp_pm_addr_entry.

Fixes 88d097316371 ("mptcp: drop free_list for deleting entries")

---

v2: Add comment explaining connection to sock_kfree_s, add "Fixes" tag

---
 net/mptcp/pm_userspace.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/mptcp/pm_userspace.c +5 -1
index 7fc19b844384..1911fe1799fa 100644
@@ -337,7 +337,11 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
 
 	release_sock(sk);
 
-	sock_kfree_s(sk, match, sizeof(*match));
+	kfree_rcu_mightsleep(match);
+	/* Adjust sk_omem_alloc like sock_kfree_s() does, to match
+	 * with allocation of this memory by sock_kmemdup()
+	 */
+	atomic_sub(sizeof(*match), &sk->sk_omem_alloc);
 
 	err = 0;
 out:
Signature · 1 line
2.49.0
#1 lore raw

Hi Mat,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/14391915501

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/b3df5ca41b93
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=952252

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Mat Martineau

Hi Mat,

Quoted 10 lines · Mat Martineau

When path manager entries are deleted from the local address list, they are first unlinked from the address list using list_del_rcu(). The entries must not be freed until after the RCU grace period, but the existing code immediately frees the entry.

Use kfree_rcu_mightsleep() and adjust sk_omem_alloc in open code instead of using the sock_kfree_s() helper. This code path is only called in a netlink handler, so the "might sleep" function is preferable to adding a rarely-used rcu_head member to struct mptcp_pm_addr_entry.

Quoted 5 lines
Fixes 88d097316371 ("mptcp: drop free_list for deleting entries")

---

v2: Add comment explaining connection to sock_kfree_s, add "Fixes" tag

Thank you for the v2, and your reply on my previous review. This v2 looks good to me:

I guess I should wait to apply "only remove entry from local_addr_list when sending a REMOVE_ADDR" series first then, right? Are these other patches supposed to be fixes for net? They are not marked as that for the moment: in that case, should we add another patch to fix mptcp_userspace_pm_delete_local_addr() as well?

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
author maintainer
#3 lore raw
Quoted 22 lines · Matthieu Baerts

Hi Mat,

Quoted 10 lines · Mat Martineau

When path manager entries are deleted from the local address list, they are first unlinked from the address list using list_del_rcu(). The entries must not be freed until after the RCU grace period, but the existing code immediately frees the entry.

Use kfree_rcu_mightsleep() and adjust sk_omem_alloc in open code instead of using the sock_kfree_s() helper. This code path is only called in a netlink handler, so the "might sleep" function is preferable to adding a rarely-used rcu_head member to struct mptcp_pm_addr_entry.

Quoted 5 lines
Fixes 88d097316371 ("mptcp: drop free_list for deleting entries")

---

v2: Add comment explaining connection to sock_kfree_s, add "Fixes" tag

Thank you for the v2, and your reply on my previous review. This v2 looks good to me:

Quoted 8 lines

I guess I should wait to apply "only remove entry from local_addr_list when sending a REMOVE_ADDR" series first then, right? Are these other patches supposed to be fixes for net? They are not marked as that for the moment: in that case, should we add another patch to fix mptcp_userspace_pm_delete_local_addr() as well?

I don't think there's any issue or conflict with applying this to export-net first, it would leave the bug not fixed in mptcp_userspace_pm_delete_local_addr(). If this patch needs to stand alone, then it would need to be reworked to add a struct rcu_head to the local addr entry because mptcp_userspace_pm_delete_local_addr() gets called in contexts where sleepable calls aren't allowed.

I'll reply separately to v2 of the "only remove entry from local_addr_list when sending a REMOVE_ADDR" series.

- Mat

maintainer
#4 lore raw

Hi Mat,

Quoted 33 lines · Mat Martineau
Quoted 22 lines · Matthieu Baerts

Hi Mat,

Quoted 10 lines · Mat Martineau

When path manager entries are deleted from the local address list, they are first unlinked from the address list using list_del_rcu(). The entries must not be freed until after the RCU grace period, but the existing code immediately frees the entry.

Use kfree_rcu_mightsleep() and adjust sk_omem_alloc in open code instead of using the sock_kfree_s() helper. This code path is only called in a netlink handler, so the "might sleep" function is preferable to adding a rarely-used rcu_head member to struct mptcp_pm_addr_entry.

Quoted 5 lines
Fixes 88d097316371 ("mptcp: drop free_list for deleting entries")

---

v2: Add comment explaining connection to sock_kfree_s, add "Fixes" tag

Thank you for the v2, and your reply on my previous review. This v2 looks good to me:

Quoted 8 lines

I guess I should wait to apply "only remove entry from local_addr_list when sending a REMOVE_ADDR" series first then, right? Are these other patches supposed to be fixes for net? They are not marked as that for the moment: in that case, should we add another patch to fix mptcp_userspace_pm_delete_local_addr() as well?

Quoted 6 lines

I don't think there's any issue or conflict with applying this to export-net first, it would leave the bug not fixed in mptcp_userspace_pm_delete_local_addr(). If this patch needs to stand alone, then it would need to be reworked to add a struct rcu_head to the local addr entry because mptcp_userspace_pm_delete_local_addr() gets called in contexts where sleepable calls aren't allowed.

Thank you, it makes sense. Now in our tree:

New patches for t/upstream-net and t/upstream:
- 49746c77f0b1: mptcp: pm: Defer freeing of MPTCP userspace path manager entries
- Results: 0142ff39fa9b..ce1452067424 (export-net)
- Results: f1e32c11be27..309e5b3a6b32 (export)

Tests are now in progress:

- export-net:
https://github.com/multipath-tcp/mptcp_net-next/commit/cbf7c52183ef1d88ba762839fb579780ff6150e8/checks
- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/b8b8b4ab98727371e1b3278b18314402cecd8da6/checks

Quoted 2 lines

I'll reply separately to v2 of the "only remove entry from local_addr_list when sending a REMOVE_ADDR" series.

Thank you!

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.