Skip to content

Commit 38bd9d0

Browse files
committed
wip
1 parent dd92865 commit 38bd9d0

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

subsys/bluetooth/host/hci_core.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,34 @@ int bt_hci_cmd_send_sync(uint16_t opcode, struct net_buf *buf,
471471
return err;
472472
}
473473

474-
/* TODO: disallow sending sync commands from syswq altogether */
474+
if (k_current_get() == &bt_taskq_chosen->thread) {
475+
struct net_buf *cmd;
475476

476-
/* Since the commands are now processed in the syswq, we cannot suspend
477-
* and wait. We have to send the command from the current context.
478-
*/
479-
if (!IS_ENABLED(CONFIG_BT_TASKQ_DEDICATED) && k_current_get() == &k_sys_work_q.thread) {
480-
/* drain the command queue until we get to send the command of interest. */
481-
struct net_buf *cmd = NULL;
477+
/* We are on the same thread where commands are processed and would
478+
* deadlock.
479+
*
480+
* We will immediately process commands until our command is processed
481+
* and we can return.
482+
*
483+
* This code path exists to resolve deadlocks when
484+
* CONFIG_BT_TASKQ_SYSTEM_WORKQUEUE is enabled. This does not always
485+
* work, especially if CONFIG_BT_RECV_WORKQ_SYS is also enabled.
486+
*
487+
* Another downside is that there has to be enough stack space left in
488+
* the current thread to do so or we will overflow.
489+
*/
490+
491+
if (IS_ENABLED(CONFIG_BT_TASKQ_DEDICATED)) {
492+
/* Dedicated bt_taskq should not invoke bt_hci_cmd_send_sync() or other
493+
* blocking commands.
494+
*
495+
* If you see this warning, please send us a stack trace.
496+
*/
497+
LOG_WRN_ONCE("bt_workq missuse");
498+
if (1 || IS_ENABLED(CONFIG_TEST)) {
499+
k_panic();
500+
}
501+
}
482502

483503
do {
484504
cmd = k_fifo_peek_head(&bt_dev.cmd_tx_queue);

0 commit comments

Comments
 (0)