Skip to contentSkip to conversation

iavf: Fix panics due to active work queues being freed in iavf_remove()

PATCH New Ken Cox 2 participants 12 messages Dec 8, 2021 – Dec 14, 2021

Subsystems (2)
lore
Share & tools
lore

Ken Cox

author
#0 lore raw

cover iavf: Fix panics due to active work queues being freed in iavf_remove()

This series fixes panics that occur after iavf_remove() is called.

The panics occur because the iavf_adapter structure is freed at the end
of iavf_remove(), but it is possible that new work has been scheduled using
the work_struct's contained within the iavf_adapter structure. If this occurs, the system will panic when it later tries to process the work queue.

Ken Cox (2):
iavf: Fix panic in iavf_remove
iavf: Prevent reset from being scheduled while adapter is being
removed

 drivers/net/ethernet/intel/iavf/iavf_ethtool.c  |  7 +++++--
 drivers/net/ethernet/intel/iavf/iavf_main.c     | 17 +++++++++++------
 drivers/net/ethernet/intel/iavf/iavf_virtchnl.c |  4 +++-
 3 files changed, 19 insertions(+), 9 deletions(-)
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH 1/2 iavf: Fix panic in iavf_remove

It's possible for the client_task to get scheduled by the watchdog after cancel_delayed_work_sync(&adapter->client_task); This can cause a panic because free_netdev() is called with the client_task still queued on the work queue.

The stack backtrace usually looks similar to:

[  121.272963] Workqueue:  0x0 (iavf)
[  121.272969] RIP: 0010:__list_del_entry_valid.cold.1+0x20/0x4c
...
[  121.272980] Call Trace:
[  121.272985]  move_linked_works+0x49/0xa0
[  121.272988]  pwq_activate_delayed_work+0x43/0x100
[  121.272991]  pwq_dec_nr_in_flight+0x5d/0x90
[  121.272993]  worker_thread+0x30/0x370
[  121.272995]  ? process_one_work+0x420/0x420
[  121.272998]  kthread+0x15d/0x180
[  121.273000]  ? __kthread_parkme+0xa0/0xa0
[  121.273003]  ret_from_fork+0x1f/0x40
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +1 -1
index 6c2afbc8acbcd..63eec7edbf60a 100644
@@ -3940,7 +3940,6 @@ static void iavf_remove(struct pci_dev *pdev)
 	set_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section);
 	cancel_delayed_work_sync(&adapter->init_task);
 	cancel_work_sync(&adapter->reset_task);
