Skip to contentSkip to conversation

be2net: Signal that the device cannot transmit during reconfiguration

PATCH Applied Benjamin Poirier 3 participants 7 messages Jul 16, 2019 – Jul 17, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 be2net: Signal that the device cannot transmit during reconfiguration

While changing the number of interrupt channels, be2net stops adapter operation (including netif_tx_disable()) but it doesn't signal that it cannot transmit. This may lead dev_watchdog() to falsely trigger during that time.

Add the missing call to netif_carrier_off(), following the pattern used in many other drivers. netif_carrier_on() is already taken care of in be_open().

---
 drivers/net/ethernet/emulex/benet/be_main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/emulex/benet/be_main.c +5 -1
index 82015c8a5ed7..b7a246b33599 100644
@@ -4697,8 +4697,12 @@ int be_update_queues(struct be_adapter *adapter)
 	struct net_device *netdev = adapter->netdev;
 	int status;
 
-	if (netif_running(netdev))
+	if (netif_running(netdev)) {
+		/* device cannot transmit now, avoid dev_watchdog timeouts */
+		netif_carrier_off(netdev);
+
 		be_close(netdev);
+	}
 
 	be_cancel_worker(adapter);
 
Signature · 1 line
2.22.0
maintainer Applied
#1 lore raw

From: Benjamin Poirier <[email protected]>
Date: Tue, 16 Jul 2019 17:16:55 +0900

Quoted 10 lines

While changing the number of interrupt channels, be2net stops adapter operation (including netif_tx_disable()) but it doesn't signal that it cannot transmit. This may lead dev_watchdog() to falsely trigger during that time.

Add the missing call to netif_carrier_off(), following the pattern used in many other drivers. netif_carrier_on() is already taken care of in be_open().

Applied.

#2 lore raw
In reply to Benjamin Poirier

I think there is a problem if dev_watchdog() is triggered before netif_carrier_off(). dev_watchdog() might call ->ndo_tx_timeout(), i.e. be_tx_timeout(), if txq timeout happens. Thus be_tx_timeout() could still be able to access the memory which is being freed by be_update_queues().

Thanks,
Firo

________________________________________
From: Benjamin Poirier
Sent: Tuesday, July 16, 2019 4:16 PM
To: David Miller
Cc: Ajit Khaparde; Sathya Perla; Somnath Kotur; Sriharsha Basavapatna; Saeed Mahameed; Firo Yang; [email protected]
Subject: [PATCH net] be2net: Signal that the device cannot transmit during reconfiguration

While changing the number of interrupt channels, be2net stops adapter operation (including netif_tx_disable()) but it doesn't signal that it cannot transmit. This may lead dev_watchdog() to falsely trigger during that time.

Add the missing call to netif_carrier_off(), following the pattern used in many other drivers. netif_carrier_on() is already taken care of in be_open().

---
 drivers/net/ethernet/emulex/benet/be_main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/ethernet/emulex/benet/be_main.c +5 -1
index 82015c8a5ed7..b7a246b33599 100644
@@ -4697,8 +4697,12 @@ int be_update_queues(struct be_adapter *adapter)
        struct net_device *netdev = adapter->netdev;
        int status;
 
-       if (netif_running(netdev))
+       if (netif_running(netdev)) {
+               /* device cannot transmit now, avoid dev_watchdog timeouts */
+               netif_carrier_off(netdev);
+
                be_close(netdev);
+       }
 
        be_cancel_worker(adapter);
 

--
2.22.0

#3 lore raw
Quoted 1 line · Firo Yang

I think there is a problem if dev_watchdog() is triggered before netif_carrier_off(). dev_watchdog() might call ->ndo_tx_timeout(), i.e. be_tx_timeout(), if txq timeout happens. Thus be_tx_timeout() could still be able to access the memory which is being freed by be_update_queues().

Good point. That's a separate problem which would occur in case of real tx timeout. How about this followup change:

drivers/net/ethernet/emulex/benet/be_main.c +5 -0
@@ -4698,8 +4698,13 @@ int be_update_queues(struct be_adapter *adapter)
 	int status;
 
 	if (netif_running(netdev)) {
+		/* be_tx_timeout() must not run concurrently with this
+		 * function, synchronize with an already-running dev_watchdog
+		 */
+		netif_tx_lock_bh(netdev);
 		/* device cannot transmit now, avoid dev_watchdog timeouts */
 		netif_carrier_off(netdev);
+		netif_tx_unlock_bh(netdev);
 
 		be_close(netdev);
 	}
#4 lore raw

I don't think this change could fix this problem because if SMP, dev_watchdog() could run on a different CPU.

Thanks,
Firo

#5 lore raw
Quoted 1 line · Firo Yang

I don't think this change could fix this problem because if SMP, dev_watchdog() could run on a different CPU.

hmm, SMP is clearly part of the picture here. The change I proposed revolves around the synchronization offered by dev->tx_global_lock:

we have
\ dev_watchdog

	\ netif_tx_lock
		spin_lock(&dev->tx_global_lock);
	...
	\ netif_tx_unlock

and

\ be_update_queues

	\ netif_tx_lock_bh
		\ netif_tx_lock
			spin_lock(&dev->tx_global_lock);

Makes sense?