Skip to content

userspace: proxy: Add support for llext modules#10643

Open
softwarecki wants to merge 5 commits intothesofproject:mainfrom
softwarecki:userspace-llext
Open

userspace: proxy: Add support for llext modules#10643
softwarecki wants to merge 5 commits intothesofproject:mainfrom
softwarecki:userspace-llext

Conversation

@softwarecki
Copy link
Copy Markdown
Collaborator

  • Add support for userspace llext loadable modules to the userspace proxy.
  • Extend the SOF_LLEXT_MODULE_MANIFEST macro with an optional variadic parameter to specify the user_mode flag for llext modules. When the argument is omitted, user_mode defaults to 0, preserving backward compatibility with existing module manifests.
  • Allow fast_get sram buffer sharing across multiple userspace module instances when CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP is enabled.
  • Simplify checking whether a calling thread runs in userspace by verifying
    if the K_USER flag is set.
  • Add a memory partition for the module driver heap k_heap structure to the module's memory domain to allow it to be referenced by syscalls.
  • Update the userspace_proxy_memory_init function to reflect the removal of memory double mapping in Zephyr by replacing the CONFIG_XTENSA_MMU_DOUBLE_MAP with a simple CONFIG_SOF_ZEPHYR_HEAP_CACHED check.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 adds support for userspace llext modules in the userspace proxy and updates related memory-domain and fast_get behavior to accommodate shared heaps and Zephyr MMU changes.

Changes:

  • Extend llext module manifests to optionally set a user_mode flag and propagate it into rimage manifests.
  • Update userspace proxy memory-domain setup (including adding a partition for the module driver heap k_heap structure) and add llext domain integration.
  • Adjust fast_get() behavior for userspace/driver-heap configurations and simplify userspace-thread detection.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
zephyr/lib/userspace_helper.c Removes a now-unneeded macro alias related to heap caching configuration.
zephyr/lib/fast-get.c Adjusts buffer sharing/caching logic and userspace-thread detection.
tools/rimage/src/manifest.c Propagates user_mode into generated module manifests.
src/library_manager/lib_manager.c Makes agent start conditional and ensures LLEXT uses no agent interface.
src/include/module/module/llext.h Extends LLEXT manifest macro with optional user_mode argument.
src/audio/module_adapter/library/userspace_proxy.c Adds llext manager integration, updates memory-domain partitioning, and handles agent-less modules.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread zephyr/lib/fast-get.c
/* We only get there for large buffers */
if (k_current_get()->mem_domain_info.mem_domain->num_partitions > 1) {
/* We only get there for large buffers or module driver heap is in use */
if (k_current_get()->base.user_options & K_USER && size > FAST_GET_MAX_COPY_SIZE) {
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The comment states this branch applies to 'large buffers or module driver heap is in use', but the condition only gates on size > FAST_GET_MAX_COPY_SIZE. If the driver-heap configuration is intended to share buffers across userspace instances independent of size, the condition should incorporate CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP (or the comment should be corrected). As written, the driver-heap case is ignored by this userspace-thread path.

Suggested change
if (k_current_get()->base.user_options & K_USER && size > FAST_GET_MAX_COPY_SIZE) {
if ((k_current_get()->base.user_options & K_USER) &&
(size > FAST_GET_MAX_COPY_SIZE ||
IS_ENABLED(CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP))) {

Copilot uses AI. Check for mistakes.
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.

Can you address this, same problem, how do the comment and code relate?

Comment thread src/audio/module_adapter/library/userspace_proxy.c
Comment thread src/audio/module_adapter/library/userspace_proxy.c
Comment thread src/audio/module_adapter/library/userspace_proxy.c Outdated
Comment thread src/audio/module_adapter/library/userspace_proxy.c Outdated
Comment thread src/audio/module_adapter/library/userspace_proxy.c
Comment thread src/audio/module_adapter/library/userspace_proxy.c
Comment thread src/audio/module_adapter/library/userspace_proxy.c
@lyakh
Copy link
Copy Markdown
Collaborator

lyakh commented Mar 24, 2026

let's first merge a fast-get fix, before adding new features to it. Marking this DNM until #10639 is merged

@lyakh lyakh added the DNM Do Not Merge tag label Mar 24, 2026
@softwarecki softwarecki removed the DNM Do Not Merge tag label Mar 24, 2026
Comment thread src/audio/module_adapter/library/userspace_proxy.c Outdated
Comment thread src/audio/module_adapter/library/userspace_proxy.c Outdated
Comment thread src/audio/module_adapter/library/userspace_proxy.c
Copy link
Copy Markdown
Collaborator

@kv2019i kv2019i left a comment

Choose a reason for hiding this comment

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

Nothing major, a few notes inline.

Comment thread zephyr/lib/fast-get.c Outdated
Comment thread zephyr/lib/fast-get.c
/* We only get there for large buffers */
if (k_current_get()->mem_domain_info.mem_domain->num_partitions > 1) {
/* We only get there for large buffers or module driver heap is in use */
if (k_current_get()->base.user_options & K_USER && size > FAST_GET_MAX_COPY_SIZE) {
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.

Can you address this, same problem, how do the comment and code relate?

@lgirdwood
Copy link
Copy Markdown
Member

@softwarecki do I dare and click the fix conflicts button with copilot or do you want to fix ? and we can merge.

Comment thread src/include/module/module/llext.h
…FEST

Extend the SOF_LLEXT_MODULE_MANIFEST macro with an optional variadic
parameter to specify the user_mode flag for llext modules. When the
argument is omitted, user_mode defaults to 0, preserving backward
compatibility with existing module manifests.

Update the rimage to propagate the user_mode field from the module manifest
to manifest structure in the final firmware binary image.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
Add support for userspace llext loadable modules to the userspace proxy.
Call lib_manager_start_agent unconditionally, even when the system agent
is not used, as this function is responsible for creating the userspace
module proxy.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
Allow fast_get sram buffer sharing across multiple userspace module
instances when CONFIG_SOF_USERSPACE_USE_DRIVER_HEAP is enabled. The module
driver heap is shared by all instances of a given module, so allocated
buffers can safely be reused between them.

Simplify checking whether a calling thread runs in userspace by verifying
if the K_USER flag is set.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
Rename user_get_partition_attr() to user_get_partition_cache_attr().

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
Add a memory partition for the module driver heap k_heap structure to the
module's memory domain to allow it to be referenced by syscalls. When a new
memory domain is created, only L2 entries mapped with OPTION_SAVE_ATTRS are
copied. Memory mapped dynamically during firmware execution is not
accessible in new memory domains by default.

Update the code to reflect the removal of memory double mapping in Zephyr
by replacing the CONFIG_XTENSA_MMU_DOUBLE_MAP with a simple
CONFIG_SOF_ZEPHYR_HEAP_CACHED check.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
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.

8 participants