Skip to contentSkip to conversation

wifi: rtw88: usb: stop RX work before unregistering hardware

PATCH Superseded Zhao Li 2 participants 3 messages Oct 28 – Nov 1

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zhao Li

author
#0 lore raw

PATCH 1/1 wifi: rtw88: usb: stop RX work before unregistering hardware

Disconnecting an rtw88 USB device while RX traffic is active can leave the RX worker running after mac80211 hardware is unregistered. A firmware event can then queue C2H work onto a destroyed workqueue.

rtw_usb_disconnect() kills active RX URBs and unregisters the hardware without disabling rx_urb_work or canceling rx_work. The resubmission work can restart a killed URB, while an in-flight RX worker can keep processing packets during teardown.

Disable rx_urb_work before killing the active RX URBs, then cancel rx_work synchronously before unregistering the hardware.

LLM assistance was used to find the bug and review.

Fixes a82dfd33d123 ("wifi: rtw88: Add common USB chip support")
Fixes 3e3aa566dd18 ("wifi: rtw88: usb: Preallocate and reuse the RX skbs")
Cc [email protected] # needs adjustments for <= 6.13

---
Validation: A W=1 module build with MODPOST passed on the rtw tree. Not reproduced; rtw88 USB hardware was unavailable. Sparse C=2 passed. Targeted Smatch introduced no new diagnostics. Kernels before 6.14 have no rx_urb_work, and 6.6 also lacks disable_work_sync(). There, killing the URBs already stops resubmission, so the backport only needs cancel_work_sync(&rtwusb->rx_work) after rtw_usb_cancel_rx_bufs().

 drivers/net/wireless/realtek/rtw88/usb.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/wireless/realtek/rtw88/usb.c +3 -0
index 64e1c3420e0a..1d2759eb96bf 100644
@@ -1370,7 +1370,10 @@ void rtw_usb_disconnect(struct usb_interface *intf)
 	rtwdev = hw->priv;
 	rtwusb = rtw_get_usb_priv(rtwdev);
 
+	/* Stop deferred resubmission before killing the active RX URBs. */
+	disable_work_sync(&rtwusb->rx_urb_work);
 	rtw_usb_cancel_rx_bufs(rtwusb);
+	cancel_work_sync(&rtwusb->rx_work);
 
 	rtw_unregister_hw(rtwdev, hw);
 	rtw_usb_deinit_tx(rtwdev);

base-commit: af32da41b0327b9c6a37856ba82b6760d6c8d10e

Signature · 1 line
2.56.0
#1 lore raw

Hi Zhao,

Thanks for the fix. One comment below.

drivers/net/wireless/realtek/rtw88/usb.c void rtw_usb_disconnect(struct usb_interface *intf) · line 1374

Quoted 10 lines · Zhao Li
drivers/net/wireless/realtek/rtw88/usb.c +2 -0
index 64e1c3420e0a..1d2759eb96bf 100644
@@ -1370,7 +1370,10 @@ void rtw_usb_disconnect(struct usb_interface *intf)
      rtwdev = hw->priv;
      rtwusb = rtw_get_usb_priv(rtwdev);
 
+     /* Stop deferred resubmission before killing the active RX URBs. */
+     disable_work_sync(&rtwusb->rx_urb_work);

As far as I can see, rx_urb_work can't bring an URB back at this point. rtw88 doesn't set soft_unbind, so the USB core disables the endpoints before it calls the driver:

        usb_unbind_interface()
          usb_disable_interface()
            usb_disable_endpoint()
              ep->enabled = 0;
          driver->disconnect()
            rtw_usb_disconnect()

After that usb_submit_urb() on the RX pipe fails for the rest of the RX teardown, and a failed submit only queues the work again on -ENOMEM. So I think cancel_work_sync() on rx_work alone already closes the race, and the same change would then work for the older stable trees too.

Keeping disable_work_sync() doesn't hurt, but then the commit message shouldn't say the work can restart a killed URB. Or did I miss a path where we get here with the endpoints still enabled?

Best regards,
Luka Gejak

author
#2 lore raw

Hi Luka,

Quoted 11 lines · Luka Gejak

As far as I can see, rx_urb_work can't bring an URB back at this point. rtw88 doesn't set soft_unbind, so the USB core disables the endpoints before it calls the driver:

        usb_unbind_interface()
          usb_disable_interface()
            usb_disable_endpoint()
              ep->enabled = 0;
          driver->disconnect()
            rtw_usb_disconnect()
Quoted 8 lines

After that usb_submit_urb() on the RX pipe fails for the rest of the RX teardown, and a failed submit only queues the work again on -ENOMEM. So I think cancel_work_sync() on rx_work alone already closes the race, and the same change would then work for the older stable trees too.

Keeping disable_work_sync() doesn't hurt, but then the commit message shouldn't say the work can restart a killed URB. Or did I miss a path where we get here with the endpoints still enabled?

You didn't miss one. usb_unbind_interface() is the only caller of an interface driver's ->disconnect(), and none of the rtw88 USB drivers sets soft_unbind. Before rtw_usb_disconnect() returns, only its own usb_reset_device() enables the endpoints again, and that runs after rtw_usb_deinit_rx() has destroyed rxwq.

rx_urb_work can still run until then after an allocation failure, but its submit fails on the disabled endpoint. The commit message was wrong about that.

I'll send a v2 that only adds cancel_work_sync(&rtwusb->rx_work) after rtw_usb_cancel_rx_bufs(), with a corrected message and without the 3e3aa566dd18 Fixes tag. It applies unchanged to 6.6.y and later.

Thanks,
Zhao