Linux USB
 help / color / mirror / Atom feed
* [PATCH v2 net-next 1/1] net: usb: rtl8150: break cycle between tasklet and URB
@ 2026-11-18 13:35 Oliver Neukum
  2026-11-19 13:36 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Oliver Neukum @ 2026-11-18 13:35 UTC (permalink / raw)
  To: petkan, andrew+netdev, davem, edumazet, kuba, pabeni, linux-usb,
	netdev, linux-kernel
  Cc: Oliver Neukum

The tasklet can resubmit the URB, which in turn can
resubmit the tasklet. The cycle needs to be broken.
The simplest way to do so is to prevent the resubmission
of the URBs by poisoning them.

This has been detected by automatic code analysis.

Fixes: eff674a514bd3 ("USB: rtl8150_disconnect() needs tasklet_kill()")
Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
 drivers/net/usb/rtl8150.c | 10 +++++++++-

V2: Sashiko pointed out errors which conceptually arose from handling
close() and disconnect() in the same way. Treating disconnect()
separatly makes them go away

 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
index d51e43170e03..6d20f52d52ef 100644
--- a/drivers/net/usb/rtl8150.c
+++ b/drivers/net/usb/rtl8150.c
@@ -353,6 +353,13 @@ static void free_all_urbs(rtl8150_t * dev)
 	usb_free_urb(dev->intr_urb);
 }
 
+static void terminate_all_urbs(rtl8150_t *dev)
+{
+	usb_poison_urb(dev->rx_urb);
+	usb_poison_urb(dev->tx_urb);
+	usb_poison_urb(dev->intr_urb);
+}
+
 static void unlink_all_urbs(rtl8150_t * dev)
 {
 	usb_kill_urb(dev->rx_urb);
@@ -970,7 +977,8 @@ static void rtl8150_disconnect(struct usb_interface *intf)
 		set_bit(RTL8150_UNPLUG, &dev->flags);
 		tasklet_kill(&dev->tl);
 		unregister_netdev(dev->netdev);
-		unlink_all_urbs(dev);
+		terminate_all_urbs(dev);
+		tasklet_kill(&dev->tl);
 		free_all_urbs(dev);
 		free_skb_pool(dev);
 		dev_kfree_skb(dev->rx_skb);
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2 net-next 1/1] net: usb: rtl8150: break cycle between tasklet and URB
  2026-11-18 13:35 [PATCH v2 net-next 1/1] net: usb: rtl8150: break cycle between tasklet and URB Oliver Neukum
@ 2026-11-19 13:36 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-19 13:36 UTC (permalink / raw)
  To: Oliver Neukum, linux-usb

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] net: usb: rtl8150: tasklet livelock on poisoned URB in
  rx_fixup()
- [Medium] net: usb: rtl8150: URBs poisoned too late in
  rtl8150_disconnect()
--

commit 1541c4307c346b500c4b1389da4c563d28fd64b6
Author: Oliver Neukum <oneukum@suse.com>

net: usb: rtl8150: break cycle between tasklet and URB

This commit replaces unlink_all_urbs() with terminate_all_urbs() using
usb_poison_urb() in rtl8150_disconnect(), followed by a second
tasklet_kill(), to break the resubmission cycle between URBs and the
tasklet.

> diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
> index d51e43170e033..6d20f52d52efd 100644
> --- a/drivers/net/usb/rtl8150.c
> +++ b/drivers/net/usb/rtl8150.c
> @@ -353,6 +353,13 @@ static void free_all_urbs(rtl8150_t * dev)
>  	usb_free_urb(dev->intr_urb);
>  }
>  
> +static void terminate_all_urbs(rtl8150_t *dev)
> +{
> +	usb_poison_urb(dev->rx_urb);
> +	usb_poison_urb(dev->tx_urb);
> +	usb_poison_urb(dev->intr_urb);
> +}
> +
>  static void unlink_all_urbs(rtl8150_t * dev)
>  {
>  	usb_kill_urb(dev->rx_urb);
> @@ -970,7 +977,8 @@ static void rtl8150_disconnect(struct usb_interface *intf)
>  		set_bit(RTL8150_UNPLUG, &dev->flags);
>  		tasklet_kill(&dev->tl);
>  		unregister_netdev(dev->netdev);
> -		unlink_all_urbs(dev);
> +		terminate_all_urbs(dev);

[Severity: Medium]
Can rx_fixup() still run during unregister_netdev() before
terminate_all_urbs() poisons the URBs?

CPU0                                    CPU1
                                        read_bulk_callback()
                                          test_bit(RTL8150_UNPLUG, ...)
rtl8150_disconnect()
  set_bit(RTL8150_UNPLUG, ...)
  tasklet_kill(&dev->tl)
  unregister_netdev(dev->netdev)
    ...
      rtl8150_close()
        unlink_all_urbs(dev)
          usb_kill_urb(dev->rx_urb)
                                          usb_submit_urb() -> -EPERM
                                          tasklet_schedule(&dev->tl)
          /* urb->reject returns to 0 */
                                        rx_fixup()
                                          usb_submit_urb(dev->rx_urb, ...)
  terminate_all_urbs(dev)

Because rtl8150_close() only uses usb_kill_urb(), dev->rx_urb is unpoisoned
again as soon as usb_kill_urb() returns.  If an in-flight
read_bulk_callback() passed the RTL8150_UNPLUG check just before
rtl8150_disconnect() set the bit, its usb_submit_urb() fails with -EPERM
while usb_kill_urb() is waiting and schedules dev->tl.  rx_fixup() can then
run before terminate_all_urbs() and either resubmit dev->rx_urb after
rtl8150_close() or, if usb_submit_urb() returns -ENODEV, call
netif_device_detach() on an unregistered net_device.

Would calling terminate_all_urbs() before the first tasklet_kill() and
unregister_netdev() avoid this window?

> +		tasklet_kill(&dev->tl);

[Severity: High]
Will tasklet_kill(&dev->tl) livelock if dev->tl is scheduled after
dev->rx_urb is poisoned?

drivers/net/usb/rtl8150.c:rx_fixup() {
	...
try_again:
	status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
	if (status == -ENODEV) {
		netif_device_detach(dev->netdev);
	} else if (status) {
		set_bit(RX_URB_FAIL, &dev->flags);
		goto tlsched;
	} else {
		clear_bit(RX_URB_FAIL, &dev->flags);
	}

	return;
tlsched:
	tasklet_schedule(&dev->tl);
}

Submitting a poisoned URB returns -EPERM (or -ENOENT once the endpoint is
disabled), not -ENODEV.  Because rx_fixup() does not check RTL8150_UNPLUG
and treats any error other than -ENODEV as retryable, it sets RX_URB_FAIL
and reschedules dev->tl on every run.  On subsequent runs RX_URB_FAIL makes
rx_fixup() jump straight to try_again, get -EPERM from the poisoned
dev->rx_urb, and call tasklet_schedule(&dev->tl) again, spinning in softirq
and hanging tasklet_kill() in rtl8150_disconnect() during driver unbind or
disconnect.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118133550.955312-1-oneukum@suse.com?part=1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19 13:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 13:35 [PATCH v2 net-next 1/1] net: usb: rtl8150: break cycle between tasklet and URB Oliver Neukum
2026-11-19 13:36 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox