* [PATCH v2 net-next 1/1] net: usb: rtl8150: break cycle between tasklet and URB
@ 2026-11-18 13:35 Oliver Neukum
2026-11-21 23:02 ` netdev-bot+sashiko
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-21 23:02 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-21 23:02 UTC (permalink / raw)
To: oneukum
Cc: petkan, andrew+netdev, davem, edumazet, kuba, pabeni, linux-usb,
netdev, linux-kernel
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 1 (1) · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] Poisoning the URBs does not break the cycle.
- [Medium] The tasklet/URB resubmission cycle from the commit message is
still open in rtl8150_close() and rtl8150_suspend().
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
read_bulk_callback() hands dev->rx_skb to netif_rx() (line 430).
- [Medium] This problem wasn't introduced by this patch, but rx_fixup()
has a second self-rescheduling path that never touches a URB.
--
net: usb: rtl8150: break cycle between tasklet and URB
In rtl8150_disconnect(), this patch swaps usb_kill_urb() for
usb_poison_urb() on all three URBs. The goal is to stop the rx_fixup()
tasklet from resubmitting rx_urb. It also adds a second tasklet_kill()
after poisoning, so the tasklet is stopped before the URBs and skbs are
freed.
> 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);
[Severity: Medium]
The commit message says the tasklet/URB cycle needs to be broken. Is it
still open in rtl8150_close() and rtl8150_suspend()? Both stop rx_urb
with usb_kill_urb() only, and neither one stops the tasklet:
rtl8150_close() {
...
if (!test_bit(RTL8150_UNPLUG, &dev->flags))
disable_net_traffic(dev);
unlink_all_urbs(dev);
...
}
usb_kill_urb() raises urb->reject only while the call is running. If
rx_fixup() is pending or looping when close runs, its submit fails with
-EPERM during the kill and it reschedules itself. The next run, after
usb_kill_urb() has returned, then submits rx_urb successfully:
rx_fixup() {
...
try_again:
status = usb_submit_urb(dev->rx_urb, GFP_ATOMIC);
...
}
The tasklet can easily be pending at close time. read_bulk_callback()
schedules it whenever the 4-entry rx_skb_pool runs dry, and it keeps
looping while GFP_ATOMIC allocation fails.
disable_net_traffic() has already turned the receiver off, so the
bulk-IN URB just stays in flight. On the next ndo_open, rtl8150_open()
refills and resubmits the URB that is still active:
usb_fill_bulk_urb(dev->rx_urb, dev->udev, usb_rcvbulkpipe(dev->udev, 1),
dev->rx_skb->data, RTL8150_MTU, read_bulk_callback, dev);
if ((res = usb_submit_urb(dev->rx_urb, GFP_KERNEL))) {
That would hit the "URB %p submitted while active" WARN_ONCE in
usb_submit_urb() and return -EBUSY. Wouldn't every later open then fail
the same way until the device is replugged or rebound?
The suspend path looks similar. A tasklet submit can follow the
usb_kill_urb() in rtl8150_suspend(), and a later resubmit of rx_urb
after resume would then fail with -EBUSY.
[ ... ]
> @@ -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);
[Severity: High]
Does poisoning actually break the cycle here? It makes every resubmit
fail. However, rx_fixup() reschedules itself after any submit error
other than -ENODEV, and it never checks RTL8150_UNPLUG:
rx_fixup() {
...
if (test_bit(RX_URB_FAIL, &dev->flags))
if (dev->rx_skb)
goto try_again;
...
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;
...
}
On a soft unbind (rmmod, sysfs unbind, or a forced unbind from
usb_reset_device()), the device is still attached, so usb_submit_urb()
never returns -ENODEV. Instead:
- rtl8150_driver has no soft_unbind, so usb_unbind_interface() disables
the endpoints before calling ->disconnect. Submits then fail with
-ENOENT from usb_hcd_link_urb_to_ep().
- After terminate_all_urbs(), urb->reject stays raised for good, so
submits fail with -EPERM.
Either way, once the tasklet runs it reschedules itself forever.
tasklet_action_common() clears TASKLET_STATE_SCHED just before it calls
the callback, and the callback sets it again. tasklet_kill() waits with
wait_on_bit_lock(SCHED) in TASK_UNINTERRUPTIBLE, so it can only win
inside that short window.
On a non-RT kernel, a waiter on the same CPU cannot preempt the softirq,
so it only ever sees SCHED set. On UP, wouldn't this be a deterministic
livelock? rtl8150_disconnect() would sit in D state holding the device
lock while ksoftirqd spins. On SMP the waiter can keep losing the race.
The loop can also start before this point. On a soft unbind with the
interface up, usb_disable_interface() flushes rx_urb with -ESHUTDOWN
while RTL8150_UNPLUG is still clear. read_bulk_callback() takes the
default case to goon, the resubmit fails with -ENOENT, and it calls
tasklet_schedule(). So the existing first tasklet_kill() already faces
this loop, and on a soft unbind the new second one always faces it.
Could rx_fixup() be stopped from rescheduling instead? For example, it
could check RTL8150_UNPLUG on entry or treat -EPERM/-ENOENT as fatal.
Another option is to disable the tasklet before killing it.
[Severity: Medium]
This isn't a bug introduced by this patch, but rx_fixup() has a second
self-rescheduling path that never touches a URB:
rx_fixup() {
...
spin_lock_irq(&dev->rx_pool_lock);
skb = pull_skb(dev);
spin_unlock_irq(&dev->rx_pool_lock);
if (skb == NULL)
goto tlsched;
...
}
If dev_alloc_skb(RTL8150_MTU + 2) in fill_skb_pool() fails while the
pool is empty, pull_skb() returns NULL and the tasklet reschedules
itself. Poisoning in terminate_all_urbs() has no effect on this path,
and RTL8150_UNPLUG is not checked.
While GFP_ATOMIC allocations keep failing at disconnect time, can both
tasklet_kill() calls in rtl8150_disconnect() stall the same way as
described above? The stall ends once an allocation succeeds, so it only
lasts as long as the memory pressure. A check for RTL8150_UNPLUG at the
top of rx_fixup() would fix this along with the issue above.
> free_all_urbs(dev);
> free_skb_pool(dev);
> dev_kfree_skb(dev->rx_skb);
[Severity: High]
This is a pre-existing issue, but can dev->rx_skb be stale here?
read_bulk_callback() hands dev->rx_skb to the stack. When the pool is
empty, it leaves the old pointer in place:
read_bulk_callback() {
...
netif_rx(dev->rx_skb);
...
spin_lock_irqsave(&dev->rx_pool_lock, flags);
skb = pull_skb(dev);
spin_unlock_irqrestore(&dev->rx_pool_lock, flags);
if (!skb)
goto resched;
dev->rx_skb = skb;
...
}
The pool has only 4 entries and only the tasklet refills it, so this
happens routinely. Nothing ever sets dev->rx_skb to NULL. The pointer
is only replaced by a later successful pull_skb() in rx_fixup().
If that replacement never happens, this dev_kfree_skb() frees an skb
that the network stack already owns. It can fail to happen in two ways:
- dev_alloc_skb() in rx_fixup() fails on the run during which
tasklet_kill() wins.
- A completion passes the RTL8150_UNPLUG check just before set_bit().
Its tasklet_schedule() then runs while the first tasklet_kill() holds
TASKLET_STATE_SCHED through wait_on_bit_lock(). tasklet_schedule()
does nothing when SCHED is already set, so the tasklet never runs.
The same stale pointer also seems to affect rtl8150_open():
if (dev->rx_skb == NULL)
dev->rx_skb = pull_skb(dev);
Suppose a close/open happens while the tasklet is still looping on
allocation failure. Wouldn't rx_urb then be submitted with the freed
skb's data as its DMA buffer?
Because of this, the "if (!dev->rx_skb) goto resched;" check in
read_bulk_callback() also looks like dead code.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118133550.955312-1-oneukum%40suse.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-21 23:02 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-21 23:02 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox