MPTCP Linux Development
 help / color / mirror / Atom feed
From: Geliang Tang <geliang@kernel.org>
To: Mat Martineau <martineau@kernel.org>, mptcp@lists.linux.dev
Subject: Re: [mptcp-net] mptcp: pm: Defer freeing of MPTCP userspace path manager entries
Date: Wed, 30 Apr 2025 17:15:05 +0800	[thread overview]
Message-ID: <e89f06093e7837386e9f38fdeb2e660f67a3bad3.camel@kernel.org> (raw)
In-Reply-To: <20250410025931.1882967-1-martineau@kernel.org>

Hi Mat,

On Wed, 2025-04-09 at 19:59 -0700, Mat Martineau wrote:
> 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.
> 
> Signed-off-by: Mat Martineau <martineau@kernel.org>
> ---
> 
> My first implementation did add a sock_kfree_rcu_s() function like
> Geliang suggested, but kfree_rcu() is a macro so that approach got
> complicated. sock_kfree_rcu_s_mightsleep() seemed cumbersome, so I

I thought about this again recently, and I think sock_krfree_s() is a
better name, and it matches sock_kfree_s() and sock_kzfree_s() better.
I just sent a patch named "sock: add sock_krfree_s helper" for this to
MPTCP ML, please review it for me.

Thanks,
-Geliang

> went
> ahead and open-coded it. This should be applied after Geliang's v2,
> which will delete similar code in a helper function.
> 
> ---
>  net/mptcp/pm_userspace.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
> index 7fc19b844384..959af1e42a97 100644
> --- a/net/mptcp/pm_userspace.c
> +++ b/net/mptcp/pm_userspace.c
> @@ -337,7 +337,8 @@ 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);
> +	atomic_sub(sizeof(*match), &sk->sk_omem_alloc);
>  
>  	err = 0;
>  out:


      parent reply	other threads:[~2025-04-30  9:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-10  2:59 [mptcp-net] mptcp: pm: Defer freeing of MPTCP userspace path manager entries Mat Martineau
2025-04-10  4:41 ` MPTCP CI
2025-04-10  6:37 ` MPTCP CI
2025-04-10 17:55 ` Matthieu Baerts
2025-04-10 18:54   ` Mat Martineau
2025-04-30  9:15 ` Geliang Tang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e89f06093e7837386e9f38fdeb2e660f67a3bad3.camel@kernel.org \
    --to=geliang@kernel.org \
    --cc=martineau@kernel.org \
    --cc=mptcp@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox