Skip to content

kernel/user partition, Phase 4 part 7: CI check against <sof/kernel/...> in user-space code - #11489

Merged
lgirdwood merged 5 commits into
thesofproject:mainfrom
lgirdwood:kernel-user/phase4g
Nov 20, 2026
Merged

lgirdwood merged 5 commits into
thesofproject:mainfrom
lgirdwood:kernel-user/phase4g

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

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 the codestyle workflow instead.

Why

The build-based include check (#11464) only sees what the CI configurations compile. Since #11487, kernel-only headers in src/kernel/include are included as <sof/kernel/...>, so a kernel-only include is visible in the source. That makes a source-tree check cheap and exact:

  • it runs without building anything, so a pull request gets the result quickly;
  • it covers files that no CI configuration compiles.

Patches

  1. debug: remove src/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 own panic.c. The source check found it, because it includes <sof/kernel/platform.h>.
  2. debug: remove the panic declarations that only panic.c used: sof/debug/backtrace.h, the host arch/debug/backtrace.h and arch/debug/panic.h, and the dump_panicinfo() and panic_dump() prototypes in the host rtos/panic.h, which have no definition.
  3. 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.
    • They set up interrupts and timers, and include <sof/kernel/platform.h>.
    • Like the legacy host and DAI drivers, they go when the remaining platforms move to the Zephyr native drivers.
  4. scripts: check_kernel_includes: add a --sources mode, which checks the source tree for <sof/kernel/...> includes.
    • What it checks: user-space sources, and the user-space headers listed in a new [user-headers] manifest section: every .h and .hpp in src/ and zephyr/include apart from the kernel sources and the kernel-only headers. That is 626 headers today, including those local to modules that no CI configuration builds.
    • No baseline: no user-space code includes them today.
    • Strict mode: --strict fails when one is added.
  5. ci: codestyle: run check_kernel_includes.py --sources --strict in a new kernel-includes job, and describe it in the src/kernel README.

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_headers include directories, and #11487 put src/kernel/include on sof_options instead. 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

  • Source check:
    • passes on the tree;
    • with a <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 a zephyr/include header (rtos/alloc.h), it reports each and fails;
    • combined with build directories, --sources is an error.
  • Build check: with --strict, it still passes for the 12 CI build configurations and the other configurations below, with the same 16 baseline sources.
  • Workflow: codestyle.yml passes yamllint with the workflow's settings.
  • Per commit, compared with main:
    • Builds: tgl, tgl-h, mtl, lnl, ptl, wcl, nvl, imx8, imx8x, imx8m, imx8m_cm7, imx8ulp, imx95 and qemu_xtensa, and the extra CI configurations:
      • native_sim IPC3/IPC4 stub builds;
      • imx93 64-bit;
      • PTL with each userspace overlay;
      • PTL with CONFIG_SOF_USERSPACE_PROXY=n;
      • PTL and MTL with os_linux_overlay.conf;llext_relocatable.conf;
      • PTL and TGL with app/debug_stream_overlay.conf, and PTL with that overlay and user-space LL.
    • Comparisons: objects, LLEXT modules and firmware images (sections, symbols, SYS_INIT() order), and the per-function disassembly. No object changes at any commit. The only image difference is sof_init() on imx8m_cm7, imx93 and imx95, which embeds the git hash.
    • Signing: rimage runs for every Intel platform, and the generated configs are unchanged.
    • ZTest: the unit tests pass, run as in CI (20 of 20 configurations).
    • Host: the host library and the cmocka unit tests build and pass.
  • At the tip:
    • the testbench and the tools pass;
    • the host library and the cmocka unit tests pass for all nine defconfigs and the library config;
    • the platforms that already fail on main (acp_6_0, acp_7_0, acp_7_x, mt8186, mt8188, mt8195, mt8196, mt8365) have unchanged error sets.

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

  • Rebased onto current main, now that kernel/user partition, Phase 4 part 6: move kernel-only headers to sof/kernel #11487 is merged.
  • Review:
    • [user-headers] covers all user-space headers in src/ and zephyr/include, and .hpp files: 626 instead of 286, with no findings.
    • source_files() splits git ls-files by lines, and its fallback normalizes the path separator and skips .git and build directories.
    • --sources cannot be combined with build directories.
    • The src/kernel README shows --strict.
    • A new commit removes the panic declarations that only panic.c used.

🤖 Generated with Claude Code

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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 only src/include/* and src/platform/* (286 headers), skipping 313 module-private headers colocated under src/ (src/audio/**/*.h, src/debug/**/*.h, src/math/**/*.h, etc.) and 27 user-space headers in zephyr/include/ (rtos/alloc.h, sof/lib/dai.h, sof/lib/dma.h, sof/lib/sof_dma.h, etc.). Expanding [user-headers] to src/* + zephyr/include/* and excluding not_user alongside kernel_hdr checks all 626 user-space headers with zero false positives (see inline suggestions).

Minor Polish

  • scripts/check_kernel_includes.py: out.splitlines() + path normalization in source_files(), and rejecting --sources combined with <build-dir>.
  • src/debug/panic.c removal: Leaves src/include/sof/debug/backtrace.h (+ src/kernel/arch/host/include/arch/debug/backtrace.h) and dump_panicinfo() / panic_dump() in posix/include/rtos/panic.h with zero remaining users.
  • src/kernel/README.md: Include --strict in the check_kernel_includes.py --sources --strict command reference.

Comment thread scripts/kernel_user_partition.txt Outdated
Comment on lines +36 to +38
[user-headers]
src/include/*
src/platform/*

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Coverage gap: Listing only src/include/* and src/platform/* checks 286 headers and skips:

  1. 313 subsystem/module-local headers under src/ (src/audio/**/*.h, src/debug/**/*.h, src/math/**/*.h, etc. — including optional/LLEXT modules not built in default CI configs).
  2. 27 user-space headers in zephyr/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 of zephyr/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:

