Repository navigation
Description
Partitioning user/kernel code for trust boundary and later safety island. Claude generated.
Is your feature request related to a problem? Please describe.
SOF is moving LL pipelines, DP modules and IPC processing into Zephyr user
threads (CONFIG_SOF_USERSPACE_LL, CONFIG_SOF_USERSPACE_PROXY, the
handler-kernel.c / handler-user.c split, and the syscalls in zephyr/syscall/).
The source tree doesn't show that boundary, though:
- Kernel-only code (MMIO, IRQs,
k_thread_create,k_mem_domain_*, PM,
clocks, rawdma_*, IDC, LLEXT loading) sits next to code that must be
user-safe, often in the same file. Examples:ipc-common.c,
zephyr_domain.c,zephyr_ll.c,lib/dma.c,lib/dai.c. - User-facing headers pull in kernel headers.
component.hincludes
rtos/idc.h,sof/lib/dai.h(→zephyr/drivers/dai.h) and
schedule/schedule.h.audio_stream.hincludessof/lib/dma.h
(→zephyr/drivers/dma.h).rtos/alloc.hincludessof/lib/memory.h,
which includesplatform/lib/memory.h.sof/platform.his included by about 54
audio/math/ipc files. As a result, every component and every LLEXT module
(they inheritzephyr_interfaceinclude dirs) can see platform, DMA and DAI
internals. - There is no build-time enforcement, so you only find out that user code
calls a privileged API when it faults on hardware.
Describe the solution you'd like
Partition the sources and headers into DSP kernel and userspace parts,
and have the build enforce the split.
Definitions:
- Kernel = code that must run in supervisor mode.
- User = everything else. It must be user-safe: plain C, syscall-backed Zephyr
APIs, and SOF syscalls. - The directory says what the code is allowed to do, not where it runs in a
particular config. WithSOF_USERSPACE_LL=n, user code still runs in
supervisor mode, and that's fine.
Layout:
src/kernel/ # new: supervisor-only code, own CMake lib (sof_kernel)
include/sof/kernel/... # kernel-private headers -> #include <sof/kernel/...>
init/ idc/ library_manager/ logging/ platform/ drivers/ arch/ probe/
base_fw/ (base_fw*.c, intel_uaol.c) mic_privacy/
ipc/ (ipc-zephyr.c, ipc4/handler-kernel.c, notification*.c, ipc3/)
schedule/ lib/ debug/ audio/ # kernel halves of split files
src/{audio,math,module,samples,ipc,schedule,lib,debug}/ # user (what remains)
src/include/ # user-visible headers only
zephyr/ # Zephyr module root stays where it is (OS glue = kernel)
Decisions:
-
Include path. Kernel-private headers are included as
<sof/kernel/...>. They live insrc/kernel/include/, which is a PRIVATE
include dir of thesof_kernellibrary. It is not onzephyr_interface, so
neither user code nor LLEXT modules can include them, and a simple rule
(no<sof/kernel/in user sources) is checkable in CI and checkpatch. The host
ABI dirssrc/include/kernel/andsrc/include/user/(Linux driver and tools
ABI) are not touched. -
XTOS is deleted rather than moved:
xtos/, the XTOS firmware build,
XTOS-only platform, driver and arch code, and the olddebug/gdbstub.
Removing the legacy-driver path thatKconfig.xtosexists for
(dai-legacy.c,host-legacy.c, the DMA domain schedulers and
ll_schedule_xtos.c) depends on the remaining non-native platforms moving to
native Zephyr drivers and on the testbench no longer using the legacy
host/DAI components (see Phase 0b). -
zephyr/stays at the top level. It is the Zephyr module root and OS
glue, and is treated as kernel. -
IPC3 is kernel. There is no user IPC3 thread, and it uses raw DMA
(ipc3/dai.c,host-page-table.c). It moves tosrc/kernel/ipc/ipc3/. -
lib/notifier.cis deleted and replaced with Zephyr mechanisms. It
usesk_spin_lock+ IDC, so it can't be called from user mode, and its
callbacks run in the notifier's context. Per event:Event Live users after XTOS removal Replacement CPU_FREQ/SSP_FREQnone (ids are set in clock_info, but nothing is ever fired on Zephyr)delete DMA_COPY,DMA_IRQ,DMA_DOMAIN_CHANGElegacy drivers and DMA domains only ( dai-legacy.c,host-legacy.c,dw/dma.c, AMD/MTK legacy DMA,dma_*_chan_domain.c)deleted along with the legacy-driver path. Native drivers use Zephyr dma_config.dma_callbackDAI_TRIGGERdai-zephyr.cDAI-group sync trigger (irq_local_disable+notifier_event)the last DAI to trigger walks the group member list itself. The atomic section becomes a kernel syscall (e.g. sof_dai_group_trigger()) that holds the IRQ lockKPB_CLIENT_EVTgoogle_hotword_detect.c,detect_test.c→kpb.ck_msgq(ork_event+ shared payload) owned by kpb and granted to the pipeline memory domain. Both are syscall-backedMIC_PRIVACY_STATE_CHANGEmic_privacy_manager IRQ → copier.ck_event_post()from the ISR. Copier checks it withk_event_test()/K_NO_WAITin its copy path and reads the state through a syscall or a mapped partition. No callback runs in IRQ context
Enforcement: scripts/check_kernel_includes.py, which reads the ninja
dependency log of a build and reports kernel-only headers included by
user-space sources, classified in scripts/kernel_user_partition.txt. It starts
as report-only and becomes enforcing once the headers are moved.
Implementation is a series of PRs. Every commit builds in all CI configs. Directory
moves are git mv plus path fixups only, so history is preserved.
Checklist
Phase 0: guard rails, XTOS and ALSA plugin removal
0a: no platform loses support. Merged in #11312:
- zephyr: remove the references to the deleted
hda-dma.candlps_wait.c - ci: remove the no-op XTOS reproducible build check (
test-repro-build.sh
exits 0 becausextensa-build-all.shno longer exists) - test: cmocka: remove the dead Xtensa (
xt-run) unit test build - test: cmocka: move the unit test defconfigs from
src/arch/xtensa/configs
totest/cmocka/configs - cmake: remove the legacy XTOS firmware build (top-level
add_executable(sof),
xtensa toolchain file, scan-build wrapper, XTOS-only per-platform/driver
CMake files, Chrome XTOS config overrides) - platform: amd: remove Renoir, Vangogh and ACP 6.3
- drivers: amd: remove the sources that no build uses
- platform: mediatek: remove the per-SoC XTOS dirs (
src/platform/mt81xx,
src/drivers/mediatek/mt8*,afe-sgen); Zephyr usessrc/platform/mtk - platform: imx: remove the XTOS DMA, DAI, interrupt and timer drivers
- drivers: dw: remove the DesignWare DMA, GPIO and SPI drivers (
CONFIG_DW
has no prompt and nothing selects it, soCONFIG_DW_DMAcannot be enabled) - drivers: remove the unused Intel HDA headers
- platform: posix: remove the unused
base_fw_platform.c - debug: remove the old SOF GDB stub (
CONFIG_GDB_DEBUG, cannot build for
any firmware target); the ZephyrCONFIG_GDBSTUBpath is unaffected - zephyr: move the legacy XTOS IRQ header into
zephyr/include; then remove
xtos/include - installer: remove the XTOS firmware installer
- docker: sof_builder: drop the XTOS crosstool-ng toolchains
- tools: plugin: remove the SOF ALSA plugin, its topology and the
shared-library module build (CONFIG_COMP_MODULE_SHARED_LIBRARY_BUILD) - library: always build the host library statically (drop
CONFIG_LIBRARY_STATIC) - scripts: add
check_kernel_includes.pyandkernel_user_partition.txt;
ci: run it report-only in the Zephyr workflow. Current baseline for PTL:
148 user-space sources include 28 kernel-only headers. -
src/trace: removed in Kernel/user partition: remove the SOF DMA trace #11421. Zephyr builds can't enable the SOF DMA trace,
so it was only built for the host. The testbench and host library now print
their traces through a smalltrace-host.h, with the same levels and output.
src/trace,dma-trace.h,trace-soflogger.h,dma-copy.cand
CONFIG_TRACE*are gone. The host ABI ininclude/ipc/trace.hstays.
Verification for 0a: the non-debug sections of zephyr.elf are identical on all
15 platforms that build on main, and so are all 66 LLEXT modules. The libsof.a
symbol table is unchanged. testbench, tools and all cmocka configurations pass.
The full error sets of the platforms that already fail on main are unchanged.
0b: legacy driver path (needs the AMD and MediaTek maintainers). These platforms
do not build on main today, and CI does not build them:
acp_6_0,mt8186,mt8188,mt8195andmt8365fail inipc3/dai.cand
host-legacy.c.acp_7_xfails because Kconfig symbols are missing in the pinned Zephyr.mt8196fails because themediatek,sof-host-dmaDT node is missing.
Items:
- AMD
acp_6_0(Rembrandt): native Zephyr ACP DAI/DMA, andzephyr_ll.c
instead ofll_schedule_xtos.c+dma_multi_chan_domain.c - MTK
mt8186,mt8188,mt8195,mt8365:CONFIG_ZEPHYR_NATIVE_DRIVERS=y
(zephyr_mtk_*), as already done for mt8196 - testbench: stop building
host-legacy.canddai-legacy.c - Delete the legacy-driver path:
-
dai-legacy.c,host-legacy.c,dma-legacy.h - legacy AMD/MTK DMA drivers,
dummy-dma.c -
dma_*_chan_domain.c,zephyr_dma_domain.c,ll_schedule_xtos.c -
rtos/interrupt-legacy.h+src/drivers/interrupt.c -
Kconfig.xtos,ZEPHYR_NATIVE_DRIVERS
-
Phase 1: header untangle (no moves)
First part: merged in #11330, header hygiene with no functional change. Kernel-only headers pulled into user-space sources on PTL: zephyr/drivers/dma.h 145 → 27, mailbox.h 141 → 20, rtos/timer.h 139 → 10, rtos/userspace_helper.h 136 → 10, rtos/idc.h 135 → 26. What remains mostly comes through rtos/alloc.h → sof/lib/memory.h (the platform memory map), which the second part addresses.
Second part: merged in #11345. PLATFORM_DCACHE_ALIGN now comes from the Zephyr cache line size and PLATFORM_MAX_CHANNELS is the Kconfig option CONFIG_PLATFORM_MAX_CHANNELS. The cold code attributes move to sof/lib/cold.h, and rtos/alloc.h, rtos/sof.h and ipc/msg.h no longer include the platform memory map or sof/platform.h. On PTL, sof/platform.h now reaches 15 user-space sources instead of 130, and the platform clock headers 20 instead of 130. sof/lib/memory.h is still reached through sof/coherent.h, which needs the cached/uncached address helpers.
Third part: merged in #11364, with no functional change. The cached/uncached alias helpers move to rtos/cache.h (Zephyr cache API on ACE, unchanged elsewhere), so sof/coherent.h no longer includes the memory map. comp_dai_config() moves to sof/audio/component_dai.h. PLATFORM_MAX_STREAMS becomes CONFIG_PLATFORM_MAX_STREAMS. The LL period and user LL lock helpers move to ll_schedule.h, and unused component_ext.h includes are dropped. On PTL, user-space sources including any kernel-only header go from 143 to 45: the memory map 141 → 34, rtos/idc.h 26 → 11, zephyr/drivers/dma.h 27 → 10, the clock headers 20 → 14 and sof/platform.h 15 → 11.
Fourth part: merged in #11386, with no functional change. CONFIG_ACE_VERSION_2_0_OR_LATER replaces the ACE_VERSION > ACE_VERSION_1_5 checks, so the DAI code drops sof/platform.h. The DRC, multiband DRC and SRC sources switch from the memory map to sof/lib/cold.h, unused rtos/ includes are dropped, and the volume peak meter mailbox write moves out of volume.h. On PTL, user-space sources including any kernel-only header go from 45 to 26: the memory map 34 → 19, mailbox.h 20 → 12 and rtos/userspace_helper.h 10 → 2. PLATFORM_PRIMARY_CORE_ID turned out to come from sof/lib/cpu.h, not sof/platform.h.
-
component.h: droprtos/idc.h,sof/lib/dai.h,schedule/schedule.h(Phase 1: stop user-facing headers pulling in kernel-only headers #11330)
(use forward declarations). -
audio_stream.h: dropsof/lib/dma.h(Phase 1: stop user-facing headers pulling in kernel-only headers #11330). Splitsof/lib/dma.hinto a user
part (sg structs,dma_buffer_copy_*,sof_dma_*syscalls) and a kernel
part (struct dma,dma_plat_data,dmac_init). -
sof/lib/memory.h: keep the user-safe alignment/cache-line subset (Phase 1 (part 2): stop user-space code depending on the platform memory map and headers #11345: alignment from Zephyr, cold attributes split; cached/uncached helpers moved tortos/cache.hin Phase 1 (part 3): cache helpers, component_ext.h and LL scheduler header cleanup #11364). The
platform memory map goes to kernel. -
sof/platform.h(Phase 1 (part 2): stop user-space code depending on the platform memory map and headers #11345:CONFIG_PLATFORM_MAX_CHANNELS; Phase 1 (part 3): cache helpers, component_ext.h and LL scheduler header cleanup #11364:CONFIG_PLATFORM_MAX_STREAMS; Phase 1 (part 4): more include cleanup in user-space code #11386:CONFIG_ACE_VERSION_2_0_OR_LATER;PLATFORM_PRIMARY_CORE_IDis already insof/lib/cpu.h): move the constants user code needs to a user header or
Kconfig. The rest goes to kernel. - Split the mixed headers (user prototypes and
__syscalls stay user):-
dai-zephyr.h -
rtos/alloc.h -
schedule/schedule.h -
ll_schedule_domain.h(Phase 1 (part 3): cache helpers, component_ext.h and LL scheduler header cleanup #11364: LL period and user LL locks moved toll_schedule.h) -
dp_schedule.h -
lib_manager.h -
debug_stream_slot.h
-
-
rtos/: interrupt, clk, idc, timer, init, spinlock and userspace_helper
become kernel. Splitwait.hso thatwait_for_interruptgoes to kernel. -
component_ext.h: move the cross-core IDC, DAI and scheduler helpers out of the component API (Phase 1 (part 3): cache helpers, component_ext.h and LL scheduler header cleanup #11364:comp_dai_config()moved tocomponent_dai.h, unused includes dropped; the IDC dispatchers remain, used by the pipeline). - Remove the direct kernel includes from user
.cfiles (unused ones removed in Phase 1: stop user-facing headers pulling in kernel-only headers #11330):rtos/interrupt.h
(11 files),rtos/clk.h(4 files),sof/lib/memory.h(26 files). - Remove the relative
"../audio/copier/copier.h"includes
(lib/dma.c,pipeline-stream.c). - Exit criterion: the checker reports zero kernel-header leaks for USER files.
Phase 2: src/kernel + sof_kernel library, move the pure-kernel dirs
First part: merged in #11394. It adds src/kernel and the sof_kernel library, and moves src/init there. The library is created in zephyr/CMakeLists.txt next to modules_sof, and src/kernel/CMakeLists.txt makes it the current Zephyr library for its subtree, so the moved directories' CMake files don't change. The generated code is unchanged. The link order changes, but symbols and SYS_INIT() order are identical in every image. Boot, playback and playback after runtime suspend were checked on TGL. On the Cortex-M7 builds sof_init() changes size from commit to commit only because it embeds the git hash, and Thumb-2 encodes some hash values more compactly than others.
-
src/kernel/CMakeLists.txtandzephyr_library_named(sof_kernel)(Phase 2 (part 1): add src/kernel and a sof_kernel library, move src/init #11394).
The library is selected per directory tree (ZEPHYR_CURRENT_LIBRARY), so
add_local_sources()needs nosof_kerneltarget. Still to come:
src/kernel/Kconfig(Phase 2 (part 2): move src/idc to src/kernel/idc #11398, withidc) and the
PRIVATEsrc/kernel/include(with the header moves in Phase 4). -
git mv, one commit per directory or file. Moved code keeps its path belowsrc/kernel. The rest is grouped into three PRs: A, Zephyr-only (Phase 2 (part 4): move the Zephyr-only kernel code to src/kernel #11411, merged); B, code the host builds also compile (Phase 2 (part 5): move the host-built kernel code to src/kernel #11415, merged); C,archandplatform, with all ofsrc/kernelbuilt intosof_kernel(Phase 2 (part 6): move arch and platform to src/kernel, build src/kernel into sof_kernel #11420, merged). All kernel-only directories are now insrc/kernel; what is left outside is mixed and is split in Phase 3.-
init(Phase 2 (part 1): add src/kernel and a sof_kernel library, move src/init #11394) -
idc(Phase 2 (part 2): move src/idc to src/kernel/idc #11398; addssrc/kernel/Kconfig) -
library_manager(via Phase 2 (part 4): move the Zephyr-only kernel code to src/kernel #11411, which included Phase 2 (part 3): move src/library_manager to src/kernel/library_manager #11402's commit; boot, HDMI playback and runtime suspend checked on ARL-S) -
logging(Phase 2 (part 4): move the Zephyr-only kernel code to src/kernel #11411) (+ipc4/logging.c, Phase 2 (part 5): move the host-built kernel code to src/kernel #11415) -
arch(Phase 2 (part 6): move arch and platform to src/kernel, build src/kernel into sof_kernel #11420) -
platform(Phase 2 (part 6): move arch and platform to src/kernel, build src/kernel into sof_kernel #11420) -
drivers(Phase 2 (part 5): move the host-built kernel code to src/kernel #11415) -
probe(Phase 2 (part 4): move the Zephyr-only kernel code to src/kernel #11411) -
safety(once the safety island lands) -
audio/base_fw*.c(Phase 2 (part 4): move the Zephyr-only kernel code to src/kernel #11411) -
audio/intel_uaol.c: now mixed, since the UAOL feedback support added functions that the DAI component calls from the user LL thread. Moved to Phase 3 (split). -
audio/mic_privacy_manager(Phase 2 (part 4): move the Zephyr-only kernel code to src/kernel #11411) -
module_adapter/library/userspace_proxy.c(Phase 2 (part 4): move the Zephyr-only kernel code to src/kernel #11411) -
ipc/ipc3(Phase 2 (part 5): move the host-built kernel code to src/kernel #11415) -
ipc-zephyr.c(Phase 2 (part 4): move the Zephyr-only kernel code to src/kernel #11411) -
ipc4/handler-kernel.c(Phase 2 (part 5): move the host-built kernel code to src/kernel #11415) -
ipc4/notification.c(Phase 2 (part 5): move the host-built kernel code to src/kernel #11415) -
notification_pool.c(Phase 2 (part 5): move the host-built kernel code to src/kernel #11415) -
dma-copy.c: removed with the DMA trace (Kernel/user partition: remove the SOF DMA trace #11421) -
lib/{clk,cpu-clk-manager,ams,agent}.c(clk, cpu-clk-manager and ams in Phase 2 (part 4): move the Zephyr-only kernel code to src/kernel #11411; agent in Phase 2 (part 5): move the host-built kernel code to src/kernel #11415) -
debug/telemetry(Phase 2 (part 4): move the Zephyr-only kernel code to src/kernel #11411) -
debug/dram.c(Phase 2 (part 4): move the Zephyr-only kernel code to src/kernel #11411) -
zephyr_ll_user.c(Phase 2 (part 4): move the Zephyr-only kernel code to src/kernel #11411)
-
- Per move, update:
-
zephyr/CMakeLists.txtsource lists -
src/Kconfigrsource lines - root/
srcCMake (CONFIG_LIBRARY) - testbench, plugin, cmocka and ztest CMake
- CODEOWNERS
- fuzz dict scripts and
sdk-create-module.py - per-dir READMEs and docs
-
- Diff the
zephyr.mapsections andSYS_INITorder before and after (tgl, ptl, imx,
amd, mtk). Done per move for every image that builds on main: symbols (name, type,
size),SYS_INIT()order and section sizes. AMD and MTK don't build on main, so
for those only the error sets are compared.
Phase 3: split mixed source files (handler-kernel.c pattern), move the kernel halves
The kernel half of src/X/foo.c goes to src/kernel/X/foo-kernel.c. The kernel side gets:
- boot-time init;
- thread, timer and kernel-object setup;
- memory domains and access grants;
- the
z_impl_/z_vrfy_syscall halves.
What runs in the scheduler, IPC and DP threads stays user. Every split is checked function by function against the original file, and the per-function disassembly of every image is compared. The only differences are inlining across the new file boundary, described in each commit.
Phase 3 is complete: #11422, #11424, #11459 and #11461 are merged.
Schedulers: merged in #11424. The shared data structures are in sof/schedule/zephyr_ll.h and sof/schedule/zephyr_dp_schedule.h.
-
ipc/ipc-common.c: the kernel half gets the IPC task, the outgoing message queue and theipc_msg_send()syscall half, and the user-space IPC thread setup and grants, including the cross-core request slots. The user half keeps the IPC thread function, the default dispatch and the cross-core request helpers. (Phase 3 (part 1): split the mixed IPC files, kernel halves to src/kernel/ipc #11422, merged) -
ipc4/handler-user.c: the kernel half gets the routers and the MOD_INIT, module_id 0, CHAIN_DMA, IPCGTW and GDB paths that run in the kernel IPC thread. (Phase 3 (part 1): split the mixed IPC files, kernel halves to src/kernel/ipc #11422, merged) -
ipc4/helper.c: the kernel half gets the driver lookup (ipc4_get_drv(),ipc4_get_comp_drv()),comp_new_ipc4(),ipc4_user_module_load(),ipc4_process_on_core(),ipc_comp_free_remote()and the chain DMA manager. (Phase 3 (part 1): split the mixed IPC files, kernel halves to src/kernel/ipc #11422, merged) -
schedule/zephyr_domain.c: the kernel half gets the thread init and free, domain init and the timer ISR. The thread function and the user-space register/unregister stay user. (Phase 3 (part 2): split the schedulers, kernel parts to src/kernel/schedule #11424) -
schedule/zephyr_ll.c: the kernel half gets the scheduler init and free,init_context,grant_access, the kernel-only lock table and the semaphore syscalls. (Phase 3 (part 2): split the schedulers, kernel parts to src/kernel/schedule #11424) -
schedule/zephyr_dp_schedule*.c: the kernel half gets the locks and grants, the LL-tick and deadline syscalls, scheduler init, the DP thread creation and memory domains, andinternal_free. The thread bodies, deadline calculation and IPC forwarding stay user. (Phase 3 (part 2): split the schedulers, kernel parts to src/kernel/schedule #11424) -
schedule/zephyr_twb_schedule.c: moved whole, since it is kernel-only. It usesirq_lock()throughout and has an interrupt-context budget callback. (Phase 3 (part 2): split the schedulers, kernel parts to src/kernel/schedule #11424) -
schedule/schedule.c: scheduler registration goes to kernel. (Phase 3 (part 2): split the schedulers, kernel parts to src/kernel/schedule #11424) -
lib/dma.c,lib/dai.c: syscall impls and the legacy getters go to kernel. (Phase 3 (part 3): split lib/dma.c, lib/dai.c and intel_uaol.c, kernel parts to src/kernel #11459) -
audio/intel_uaol.c: split the UAOL feedback functions that the DAI component calls from the user LL thread from the kernel UAOL setup. The device table and its lookup stay user. (Phase 3 (part 3): split lib/dma.c, lib/dai.c and intel_uaol.c, kernel parts to src/kernel #11459) -
zephyr/lib/alloc.c,vregion.c,debug_stream_slot.c: check that the
z_impl/z_vrfy code is kernel-only.alloc.candvregion.c: thez_impl_code is kernel-only and stays. It is only reached
through the syscalls (verifiers inzephyr/syscall/) or from kernel code. The direct
calls from user code found by the check are listed under Phase 5.debug_stream_slot.c, with the other kernel-only debug stream code (the thread info
client and the exception dump hook), moves tosrc/kernel/debug/debug_stream. (Phase 3 (part 4): move the kernel-only debug stream code to src/kernel/debug #11461, merged)
Phase 4: move the kernel headers, turn on enforcement
First part: merged in #11464. The include checker is enforced in CI against a baseline of the user-space sources that still leak, so new kernel-only includes fail the build. Every source in src/ outside src/kernel is now checked as user-space code, which adds the Phase 3 user halves. It also fixes a regression: rtos/timer.h in telemetry.h (20206e3) had brought sof/platform.h back into every component source, taking PTL from 28 to 140 leaking user-space sources. The baseline has 41 sources; removing them finishes the Phase 1 exit criterion and unblocks the header moves.
Second part: draft PR #11466. The IDC message format moves to rtos/idc_msg.h, so the component API no longer includes the IDC driver header or ll_schedule_domain.h. 32 unused kernel-only includes are removed from user-space sources, and four user headers drop kernel includes they did not need. In the CI configurations, rtos/idc.h, sof/ipc/driver.h, sof/llext_manager.h, sof/drivers/dmic.h and sof/lib/mm_heap.h no longer reach any user-space source, and the (source, kernel header) pairs go from 854 to 686. The baseline goes from 41 to 39 sources. Most remaining leaks are kernel API uses, not includes.
- Remove the remaining leaks and shrink
[leak-baseline]inscripts/kernel_user_partition.txtto empty.- IDC message format, component API, unused includes (kernel/user partition, Phase 4 part 2: untangle the IDC and component headers, remove unused kernel includes #11466)
- split
sof/lib/dma.h(user: scatter-gather, buffer copy,sof_dma_*syscalls; kernel: the rest); 13 sources - mailbox writes and layout constants from user code (copier, volume, DAI, host, pipeline, IPC); 13 sources
-
irq_local_disable()/irq_local_enable()and thertos/timer.hplatform timestamps in user code -
domain_init()inll_schedule_domain.h(kernel-only inline that needsrtos/clk.h)
-
git mvthe kernel headers tosrc/kernel/include/sof/kernel/...and
rewrite the kernel includes to<sof/kernel/...>. - Platform include dirs become PRIVATE to
sof_kernel, and the user-needed subset
is exported through user headers. - Rebuild every
sof_llext_buildmodule and the LMDK samples against the
reduced include set. - Install rules install only the user include set.
- Switch the checker to enforcing in CI (kernel/user partition, Phase 4 part 1: enforce the include checker, fix a telemetry include regression #11464, merged, with a leak baseline), and add a checkpatch rule against
<sof/kernel/in user dirs.
Phase 5: remove the notifier and close the user-safety gaps
- DAI-group trigger: drop the notifier and add a
sof_dai_group_trigger()syscall
for the IRQ-locked section. - KPB client events: replace with a
k_msgq(ork_event) for the hotword
detector → kpb path, coveringgoogle_hotword_detect.canddetect_test.c. - Mic privacy: replace with an ISR
k_event_post()and copier polling. - Remove the
notification_id/notification_maskfields fromclock_info. - Delete
lib/notifier.c,notifier.h,IDC_MSG_NOTIFY,init_system_notify()
andsof->notify_data. - Remaining kernel calls from user-classified code:
- the kernel heap allocators
rmalloc(),rzalloc(),rballoc_align()andrfree(),
called directly from about 30 user-space sources (mostlysrc/audio); they only
work in kernel mode (found by the Phase 3 check, Phase 3 (part 4): move the kernel-only debug stream code to src/kernel/debug #11461) - user-safe getters that live in kernel files:
sof_sys_user_heap_get(),
sof_sys_heap_get()(zephyr/lib/alloc.c) andvregion_mem_info()
(zephyr/lib/vregion.c) -
idc_send_msg/ipc4_process_on_corefrom the user IPC thread -
idc_cmd_user()and the IDC component handlers it calls run in the user-space IPC
thread but live insrc/kernel/idc/idc.c(found in kernel/user partition, Phase 4 part 2: untangle the IDC and component headers, remove unused kernel includes #11466) -
k_cycle_get_64/sof_cycle_get_64in host-zephyr, kpb, probe and
perf_cnt (check whether this is wall-clock MMIO on intel_adsp) - kpb
pm_runtime_disableand its EDF task -
lib_notif_msg_send - probe raw
dma_*→sof_dma_*, which would let probe move back to user
- the kernel heap allocators
- Re-enable the features
app/overlays/ptl/ll_userspace_overlay.confcurrently
turns off for user LL: telemetry,CROSS_CORE_STREAM,MIC_PRIVACY, xrun
notifications, cold-store debug.
Describe alternatives you've considered
- Path-preserving header move (kernel headers keep their
<sof/lib/...>
path but move to a private include root). This means no include churn, but you
can't tell from an include line which headers are kernel-only. We chose
<sof/kernel/...>so the boundary is grep- and checkpatch-able. - Renaming the host ABI
src/include/kernel/andsrc/include/user/to free
up the names. Rejected: about 245 include sites, the topologyget_abi.sh
parsing, and the hand-synced Linux copies. - Moving legacy XTOS code into
src/kernel/legacy/instead of deleting it.
Rejected, because it moves code no Zephyr build compiles. - Keeping the notifier and making it a syscall. Rejected: callbacks would
still run in the poster's context across the privilege boundary. Zephyr
k_event/k_msgqalready give syscall-backed, memory-domain-aware
signalling.
Additional context
- Related to the userspace LL / DP work:
CONFIG_SOF_USERSPACE_LL,
CONFIG_SOF_USERSPACE_PROXY,zephyr/syscall/,src/ipc/ipc4/handler-{kernel,user}.c. - Expect merge conflicts with in-flight PRs during the Phase 2 and Phase 4 moves. Moves
will be one dir per PR and announced ahead of time. - Validation per phase: CI build matrix (Intel cAVS2.5/ACE1.5/2.0/3.0/4.0, i.MX,
AMD, MTK, native_sim/fuzz, testbench, cmocka, ztest),zephyr.elfsection
diffs, and boot+playback on TGL and PTL/ARL hardware.
Activity
lgirdwood commentedon Oct 14, 2026
I've updated the Phase 0 checklist in the description after checking each item against main.
Corrections to the original plan
src/traceis still used: the testbench builds it (CONFIG_TRACEdefaults to y for host builds). It is now a decision item rather than a deletion.ll_schedule_xtos.cand the DMA domain schedulers are still built foracp_6_0on Zephyr, and the testbench buildshost-legacy.c/dai-legacy.c. Both moved to 0b, the legacy driver path.New findings
CONFIG_DWcannot be enabled, so all ofsrc/drivers/dwis dead, including the DMA driver thatzephyr/CMakeLists.txtstill lists.test-repro-build.shexits 0 whenxtensa-build-all.shis missing.sof_builderdocker image no longer builds on main: its alsa-lib/alsa-utils stage needs a newer autoconf than Ubuntu 22.04 provides. This is unrelated to the XTOS toolchain removal.Added to Phase 0: removal of the SOF ALSA plugin, together with the shared-library module build and
CONFIG_LIBRARY_STATIC, which only existed for it.UUID registry entries of removed code are kept, because the registry requires that distributed mappings never change.
lgirdwood commentedon Oct 14, 2026
Status: Phase 0a is up as draft PR #11312, with 23 commits and one patch per checklist item.
zephyr.elfis section-identical on all 15 platforms that build on main, and all 66 LLEXT modules are unchanged.Still open:
src/trace: keep it as host-only trace, or move the testbench to a printf backend.host-legacy.c/dai-legacy.c.lgirdwood commentedon Oct 21, 2026
Status: Phase 0 is merged (#11312). The first part of Phase 1 is up as draft PR #11330: 10 header-hygiene patches with no functional change.
Next in Phase 1: remove the
rtos/alloc.h→sof/lib/memory.hdependency. That needs a small user-safe cache alignment header per platform, becausePLATFORM_DCACHE_ALIGNdiffers per platform. Then split the mixed headers (component_ext.h,sof/lib/dma.h,dai-zephyr.h, the scheduler headers).lgirdwood commentedon Oct 23, 2026
Status: the first Phase 1 part is merged (#11330). The second part is up as draft PR #11345 (6 patches):
PLATFORM_DCACHE_ALIGNnow comes from the Zephyr cache line size. This changes it from 32 to 128 on i.MX8/8X/8M/8ULP (only the IPC3 buffer allocation uses it there) and from 4 to 32 on qemu_xtensa.PLATFORM_MAX_CHANNELSbecomes the Kconfig optionCONFIG_PLATFORM_MAX_CHANNELS, with unchanged values.sof/lib/cold.h.rtos/alloc.h,rtos/sof.handipc/msg.hstop including the platform memory map andsof/platform.h.On PTL,
sof/platform.hreaches 15 user-space sources instead of 130.Next:
sof/coherent.h(they decideis_uncached()semantics on i.MX/AMD/MTK);PLATFORM_MAX_STREAMS,PLATFORM_PRIMARY_CORE_ID,ACE_VERSION);component_ext.h,sof/lib/dma.h,dai-zephyr.h, scheduler).init: move src/init to src/kernel/init
telemetry: do not include rtos/timer.h in telemetry.h