Skip to content

ci: add CheckKernelLLVM#4

Open
pv wants to merge 3 commits into
bluez:mainfrom
pv:llvm
Open

ci: add CheckKernelLLVM#4
pv wants to merge 3 commits into
bluez:mainfrom
pv:llvm

Conversation

@pv
Copy link
Copy Markdown
Contributor

@pv pv commented Apr 18, 2026

Add task to build kernel with LLVM + checking context analysis warnings:
https://docs.kernel.org/dev-tools/context-analysis.html

This feature does static compile time checking of the __must_hold,
__guarded_by etc annotations now used by kernel, as support for Sparse locking analysis was removed.

Kernel CONTEXT_ANALYSIS requires LLVM 22 (and apparently LLVM 23 in near future), so this also needs someone to update the blueztestbot docker image: BluezTestBot/docker-bluez-build#2


Also add new entrypoint.sh command to run the Docker image locally, so that it is possible to test it without having BlueZ github secrets.

Example:

$ export IMG=b4ce213a0d6ba1e743509dba866c865ee01399657c3324f9bc747c23a7675e6c
$ git clone --depth 1 https://github.com/bluez/bluetooth-next work/src
$ docker run --volume $PWD/work:/work/base:O $IMG localci kernel bluez/bluetooth-next 103
...
Test Summary:
CheckPatch                    PASS      3.08 seconds
GitLint                       FAIL      1539.75 seconds
SubjectPrefix                 PASS      0.00 seconds
BuildKernel                   PASS      43.56 seconds
CheckAllWarning               PASS      76.82 seconds
CheckSparse                   WARNING   142.24 seconds
BuildKernel32                 PASS      96.15 seconds
CheckKernelLLVM               WARNING   88.40 seconds
TestRunnerSetup               PASS      790.86 seconds
TestRunner_sco-tester         PASS      24.53 seconds
IncrementalBuild              PASS      108.80 seconds
...
##############################
Test: CheckKernelLLVM - WARNING
Desc: Build kernel with LLVM + context analysis
Output:
net/bluetooth/sco.c:266:7: warning: calling function 'sco_sock_hold' requires holding spinlock 'sco_conn_hold_unless_zero(conn).lock' exclusively [-Wthread-safety-analysis]  266 |         sk = sco_sock_hold(conn);      |              ^1 warning generated.

... in the case where we had the following in the kernel source to demonstrate an error

diff --git a/net/bluetooth/Makefile b/net/bluetooth/Makefile
index a7eede7616d..5fcc93fdd54 100644
--- a/net/bluetooth/Makefile
+++ b/net/bluetooth/Makefile
@@ -26,3 +26,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_sco.o := y
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 3a5479538e8..05257c55517 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -129,6 +129,7 @@ static struct sco_conn *sco_conn_hold_unless_zero(struct sco_conn *conn)
 }
 
 static struct sock *sco_sock_hold(struct sco_conn *conn)
+       __must_hold(&conn->lock)
 {
        if (!conn || !bt_sock_linked(&sco_sk_list, conn->sk))
                return NULL;
@@ -262,8 +263,8 @@ static void sco_conn_del(struct hci_conn *hcon, int err)
 
        BT_DBG("hcon %p conn %p, err %d", hcon, conn, err);
 
-       sco_conn_lock(conn);
        sk = sco_sock_hold(conn);
+       sco_conn_lock(conn);
        sco_conn_unlock(conn);
        sco_conn_put(conn);

pv added 3 commits April 18, 2026 17:52
Add task to build kernel with LLVM + checking context analysis warnings:
https://docs.kernel.org/dev-tools/context-analysis.html

This feature does static compile time checking of the __must_hold,
__guarded_by etc annotations now used by kernel.
Add localci command so that the docker CI can be tested locally without
secrets.

Example:

git clone --depth 1 https://github.com/bluez/bluetooth-next work/src
docker run --volume $PWD/work:/work/base:O $IMG localci kernel bluez/bluetooth-next 103
Add option for setting make -j option value.
Comment thread ci.py
sys.exit(1)

if args.jobs == "auto":
args.jobs = str(os.cpu_count())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No super found of the jobs variable being either a string or an int.

Comment thread ci.py

if args.jobs == "auto":
args.jobs = str(os.cpu_count())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the default should also be set here? That's where it's advertised.

Comment thread entrypoint.sh
*)
echo "Unknown TASK: $TASK"
eixt 1
exit 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed this separately in #5

Comment thread entrypoint.sh
if ! test -d "$GITHUB_WORKSPACE/$BASE_DIR/src"; then
echo "Cloning https://github.com/$GITHUB_REPOSITORY"
git clone --depth 1 "https://github.com/$GITHUB_REPOSITORY" \
$GITHUB_WORKSPACE/$BASE_DIR/src
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll probably want to run shellcheck on that portion of the script, see also #5 which does that for the rest of the script.

Comment thread entrypoint.sh

set -e

export PATH=/opt/llvm/bin:$PATH
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't be needed if we used llvm from the distribution, see BluezTestBot/docker-bluez-build#2 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as the CONTEXT_ANALYSIS is a bit of a moving target vs Clang versions, I think it's better to pick manually the compiler we want

Comment thread ci/checkallwarning.py
self.dry_run = dry_run

if make_params:
make_params = ['W=1'] + make_params
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know if it's too early to ask for that, but would it be possible to only have "generic" make params be added to the make params? I'm thinking of the (eventual) meson support which wouldn't know what to do with W=1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants