Repository navigation
ipc4, dma, lib_manager: stop kernel code from allocating from the LL user heap - #11495
Merged
Merged
Conversation
Chain DMA messages are handled in the kernel IPC thread in all builds, including the creation of the component, which runs the chain DMA driver code and allocates the component from the LL user heap. With the LL scheduler in user space, this should run in the IPC user thread like the other pipeline messages. As a first step, move ipc4_process_chain_dma(), ipc4_chain_manager_create() and ipc4_chain_dma_state() to handler-user.c and helper.c, and call them through a new ipc4_route_chain_dma() router. The driver lookup needs the kernel driver list, so it stays in the kernel as ipc4_chain_dma_drv() and the driver is passed to the handler. Both router variants still call the handler directly, so there is no functional change. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
kv2019i
requested review from
abonislawski,
bardliao,
dbaluta,
iuliana-prodan,
lbetlej,
lgirdwood,
lyakh,
mmaka1,
pblaszko,
plbossart and
tmleman
as code owners
November 20, 2026 10:37
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Critical issues remain: RO-area exhaustion can trigger invalid frees of the shared LL heap, and START/PAUSE timeout handling can leave DMA running without runtime-idle protection.
2 open issues
What changed in this PR
This PR hardens SOF’s low-latency (LL) userspace boundary by moving kernel runtime allocations away from the user-writable LL heap and using trusted kernel DMA state.
Changes:
- Routes chain DMA handling through the IPC user thread while keeping runtime-idle power management in the kernel.
- Moves loadable drivers and DMA channel arrays into kernel-managed LL memory areas.
- Uses trusted DMA device lookups, adds regression tests, and updates userspace configuration and documentation.
| File | Description |
|---|---|
zephyr/test/userspace/test_ll_karea.c |
Tests DMA channel placement, reuse, and trusted device lookup. |
zephyr/lib/dma.c |
Adds kernel-only DMA device lookup. |
zephyr/Kconfig |
Enlarges and documents the LL read-only area. |
zephyr/include/sof/lib/sof_dma.h |
Uses trusted device state in kernel DMA wrappers. |
src/kernel/library_manager/lib_manager.c |
Moves drivers into read-only memory and replaces direct DMA access. |
src/kernel/lib/dma-kernel.c |
Allocates and retains channel arrays in the kernel-managed RW area. |
src/kernel/ipc/ipc4/helper-kernel.c |
Retains driver lookup while moving chain lifecycle helpers out of the kernel tier. |
src/kernel/ipc/ipc4/handler-user-kernel.c |
Dispatches chain DMA messages through context-specific routing. |
src/kernel/ipc/ipc4/handler-route.h |
Declares the chain DMA router. |
src/kernel/ipc/ipc4/handler-ll-user.c |
Forwards chain commands and tracks runtime-idle locks. |
src/kernel/ipc/ipc4/handler-ll-kernel.c |
Routes non-userspace chain commands directly. |
src/ipc/ipc4/README.md |
Documents revised IPC routing and execution contexts. |
src/ipc/ipc4/helper.c |
Hosts chain creation and state-change helpers. |
src/ipc/ipc4/handler-user.c |
Hosts chain message processing and adds user-thread dispatch. |
src/include/sof/userspace/README.md |
Documents allocation ownership, DMA trust boundaries, and chain handling. |
src/include/sof/ipc/topology.h |
Updates chain helper declarations for kernel-supplied drivers. |
src/include/ipc4/handler.h |
Declares and documents the shared chain message handler. |
src/audio/chain_dma.c |
Leaves LL userspace power-management locking to the kernel router. |
app/ll_userspace_overlay.conf |
Disables the unsupported IPC gateway in the LL overlay. |
Review effort: Balanced
PR 11495: test resultsRun date: 2026-11-20 17:05 UTC Tested commit: 2fe741af589eb129dbd7694efa4b100975d2722e |
With CONFIG_SOF_USERSPACE_LL, the kernel IPC thread created and controlled chain DMA components itself. It ran the chain DMA driver code, allocated the component, its data and its DMA buffer from the LL user heap, whose metadata user threads can write, and called the component and DMA operations through LL-writable pointers. Forward GLB_CHAIN_DMA to the IPC user thread like the other pipeline messages. The kernel still looks up the driver, which needs the kernel driver list, and passes it through ipc_user->init_drv as for module init. The DMA operations now go through the DMA system calls. A started chain DMA blocks the runtime idle state, but the PM policy locks can only be changed in kernel mode. Take and release the lock in the kernel router instead. It is taken before a START is forwarded, and released when a pause or free returns, as they stop the DMA also when they fail, or when a START that took it fails. A forwarded command that times out can still run in the user thread later, so the lock is then kept until the next pause or free of the chain. A kernel-only mask of the host DMA channels with a started chain keeps the lock count balanced whatever the user thread does. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
The IPC gateway does not work with CONFIG_SOF_USERSPACE_LL: copier creation runs in the IPC user thread, but adds the gateway to a list in kernel-only memory. The gateway commands are still handled in the kernel IPC thread, which walks the gateway list and copies data through the sink and source operations of buffers that user threads can write. Disable it in the LL overlay, with the other features that are not yet compatible with user space. The Linux driver does not use the IPC gateway. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
With CONFIG_SOF_USERSPACE_LL, dma_init() allocates the channel array of a DMA controller from the LL user heap, and the last sof_dma_put() frees it. Both run in supervisor mode, mostly in the sof_dma_get() and sof_dma_put() system calls, so the kernel runs the heap allocator on metadata that user threads can write. Take the array from the kernel RW area of the LL region instead. That memory is never freed, so allocate the array of a controller on its first use, keep it in the kernel-only struct sof_dma_kinfo after the last put and reuse it on the next get. The channel count of a controller is constant, so the array always fits. The user-visible dma->chan is still cleared on the last put. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
The z_impl_sof_dma_*() wrappers call the Zephyr DMA API on dma->z_dev. With CONFIG_SOF_USERSPACE_INTERFACE_DMA, user threads can write the dma[] array, so a kernel caller of these wrappers can be made to call the DMA API on a device that a user thread forged. The system call validators already avoid this by using the kernel-only struct sof_dma_kinfo. Add sof_dma_kdev(), which returns the device from the kernel-only state, and use it in the wrappers. Without the user DMA interface, it returns dma->z_dev as before. The wrappers are only called in kernel context: user threads go through the validators, which call the Zephyr DMA API directly. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
The library loader runs in the kernel IPC thread and calls the Zephyr DMA API on dma->z_dev and dma->chan[i].dma->z_dev, and takes the channel index from dma->chan[i]. With CONFIG_SOF_USERSPACE_INTERFACE_DMA, user threads can write all of these, so they could make the kernel call the DMA API on a forged device. Use the sof_dma_*() wrappers, which take the device from kernel-only state, and keep the channel index in the kernel-only loader context instead of a pointer into the channel array. Without the user DMA interface, the wrappers call the same functions on dma->z_dev as before. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
With CONFIG_SOF_USERSPACE_LL, the comp_driver of a loadable module is allocated from the LL user heap by the kernel. User threads can write it there, but the kernel calls its ops, for example to create DP modules, so a user thread could redirect the kernel to any function. The allocation also runs the heap allocator on metadata that user threads can write. Allocate the drivers from the kernel RO area of the LL region instead. The LL and IPC user threads still read the driver, but cannot write it. Only kernel threads write it, when the driver is registered and when its module adapter ops are set. Loadable drivers are never unregistered, so the area never needs to free them. Each driver takes 128 bytes of the area, and on PTL nocodec the area holds 1.5 KB after registering 7 drivers, with 22 LLEXT files in the image. Increase its default size to 8 KB, taken from the LL user heap. A full RO area now fails the registration, and the cleanup passed drv_heap to module_driver_heap_remove() also when it is the shared user heap, which frees its memory and the heap object. Only remove a heap that module_driver_heap_init() created. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Add two cases to the kernel area suite. The first checks that the channel array of the host DMA controller is in the kernel RW area of the LL region, and that it is kept after the last put and reused by the next get. The second points the user-writable dma->z_dev at kernel data and checks that the kernel sof_dma_get_attribute() wrapper still works, because it uses the device from the kernel-only state. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Update the LL memory region section with the objects that are now in the kernel areas, the loadable drivers in the RO area and the DMA channel arrays in the RW area. Describe how chain DMA messages are handled and how kernel code drives DMA without trusting dma[], and note that kernel threads no longer use the LL user heap, while the heap system calls still run the allocator in supervisor mode. Move GLB_CHAIN_DMA to the kernel and user messages in the IPC4 routing table. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
kv2019i
force-pushed
the
202611-ll-heap-kpaths
branch
from
November 20, 2026 16:40
b25015d to
2fe741a
Compare
Collaborator
Author
|
V2 pushed:
|
Member
|
Verify boot log randomly failing on some DUTs but audio tests passing |
lgirdwood
approved these changes
Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

With CONFIG_SOF_USERSPACE_LL, the LL user heap's sys_heap metadata sits in memory that the LL and IPC user threads can write. Kernel code that allocates from that heap, or that follows pointers stored in LL-writable memory, can be steered by a compromised user thread. This series removes the remaining kernel-side runtime users of the LL heap. It also stops kernel code from trusting the LL-writable DMA state.