Skip to content

Conversation

@softwarecki
Copy link
Collaborator

  • Add helper functions user_add_memory and user_remove_memory that allows to add/remove memory regions from the memory domain. The purpose of these functions is to round addresses appropriately for the memory domain.
  • Extend the module_adapter_new_ext function with an additional user_ctx parameter. This enables the caller to explicitly set the userspace context field within the processing module structure during module adapter initialization.
  • Introduce initial support for userspace proxy logic. This includes configuring the module's memory domain to ensure proper access rights and creating intermediary functions that forward calls to the module's interface.
  • Introduce support for loading userspace modules. Allow the DP thread to process audio data in userspace.

jxstelter and others added 4 commits October 14, 2025 21:49
Add helper functions user_add_memory and user_remove_memory that allows to
add/remove memory regions from the memory domain. The purpose of these
functions is to round addresses appropriately for the memory domain.

Signed-off-by: Jaroslaw Stelter <[email protected]>
Signed-off-by: Adrian Warecki <[email protected]>
Introduce initial support for userspace proxy logic. This includes
configuring the module's memory domain to ensure proper access rights and
creating intermediary functions that forward calls to the module's
interface.

Signed-off-by: Jaroslaw Stelter <[email protected]>
Signed-off-by: Adrian Warecki <[email protected]>
Extend the module_adapter_new_ext function with an additional user_ctx
parameter. This enables the caller to explicitly set the userspace context
field within the processing module structure during module adapter
initialization.

Signed-off-by: Adrian Warecki <[email protected]>
Introduce support for loading userspace modules. Allow the DP thread to
process audio data in userspace.

Signed-off-by: Jaroslaw Stelter <[email protected]>
Signed-off-by: Adrian Warecki <[email protected]>
Copy link

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 implements userspace module data processing support in the PTL MMU component. It introduces helper functions for memory domain management, extends module adapter initialization, and provides userspace proxy functionality to enable audio data processing in userspace modules.

  • Add memory domain helper functions for adding/removing memory regions with proper alignment
  • Extend module adapter initialization with userspace context parameter
  • Implement userspace proxy module with complete interface forwarding for secure module execution

Reviewed Changes

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

Show a summary per file
File Description
zephyr/lib/userspace_helper.c Implements user_add_memory and user_remove_memory functions for memory domain management
zephyr/include/rtos/userspace_helper.h Adds function declarations for memory domain helper functions
uuid-registry.txt Registers UUID for userspace_proxy module
src/library_manager/lib_manager.c Integrates userspace proxy creation and module registration with userspace support
src/include/sof/audio/module_adapter/module/generic.h Updates module_adapter_new_ext signature to include userspace context
src/include/sof/audio/module_adapter/library/userspace_proxy.h Defines userspace proxy interface and context structure
src/audio/module_adapter/module_adapter.c Updates module adapter to use userspace-aware memory allocation
src/audio/module_adapter/module/modules.c Adds APP_TASK_DATA annotation to processing module interface
src/audio/module_adapter/library/userspace_proxy.c Implements complete userspace proxy module with interface forwarding
src/audio/module_adapter/CMakeLists.txt Adds conditional compilation for userspace proxy

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

int ret;

/* Define parameters for user_partition */
k_mem_region_align(&addr_aligned, &size_aligned, (uintptr_t)addr, size, HOST_PAGE_SIZE);
Copy link

Copilot AI Oct 14, 2025

Choose a reason for hiding this comment

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

Redundant cast to uintptr_t - the parameter addr is already of type uintptr_t.

Suggested change
k_mem_region_align(&addr_aligned, &size_aligned, (uintptr_t)addr, size, HOST_PAGE_SIZE);
k_mem_region_align(&addr_aligned, &size_aligned, addr, size, HOST_PAGE_SIZE);

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

ditto - lets keep this in pages so that clients are forced to consider what's in userspace and whats not.

const struct sof_man_module *manifest, system_agent_start_fn start_fn,
uintptr_t entry_point, uint32_t module_id, uint32_t instance_id,
uint32_t core_id, uint32_t log_handle, byte_array_t *mod_cfg,
const void **agent_interface, const struct module_interface **ops)
Copy link
Collaborator

Choose a reason for hiding this comment

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

