ice: protect VF lifetime during LLDP configuration
Subsystems (3)
PATCH 1/1 ice: protect VF lifetime during LLDP configuration
ice_free_vfs() can free a VF or its VSI while ice_cfg_sw_rx_lldp() is configuring LLDP. Taking table_lock here would reverse the lock order because ethtool already holds RTNL and ice_free_vfs() takes RTNL under table_lock.
Look up each VF by ID to hold a reference. Hold the VF's cfg_lock while configuring its VSI to prevent ice_free_vfs() from releasing the VSI during configuration.
---
Found with a static analysis tool we are developing.
Compile-tested only, with x86_64_defconfig plus PCI_IOV, ICE, DCB and W=1.
Taking cfg_lock under RTNL follows the order set by commit ae82ccd68774 ("ice: attach and detach VF representors outside of vf->cfg_lock") in dev-queue.
drivers/net/ethernet/intel/ice/ice_lib.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/net/ethernet/intel/ice/ice_lib.c +9 -6
@@ -2207,7 +2207,6 @@ void ice_cfg_sw_rx_lldp(struct ice_pf *pf, bool enable) {struct ice_vsi *vsi;struct ice_vf *vf; -unsigned int bkt; vsi =ice_get_main_vsi (pf);ice_vsi_cfg_sw_lldp (vsi, false, enable);
@@ -2215,14 +2214,18 @@ void ice_cfg_sw_rx_lldp(struct ice_pf *pf, bool enable)if (!test_bit (ICE_FLAG_SRIOV_ENA , pf->flags))return ; -ice_for_each_vf (pf, bkt, vf) { - vsi =ice_get_vf_vsi (vf); - -if (WARN_ON (!vsi)) +for (u16 vf_id =0 ; vf_id < pf->vfs.num_supported; vf_id++) { + vf =ice_get_vf_by_id (pf, vf_id); +if (!vf)continue ; -if (ice_vf_is_lldp_ena (vf)) +mutex_lock (&vf->cfg_lock); + vsi =ice_get_vf_vsi (vf); +if (vsi &&ice_vf_is_lldp_ena (vf))ice_vsi_cfg_sw_lldp (vsi, false, enable); +mutex_unlock (&vf->cfg_lock); + +ice_put_vf (vf); } }
base-commit: c2c187fd5fa667cedb0b946f5f7a5099fb8e8402
Signature · 1 line
2.43.0