Skip to content

[Userspace LL] scattered commits from #10945 without dependencies - #11065

Open
lyakh wants to merge 10 commits into
thesofproject:mainfrom
lyakh:llprep
Open

[Userspace LL] scattered commits from #10945 without dependencies#11065
lyakh wants to merge 10 commits into
thesofproject:mainfrom
lyakh:llprep

Conversation

@lyakh

@lyakhlyakh commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

various commits from #10945 without unmerged dependencies

CopilotAI 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.

Pull request overview

This PR cherry-picks a set of userspace-LL–related changes (from #10945) to support userspace low-latency scheduling, including userspace-safe module allocation/freeing paths and memory-domain handling for dynamically loaded modules and DP vregion-backed allocations.

Changes:

  • Extend module/vregion allocation plumbing to track vregion address/size and (when CONFIG_SOF_USERSPACE_LL) map/unmap vregion memory into the LL memory domain via syscalls.
  • Update library manager + LLEXT manager to better integrate with Zephyr userspace (syscall for module free, LL domain integration, DP-domain exceptions).
  • Refactor IPC user thread creation to allocate kernel objects dynamically and improve multi-pipeline state handling safety.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
zephyr/include/rtos/alloc.hExtends mod_alloc_ctx with vregion base/size for domain mapping/unmapping.
zephyr/CMakeLists.txtAdds lib_manager.h to Zephyr syscall header generation.
src/schedule/zephyr_dp_schedule.cMoves scheduler state allocation to heap allocator and ensures ops struct is in sysuser data.
src/library_manager/llext_manager.cAdds LL-domain mapping logic and refactors module-domain add/remove internals.
src/library_manager/lib_manager.cIntroduces syscall-backed module free and refactors module create/free helper paths.
src/ipc/ipc4/helper.cTightens pointer types used for IPC payload parsing (unsigned char *).
src/ipc/ipc4/handler-user.cExtracts pipeline ID parsing and adds mailbox bounds checks for multi-pipeline IPC.
src/ipc/ipc-helper.cAdjusts locking path for userspace LL builds (avoid unused IRQ flags).
src/ipc/ipc-common.cRefactors IPC userspace thread creation to use dynamically allocated kernel objects.
src/include/sof/lib_manager.hAdds syscall declaration and exposes lib_manager_mod_create_priv() helper.
src/include/sof/audio/module_adapter/module/generic.hAdds syscalls for vregion creation/unmapping and exports vregion-free helper.
src/include/sof/audio/component.hAdds uid_cp storage to keep stable UUID backing for LLEXT module drivers.
src/audio/module_adapter/module_adapter.cImplements vregion syscalls, LL-domain partition mapping/unmapping, and unified vregion free helper.
src/audio/buffers/comp_buffer.cSwitches vregion-backed buffer teardown to the new module_adapter_vreg_free() helper.
Suppressed comments (3)

src/ipc/ipc4/handler-user.c:460

  • dcache_invalidate_region() is invalidating cnt entries of a uint32_t array, but uses sizeof(int) * cnt. This is the wrong element size and can under/over-invalidate depending on platform type sizes.
	dcache_invalidate_region((__sparse_force void __sparse_cache *)ppl_data->ppl_id,
sizeof(int) * cnt);

src/ipc/ipc4/handler-user.c:498

  • When there is a single pipeline, ppl_id = &id; points a const uint32_t * at an int. This is a type/size mismatch and can lead to incorrect ppl_id[i] values when iterating.
	if (ppl_count == 1)
ppl_id = &id;

src/audio/module_adapter/module_adapter.c:154

  • vreg_start and vreg_size are uninitialized when the vregion path is not taken, but are still copied into alloc. Even if currently unused when alloc->vreg == NULL, this is undefined/indeterminate data and can trigger compiler or static-analysis warnings.
	size_t vreg_size;
uintptr_t vreg_start;

Comment threadsrc/library_manager/llext_manager.c Outdated
Comment threadsrc/ipc/ipc4/handler-user.c
Comment threadsrc/audio/module_adapter/module_adapter.c Outdated
@lyakh
lyakhforce-pushed the llprep branch 3 times, most recently from 3fe509c to ff15ff6CompareAugust 5, 2026 15:22

@kv2019ikv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A few comments inline

Comment threadsrc/library_manager/lib_manager.c Outdated

static int z_vrfy_lib_manager_free_module(const uint32_t component_id)
{
return z_impl_lib_manager_free_module(component_id);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Isn't this too unsafe? Any user-space code (including non-privileged DP module can free a module)?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

@kv2019i ok, that commit requires more care than what this PR is supposed to need. I'm dropping it from here, let's check that separately.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@lyakh hmm, you say you drop but it's still here...?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

ok, this one is also better left out for when 8d16a0d is also merged, they go best together, then we can also improve safety

{
K_OOPS(K_SYSCALL_MEMORY_WRITE(vreg_start, sizeof(*vreg_start)));
K_OOPS(K_SYSCALL_MEMORY_WRITE(vreg_size, sizeof(*vreg_size)));
K_OOPS(K_SYSCALL_MEMORY_READ(config, sizeof(*config)));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Minor: syscall should do a copy of config to protect against user-space modifying the config when kernel code is using the struct. Not really an issue yet as "config" is unused for now, but could be an issue later if config desribes the size of allocation needed and kernel needs to verify valid config parameters. To prepare for this case, a copy should be made of config (or at least a visible TODO/FIXME).

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

@lyakh hmm, you say you drop but it's still here...?

@kv2019i ah, sorry, it's this one that I've dropped for now. Let me check the other one that you'd commented about

@lyakh
lyakhforce-pushed the llprep branch 4 times, most recently from 010fa8f to 4057273CompareAugust 7, 2026 12:03
lyakh added 5 commits August 7, 2026 14:54
When CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP isn't selected, dynamically
allocated driver objects should still be accessible to the userspace.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
When loading and linking LLEXT modules map them automatically for the
LL memory domain, unless they belong to the DP domain.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Prepare for multi-core support: allocate the IPC thread dynamically
and extract thread initialisation into a separate function.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Userspace IPC context is global, allocate it uncached.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
The SOF_IPC4_GLB_SET_PIPELINE_STATE IPC can apply to one or to
multiple pipelines. Extract pipeline ID detection into a function
to be re-used with userspace IPC processing.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
lyakh added 5 commits August 7, 2026 14:54
DP scheduler operations, instance data and DP module memory have to
be accessible to the userspace LL scheduler. Allocate dynamic data on
the userspace heap and place static data in the userspace accessible
ELF section.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Fix an "unused variable" compiler warning for when buildins with
CONFIG_SOF_USERSPACE_LL=y.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Change several pointers from "char *" to "unsigned char *" to reduce
the number of type-casts.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
The .uid field in struct comp_driver is used for driver
identification using its unique UUID. However with LLEXT that UUID is
located in DRAM, which makes access to it difficult from userspace
threads. Make a local copy of it instead for reliable driver
searching from different contexts.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Add a check to llext_manager_mod_find() in case scanning the array
reached the last element, that the index indeed is within that
element's range. Return an error otherwise.
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>

@kv2019ikv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @lyakh , this set looks fine now.

Sign up for freeto 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

@lyakh@kv2019i