Skip to contentSkip to conversation

Bluetooth: hci_sync: invoke destroy callbacks outside lock

PATCH Applied Zheng Shuhao 3 participants 3 messages Nov 21 – Nov 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: hci_sync: invoke destroy callbacks outside lock

hci_cmd_sync_clear() cancels queued command-sync entries while holding cmd_sync_work_lock. Cancellation invokes entry->destroy(), and add_ext_adv_params_complete() takes hdev->lock. In the opposite direction, le_conn_complete_evt() holds hdev->lock while hci_update_passive_scan() queues work and acquires cmd_sync_work_lock. This creates the circular locking dependency reported by lockdep during controller teardown.

Detach the queued entries to a local list under cmd_sync_work_lock, then run the cancellation callbacks after releasing the mutex. This keeps queue updates serialized without invoking callbacks under the mutex.

Testing:
- Lockdep-enabled QEMU baseline: reproducer completed twice and emitted the circular-locking warning once.
- Patched QEMU kernel: reproducer completed five times with no such warning.
- Bluetooth ECDH and SMP self-tests passed in both kernels.
- Both kernels built; baseline build logged a timestamp clock-skew warning. checkpatch.pl --strict reported no errors or warnings.

Fixes 1c66bee492a5 ("Bluetooth: Fix race condition in hci_cmd_sync_clear")
Reported-by [email protected]
net/bluetooth/hci_sync.c +6 -2
index ea2014e74..65b8aa4ad 100644
@@ -683,6 +683,7 @@ static void _hci_cmd_sync_cancel_entry(struct hci_dev *hdev,
 
 void hci_cmd_sync_clear(struct hci_dev *hdev)
 {
+	LIST_HEAD(cancel_list);
 	struct hci_cmd_sync_work_entry *entry, *tmp;
 
 	/* cmd_work is disabled, the pending request can only time out */
@@ -690,10 +691,13 @@ void hci_cmd_sync_clear(struct hci_dev *hdev)
 	cancel_work_sync(&hdev->cmd_sync_work);
 	cancel_work_sync(&hdev->reenable_adv_work);
 
+	/* Run destroy callbacks without holding cmd_sync_work_lock. */
 	mutex_lock(&hdev->cmd_sync_work_lock);
-	list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list)
-		_hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED);
+	list_splice_init(&hdev->cmd_sync_work_list, &cancel_list);
 	mutex_unlock(&hdev->cmd_sync_work_lock);
+
+	list_for_each_entry_safe(entry, tmp, &cancel_list, list)
+		_hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED);
 }
 
 void hci_cmd_sync_cancel(struct hci_dev *hdev, int err)
#1 lore raw

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/series/1218076/

---Test result---

Test Summary:

CheckPatch                    PASS      0.61 seconds
VerifyFixes                   PASS      0.07 seconds
VerifySignedoff               PASS      0.07 seconds
GitLint                       PASS      0.23 seconds
SubjectPrefix                 PASS      0.07 seconds
BuildKernel                   PASS      31.62 seconds
CheckAllWarning               PASS      35.35 seconds
CheckSparse                   PASS      39.02 seconds
BuildKernel32                 PASS      32.20 seconds
CheckKernelLLVM               PASS      35.33 seconds
TestRunnerSetup               PASS      767.08 seconds
TestRunner_l2cap-tester       PASS      14.71 seconds
TestRunner_iso-tester         PASS      13.21 seconds
TestRunner_bnep-tester        PASS      3.12 seconds
TestRunner_mgmt-tester        PASS      88.95 seconds
TestRunner_rfcomm-tester      PASS      4.48 seconds
TestRunner_sco-tester         PASS      5.60 seconds
TestRunner_ioctl-tester       PASS      4.59 seconds
TestRunner_mesh-tester        PASS      4.49 seconds
TestRunner_smp-tester         PASS      4.30 seconds
TestRunner_userchan-tester    PASS      3.18 seconds
TestRunner_6lowpan-tester     PASS      4.48 seconds
IncrementalBuild              PASS      29.72 seconds

https://github.com/bluez/bluetooth-next/pull/1176

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Zheng Shuhao
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 8 lines · On Sat, 21 Nov 2026 20:01:20 +0800 you wrote:

hci_cmd_sync_clear() cancels queued command-sync entries while holding cmd_sync_work_lock. Cancellation invokes entry->destroy(), and add_ext_adv_params_complete() takes hdev->lock. In the opposite direction, le_conn_complete_evt() holds hdev->lock while hci_update_passive_scan() queues work and acquires cmd_sync_work_lock. This creates the circular locking dependency reported by lockdep during controller teardown.

[...]

Here is the summary with links:
- Bluetooth: hci_sync: invoke destroy callbacks outside lock

    https://git.kernel.org/bluetooth/bluetooth-next/c/f99caa0d2467

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html