1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/drivers/net/ethernet/intel/igb
Lin Ma 6faee3d4ee igb: Add lock to avoid data race
The commit c23d92b80e ("igb: Teardown SR-IOV before
unregister_netdev()") places the unregister_netdev() call after the
igb_disable_sriov() call to avoid functionality issue.

However, it introduces several race conditions when detaching a device.
For example, when .remove() is called, the below interleaving leads to
use-after-free.

 (FREE from device detaching)      |   (USE from netdev core)
igb_remove                         |  igb_ndo_get_vf_config
 igb_disable_sriov                 |  vf >= adapter->vfs_allocated_count?
  kfree(adapter->vf_data)          |
  adapter->vfs_allocated_count = 0 |
                                   |    memcpy(... adapter->vf_data[vf]

Moreover, the igb_disable_sriov() also suffers from data race with the
requests from VF driver.

 (FREE from device detaching)      |   (USE from requests)
igb_remove                         |  igb_msix_other
 igb_disable_sriov                 |   igb_msg_task
  kfree(adapter->vf_data)          |    vf < adapter->vfs_allocated_count
  adapter->vfs_allocated_count = 0 |

To this end, this commit first eliminates the data races from netdev
core by using rtnl_lock (similar to commit 7194792308 ("dpaa2-eth: add
MAC/PHY support through phylink")). And then adds a spinlock to
eliminate races from driver requests. (similar to commit 1e53834ce5
("ixgbe: Add locking to prevent panic when setting sriov_numvfs to zero")

Fixes: c23d92b80e ("igb: Teardown SR-IOV before unregister_netdev()")
Signed-off-by: Lin Ma <linma@zju.edu.cn>
Tested-by: Konrad Jankowski <konrad0.jankowski@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
Link: https://lore.kernel.org/r/20220817184921.735244-1-anthony.l.nguyen@intel.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2022-08-18 11:03:26 -07:00
..
e1000_82575.c igb: remove unexpected word "the" 2022-06-30 10:43:18 -07:00
e1000_82575.h igb: Add UDP segmentation offload support 2019-10-29 21:05:33 -07:00
e1000_defines.h igb: Remove duplicate defines 2022-06-09 10:05:31 -07:00
e1000_hw.h igb: Fix duplicate include guard 2021-03-19 08:47:46 -07:00
e1000_i210.c igb: remove never changed variable `ret_val' 2021-12-21 09:17:47 -08:00
e1000_i210.h net: intel: Cleanup the copyright/license headers 2018-04-27 14:00:04 -04:00
e1000_mac.c intel/igb:fix repeated words in comments 2022-06-30 11:02:36 -07:00
e1000_mac.h net: intel: Cleanup the copyright/license headers 2018-04-27 14:00:04 -04:00
e1000_mbx.c intel: clean up mismatched header comments 2021-03-23 11:34:02 -07:00
e1000_mbx.h net: intel: Cleanup the copyright/license headers 2018-04-27 14:00:04 -04:00
e1000_nvm.c ethernet/intel: Convert fallthrough code comments 2020-07-01 13:47:43 -07:00
e1000_nvm.h net: intel: Cleanup the copyright/license headers 2018-04-27 14:00:04 -04:00
e1000_phy.c igb: Fix fall-through warnings for Clang 2021-03-23 11:34:02 -07:00
e1000_phy.h net: intel: Cleanup the copyright/license headers 2018-04-27 14:00:04 -04:00
e1000_regs.h igb: Remove duplicate defines 2022-06-09 10:05:31 -07:00
igb.h igb: Add lock to avoid data race 2022-08-18 11:03:26 -07:00
igb_ethtool.c igb: Convert kmap() to kmap_local_page() 2022-05-05 08:37:14 -07:00
igb_hwmon.c igb: convert to use i2c_new_client_device() 2020-03-26 19:31:21 -07:00
igb_main.c igb: Add lock to avoid data race 2022-08-18 11:03:26 -07:00
igb_ptp.c igb: convert .adjfreq to .adjfine 2022-07-28 11:03:01 -07:00
Makefile net: intel: Cleanup the copyright/license headers 2018-04-27 14:00:04 -04:00