Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport v3.5-branch] Bluetooth: host: sched-lock bt_recv() #75362

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions drivers/bluetooth/hci/rpmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,7 @@ static void bt_rpmsg_rx(const uint8_t *data, size_t len)

if (buf) {
LOG_DBG("Calling bt_recv(%p)", buf);

/* The IPC service does not guarantee that the handler thread
* is cooperative. In particular, the OpenAMP implementation is
* preemtible by default. OTOH, the HCI driver interface requires
* that the bt_recv() function is called from a cooperative
* thread.
*
* Calling `k_sched lock()` has the effect of making the current
* thread cooperative.
*/
k_sched_lock();
bt_recv(buf);
k_sched_unlock();

LOG_HEXDUMP_DBG(buf->data, buf->len, "RX buf payload:");
}
Expand Down
2 changes: 0 additions & 2 deletions include/zephyr/drivers/bluetooth/hci_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ static inline uint8_t bt_hci_evt_get_flags(uint8_t evt)
* for so-called high priority HCI events, which should instead be delivered to
* the host stack through bt_recv_prio().
*
* @note This function must only be called from a cooperative thread.
*
* @param buf Network buffer containing data from the controller.
*
* @return 0 on success or negative error number on failure.
Expand Down
13 changes: 12 additions & 1 deletion subsys/bluetooth/host/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3758,7 +3758,7 @@ static void rx_queue_put(struct net_buf *buf)
}
#endif /* !CONFIG_BT_RECV_BLOCKING */

int bt_recv(struct net_buf *buf)
static int bt_recv_unsafe(struct net_buf *buf)
{
bt_monitor_send(bt_monitor_opcode(buf), buf->data, buf->len);

Expand Down Expand Up @@ -3809,6 +3809,17 @@ int bt_recv(struct net_buf *buf)
}
}

int bt_recv(struct net_buf *buf)
{
int err;

k_sched_lock();
err = bt_recv_unsafe(buf);
k_sched_unlock();

return err;
}

int bt_recv_prio(struct net_buf *buf)
{
bt_monitor_send(bt_monitor_opcode(buf), buf->data, buf->len);
Expand Down
Loading