All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthieu Baerts <matttbe@kernel.org>
To: Geliang Tang <geliang@kernel.org>, mptcp@lists.linux.dev
Cc: Geliang Tang <tanggeliang@kylinos.cn>
Subject: Re: [PATCH mptcp-next v2 1/2] mptcp: give MPTCP sockets a distinct lockdep class
Date: Fri, 16 Oct 2026 10:03:29 +0200	[thread overview]
Message-ID: <f9145188-a354-49e9-ad5f-889a2895e4fa@kernel.org> (raw)
In-Reply-To: <8651f29fb4e11de14a7ea7d05d97a33b1e5390f3.1792114102.git.tanggeliang@kylinos.cn>

Hi Geliang,

Thank you for the new version.

On 16/10/2026 03:35, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> MPTCP sockets and their subflows share the same k-sk_lock-AF_INET
> lockdep class. When both are kernel sockets, lockdep flags every path
> that holds the MPTCP socket lock and then locks a subflow (setsockopt,
> connect, bind, worker send-ack) as "possible recursive locking".
> 
> Extract the lock reclassification logic from PM listener socket creation
> into mptcp_reclassify_socket() helper to reclassify MPTCP socket locks
> to a distinct class (msk_lock-AF_INET for IPv4, msk_lock-AF_INET6 for
> IPv6). Call it from __mptcp_init_sock() to cover both active (connect)
> and passive (accept/clone) socket creation paths.
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  net/mptcp/pm_kernel.c | 18 ++++++++++++------
>  net/mptcp/protocol.c  |  3 +++
>  net/mptcp/protocol.h  |  2 ++
>  3 files changed, 17 insertions(+), 6 deletions(-)
> 
> diff --git a/net/mptcp/pm_kernel.c b/net/mptcp/pm_kernel.c
> index d3014bf57bf3..5e8792ad38ca 100644
> --- a/net/mptcp/pm_kernel.c
> +++ b/net/mptcp/pm_kernel.c
> @@ -849,10 +849,20 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet,
>  static struct lock_class_key mptcp_slock_keys[2];
>  static struct lock_class_key mptcp_keys[2];
>  
> +void mptcp_reclassify_socket(struct sock *sk)
> +{
> +	bool is_ipv6 = sk->sk_family == AF_INET6;
> +
> +	sock_lock_init_class_and_name(sk,
> +				      is_ipv6 ? "mlock-AF_INET6" : "mlock-AF_INET",
> +				      &mptcp_slock_keys[is_ipv6],
> +				      is_ipv6 ? "msk_lock-AF_INET6" : "msk_lock-AF_INET",
> +				      &mptcp_keys[is_ipv6]);
> +}

Good idea to share this code here, but then I think it should be better
in net/mptcp/protocol.c than in the in-kernel PM.

>  static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
>  					    struct mptcp_pm_addr_entry *entry)
>  {
> -	bool is_ipv6 = entry->addr.family == AF_INET6;
>  	int addrlen = sizeof(struct sockaddr_in);
>  	struct sockaddr_storage addr;
>  	struct sock *newsk, *ssk;
> @@ -874,11 +884,7 @@ static int mptcp_pm_nl_create_listen_socket(struct sock *sk,
>  	 * modifiers in several places, re-init the lock class for the msk
>  	 * socket to an mptcp specific one.
>  	 */
> -	sock_lock_init_class_and_name(newsk,
> -				      is_ipv6 ? "mlock-AF_INET6" : "mlock-AF_INET",
> -				      &mptcp_slock_keys[is_ipv6],
> -				      is_ipv6 ? "msk_lock-AF_INET6" : "msk_lock-AF_INET",
> -				      &mptcp_keys[is_ipv6]);
> +	mptcp_reclassify_socket(newsk);
>  
>  	lock_sock(newsk);
>  	ssk = __mptcp_nmpc_sk(mptcp_sk(newsk));
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 60cbd91be632..68f339311993 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -3245,6 +3245,9 @@ static void __mptcp_init_sock(struct sock *sk)
>  	/* re-use the csk retrans timer for MPTCP-level retrans */
>  	timer_setup(&sk->mptcp_retransmit_timer, mptcp_retransmit_timer, 0);
>  	timer_setup(&msk->sk.mptcp_tout_timer, mptcp_tout_timer, 0);
> +
> +	if (sk->sk_socket)

If you need this check here, that means the reclassification is not
always done, thus this new helper is certainly called from the wrong place.

> +		mptcp_reclassify_socket(sk);
>  }
>  
>  static void mptcp_ca_reset(struct sock *sk)
> diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
> index ed2f363bb915..325499e65236 100644
> --- a/net/mptcp/protocol.h
> +++ b/net/mptcp/protocol.h
> @@ -1265,6 +1265,8 @@ u8 mptcp_pm_get_endp_fullmesh_max(const struct mptcp_sock *msk);
>  u8 mptcp_pm_get_limit_add_addr_accepted(const struct mptcp_sock *msk);
>  u8 mptcp_pm_get_limit_extra_subflows(const struct mptcp_sock *msk);
>  
> +void mptcp_reclassify_socket(struct sock *sk);
> +
>  /* called under PM lock */
>  static inline void __mptcp_pm_close_subflow(struct mptcp_sock *msk)
>  {

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.


  parent reply	other threads:[~2026-10-16  8:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-16  1:35 [PATCH mptcp-next v2 0/2] add distinct lockdep class for MPTCP sockets Geliang Tang
2026-10-16  1:35 ` [PATCH mptcp-next v2 1/2] mptcp: give MPTCP sockets a distinct lockdep class Geliang Tang
2026-10-16  1:46   ` sashiko-bot
2026-10-16  8:03   ` Matthieu Baerts [this message]
2026-10-16  1:35 ` [PATCH mptcp-next v2 2/2] mptcp: kunit: add sockopt test for subflow socket locking Geliang Tang
2026-10-16  8:05   ` Matthieu Baerts
2026-10-16  2:49 ` [PATCH mptcp-next v2 0/2] add distinct lockdep class for MPTCP sockets MPTCP CI

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=f9145188-a354-49e9-ad5f-889a2895e4fa@kernel.org \
    --to=matttbe@kernel.org \
    --cc=geliang@kernel.org \
    --cc=mptcp@lists.linux.dev \
    --cc=tanggeliang@kylinos.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.