netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V1 net 0/3] net: ena: hibernation and rmmod bug fixes
@ 2018-11-19 10:05 akiyano
  2018-11-19 10:05 ` [PATCH V1 net 1/3] net: ena: fix crash during failed resume from hibernation akiyano
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: akiyano @ 2018-11-19 10:05 UTC (permalink / raw)
  To: davem, netdev
  Cc: Arthur Kiyanovski, dwmw, zorik, matua, saeedb, msw, aliguori,
	nafea, gtzalik, netanel, alisaidi

From: Arthur Kiyanovski <akiyano@amazon.com>

This patchset includes 2 bug fixes:
1. A fix to a crash during resume from hibernation.
2. A fix to an illegal memory access during driver removal (e.g. during rmmod)
   which might cause a crash in certain systems.

The subminor number in the driver version is also promoted to indicate driver
was changed.

Arthur Kiyanovski (3):
  net: ena: fix crash during failed resume from hibernation
  net: ena: fix crash during ena_remove()
  net: ena: update driver version from 2.0.1 to 2.0.2

 drivers/net/ethernet/amazon/ena/ena_netdev.c | 23 +++++++++++------------
 drivers/net/ethernet/amazon/ena/ena_netdev.h |  2 +-
 2 files changed, 12 insertions(+), 13 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH V1 net 1/3] net: ena: fix crash during failed resume from hibernation
  2018-11-19 10:05 [PATCH V1 net 0/3] net: ena: hibernation and rmmod bug fixes akiyano
@ 2018-11-19 10:05 ` akiyano
  2018-11-19 10:05 ` [PATCH V1 net 2/3] net: ena: fix crash during ena_remove() akiyano
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: akiyano @ 2018-11-19 10:05 UTC (permalink / raw)
  To: davem, netdev
  Cc: Arthur Kiyanovski, dwmw, zorik, matua, saeedb, msw, aliguori,
	nafea, gtzalik, netanel, alisaidi

From: Arthur Kiyanovski <akiyano@amazon.com>

During resume from hibernation if ena_restore_device fails,
ena_com_dev_reset() is called, and uses the readless read mechanism,
which was already destroyed by the call to
ena_com_mmio_reg_read_request_destroy(). This causes a NULL pointer
reference.

In this commit we switch the call order of the above two functions
to avoid this crash.

Fixes: d7703ddbd7c9 ("net: ena: fix rare bug when failed restart/resume is followed by driver removal")
Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 18956e7..1d3cead 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -2694,8 +2694,8 @@ static int ena_restore_device(struct ena_adapter *adapter)
 	ena_com_abort_admin_commands(ena_dev);
 	ena_com_wait_for_abort_completion(ena_dev);
 	ena_com_admin_destroy(ena_dev);
-	ena_com_mmio_reg_read_request_destroy(ena_dev);
 	ena_com_dev_reset(ena_dev, ENA_REGS_RESET_DRIVER_INVALID_STATE);
+	ena_com_mmio_reg_read_request_destroy(ena_dev);
 err:
 	clear_bit(ENA_FLAG_DEVICE_RUNNING, &adapter->flags);
 	clear_bit(ENA_FLAG_ONGOING_RESET, &adapter->flags);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH V1 net 2/3] net: ena: fix crash during ena_remove()
  2018-11-19 10:05 [PATCH V1 net 0/3] net: ena: hibernation and rmmod bug fixes akiyano
  2018-11-19 10:05 ` [PATCH V1 net 1/3] net: ena: fix crash during failed resume from hibernation akiyano
