* [PATCH v2 1/3] Bluetooth: hci_core: Rework hci_dev_do_reset() to use hci_sync functions
2026-05-26 13:50 [PATCH v2 0/3] Bluetooth: hci_core: Refactor HCI reset functions Heitor Alves de Siqueira
@ 2026-05-26 13:50 ` Heitor Alves de Siqueira
2026-05-26 13:50 ` [PATCH v2 2/3] Bluetooth: hci_sync: Set HCI_CMD_DRAIN_WORKQUEUE during device close Heitor Alves de Siqueira
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Heitor Alves de Siqueira @ 2026-05-26 13:50 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz, Gustavo Padovan, Schspa Shi
Cc: linux-bluetooth, linux-kernel, kernel-dev,
Heitor Alves de Siqueira, Luiz Augusto von Dentz
The current HCI reset function in hci_core.c duplicates most of the work
done by hci_dev_close_sync(), and doesn't handle LE, advertising or
discovery.
Instead of porting these to hci_dev_do_reset(), directly call the
close/open functions from hci_sync to reset the hdev. MGMT now notifies
when a user performs a reset.
Suggested-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Signed-off-by: Heitor Alves de Siqueira <halves@igalia.com>
---
net/bluetooth/hci_core.c | 43 +++----------------------------------------
1 file changed, 3 insertions(+), 40 deletions(-)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index c46c1236ebfa..28d7929dc593 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -539,46 +539,9 @@ static int hci_dev_do_reset(struct hci_dev *hdev)
hci_req_sync_lock(hdev);
- /* Drop queues */
- skb_queue_purge(&hdev->rx_q);
- skb_queue_purge(&hdev->cmd_q);
-
- /* Cancel these to avoid queueing non-chained pending work */
- hci_dev_set_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE);
- /* Wait for
- *
- * if (!hci_dev_test_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE))
- * queue_delayed_work(&hdev->{cmd,ncmd}_timer)
- *
- * inside RCU section to see the flag or complete scheduling.
- */
- synchronize_rcu();
- /* Explicitly cancel works in case scheduled after setting the flag. */
- cancel_delayed_work(&hdev->cmd_timer);
- cancel_delayed_work(&hdev->ncmd_timer);
-
- /* Avoid potential lockdep warnings from the *_flush() calls by
- * ensuring the workqueue is empty up front.
- */
- drain_workqueue(hdev->workqueue);
-
- hci_dev_lock(hdev);
- hci_inquiry_cache_flush(hdev);
- hci_conn_hash_flush(hdev);
- hci_dev_unlock(hdev);
-
- if (hdev->flush)
- hdev->flush(hdev);
-
- hci_dev_clear_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE);
-
- atomic_set(&hdev->cmd_cnt, 1);
- hdev->acl_cnt = 0;
- hdev->sco_cnt = 0;
- hdev->le_cnt = 0;
- hdev->iso_cnt = 0;
-
- ret = hci_reset_sync(hdev);
+ ret = hci_dev_close_sync(hdev);
+ if (!ret)
+ ret = hci_dev_open_sync(hdev);
hci_req_sync_unlock(hdev);
return ret;
--
2.54.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 2/3] Bluetooth: hci_sync: Set HCI_CMD_DRAIN_WORKQUEUE during device close
2026-05-26 13:50 [PATCH v2 0/3] Bluetooth: hci_core: Refactor HCI reset functions Heitor Alves de Siqueira
2026-05-26 13:50 ` [PATCH v2 1/3] Bluetooth: hci_core: Rework hci_dev_do_reset() to use hci_sync functions Heitor Alves de Siqueira
@ 2026-05-26 13:50 ` Heitor Alves de Siqueira
2026-05-26 13:50 ` [PATCH v2 3/3] Bluetooth: hci_sync: Reset device counters in hci_dev_close_sync() Heitor Alves de Siqueira
2026-05-27 20:50 ` [PATCH v2 0/3] Bluetooth: hci_core: Refactor HCI reset functions patchwork-bot+bluetooth
3 siblings, 0 replies; 5+ messages in thread
From: Heitor Alves de Siqueira @ 2026-05-26 13:50 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz, Gustavo Padovan, Schspa Shi
Cc: linux-bluetooth, linux-kernel, kernel-dev,
Heitor Alves de Siqueira, Luiz Augusto von Dentz
Since hci_dev_close_sync() can now be called during the reset path, we
should also set HCI_CMD_DRAIN_WORKQUEUE. This avoids queuing timeouts
while the hdev workqueue is being drained.
Fixes: 877afadad2dc ("Bluetooth: When HCI work queue is drained, only queue chained work")
Signed-off-by: Heitor Alves de Siqueira <halves@igalia.com>
---
net/bluetooth/hci_sync.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index fd3aacdea512..84d8f457c799 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -5298,6 +5298,12 @@ int hci_dev_close_sync(struct hci_dev *hdev)
bt_dev_dbg(hdev, "");
+ /* Set HCI_DRAIN_WORKQUEUE flag to prevent queuing work during
+ * reset/close. See hci_cmd_work() and handle_cmd_cnt_and_timer().
+ */
+ hci_dev_set_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE);
+ synchronize_rcu();
+
if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) {
disable_delayed_work(&hdev->power_off);
disable_delayed_work(&hdev->ncmd_timer);
@@ -5321,6 +5327,7 @@ int hci_dev_close_sync(struct hci_dev *hdev)
if (!test_and_clear_bit(HCI_UP, &hdev->flags)) {
cancel_delayed_work_sync(&hdev->cmd_timer);
+ hci_dev_clear_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE);
return err;
}
@@ -5420,6 +5427,7 @@ int hci_dev_close_sync(struct hci_dev *hdev)
/* Clear flags */
hdev->flags &= BIT(HCI_RAW);
hci_dev_clear_volatile_flags(hdev);
+ hci_dev_clear_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE);
memset(hdev->eir, 0, sizeof(hdev->eir));
memset(hdev->dev_class, 0, sizeof(hdev->dev_class));
--
2.54.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 3/3] Bluetooth: hci_sync: Reset device counters in hci_dev_close_sync()
2026-05-26 13:50 [PATCH v2 0/3] Bluetooth: hci_core: Refactor HCI reset functions Heitor Alves de Siqueira
2026-05-26 13:50 ` [PATCH v2 1/3] Bluetooth: hci_core: Rework hci_dev_do_reset() to use hci_sync functions Heitor Alves de Siqueira
2026-05-26 13:50 ` [PATCH v2 2/3] Bluetooth: hci_sync: Set HCI_CMD_DRAIN_WORKQUEUE during device close Heitor Alves de Siqueira
@ 2026-05-26 13:50 ` Heitor Alves de Siqueira
2026-05-27 20:50 ` [PATCH v2 0/3] Bluetooth: hci_core: Refactor HCI reset functions patchwork-bot+bluetooth
3 siblings, 0 replies; 5+ messages in thread
From: Heitor Alves de Siqueira @ 2026-05-26 13:50 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz, Gustavo Padovan, Schspa Shi
Cc: linux-bluetooth, linux-kernel, kernel-dev,
Heitor Alves de Siqueira, Luiz Augusto von Dentz
Before resetting or closing the device, protocol counters should also be
zeroed.
Fixes: d0b137062b2d ("Bluetooth: hci_sync: Rework init stages")
Signed-off-by: Heitor Alves de Siqueira <halves@igalia.com>
---
net/bluetooth/hci_sync.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 84d8f457c799..c11d5a1f2dba 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -5390,6 +5390,10 @@ int hci_dev_close_sync(struct hci_dev *hdev)
/* Reset device */
skb_queue_purge(&hdev->cmd_q);
atomic_set(&hdev->cmd_cnt, 1);
+ hdev->acl_cnt = 0;
+ hdev->sco_cnt = 0;
+ hdev->le_cnt = 0;
+ hdev->iso_cnt = 0;
if (hci_test_quirk(hdev, HCI_QUIRK_RESET_ON_CLOSE) &&
!auto_off && !hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) {
set_bit(HCI_INIT, &hdev->flags);
--
2.54.0
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2 0/3] Bluetooth: hci_core: Refactor HCI reset functions
2026-05-26 13:50 [PATCH v2 0/3] Bluetooth: hci_core: Refactor HCI reset functions Heitor Alves de Siqueira
` (2 preceding siblings ...)
2026-05-26 13:50 ` [PATCH v2 3/3] Bluetooth: hci_sync: Reset device counters in hci_dev_close_sync() Heitor Alves de Siqueira
@ 2026-05-27 20:50 ` patchwork-bot+bluetooth
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+bluetooth @ 2026-05-27 20:50 UTC (permalink / raw)
To: Heitor Alves de Siqueira
Cc: marcel, luiz.dentz, padovan, schspa, linux-bluetooth,
linux-kernel, kernel-dev, luiz.von.dentz
Hello:
This series was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Tue, 26 May 2026 10:50:56 -0300 you wrote:
> Dear maintainers,
>
> While investigating some warnings reported by syzbot on the hdev
> workqueue, Luiz kindly mentioned the possibility of reworking the reset
> functions in hci_core. A lot of the work done "manually" in
> hci_dev_do_reset() is already handled by the close/open functions in
> hci_sync, and those also handle missing functionality related to LE,
> discovery and advertising.
>
> [...]
Here is the summary with links:
- [v2,1/3] Bluetooth: hci_core: Rework hci_dev_do_reset() to use hci_sync functions
https://git.kernel.org/bluetooth/bluetooth-next/c/54f93846b7a8
- [v2,2/3] Bluetooth: hci_sync: Set HCI_CMD_DRAIN_WORKQUEUE during device close
https://git.kernel.org/bluetooth/bluetooth-next/c/db6e813f5789
- [v2,3/3] Bluetooth: hci_sync: Reset device counters in hci_dev_close_sync()
https://git.kernel.org/bluetooth/bluetooth-next/c/a92f90568cc9
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread