Bluetooth: hci_sync: Cancel cmd_timer before draining workqueue
Subsystems (2)
PATCH 1/1 Bluetooth: hci_sync: Cancel cmd_timer before draining workqueue
cmd_timer can expire while hdev->workqueue is being drained, causing hci_cmd_timeout to be queued on a draining workqueue.
Cancel cmd_timer before draining the workqueue.
--- net/bluetooth/hci_sync.c | 2 ++ 1 file changed, 2 insertions(+)
net/bluetooth/hci_sync.c +2 -0
@@ -5545,6 +5545,8 @@ int hci_dev_close_sync(struct hci_dev *hdev)*/ hci_dev_set_flag (hdev,HCI_CMD_DRAIN_WORKQUEUE );synchronize_rcu (); +/* Explicitly cancel works in case scheduled after setting the flag. */ +cancel_delayed_work_sync (&hdev->cmd_timer);if (hci_dev_test_flag (hdev,HCI_UNREGISTER )) {disable_delayed_work (&hdev->power_off);
Signature · 1 line
2.43.0
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/1178060/
---Test result---
Test Summary:
CheckPatch PASS 0.77 seconds VerifyFixes PASS 0.14 seconds VerifySignedoff PASS 0.14 seconds GitLint PASS 0.35 seconds SubjectPrefix PASS 0.13 seconds BuildKernel PASS 29.13 seconds CheckAllWarning PASS 33.26 seconds CheckSparse PASS 35.57 seconds BuildKernel32 PASS 29.02 seconds CheckKernelLLVM PASS 32.88 seconds TestRunnerSetup PASS 780.92 seconds TestRunner_l2cap-tester PASS 12.76 seconds TestRunner_iso-tester PASS 18.75 seconds TestRunner_bnep-tester PASS 3.13 seconds TestRunner_mgmt-tester FAIL 61.09 seconds TestRunner_rfcomm-tester PASS 4.48 seconds TestRunner_sco-tester PASS 5.55 seconds TestRunner_ioctl-tester PASS 4.63 seconds TestRunner_mesh-tester FAIL 7.82 seconds TestRunner_smp-tester PASS 4.33 seconds TestRunner_userchan-tester PASS 3.19 seconds TestRunner_6lowpan-tester PASS 4.40 seconds IncrementalBuild PASS 26.94 seconds
Details
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner Output:
Total: 503, Passed: 502 (99.8%), Failed: 1, Not Run: 0
Failed Test Cases
Pairing Acceptor - LE Security Level Changed Failed 0.026 seconds
##############################
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.418 seconds Mesh - Send cancel - 2 Timed out 2.000 seconds
https://github.com/bluez/bluetooth-next/pull/850
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerHi Rabindra,
Quoted 20 lines · On Fri, Oct 2, 2026 at 12:48 AM rabindra789 <[email protected]> wrote:
cmd_timercan expire whilehdev->workqueueis being drained, causinghci_cmd_timeoutto be queued on a draining workqueue.Cancel
cmd_timerbefore draining the workqueue.Reported-by [email protected]Fixes 40b87657200c ("Bluetooth: hci_core: Rework hci_dev_do_reset() to use hci_sync functions")Signed-off-by rabindra789 <[email protected]>--- net/bluetooth/hci_sync.c | 2 ++ 1 file changed, 2 insertions(+)net/bluetooth/hci_sync.c +0
-0
net/bluetooth/hci_sync.c int hci_dev_close_sync(struct hci_dev *hdev) · line 5549
Quoted 5 lines
net/bluetooth/hci_sync.c +2
-0@@ -5545,6 +5545,8 @@ int hci_dev_close_sync(struct hci_dev *hdev)*/ hci_dev_set_flag (hdev,HCI_CMD_DRAIN_WORKQUEUE );synchronize_rcu (); +/* Explicitly cancel works in case scheduled after setting the flag. */ +cancel_delayed_work_sync (&hdev->cmd_timer);
I'm not following here. If a command is outstanding and times out while we are draining the queue that should be flagged. Or perhaps the problem is that hci_cmd_sync_cancel_sync don't actually behave like hci_cmd_sync_cancel which clears the cmd_timer whenever it cancels the cmd_sync work:
static void hci_cmd_sync_cancel_work(struct work_struct *work) {
struct hci_dev *hdev = container_of(work, struct hci_dev,cmd_sync_cancel_work);
cancel_delayed_work_sync(&hdev->cmd_timer);
cancel_delayed_work_sync(&hdev->ncmd_timer);
atomic_set(&hdev->cmd_cnt, 1);
wake_up_interruptible(&hdev->req_wait_q);
}Quoted 5 lines
net/bluetooth/hci_sync.c +0
-1if (hci_dev_test_flag (hdev,HCI_UNREGISTER )) {disable_delayed_work (&hdev->power_off); --2.43.0
Signature · 1 line
Luiz Augusto von Dentz
Luiz Augusto von Dentz
maintainerHi,
Quoted 41 lines · Luiz Augusto von Dentz
Hi Rabindra,
Quoted 20 lines · On Fri, Oct 2, 2026 at 12:48 AM rabindra789 <[email protected]> wrote:
cmd_timercan expire whilehdev->workqueueis being drained, causinghci_cmd_timeoutto be queued on a draining workqueue.Cancel
cmd_timerbefore draining the workqueue.Reported-by [email protected]Fixes 40b87657200c ("Bluetooth: hci_core: Rework hci_dev_do_reset() to use hci_sync functions")Signed-off-by rabindra789 <[email protected]>--- net/bluetooth/hci_sync.c | 2 ++ 1 file changed, 2 insertions(+)net/bluetooth/hci_sync.c +0
-0net/bluetooth/hci_sync.c int hci_dev_close_sync(struct hci_dev *hdev) · line 5549
Quoted 5 lines
net/bluetooth/hci_sync.c +2
-0@@ -5545,6 +5545,8 @@ int hci_dev_close_sync(struct hci_dev *hdev)*/ hci_dev_set_flag (hdev,HCI_CMD_DRAIN_WORKQUEUE );synchronize_rcu (); +/* Explicitly cancel works in case scheduled after setting the flag. */ +cancel_delayed_work_sync (&hdev->cmd_timer);I'm not following here. If a command is outstanding and times out while we are draining the queue that should be flagged. Or perhaps the problem is that
hci_cmd_sync_cancel_syncdon't actually behave likehci_cmd_sync_cancelwhich clears thecmd_timerwhenever it cancels thecmd_syncwork:static void
hci_cmd_sync_cancel_work(struct work_struct *work){
structhci_dev*hdev = container_of(work, structhci_dev,cmd_sync_cancel_work);
Quoted 6 lines
cancel_delayed_work_sync(&hdev->cmd_timer);
cancel_delayed_work_sync(&hdev->ncmd_timer);
atomic_set(&hdev->cmd_cnt, 1);
wake_up_interruptible(&hdev->req_wait_q);
}Maybe something like the following:
net/bluetooth/hci_sync.c +0 -0
@@ -702,6 +702,12 @@ void hci_cmd_sync_cancel_sync(struct hci_dev
*hdev, int err)
hdev->req_result = err < 0 ? -err : err;
WRITE_ONCE(hdev->req_status, HCI_REQ_CANCELED);+ if (!hci_dev_test_flag(hdev, HCI_UNREGISTER)) {
+ cancel_delayed_work_sync(&hdev->cmd_timer);
+ cancel_delayed_work_sync(&hdev->ncmd_timer);
+ atomic_set(&hdev->cmd_cnt, 1);
+ }
+
wake_up_interruptible(&hdev->req_wait_q);
}}
Quoted 9 lines
Quoted 5 lines
net/bluetooth/hci_sync.c +0
-1if (hci_dev_test_flag (hdev,HCI_UNREGISTER )) {disable_delayed_work (&hdev->power_off); --2.43.0
--
Luiz Augusto von Dentz
Signature · 1 line
Luiz Augusto von Dentz
A message that is not in the archive (sent off-list or not yet received): CAOa02aN_YgSB7L6eG-+Og3dx103kZpoRy1Ho27aMvo2dsoQCVw@mail.gmail.com
Hi Luiz,
Thanks, I checked the reported path again. And the warning is from a cmd_timer already armed before hci_dev_close_sync(). The re-arm path is already blocked by HCI_CMD_DRAIN_WORKQUEUE + synchronize_rcu(). I think cmd_timer still needs to be canceled before drain_workqueue(). Moving cancel_delayed_work_sync() into hci_cmd_sync_cancel_sync() would make hci_cmd_timeout() synchronouslly cancel its own cmd_timer. Also, in the reported path req_status has already been reset to 0 before hci_dev_close_sync() calls hci_cmd_sync_cancel_sync(), so the HCI_REQ_PEND casewould not cover this warning.
Thanks,
Rabindra
Quoted 103 lines · Rabindra Kumar Meher
Hi Luiz,
Thanks, I checked the reported path again. And the warning is from a
cmd_timeralready armed beforehci_dev_close_sync(). The re-arm path is already blocked byHCI_CMD_DRAIN_WORKQUEUE+synchronize_rcu().
I thinkcmd_timerstill needs to be canceled beforedrain_workqueue(). Movingcancel_delayed_work_sync()intohci_cmd_sync_cancel_sync()would makehci_cmd_timeout()synchronousllly cancel its owncmd_timer. Also, in the reported pathreq_statushas already been reset to 0 beforehci_dev_close_sync()callshci_cmd_sync_cancel_sync()so theHCI_REQ_PENDcase would not cover this warning.Thanks,
RabindraQuoted 81 lines · Luiz Augusto von Dentz
Hi,
Quoted 41 lines · Luiz Augusto von Dentz
Hi Rabindra,
Quoted 20 lines · On Fri, Oct 2, 2026 at 12:48 AM rabindra789 <[email protected]> wrote:
cmd_timercan expire whilehdev->workqueueis being drained, causinghci_cmd_timeoutto be queued on a draining workqueue.Cancel
cmd_timerbefore draining the workqueue.Reported-by [email protected]Fixes 40b87657200c ("Bluetooth: hci_core: Rework hci_dev_do_reset() to use hci_sync functions")Signed-off-by rabindra789 <[email protected]>--- net/bluetooth/hci_sync.c | 2 ++ 1 file changed, 2 insertions(+)net/bluetooth/hci_sync.c +0
-0net/bluetooth/hci_sync.c int hci_dev_close_sync(struct hci_dev *hdev) · line 5549
Quoted 5 lines
net/bluetooth/hci_sync.c +2
-0@@ -5545,6 +5545,8 @@ int hci_dev_close_sync(struct hci_dev *hdev)*/ hci_dev_set_flag (hdev,HCI_CMD_DRAIN_WORKQUEUE );synchronize_rcu (); +/* Explicitly cancel works in case scheduled after setting the flag. */ +cancel_delayed_work_sync (&hdev->cmd_timer);I'm not following here. If a command is outstanding and times out while we are draining the queue that should be flagged. Or perhaps the problem is that
hci_cmd_sync_cancel_syncdon't actually behave likehci_cmd_sync_cancelwhich clears thecmd_timerwhenever it cancels thecmd_syncwork:static void
hci_cmd_sync_cancel_work(struct work_struct *work){
structhci_dev*hdev = container_of(work, structhci_dev,cmd_sync_cancel_work);Quoted 6 lines
cancel_delayed_work_sync(&hdev->cmd_timer); cancel_delayed_work_sync(&hdev->ncmd_timer); atomic_set(&hdev->cmd_cnt, 1); wake_up_interruptible(&hdev->req_wait_q); }Maybe something like the following:
net/bluetooth/hci_sync.c +6
-0@@ -702,6 +702,12 @@ void hci_cmd_sync_cancel_sync(struct hci_dev *hdev, int err) hdev->req_result = err <0 ? -err : err;WRITE_ONCE (hdev->req_status,HCI_REQ_CANCELED ); +if (!hci_dev_test_flag (hdev,HCI_UNREGISTER )) { +cancel_delayed_work_sync (&hdev->cmd_timer); +cancel_delayed_work_sync (&hdev->ncmd_timer); +atomic_set (&hdev->cmd_cnt,1 ); + } +wake_up_interruptible (&hdev->req_wait_q); }}
Quoted 7 lines
Quoted 5 lines
net/bluetooth/hci_sync.c +0
-1if (hci_dev_test_flag (hdev,HCI_UNREGISTER )) {disable_delayed_work (&hdev->power_off); --2.43.0
Quoted 7 lines
Quoted 2 lines
--
Luiz Augusto von Dentz--
Luiz Augusto von Dentz--
Rabindra Kumar Meher
Signature · 1 line
Rabindra Kumar Meher