@ 2018-11-19 10:05 ` akiyano
  2018-11-19 10:05 ` [PATCH V1 net 3/3] net: ena: update driver version from 2.0.1 to 2.0.2 akiyano
  2018-11-19 23:13 ` [PATCH V1 net 0/3] net: ena: hibernation and rmmod bug fixes David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: akiyano @ 2018-11-19 10:05 UTC (permalink / raw)
  To: davem, netdev
  Cc: Arthur Kiyanovski, dwmw, zorik, matua, saeedb, msw, aliguori,
	nafea, gtzalik, netanel, alisaidi

From: Arthur Kiyanovski <akiyano@amazon.com>

In ena_remove() we have the following stack call:
ena_remove()
  unregister_netdev()
  ena_destroy_device()
    netif_carrier_off()

Calling netif_carrier_off() causes linkwatch to try to handle the
link change event on the already unregistered netdev, which leads
to a read from an unreadable memory address.

This patch switches the order of the two functions, so that
netif_carrier_off() is called on a regiestered netdev.

To accomplish this fix we also had to:
1. Remove the set bit ENA_FLAG_TRIGGER_RESET
2. Add a sanitiy check in ena_close()
both to prevent double device reset (when calling unregister_netdev()
ena_close is called, but the device was already deleted in
ena_destroy_device()).
3. Set the admin_queue running state to false to avoid using it after
device was reset (for example when calling ena_destroy_all_io_queues()
right after ena_com_dev_reset() in ena_down)

Fixes: 944b28aa2982 ("net: ena: fix missing lock during device destruction")
Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_netdev.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c b/drivers/net/ethernet/amazon/ena/ena_netdev.c
index 1d3cead..a70bb1b 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
@@ -1848,6 +1848,8 @@ static void ena_down(struct ena_adapter *adapter)
 		rc = ena_com_dev_reset(adapter->ena_dev, adapter->reset_reason);
 		if (rc)
 			dev_err(&adapter->pdev->dev, "Device reset failed\n");
+		/* stop submitting admin commands on a device that was reset */
+		ena_com_set_admin_running_state(adapter->ena_dev, false);
 	}
 
 	ena_destroy_all_io_queues(adapter);
@@ -1914,6 +1916,9 @@ static int ena_close(struct net_device *netdev)
 
 	netif_dbg(adapter, ifdown, netdev, "%s\n", __func__);
 
+	if (!test_bit(ENA_FLAG_DEVICE_RUNNING, &adapter->flags))
+		return 0;
+
 	if (test_bit(ENA_FLAG_DEV_UP, &adapter->flags))
 		ena_down(adapter);
 
@@ -2613,9 +2618,7 @@ static void ena_destroy_device(struct ena_adapter *adapter, bool graceful)
 		ena_down(adapter);
 
 	/* Stop the device from sending AENQ events (in case reset flag is set
-	 *  and device is up, ena_close already reset the device
-	 * In case the reset flag is set and the device is up, ena_down()
-	 * already perform the reset, so it can be skipped.
+	 *  and device is up, ena_down() already reset the device.
 	 */
 	if (!(test_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags) && dev_up))
 		ena_com_dev_reset(adapter->ena_dev, adapter->reset_reason);
@@ -3452,6 +3455,8 @@ static int ena_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	ena_com_rss_destroy(ena_dev);
 err_free_msix:
 	ena_com_dev_reset(ena_dev, ENA_REGS_RESET_INIT_ERR);
+	/* stop submitting admin commands on a device that was reset */
+	ena_com_set_admin_running_state(ena_dev, false);
 	ena_free_mgmnt_irq(adapter);
 	ena_disable_msix(adapter);
 err_worker_destroy:
@@ -3498,18 +3503,12 @@ static void ena_remove(struct pci_dev *pdev)
 
 	cancel_work_sync(&adapter->reset_task);
 
-	unregister_netdev(netdev);
-
-	/* If the device is running then we want to make sure the device will be
-	 * reset to make sure no more events will be issued by the device.
-	 */
-	if (test_bit(ENA_FLAG_DEVICE_RUNNING, &adapter->flags))
-		set_bit(ENA_FLAG_TRIGGER_RESET, &adapter->flags);
-
 	rtnl_lock();
 	ena_destroy_device(adapter, true);
 	rtnl_unlock();
 
+	unregister_netdev(netdev);
+
 	free_netdev(netdev);
 
 	ena_com_rss_destroy(ena_dev);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH V1 net 3/3] net: ena: update driver version from 2.0.1 to 2.0.2
  2018-11-19 10:05 [PATCH V1 net 0/3] net: ena: hibernation and rmmod bug fixes akiyano
  2018-11-19 10:05 ` [PATCH V1 net 1/3] net: ena: fix crash during failed resume from hibernation akiyano
  2018-11-19 10:05 ` [PATCH V1 net 2/3] net: ena: fix crash during ena_remove() akiyano
@ 2018-11-19 10:05 ` akiyano
  2018-11-19 23:13 ` [PATCH V1 net 0/3] net: ena: hibernation and rmmod bug fixes David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: akiyano @ 2018-11-19 10:05 UTC (permalink / raw)
  To: davem, netdev
  Cc: Arthur Kiyanovski, dwmw, zorik, matua, saeedb, msw, aliguori,
	nafea, gtzalik, netanel, alisaidi

From: Arthur Kiyanovski <akiyano@amazon.com>

Update driver version due to critical bug fixes.

Signed-off-by: Arthur Kiyanovski <akiyano@amazon.com>
---
 drivers/net/ethernet/amazon/ena/ena_netdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.h b/drivers/net/ethernet/amazon/ena/ena_netdev.h
index 5218736..dc8b617 100644
--- a/drivers/net/ethernet/amazon/ena/ena_netdev.h
+++ b/drivers/net/ethernet/amazon/ena/ena_netdev.h
@@ -45,7 +45,7 @@
 
 #define DRV_MODULE_VER_MAJOR	2
 #define DRV_MODULE_VER_MINOR	0
-#define DRV_MODULE_VER_SUBMINOR 1
+#define DRV_MODULE_VER_SUBMINOR 2
 
 #define DRV_MODULE_NAME		"ena"
 #ifndef DRV_MODULE_VERSION
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH V1 net 0/3] net: ena: hibernation and rmmod bug fixes
  2018-11-19 10:05 [PATCH V1 net 0/3] net: ena: hibernation and rmmod bug fixes akiyano
                   ` (2 preceding siblings ...)
  2018-11-19 10:05 ` [PATCH V1 net 3/3] net: ena: update driver version from 2.0.1 to 2.0.2 akiyano
@ 2018-11-19 23:13 ` David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2018-11-19 23:13 UTC (permalink / raw)
  To: akiyano
  Cc: netdev, dwmw, zorik, matua, saeedb, msw, aliguori, nafea, gtzalik,
	netanel, alisaidi

From: <akiyano@amazon.com>
Date: Mon, 19 Nov 2018 12:05:19 +0200

> From: Arthur Kiyanovski <akiyano@amazon.com>
> 
> This patchset includes 2 bug fixes:
> 1. A fix to a crash during resume from hibernation.
> 2. A fix to an illegal memory access during driver removal (e.g. during rmmod)
>    which might cause a crash in certain systems.
> 
> The subminor number in the driver version is also promoted to indicate driver
> was changed.

Series applied, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-11-20  9:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-19 10:05 [PATCH V1 net 0/3] net: ena: hibernation and rmmod bug fixes akiyano
2018-11-19 10:05 ` [PATCH V1 net 1/3] net: ena: fix crash during failed resume from hibernation akiyano
2018-11-19 10:05 ` [PATCH V1 net 2/3] net: ena: fix crash during ena_remove() akiyano
2018-11-19 10:05 ` [PATCH V1 net 3/3] net: ena: update driver version from 2.0.1 to 2.0.2 akiyano
2018-11-19 23:13 ` [PATCH V1 net 0/3] net: ena: hibernation and rmmod bug fixes David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).