Bluetooth: btusb: Intel AX211 (8087:0033) permanently lost after suspend/resume
Hi,
I'm hitting an issue where my Intel AX211 Bluetooth controller (USB 8087:0033) permanently vanishes after suspend/resume. The device disappears from lsusb entirely and doesn't come back, even across further suspend/resume cycles. Only way to recover without rebooting is resetting the xHCI host controller.
I traced this across multiple suspend/resume cycles in the same boot and found what looks like a race condition between the PM notifier's HCI shutdown and the USB subsystem tearing down the device. I also took a look at the btusb source and believe I found the root cause, included as a patch in a follow-up.
*Setup:*
* Lenovo ThinkPad T14 Intel
* Intel AX211 Bluetooth, USB ID 8087:0033
* Internal USB port 3-10, xHCI at PCI 0000:00:14.0
* Firmware: intel/ibt-0040-0041.sfi, version 133-20.25
* Kernel: 6.17.0-14-generic (Ubuntu)
*What I'm seeing:*
On successful resumes, the HCI power-off command (Write Scan Enable, 0x0c1a) times out with -ETIMEDOUT. The ACPI reset method then kicks in, the device re-enumerates at full-speed, firmware loads, everything works:
|Bluetooth: hci0: command 0x0c1a tx timeout Bluetooth: hci0: Initiating acpi reset method Bluetooth: hci0: Opcode 0x0c1a failed: -110 usb 3-10: new full-speed USB device using xhci_hcd usb 3-10: New USB device found, idVendor=8087, idProduct=0033 Bluetooth: hci0: Found device firmware: intel/ibt-0040-0041.sfi Bluetooth: hci0: Firmware loaded in 1602079 usecs |
On the failed resume, the USB subsystem disconnects the device before the HCI command can timeout. The error is -ENODEV instead of -ETIMEDOUT:
|usb 3-10: USB disconnect, device number 19 Bluetooth: hci0: Opcode 0x0c1a failed: -19 Bluetooth: hci0: Error when powering off device on rfkill (-19) Bluetooth: hci0: sending frame failed (-19) Bluetooth: hci0: HCI reset during shutdown failed usb 3-10: new low-speed USB device number 30 using xhci_hcd usb 3-10: Device not responding to setup address. usb 3-10: device not accepting address 30, error -71 |
After this, /sys/bus/usb/devices/3-10/ is gone, bluetoothctl says "No default controller available", and btusb is loaded with 0 users. rfkill block/unblock does nothing since the USB device itself no longer exists.
*What I think is happening in the code:*
hci_cmd_timeout() (hci_core.c:1462) is the only path that calls hdev->reset(), which for Intel devices triggers btintel_acpi_reset_method() via btusb_intel_reset(). But when the pending HCI command is canceled with ENODEV (via hci_cmd_sync_cancel_sync in hci_dev_close_sync), hci_cmd_timeout never fires, so the ACPI reset that would recover the device is bypassed entirely.
The race exists because the PM notifier (hci_suspend_notifier -> hci_suspend_dev) and USB suspend (btusb_suspend) run concurrently with no synchronization. Whether the device survives depends on whether the HCI command times out before or after the USB subsystem tears things down.
*Recovery* (without reboot):
|echo "0000:00:14.0" > /sys/bus/pci/drivers/xhci_hcd/unbind sleep 3 echo "0000:00:14.0" > /sys/bus/pci/drivers/xhci_hcd/bind |
*Reproduction:*
Intermittent, timing-dependent. In my case, the first two suspend/resume cycles in a boot succeeded and the third failed. I haven't bisected to a specific commit yet.
Thanks,
Frederik Berg
PATCH 1/1 Bluetooth: btusb: cancel pending HCI commands before USB suspend
During system suspend, the PM notifier and USB subsystem suspend run concurrently without synchronization. If the PM notifier's hci_power_off_sync() is blocked waiting for an HCI command response (e.g., Write Scan Enable, opcode 0x0c1a) when the USB subsystem tears down the device, the command fails with -ENODEV.
Unlike a timeout (-ETIMEDOUT), an ENODEV cancellation does not trigger hci_cmd_timeout(), which means hdev->reset() is never called and the Intel ACPI reset method (_PRR/_RST) that would recover the device is bypassed. The device then fails to re-enumerate on resume (detected as low-speed instead of full-speed, error -71) and is permanently lost until the xHCI host controller is reset or the system is rebooted.
Cancel any pending synchronous HCI commands in btusb_suspend() before btusb_stop_traffic() kills the URBs, but only for non-autosuspend (system suspend). This matches the pattern used by hci_suspend_dev() which calls hci_cancel_cmd_sync(hdev, EHOSTDOWN) before proceeding with HCI-level suspend.
---
Proposed fix for the race described in the parent email. This cancels any pending synchronous HCI commands in btusb_suspend() before btusb_stop_traffic() kills the URBs, preventing the race. Only for system suspend, not autosuspend. Same pattern used by hci_suspend_dev() which calls hci_cancel_cmd_sync(hdev, EHOSTDOWN).
I haven't been able to build-test this against a running kernel yet, so consider this an RFC.
drivers/bluetooth/btusb.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/bluetooth/btusb.c +3 -0
@@ -4497,6 +4497,9 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message)cancel_work_sync (&data->work); +if (!PMSG_IS_AUTO (message)) +hci_cmd_sync_cancel_sync (data->hdev,EHOSTDOWN ); +if (data->suspend) data->suspend (data->hdev);
Signature · 1 line
2.53.0
RE: Bluetooth: btusb: cancel pending HCI commands before USB suspend
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1069868
---Test result---
Test Summary:
CheckPatch PENDING 0.38 seconds GitLint PENDING 0.23 seconds SubjectPrefix PASS 0.09 seconds BuildKernel PASS 26.69 seconds CheckAllWarning PASS 29.06 seconds CheckSparse PASS 28.04 seconds BuildKernel32 PASS 25.68 seconds TestRunnerSetup PASS 569.56 seconds TestRunner_l2cap-tester PASS 28.01 seconds TestRunner_iso-tester FAIL 38.59 seconds TestRunner_bnep-tester PASS 6.27 seconds TestRunner_mgmt-tester FAIL 116.26 seconds TestRunner_rfcomm-tester PASS 9.50 seconds TestRunner_sco-tester FAIL 14.44 seconds TestRunner_ioctl-tester PASS 10.30 seconds TestRunner_mesh-tester FAIL 11.49 seconds TestRunner_smp-tester PASS 8.55 seconds TestRunner_userchan-tester PASS 6.66 seconds IncrementalBuild PENDING 0.89 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner
Output:
BUG: KASAN: slab-use-after-free in le_read_features_complete+0x7e/0x2b0
Total: 141, Passed: 141 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4
Failed Test Cases
Read Exp Feature - Success Failed 0.104 seconds
##############################
Test: TestRunner_sco-tester - FAIL
Desc: Run sco-tester with test-runner
Output:
WARNING: possible circular locking dependency detected
BUG: sleeping function called from invalid context at net/core/sock.c:3782
Total: 30, Passed: 30 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0
Failed Test Cases
Mesh - Send cancel - 1 Timed out 1.845 seconds Mesh - Send cancel - 2 Timed out 1.997 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerRe: [PATCH] Bluetooth: btusb: cancel pending HCI commands before USB suspend
In reply to Frederik BergHi Frederik,
Quoted 49 lines · Frederik Berg
During system suspend, the PM notifier and USB subsystem suspend run concurrently without synchronization. If the PM notifier's
hci_power_off_sync()is blocked waiting for an HCI command response (e.g., Write Scan Enable, opcode0x0c1a) when the USB subsystem tears down the device, the command fails with-ENODEV.Unlike a timeout (
-ETIMEDOUT), an ENODEV cancellation does not triggerhci_cmd_timeout(), which meanshdev->reset()is never called and the Intel ACPI reset method (_PRR/_RST) that would recover the device is bypassed. The device then fails to re-enumerate on resume (detected as low-speed instead of full-speed, error -71) and is permanently lost until the xHCI host controller is reset or the system is rebooted.Cancel any pending synchronous HCI commands in
btusb_suspend()beforebtusb_stop_traffic()kills the URBs, but only for non-autosuspend (system suspend). This matches the pattern used byhci_suspend_dev()which callshci_cancel_cmd_sync(hdev, EHOSTDOWN)before proceeding with HCI-level suspend.Signed-off-by Frederik Berg <[email protected]>---
Proposed fix for the race described in the parent email. This cancels any pending synchronous HCI commands inbtusb_suspend()beforebtusb_stop_traffic()kills the URBs, preventing the race. Only for system suspend, not autosuspend. Same pattern used byhci_suspend_dev()which callshci_cancel_cmd_sync(hdev, EHOSTDOWN).I haven't been able to build-test this against a running kernel yet, so consider this an RFC.
drivers/bluetooth/btusb.c | 3 +++ 1 file changed, 3 insertions(+)drivers/bluetooth/btusb.c +3
-1@@ -4497,6 +4497,9 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message)cancel_work_sync (&data->work); +if (!PMSG_IS_AUTO (message)) +hci_cmd_sync_cancel_sync (data->hdev,EHOSTDOWN ); +if (data->suspend) data->suspend (data->hdev); --
Quoted 1 line
2.53.0
Have to agree with a few points over here:
https://sashiko.dev/#/patchset/20260320114347.2340528-1-fberg%40posteo.de
Specially the first point: if hci_suspend_sync (which should be pending not hci_power_off_sync ) had run, then there shouldn't be anything to cancel at btusb_suspend and hdev should be suspended. Perhaps something is trying to power off bluetooth (e.g. userspace)? Anyway hci_suspend_dev does already perform hci_cmd_sync_cancel_sync(data->hdev, EHOSTDOWN); or do you have HCI_QUIRK_NO_SUSPEND_NOTIFIER set for it, which is why it doesn't run?
The other option would be to call hci_suspend_dev directly from the driver, but then again the register_pm_notifier guarantee that the notifier completed before calling the driver suspend, or am I missing something?
Signature · 1 line
Luiz Augusto von Dentz
Re: [PATCH] Bluetooth: btusb: cancel pending HCI commands before USB suspend
Hi Luiz,
Thank you for the quick and thorough feedback.
You're right that HCI_QUIRK_NO_SUSPEND_NOTIFIER is not set for Intel, so hci_suspend_dev() should be running and completing before btusb_suspend(). I missed that the PM notifier ordering guarantees this.
Looking at the logs again more carefully, the error message is specifically "Error when powering off device on rfkill (-19)" which points to the hci_rfkill_set_block() -> hci_dev_do_poweroff() path, not the PM notifier's hci_suspend_sync(). So you're right that something in userspace appears to be triggering rfkill to power off bluetooth around the same time as system suspend.
I had a custom systemd user service running that did "rfkill block bluetooth" followed by "rfkill unblock bluetooth" on resume, which was an earlier workaround attempt. That rfkill block could have been racing with USB suspend. I've since removed it and will test a few suspend/resume cycles without it to see if the issue still reproduces.
I'll report back with results. If the issue persists without the rfkill workaround, I'll capture btmon traces and dmesg with more detail around the suspend path.
Thanks,
Frederik
Quoted 69 lines · Luiz Augusto von Dentz
Hi Frederik,
Quoted 48 lines · Frederik Berg
During system suspend, the PM notifier and USB subsystem suspend run concurrently without synchronization. If the PM notifier's
hci_power_off_sync()is blocked waiting for an HCI command response (e.g., Write Scan Enable, opcode0x0c1a) when the USB subsystem tears down the device, the command fails with-ENODEV.Unlike a timeout (
-ETIMEDOUT), an ENODEV cancellation does not triggerhci_cmd_timeout(), which meanshdev->reset()is never called and the Intel ACPI reset method (_PRR/_RST) that would recover the device is bypassed. The device then fails to re-enumerate on resume (detected as low-speed instead of full-speed, error -71) and is permanently lost until the xHCI host controller is reset or the system is rebooted.Cancel any pending synchronous HCI commands in
btusb_suspend()beforebtusb_stop_traffic()kills the URBs, but only for non-autosuspend (system suspend). This matches the pattern used byhci_suspend_dev()which callshci_cancel_cmd_sync(hdev, EHOSTDOWN)before proceeding with HCI-level suspend.Signed-off-by Frederik Berg <[email protected]>---
Proposed fix for the race described in the parent email. This cancels any pending synchronous HCI commands inbtusb_suspend()beforebtusb_stop_traffic()kills the URBs, preventing the race. Only for system suspend, not autosuspend. Same pattern used byhci_suspend_dev()which callshci_cancel_cmd_sync(hdev, EHOSTDOWN).I haven't been able to build-test this against a running kernel yet, so consider this an RFC.
drivers/bluetooth/btusb.c | 3 +++ 1 file changed, 3 insertions(+)drivers/bluetooth/btusb.c +3
-1@@ -4497,6 +4497,9 @@ static int btusb_suspend(struct usb_interface *intf, pm_message_t message)cancel_work_sync (&data->work); +if (!PMSG_IS_AUTO (message)) +hci_cmd_sync_cancel_sync (data->hdev,EHOSTDOWN ); +if (data->suspend) data->suspend (data->hdev); --Quoted 1 line
2.53.0
Have to agree with a few points over here:
https://sashiko.dev/#/patchset/20260320114347.2340528-1-fberg%40posteo.de
Specially the first point: if
hci_suspend_sync(which should be pending nothci_power_off_sync) had run, then there shouldn't be anything to cancel atbtusb_suspendand hdev should be suspended. Perhaps something is trying to power off bluetooth (e.g. userspace)? Anywayhci_suspend_devdoes already performhci_cmd_sync_cancel_sync(data->hdev, EHOSTDOWN); or do you haveHCI_QUIRK_NO_SUSPEND_NOTIFIERset for it, which is why it doesn't run?The other option would be to call
hci_suspend_devdirectly from the driver, but then again theregister_pm_notifierguarantee that the notifier completed before calling the driver suspend, or am I missing something?
RE: Bluetooth: btusb: cancel pending HCI commands before USB suspend
In reply to Frederik BergThis is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1069868
---Test result---
Test Summary:
CheckPatch PENDING 0.38 seconds GitLint PENDING 0.27 seconds SubjectPrefix PASS 0.12 seconds BuildKernel PASS 25.39 seconds CheckAllWarning PASS 26.92 seconds CheckSparse PASS 26.22 seconds BuildKernel32 PASS 24.53 seconds TestRunnerSetup PASS 524.06 seconds TestRunner_l2cap-tester PASS 27.36 seconds TestRunner_iso-tester PASS 37.43 seconds TestRunner_bnep-tester PASS 6.33 seconds TestRunner_mgmt-tester FAIL 111.35 seconds TestRunner_rfcomm-tester PASS 9.32 seconds TestRunner_sco-tester FAIL 14.09 seconds TestRunner_ioctl-tester PASS 13.29 seconds TestRunner_mesh-tester FAIL 11.62 seconds TestRunner_smp-tester PASS 8.60 seconds TestRunner_userchan-tester PASS 6.64 seconds TestRunner_6lowpan-tester FAIL 8.78 seconds IncrementalBuild PENDING 0.27 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner Output:
Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4
Failed Test Cases
Read Exp Feature - Success Failed 0.103 seconds
##############################
Test: TestRunner_sco-tester - FAIL
Desc: Run sco-tester with test-runner
Output:
WARNING: possible circular locking dependency detected
7.0.0-rc2-gc1ac32606e7b #1 Not tainted
------------------------------------------------------
kworker/u5:2/117 is trying to acquire lock:ffff888001abe240 (sk_lock-AF_BLUETOOTH-BTPROTO_SCO){+.+.}-{0:0}, at: sco_connect_cfm+0x358/0x8d0
but task is already holding lock:ffff888002090c20 (&conn->lock){+.+.}-{3:3}, at: sco_connect_cfm+0x22d/0x8d0
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (&conn->lock){+.+.}-{3:3}:
lock_acquire+0xf7/0x2c0
_raw_spin_lock+0x2a/0x40
sco_sock_connect+0x4d7/0x1280
__sys_connect+0x1a3/0x260
__x64_sys_connect+0x6e/0xb0
do_syscall_64+0xa0/0x570
entry_SYSCALL_64_after_hwframe+0x74/0x7c-> #0 (sk_lock-AF_BLUETOOTH-BTPROTO_SCO){+.+.}-{0:0}:
check_prev_add+0xe9/0xc70
__lock_acquire+0x1457/0x1df0
lock_acquire+0xf7/0x2c0
lock_sock_nested+0x36/0xd0
sco_connect_cfm+0x358/0x8d0
hci_sync_conn_complete_evt+0x3d3/0x8e0
hci_event_packet+0x74f/0xb10
hci_rx_work+0x398/0xd00
process_scheduled_works+0xb16/0x1ac0
worker_thread+0x4ff/0xba0
kthread+0x368/0x490
ret_from_fork+0x498/0x7e0
ret_from_fork_asm+0x19/0x30other info that might help us debug this:
...
BUG: sleeping function called from invalid context at net/core/sock.c:3782
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 117, name: kworker/u5:2preempt_count: 1, expected: 0
RCU nest depth: 0, expected: 0
INFO: lockdep is turned off.
CPU: 0 UID: 0 PID: 117 Comm: kworker/u5:2 Not tainted 7.0.0-rc2-gc1ac32606e7b #1 PREEMPT(lazy) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014 Workqueue: hci0 hci_rx_work Call Trace: <TASK> dump_stack_lvl+0x49/0x60 __might_resched+0x2ea/0x500 lock_sock_nested+0x47/0xd0 ? sco_connect_cfm+0x358/0x8d0 sco_connect_cfm+0x358/0x8d0 ? hci_debugfs_create_conn+0x190/0x210 ? __pfx_sco_connect_cfm+0x10/0x10 hci_sync_conn_complete_evt+0x3d3/0x8e0 hci_event_packet+0x74f/0xb10 ? __pfx_hci_sync_conn_complete_evt+0x10/0x10 ? __pfx_hci_event_packet+0x10/0x10 ? mark_held_locks+0x49/0x80 ? lockdep_hardirqs_on_prepare+0xd4/0x180 ? _raw_spin_unlock_irqrestore+0x2c/0x50 hci_rx_work+0x398/0xd00 process_scheduled_works+0xb16/0x1ac0 ? __pfx_process_scheduled_works+0x10/0x10 ? lock_acquire+0xf7/0x2c0 ? lock_is_held_type+0x9b/0x110 ? __pfx_hci_rx_work+0x10/0x10 worker_thread+0x4ff/0xba0 ? _raw_spin_unlock_irqrestore+0x2c/0x50 ? __pfx_worker_thread+0x10/0x10 kthread+0x368/0x490 ? _raw_spin_unlock_irq+0x23/0x40 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x498/0x7e0 ? __pfx_ret_from_fork+0x10/0x10 ? __switch_to+0x9e4/0xe50 ? __switch_to_asm+0x32/0x60
...
Total: 30, Passed: 30 (100.0%), Failed: 0, Not Run: 0
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0
Failed Test Cases
Mesh - Send cancel - 1 Timed out 2.003 seconds Mesh - Send cancel - 2 Timed out 1.995 seconds
##############################
Test: TestRunner_6lowpan-tester - FAIL
Desc: Run 6lowpan-tester with test-runner
Output:
WARNING: possible circular locking dependency detected 7.0.0-rc2-gc1ac32606e7b #1 Not tainted
------------------------------------------------------
kworker/0:1/11 is trying to acquire lock:ffff88800277f140 ((wq_completion)hci0#2){+.+.}-{0:0}, at: touch_wq_lockdep_map+0x75/0x180
but task is already holding lock:ffffffff90e4d720 (rtnl_mutex){+.+.}-{4:4}, at: lowpan_unregister_netdev+0xd/0x30
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #4 (rtnl_mutex){+.+.}-{4:4}:
lock_acquire+0xf7/0x2c0
__mutex_lock+0x16b/0x1fc0
lowpan_register_netdev+0x11/0x30
chan_ready_cb+0x836/0xd00
l2cap_recv_frame+0x6a06/0x8920
l2cap_recv_acldata+0x790/0xdf0
hci_rx_work+0x500/0xd00
process_scheduled_works+0xb16/0x1ac0
worker_thread+0x4ff/0xba0
kthread+0x368/0x490
ret_from_fork+0x498/0x7e0
ret_from_fork_asm+0x19/0x30-> #3 (&chan->lock#3/1){+.+.}-{4:4}:
lock_acquire+0xf7/0x2c0
__mutex_lock+0x16b/0x1fc0
l2cap_chan_connect+0x74e/0x1980
lowpan_control_write+0x523/0x660
full_proxy_write+0x10b/0x190
vfs_write+0x1c0/0xf60
ksys_write+0xf1/0x1d0
do_syscall_64+0xa0/0x570
entry_SYSCALL_64_after_hwframe+0x74/0x7c-> #2 (&conn->lock){+.+.}-{4:4}:
...
Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:
https://github.com/bluez/bluetooth-next/pull/26/checks
---
Regards,
Linux Bluetooth