zephyr: driver: bluetooth: userchan: Stuck in rx_thread: calling read()

Hi All,

When I was testing a Nordic Controller, I discovered that Zephyr’s Host HCI might have problems in userchan mode.

Reproduction steps

  1. You need to integrate the test patch I provided(https://github.com/LingaoM/zephyr/commit/3cabf9bfe6bb099b6ea5f4fdadc87e5b7d36f761).

  2. west build -b native_sim zephyr/samples/bluetooth/mesh -p auto (Must be native_sim, so HCI userchan mode is used.)

  3. west build -b bbc_microbit_v2 zephyr/samples/bluetooth/mesh_provisioner -p auto (This could be the nRF52840 DK either one is fine.) & west flash

  4. If you don’t have a NEW PTS Dongle, please find the nRF52840 Dongle and flash pts.zip (this is the Controller firmware provided by Bluetooth SIG) Use nrfutil dfu usb-serial -pkg pts.zip -p /dev/ttyACM0, or have PTS Dongle(NEW LE Only - up to Core Spec v5.2 supported (Laird Connectivity, part number 451-00004)), direct attach The Controller.

sudo btattach -B /dev/ttyACM0 -S 1000000 -R Attaching Primary controller to /dev/ttyACM0 Switched line discipline from 0 to 15 Device index 0 attached Manufacturer: 2024

  1. Run zephyr.exe generated in the second step. Use sudo build/zephyr/zephyr.exe --bt-dev=hci0.

  2. Open new terminal, sudo btmon -w btsnoop.pcapng.

  3. Wait patiently for a while, and you can see that the PB-ADV PB-GATT network provision test is being executed repeatedly.

Waiting for unprovisioned beacon...
Provisioning over PB-GATT dddd0000000000000000000000000000
Waiting for node to be added...
Added node 0x0002
Waiting for unprovisioned beacon...
Provisioning over PB-ADV dddd0000000000000000000000000000
Waiting for node to be added...
Added node 0x0002
Waiting for unprovisioned beacon...
Provisioning over PB-GATT dddd0000000000000000000000000000
  1. The problem will arise when the program in step 6 suddenly crashes.
[00:01:32.220,000] <dbg> bt_driver: rx_thread: calling read()
[00:01:32.220,000] <dbg> bt_driver: rx_thread: Calling bt_recv(0x565c5db4)
[00:01:32.220,000] <dbg> bt_hci_core: bt_recv: buf 0x565c5db4 len 59
[00:01:32.220,000] <dbg> bt_driver: rx_thread: calling read()
[00:01:32.220,000] <dbg> bt_driver: rx_thread: Calling bt_recv(0x565c5dd0)
[00:01:32.220,000] <dbg> bt_hci_core: bt_recv: buf 0x565c5dd0 len 47
[00:01:32.220,000] <dbg> bt_driver: rx_thread: calling read()
[00:01:32.220,000] <dbg> bt_gatt: bt_gatt_attr_read: handle 0x0000 offset 0 length 2
[00:01:32.220,000] <dbg> bt_gatt: bt_gatt_attr_read: handle 0x0000 offset 0 length 5
[00:01:32.220,000] <dbg> bt_gatt: bt_gatt_attr_read: handle 0x0000 offset 0 length 5
[00:01:32.220,000] <dbg> bt_gatt: bt_gatt_attr_read: handle 0x0000 offset 0 length 5
[00:01:32.220,000] <dbg> bt_gatt: bt_gatt_attr_read: handle 0x0000 offset 0 length 2
[00:01:32.220,000] <dbg> bt_gatt: bt_gatt_attr_read: handle 0x0000 offset 0 length 5
[00:01:32.220,000] <dbg> bt_gatt: bt_gatt_attr_read: handle 0x0000 offset 0 length 5
[00:01:32.220,000] <dbg> bt_gatt: bt_gatt_attr_read: handle 0x0000 offset 0 length 5
[00:01:32.220,000] <dbg> bt_gatt: db_hash_gen: Hash: 
                                 fb 77 e2 2d 82 8a 4b 4d  45 c6 c0 32 1e cf 57 af |.w.-..KM E..2..W.
ASSERTION FAIL [err == 0] @ ZEPHYR_BASE/subsys/bluetooth/host/hci_core.c:340
   command opcode 0x2039 timeout with err -11
@ ZEPHYR_BASE/subsys/bluetooth/host/hci_core.c:340
[00:02:32.210,000] <err> os: z_fatal_error: >>> ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0
[00:02:32.210,000] <err> os: z_fatal_error: Current thread: 0x565caf80 (unknown)
[00:02:32.210,000] <err> os: k_sys_fatal_error_handler: Halting system
Exiting due to fatal error
  1. You can see from the timestamp that the program suddenly got stuck at 00:01:32.220,000, but there is available more data in btsnoop.pcapng.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

image

The reason was found, it was K_FOREVER caused by this BT_HCI_EVT_LE_EXT_ADVERTISING_REPORT.

This might also be a Linux bug. If you look at the userchan.c code it’s quite simple - the read() is always followed by poll() indicating that there is data to be read (POLLIN).

May be, if this is deadlock, can it be reproduced purely between two target boards?

This problem cannot be found between two real board.

no idea

It appears the HCI Controller is not responding. Is this the crash in the mesh_provisioner sample on the bbc_microbit_v2 or the crash on the native_posix?

native