igb/ixgbe: Fix ordering of SR-IOV teardown
Subsystems (3)
v2 cover igb/ixgbe: Fix ordering of SR-IOV teardown
v2:
- Rebase to DaveM's net tree, context-only change
- Add Mitch's Acks
There's no functional change from v1, so the choice of v1 or v2 is just a matter of which maintainer wants to take these.
Original description:
When running a Windows 2012 R2 guest with a pair of VFs assigned through vfio-pci, we run into a problem trying to hot-unplug those VFs after the PF has unregistered the netdev. This is a common scenario if the PF is unbound from the driver while VFs are active. In the case of igb, the resulting guest behavior differs slightly between the Microsoft provided and Intel add-on guest drivers. With the Microsoft driver, the guest seems to stumble through ejecting both VFs, but takes longer than normal to do so. With the Intel drivers, only one VF is unplugged, but Device Manager still shows it as present. The second VF is non-functional but also still shown in Device Manager. At this point, the guest is in such a state that it will not cleanly shutdown. With ixgbe VFs, both the Microsoft and Intel drivers take on this latter behavior.
For both, I've found that disabling SR-IOV before unregistering the PF netdev device allows the hot-unplug to proceed without interruption or further ill behavior in the guest. This is true regardless of which driver is used. I don't fully understand what dependency is broken by unregistering the netdev prior to disabling SR-IOV, but I also don't see the benefit in delaying SR-IOV teardown in this call path. It could potentially be moved even earlier, but I'll let those more familiar with the hardware and code make that determination. In any case, the VM behavior is substantially improved by this slight re-ordering.
I don't have an i40e for testing, but it already appears to disable SR-IOV much earlier in the unbind path, so I wouldn't expect to find similar issues. Thanks,
Alex
---
Alex Williamson (2):
igb: Teardown SR-IOV before unregister_netdev()
ixgbe: Teardown SR-IOV before unregister_netdev()
drivers/net/ethernet/intel/igb/igb_main.c | 8 ++++---- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-)
PATCH v2 1/2 igb: Teardown SR-IOV before unregister_netdev()
When the .remove() callback for a PF is called, SR-IOV support for the device is disabled, which requires unbinding and removing the VFs. The VFs may be in-use either by the host kernel or userspace, such as assigned to a VM through vfio-pci. In this latter case, the VFs may be removed either by shutting down the VM or hot-unplugging the devices from the VM. Unfortunately in the case of a Windows 2012 R2 guest, hot-unplug is broken due to the ordering of the PF driver teardown. Disabling SR-IOV prior to unregister_netdev() avoids this issue.
--- drivers/net/ethernet/intel/igb/igb_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/intel/igb/igb_main.c +4 -4
@@ -2805,14 +2805,14 @@ static void igb_remove(struct pci_dev *pdev)*/ igb_release_hw_control (adapter); -unregister_netdev (netdev); - -igb_clear_interrupt_scheme (adapter); -#ifdef CONFIG_PCI_IOV igb_disable_sriov (pdev);#endif +unregister_netdev (netdev); + +igb_clear_interrupt_scheme (adapter); +pci_iounmap (pdev, hw->hw_addr);if (hw->flash_address)iounmap (hw->flash_address);
RE: [Intel-wired-lan] [PATCH v2 1/2] igb: Teardown SR-IOV before unregister_netdev()
Quoted 19 lines
From: Intel-wired-lan [mailto:intel-wired-lan-bounces at lists.osuosl.org] On Behalf Of Alex Williamson
Sent: Wednesday, July 29, 2015 1:38 PM
To: intel-wired-lan at lists.osuosl.org; davem at davemloft.net; Kirsher, Jeffrey T
Cc: netdev at vger.kernel.org; linux-kernel at vger.kernel.org
Subject: [Intel-wired-lan] [PATCH v2 1/2] igb: Teardown SR-IOV beforeunregister_netdev()When the .remove() callback for a PF is called, SR-IOV support for the device is disabled, which requires unbinding and removing the VFs. The VFs may be in-use either by the host kernel or userspace, such as assigned to a VM through vfio-pci. In this latter case, the VFs may be removed either by shutting down the VM or hot-unplugging the devices from the VM. Unfortunately in the case of a Windows 2012 R2 guest, hot-unplug is broken due to the ordering of the PF driver teardown. Disabling SR-IOV prior to
unregister_netdev()avoids this issue.
Quoted 5 lines
Signed-off-by Alex Williamson <[email protected]>Acked-by Mitch Williams <[email protected]>--- drivers/net/ethernet/intel/igb/igb_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
PATCH v2 2/2 ixgbe: Teardown SR-IOV before unregister_netdev()
In reply to Alex WilliamsonWhen the .remove() callback for a PF is called, SR-IOV support for the device is disabled, which requires unbinding and removing the VFs. The VFs may be in-use either by the host kernel or userspace, such as assigned to a VM through vfio-pci. In this latter case, the VFs may be removed either by shutting down the VM or hot-unplugging the devices from the VM. Unfortunately in the case of a Windows 2012 R2 guest, hot-unplug is broken due to the ordering of the PF driver teardown. Disabling SR-IOV prior to unregister_netdev() avoids this issue.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +3 -3
@@ -8855,9 +8855,6 @@ static void ixgbe_remove(struct pci_dev *pdev)/* remove the added san mac */ ixgbe_del_sanmac_netdev (netdev); -if (netdev->reg_state ==NETREG_REGISTERED ) -unregister_netdev (netdev); -#ifdef CONFIG_PCI_IOV /* * Only disable SR-IOV on unload if the user specified the now
@@ -8866,6 +8863,9 @@ static void ixgbe_remove(struct pci_dev *pdev)if (max_vfs)ixgbe_disable_sriov (adapter);#endif +if (netdev->reg_state ==NETREG_REGISTERED ) +unregister_netdev (netdev); +ixgbe_clear_interrupt_scheme (adapter);ixgbe_release_hw_control (adapter);