* [PATCH] Bluetooth: mgmt: disable discoverable work before device lock
@ 2026-12-02 2:06 Baek Kyu, Kim
2026-12-02 3:02 ` bluez.test.bot
0 siblings, 1 reply; 2+ messages in thread
From: Baek Kyu, Kim @ 2026-12-02 2:06 UTC (permalink / raw)
To: Marcel Holtmann, Luiz Augusto von Dentz; +Cc: linux-bluetooth
mgmt_index_removed() synchronously cancels discov_off while its callers
hold hdev->lock. The delayed work also takes hdev->lock, so index removal
can wait for a worker that is waiting for the remover's lock.
Drain the work before taking hdev->lock. Keep it disabled across index
removal so another management command cannot requeue it between the
cancellation and the lock acquisition. Re-enable it under hdev->lock
after temporary configuration and user-channel transitions; leave it
disabled during unregister.
Use a locked precheck to skip draining work when a configuration
request cannot remove the index, including unchanged options.
Signed-off-by: Baek Kyu, Kim <pocj8ur4in@gmail.com>
---
On arm64 QEMU/KVM, an instrumented baseline stalled during index
removal while discov_off waited for hdev->lock. The changed kernel
completed teardown. Test-only virtual-controller setup exercised both
configuration transitions and user-channel bind; attempted requeues
were blocked while the work was disabled. Unchanged configuration
requests left it enabled. Normal discoverable timeout and user-channel
tests passed. No physical controller was tested.
net/bluetooth/hci_core.c | 3 +++
net/bluetooth/hci_sock.c | 7 +++++++
net/bluetooth/mgmt.c | 34 +++++++++++++++++++++++++++++++---
3 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 255005916f37..ced6996aa1b4 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -2778,6 +2778,9 @@ void hci_unregister_dev(struct hci_dev *hdev)
if (!test_bit(HCI_INIT, &hdev->flags) &&
!hci_dev_test_flag(hdev, HCI_SETUP) &&
!hci_dev_test_flag(hdev, HCI_CONFIG)) {
+ if (hci_dev_test_flag(hdev, HCI_MGMT))
+ disable_delayed_work_sync(&hdev->discov_off);
+
hci_dev_lock(hdev);
mgmt_index_removed(hdev);
hci_dev_unlock(hdev);
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 3da994d1fe65..098373d14b44 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -1208,6 +1208,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr_unsized *addr,
struct sock *sk = sock->sk;
struct hci_dev *hdev = NULL;
struct sk_buff *skb;
+ bool discov_disabled = false;
int len, err = 0;
BT_DBG("sock %p sk %p", sock, sk);
@@ -1329,8 +1330,14 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr_unsized *addr,
goto done;
}
+ discov_disabled = hci_dev_test_flag(hdev, HCI_MGMT);
+ if (discov_disabled)
+ disable_delayed_work_sync(&hdev->discov_off);
+
hci_dev_lock(hdev);
mgmt_index_removed(hdev);
+ if (discov_disabled)
+ enable_delayed_work(&hdev->discov_off);
hci_dev_unlock(hdev);
err = hci_dev_open(hdev->id);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index e6876c76ca24..9156888c5f29 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -8588,7 +8588,8 @@ static int set_external_config(struct sock *sk, struct hci_dev *hdev,
void *data, u16 len)
{
struct mgmt_cp_set_external_config *cp = data;
- bool changed;
+ bool discov_disabled = false;
+ bool changed, configured;
int err;
bt_dev_dbg(hdev, "sock %p", sk);
@@ -8606,6 +8607,19 @@ static int set_external_config(struct sock *sk, struct hci_dev *hdev,
MGMT_STATUS_NOT_SUPPORTED);
hci_dev_lock(hdev);
+ changed = cp->config != hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED);
+ configured = cp->config &&
+ (!(hci_test_quirk(hdev, HCI_QUIRK_INVALID_BDADDR) ||
+ hci_test_quirk(hdev, HCI_QUIRK_USE_BDADDR_PROPERTY)) ||
+ !!bacmp(&hdev->public_addr, BDADDR_ANY));
+ /* Drain the work only if this request may remove the index. */
+ if (changed && hci_dev_test_flag(hdev, HCI_UNCONFIGURED) == configured &&
+ hci_dev_test_flag(hdev, HCI_MGMT)) {
+ hci_dev_unlock(hdev);
+ disable_delayed_work_sync(&hdev->discov_off);
+ discov_disabled = true;
+ hci_dev_lock(hdev);
+ }
if (cp->config)
changed = !hci_dev_test_and_set_flag(hdev, HCI_EXT_CONFIGURED);
@@ -8636,6 +8650,8 @@ static int set_external_config(struct sock *sk, struct hci_dev *hdev,
}
unlock:
+ if (discov_disabled)
+ enable_delayed_work(&hdev->discov_off);
hci_dev_unlock(hdev);
return err;
}
@@ -8644,7 +8660,8 @@ static int set_public_address(struct sock *sk, struct hci_dev *hdev,
void *data, u16 len)
{
struct mgmt_cp_set_public_address *cp = data;
- bool changed;
+ bool discov_disabled = false;
+ bool changed, configured;
int err;
bt_dev_dbg(hdev, "sock %p", sk);
@@ -8662,6 +8679,16 @@ static int set_public_address(struct sock *sk, struct hci_dev *hdev,
MGMT_STATUS_NOT_SUPPORTED);
hci_dev_lock(hdev);
+ changed = !!bacmp(&hdev->public_addr, &cp->bdaddr);
+ configured = !hci_test_quirk(hdev, HCI_QUIRK_EXTERNAL_CONFIG) ||
+ hci_dev_test_flag(hdev, HCI_EXT_CONFIGURED);
+ /* Drain the work only if this request may remove the index. */
+ if (changed && configured && hci_dev_test_flag(hdev, HCI_MGMT)) {
+ hci_dev_unlock(hdev);
+ disable_delayed_work_sync(&hdev->discov_off);
+ discov_disabled = true;
+ hci_dev_lock(hdev);
+ }
changed = !!bacmp(&hdev->public_addr, &cp->bdaddr);
bacpy(&hdev->public_addr, &cp->bdaddr);
@@ -8688,6 +8715,8 @@ static int set_public_address(struct sock *sk, struct hci_dev *hdev,
}
unlock:
+ if (discov_disabled)
+ enable_delayed_work(&hdev->discov_off);
hci_dev_unlock(hdev);
return err;
}
@@ -10105,7 +10134,6 @@ void mgmt_index_removed(struct hci_dev *hdev)
/* Cancel any remaining timed work */
if (!hci_dev_test_flag(hdev, HCI_MGMT))
return;
- cancel_delayed_work_sync(&hdev->discov_off);
cancel_delayed_work_sync(&hdev->service_cache);
cancel_delayed_work_sync(&hdev->rpa_expired);
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* RE: Bluetooth: mgmt: disable discoverable work before device lock
2026-12-02 2:06 [PATCH] Bluetooth: mgmt: disable discoverable work before device lock Baek Kyu, Kim
@ 2026-12-02 3:02 ` bluez.test.bot
0 siblings, 0 replies; 2+ messages in thread
From: bluez.test.bot @ 2026-12-02 3:02 UTC (permalink / raw)
To: linux-bluetooth, pocj8ur4in
[-- Attachment #1: Type: text/plain, Size: 1884 bytes --]
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1228797/
---Test result---
Test Summary:
CheckPatch PASS 0.72 seconds
VerifyFixes PASS 0.05 seconds
VerifySignedoff PASS 0.05 seconds
GitLint PASS 0.16 seconds
SubjectPrefix PASS 0.04 seconds
BuildKernel PASS 20.66 seconds
CheckAllWarning PASS 25.07 seconds
CheckSparse PASS 25.44 seconds
BuildKernel32 PASS 21.03 seconds
CheckKernelLLVM PASS 22.27 seconds
TestRunnerSetup PASS 494.28 seconds
TestRunner_l2cap-tester FAIL 13.71 seconds
TestRunner_iso-tester PASS 11.84 seconds
TestRunner_bnep-tester PASS 3.13 seconds
TestRunner_mgmt-tester PASS 84.88 seconds
TestRunner_rfcomm-tester PASS 4.39 seconds
TestRunner_sco-tester PASS 5.44 seconds
TestRunner_ioctl-tester PASS 4.52 seconds
TestRunner_mesh-tester PASS 4.43 seconds
TestRunner_smp-tester PASS 4.28 seconds
TestRunner_userchan-tester PASS 3.17 seconds
TestRunner_6lowpan-tester PASS 4.32 seconds
IncrementalBuild PASS 19.06 seconds
Details
##############################
Test: TestRunner_l2cap-tester - FAIL
Desc: Run l2cap-tester with test-runner
Output:
Total: 144, Passed: 143 (99.3%), Failed: 1, Not Run: 0
Failed Test Cases
L2CAP BR/EDR Client SSP - Success 2 Failed 0.017 seconds
https://github.com/bluez/bluetooth-next/pull/1272
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 3:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 2:06 [PATCH] Bluetooth: mgmt: disable discoverable work before device lock Baek Kyu, Kim
2026-12-02 3:02 ` bluez.test.bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox