| Message ID | 20261023070258.730168-6-poros@redhat.com |
|---|---|
| State | New |
| Headers | show |
| Series | ice: fix RTNL vs auxiliary device lock inversion | expand |
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] ice: orphaned channel VSIs and memory leak when ice_setup_tc() fails teardown -- commit 58934f25b30092ac8064d34365ba48edb6a32a06 Author: Petr Oros <poros@redhat.com> ice: do not block on the aux device lock in ndo_setup_tc This commit replaces device_lock() with device_trylock() on the RDMA auxiliary device in the TC_SETUP_QDISC_MQPRIO path of ice_setup_tc() to avoid a lock dependency cycle with the RTNL lock, returning -EBUSY when the lock is contended. > diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c > index 9de375f5c4deb..7eb653a7ebacd 100644 > --- a/drivers/net/ethernet/intel/ice/ice_main.c > +++ b/drivers/net/ethernet/intel/ice/ice_main.c > @@ -9451,7 +9451,12 @@ ice_setup_tc(struct net_device *netdev, enum tc_setup_type type, > mutex_lock(&pf->adev_mutex); > adev = cdev->adev; > if (adev) { > - device_lock(&adev->dev); > + if (!device_trylock(&adev->dev)) { > + mutex_unlock(&pf->adev_mutex); > + netdev_warn(netdev, "RDMA auxiliary device is busy, qdisc not changed\n"); > + err = -EBUSY; > + goto tc_unlock; > + } [Severity: High] Can failing with -EBUSY during qdisc removal permanently leak the struct ice_channel entries on vsi->ch_list and leave channel VSI state orphaned? The commit message notes that when the qdisc is deleted, mqprio_disable_offload() ignores the return value so the hardware traffic classes and channel VSIs stay in place until a later qdisc teardown gets through. However, in net/sched/sch_mqprio.c, mqprio_destroy() calls mqprio_disable_offload() once while destroying the Qdisc: net/sched/sch_mqprio.c:mqprio_destroy() { ... if (priv->hw_offload && dev->netdev_ops->ndo_setup_tc) mqprio_disable_offload(sch); else netdev_set_num_tc(dev, 0); } Once mqprio_destroy() finishes, the Qdisc object is freed and no mqprio Qdisc remains attached to the net_device, so no subsequent teardown call will happen for it (including on unregister_netdev()). During driver unload (ice_remove() -> ice_unload() -> ice_deinit() -> ice_vsi_release_all()), ice_deinit_pf_sw() releases the main VSI without calling ice_remove_q_channels(), and ice_vsi_release_all() skips ICE_VSI_CHNL VSIs: drivers/net/ethernet/intel/ice/ice_main.c:ice_vsi_release_all() { ... if (pf->vsi[i]->type == ICE_VSI_CHNL) continue; err = ice_vsi_release(pf->vsi[i]); ... } Moreover, if a user later adds a new offloaded mqprio qdisc (hw != 0) to attempt another teardown, ice_setup_tc_mqprio_qdisc() only removes existing channels when disabling offload: drivers/net/ethernet/intel/ice/ice_main.c:ice_setup_tc_mqprio_qdisc() { ... if (!hw && !test_bit(ICE_FLAG_TC_MQPRIO, pf->flags)) ice_remove_q_channels(vsi, true); ... if (hw) { ... ret = ice_create_q_channels(vsi); ... } } Wouldn't adding a new offloaded mqprio qdisc leave the old struct ice_channel entries on vsi->ch_list, rebuild the main VSI rings, and append duplicate channels via ice_create_q_channels(), potentially indexing past vsi->tx_rings[] and vsi->rx_rings[] in ice_remove_q_channels() if the new qdisc configures fewer queues?
diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c index 9de375f5c4deb5..7eb653a7ebacd5 100644 --- a/drivers/net/ethernet/intel/ice/ice_main.c +++ b/drivers/net/ethernet/intel/ice/ice_main.c @@ -9451,7 +9451,12 @@ ice_setup_tc(struct net_device *netdev, enum tc_setup_type type, mutex_lock(&pf->adev_mutex); adev = cdev->adev; if (adev) { - device_lock(&adev->dev); + if (!device_trylock(&adev->dev)) { + mutex_unlock(&pf->adev_mutex); + netdev_warn(netdev, "RDMA auxiliary device is busy, qdisc not changed\n"); + err = -EBUSY; + goto tc_unlock; + } locked = true; if (adev->dev.driver) { netdev_err(netdev, "Cannot change qdisc when RDMA is active\n"); @@ -9471,6 +9476,7 @@ ice_setup_tc(struct net_device *netdev, enum tc_setup_type type, device_unlock(&adev->dev); mutex_unlock(&pf->adev_mutex); } +tc_unlock: mutex_unlock(&pf->tc_mutex); return err; case TC_SETUP_QDISC_ETF:
The TC_SETUP_QDISC_MQPRIO path of ice_setup_tc() takes the auxiliary device lock to test whether the RDMA driver is bound, and ndo_setup_tc() runs with the RTNL lock held. This closes the same cycle against the RDMA auxiliary probe as the two preceding patches. Use device_trylock() and report the device as busy when it fails. When the qdisc is added, userspace gets -EBUSY and can retry. When it is deleted, mqprio_disable_offload() ignores the return value, so the hardware traffic classes and the channel VSIs stay in place until a later qdisc teardown gets through, the same as the existing -EBUSY for a bound RDMA driver. The message is a netdev_warn() because of that second case, nothing else reports it. Fixes: 4b31fd4d77ff ("ice: Fix RDMA VSI removal during queue rebuild") Signed-off-by: Petr Oros <poros@redhat.com> --- v2: - rebased on the new patches 1 and 2 - netdev_warn() instead of netdev_dbg(), the qdisc teardown cannot retry and ignores the return value v1: https://lore.kernel.org/all/20261019065301.3983537-4-poros@redhat.com/ --- drivers/net/ethernet/intel/ice/ice_main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)