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 1/2] mptcp: give MPTCP sockets a distinct lockdep class
Date: Thu, 15 Oct 2026 19:30:44 +0200	[thread overview]
Message-ID: <e30d15a5-10b2-4efe-8fc7-6b77d18ac154@kernel.org> (raw)
In-Reply-To: <23c5f34fa80bff87b4c49981b1ab19d13bf7f136.1792060837.git.tanggeliang@kylinos.cn>

Hi Geliang,

Thank you for the patches!

On 15/10/2026 12:42, 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".
> 
> Reclassify the MPTCP socket lock in mptcp_init_sock() to use a distinct
> lock class (sk_lock-AF_INET-MPTCP for IPv4, sk_lock-AF_INET6-MPTCP for
> IPv6). This approach is similar to nvme-tcp and avoids the need to
> reclassify each subflow socket individually.
> 
> The implementation is based on nvme_tcp_reclassify_socket() from
> drivers/nvme/host/tcp.c.

Note: we also do that in pm_kernel.c for the extra listening socket.

> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  net/mptcp/protocol.c | 37 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 37 insertions(+)
> 
> diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
> index 60cbd91be632..e63896a60595 100644
> --- a/net/mptcp/protocol.c
> +++ b/net/mptcp/protocol.c
> @@ -56,6 +56,41 @@ DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions) = {
>  };
>  static struct net_device *mptcp_napi_dev;
>  
> +#ifdef CONFIG_DEBUG_LOCK_ALLOC

In pm_kernel.c we don't have that. Do we really need it? If all the
functions are nops, maybe not?

> +/* distinct lockdep class for MPTCP sockets */
> +static struct lock_class_key mptcp_sk_key[2];
> +static struct lock_class_key mptcp_slock_key[2];
> +
> +static void mptcp_reclassify_socket(struct socket *sock)
> +{
> +	struct sock *sk = sock->sk;
> +
> +	if (WARN_ON_ONCE(!sock_allow_reclassification(sk)))
> +		return;
> +
> +	switch (sk->sk_family) {
> +	case AF_INET:
> +		sock_lock_init_class_and_name(sk, "slock-AF_INET-MPTCP",
> +					      &mptcp_slock_key[0],
> +					      "sk_lock-AF_INET-MPTCP",
> +					      &mptcp_sk_key[0]);
> +		break;
> +#if IS_ENABLED(CONFIG_MPTCP_IPV6)
> +	case AF_INET6:
> +		sock_lock_init_class_and_name(sk, "slock-AF_INET6-MPTCP",
> +					      &mptcp_slock_key[1],
> +					      "sk_lock-AF_INET6-MPTCP",
> +					      &mptcp_sk_key[1]);

In pm_kernel.c we only call sock_lock_init_class_and_name() once. Maybe
we should do the same here, then no need to have a special helper?

> +		break;
> +#endif
> +	default:
> +		WARN_ON_ONCE(1);
> +	}
> +}
> +#else
> +static void mptcp_reclassify_socket(struct socket *sock) { }
> +#endif
> +
>  /* Returns end sequence number of the receiver's advertised window */
>  u64 mptcp_wnd_end(const struct mptcp_sock *msk)
>  {
> @@ -3292,6 +3327,8 @@ static int mptcp_init_sock(struct sock *sk)
>  	sk->sk_sndbuf = READ_ONCE(net->ipv4.sysctl_tcp_wmem[1]);
>  	sk->sk_write_space = sk_stream_write_space;
>  
> +	mptcp_reclassify_socket(sk->sk_socket);

Indeed, better in __mptcp_init_sock().

> +
>  	return 0;
>  }
>  

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


  parent reply	other threads:[~2026-10-15 17:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 10:42 [PATCH mptcp-next 0/2] add distinct lockdep class for MPTCP sockets Geliang Tang
2026-10-15 10:42 ` [PATCH mptcp-next 1/2] mptcp: give MPTCP sockets a distinct lockdep class Geliang Tang
2026-10-15 10:59   ` sashiko-bot
2026-10-15 17:30   ` Matthieu Baerts [this message]
2026-10-15 10:42 ` [PATCH mptcp-next 2/2] mptcp: kunit: add sockopt test for subflow socket locking Geliang Tang
2026-10-15 11:48 ` [PATCH mptcp-next 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=e30d15a5-10b2-4efe-8fc7-6b77d18ac154@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.