Skip to contentSkip to conversation

Bluetooth: enable context analysis

PATCH Applied Pauli Virtanen 3 participants 8 messages Jun 14 – Jun 22

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover Bluetooth: enable context analysis

v2:
- Add annotations to RFCOMM
- Enable analysis also for BNEP, RFCOMM, HIDP

***

Set up compiler context analysis that generate compiler warnings on problems that Clang -Wthread-safety can detect:

https://docs.kernel.org/dev-tools/context-analysis.html

Sparse locking analysis support was removed in commit 5b63d0ae94ccfd64dcbdb693d88eb3650eb3c64c, this is its successor.

Clang 22 is required, and likely in future Clang 23 [1] (unreleased, use snapshot eg from
https://mirrors.edge.kernel.org/pub/tools/llvm/files/prerelease/ )

This series enables the analysis and adds minimal annotations to remove all warnings.

In future, it probably is a good idea to make more use of it and add __must_hold, __guarded_by etc annotations.

Kernel test robot appears to be checking for these, but not sure in what trees [2]

BlueZ testbot doesn't check these currently but it's possible to add
https://github.com/bluez/action-ci/pull/4

[1] https://lore.kernel.org/all/177996424926.1039918.344230591161201072.tip-bot2@tip-bot2/
[2] https://lore.kernel.org/all/[email protected]/

Pauli Virtanen (5):
Bluetooth: af_bluetooth: Add minimal context analysis annotations
Bluetooth: hci_core: Add minimal context analysis annotations
Bluetooth: L2CAP: Add minimal context analysis annotations
Bluetooth: RFCOMM: Add minimal context analysis annotations
Bluetooth: enable context analysis

 drivers/bluetooth/Makefile    | 2 ++
 net/bluetooth/Makefile        | 2 ++
 net/bluetooth/af_bluetooth.c  | 7 +++++--
 net/bluetooth/bnep/Makefile   | 2 ++
 net/bluetooth/hci_core.c      | 3 +++
 net/bluetooth/hidp/Makefile   | 2 ++
 net/bluetooth/l2cap_sock.c    | 1 +
 net/bluetooth/rfcomm/Makefile | 2 ++
 net/bluetooth/rfcomm/sock.c   | 1 +
 9 files changed, 20 insertions(+), 2 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH v2 1/5 Bluetooth: af_bluetooth: Add minimal context analysis annotations

Add minimal compiler context analysis annotations, required for compilation to pass.

---
 net/bluetooth/af_bluetooth.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/bluetooth/af_bluetooth.c +5 -2
index bcbc11c9cb15..62b751203fb0 100644
@@ -209,6 +209,7 @@ bool bt_sock_linked(struct bt_sock_list *l, struct sock *s)
 EXPORT_SYMBOL(bt_sock_linked);
 
 void bt_accept_enqueue(struct sock *parent, struct sock *sk, bool bh)
+	__context_unsafe(/* conditional locking */)
 {
 	const struct cred *old_cred;
 	struct pid *old_pid;
@@ -826,7 +827,8 @@ EXPORT_SYMBOL(bt_sock_wait_ready);
 
 #ifdef CONFIG_PROC_FS
 static void *bt_seq_start(struct seq_file *seq, loff_t *pos)
-	__acquires(seq->private->l->lock)
+	__acquires_shared(&((struct bt_sock_list *)
+			    pde_data(file_inode(seq->file)))->lock)
 {
 	struct bt_sock_list *l = pde_data(file_inode(seq->file));
 
@@ -842,7 +844,8 @@ static void *bt_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 }
 
 static void bt_seq_stop(struct seq_file *seq, void *v)
-	__releases(seq->private->l->lock)
+	__releases_shared(&((struct bt_sock_list *)
+			    pde_data(file_inode(seq->file)))->lock)
 {
 	struct bt_sock_list *l = pde_data(file_inode(seq->file));
 
Signature · 1 line
2.54.0
#2 lore raw

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=1111252

---Test result---

Test Summary:

CheckPatch                    PASS      3.44 seconds
VerifyFixes                   PASS      0.07 seconds
VerifySignedoff               PASS      0.07 seconds
GitLint                       PASS      0.98 seconds
SubjectPrefix                 PASS      0.54 seconds
BuildKernel                   PASS      26.52 seconds
CheckAllWarning               PASS      29.29 seconds
CheckSparse                   PASS      28.58 seconds
BuildKernel32                 PASS      26.00 seconds
TestRunnerSetup               PASS      575.93 seconds
TestRunner_l2cap-tester       PASS      58.42 seconds
TestRunner_iso-tester         PASS      87.26 seconds
TestRunner_bnep-tester        PASS      19.12 seconds
TestRunner_mgmt-tester        FAIL      208.56 seconds
TestRunner_rfcomm-tester      PASS      25.04 seconds
TestRunner_sco-tester         PASS      32.00 seconds
TestRunner_ioctl-tester       PASS      25.73 seconds
TestRunner_mesh-tester        FAIL      25.83 seconds
TestRunner_smp-tester         PASS      24.88 seconds
TestRunner_userchan-tester    PASS      19.72 seconds
TestRunner_6lowpan-tester     FAIL      45.81 seconds
IncrementalBuild              PASS      33.20 seconds

Details
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner Output:
Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4

Failed Test Cases
Read Exp Feature - Success Failed 0.236 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    2.574 seconds
Mesh - Send cancel - 2                               Timed out    1.991 seconds

##############################
Test: TestRunner_6lowpan-tester - FAIL
Desc: Run 6lowpan-tester with test-runner Output:
Total: 8, Passed: 3 (37.5%), Failed: 5, Not Run: 0

Failed Test Cases

Client Connect - Disconnect                          Timed out    5.323 seconds
Client Recv Dgram - Success                          Timed out    4.988 seconds
Client Recv Raw - Success                            Timed out    5.015 seconds
Client Recv IPHC Dgram - Success                     Timed out    4.978 seconds
Client Recv IPHC Raw - Success                       Timed out    5.004 seconds

https://github.com/bluez/bluetooth-next/pull/314

---
Regards,
Linux Bluetooth

#3 lore raw

PATCH v2 2/5 Bluetooth: hci_core: Add minimal context analysis annotations

In reply to Pauli Virtanen

Add minimal compiler context analysis annotations, required for compilation to pass.

compiler-context-analysis.h doesn't have tools to deal with the conditional SRCU locking on return value used here, so just disable the analysis in places instead of refactoring, in order to not make code changes here.

---
 net/bluetooth/hci_core.c | 3 +++
 1 file changed, 3 insertions(+)
net/bluetooth/hci_core.c +3 -0
index 5ba9fe8261ec..d1e78ae7728e 100644
@@ -62,6 +62,7 @@ static DEFINE_IDA(hci_index_ida);
 /* Get HCI device by index.
  * Device is held on return. */
 static struct hci_dev *__hci_dev_get(int index, int *srcu_index)
+	__context_unsafe(/* conditional locking */)
 {
 	struct hci_dev *hdev = NULL, *d;
 
@@ -89,11 +90,13 @@ struct hci_dev *hci_dev_get(int index)
 }
 
 static struct hci_dev *hci_dev_get_srcu(int index, int *srcu_index)
+	__context_unsafe(/* conditional locking vs return */)
 {
 	return __hci_dev_get(index, srcu_index);
 }
 
 static void hci_dev_put_srcu(struct hci_dev *hdev, int srcu_index)
+	__context_unsafe(/* conditional locking vs return */)
 {
 	srcu_read_unlock(&hdev->srcu, srcu_index);
 	hci_dev_put(hdev);
Signature · 1 line
2.54.0
#4 lore raw

PATCH v2 3/5 Bluetooth: L2CAP: Add minimal context analysis annotations

In reply to Pauli Virtanen

Add minimal compiler context analysis annotations, required for compilation to pass.

Don't check complex conn->lock usage in l2cap_sock_shutdown(). The analysis cannot know that chan->conn pointer is never replaced by a different l2cap_conn.

---
 net/bluetooth/l2cap_sock.c | 1 +
 1 file changed, 1 insertion(+)
net/bluetooth/l2cap_sock.c +1 -0
index 4853f1b33449..8558a7071ff5 100644
@@ -1351,6 +1351,7 @@ static int __l2cap_wait_ack(struct sock *sk, struct l2cap_chan *chan)
 }
 
 static int l2cap_sock_shutdown(struct socket *sock, int how)
+	__context_unsafe(/* complex chan->conn locking */)
 {
 	struct sock *sk = sock->sk;
 	struct l2cap_chan *chan;
Signature · 1 line
2.54.0
#5 lore raw

PATCH v2 4/5 Bluetooth: RFCOMM: Add minimal context analysis annotations

In reply to Pauli Virtanen

Add minimal compiler context analysis annotations, required for compilation to pass.

---
 net/bluetooth/rfcomm/sock.c | 1 +
 1 file changed, 1 insertion(+)
net/bluetooth/rfcomm/sock.c +1 -0
index feb302a491fa..958081adb9b5 100644
@@ -60,6 +60,7 @@ static void rfcomm_sk_data_ready(struct rfcomm_dlc *d, struct sk_buff *skb)
 }
 
 static void rfcomm_sk_state_change(struct rfcomm_dlc *d, int err)
+	__must_hold(&d->lock)
 {
 	struct sock *sk = d->owner, *parent;
 
Signature · 1 line
2.54.0
#6 lore raw

PATCH v2 5/5 Bluetooth: enable context analysis

In reply to Pauli Virtanen

Enable compiler context analysis for Bluetooth subsystem and drivers.

---
 drivers/bluetooth/Makefile    | 2 ++
 net/bluetooth/Makefile        | 2 ++
 net/bluetooth/bnep/Makefile   | 2 ++
 net/bluetooth/hidp/Makefile   | 2 ++
 net/bluetooth/rfcomm/Makefile | 2 ++
 5 files changed, 10 insertions(+)
drivers/bluetooth/Makefile +2 -0
index bafc26250b63..e6b1c1180d1d 100644
@@ -50,3 +50,5 @@ hci_uart-$(CONFIG_BT_HCIUART_AG6XX)	+= hci_ag6xx.o
 hci_uart-$(CONFIG_BT_HCIUART_MRVL)	+= hci_mrvl.o
 hci_uart-$(CONFIG_BT_HCIUART_AML)	+= hci_aml.o
 hci_uart-objs				:= $(hci_uart-y)
+
+CONTEXT_ANALYSIS := y
net/bluetooth/Makefile +2 -0
index 41049b280887..ff466ea97436 100644
@@ -25,3 +25,5 @@ bluetooth-$(CONFIG_BT_MSFTEXT) += msft.o
 bluetooth-$(CONFIG_BT_AOSPEXT) += aosp.o
 bluetooth-$(CONFIG_BT_DEBUGFS) += hci_debugfs.o
 bluetooth-$(CONFIG_BT_SELFTEST) += selftest.o
+
+CONTEXT_ANALYSIS := y
net/bluetooth/bnep/Makefile +2 -0
index 8af9d56bb012..f42015cc3245 100644
@@ -6,3 +6,5 @@
 obj-$(CONFIG_BT_BNEP) += bnep.o
 
 bnep-objs := core.o sock.o netdev.o
+
+CONTEXT_ANALYSIS := y
net/bluetooth/hidp/Makefile +2 -0
index f41b0aa02b23..53e139e41bdc 100644
@@ -6,3 +6,5 @@
 obj-$(CONFIG_BT_HIDP) += hidp.o
 
 hidp-objs := core.o sock.o
+
+CONTEXT_ANALYSIS := y
net/bluetooth/rfcomm/Makefile +2 -0
index 593e5c48c131..15f909f40f25 100644
@@ -7,3 +7,5 @@ obj-$(CONFIG_BT_RFCOMM) += rfcomm.o
 
 rfcomm-y			:= core.o sock.o
 rfcomm-$(CONFIG_BT_RFCOMM_TTY)	+= tty.o
+
+CONTEXT_ANALYSIS := y
Signature · 1 line
2.54.0
#7 lore raw
In reply to Pauli Virtanen
This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This series was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 10 lines · On Sun, 14 Jun 2026 13:27:01 +0300 you wrote:

v2:
- Add annotations to RFCOMM
- Enable analysis also for BNEP, RFCOMM, HIDP

***

Set up compiler context analysis that generate compiler warnings on problems that Clang -Wthread-safety can detect:

[...]

Here is the summary with links:
- [v2,1/5] Bluetooth: af_bluetooth: Add minimal context analysis annotations

    https://git.kernel.org/bluetooth/bluetooth-next/c/077b1a4fdaa3
  - [v2,2/5] Bluetooth: hci_core: Add minimal context analysis annotations
    https://git.kernel.org/bluetooth/bluetooth-next/c/2f798c97b743
  - [v2,3/5] Bluetooth: L2CAP: Add minimal context analysis annotations
    https://git.kernel.org/bluetooth/bluetooth-next/c/a9cdc2959c77
  - [v2,4/5] Bluetooth: RFCOMM: Add minimal context analysis annotations
    https://git.kernel.org/bluetooth/bluetooth-next/c/14cb114880c7
  - [v2,5/5] Bluetooth: enable context analysis
    https://git.kernel.org/bluetooth/bluetooth-next/c/9218167503ef

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html