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 Bluetooth: Controller: Replace BT_CTLR with HAS_BT_CTLR 2024-12-03 10:16:44 +01:00
adv
at
audio Bluetooth: ISO: Make setting ISO data explicit 2025-03-19 10:56:57 +01:00
bluetooth Bluetooth: Controller: Replace BT_CTLR with HAS_BT_CTLR 2024-12-03 10:16:44 +01:00
bt_crypto test: Bluetooth: crypto: increase stack size for all the boards 2025-01-27 17:10:21 +01:00
bt_crypto_ccm Bluetooth: Controller: Replace BT_CTLR with HAS_BT_CTLR 2024-12-03 10:16:44 +01:00
buf tests: bluetooth: buf: Test the freed buf callback 2024-12-10 11:09:36 +01:00
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 Bluetooth: Host: Add conversion macros from ms to various units 2024-11-16 14:06:03 -05:00
gatt Bluetooth: fix GATT service reregistering 2024-12-04 12:10:22 +01:00
hci Bluetooth: Controller: Replace BT_CTLR with HAS_BT_CTLR 2024-12-03 10:16:44 +01:00
hci_codecs_info Bluetooth: Controller: Fix HCI command buffer allocation failure 2025-02-21 11:30:38 +00:00
hci_prop_evt Bluetooth: Controller: Replace BT_CTLR with HAS_BT_CTLR 2024-12-03 10:16:44 +01:00
hci_uart_async drivers: bluetooth: hci: Place API into iterable section 2024-11-29 14:49:53 +01:00
host Bluetooth: Fix deadlock with settings and bt_hci_cmd_send_sync() 2025-04-01 16:28:00 +02:00
host_config_variants bluetooth: smp: Fix build warnings for central with OOB legacy only 2024-12-12 11:05:38 +01:00
host_long_adv_recv Bluetooth: Controller: Replace BT_CTLR with HAS_BT_CTLR 2024-12-03 10:16:44 +01:00
init Bluetooth: Host: Add support for Advertising Coding Selection 2025-02-08 10:09:41 +01:00
l2cap Bluetooth: Controller: Replace BT_CTLR with HAS_BT_CTLR 2024-12-03 10:16:44 +01:00
mesh tests: bt: add Mbed TLS headers to the build 2024-11-27 16:40:47 -05:00
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 Bluetooth: Controller: Replace BT_CTLR with HAS_BT_CTLR 2024-12-03 10:16:44 +01:00