All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netdev@vger.kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, <linux-kernel@vger.kernel.org>,
	sdf@fomichev.me
Subject: [PATCH net 1/2] net: core: move unregister_many inner loops to a helper
Date: Fri, 10 Oct 2025 15:54:11 +0200	[thread overview]
Message-ID: <20251010135412.22602-2-fw@strlen.de> (raw)
In-Reply-To: <20251010135412.22602-1-fw@strlen.de>

Will be re-used in a followup patch, no functional change intended.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/core/dev.c | 57 +++++++++++++++++++++++++++++---------------------
 1 file changed, 33 insertions(+), 24 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index a64cef2c537e..9a09b48c9371 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -12176,11 +12176,42 @@ static void dev_memory_provider_uninstall(struct net_device *dev)
 	}
 }
 
+static void unregister_netdevice_close_many(struct list_head *head)
+{
+	struct net_device *dev;
+	LIST_HEAD(close_head);
+
+	/* If device is running, close it first. Start with ops locked... */
+	list_for_each_entry(dev, head, unreg_list) {
+		if (netdev_need_ops_lock(dev)) {
+			list_add_tail(&dev->close_list, &close_head);
+			netdev_lock(dev);
+		}
+	}
+	netif_close_many(&close_head, true);
+	/* ... now unlock them and go over the rest. */
+
+	list_for_each_entry(dev, head, unreg_list) {
+		if (netdev_need_ops_lock(dev))
+			netdev_unlock(dev);
+		else
+			list_add_tail(&dev->close_list, &close_head);
+	}
+	netif_close_many(&close_head, true);
+
+	list_for_each_entry(dev, head, unreg_list) {
+		/* And unlink it from device chain. */
+		unlist_netdevice(dev);
+		netdev_lock(dev);
+		WRITE_ONCE(dev->reg_state, NETREG_UNREGISTERING);
+		netdev_unlock(dev);
+	}
+}
+
 void unregister_netdevice_many_notify(struct list_head *head,
 				      u32 portid, const struct nlmsghdr *nlh)
 {
 	struct net_device *dev, *tmp;
-	LIST_HEAD(close_head);
 	int cnt = 0;
 
 	BUG_ON(dev_boot_phase);
@@ -12206,30 +12237,8 @@ void unregister_netdevice_many_notify(struct list_head *head,
 		BUG_ON(dev->reg_state != NETREG_REGISTERED);
 	}
 
-	/* If device is running, close it first. Start with ops locked... */
-	list_for_each_entry(dev, head, unreg_list) {
-		if (netdev_need_ops_lock(dev)) {
-			list_add_tail(&dev->close_list, &close_head);
-			netdev_lock(dev);
-		}
-	}
-	netif_close_many(&close_head, true);
-	/* ... now unlock them and go over the rest. */
-	list_for_each_entry(dev, head, unreg_list) {
-		if (netdev_need_ops_lock(dev))
-			netdev_unlock(dev);
-		else
-			list_add_tail(&dev->close_list, &close_head);
-	}
-	netif_close_many(&close_head, true);
+	unregister_netdevice_close_many(head);
 
-	list_for_each_entry(dev, head, unreg_list) {
-		/* And unlink it from device chain. */
-		unlist_netdevice(dev);
-		netdev_lock(dev);
-		WRITE_ONCE(dev->reg_state, NETREG_UNREGISTERING);
-		netdev_unlock(dev);
-	}
 	flush_all_backlogs();
 
 	synchronize_net();
-- 
2.49.1


  reply	other threads:[~2025-10-10 13:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-10 13:54 [PATCH net 0/2] net: avoid LOCKDEP MAX_LOCK_DEPTH splat Florian Westphal
2025-10-10 13:54 ` Florian Westphal [this message]
2025-10-10 13:54 ` [PATCH net 2/2] net: core: split unregister_netdevice list into smaller chunks Florian Westphal
2025-10-10 22:38   ` Stanislav Fomichev
2025-10-11 14:30     ` Florian Westphal

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=20251010135412.22602-2-fw@strlen.de \
    --to=fw@strlen.de \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    /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.