that looks like way too many parameters to me

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that this function takes too many parameters, but I see that lib_manager_start_agent looks similar. Maybe later it would be worth giving them a little makeover.

#endif /* CONFIG_IPC_MAJOR_4 */

module_driver_heap_free(drv->user_heap, mod);
module_driver_heap_free(drv->user_heap, dev);
Copy link
Collaborator

Choose a reason for hiding this comment

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

this and a similar hunk below are unrelated bug-fixes, also fixed in 0087192

@lyakh
Copy link
Collaborator

lyakh commented Oct 15, 2025

@softwarecki also a general request: could you please put your implementation under #if CONFIG_... using a new Kconfig option, e.g. the one I'm adding in 3e5f62c

Copy link
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

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

@softwarecki we are going to have several options around userspace and will need to split the CONFIG_USERSPACE into more meaningful configs e.g. we could have

  1. CONFIG_USERSPACE code needed by all userspace.
  2. CONFIG_USERSPACE_DP_PROXY code needed by this PR
  3. CONFIG_USERSPACE_APP code needed by running infra and LL in userspace.

This way it should mean easier partitioning of the code.

One other thing is we will need more abstraction around memory alloc and free so that the modules allocate from the right place depending on the CONFIG.

return k_mem_domain_add_thread(comp_dom, thread_id);
}

int user_add_memory(struct k_mem_domain *domain, uintptr_t addr, size_t size, uint32_t attr)
Copy link
Member

Choose a reason for hiding this comment

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

it probably better if we fail if size or addr are not page aligned, that way we force the client users to think about whats in the domain (rather than silently growing the domain to include the whole page).

int ret;

/* Define parameters for user_partition */
k_mem_region_align(&addr_aligned, &size_aligned, (uintptr_t)addr, size, HOST_PAGE_SIZE);
Copy link
Member

Choose a reason for hiding this comment

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

ditto - lets keep this in pages so that clients are forced to consider what's in userspace and whats not.

Comment on lines -1281 to +1286
rfree(mod->stream_params);
rfree(mod);
rfree(dev);
module_driver_heap_free(drv->user_heap, mod->stream_params);
module_driver_heap_free(drv->user_heap, mod);
module_driver_heap_free(drv->user_heap, dev);
Copy link
Member

Choose a reason for hiding this comment

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

Fwiw, I have a change coming here that will mean some abstraction. Yes we will still be able to assign the pages to the user driver domain, but the method to allocate/free will be different as pipeline/DP modules will have virtual continuous pages preallocated for them (and the driver user heap would reside in these pages).

Copy link
Member

Choose a reason for hiding this comment

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

@softwarecki ok, we are still keeping the free() so this should merge in with minimal update now.

/* Intel modules expects DW size here */
mod_cfg.size = args->size >> 2;

#if CONFIG_USERSPACE
Copy link
Member

Choose a reason for hiding this comment

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

We need to abstract this config a little better as we will have more userspace Kconfig options.

Copy link
Contributor

@tmleman tmleman left a comment

Choose a reason for hiding this comment

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

Just minor comments and questions.

const struct sof_man_module *manifest, system_agent_start_fn start_fn,
uintptr_t entry_point, uint32_t module_id, uint32_t instance_id,
uint32_t core_id, uint32_t log_handle, byte_array_t *mod_cfg,
const void **agent_interface, const struct module_interface **ops)
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that this function takes too many parameters, but I see that lib_manager_start_agent looks similar. Maybe later it would be worth giving them a little makeover.

Comment on lines +171 to +175
ret = k_mem_domain_add_partition(domain, &part);
/* -EINVAL means that given page is already in the domain */
/* Not an error case for us. */
if (ret == -EINVAL)
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

How do we know that's the case here? This error can be returned in many other cases by this function.

Copy link
Contributor

@tmleman tmleman left a comment

Choose a reason for hiding this comment

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

You'll get my approval once you fix the issues reported by checkpatch and clarify that one small issue below.

Comment on lines -744 to +782
rfree(drv);
rfree(new_drv_info);
module_driver_heap_free(drv_heap, drv);
module_driver_heap_free(drv_heap, new_drv_info);
module_driver_heap_remove(drv_heap);
Copy link
Contributor

Choose a reason for hiding this comment

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

new_drv_info is from rzalloc.

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.

5 participants