Netdev List
 help / color / mirror / Atom feed
From: Junseo Lim <zirajs7@gmail.com>
To: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org
Cc: Simon Horman <horms@kernel.org>,
	linux-kernel@vger.kernel.org, Sechang Lim <rhkrqnwk98@gmail.com>
Subject: [WARN] net: lockdep reports false ABBA between netdev instance locks during batch unregister
Date: Mon,  3 Aug 2026 20:17:14 +0900	[thread overview]
Message-ID: <20260803111714.98235-1-zirajs7@gmail.com> (raw)

Hi,

We found a CONFIG_LOCKDEP warning in the netdev unregister path while
network namespaces are being cleaned up in batch.

The warning is:

WARNING: possible circular locking dependency detected
7.2.0-rc1-dirty #93 Not tainted

kworker/u8:2/38 is trying to acquire lock:
ffff888022d54d88 (&dev_instance_lock_key#15){+.+.}-{4:4}, at:
netdev_lock linux/include/linux/netdevice.h:2847 [inline]
unregister_netdevice_many_notify+0x541/0x2180 linux/net/core/dev.c:12400

but task is already holding lock:
ffff888116e10d88 (&dev_instance_lock_key#3){+.+.}-{4:4}, at:
netdev_lock linux/include/linux/netdevice.h:2847 [inline]
unregister_netdevice_many_notify+0x541/0x2180 linux/net/core/dev.c:12400

5 locks held by kworker/u8:2/38:
 #3: ffffffff986ea2e0 (rtnl_mutex){+.+.}-{4:4}, at:
 default_device_exit_batch+0xe1/0xa10 linux/net/core/dev.c:13079

Call Trace:
 unregister_netdevice_many_notify
 unregister_netdevice_many
 default_device_exit_batch
 cleanup_net
 worker_thread

The warning is triggered by the ops-locked close phase in
unregister_netdevice_many_notify():

list_for_each_entry(dev, head, unreg_list) {
	if (!(dev->flags & IFF_UP))
		continue;
	if (netdev_need_ops_lock(dev)) {
		list_add_tail(&dev->close_list, &close_head);
		netdev_lock(dev);
	}
	netif_close_many_and_unlock_cond(&close_head);
}
netif_close_many_and_unlock(&close_head);

This loop can accumulate multiple devices in close_head while their
per-device dev->lock mutexes are held. In this report, lockdep had already
recorded:

  dev_instance_lock_key#15 -> dev_instance_lock_key#3

and the current execution was trying to add the reverse dependency:

  dev_instance_lock_key#3 -> dev_instance_lock_key#15

The current stack is running under rtnl_mutex, and netdev_lock_cmp_fn()
also appears to intend to allow nested netdev locks under RTNL. However,
the two locks in this report are in distinct lockdep classes, so the
RTNL-based ordering exception does not prevent the cross-class ABBA report.

A possible way to avoid the warning is to make
netif_close_many_and_unlock_cond() always flush the accumulated close list
under CONFIG_LOCKDEP, instead of doing so only when lockdep depth exceeds
the limit:

static void netif_close_many_and_unlock_cond(struct list_head *close_head)
{
#ifdef CONFIG_LOCKDEP
	netif_close_many_and_unlock(close_head);
#endif
}

This keeps the non-CONFIG_LOCKDEP behavior unchanged, but makes
CONFIG_LOCKDEP skip batching in this close phase by flushing the close list
earlier.

This was found by our custom fuzzer developed by
Sechang Lim <rhkrqnwk98@gmail.com>.

Thanks,
Junseo Lim

                 reply	other threads:[~2026-08-03 11:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260803111714.98235-1-zirajs7@gmail.com \
    --to=zirajs7@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rhkrqnwk98@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