iavf: Fix panics due to active work queues being freed in iavf_remove()
Subsystems (2)
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
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
@@ -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
Jankowski
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 iniavf_removeIt's possible for the
client_taskto get scheduled by the watchdog aftercancel_delayed_work_sync(&adapter->client_task); This can cause a panic becausefree_netdev()is called with theclient_taskstill 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/0x40Signed-off-by Ken Cox <[email protected]>--- 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@@ -3940,7 +3940,6 @@ static void iavf_remove(struct pci_dev *pdev)
Jankowski
PATCH 1/2 iavf: Fix panic in iavf_remove
I'm sorry, this was not sent to me, it is still untested
Nguyen
PATCH 1/2 iavf: Fix panic in iavf_remove
In reply to Ken CoxQuoted 42 lines · Ken Cox
It's possible for the
client_taskto get scheduled by the watchdog aftercancel_delayed_work_sync(&adapter->client_task);? This can cause
a panic becausefree_netdev()is called with theclient_taskstill 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/0x40Signed-off-by Ken Cox <[email protected]>---
?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@@ -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
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_taskto get scheduled by the watchdog aftercancel_delayed_work_sync(&adapter->client_task);? This can cause
a panic becausefree_netdev()is called with theclient_taskstill 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/0x40Signed-off-by Ken Cox <[email protected]>--- ?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@@ -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_taskbeing cancelled before theclient_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
PATCH 2/2 iavf: Prevent reset from being scheduled while adapter is being removed
In reply to Ken CoxIf 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
@@ -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
@@ -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
@@ -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
Jankowski
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 removedIf a reset gets scheduled while the adapter is being removed it can cause a panic.
The
work_structfor thereset_taskis contained in theiavf_adapterstructure.iavf_remove()eventually frees theiavf_adapterstructure so if there is active work scheduled it can cause a panic.Signed-off-by Ken Cox <[email protected]>--- 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@@ -519,7 +519,9 @@ static int iavf_set_priv_flags(struct net_device
Jankowski
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 removedQuoted 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 removedIf a reset gets scheduled while the adapter is being removed it can cause a panic.
The
work_structfor thereset_taskis contained in theiavf_adapterstructure.iavf_remove()eventually frees theiavf_adapterstructure so if there is active work scheduled it can cause a panic.Signed-off-by Ken Cox <[email protected]>--- 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@@ -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
Nguyen
PATCH 2/2 iavf: Prevent reset from being scheduled while adapter is being removed
In reply to Ken CoxQuoted 8 lines · Ken Cox
If a reset gets scheduled while the adapter is being removed it can cause a panic.
The
work_structfor thereset_taskis contained in theiavf_adapterstructure.?iavf_remove()eventually frees theiavf_adapterstructure so if there is active work scheduled it can cause a panic.Signed-off-by Ken Cox <[email protected]>
Like the other patch, this one isn't applying.
Thanks,
Tony
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_structfor thereset_taskis contained in theiavf_adapterstructure.?iavf_remove()eventually frees theiavf_adapterstructure so if there is active work scheduled it can cause a panic.
Quoted 7 lines
Quoted 1 line
Signed-off-by Ken Cox <[email protected]>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.
cover iavf: Fix panics due to active work queues being freed in iavf_remove()
In reply to Ken CoxQuoted 11 lines · Ken Cox
This series fixes panics that occur after
iavf_remove()is called.The panics occur because the
iavf_adapterstructure is freed at the end
ofiavf_remove(), but it is possible that new work has been scheduled using
the work_struct's contained within theiavf_adapterstructure. If this occurs, the system will panic when it later tries to process the work queue.Ken Cox (2):
iavf: Fix panic iniavf_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.