-	cancel_delayed_work_sync(&adapter->client_task);
 	if (adapter->netdev_registered) {
 		unregister_netdev(netdev);
 		adapter->netdev_registered = false;
@@ -3974,6 +3973,7 @@ static void iavf_remove(struct pci_dev *pdev)
 	iavf_free_q_vectors(adapter);
 
 	cancel_delayed_work_sync(&adapter->watchdog_task);
+	cancel_delayed_work_sync(&adapter->client_task);
 
 	cancel_work_sync(&adapter->adminq_task);
 
Signature · 1 line
2.31.1
#2 lore raw

PATCH 1/2 iavf: Fix panic in iavf_remove

drivers/net/ethernet/intel/iavf/iavf_main.c static void iavf_remove(struct pci_dev *pdev)

Quoted 40 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Ken Cox
Sent: ?roda, 8 grudnia 2021 11:22
To: intel-wired-lan at osuosl.org
Cc: Ken Cox <[email protected]>
Subject: [Intel-wired-lan] [Patch 1/2] iavf: Fix panic in iavf_remove

It's possible for the client_task to get scheduled by the watchdog after cancel_delayed_work_sync(&adapter->client_task); This can cause a panic because free_netdev() is called with the client_task still queued on the work queue.

The stack backtrace usually looks similar to:

[  121.272963] Workqueue:  0x0 (iavf)
[  121.272969] RIP: 0010:__list_del_entry_valid.cold.1+0x20/0x4c
...
[  121.272980] Call Trace:
[  121.272985]  move_linked_works+0x49/0xa0 [  121.272988]
pwq_activate_delayed_work+0x43/0x100
[  121.272991]  pwq_dec_nr_in_flight+0x5d/0x90 [  121.272993]
worker_thread+0x30/0x370 [  121.272995]  ?
process_one_work+0x420/0x420 [  121.272998]  kthread+0x15d/0x180 [
121.273000]  ? __kthread_parkme+0xa0/0xa0 [  121.273003]
ret_from_fork+0x1f/0x40
---
 drivers/net/ethernet/intel/iavf/iavf_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +0 -0
index 6c2afbc8acbcd..63eec7edbf60a 100644
@@ -3940,7 +3940,6 @@ static void iavf_remove(struct pci_dev *pdev)
#3 lore raw

PATCH 1/2 iavf: Fix panic in iavf_remove

I'm sorry, this was not sent to me, it is still untested

#4 lore raw

PATCH 1/2 iavf: Fix panic in iavf_remove

In reply to Ken Cox
Quoted 42 lines · Ken Cox

It's possible for the client_task to get scheduled by the watchdog after cancel_delayed_work_sync(&adapter->client_task);? This can cause
a panic because free_netdev() is called with the client_task still queued
on the work queue.

The stack backtrace usually looks similar to:

[? 121.272963] Workqueue:? 0x0 (iavf)
[? 121.272969] RIP: 0010:__list_del_entry_valid.cold.1+0x20/0x4c
...
[? 121.272980] Call Trace:
[? 121.272985]? move_linked_works+0x49/0xa0
[? 121.272988]? pwq_activate_delayed_work+0x43/0x100 [? 121.272991]? pwq_dec_nr_in_flight+0x5d/0x90
[? 121.272993]? worker_thread+0x30/0x370
[? 121.272995]? ? process_one_work+0x420/0x420
[? 121.272998]? kthread+0x15d/0x180
[? 121.273000]? ? __kthread_parkme+0xa0/0xa0
[? 121.273003]? ret_from_fork+0x1f/0x40

---
?drivers/net/ethernet/intel/iavf/iavf_main.c | 2 +- ?1 file changed, 1 insertion(+), 1 deletion(-)

drivers/net/ethernet/intel/iavf/iavf_main.c +0 -1
index 6c2afbc8acbcd..63eec7edbf60a 100644
@@ -3940,7 +3940,6 @@ static void iavf_remove(struct pci_dev *pdev)
 ????????set_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section);
 ????????cancel_delayed_work_sync(&adapter->init_task);
 ????????cancel_work_sync(&adapter->reset_task);
-???????cancel_delayed_work_sync(&adapter->client_task);
 ????????if (adapter->netdev_registered) {
 ????????????????unregister_netdev(netdev);
 ????????????????adapter->netdev_registered = false;
@@ -3974,6 +3973,7 @@ static void iavf_remove(struct pci_dev *pdev)
 ????????iavf_free_q_vectors(adapter);
Quoted 6 lines

? ????????cancel_delayed_work_sync(&adapter->watchdog_task); +???????cancel_delayed_work_sync(&adapter->client_task); ? ????????cancel_work_sync(&adapter->adminq_task); ?

Hi Ken,

What tree is this patch based on? This doesn't apply to either of the IWL trees or the netdev trees.

The ordering looks correct on the kernel tree with watchdog_task being cancelled before the client_task [1]. However, we do have an extra 'cancel_delayed_work_sync(&adapter->watchdog_task)'. I'll get a patch together to remove the extra one.

Thanks,
Tony

[1] https://elixir.bootlin.com/linux/v5.16-
rc5/source/drivers/net/ethernet/intel/iavf/iavf_main.c#3979

author
#5 lore raw

PATCH 1/2 iavf: Fix panic in iavf_remove

Quoted 47 lines · Anthony L
Quoted 46 lines · Ken Cox

It's possible for the client_task to get scheduled by the watchdog after cancel_delayed_work_sync(&adapter->client_task);? This can cause
a panic because free_netdev() is called with the client_task still queued
on the work queue.

The stack backtrace usually looks similar to:

[? 121.272963] Workqueue:? 0x0 (iavf)
[? 121.272969] RIP: 0010:__list_del_entry_valid.cold.1+0x20/0x4c
...
[? 121.272980] Call Trace:
[? 121.272985]? move_linked_works+0x49/0xa0
[? 121.272988]? pwq_activate_delayed_work+0x43/0x100 [? 121.272991]? pwq_dec_nr_in_flight+0x5d/0x90
[? 121.272993]? worker_thread+0x30/0x370
[? 121.272995]? ? process_one_work+0x420/0x420
[? 121.272998]? kthread+0x15d/0x180
[? 121.273000]? ? __kthread_parkme+0xa0/0xa0
[? 121.273003]? ret_from_fork+0x1f/0x40

---
 ?drivers/net/ethernet/intel/iavf/iavf_main.c | 2 +-

?1 file changed, 1 insertion(+), 1 deletion(-)

drivers/net/ethernet/intel/iavf/iavf_main.c +1 -1
index 6c2afbc8acbcd..63eec7edbf60a 100644
@@ -3940,7 +3940,6 @@ static void iavf_remove(struct pci_dev *pdev)
 ????????set_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section);
 ????????cancel_delayed_work_sync(&adapter->init_task);
 ????????cancel_work_sync(&adapter->reset_task);
