zephyr/subsys/bluetooth/host
Kyra Lengfeld 6464ffa3f9 Bluetooth: Host: Fix deadlock when failing to alloc on BT RX thread
This commit alignes the timeout value for allocating buffers within att
on the BT RX thread, making it consistent within att.c, see
bt_att_req_alloc.

We are inferring in many bt_gatt_* functions that if called from a BT RX
thread (which is inherently the case if called from a callback when
running a Bluetooth application), we don't block and instead return
-ENOMEM when the ATT request queue is full, avoiding a deadlock.
This promise is fulfilled within bt_att_req_alloc, where the timeout for
allocation of the request slab is set to K_NO_WAIT if we are on the BT
RX thread. Unfortunately, we break this promise in
bt_att_chan_create_pdu, where the timeout for allocation of the att pool
is still K_FOREVER and deadlocks can (and do) occur when too many
requests are sent yet the pool is depleted.

Note: Both req_slab and att_pool sizes are defined by
CONFIG_BT_ATT_TX_COUNT. If applications start getting -ENOMEM with this
change, they were at risk of such a deadlock, and may increase
CONFIG_BT_ATT_TX_COUNT to allocate the att pool for their requests.

Note: This possible deadlock has been flying under the radar, as
att_pools are freed when the HCI driver has sent it to the controller
(instead of when receiving the response, as it happens with req_slabs)
and due to the att_pool and the req_slab being both sized by
CONFIG_BT_ATT_TX_COUNT, and req_slab being allocated before and
returning -ENOMEM already if there is no space, it takes a more specific
situation to deplete the att_pool but not the req_slab pool at this
point.

Note: Ideally, we don't want functions to behave differently depending
on which thread they are running, and while this commit makes it more
consistent, it should be considered a workaround solution.

Signed-off-by: Kyra Lengfeld <kyra.lengfeld@nordicsemi.no>
2025-02-28 10:10:01 +01:00
..
classic Bluetooth: AVDTP: Fix memory leak issue 2025-02-18 13:30:53 +01:00
shell Bluetooth: Shell: fix assert when print address. 2025-02-20 11:47:39 +01:00
addr_internal.h
addr.c
adv.c Bluetooth: Host: Remove nested allocation of HCI command buffer 2025-02-21 11:30:38 +00:00
adv.h
aes_ccm.c
att_internal.h
att.c Bluetooth: Host: Fix deadlock when failing to alloc on BT RX thread 2025-02-28 10:10:01 +01:00
buf_view.h
buf.c Bluetooth: Controller: Fix HCI command buffer allocation failure 2025-02-21 11:30:38 +00:00
CMakeLists.txt Bluetooth: Host: Remove HCI ECC emulation 2025-01-23 10:14:46 +01:00
conn_internal.h Bluetooth: Host: deprecate bt_le_set_auto_conn() 2024-11-26 10:37:12 +00:00
conn.c Bluetooth: Host: Add type check for bt_conn API 2025-02-11 22:04:51 +01:00
crypto_psa.c bluetooth: host/crypto: fix the psa crypto init for host 2025-02-10 14:33:24 +01:00
crypto.h bluetooth: host/crypto: fix the psa crypto init for host 2025-02-10 14:33:24 +01:00
cs.c bluetooth: host: Use LOG_WRN for failed CS procedures 2024-11-27 10:31:25 +01:00
data.c
direction_internal.h
direction.c
ecc.c bluetooth: host: Allow for ECDH operations through system workq 2025-02-12 20:26:28 +01:00
ecc.h Bluetooth: Host: SMP: Verify public key before usage 2024-12-11 21:29:08 +01:00
gatt_internal.h
gatt.c bluetooth: Guard gatt_prepare_write against calls while disconnected 2025-02-24 15:37:18 +00:00
hci_common.c Bluetooth: Controller: Fix HCI command buffer allocation failure 2025-02-21 11:30:38 +00:00
hci_core.c Bluetooth: Controller: Fix HCI command buffer allocation failure 2025-02-21 11:30:38 +00:00
hci_core.h Bluetooth: Host: Remove HCI ECC emulation 2025-01-23 10:14:46 +01:00
hci_raw_internal.h Bluetooth: Host: Remove deprecated HCI driver API 2024-11-22 11:37:12 +01:00
hci_raw.c Bluetooth: Controller: Fix HCI command buffer allocation failure 2025-02-21 11:30:38 +00:00
id.c bluetooth: id: Fix logging 2025-02-24 15:37:41 +00:00
id.h
iso_internal.h Bluetooth: ISO: Add support for cis_established_v2 in host 2024-12-20 10:19:23 +01:00
iso.c Bluetooth: ISO: Fix -Wsometimes-uninitialized warning 2025-02-08 08:14:26 +01:00
Kconfig bluetooth: host: Allow for ECDH operations through system workq 2025-02-12 20:26:28 +01:00
Kconfig.gatt bluetooth: host: Add select PSA_WANT_ALG_ECB_NO_PADDING 2025-01-30 11:15:24 +01:00
Kconfig.l2cap Bluetooth: Tester: Use BT_L2CAP_SEG_RECV for L2CAP tests 2024-11-27 08:16:18 +01:00
keys.c
keys.h
l2cap_internal.h Bluetooth: Tester: Use BT_L2CAP_SEG_RECV for L2CAP tests 2024-11-27 08:16:18 +01:00
l2cap.c Bluetoth: Host: Fix buffer allocation warnings in system workqueue 2025-02-25 15:14:08 +00:00
long_wq.c
long_wq.h
monitor.c Bluetooth: monitor: Fix SEGGER RTT compilation error 2025-02-10 14:33:01 +01:00
monitor.h
scan.c Bluetooth: Host: Add host support for Advertising Coding Selection 2025-02-14 17:08:23 +01:00
scan.h Bluetooth: Host: Log when connecting while scanning may give bad params 2024-11-27 10:38:27 -05:00
settings.c Bluetooth: Mesh: use settings priority feature 2025-01-14 00:00:56 +01:00
settings.h Bluetooth: Mesh: use settings priority feature 2025-01-14 00:00:56 +01:00
smp_null.c
smp.c bluetooth: host: smp: fix deadlock when public key generation fails 2025-02-18 18:44:23 +01:00
smp.h
uuid.c Bluetooth: Rename BLE to Bluetooth (LE) where applicable 2025-02-12 12:24:18 +01:00