Bug 198043
Summary: | Bluetooth mgmt api set powered causes kernel race condition | ||
---|---|---|---|
Product: | Drivers | Reporter: | Matias Karhumaa (matias.karhumaa) |
Component: | Bluetooth | Assignee: | linux-bluetooth (linux-bluetooth) |
Status: | NEW --- | ||
Severity: | blocking | CC: | l.perneel |
Priority: | P1 | ||
Hardware: | Other | ||
OS: | Linux | ||
Kernel Version: | 4.10 | Subsystem: | |
Regression: | No | Bisected commit-id: |
Description
Matias Karhumaa
2017-11-30 13:22:45 UTC
Had a similar issue on a 4.9.60 build where the hci_sock_release and hci_send_to_channel on two CPUs generate a soft lockup between them. The hci_sock_release with the _raw_write_lock (like here) and the hci_sock_release with the _raw_read_lock (different than this case, but highly probable caused by the same issue). So it seems that the _raw_write_lock and the _raw_read_lock have a deadly race between them. Will dig deeper into the issue and post an update later. OK found the cause, but it is solved in the upcoming 4.15 kernel. Patch can be found in: https://patchwork.kernel.org/patch/9963977/ In short: the function hci_send_monitor_ctrl_event (in hci_sock.c) takes the read_lock. Then it calls hci_send_to_channel which also takes the read_lock. If now between the two read lock takes, a write lock is entered on another cpu (and thus the waiting writer flag is set), the second take will decrease again its counter (not entering the lock) and wait until the writer finished. However, as the same thread took it already, it will never decrease to zero. At the end both cpus are spinlocking waiting on each other for ever. On a dual core system, this actually means you are dead. (in fact you loose two cores when this happen on whatever system, and each next bluetooth request can lockup another core until the system is dead). I will fix my 4.9 kernel, but I hope this nasty bug is backported towards older kernels. Checked it: bug is introduced in 4.9 where the function hci_send_monitor_ctrl_event was added (which contains the bug). |