Skip to content

Conversation

Thalley
Copy link
Contributor

@Thalley Thalley commented Jul 17, 2025

BIS termination as broadcaster is handled different than ACL and CIS, and in rare chances the
tx_complete for BIS may not have been completed in the system workqueue before iso_new was called for the same bt_conn struct (e.g. via bt_iso_cig_create), which would perform

k_work_init(&conn->tx_complete_work, tx_complete_work);

but where conn->tx_complete_work still existed in
the system workqueue, which would cause the list
of pending items on the system workqueue to be removed as the next pointer would be NULL.

This also adds an assert in bt_conn_new to prevent this issue from appearing again.

@Thalley
Copy link
Contributor Author

Thalley commented Jul 17, 2025

The assert from this PR may be superseded by #93279

@Thalley Thalley force-pushed the bis_terminate_tx_fix branch 3 times, most recently from df12b0e to 41bc2d1 Compare July 17, 2025 20:09
@Thalley Thalley requested a review from Copilot July 17, 2025 20:18
Copilot

This comment was marked as outdated.

@Thalley Thalley force-pushed the bis_terminate_tx_fix branch from 41bc2d1 to 109eb53 Compare July 17, 2025 20:24
@Thalley Thalley marked this pull request as ready for review July 17, 2025 20:51
@zephyrbot zephyrbot added area: Bluetooth area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth ISO Bluetooth LE Isochronous Channels labels Jul 17, 2025
cvinayak
cvinayak previously approved these changes Jul 23, 2025
@Thalley Thalley force-pushed the bis_terminate_tx_fix branch from 109eb53 to f7e0400 Compare July 29, 2025 09:20
@cvinayak cvinayak requested a review from PavelVPV July 29, 2025 12:13
@cvinayak
Copy link
Contributor

@PavelVPV FYI, as this issue concerns the way Host uses system workqueue, potentially causing issues to other users of system work queue.

@@ -1,9 +1,12 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
* Copyright (c) 2024-2025 Nordic Semiconductor ASA
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC we don't need to update copyright year.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't we ever managed to write and guidelines on this :D I usually just update them when I remember them, but I can omit it if you prefer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me. I remember getting such comment long time ago, but can't find it now.

@PavelVPV
Copy link
Contributor

@PavelVPV FYI, as this issue concerns the way Host uses system workqueue, potentially causing issues to other users of system work queue.

Perhaps, all work items should be moved below ref in bt_conn and initialized just once.

@Thalley
Copy link
Contributor Author

Thalley commented Jul 31, 2025

I moved the assert to bt_conn_unref when a bt_conn is unreffed, as that's really where all pending TX should have been flushed

@Thalley Thalley force-pushed the bis_terminate_tx_fix branch from c1bad57 to e7bf83c Compare July 31, 2025 09:24
PavelVPV
PavelVPV previously approved these changes Jul 31, 2025
@PavelVPV PavelVPV self-requested a review July 31, 2025 09:50
BIS termination as broadcaster is handled different
than ACL and CIS, and in rare chances the
tx_complete for BIS may not have been completed in
the system workqueue before iso_new was called for the
same bt_conn struct (e.g. via bt_iso_cig_create), which
would perform

k_work_init(&conn->tx_complete_work, tx_complete_work);

but where conn->tx_complete_work still existed in
the system workqueue, which would cause the list
of pending items on the system workqueue to be removed
as the `next` pointer would be NULL.

This also adds an assert in bt_conn_new to prevent this
issue from appearing again.

Signed-off-by: Emil Gydesen <[email protected]>
Copy link

@Thalley Thalley requested a review from Copilot July 31, 2025 10:34
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a race condition in Bluetooth ISO (Isochronous) connections where BIS (Broadcast Isochronous Stream) termination could cause work queue corruption. The issue occurred when tx_complete_work was reinitialized while still pending in the system workqueue, potentially corrupting the queue's linked list structure.

Key changes:

  • Add explicit tx_complete cleanup for BIS broadcaster termination
  • Add assertion to detect work queue corruption during connection deallocation
  • Add mock functions for k_work_busy_get to support testing

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
subsys/bluetooth/host/iso.c Adds explicit bt_conn_tx_notify call for BIS broadcaster disconnection to flush pending tx_complete work
subsys/bluetooth/host/conn.c Adds assertion to detect pending tx_complete_work during connection deallocation
tests/bluetooth/host/conn/mocks/kernel.h Declares mock function for k_work_busy_get
tests/bluetooth/host/conn/mocks/kernel.c Defines mock function for k_work_busy_get

IF_ENABLED(CONFIG_BT_CONN_TX,
(__ASSERT(!(deallocated && k_work_is_pending(&conn->tx_complete_work)),
"tx_complete_work is pending when conn is deallocated")));
conn = NULL;
Copy link
Preview

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting conn to NULL after the assertion will cause the assertion to access a NULL pointer. The conn = NULL assignment should remain after the assertion, but the assertion should be moved before this line or use a different approach to access the work structure.

Copilot uses AI. Check for mistakes.

@cfriedt cfriedt merged commit b76f09d into zephyrproject-rtos:main Jul 31, 2025
28 checks passed
@Thalley Thalley deleted the bis_terminate_tx_fix branch August 1, 2025 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth ISO Bluetooth LE Isochronous Channels area: Bluetooth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants