public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* RE: Bluetooth: hci_event: Fix connection state issues during suspend/resume
  2025-08-12 14:10 [PATCH 1/2] Bluetooth: hci_event: Treat UNKNOWN_CONN_ID on disconnect as success Ludovico de Nittis
@ 2025-08-12 14:36 ` bluez.test.bot
  0 siblings, 0 replies; 6+ messages in thread
From: bluez.test.bot @ 2025-08-12 14:36 UTC (permalink / raw)
  To: linux-bluetooth, ludovico.denittis

[-- Attachment #1: Type: text/plain, Size: 2750 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/project/bluetooth/list/?series=990596

---Test result---

Test Summary:
CheckPatch                    PENDING   0.46 seconds
GitLint                       PENDING   0.28 seconds
SubjectPrefix                 PASS      0.16 seconds
BuildKernel                   PASS      24.51 seconds
CheckAllWarning               PASS      27.11 seconds
CheckSparse                   WARNING   30.90 seconds
BuildKernel32                 PASS      24.41 seconds
TestRunnerSetup               PASS      488.03 seconds
TestRunner_l2cap-tester       PASS      25.51 seconds
TestRunner_iso-tester         PASS      42.81 seconds
TestRunner_bnep-tester        PASS      6.11 seconds
TestRunner_mgmt-tester        FAIL      133.96 seconds
TestRunner_rfcomm-tester      PASS      9.52 seconds
TestRunner_sco-tester         PASS      15.07 seconds
TestRunner_ioctl-tester       PASS      10.20 seconds
TestRunner_mesh-tester        FAIL      11.36 seconds
TestRunner_smp-tester         PASS      8.70 seconds
TestRunner_userchan-tester    PASS      6.32 seconds
IncrementalBuild              PENDING   0.53 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:
net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 490, Passed: 483 (98.6%), Failed: 3, Not Run: 4

Failed Test Cases
Add Ext Advertising - Success 22 (LE -> off, Remove) Failed       0.132 seconds
Set Device ID - Power off and Power on               Failed       0.129 seconds
Set Device ID - SSP off and Power on                 Failed       0.131 seconds
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner
Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases
Mesh - Send cancel - 1                               Timed out    1.988 seconds
Mesh - Send cancel - 2                               Timed out    1.996 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 0/2] Bluetooth: hci_event: Fix connection state issues during suspend/resume
@ 2025-08-12 15:55 Ludovico de Nittis
  2025-08-12 15:55 ` [PATCH v2 1/2] Bluetooth: hci_event: Treat UNKNOWN_CONN_ID on disconnect as success Ludovico de Nittis
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Ludovico de Nittis @ 2025-08-12 15:55 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ludovico de Nittis

This patch series addresses connection state synchronization issues
between the Bluetooth controller and kernel during suspend/resume cycles.

The problem seems to be visible when using devices that very quickly try
to send multiple reconnect events without waiting enough for the host
to fully resume from suspend.

Fixes the issues reported in https://github.com/bluez/bluez/issues/1226.

v2:
- Add an explicit check for hdev->suspended
- Include the btmon log in the commit message

Ludovico de Nittis (2):
  Bluetooth: hci_event: Treat UNKNOWN_CONN_ID on disconnect as success
  Bluetooth: hci_event: Mark connection as closed during suspend
    disconnect

 net/bluetooth/hci_event.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

-- 
2.50.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] Bluetooth: hci_event: Treat UNKNOWN_CONN_ID on disconnect as success
  2025-08-12 15:55 [PATCH v2 0/2] Bluetooth: hci_event: Fix connection state issues during suspend/resume Ludovico de Nittis
@ 2025-08-12 15:55 ` Ludovico de Nittis
  2025-08-12 16:40   ` Bluetooth: hci_event: Fix connection state issues during suspend/resume bluez.test.bot
  2025-08-12 15:55 ` [PATCH v2 2/2] Bluetooth: hci_event: Mark connection as closed during suspend disconnect Ludovico de Nittis
  2025-08-19 14:30 ` [PATCH v2 0/2] Bluetooth: hci_event: Fix connection state issues during suspend/resume patchwork-bot+bluetooth
  2 siblings, 1 reply; 6+ messages in thread
From: Ludovico de Nittis @ 2025-08-12 15:55 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ludovico de Nittis

When the host sends an HCI_OP_DISCONNECT command, the controller may
respond with the status HCI_ERROR_UNKNOWN_CONN_ID (0x02). E.g. this can
happen on resume from suspend, if the link was terminated by the remote
device before the event mask was correctly set.

This is a btmon snippet that shows the issue:
```
> ACL Data RX: Handle 3 flags 0x02 dlen 12
      L2CAP: Disconnection Request (0x06) ident 5 len 4
        Destination CID: 65
        Source CID: 72
< ACL Data TX: Handle 3 flags 0x00 dlen 12
      L2CAP: Disconnection Response (0x07) ident 5 len 4
        Destination CID: 65
        Source CID: 72
> ACL Data RX: Handle 3 flags 0x02 dlen 12
      L2CAP: Disconnection Request (0x06) ident 6 len 4
        Destination CID: 64
        Source CID: 71
< ACL Data TX: Handle 3 flags 0x00 dlen 12
      L2CAP: Disconnection Response (0x07) ident 6 len 4
        Destination CID: 64
        Source CID: 71
< HCI Command: Set Event Mask (0x03|0x0001) plen 8
        Mask: 0x3dbff807fffbffff
          Inquiry Complete
          Inquiry Result
          Connection Complete
          Connection Request
          Disconnection Complete
          Authentication Complete
[...]
< HCI Command: Disconnect (0x01|0x0006) plen 3
        Handle: 3 Address: 78:20:A5:4A:DF:28 (Nintendo Co.,Ltd)
        Reason: Remote User Terminated Connection (0x13)
> HCI Event: Command Status (0x0f) plen 4
      Disconnect (0x01|0x0006) ncmd 1
        Status: Unknown Connection Identifier (0x02)
```

Currently, the hci_cs_disconnect function treats any non-zero status
as a command failure. This can be misleading because the connection is
indeed being terminated and the controller is confirming that is has no
knowledge of that connection handle. Meaning that the initial request of
disconnecting a device should be treated as done.

With this change we allow the function to proceed, following the success
path, which correctly calls `mgmt_device_disconnected` and ensures a
consistent state.

Link: https://github.com/bluez/bluez/issues/1226
Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
---
 net/bluetooth/hci_event.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index fe7cdd67a..6c67dfa13 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2703,7 +2703,7 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
 	if (!conn)
 		goto unlock;
 
-	if (status) {
+	if (status && status != HCI_ERROR_UNKNOWN_CONN_ID) {
 		mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
 				       conn->dst_type, status);
 
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/2] Bluetooth: hci_event: Mark connection as closed during suspend disconnect
  2025-08-12 15:55 [PATCH v2 0/2] Bluetooth: hci_event: Fix connection state issues during suspend/resume Ludovico de Nittis
  2025-08-12 15:55 ` [PATCH v2 1/2] Bluetooth: hci_event: Treat UNKNOWN_CONN_ID on disconnect as success Ludovico de Nittis
@ 2025-08-12 15:55 ` Ludovico de Nittis
  2025-08-19 14:30 ` [PATCH v2 0/2] Bluetooth: hci_event: Fix connection state issues during suspend/resume patchwork-bot+bluetooth
  2 siblings, 0 replies; 6+ messages in thread
From: Ludovico de Nittis @ 2025-08-12 15:55 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Ludovico de Nittis

When suspending, the disconnect command for an active Bluetooth
connection could be issued, but the corresponding
`HCI_EV_DISCONN_COMPLETE` event might not be received before the system
completes the suspend process. This can lead to an inconsistent state.

On resume, the controller may auto-accept reconnections from the same
device (due to suspend event filters), but these new connections are
rejected by the kernel which still has connection objects from before
suspend. Resulting in errors like:
```
kernel: Bluetooth: hci0: ACL packet for unknown connection handle 1
kernel: Bluetooth: hci0: Ignoring HCI_Connection_Complete for existing
connection
```

This is a btmon snippet that shows the issue:
```
< HCI Command: Disconnect (0x01|0x0006) plen 3
        Handle: 1 Address: 78:20:A5:4A:DF:28 (Nintendo Co.,Ltd)
        Reason: Remote User Terminated Connection (0x13)
> HCI Event: Command Status (0x0f) plen 4
      Disconnect (0x01|0x0006) ncmd 2
        Status: Success (0x00)
[...]
// Host suspends with the event filter set for the device
// On resume, the device tries to reconnect with a new handle

> HCI Event: Connect Complete (0x03) plen 11
        Status: Success (0x00)
        Handle: 2
        Address: 78:20:A5:4A:DF:28 (Nintendo Co.,Ltd)

// Kernel ignores this event because there is an existing connection
with
// handle 1
```

By explicitly setting the connection state to BT_CLOSED we can ensure a
consistent state, even if we don't receive the disconnect complete event
in time.

Link: https://github.com/bluez/bluez/issues/1226
Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
---
 net/bluetooth/hci_event.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 6c67dfa13..ce0ff06f2 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2718,6 +2718,12 @@ static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
 		goto done;
 	}
 
+	/* During suspend, mark connection as closed immediately
+	 * since we might not receive HCI_EV_DISCONN_COMPLETE
+	 */
+	if (hdev->suspended)
+		conn->state = BT_CLOSED;
+
 	mgmt_conn = test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags);
 
 	if (conn->type == ACL_LINK) {
-- 
2.50.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* RE: Bluetooth: hci_event: Fix connection state issues during suspend/resume
  2025-08-12 15:55 ` [PATCH v2 1/2] Bluetooth: hci_event: Treat UNKNOWN_CONN_ID on disconnect as success Ludovico de Nittis
@ 2025-08-12 16:40   ` bluez.test.bot
  0 siblings, 0 replies; 6+ messages in thread
From: bluez.test.bot @ 2025-08-12 16:40 UTC (permalink / raw)
  To: linux-bluetooth, ludovico.denittis

[-- Attachment #1: Type: text/plain, Size: 2750 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/project/bluetooth/list/?series=990639

---Test result---

Test Summary:
CheckPatch                    PENDING   0.38 seconds
GitLint                       PENDING   0.29 seconds
SubjectPrefix                 PASS      0.19 seconds
BuildKernel                   PASS      25.83 seconds
CheckAllWarning               PASS      28.90 seconds
CheckSparse                   WARNING   32.02 seconds
BuildKernel32                 PASS      24.83 seconds
TestRunnerSetup               PASS      499.81 seconds
TestRunner_l2cap-tester       PASS      25.60 seconds
TestRunner_iso-tester         PASS      42.26 seconds
TestRunner_bnep-tester        PASS      6.07 seconds
TestRunner_mgmt-tester        FAIL      131.91 seconds
TestRunner_rfcomm-tester      PASS      9.51 seconds
TestRunner_sco-tester         PASS      15.02 seconds
TestRunner_ioctl-tester       PASS      10.27 seconds
TestRunner_mesh-tester        FAIL      11.40 seconds
TestRunner_smp-tester         PASS      8.73 seconds
TestRunner_userchan-tester    PASS      6.36 seconds
IncrementalBuild              PENDING   1.10 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:
net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 490, Passed: 483 (98.6%), Failed: 3, Not Run: 4

Failed Test Cases
Add Ext Advertising - Success 22 (LE -> off, Remove) Failed       0.136 seconds
Set Device ID - Power off and Power on               Failed       0.132 seconds
Set Device ID - SSP off and Power on                 Failed       0.124 seconds
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner
Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases
Mesh - Send cancel - 1                               Timed out    1.871 seconds
Mesh - Send cancel - 2                               Timed out    1.995 seconds
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/2] Bluetooth: hci_event: Fix connection state issues during suspend/resume
  2025-08-12 15:55 [PATCH v2 0/2] Bluetooth: hci_event: Fix connection state issues during suspend/resume Ludovico de Nittis
  2025-08-12 15:55 ` [PATCH v2 1/2] Bluetooth: hci_event: Treat UNKNOWN_CONN_ID on disconnect as success Ludovico de Nittis
  2025-08-12 15:55 ` [PATCH v2 2/2] Bluetooth: hci_event: Mark connection as closed during suspend disconnect Ludovico de Nittis
@ 2025-08-19 14:30 ` patchwork-bot+bluetooth
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+bluetooth @ 2025-08-19 14:30 UTC (permalink / raw)
  To: Ludovico de Nittis; +Cc: linux-bluetooth

Hello:

This series was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Tue, 12 Aug 2025 17:55:25 +0200 you wrote:
> This patch series addresses connection state synchronization issues
> between the Bluetooth controller and kernel during suspend/resume cycles.
> 
> The problem seems to be visible when using devices that very quickly try
> to send multiple reconnect events without waiting enough for the host
> to fully resume from suspend.
> 
> [...]

Here is the summary with links:
  - [v2,1/2] Bluetooth: hci_event: Treat UNKNOWN_CONN_ID on disconnect as success
    https://git.kernel.org/bluetooth/bluetooth-next/c/f6305e06185a
  - [v2,2/2] Bluetooth: hci_event: Mark connection as closed during suspend disconnect
    https://git.kernel.org/bluetooth/bluetooth-next/c/e090ee03a6ed

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-08-19 14:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12 15:55 [PATCH v2 0/2] Bluetooth: hci_event: Fix connection state issues during suspend/resume Ludovico de Nittis
2025-08-12 15:55 ` [PATCH v2 1/2] Bluetooth: hci_event: Treat UNKNOWN_CONN_ID on disconnect as success Ludovico de Nittis
2025-08-12 16:40   ` Bluetooth: hci_event: Fix connection state issues during suspend/resume bluez.test.bot
2025-08-12 15:55 ` [PATCH v2 2/2] Bluetooth: hci_event: Mark connection as closed during suspend disconnect Ludovico de Nittis
2025-08-19 14:30 ` [PATCH v2 0/2] Bluetooth: hci_event: Fix connection state issues during suspend/resume patchwork-bot+bluetooth
  -- strict thread matches above, loose matches on Subject: below --
2025-08-12 14:10 [PATCH 1/2] Bluetooth: hci_event: Treat UNKNOWN_CONN_ID on disconnect as success Ludovico de Nittis
2025-08-12 14:36 ` Bluetooth: hci_event: Fix connection state issues during suspend/resume 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