Skip to content

schedule: move DP module allocations off the LL user heap - #11479

Open
kv2019i wants to merge 4 commits into
thesofproject:mainfrom
kv2019i:202611-ll-heap-dp
Open

kv2019i wants to merge 4 commits into
thesofproject:mainfrom
kv2019i:202611-ll-heap-dp

Conversation

@kv2019i

@kv2019i kv2019i commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

DP modules are created by kernel code (ipc4_init_module_instance()) and then run in their own DP user thread. While creating them, the kernel still allocated three kinds of objects from the LL user heap, whose sys_heap metadata user threads can write:

  • the module allocation context;
  • the component container;
  • the module configuration buffers.

Two problems came with this:

  • Free from another context: some of these objects were freed by a different context than the one that allocated them, such as the IPC user thread or whichever holder dropped the last vregion reference.
  • DP thread killed: DP modules that call module_set_configuration() called sof_heap_alloc() from the DP thread, and the syscall caller check kills that thread.

After this series, creating a DP module no longer allocates from the LL user heap in kernel code.

This is preparation for moving LL user heap completely to user-space, completing isolation of kernel code.

Copilot AI balanced review requested due to automatic review settings November 17, 2026 20:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical issues remain: a forwarding timeout can leave a freed component accessible to the IPC user thread or component list, and repeated configuration calls can exhaust non-reclaimable staging storage.

2 open issues
What changed in this PR

Moves DP module allocations away from the LL user heap, preparing SOF for stronger kernel/user-space isolation.

Changes:

  • Uses module-owned storage for DP allocation contexts and configuration buffers.
  • Delegates registration of kernel-created DP components to the IPC user thread.
  • Updates cleanup and documents the revised allocation ownership.
File Description
src/​kernel/​ipc/​ipc4/​helper-kernel.c Defers component registration when LL userspace is enabled.
src/​kernel/​ipc/​ipc4/​handler-user-kernel.c Hands component registration to the IPC user thread.
src/​ipc/​ipc4/​handler-user.c Registers components already created by the kernel.
src/​include/​sof/​userspace/​README.md Documents DP allocation ownership and registration.
src/​include/​sof/​ipc/​common.h Adds the component pointer used for the handoff.
src/​audio/​module_adapter/​module/​generic.c Moves configuration buffers to module-managed allocation.
src/​audio/​module_adapter/​module_adapter.c Places DP allocation contexts in their virtual regions.
src/​audio/​buffers/​comp_buffer.c Relies on virtual-region teardown to release allocation contexts.

Review effort: Balanced

@intel-sofci

intel-sofci commented Nov 17, 2026 •

Copy link
Copy Markdown

PR 11479: test results

Run date: 2026-11-18 17:01 UTC

Tested commit: 5ed38403f308fcf9b94fdcda5ff0128d12ca79bb

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

@lgirdwood

Copy link
Copy Markdown
Member

@kv2019i I guess you will re-flow for copilot and CI, but LGTM.

DP modules are created by kernel code, which allocated the allocation
context of each DP module from the LL user heap, whose metadata user
threads can write. The context was then freed by whichever of the
module and its buffers dropped the last reference to the module's
vregion.

Allocate the context from the module's own vregion instead. It is
released with the vregion, so the module and buffer free paths only
put their vregion reference.

The context becomes writable by the DP thread. This does not give the
DP thread new means: it can already make the module point to any
context through struct processing_module, which is in the same
vregion.

Signed-off-by: Kai Vehmanen <[email protected]>
With CONFIG_SOF_USERSPACE_LL, DP modules are created by kernel code,
which then allocated the component container from the LL user heap,
whose metadata user threads can write, and linked it into the
user-writable component list. The container was later freed by the IPC
user thread.

After creating a DP component, forward the request to the IPC user
thread of the core, which adds the component to the list, so the
container is both allocated and freed by that thread. If the thread
reports an error, the kernel frees the component. If the forward times
out, the thread may still add the component later, so the kernel
withdraws the component from the request and does not free it. At
worst the component is leaked, but never used after it is freed.

Signed-off-by: Kai Vehmanen <[email protected]>
module_set_configuration() and module_load_config() allocated the
runtime parameter and configuration buffers with sof_heap_alloc() from
the LL user heap. Modules such as cadence, waves, dts and ffmpeg call
module_set_configuration() from their set_configuration operation,
which for a DP module runs in the DP thread. DP threads may not call
sof_heap_alloc(), so the system call caller check kills the thread.

Allocate and free the buffers of DP modules through the module's
allocation context instead, as module memory in their vregion. Other
modules keep using the LL user heap.

Until the pipeline is complete, a vregion only has its lifetime
allocator, which does not reclaim freed memory, and the host sets the
module configuration before that. So keep the staging buffer of
module_set_configuration() for the next request of a DP module, and
only replace it when a larger one is needed, instead of allocating a
new one for each request. The buffer is freed with the module.

Signed-off-by: Kai Vehmanen <[email protected]>
Document that the allocation context, pin formats and configuration
buffers of DP modules are in the module vregion, and that the IPC user
thread adds kernel-created DP components to the component list.

Signed-off-by: Kai Vehmanen <[email protected]>
@kv2019i

kv2019i commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

V2 pushed:

  • fixed code review comments
  • rebased to latest main as there was a regression mainline that broken DP tests on some targets

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Alternating configuration sizes repeatedly allocate non-reclaimable DP vregion storage, risking exhaustion and configuration failures with -ENOMEM unless destination capacity is tracked and reused.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment on lines +126 to +127
module_cfg_free(mod, dst->data);
dst->data = module_cfg_alloc(mod, size);
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.

4 participants