Netdev List
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: edumazet@google.com, sdf.kernel@gmail.com
Cc: davem@davemloft.net, netdev@vger.kernel.org, pabeni@redhat.com,
	andrew+netdev@lunn.ch, horms@kernel.org
Subject: Re: [PATCH net-next 1/2] net: use a single lockdep class for the netdev instance lock
Date: Fri, 25 Sep 2026 18:36:43 -0700	[thread overview]
Message-ID: <20260925183643.4f7d9eb8@kernel.org> (raw)
In-Reply-To: <20260923223545.3815583-1-kuba@kernel.org>

On Wed, 23 Sep 2026 15:35:44 -0700 Jakub Kicinski wrote:
>  	(dev)->qdisc_tx_busylock = &qdisc_tx_busylock_key;	\
>  	lockdep_set_class(&(dev)->addr_list_lock,		\
>  			  &dev_addr_list_lock_key);		\
> -	lockdep_set_class(&(dev)->lock,				\
> -			  &dev_instance_lock_key);		\
> -	lock_set_cmp_fn(&dev->lock, netdev_lock_cmp_fn, NULL);	\
>  	for (i = 0; i < (dev)->num_tx_queues; i++)		\
>  		lockdep_set_class(&(dev)->_tx[i]._xmit_lock,	\
>  				  &qdisc_xmit_lock_key);	\
> diff --git a/net/core/dev.c b/net/core/dev.c
> index c67900354fa6..bca7b267f937 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -568,6 +568,22 @@ static inline void netdev_set_addr_lockdep_class(struct net_device *dev)
>  }
>  #endif
>  
> +#ifdef CONFIG_PROVE_LOCKING
> +static int netdev_lock_cmp_fn(const struct lockdep_map *a,
> +			      const struct lockdep_map *b)
> +{
> +	if (a == b)
> +		return 0;
> +
> +	/* Allow locking multiple devices only under rtnl_lock,
> +	 * the exact order doesn't matter.
> +	 * Note that upper devices don't lock their ops, so nesting
> +	 * mostly happens in batched device removal for now.
> +	 */
> +	return lockdep_rtnl_is_held() ? -1 : 1;
> +}
> +#endif

ugh, clashiko points out this is weakening the condition more than
I thought. Apparently lockdep_rtnl_is_held() is always UNKNOWN (-1)
when called from inside lockdep code ;( So this lockdep_rtnl_is_held()
is always true, and we would never fire a lockdep warning on instance
locks.

I need to switch to non-lockdep rtnl_is_held(), I think, and we either
bring back the classes for virt devices (but one class for all) or
we explicitly handle the virt->phys order that queue leasing needs.
Coding it up now, let me see which one is less ugly.

      parent reply	other threads:[~2026-09-26  1:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23 22:35 [PATCH net-next 1/2] net: use a single lockdep class for the netdev instance lock Jakub Kicinski
2026-09-23 22:35 ` [PATCH net-next 2/2] selftests: net: add test for netdev instance lock ordering on unregister Jakub Kicinski
2026-09-24 15:18   ` Eric Dumazet
2026-09-24 15:53   ` Stanislav Fomichev
2026-09-24 15:17 ` [PATCH net-next 1/2] net: use a single lockdep class for the netdev instance lock Eric Dumazet
2026-09-24 15:53 ` Stanislav Fomichev
2026-09-26  1:36 ` Jakub Kicinski [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=20260925183643.4f7d9eb8@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf.kernel@gmail.com \
    /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