usb: xhci: Two possible sleep-in-atomic-context bugs
The driver may sleep with holding a spinlock.
The function call paths (from bottom to top) in Linux-4.16.7 are:
[FUNC] scheduledrivers/base/power/runtime.c, 741: schedule in rpm_resume drivers/base/power/runtime.c, 1322: rpm_resume in pm_runtime_forbid drivers/usb/host/xhci-hub.c, 647: pm_runtime_forbid in xhci_enter_test_mode drivers/usb/host/xhci-hub.c, 632: _raw_spin_lock_irqsave in xhci_enter_test_mode
[FUNC] scheduledrivers/base/power/runtime.c, 570: schedule in rpm_suspend drivers/base/power/runtime.c, 434: rpm_suspend in rpm_idle drivers/base/power/runtime.c, 1343: rpm_idle in pm_runtime_allow drivers/usb/host/xhci-hub.c, 670: pm_runtime_allow in xhci_exit_test_mode drivers/usb/host/xhci-hub.c, 1387: xhci_exit_test_mode in xhci_hub_control drivers/usb/host/xhci-hub.c, 1038: _raw_spin_lock_irqsave in xhci_hub_control
These bugs are found by my static analysis tool (DSAC-2) and checked by my code review.
I do not know how to correctly fix these bugs, so I just report them.
Best wishes,
Jia-Ju Bai
Quoted 19 lines
The driver may sleep with holding a spinlock.
The function call paths (from bottom to top) in Linux-4.16.7 are:[FUNC] schedule
drivers/base/power/runtime.c, 741: schedule inrpm_resumedrivers/base/power/runtime.c, 1322:rpm_resumeinpm_runtime_forbiddrivers/usb/host/xhci-hub.c, 647:pm_runtime_forbidinxhci_enter_test_modedrivers/usb/host/xhci-hub.c, 632:_raw_spin_lock_irqsaveinxhci_enter_test_mode[FUNC] schedule
drivers/base/power/runtime.c, 570: schedule inrpm_suspenddrivers/base/power/runtime.c, 434:rpm_suspendinrpm_idledrivers/base/power/runtime.c, 1343:rpm_idleinpm_runtime_allowdrivers/usb/host/xhci-hub.c, 670:pm_runtime_allowinxhci_exit_test_modedrivers/usb/host/xhci-hub.c, 1387:xhci_exit_test_modeinxhci_hub_controldrivers/usb/host/xhci-hub.c, 1038:_raw_spin_lock_irqsaveinxhci_hub_control
Quoted 3 lines
These bugs are found by my static analysis tool (DSAC-2) and checked by my code review.
I don't think runtime PM API is needed at xhci_hub_control since the controller should be always active, Mathias, do you agree I delete pm_runtime_forbid and pm_runtime_allow to fix this issue?
Peter
Quoted 19 lines · Peter Chen
Quoted 19 lines
The driver may sleep with holding a spinlock.
The function call paths (from bottom to top) in Linux-4.16.7 are:[FUNC] schedule
drivers/base/power/runtime.c, 741: schedule inrpm_resumedrivers/base/power/runtime.c, 1322:rpm_resumeinpm_runtime_forbiddrivers/usb/host/xhci-hub.c, 647:pm_runtime_forbidinxhci_enter_test_modedrivers/usb/host/xhci-hub.c, 632:_raw_spin_lock_irqsaveinxhci_enter_test_mode[FUNC] schedule
drivers/base/power/runtime.c, 570: schedule inrpm_suspenddrivers/base/power/runtime.c, 434:rpm_suspendinrpm_idledrivers/base/power/runtime.c, 1343:rpm_idleinpm_runtime_allowdrivers/usb/host/xhci-hub.c, 670:pm_runtime_allowinxhci_exit_test_modedrivers/usb/host/xhci-hub.c, 1387:xhci_exit_test_modeinxhci_hub_controldrivers/usb/host/xhci-hub.c, 1038:_raw_spin_lock_irqsaveinxhci_hub_control
Quoted 8 lines
Quoted 3 lines
These bugs are found by my static analysis tool (DSAC-2) and checked by my code review.
I don't think runtime PM API is needed at
xhci_hub_controlsince the controller should be always active, Mathias, do you agree I deletepm_runtime_forbidandpm_runtime_allowto fix this issue?
The USB2 test mode is a bit special, it will disable all connected devices, and halt the host. Port should stay in test mode until feature is cleared or host reset.
There is a risk runtime suspend will try to suspend the host as no devices seem preset.
But I think pm_runtime_get_noresume() and pm_runtime_put_noidle() could be used instad, those should be safe.
-Mathias