-
Notifications
You must be signed in to change notification settings - Fork 347
ptl: mmu: Enable module data processing in userspace #10305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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]>
There was a problem hiding this 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); |
Copilot
AI
Oct 14, 2025
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
|
@softwarecki also a general request: could you please put your implementation under |
There was a problem hiding this 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
- CONFIG_USERSPACE code needed by all userspace.
- CONFIG_USERSPACE_DP_PROXY code needed by this PR
- 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) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
| 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); |
There was a problem hiding this comment.
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.
user_add_memoryanduser_remove_memorythat allows to add/remove memory regions from the memory domain. The purpose of these functions is to round addresses appropriately for the memory domain.module_adapter_new_extfunction with an additionaluser_ctxparameter. This enables the caller to explicitly set the userspace context field within the processing module structure during module adapter initialization.