Repository navigation
kernel/user partition, Phase 4 part 7: CI check against <sof/kernel/...> in user-space code - #11489
Conversation
lgirdwood
left a comment
There was a problem hiding this comment.
Code Review Summary (Commits 54ae52a009..2c714596f4)
Clean, fast source-tree enforcement (12s in codestyle.yml) and nice cleanup of src/debug/panic.c plus classifying the 4 legacy LL scheduling domains (dma_multi_chan_domain.c, dma_single_chan_domain.c, ll_schedule_xtos.c, zephyr_dma_domain.c) under [not-user-sources].
Main Finding — Header Coverage Gap in --sources
[user-headers]+check_sources()(scripts/kernel_user_partition.txt,scripts/check_kernel_includes.py):[user-headers]currently lists onlysrc/include/*andsrc/platform/*(286headers), skipping313module-private headers colocated undersrc/(src/audio/**/*.h,src/debug/**/*.h,src/math/**/*.h, etc.) and27user-space headers inzephyr/include/(rtos/alloc.h,sof/lib/dai.h,sof/lib/dma.h,sof/lib/sof_dma.h, etc.). Expanding[user-headers]tosrc/*+zephyr/include/*and excludingnot_useralongsidekernel_hdrchecks all626user-space headers with zero false positives (see inline suggestions).
Minor Polish
scripts/check_kernel_includes.py:out.splitlines()+ path normalization insource_files(), and rejecting--sourcescombined with<build-dir>.src/debug/panic.cremoval: Leavessrc/include/sof/debug/backtrace.h(+src/kernel/arch/host/include/arch/debug/backtrace.h) anddump_panicinfo()/panic_dump()inposix/include/rtos/panic.hwith zero remaining users.src/kernel/README.md: Include--strictin thecheck_kernel_includes.py --sources --strictcommand reference.
| [user-headers] | ||
| src/include/* | ||
| src/platform/* |
There was a problem hiding this comment.
Coverage gap: Listing only src/include/* and src/platform/* checks 286 headers and skips:
313subsystem/module-local headers undersrc/(src/audio/**/*.h,src/debug/**/*.h,src/math/**/*.h, etc. — including optional/LLEXT modules not built in default CI configs).27user-space headers inzephyr/include/(rtos/alloc.h,rtos/cache.h,sof/lib/cpu.h,sof/lib/dai.h,sof/lib/dma.h,sof/lib/sof_dma.h,sof/trace/trace.h, etc. —[kernel-headers]below already lists the kernel-only subset ofzephyr/include/*).
Paired with excluding not_user (src/kernel/*) in check_sources(), expanding this to src/* + zephyr/include/* checks all 626 user-space headers with 0 false positives:
| [user-headers] | |
| src/include/* | |
| src/platform/* | |
| [user-headers] | |
| src/* | |
| zephyr/include/* |
There was a problem hiding this comment.
Done. [user-headers] is now src/* and zephyr/include/*. With the kernel sources and the kernel-only headers excluded, that is 626 headers, and the check finds nothing on the tree. A test include added to a module-local header (copier/copier.h) and to a zephyr/include header (rtos/alloc.h) is reported and fails the check.
| elif not (rel.endswith('.h') and matches(rel, user_hdr)) or \ | ||
| matches(rel, kernel_hdr): | ||
| continue |
There was a problem hiding this comment.
Companion to expanding [user-headers] to src/* and zephyr/include/* — exclude not_user (src/kernel/*) as well as kernel_hdr (and check .hpp alongside .h):
| elif not (rel.endswith('.h') and matches(rel, user_hdr)) or \ | |
| matches(rel, kernel_hdr): | |
| continue | |
| elif not (rel.endswith(('.h', '.hpp')) and matches(rel, user_hdr)) or \ | |
| matches(rel, not_user) or matches(rel, kernel_hdr): | |
| continue |
There was a problem hiding this comment.
Done, as suggested: .hpp headers are checked too, and the kernel sources ([not-user-sources]) are excluded as well as the kernel-only headers.
| try: | ||
| out = subprocess.run(['git', '-C', sof_root, 'ls-files'], | ||
| check=True, capture_output=True, text=True).stdout | ||
| return out.split() | ||
| except (OSError, subprocess.CalledProcessError): | ||
| files = [] | ||
| for top, _, names in os.walk(sof_root): | ||
| files += [os.path.relpath(os.path.join(top, n), sof_root) for n in names] | ||
| return files |
There was a problem hiding this comment.
Nit: out.split() splits on spaces/tabs if a path ever contains whitespace (out.splitlines() matches ninja_deps() above), and in the os.walk fallback normalizing os.sep (/ on Windows) + pruning .git / build* avoids mismatches or scanning in-tree build directories:
| try: | |
| out = subprocess.run(['git', '-C', sof_root, 'ls-files'], | |
| check=True, capture_output=True, text=True).stdout | |
| return out.split() | |
| except (OSError, subprocess.CalledProcessError): | |
| files = [] | |
| for top, _, names in os.walk(sof_root): | |
| files += [os.path.relpath(os.path.join(top, n), sof_root) for n in names] | |
| return files | |
| try: | |
| out = subprocess.run(['git', '-C', sof_root, 'ls-files'], | |
| check=True, capture_output=True, text=True).stdout | |
| return out.splitlines() | |
| except (OSError, subprocess.CalledProcessError): | |
| files = [] | |
| for top, dirs, names in os.walk(sof_root): | |
| dirs[:] = [d for d in dirs if d != '.git' and not d.startswith('build')] | |
| files += [os.path.relpath(os.path.join(top, n), sof_root).replace(os.sep, '/') | |
| for n in names] | |
| return files |
There was a problem hiding this comment.
Done: git ls-files output is split by lines, and the os.walk() fallback normalizes the separator and skips .git and build directories.
| if args.sources: | ||
| found = check_sources(manifest, args.sof_root) |
There was a problem hiding this comment.
Nit: Passing both --sources and <build-dir> currently ignores build_dirs silently:
| if args.sources: | |
| found = check_sources(manifest, args.sof_root) | |
| if args.sources: | |
| if args.build_dirs: | |
| parser.error('--sources cannot be combined with build directories') | |
| found = check_sources(manifest, args.sof_root) |
There was a problem hiding this comment.
Done: --sources with build directories is now an argument error.
| #include <sof/debug/backtrace.h> | ||
| #include <sof/debug/debug.h> | ||
| #include <rtos/panic.h> |
There was a problem hiding this comment.
Follow-up / optional cleanup: Removing src/debug/panic.c leaves zero remaining users in the tree for:
src/include/sof/debug/backtrace.h(which sits in user-spacesrc/include/while wrapping<arch/debug/backtrace.h>) andsrc/kernel/arch/host/include/arch/debug/backtrace.hdump_panicinfo()andpanic_dump()prototypes inposix/include/rtos/panic.h(lines 33–35) plus<arch/debug/panic.h>/src/kernel/arch/host/include/arch/debug/panic.h(src/kernel/platform/library/panic.conly defines__panic()).
There was a problem hiding this comment.
Done in a new commit, "debug: remove the panic declarations left unused by panic.c". It removes sof/debug/backtrace.h with the host arch/debug/backtrace.h, the host arch/debug/panic.h (its arch_dump_regs() has no callers; the arch_dump_regs_a() that the coredump reader uses is a different function), and the dump_panicinfo() and panic_dump() prototypes in the host rtos/panic.h. The host library and its unit tests build and pass for all defconfigs.
| User-space code must not include anything from here: the `codestyle` CI workflow runs | ||
| `scripts/check_kernel_includes.py --sources`, which fails when a user-space source or header | ||
| includes `<sof/kernel/...>`. |
There was a problem hiding this comment.
Nit: Include --strict here to match codestyle.yml (without --strict, --sources exits 0 even when includes are found):
| User-space code must not include anything from here: the `codestyle` CI workflow runs | |
| `scripts/check_kernel_includes.py --sources`, which fails when a user-space source or header | |
| includes `<sof/kernel/...>`. | |
| User-space code must not include anything from here: the `codestyle` CI workflow runs | |
| `scripts/check_kernel_includes.py --sources --strict`, which fails when a user-space source or | |
| header includes `<sof/kernel/...>`. |
There was a problem hiding this comment.
Done, the README now shows --sources --strict.
src/debug/panic.c is the XTOS panic handler. Its build rules went with the XTOS support in commit e68dfe9 ("build: remove XTOS-specific sections from cmake lists"), and the host library has its own panic.c, so nothing builds it. Remove it. No functional change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
With the XTOS panic handler gone, nothing includes sof/debug/backtrace.h or the host arch/debug/backtrace.h it wraps, nothing calls the host arch_dump_regs() in arch/debug/panic.h, and dump_panicinfo() and panic_dump(), declared in the host rtos/panic.h, have no definition. Remove them. The host library keeps __panic() and the assertions. No functional change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
The DMA single and multi channel and the Zephyr DMA LL scheduling domains, and the XTOS LL scheduler that ACP 6.0 still builds, set up interrupts and timers and include sof/kernel/platform.h. Like the legacy host and DAI drivers, they are kernel code that goes when the remaining platforms move to the Zephyr native drivers. Classify them as kernel sources. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
The kernel-only headers are moving to src/kernel/include, included as <sof/kernel/...>. Add a --sources mode that checks the source tree, without build directories, for such includes in user-space sources and headers. The headers are listed in the new [user-headers] manifest section: everything in src/ and zephyr/include, apart from the kernel sources and the kernel-only headers, that is over 600 headers today, including the ones local to modules that no CI configuration builds. This is the "no <sof/kernel/ in user-space code" rule of thesofproject#11306. It also covers code that no checked build configuration compiles, and there is nothing to baseline: no user-space code includes them today. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Run the include checker on the source tree in the codestyle workflow, so that a pull request that includes a header from src/kernel/include in user-space code fails without waiting for the firmware builds, and also when no CI configuration compiles the file. Describe it in the src/kernel README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
2c71459 to
6094409
Compare
PR 11489: test resultsRun date: 2026-11-20 13:56 UTC Tested commit: 6094409f9b8f02ecdcdb7a28df157d3e29b5ff53 |
|
Unrelated CI issue. |
Phase 4 of #11306 (kernel / user-space partition), seventh part: enforce the "no
<sof/kernel/...>in user-space code" rule on the source tree, as the issue plans ("add a checkpatch rule against<sof/kernel/in user dirs"). SOF's CI does not run checkpatch, so this is a mode of the include checker that runs in thecodestyleworkflow instead.Why
The build-based include check (#11464) only sees what the CI configurations compile. Since #11487, kernel-only headers in
src/kernel/includeare included as<sof/kernel/...>, so a kernel-only include is visible in the source. That makes a source-tree check cheap and exact:Patches
debug: removesrc/debug/panic.c, the XTOS panic handler. Nothing builds it since the XTOS build rules were removed in e68dfe9, and the host library has its ownpanic.c. The source check found it, because it includes<sof/kernel/platform.h>.debug: remove the panic declarations that onlypanic.cused:sof/debug/backtrace.h, the hostarch/debug/backtrace.handarch/debug/panic.h, and thedump_panicinfo()andpanic_dump()prototypes in the hostrtos/panic.h, which have no definition.scripts: kernel_user_partition: classify the legacy LL scheduling domains (DMA single and multi channel, the Zephyr DMA domain, and the XTOS LL scheduler that ACP 6.0 still builds) as kernel sources.<sof/kernel/platform.h>.scripts: check_kernel_includes: add a--sourcesmode, which checks the source tree for<sof/kernel/...>includes.[user-headers]manifest section: every.hand.hppinsrc/andzephyr/includeapart from the kernel sources and the kernel-only headers. That is 626 headers today, including those local to modules that no CI configuration builds.--strictfails when one is added.ci: codestyle: runcheck_kernel_includes.py --sources --strictin a newkernel-includesjob, and describe it in thesrc/kernelREADME.Install rules
The issue's item "install rules install only the user include set" needs no change. Only the host library installs headers: it installs the
sof_public_headersinclude directories, and #11487 putsrc/kernel/includeonsof_optionsinstead. So the kernel-only headers are not installed. The host platform headers still are, but the host build is not partitioned, and its users, the testbench and plugin, need them.Functional change
None.
Testing
<sof/kernel/...>include added to a user-space source (volume.c), a user-space header (component.h), a module-local header (copier/copier.h) and azephyr/includeheader (rtos/alloc.h), it reports each and fails;--sourcesis an error.--strict, it still passes for the 12 CI build configurations and the other configurations below, with the same 16 baseline sources.codestyle.ymlpassesyamllintwith the workflow's settings.CONFIG_SOF_USERSPACE_PROXY=n;os_linux_overlay.conf;llext_relocatable.conf;app/debug_stream_overlay.conf, and PTL with that overlay and user-space LL.SYS_INIT()order), and the per-function disassembly. No object changes at any commit. The only image difference issof_init()on imx8m_cm7, imx93 and imx95, which embeds the git hash.All of the above, and the documentation build as in CI (no warnings, at every commit), was run on 412057e (current main).
Changes since the last push
[user-headers]covers all user-space headers insrc/andzephyr/include, and.hppfiles: 626 instead of 286, with no findings.source_files()splitsgit ls-filesby lines, and its fallback normalizes the path separator and skips.gitand build directories.--sourcescannot be combined with build directories.src/kernelREADME shows--strict.panic.cused.🤖 Generated with Claude Code