lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <174265438746.356712.4413297068942699975.stgit@pro.pro>
Date: Sat, 22 Mar 2025 17:39:47 +0300
From: Kirill Tkhai <tkhai@...ru>
To: netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org
Cc: tkhai@...ru
Subject: [PATCH NET-PREV 15/51] iavf: Use __register_netdevice()

Attach, detach and take nd_lock in appropriate way:

nd_lock should be outside driver's locks.

Signed-off-by: Kirill Tkhai <tkhai@...ru>
---
 drivers/net/ethernet/intel/iavf/iavf_main.c |   59 +++++++++++++++++++--------
 1 file changed, 41 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ethernet/intel/iavf/iavf_main.c b/drivers/net/ethernet/intel/iavf/iavf_main.c
index f782402cd789..77fbe80c04a4 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_main.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_main.c
@@ -1968,14 +1968,36 @@ static int iavf_reinit_interrupt_scheme(struct iavf_adapter *adapter, bool runni
 static void iavf_finish_config(struct work_struct *work)
 {
 	struct iavf_adapter *adapter;
-	int pairs, err;
+	struct nd_lock *nd_lock;
+	int pairs, err = 0;
 
 	adapter = container_of(work, struct iavf_adapter, finish_config);
 
 	/* Always take RTNL first to prevent circular lock dependency */
 	rtnl_lock();
+	lock_netdev(adapter->netdev, &nd_lock);
 	mutex_lock(&adapter->crit_lock);
 
+	if (adapter->netdev->reg_state != NETREG_REGISTERED &&
+	    adapter->state == __IAVF_DOWN) {
+		err = __register_netdevice(adapter->netdev);
+	}
+
+	unlock_netdev(nd_lock);
+
+	if (err) {
+		dev_err(&adapter->pdev->dev, "Unable to register netdev (%d)\n",
+			err);
+
+		/* go back and try again.*/
+		iavf_free_rss(adapter);
+		iavf_free_misc_irq(adapter);
+		iavf_reset_interrupt_capability(adapter);
+		iavf_change_state(adapter,
+				  __IAVF_INIT_CONFIG_ADAPTER);
+		goto out;
+	}
+
 	if ((adapter->flags & IAVF_FLAG_SETUP_NETDEV_FEATURES) &&
 	    adapter->netdev->reg_state == NETREG_REGISTERED &&
 	    !test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section)) {
@@ -1985,22 +2007,6 @@ static void iavf_finish_config(struct work_struct *work)
 
 	switch (adapter->state) {
 	case __IAVF_DOWN:
-		if (adapter->netdev->reg_state != NETREG_REGISTERED) {
-			err = register_netdevice(adapter->netdev);
-			if (err) {
-				dev_err(&adapter->pdev->dev, "Unable to register netdev (%d)\n",
-					err);
-
-				/* go back and try again.*/
-				iavf_free_rss(adapter);
-				iavf_free_misc_irq(adapter);
-				iavf_reset_interrupt_capability(adapter);
-				iavf_change_state(adapter,
-						  __IAVF_INIT_CONFIG_ADAPTER);
-				goto out;
-			}
-		}
-
 		/* Set the real number of queues when reset occurs while
 		 * state == __IAVF_DOWN
 		 */
@@ -5054,6 +5060,7 @@ static int iavf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	struct net_device *netdev;
 	struct iavf_adapter *adapter = NULL;
 	struct iavf_hw *hw = NULL;
+	struct nd_lock *nd_lock;
 	int err;
 
 	err = pci_enable_device(pdev);
@@ -5085,6 +5092,12 @@ static int iavf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 	SET_NETDEV_DEV(netdev, &pdev->dev);
 
+	nd_lock = attach_new_nd_lock(netdev);
+	if (!nd_lock) {
+		err = -ENOMEM;
+		goto err_alloc_lock;
+	}
+
 	pci_set_drvdata(pdev, netdev);
 	adapter = netdev_priv(netdev);
 
@@ -5163,6 +5176,10 @@ static int iavf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 err_ioremap:
 	destroy_workqueue(adapter->wq);
 err_alloc_wq:
+	mutex_lock(&nd_lock->mutex);
+	detach_nd_lock(netdev);
+	mutex_unlock(&nd_lock->mutex);
+err_alloc_lock:
 	free_netdev(netdev);
 err_alloc_etherdev:
 	pci_release_regions(pdev);
@@ -5255,6 +5272,7 @@ static void iavf_remove(struct pci_dev *pdev)
 	struct iavf_mac_filter *f, *ftmp;
 	struct iavf_adapter *adapter;
 	struct net_device *netdev;
+	struct nd_lock *nd_lock;
 	struct iavf_hw *hw;
 
 	/* Don't proceed with remove if netdev is already freed */
@@ -5291,8 +5309,13 @@ static void iavf_remove(struct pci_dev *pdev)
 	cancel_delayed_work_sync(&adapter->watchdog_task);
 	cancel_work_sync(&adapter->finish_config);
 
-	if (netdev->reg_state == NETREG_REGISTERED)
+	if (netdev->reg_state == NETREG_REGISTERED) {
 		unregister_netdev(netdev);
+	} else {
+		lock_netdev(netdev, &nd_lock);
+		detach_nd_lock(netdev);
+		unlock_netdev(nd_lock);
+	}
 
 	mutex_lock(&adapter->crit_lock);
 	dev_info(&adapter->pdev->dev, "Removing device\n");


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