Repository navigation
user-dp: keep DP module regions and their owner kernel-side (on top of PR11563) - #11610
Conversation
|
Keeping as draft until #11563 is merged. Submitting for early review and CI dry run. |
There was a problem hiding this comment.
🟡 Changes recommended
Critical lifetime-enforcement gaps still allow kernel operations on DP-writable interim heaps, while DP allocation/free wrappers can fault before reaching permitted syscalls.
4 open issues
What changed in this PR
Building on #11563, this PR moves DP region trust decisions into kernel state and tightens userspace allocation boundaries.
Changes:
- Track DP regions and their owners in kernel-only state.
- Add user-mode pipeline heaps and an LL module resource allowlist.
- Extend userspace tests and documentation.
| File | Description |
|---|---|
zephyr/test/userspace/test_ll_user_heap.c |
Adds heap, ownership, and allowlist tests. |
zephyr/test/userspace/README.md |
Documents interim-heap tests. |
zephyr/syscall/vregion.c |
Adds owner-aware allocation validation. |
zephyr/lib/vregion.c |
Implements region ownership and heap modes. |
zephyr/Kconfig |
Configures user-mode region heaps. |
zephyr/include/rtos/alloc.h |
Routes context allocations through user-heap helpers. |
src/lib/vregion_user.c |
Implements user-mode interim heaps. |
src/lib/objpool.c |
Uses user-aware region allocation helpers. |
src/lib/CMakeLists.txt |
Conditionally builds user-heap support. |
src/kernel/schedule/zephyr_dp_schedule_thread-kernel.c |
Updates the scheduler initialization signature. |
src/kernel/schedule/zephyr_dp_schedule_application-kernel.c |
Retains trusted regions and manages ownership. |
src/include/sof/userspace/README.md |
Documents allocation boundaries and ownership. |
src/include/sof/schedule/dp_schedule.h |
Adds the trusted-region scheduler parameter. |
src/include/sof/lib/vregion.h |
Declares ownership and user-heap APIs. |
src/include/sof/audio/pipeline.h |
Updates DP task initialization API. |
src/include/sof/audio/module_adapter/module/generic.h |
Declares LL resource registration helpers. |
src/audio/pipeline/pipeline-schedule.c |
Passes trusted regions to the scheduler. |
src/audio/pipeline/pipeline-graph.c |
Manages pipeline user-heap lifecycle. |
src/audio/module_adapter/module/generic.c |
Adds the LL module resource allowlist. |
src/audio/module_adapter/module_adapter.c |
Registers LL modules and passes DP regions directly. |
Review effort: Balanced
| if (lifetime_only) { | ||
| /* the kernel does not run a heap for the owner thread */ | ||
| LOG_ERR("error: interim alloc of %zu from %p by its owner refused", | ||
| size, (void *)vr); | ||
| p = NULL; |
There was a problem hiding this comment.
Good catch, thanks. Fixed in V2. Since the interim heap is created lazily on the next allocation, an owner request after vregion_set_interim() first had the kernel set up the heap in the DP-writable range and then refused it, and the common tail could read the heap statistics. Fixed: the owner (lifetime-only) request is now refused right after taking the lock, if the switch is pending or the region is no longer in lifetime mode, before interim_heap_init() and before any statistics are read. Squashed into "vregion: let the owner DP thread use its lifetime allocator" (commit message updated).
Telemetry reads the usage counters that the user-mode allocator of a pipeline region keeps at the start of the interim range. With telemetry enabled for user-space LL, the telemetry work, a kernel thread, read them in region memory that the LL and IPC user threads use. Kernel threads must not access the memory of user threads: that leaves kernel-ring DTLB entries, on which the user threads of the same core then fault. Read the counters only in system calls of user threads, which map the region, and keep the last values otherwise. Sample all user-mode region heaps where the LL user heap counters are sampled: every 1024 LL ticks, when LL tasks start and stop, and after the IPC commands. The sampling skips the regions whose lock is busy, so the LL thread is not held up. The test makes the IPC user thread copy the counters before it checks what telemetry reports. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
pipeline_complete() only warned when vregion_user_heap_add() failed and marked the pipeline ready. With the table of user-mode region heaps full, -ENOSPC, the region then had no heap at all: the kernel refuses its interim range too, so every allocation after the completion failed, starting with the pipeline task, although the region had free memory. Fail the completion in that case, so that the host gets the error at the state change. A region too small for a heap is still not fatal, as with the kernel-run interim heap. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
scheduler_dp_task_init() built the heap partitions of the DP domain from mod_heap_info(), which follows the allocation context pointer in module memory to the region. LL and IPC user threads can write that memory, so they could make the kernel map other memory into the DP domain. The kernel creates the region of a DP module itself, in module_adapter_mem_alloc(). Pass it on through pipeline_comp_dp_task_init() to scheduler_dp_task_init(), which keeps a reference in the kernel-only task record and takes the partition bounds from the kernel-only struct vregion. The reference is dropped when the task is freed. The free system call checks the caller's access to that region too. Modules without a region keep using mod_heap_info(). Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Add vregion_owner_set(), which records the owner thread of a region in the kernel-only struct vregion. The DP scheduler sets the DP thread as the owner of its module region right before the thread starts, and clears it when the task is freed, after the thread is aborted. The owner is not used yet. It lets the vregion system calls tell the DP thread of a module from other DP threads. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Add vregion_owner_check() for the vregion system call validators. It passes for the LL and IPC user threads and for the owner thread of the region, and unpins the region and kills any other caller, such as the DP thread of another module. vregion_alloc_align(), vregion_alloc_coherent_align() and vregion_free() now accept the owner DP thread, but only for the lifetime allocator, through the new kernel functions vregion_lifetime_alloc_align() and vregion_lifetime_free(): the kernel never runs the interim heap for it. Its requests are refused as soon as the region switches to interim allocations, before the kernel sets up the heap or reads its statistics. The other vregion system calls stay limited to the LL and IPC user threads. The DP threads do not use the calls yet. They will, once DP modules use their resources in user mode. Without the syscall caller registry, every user thread but the owner is treated as before. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
The LL and IPC user threads decided from the processing domain in the comp_dev whether to run the module resource functions in user mode or through the mod_dp_*() system calls. The comp_dev and module objects of a DP module are in DP memory, so a DP thread could mark its module as an LL module, or hand over a made-up module through dev->mod, and an IPC user thread would then walk a resource pool and allocation context that the DP thread controls, in user mode, with access to all LL memory. Register the LL modules in LL memory when they are created in user mode, in module_adapter_mem_alloc(), and remove them when their memory is freed. The user-mode path is now taken only for registered modules. Any other module goes to the system calls, whose validators reject LL modules and modules without a live vregion. The processing domain is still checked first, so that DP threads, which cannot access the list, use the system calls for their own module. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Add cases for the owner of a region, the DP thread of a module. It allocates from and frees to the lifetime allocator of its own region with the vregion system calls, coherent memory too, and its requests are refused, without a fault, once the kernel runs the interim heap. The IPC user thread may still use that heap. A thread that is neither the owner nor an LL or IPC user thread is killed, also when the region is mapped for it, and the pins of the killed calls are released. The module resource functions only run in user mode for LL modules that were registered when they were created: a module that claims to be an LL module but is not registered goes to the DP system call, which kills the IPC user thread. The existing cases register their module. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Describe how the kernel keeps the region of a DP module and records its DP thread as the owner, which vregion system calls the owner may use, and that the LL and IPC user threads use the resources of registered LL modules only in user mode. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
1d9b96f to
de52db1
Compare
|
V2 pushed:
|
PR 11610: test resultsRun date: 2026-12-04 18:03 UTC Tested commit: de52db1d87f500798e6cbf5c6f3785b0f0dc59ab |


Depends on #11563 (user-mode interim heap of the pipeline regions)
This is the first step towards letting the DP thread of a module run the interim heap of its own region. It moves the trust decisions about DP module regions out of module memory that user threads can write, and into kernel-only state.
Testing: on PTL, the standalone userspace suites pass 12 of 12, and the full LL regression passes. The regression covered chain DMA, HDA, multiple-pipeline, DP streams, D3 and LL SRC, plus 50 DP create/free cycles with no page leak. Every commit builds, and the mtl, lnl, ptl, imx8m and testbench builds pass.
🤖 Generated with Claude Code