Suggested change
[user-headers]
src/include/*
src/platform/*
[user-headers]
src/*
zephyr/include/*

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread scripts/check_kernel_includes.py Outdated
Comment on lines +160 to +162
elif not (rel.endswith('.h') and matches(rel, user_hdr)) or \
matches(rel, kernel_hdr):
continue

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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):

Suggested change
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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done, as suggested: .hpp headers are checked too, and the kernel sources ([not-user-sources]) are excluded as well as the kernel-only headers.

Comment on lines +137 to +145
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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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:

Suggested change
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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done: git ls-files output is split by lines, and the os.walk() fallback normalizes the separator and skips .git and build directories.

Comment on lines +193 to +194
if args.sources:
found = check_sources(manifest, args.sof_root)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nit: Passing both --sources and <build-dir> currently ignores build_dirs silently:

Suggested change
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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done: --sources with build directories is now an argument error.

Comment thread src/debug/panic.c
Comment on lines -7 to -9
#include <sof/debug/backtrace.h>
#include <sof/debug/debug.h>
#include <rtos/panic.h>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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-space src/include/ while wrapping <arch/debug/backtrace.h>) and src/kernel/arch/host/include/arch/debug/backtrace.h
  • dump_panicinfo() and panic_dump() prototypes in posix/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.c only defines __panic()).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread src/kernel/README.md Outdated
Comment on lines +33 to +35
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/...>`.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nit: Include --strict here to match codestyle.yml (without --strict, --sources exits 0 even when includes are found):

Suggested change
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/...>`.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done, the README now shows --sources --strict.

lrgirdwo and others added 5 commits November 19, 2026 16:14
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>
@lgirdwood
lgirdwood marked this pull request as ready for review November 19, 2026 20:30
@intel-sofci

intel-sofci commented Nov 19, 2026 •

Copy link
Copy Markdown

PR 11489: test results

Run date: 2026-11-20 13:56 UTC

Tested commit: 6094409f9b8f02ecdcdb7a28df157d3e29b5ff53

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

@lgirdwood

Copy link
Copy Markdown
Member Author

Unrelated CI issue.

@lgirdwood
lgirdwood merged commit 9a990f5 into thesofproject:main Nov 20, 2026
45 of 46 checks passed
@lgirdwood
lgirdwood deleted the kernel-user/phase4g branch November 20, 2026 10:49
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.

3 participants