zephyr/tests/bluetooth
Johan Hedberg 39c2605930 Bluetooth: Fix deadlock with settings and bt_hci_cmd_send_sync()
We can't do synchronous HCI command sending in any settings commit()
callback, since we don't know what context the callback is being called
from. One particular deadlock can happen if settings_load() is called from
the preemptible main thread:

main()
 |--> settings_load() (aquire settings_lock mutex)
       |-->commit callback A that defers to system wq
       |-->commit callback B that calls bt_hci_cmd_send_sync()

system wq from the previous deferral from within settings_load():
 |--> work item
       |--> settings_save_one()
             |--> attempt to aquire settings_lock mutex

In the above scenario, the bt_hci_cmd_send_sync() call from the main thread
depends on the system workqueue being processed (since that's what does HCI
command processing by default), while at the same time holding the settings
subsystem's mutex. At the same time, a system wq item tries to store
something into settings, however it deadlocks waiting for the settings
mutex.

The actual scenario that we have in the Bluetooth subsystem is where
"commit callback A" is commit_settings() in host/settings.c, and "commit
callback B" is keys_commit() in host/keys.c.

The solution to the deadlock is to take advantage of deferred bt_id_add()
handling which already exists, i.e. set a flag and deferre the actual
adding to the system workqueue.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2025-04-01 16:28:00 +02:00
..
addr
adv
at
audio Bluetooth: ISO: Make setting ISO data explicit 2025-03-19 10:56:57 +01:00
bluetooth
bt_crypto test: Bluetooth: crypto: increase stack size for all the boards 2025-01-27 17:10:21 +01:00
bt_crypto_ccm
buf
classic tests: Bluetooth: BR: Add test suite sdp_server 2025-03-24 15:09:26 +01:00
common/testlib Bluetooth: testlib: Add addr string macro 2025-02-12 09:40:07 +01:00
controller Bluetooth: Controller: Fix incorrect CIS offset accepting peer instant 2025-03-29 06:32:21 +01:00
df Bluetooth: Rename BLE to Bluetooth (LE) where applicable 2025-02-12 12:24:18 +01:00
gap
gatt
hci
hci_codecs_info Bluetooth: Controller: Fix HCI command buffer allocation failure 2025-02-21 11:30:38 +00:00
hci_prop_evt
hci_uart_async
host Bluetooth: Fix deadlock with settings and bt_hci_cmd_send_sync() 2025-04-01 16:28:00 +02:00
host_config_variants
host_long_adv_recv
init Bluetooth: Host: Add support for Advertising Coding Selection 2025-02-08 10:09:41 +01:00
l2cap
mesh
mesh_shell Bluetooth: Mesh: use secure storage in ble mesh 2025-01-14 13:23:47 +01:00
qualification tests: Bluetooth: Mark generated qualification file as binaries 2025-03-05 19:05:09 +00:00
shell Bluetooth: CSIP: Add support for dynamically setting set size 2025-03-20 14:23:40 +01:00
smp boards native_posix: Remove twister support 2025-03-07 19:16:14 +01:00
tester tests: Bluetooth: Tester: Fix typo in PBP announcement 2025-03-31 19:48:25 -04:00
uuid