Intel Wired LAN Driver Updates 2022-02-25
Subsystems (3)
Tony Nguyen
maintainerThis series contains updates to iavf driver only.
Slawomir fixes stability issues that can be seen when stressing the driver using a large number of VFs with a multitude of operations. Among the fixes are reworking mutexes to provide more effective locking, ensuring initialization is complete before teardown, preventing operations which could race while removing the driver, stopping certain tasks from being queued when the device is down, and adding a missing mutex unlock.
The following are changes since commit e01b042e580f1fbf4fd8da467442451da00c7a90:
net: stmmac: fix return value of __setup handler
and are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue 40GbE
Slawomir Laba (8):
iavf: Rework mutexes for better synchronisation
iavf: Add waiting so the port is initialized in remove
iavf: Fix init state closure on remove
iavf: Fix locking for VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
iavf: Fix race in init state
iavf: Fix deadlock in iavf_reset_task
iavf: Fix missing check for running netdev
iavf: Fix __IAVF_RESETTING state usage
drivers/net/ethernet/intel/iavf/iavf.h | 6 +- drivers/net/ethernet/intel/iavf/iavf_main.c | 159 ++++++++++++------ .../net/ethernet/intel/iavf/iavf_virtchnl.c | 24 +-- 3 files changed, 114 insertions(+), 75 deletions(-)
Signature · 1 line
2.31.1
Tony Nguyen
maintainerPATCH 1/8 iavf: Rework mutexes for better synchronisation
From: Slawomir Laba <[email protected]>
The driver used to crash in multiple spots when put to stress testing of the init, reset and remove paths.
The user would experience call traces or hangs when creating, resetting, removing VFs. Depending on the machines, the call traces are happening in random spots, like reset restoring resources racing with driver remove.
Make adapter->crit_lock mutex a mandatory lock for guarding the operations performed on all workqueues and functions dealing with resource allocation and disposal.
Make __IAVF_REMOVE a final state of the driver respected by workqueues that shall not requeue, when they fail to obtain the crit_lock.
Make the IRQ handler not to queue the new work for adminq_task when the __IAVF_REMOVE state is set.
--- drivers/net/ethernet/intel/iavf/iavf.h | 1 - drivers/net/ethernet/intel/iavf/iavf_main.c | 66 +++++++++++---------- 2 files changed, 36 insertions(+), 31 deletions(-)
drivers/net/ethernet/intel/iavf/iavf.h +0 -1
@@ -246,7 +246,6 @@ struct iavf_adapter {struct list_head mac_filter_list;struct mutex crit_lock;struct mutex client_lock; -struct mutex remove_lock;/* Lock to protect accesses to MAC and VLAN lists */ spinlock_t mac_vlan_list_lock;char misc_vector_name[IFNAMSIZ +9 ];
drivers/net/ethernet/intel/iavf/iavf_main.c +36 -30
149 lines not on this page · raw message
Signature · 1 line
2.31.1
Tony Nguyen
maintainerPATCH 2/8 iavf: Add waiting so the port is initialized in remove
In reply to Tony NguyenFrom: Slawomir Laba <[email protected]>
There exist races when port is being configured and remove is triggered.
unregister_netdev is not and can't be called under crit_lock mutex since it is calling ndo_stop -> iavf_close which requires this lock. Depending on init state the netdev could be still unregistered so unregister_netdev never cleans up, when shortly after that the device could become registered.
Make iavf_remove wait until port finishes initialization. All critical state changes are atomic (under crit_lock). Crashes that come from iavf_reset_interrupt_capability and iavf_free_traffic_irqs should now be solved in a graceful manner.
--- drivers/net/ethernet/intel/iavf/iavf_main.c | 27 ++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +16 -11
@@ -4558,7 +4558,6 @@ static int __maybe_unused iavf_resume(struct device *dev_d)static void iavf_remove (struct pci_dev *pdev) {struct iavf_adapter *adapter =iavf_pdev_to_adapter (pdev); -enum iavf_state_t prev_state = adapter->last_state;struct net_device *netdev = adapter->netdev;struct iavf_fdir_fltr *fdir, *fdirtmp;struct iavf_vlan_filter *vlf, *vlftmp;
@@ -4568,6 +4567,22 @@ static void iavf_remove(struct pci_dev *pdev)struct iavf_hw *hw = &adapter->hw;int err; +/* Wait until port initialization is complete. +* There are flows where register/unregister netdev may race. +*/ +while (1 ) { +mutex_lock (&adapter->crit_lock); +if (adapter->state == __IAVF_RUNNING || + adapter->state == __IAVF_DOWN) { +mutex_unlock (&adapter->crit_lock); +break ; + } + +mutex_unlock (&adapter->crit_lock); +usleep_range (500 ,1000 ); + } +cancel_delayed_work_sync (&adapter->watchdog_task); +if (adapter->netdev_registered) {unregister_netdev (netdev); adapter->netdev_registered = false;
@@ -4605,16 +4620,6 @@ static void iavf_remove(struct pci_dev *pdev)iavf_free_all_rx_resources (adapter);iavf_free_misc_irq (adapter); -/* In case we enter iavf_remove from erroneous state, free traffic irqs -* here, so as to not cause a kernel crash, when calling -* iavf_reset_interrupt_capability. -*/ -if ((adapter->last_state == __IAVF_RESETTING && - prev_state != __IAVF_DOWN) || - (adapter->last_state == __IAVF_RUNNING && - !(netdev->flags &IFF_UP ))) -iavf_free_traffic_irqs (adapter); -iavf_reset_interrupt_capability (adapter);iavf_free_q_vectors (adapter);
Signature · 1 line
2.31.1
Tony Nguyen
maintainerPATCH 3/8 iavf: Fix init state closure on remove
In reply to Tony NguyenFrom: Slawomir Laba <[email protected]>
When init states of the adapter work, the errors like lack of communication with the PF might hop in. If such events occur the driver restores previous states in order to retry initialization in a proper way. When remove task kicks in, this situation could lead to races with unregistering the netdevice as well as resources cleanup. With the commit introducing the waiting in remove for init to complete, this problem turns into an endless waiting if init never recovers from errors.
Introduce __IAVF_IN_REMOVE_TASK bit to indicate that the remove thread has started.
Make __IAVF_COMM_FAILED adapter state respect the __IAVF_IN_REMOVE_TASK bit and set the __IAVF_INIT_FAILED state and return without any action instead of trying to recover.
Make __IAVF_INIT_FAILED adapter state respect the __IAVF_IN_REMOVE_TASK bit and return without any further actions.
Make the loop in the remove handler break when adapter has __IAVF_INIT_FAILED state set.
--- drivers/net/ethernet/intel/iavf/iavf.h | 4 ++++ drivers/net/ethernet/intel/iavf/iavf_main.c | 24 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/iavf/iavf.h +4 -0
@@ -201,6 +201,10 @@ enum iavf_state_t { __IAVF_RUNNING, /* opened, working */ }; +enum iavf_critical_section_t { + __IAVF_IN_REMOVE_TASK,/* device being removed */ +}; +#define IAVF_CLOUD_FIELD_OMAC 0x01#define IAVF_CLOUD_FIELD_IMAC 0x02#define IAVF_CLOUD_FIELD_IVLAN 0x04
drivers/net/ethernet/intel/iavf/iavf_main.c +23 -1
@@ -2424,6 +2424,15 @@ static void iavf_watchdog_task(struct work_struct *work) msecs_to_jiffies(1));return ;case __IAVF_INIT_FAILED: +if (test_bit (__IAVF_IN_REMOVE_TASK, + &adapter->crit_section)) { +/* Do not update the state and do not reschedule +* watchdog task, iavf_remove should handle this state +* as it can loop forever +*/ +mutex_unlock (&adapter->crit_lock); +return ; + }if (++adapter->aq_wait_count >IAVF_AQ_MAX_ERR ) {dev_err (&adapter->pdev->dev,"Failed to communicate with PF; waiting before retry\n" );
@@ -2440,6 +2449,17 @@ static void iavf_watchdog_task(struct work_struct *work)queue_delayed_work (iavf_wq, &adapter->watchdog_task,HZ );return ;case __IAVF_COMM_FAILED: +if (test_bit (__IAVF_IN_REMOVE_TASK, + &adapter->crit_section)) { +/* Set state to __IAVF_INIT_FAILED and perform remove +* steps. Remove IAVF_FLAG_PF_COMMS_FAILED so the task +* doesn't bring the state back to __IAVF_COMM_FAILED. +*/ +iavf_change_state (adapter, __IAVF_INIT_FAILED); + adapter->flags &= ~IAVF_FLAG_PF_COMMS_FAILED ; +mutex_unlock (&adapter->crit_lock); +return ; + } reg_val =rd32 (hw,IAVF_VFGEN_RSTAT ) &IAVF_VFGEN_RSTAT_VFR_STATE_MASK ; if (reg_val == VIRTCHNL_VFR_VFACTIVE ||
@@ -4567,13 +4587,15 @@ static void iavf_remove(struct pci_dev *pdev)struct iavf_hw *hw = &adapter->hw;int err; +set_bit (__IAVF_IN_REMOVE_TASK, &adapter->crit_section);/* Wait until port initialization is complete. * There are flows where register/unregister netdev may race. */ while (1 ) {mutex_lock (&adapter->crit_lock);if (adapter->state == __IAVF_RUNNING || - adapter->state == __IAVF_DOWN) { + adapter->state == __IAVF_DOWN || + adapter->state == __IAVF_INIT_FAILED) {mutex_unlock (&adapter->crit_lock);break ; }
Signature · 1 line
2.31.1
Tony Nguyen
maintainerPATCH 4/8 iavf: Fix locking for VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS
In reply to Tony NguyenFrom: Slawomir Laba <[email protected]>
iavf_virtchnl_completion is called under crit_lock but when the code for VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS is called, this lock is released in order to obtain rtnl_lock to avoid ABBA deadlock with unregister_netdev.
Along with the new way iavf_remove behaves, there exist many risks related to the lock release and attmepts to regrab it. The driver faces crashes related to races between unregister_netdev and netdev_update_features. Yet another risk is that the driver could already obtain the crit_lock in order to destroy it and iavf_virtchnl_completion could crash or block forever.
Make iavf_virtchnl_completion never relock crit_lock in it's call paths.
Extract rtnl_lock locking logic to the driver for unregister_netdev in order to set the netdev_registered flag inside the lock.
Introduce a new flag that will inform adminq_task to perform the code from VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS right after it finishes processing messages. Guard this code with remove flags so it's never called when the driver is in remove state.
--- drivers/net/ethernet/intel/iavf/iavf.h | 1 + drivers/net/ethernet/intel/iavf/iavf_main.c | 22 ++++++++++++++++- .../net/ethernet/intel/iavf/iavf_virtchnl.c | 24 +------------------ 3 files changed, 23 insertions(+), 24 deletions(-)
drivers/net/ethernet/intel/iavf/iavf.h +1 -0
@@ -287,6 +287,7 @@ struct iavf_adapter {#define IAVF_FLAG_LEGACY_RX BIT(15)#define IAVF_FLAG_REINIT_ITR_NEEDED BIT(16)#define IAVF_FLAG_QUEUES_DISABLED BIT(17) +#define IAVF_FLAG_SETUP_NETDEV_FEATURES BIT(18)/* duplicates for common code */ #define IAVF_FLAG_DCB_ENABLED 0/* flags for admin queue service task */
drivers/net/ethernet/intel/iavf/iavf_main.c +21 -1
@@ -2879,6 +2879,24 @@ static void iavf_adminq_task(struct work_struct *work) }while (pending);mutex_unlock (&adapter->crit_lock); +if ((adapter->flags &IAVF_FLAG_SETUP_NETDEV_FEATURES )) { +if (adapter->netdev_registered || + !test_bit (__IAVF_IN_REMOVE_TASK, &adapter->crit_section)) { +struct net_device *netdev = adapter->netdev; + +rtnl_lock (); +netdev_update_features (netdev); +rtnl_unlock (); +/* Request VLAN offload settings */ +if (VLAN_V2_ALLOWED (adapter)) +iavf_set_vlan_offload_features + (adapter,0 , netdev->features); + +iavf_set_queue_vlan_tag_loc (adapter); + } + + adapter->flags &= ~IAVF_FLAG_SETUP_NETDEV_FEATURES ; + }if ((adapter->flags & (IAVF_FLAG_RESET_PENDING |IAVF_FLAG_RESET_NEEDED )) || adapter->state == __IAVF_RESETTING)
@@ -4606,8 +4624,10 @@ static void iavf_remove(struct pci_dev *pdev)cancel_delayed_work_sync (&adapter->watchdog_task);if (adapter->netdev_registered) { -unregister_netdev (netdev); +rtnl_lock (); +unregister_netdevice (netdev); adapter->netdev_registered = false; +rtnl_unlock (); }if (CLIENT_ALLOWED (adapter)) { err =iavf_lan_del_device (adapter);
drivers/net/ethernet/intel/iavf/iavf_virtchnl.c +1 -23
@@ -2146,29 +2146,7 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter, sizeof(adapter->vlan_v2_caps)));iavf_process_config (adapter); - -/* unlock crit_lock before acquiring rtnl_lock as other -* processes holding rtnl_lock could be waiting for the same -* crit_lock -*/ -mutex_unlock (&adapter->crit_lock); -/* VLAN capabilities can change during VFR, so make sure to -* update the netdev features with the new capabilities -*/ -rtnl_lock (); -netdev_update_features (netdev); -rtnl_unlock (); -if (iavf_lock_timeout (&adapter->crit_lock,10000 )) -dev_warn (&adapter->pdev->dev,"failed to acquire crit_lock in %s\n" , - __FUNCTION__); - -/* Request VLAN offload settings */ -if (VLAN_V2_ALLOWED (adapter)) -iavf_set_vlan_offload_features (adapter,0 , - netdev->features); - -iavf_set_queue_vlan_tag_loc (adapter); - + adapter->flags |=IAVF_FLAG_SETUP_NETDEV_FEATURES ; }break ;case VIRTCHNL_OP_ENABLE_QUEUES :
Signature · 1 line
2.31.1
Tony Nguyen
maintainerPATCH 5/8 iavf: Fix race in init state
In reply to Tony NguyenFrom: Slawomir Laba <[email protected]>
When iavf_init_version_check sends VIRTCHNL_OP_GET_VF_RESOURCES message, the driver will wait for the response after requeueing the watchdog task in iavf_init_get_resources call stack. The logic is implemented this way that iavf_init_get_resources has to be called in order to allocate adapter->vf_res. It is polling for the AQ response in iavf_get_vf_config function. Expect a call trace from kernel when adminq_task worker handles this message first. adapter->vf_res will be NULL in iavf_virtchnl_completion.
Make the watchdog task not queue the adminq_task if the init process is not finished yet.
--- drivers/net/ethernet/intel/iavf/iavf_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +2 -1
@@ -2532,7 +2532,8 @@ static void iavf_watchdog_task(struct work_struct *work)schedule_delayed_work (&adapter->client_task,msecs_to_jiffies (5 ));mutex_unlock (&adapter->crit_lock); restart_watchdog: -queue_work (iavf_wq, &adapter->adminq_task); +if (adapter->state >= __IAVF_DOWN) +queue_work (iavf_wq, &adapter->adminq_task);if (adapter->aq_required)queue_delayed_work (iavf_wq, &adapter->watchdog_task,msecs_to_jiffies (20 ));
Signature · 1 line
2.31.1
Tony Nguyen
maintainerPATCH 6/8 iavf: Fix deadlock in iavf_reset_task
In reply to Tony NguyenFrom: Slawomir Laba <[email protected]>
There exists a missing mutex_unlock call on crit_lock in iavf_reset_task call path.
Unlock the crit_lock before returning from reset task.
--- drivers/net/ethernet/intel/iavf/iavf_main.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/intel/iavf/iavf_main.c +1 -0
@@ -2688,6 +2688,7 @@ static void iavf_reset_task(struct work_struct *work) reg_val);iavf_disable_vf (adapter);mutex_unlock (&adapter->client_lock); +mutex_unlock (&adapter->crit_lock);return ;/* Do not attempt to reinit. It's dead, Jim. */ }
Signature · 1 line
2.31.1
Tony Nguyen
maintainerPATCH 7/8 iavf: Fix missing check for running netdev
In reply to Tony NguyenFrom: Slawomir Laba <[email protected]>
The driver was queueing reset_task regardless of the netdev state.
Do not queue the reset task in iavf_change_mtu if netdev is not running.
--- drivers/net/ethernet/intel/iavf/iavf_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +5 -2
@@ -3905,8 +3905,11 @@ 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 (netif_running (netdev)) { + adapter->flags |=IAVF_FLAG_RESET_NEEDED ; +queue_work (iavf_wq, &adapter->reset_task); + }return 0 ; }
Signature · 1 line
2.31.1
Tony Nguyen
maintainerPATCH 8/8 iavf: Fix __IAVF_RESETTING state usage
In reply to Tony NguyenFrom: Slawomir Laba <[email protected]>
The setup of __IAVF_RESETTING state in watchdog task had no effect and could lead to slow resets in the driver as the task for __IAVF_RESETTING state only requeues watchdog. Till now the __IAVF_RESETTING was interpreted by reset task as running state which could lead to errors with allocating and resources disposal.
Make watchdog_task queue the reset task when it's necessary. Do not update the state to __IAVF_RESETTING so the reset task knows exactly what is the current state of the adapter.
--- drivers/net/ethernet/intel/iavf/iavf_main.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/net/ethernet/intel/iavf/iavf_main.c +6 -7
@@ -1137,8 +1137,7 @@ void iavf_down(struct iavf_adapter *adapter) rss->state =IAVF_ADV_RSS_DEL_REQUEST ;spin_unlock_bh (&adapter->adv_rss_lock); -if (!(adapter->flags &IAVF_FLAG_PF_COMMS_FAILED ) && - adapter->state != __IAVF_RESETTING) { +if (!(adapter->flags &IAVF_FLAG_PF_COMMS_FAILED )) {/* cancel any current operation */ adapter->current_op =VIRTCHNL_OP_UNKNOWN ;/* Schedule operations to close down the HW. Don't wait
@@ -2385,11 +2384,12 @@ static void iavf_watchdog_task(struct work_struct *work)if (adapter->flags &IAVF_FLAG_PF_COMMS_FAILED )iavf_change_state (adapter, __IAVF_COMM_FAILED); -if (adapter->flags &IAVF_FLAG_RESET_NEEDED && - adapter->state != __IAVF_RESETTING) { -iavf_change_state (adapter, __IAVF_RESETTING); +if (adapter->flags &IAVF_FLAG_RESET_NEEDED ) { adapter->aq_required =0 ; adapter->current_op =VIRTCHNL_OP_UNKNOWN ; +mutex_unlock (&adapter->crit_lock); +queue_work (iavf_wq, &adapter->reset_task); +return ; }switch (adapter->state) {
@@ -2697,8 +2697,7 @@ static void iavf_reset_task(struct work_struct *work)* ndo_open() returning, so we can't assume it means all our open * tasks have finished, since we're not holding the rtnl_lock here. */ - running = ((adapter->state == __IAVF_RUNNING) || - (adapter->state == __IAVF_RESETTING)); + running = adapter->state == __IAVF_RUNNING;if (running) { netdev->flags &= ~IFF_UP ;
Signature · 1 line
2.31.1
This series was applied to netdev/net.git (master) by Tony Nguyen <[email protected]>:
Hello:
This series was applied to netdev/net.git (master) by Tony Nguyen <[email protected]>:
Quoted 11 lines · On Fri, 25 Feb 2022 11:46:06 -0800 you wrote:
This series contains updates to iavf driver only.
Slawomir fixes stability issues that can be seen when stressing the driver using a large number of VFs with a multitude of operations. Among the fixes are reworking mutexes to provide more effective locking, ensuring initialization is complete before teardown, preventing operations which could race while removing the driver, stopping certain tasks from being queued when the device is down, and adding a missing mutex unlock.
[...]
Here is the summary with links:
- [net,1/8] iavf: Rework mutexes for better synchronisation
https://git.kernel.org/netdev/net/c/fc2e6b3b132a - [net,2/8] iavf: Add waiting so the port is initialized in remove https://git.kernel.org/netdev/net/c/974578017fc1 - [net,3/8] iavf: Fix init state closure on remove https://git.kernel.org/netdev/net/c/3ccd54ef44eb - [net,4/8] iavf: Fix locking for VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS https://git.kernel.org/netdev/net/c/0579fafd37fb - [net,5/8] iavf: Fix race in init state https://git.kernel.org/netdev/net/c/a472eb5cbaeb - [net,6/8] iavf: Fix deadlock in iavf_reset_task https://git.kernel.org/netdev/net/c/e85ff9c631e1 - [net,7/8] iavf: Fix missing check for running netdev https://git.kernel.org/netdev/net/c/d2c0f45fcceb - [net,8/8] iavf: Fix __IAVF_RESETTING state usage https://git.kernel.org/netdev/net/c/14756b2ae265
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html