-???????cancel_delayed_work_sync(&adapter->client_task);
 ????????if (adapter->netdev_registered) {
 ????????????????unregister_netdev(netdev);
 ????????????????adapter->netdev_registered = false;
@@ -3974,6 +3973,7 @@ static void iavf_remove(struct pci_dev *pdev)
 ????????iavf_free_q_vectors(adapter);
 
 ????????cancel_delayed_work_sync(&adapter->watchdog_task);
+???????cancel_delayed_work_sync(&adapter->client_task);
 
Quoted 7 lines

drivers/net/ethernet/intel/iavf/iavf_main.c static void iavf_remove(struct pci_dev *pdev) · line 3979

Quoted 2 lines
drivers/net/ethernet/intel/iavf/iavf_main.c +0 -0
 ????????cancel_work_sync(&adapter->adminq_task);
 

Hi Ken,

What tree is this patch based on? This doesn't apply to either of the IWL trees or the netdev trees.

Sorry, I was in the wrong branch when I generated these patches. Please disregard. I will re-evaluate and resend if necessary.

Quoted 13 lines

The ordering looks correct on the kernel tree with watchdog_task being cancelled before the client_task [1]. However, we do have an extra 'cancel_delayed_work_sync(&adapter->watchdog_task)'. I'll get a patch together to remove the extra one.

Thanks,
Tony

[1] https://elixir.bootlin.com/linux/v5.16-
rc5/source/drivers/net/ethernet/intel/iavf/iavf_main.c#3979

author
#6 lore raw

PATCH 2/2 iavf: Prevent reset from being scheduled while adapter is being removed

In reply to Ken Cox

If a reset gets scheduled while the adapter is being removed it can cause a panic.

The work_struct for the reset_task is contained in the iavf_adapter structure. iavf_remove() eventually frees the iavf_adapter structure so if there is active work scheduled it can cause a panic.

---
 drivers/net/ethernet/intel/iavf/iavf_ethtool.c  |  7 +++++--
 drivers/net/ethernet/intel/iavf/iavf_main.c     | 15 ++++++++++-----
 drivers/net/ethernet/intel/iavf/iavf_virtchnl.c |  4 +++-
 3 files changed, 18 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_ethtool.c +5 -2
index af43fbd8cb75e..3cf1679153604 100644
@@ -519,7 +519,9 @@ static int iavf_set_priv_flags(struct net_device *netdev, u32 flags)
 
 	/* issue a reset to force legacy-rx change to take effect */
 	if (changed_flags & IAVF_FLAG_LEGACY_RX) {
-		if (netif_running(netdev)) {
+
+		if (netif_running(netdev) &&
+		    !test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section)) {
 			adapter->flags |= IAVF_FLAG_RESET_NEEDED;
 			queue_work(iavf_wq, &adapter->reset_task);
 		}
@@ -630,7 +632,8 @@ static int iavf_set_ringparam(struct net_device *netdev,
 	adapter->tx_desc_count = new_tx_count;
 	adapter->rx_desc_count = new_rx_count;
 
-	if (netif_running(netdev)) {
+	if (netif_running(netdev) &&
+	    !test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section)) {
 		adapter->flags |= IAVF_FLAG_RESET_NEEDED;
 		queue_work(iavf_wq, &adapter->reset_task);
 	}
drivers/net/ethernet/intel/iavf/iavf_main.c +10 -5
index 63eec7edbf60a..af2788c997ca2 100644
@@ -164,7 +164,8 @@ static int iavf_lock_timeout(struct iavf_adapter *adapter,
 void iavf_schedule_reset(struct iavf_adapter *adapter)
 {
 	if (!(adapter->flags &
-	      (IAVF_FLAG_RESET_PENDING | IAVF_FLAG_RESET_NEEDED))) {
+	      (IAVF_FLAG_RESET_PENDING | IAVF_FLAG_RESET_NEEDED)) &&
+	    !test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section)) {
 		adapter->flags |= IAVF_FLAG_RESET_NEEDED;
 		queue_work(iavf_wq, &adapter->reset_task);
 	}
@@ -2013,7 +2014,8 @@ static void iavf_watchdog_task(struct work_struct *work)
 		adapter->aq_required = 0;
 		adapter->current_op = VIRTCHNL_OP_UNKNOWN;
 		dev_err(&adapter->pdev->dev, "Hardware reset detected\n");
-		queue_work(iavf_wq, &adapter->reset_task);
+		if (!test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section))
+			queue_work(iavf_wq, &adapter->reset_task);
 		goto watchdog_done;
 	}
 
@@ -3348,8 +3350,10 @@ static int iavf_change_mtu(struct net_device *netdev, int new_mtu)
 		iavf_notify_client_l2_params(&adapter->vsi);
 		adapter->flags |= IAVF_FLAG_SERVICE_CLIENT_REQUESTED;
 	}
