[userspace LL] LLEXT part of #10945 - #11112
Conversation
Move llext_manager_add_partition() and llext_manager_rm_partition() higher in the file for future use. No functional change. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
There was a problem hiding this comment.
Pull request overview
This PR extracts LLEXT-related userspace LL scheduling changes (from #10945) into the main SOF library manager flow, primarily by making LLEXT module identification available outside llext_manager.c and by adding temporary memory-domain partitioning to support LLEXT unload/unmap operations.
Changes:
- Exposes
llext_manager_mod_find()viasof/llext_manager.hand uses it inlib_manager_free_module()to route frees to the LLEXT manager when applicable. - Adds temporary mapping of ELF section-header inspection data during LLEXT module unload to support section-based unmapping.
- Refactors
CONFIG_USERSPACEpartition helper placement inllext_manager.c(moved earlier in file).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/library_manager/llext_manager.c | Adds/uses userspace memory-domain partition helpers during unload; exports llext_manager_mod_find() for external use. |
| src/library_manager/lib_manager.c | Routes module freeing to LLEXT manager based on llext_manager_mod_find() result. |
| src/include/sof/llext_manager.h | Declares llext_manager_mod_find() and adds a non-LLEXT stub macro for it. |
Suppressed comments (2)
src/library_manager/llext_manager.c:594
llext_manager_mod_find()can dereferencectx/ctx->modwhen they are NULL and can also readctx->mod[i - 1]whenctx->n_mod == 0. Additionally, whenidx < ctx->mod[0].start_idx, it currently returnsi - 1(wrap/underflow) rather than a clear-ENOENT. This function is now part of the public API, so it should defensively validate inputs and bounds.
int llext_manager_mod_find(const struct lib_manager_mod_ctx *ctx, unsigned int idx)
{
unsigned int i;
for (i = 0; i < ctx->n_mod; i++)
src/library_manager/llext_manager.c:422
llext_manager_rm_partition()is called unconditionally here, and its return value is ignored. This has the same compile-guard issue as the add call above, and a remove failure should be surfaced (at least by propagating intoerr).
llext_manager_rm_partition(zephyr_ll_mem_domain(), (uintptr_t)shdr, total,
K_MEM_PARTITION_P_RW_U_NA | XTENSA_MMU_CACHED_WB);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| unsigned int sect_cnt = llext_section_count(ext); | ||
| size_t total = sect_cnt * sizeof(elf_shdr_t); | ||
| const elf_shdr_t *shdr; | ||
|
|
||
| ret = llext_get_section_info(ldr, ext, 0, &shdr, NULL, NULL); | ||
| if (ret < 0) | ||
| return ret; | ||
|
|
||
| /* Temporarily map ELF section headers */ | ||
| llext_manager_add_partition(zephyr_ll_mem_domain(), (uintptr_t)shdr, total, | ||
| K_MEM_PARTITION_P_RW_U_NA | XTENSA_MMU_CACHED_WB); | ||
|
|
| struct lib_manager_mod_ctx *ctx = lib_manager_get_mod_ctx(module_id); | ||
| uint32_t entry_index = LIB_MANAGER_GET_MODULE_INDEX(module_id); | ||
|
|
||
| if (entry_index >= desc->header.num_module_entries) { | ||
| tr_err(&lib_manager_tr, "Invalid driver index %u exceeds %d", | ||
| entry_index, desc->header.num_module_entries - 1); | ||
| return -ENOENT; | ||
| } | ||
|
|
||
| if (!ctx->mod) { | ||
| tr_err(&lib_manager_tr, "NULL module array: ID %#x ctx %p", component_id, ctx); |
| if (llext_manager_mod_find(ctx, entry_index) >= 0) | ||
| return llext_manager_free_module(component_id); |
| #define llext_manager_free_module(component_id) 0 | ||
| #define llext_manager_add_library(module_id) 0 | ||
| #define llext_manager_add_domain(component_id, domain) 0 | ||
| #define llext_manager_mod_find(ctx, idx) -ENOENT |
abea509 to
b412170
Compare
With userspace LL enabled module freeing runs in syscall contex on behalf of the userspace IPC thread. That thread doesn't have access to DRAM. Therefore we cannot call lib_manager_get_module_manifest() in that case. Use SRAM module data by calling llext_manager_mod_find() instead. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
llext_manager_unload_module() is called in a syscall context on behalf of the userspace IPC thread, so it doesn't have direct access to LLEXT module DRAM data. Map section headers temporarily for the duration of the function. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
llext_manager_free_module() cannot access DRAM when running with userspace LL enabled. Don't call lib_manager_get_library_manifest() to obtain the DRAM descriptor, needed to verify the entry index. The index is now verified by llext_manager_mod_find(). Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
|
FYI @abonislawski @lrudyX I assume the new CI/pull_request jobs can be ignored for now as long as old "CI/merge/*" jobs pass. Right? Please notify if I start to block on the new pull_request jobs. The testbench fail is known error (fixed in main), so proceeding with merge. |
LLEXT related commits from #10945