From 0e7c9201e819e724e9c1bc6776a83523c76dede2 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Sun, 15 Nov 2026 15:20:46 +0000 Subject: [PATCH 1/4] telemetry: do not include rtos/timer.h in telemetry.h Commit 20206e3f9 ("telemetry: headers: add extended TEL2 and PMW2 window definitions") added rtos/timer.h to telemetry.h. telemetry.h is included by component.h, and rtos/timer.h includes sof/platform.h, so every component source got the platform headers back: on PTL the user-space sources that include kernel-only headers went from 28 to 140, undoing most of the header untangling of #11306 Phase 1. Nothing in telemetry.h needs the include. It only names sof_cycle_get_64() in the telemetry_timestamp macro, and the two sources that expand that macro, component.c and zephyr_ll.c, already get rtos/timer.h, as they did before that commit. No functional change. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- src/include/sof/debug/telemetry/telemetry.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/include/sof/debug/telemetry/telemetry.h b/src/include/sof/debug/telemetry/telemetry.h index 109916414781..7f4fea9a3e72 100644 --- a/src/include/sof/debug/telemetry/telemetry.h +++ b/src/include/sof/debug/telemetry/telemetry.h @@ -17,7 +17,6 @@ #include #include #ifdef __ZEPHYR__ -#include #include #include #endif From 0ecdce60787f9a0c40db46059d24f89f1c5c6190 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Sun, 15 Nov 2026 15:22:41 +0000 Subject: [PATCH 2/4] scripts: kernel_user_partition: check all user-space sources The manifest's user-space source list was written before the kernel code moved to src/kernel. Now that it has, every source in src/ outside of src/kernel is user-space code: that also covers the user halves of the Phase 3 splits in src/ipc, src/schedule, src/lib and src/debug, which were not checked. The legacy host and DAI drivers stay excluded until they are deleted. The checked builds now report 11 more user-space sources that include kernel-only headers: the user halves of the IPC, scheduler, DMA and DAI splits, the notifier and a tester module. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- scripts/kernel_user_partition.txt | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/scripts/kernel_user_partition.txt b/scripts/kernel_user_partition.txt index 95b4bc0ae99f..728839ea1971 100644 --- a/scripts/kernel_user_partition.txt +++ b/scripts/kernel_user_partition.txt @@ -14,20 +14,14 @@ # [zephyr-kernel-headers] which is relative to ZEPHYR_BASE. "*" also # matches "/". -# Sources that must be user-space safe. +# Sources that must be user-space safe: everything in src/ that is not +# kernel code. Kernel code is in src/kernel/ and the zephyr/ directory. [user-sources] -src/audio/* -src/math/* -src/module/* -src/samples/* -src/ipc/ipc-helper.c -src/ipc/ipc4/ams_helpers.c -src/ipc/ipc4/dai.c -src/ipc/ipc4/notification-user.c -src/lib/objpool.c +src/* -# Kernel sources inside the directories above. +# Kernel sources inside src/: src/kernel/ and the legacy drivers. [not-user-sources] +src/kernel/* src/audio/dai-legacy.c src/audio/host-legacy.c From b3434dbd740ac916014a104dced7f7babf2c980f Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Sun, 15 Nov 2026 15:20:46 +0000 Subject: [PATCH 3/4] scripts: check_kernel_includes: add a leak baseline Add a [leak-baseline] section to the partition manifest, listing the 41 user-space sources that still include kernel-only headers in the CI configurations and with the user-space overlays. With --strict, the checker now only fails when a user-space source outside of the baseline includes a kernel-only header, so it can be enforced before the remaining leaks are removed, and new leaks are caught when they are added. Baseline sources that were built without leaks are reported, so that they can be dropped from the list once they are clean in every configuration. Signed-off-by: Liam Girdwood Co-Authored-By: Claude Opus 5.5 --- scripts/check_kernel_includes.py | 47 +++++++++++++++++++++++++------ scripts/kernel_user_partition.txt | 47 +++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/scripts/check_kernel_includes.py b/scripts/check_kernel_includes.py index 3db354bbfd7d..d4e9a639043e 100755 --- a/scripts/check_kernel_includes.py +++ b/scripts/check_kernel_includes.py @@ -16,9 +16,13 @@ source against the kernel-only header patterns in scripts/kernel_user_partition.txt. -By default it only reports. With --strict it exits with an error when any -user-space object includes a kernel-only header; that is meant for the -later phases of the partition work, once the leaks have been removed. +By default it only reports. With --strict it exits with an error when a +user-space object includes a kernel-only header, unless its source is +listed in the manifest's [leak-baseline] section. The baseline lists the +sources that still have leaks to remove; it may only shrink, so new +leaks fail the build. Baseline sources that no longer leak in the +checked builds are reported, so that they can be dropped from the list +once they are clean in every configuration. Usage: check_kernel_includes.py [--strict] [--summary] [...] @@ -88,13 +92,15 @@ def relative_to(path, root): def check_build(build_dir, manifest, sof_root, zephyr_base): - """Return {user source: set(kernel headers)} for one build directory.""" + """Return ({user source: set(kernel headers)}, set(user sources)) for one + build directory.""" user_src = manifest['user-sources'] not_user = manifest['not-user-sources'] kernel_hdr = manifest['kernel-headers'] zephyr_hdr = manifest['zephyr-kernel-headers'] leaks = defaultdict(set) + built = set() if not os.path.exists(os.path.join(build_dir, 'build.ninja')): sys.exit(f'{build_dir}: not a ninja build directory') @@ -103,6 +109,7 @@ def check_build(build_dir, manifest, sof_root, zephyr_base): rel_src = relative_to(src, sof_root) if src else None if rel_src is None or not matches(rel_src, user_src) or matches(rel_src, not_user): continue + built.add(rel_src) for dep in deps: rel = relative_to(dep, sof_root) if rel is not None and matches(rel, kernel_hdr): @@ -112,7 +119,7 @@ def check_build(build_dir, manifest, sof_root, zephyr_base): rel = relative_to(dep, zephyr_base) if rel is not None and matches(rel, zephyr_hdr): leaks[rel_src].add('zephyr/' + rel) - return leaks + return leaks, built def main(): @@ -124,7 +131,8 @@ def main(): parser.add_argument('--zephyr-base', default=os.environ.get('ZEPHYR_BASE', os.path.join(os.path.dirname(SOF_ROOT), 'zephyr'))) parser.add_argument('--strict', action='store_true', - help='exit with an error if any kernel-only header is included') + help='exit with an error if a source outside of the baseline ' + 'includes a kernel-only header') parser.add_argument('--summary', action='store_true', help='only print per-header counts, not every source file') args = parser.parse_args() @@ -133,10 +141,13 @@ def main(): zephyr_base = args.zephyr_base if os.path.isdir(args.zephyr_base) else None leaks = defaultdict(set) + built = set() for build_dir in args.build_dirs: - for src, hdrs in check_build(build_dir, manifest, args.sof_root, - zephyr_base).items(): + build_leaks, build_srcs = check_build(build_dir, manifest, args.sof_root, + zephyr_base) + for src, hdrs in build_leaks.items(): leaks[src] |= hdrs + built |= build_srcs by_header = defaultdict(set) for src, hdrs in leaks.items(): @@ -156,7 +167,25 @@ def main(): print(f'{len(leaks)} user-space source files include {len(by_header)} ' f'kernel-only headers') - if args.strict and leaks: + baseline = manifest['leak-baseline'] + new_leaks = sorted(src for src in leaks if not matches(src, baseline)) + fixed = sorted(src for src in built - leaks.keys() if matches(src, baseline)) + + if fixed: + print('\nBaseline sources built without leaks (drop them from ' + '[leak-baseline] once they are clean in every configuration):') + for src in fixed: + print(f'\t{src}') + + if new_leaks: + print('\nUser-space sources including kernel-only headers that are not in ' + '[leak-baseline]:') + for src in new_leaks: + print(f'{src}:') + for hdr in sorted(leaks[src]): + print(f'\t{hdr}') + + if args.strict and new_leaks: return 1 return 0 diff --git a/scripts/kernel_user_partition.txt b/scripts/kernel_user_partition.txt index 728839ea1971..fc3894b9e9c9 100644 --- a/scripts/kernel_user_partition.txt +++ b/scripts/kernel_user_partition.txt @@ -59,3 +59,50 @@ zephyr/include/sof/lib/vpage.h kernel/include/* include/zephyr/drivers/dma.h include/zephyr/pm/device_runtime.h + +# User-space sources that still include kernel-only headers, removed one +# by one by the partition work (#11306). With --strict, a leak in any +# other user-space source is an error, so this list must only shrink. +# It covers the CI build configurations and the user-space overlays. +[leak-baseline] +src/audio/asrc/asrc.c +src/audio/chain_dma.c +src/audio/component.c +src/audio/copier/copier.c +src/audio/copier/copier_dai.c +src/audio/copier/copier_gain.c +src/audio/copier/copier_host.c +src/audio/copier/copier_ipcgtw.c +src/audio/dai-zephyr.c +src/audio/data_blob.c +src/audio/host-zephyr.c +src/audio/intel_uaol.c +src/audio/kpb.c +src/audio/module_adapter/iadk/kpb_service.cpp +src/audio/module_adapter/iadk/system_agent.cpp +src/audio/module_adapter/iadk/timestamping_service_provider.cpp +src/audio/module_adapter/library/native_system_service.c +src/audio/module_adapter/module_adapter_ipc3.c +src/audio/module_adapter/module_adapter_ipc4.c +src/audio/pipeline/pipeline-graph.c +src/audio/pipeline/pipeline-params.c +src/audio/pipeline/pipeline-schedule.c +src/audio/pipeline/pipeline-stream.c +src/audio/pipeline/pipeline-xrun.c +src/audio/volume/volume.c +src/audio/volume/volume_ipc4.c +src/debug/tester/tester_simple_dram_test.c +src/ipc/ipc-common.c +src/ipc/ipc-helper.c +src/ipc/ipc4/dai.c +src/ipc/ipc4/handler-user.c +src/ipc/ipc4/helper.c +src/lib/dai.c +src/lib/dma.c +src/lib/notifier.c +src/samples/audio/detect_test.c +src/schedule/zephyr_domain.c +src/schedule/zephyr_dp_schedule.c +src/schedule/zephyr_dp_schedule_application.c +src/schedule/zephyr_dp_schedule_thread.c +src/schedule/zephyr_ll.c From 2d08b0d481027a03a0b897d665e6620e08e780d5 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Sun, 15 Nov 2026 15:20:46 +0000 Subject: [PATCH 4/4] ci: zephyr: fail on new kernel-only includes from user-space code Run the kernel/user-space include checker with --strict, so that the Linux build jobs fail when a user-space source that is not in the checker's leak baseline includes a kernel-only header. Such a regression went unnoticed with the report alone: one header change brought the platform headers back into every component source. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Liam Girdwood --- .github/workflows/zephyr.yml | 10 +++++++--- src/kernel/README.md | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/zephyr.yml b/.github/workflows/zephyr.yml index 9751b628a3c3..53defeebd1dc 100644 --- a/.github/workflows/zephyr.yml +++ b/.github/workflows/zephyr.yml @@ -235,18 +235,22 @@ jobs: --no-tarball \ ${{ matrix.build_opts }} ${{ matrix.IPC_platforms }} - # Informational only for now, see scripts/check_kernel_includes.py - - name: kernel/user-space include report + # Fails when a user-space source outside of the [leak-baseline] in + # scripts/kernel_user_partition.txt includes a kernel-only header, + # see scripts/check_kernel_includes.py + - name: kernel/user-space include check if: always() env: PLATFORMS: ${{ matrix.IPC_platforms }} run: | + rc=0 for p in $PLATFORMS; do test -f build-"$p"/build.ninja || continue printf '\n==== %s ====\n' "$p" ZEPHYR_BASE="$(pwd)"/zephyr \ - python3 sof/scripts/check_kernel_includes.py --summary build-"$p" || true + python3 sof/scripts/check_kernel_includes.py --strict --summary build-"$p" || rc=1 done + exit $rc - name: Upload build artifacts uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 diff --git a/src/kernel/README.md b/src/kernel/README.md index fd92a6369716..4c7c01de4be0 100644 --- a/src/kernel/README.md +++ b/src/kernel/README.md @@ -23,6 +23,8 @@ Zephyr builds everything below this directory into the `sof_kernel` library inst library for this directory tree, so the CMake files of moved directories do not change. Their Kconfig files are sourced from [`Kconfig`](Kconfig). -Code here may use kernel-only headers. User-space code must not call into it directly; the +Code here may use kernel-only headers. User-space code must not call into it directly. The checker in `scripts/check_kernel_includes.py` reports kernel-only includes from user-space -sources. +sources, and CI fails when one is added. The user-space sources that still include +kernel-only headers are listed in the `[leak-baseline]` section of +`scripts/kernel_user_partition.txt`; that list must only shrink.