From: Paolo Abeni <pabeni@redhat.com>
To: Jakub Kicinski <kuba@kernel.org>, davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com,
andrew+netdev@lunn.ch, horms@kernel.org, sdf.kernel@gmail.com
Subject: Re: [PATCH net-next v2 1/2] net: use two lockdep classes for the netdev instance lock
Date: Tue, 29 Sep 2026 13:19:39 +0200 [thread overview]
Message-ID: <53c1812f-993b-4028-8ffe-6428113f5aae@redhat.com> (raw)
In-Reply-To: <20260926041832.1649675-1-kuba@kernel.org>
On 9/26/26 06:18, Jakub Kicinski wrote:
> diff --git a/net/core/dev.c b/net/core/dev.c
> index f660fccfc0db..a8eb382f40ca 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -568,6 +568,41 @@ 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;
> +
> + /* @a and @b must be of same class - both virtual or physical.
> + * cmp_fn won't be called for devices of different classes.
> + *
> + * For the same class only allow nesting under the protection
> + * of rtnl_lock. Note that we can't use lockdep_rtnl_is_held()
> + * here, it always answers UNKNOWN from within lockdep.
> + */
> + return rtnl_is_locked() ? -1 : 1;
> +}
> +
> +/* A virtual device can be locked before the physical device it leases
> + * queues from, see netdev_nl_queue_create_doit(). Keep the two kinds
> + * in separate classes so the dependency graph enforces the order;
> + * netdev_lock_cmp_fn() then only has to rule on same-class nesting.
> + */
> +void netdev_set_instance_lock_class(struct net_device *dev)
> +{
> + static struct lock_class_key netdev_virt_instance_lock_key;
> +
> + if (dev->dev.parent)
> + return;
> +
> + lockdep_set_class(&dev->lock, &netdev_virt_instance_lock_key);
> + lock_set_cmp_fn(&dev->lock, netdev_lock_cmp_fn, NULL);
> +}
Sashiko noted that mlx5 IB should enter !dev->dev.parent code path and
could possibly need a follow-up.
/P
next prev parent reply other threads:[~2026-09-29 11:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-26 4:18 [PATCH net-next v2 1/2] net: use two lockdep classes for the netdev instance lock Jakub Kicinski
2026-09-26 4:18 ` [PATCH net-next v2 2/2] selftests: net: add test for netdev instance lock ordering on unregister Jakub Kicinski
2026-09-26 7:08 ` [PATCH net-next v2 1/2] net: use two lockdep classes for the netdev instance lock Eric Dumazet
2026-09-28 18:21 ` Jakub Kicinski
2026-09-28 16:40 ` Stanislav Fomichev
2026-09-29 11:19 ` Paolo Abeni [this message]
2026-09-29 11:30 ` patchwork-bot+netdevbpf
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=53c1812f-993b-4028-8ffe-6428113f5aae@redhat.com \
--to=pabeni@redhat.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--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