Skip to content

Commit 6d06bc8

Browse files
sergey-senozhatskykuba-moo
authored andcommitted
net: usb: r8152: fix resume reset deadlock
rtl8152 can trigger device reset during reset which potentially can result in a deadlock: **** DPM device timeout after 10 seconds; 15 seconds until panic **** Call Trace: <TASK> schedule+0x483/0x1370 schedule_preempt_disabled+0x15/0x30 __mutex_lock_common+0x1fd/0x470 __rtl8152_set_mac_address+0x80/0x1f0 dev_set_mac_address+0x7f/0x150 rtl8152_post_reset+0x72/0x150 usb_reset_device+0x1d0/0x220 rtl8152_resume+0x99/0xc0 usb_resume_interface+0x3e/0xc0 usb_resume_both+0x104/0x150 usb_resume+0x22/0x110 The problem is that rtl8152 resume calls reset under tp->control mutex while reset basically re-enters rtl8152 and attempts to acquire the same tp->control lock once again. Reset INACCESSIBLE device outside of tp->control mutex scope to avoid recursive mutex_lock() deadlock. Fixes: 4933b06 ("r8152: If inaccessible at resume time, issue a reset") Reviewed-by: Douglas Anderson <dianders@chromium.org> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org> Link: https://patch.msgid.link/20260129031106.3805887-1-senozhatsky@chromium.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent f8db647 commit 6d06bc8

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

drivers/net/usb/r8152.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8535,19 +8535,6 @@ static int rtl8152_system_resume(struct r8152 *tp)
85358535
usb_submit_urb(tp->intr_urb, GFP_NOIO);
85368536
}
85378537

8538-
/* If the device is RTL8152_INACCESSIBLE here then we should do a
8539-
* reset. This is important because the usb_lock_device_for_reset()
8540-
* that happens as a result of usb_queue_reset_device() will silently
8541-
* fail if the device was suspended or if too much time passed.
8542-
*
8543-
* NOTE: The device is locked here so we can directly do the reset.
8544-
* We don't need usb_lock_device_for_reset() because that's just a
8545-
* wrapper over device_lock() and device_resume() (which calls us)
8546-
* does that for us.
8547-
*/
8548-
if (test_bit(RTL8152_INACCESSIBLE, &tp->flags))
8549-
usb_reset_device(tp->udev);
8550-
85518538
return 0;
85528539
}
85538540

@@ -8658,19 +8645,33 @@ static int rtl8152_suspend(struct usb_interface *intf, pm_message_t message)
86588645
static int rtl8152_resume(struct usb_interface *intf)
86598646
{
86608647
struct r8152 *tp = usb_get_intfdata(intf);
8648+
bool runtime_resume = test_bit(SELECTIVE_SUSPEND, &tp->flags);
86618649
int ret;
86628650

86638651
mutex_lock(&tp->control);
86648652

86658653
rtl_reset_ocp_base(tp);
86668654

8667-
if (test_bit(SELECTIVE_SUSPEND, &tp->flags))
8655+
if (runtime_resume)
86688656
ret = rtl8152_runtime_resume(tp);
86698657
else
86708658
ret = rtl8152_system_resume(tp);
86718659

86728660
mutex_unlock(&tp->control);
86738661

8662+
/* If the device is RTL8152_INACCESSIBLE here then we should do a
8663+
* reset. This is important because the usb_lock_device_for_reset()
8664+
* that happens as a result of usb_queue_reset_device() will silently
8665+
* fail if the device was suspended or if too much time passed.
8666+
*
8667+
* NOTE: The device is locked here so we can directly do the reset.
8668+
* We don't need usb_lock_device_for_reset() because that's just a
8669+
* wrapper over device_lock() and device_resume() (which calls us)
8670+
* does that for us.
8671+
*/
8672+
if (!runtime_resume && test_bit(RTL8152_INACCESSIBLE, &tp->flags))
8673+
usb_reset_device(tp->udev);
8674+
86748675
return ret;
86758676
}
86768677

0 commit comments

Comments
 (0)