-	adapter->flags |= IAVF_FLAG_RESET_NEEDED;
-	queue_work(iavf_wq, &adapter->reset_task);
+	if (!test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section)) {
+		adapter->flags |= IAVF_FLAG_RESET_NEEDED;
+		queue_work(iavf_wq, &adapter->reset_task);
+	}
 
 	return 0;
 }
@@ -3909,7 +3913,8 @@ static int __maybe_unused iavf_resume(struct device *dev_d)
 		return err;
 	}
 
-	queue_work(iavf_wq, &adapter->reset_task);
+	if (!test_bit(__IAVF_IN_REMOVE_TASK, &adapter->crit_section))
+		queue_work(iavf_wq, &adapter->reset_task);
 
 	netif_device_attach(netdev);
 
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +3 -1
index 0eab3c43bdc59..ba973b2ab0547 100644
@@ -1470,7 +1470,9 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
 			break;
 		case VIRTCHNL_EVENT_RESET_IMPENDING:
 			dev_info(&adapter->pdev->dev, "Reset warning received from the PF\n");
-			if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) {
+			if (!(adapter->flags & IAVF_FLAG_RESET_PENDING) &&
+			    !test_bit(__IAVF_IN_REMOVE_TASK,
+				      &adapter->crit_section)) {
 				adapter->flags |= IAVF_FLAG_RESET_PENDING;
 				dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
 				queue_work(iavf_wq, &adapter->reset_task);
Signature · 1 line
2.31.1
#7 lore raw

PATCH 2/2 iavf: Prevent reset from being scheduled while adapter is being removed

drivers/net/ethernet/intel/iavf/iavf_ethtool.c static int iavf_set_priv_flags(struct net_device

Quoted 31 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Ken Cox
Sent: ?roda, 8 grudnia 2021 11:22
To: intel-wired-lan at osuosl.org
Cc: Ken Cox <[email protected]>
Subject: [Intel-wired-lan] [Patch 2/2] iavf: Prevent reset from being scheduled while adapter is being removed

If a reset gets scheduled while the adapter is being removed it can cause a panic.

The work_struct for the reset_task is contained in the iavf_adapter structure. iavf_remove() eventually frees the iavf_adapter structure so if there is active work scheduled it can cause a panic.

---
 drivers/net/ethernet/intel/iavf/iavf_ethtool.c  |  7 +++++--
 drivers/net/ethernet/intel/iavf/iavf_main.c     | 15 ++++++++++-----
 drivers/net/ethernet/intel/iavf/iavf_virtchnl.c |  4 +++-
 3 files changed, 18 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_ethtool.c +0 -0
index af43fbd8cb75e..3cf1679153604 100644
@@ -519,7 +519,9 @@ static int iavf_set_priv_flags(struct net_device
#8 lore raw

PATCH 2/2 iavf: Prevent reset from being scheduled while adapter is being removed

Quoted 34 lines

-----Original Message-----
From: Jankowski, Konrad0
Sent: sobota, 11 grudnia 2021 12:26
To: Ken Cox <[email protected]>; intel-wired-lan at osuosl.org
Subject: RE: [Intel-wired-lan] [Patch 2/2] iavf: Prevent reset from being scheduled while adapter is being removed

Quoted 23 lines

-----Original Message-----
From: Intel-wired-lan <[email protected]> On Behalf Of Ken Cox
Sent: ?roda, 8 grudnia 2021 11:22
To: intel-wired-lan at osuosl.org
Cc: Ken Cox <[email protected]>
Subject: [Intel-wired-lan] [Patch 2/2] iavf: Prevent reset from being scheduled while adapter is being removed

If a reset gets scheduled while the adapter is being removed it can cause a panic.

The work_struct for the reset_task is contained in the iavf_adapter structure. iavf_remove() eventually frees the iavf_adapter structure so if there is active work scheduled it can cause a panic.

---
 drivers/net/ethernet/intel/iavf/iavf_ethtool.c  |  7 +++++--
 drivers/net/ethernet/intel/iavf/iavf_main.c     | 15 ++++++++++-----
 drivers/net/ethernet/intel/iavf/iavf_virtchnl.c |  4 +++-
 3 files changed, 18 insertions(+), 8 deletions(-)
Quoted 7 lines

drivers/net/ethernet/intel/iavf/iavf_ethtool.c static int iavf_set_priv_flags(struct net_device

Quoted 6 lines
drivers/net/ethernet/intel/iavf/iavf_ethtool.c +0 -0
index af43fbd8cb75e..3cf1679153604 100644
@@ -519,7 +519,9 @@ static int iavf_set_priv_flags(struct net_device

I'm sorry, this was not sent to me, it is still untested

#9 lore raw

PATCH 2/2 iavf: Prevent reset from being scheduled while adapter is being removed

In reply to Ken Cox
Quoted 8 lines · Ken Cox

If a reset gets scheduled while the adapter is being removed it can cause a panic.

The work_struct for the reset_task is contained in the iavf_adapter structure.? iavf_remove() eventually frees the iavf_adapter structure so if there is active work scheduled it can cause a panic.

Like the other patch, this one isn't applying.

Thanks,
Tony

author
#10 lore raw

PATCH 2/2 iavf: Prevent reset from being scheduled while adapter is being removed

Quoted 8 lines · Anthony L
Quoted 7 lines · Ken Cox

If a reset gets scheduled while the adapter is being removed it can cause a panic.

The work_struct for the reset_task is contained in the iavf_adapter structure.? iavf_remove() eventually frees the iavf_adapter structure so if there is active work scheduled it can cause a panic.

Quoted 7 lines
Quoted 1 line

Like the other patch, this one isn't applying.

Thanks,
Tony

Sorry, I was in the wrong branch when I generated these patches. Please disregard. I will re-evaluate and resend if necessary.

author
#11 lore raw

cover iavf: Fix panics due to active work queues being freed in iavf_remove()

In reply to Ken Cox
Quoted 11 lines · Ken Cox

This series fixes panics that occur after iavf_remove() is called.

The panics occur because the iavf_adapter structure is freed at the end
of iavf_remove(), but it is possible that new work has been scheduled using
the work_struct's contained within the iavf_adapter structure. If this occurs, the system will panic when it later tries to process the work queue.

Ken Cox (2):
iavf: Fix panic in iavf_remove
iavf: Prevent reset from being scheduled while adapter is being
removed

Quoted 5 lines
  drivers/net/ethernet/intel/iavf/iavf_ethtool.c  |  7 +++++--
  drivers/net/ethernet/intel/iavf/iavf_main.c     | 17 +++++++++++------
  drivers/net/ethernet/intel/iavf/iavf_virtchnl.c |  4 +++-
  3 files changed, 19 insertions(+), 9 deletions(-)

NAK for this series.

These patches were generated off of the wrong branch. I will re-evaluate and re-submit if necessary.