Skip to content

Commit 2e829d2

Browse files
committed
llext_manager: persist llext_buf_loader
For inspection API to work, it is imperative to keep the LLEXT loader object available. This patch adds a pointer to the full loader object in the lib_manager_module structure. The loader object is allocated once and never freed. Signed-off-by: Luca Burelli <[email protected]>
1 parent f9602f7 commit 2e829d2

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/include/sof/lib_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ struct lib_manager_module {
103103
* the library-global driver list */
104104
const struct sof_man_module_manifest *mod_manifest;
105105
struct llext *llext; /* Zephyr loadable extension context */
106+
struct llext_buf_loader *ebl; /* Zephyr loadable extension buffer loader */
106107
bool mapped;
107108
struct lib_manager_segment_desc segment[LIB_MANAGER_N_SEGMENTS];
108109
};

src/library_manager/llext_manager.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,12 @@ static bool llext_manager_section_detached(const elf_shdr_t *shdr)
239239
return shdr->sh_addr < SOF_MODULE_DRAM_LINK_END;
240240
}
241241

242-
static int llext_manager_link(struct llext_loader *ldr, const char *name,
242+
static int llext_manager_link(const char *name,
243243
struct lib_manager_module *mctx, const void **buildinfo,
244244
const struct sof_man_module_manifest **mod_manifest)
245245
{
246246
struct llext **llext = &mctx->llext;
247+
struct llext_loader *ldr = &mctx->ebl->loader;
247248
int ret;
248249

249250
if (*llext && !mctx->mapped) {
@@ -353,6 +354,7 @@ static int llext_manager_mod_init(struct lib_manager_mod_ctx *ctx,
353354
offs = mod_array[i].segment[LIB_MANAGER_TEXT].file_offset;
354355
ctx->mod[n_mod].mapped = false;
355356
ctx->mod[n_mod].llext = NULL;
357+
ctx->mod[n_mod].ebl = NULL;
356358
ctx->mod[n_mod++].start_idx = i;
357359
}
358360

@@ -431,15 +433,30 @@ static int llext_manager_link_single(uint32_t module_id, const struct sof_man_fw
431433
PAGE_SZ);
432434

433435
uintptr_t dram_base = (uintptr_t)desc - SOF_MAN_ELF_TEXT_OFFSET;
434-
struct llext_buf_loader ebl = LLEXT_BUF_LOADER((uint8_t *)dram_base + mod_offset, mod_size);
436+
437+
if (!mctx->ebl) {
438+
/* allocate once, never freed */
439+
mctx->ebl = rmalloc(SOF_MEM_ZONE_RUNTIME_SHARED, 0, SOF_MEM_CAPS_RAM,
440+
sizeof(struct llext_buf_loader));
441+
if (!mctx->ebl) {
442+
tr_err(&lib_manager_tr, "loader alloc failed");
443+
return 0;
444+
}
445+
446+
/* initialize via a temporary */
447+
struct llext_buf_loader tmp_ebl = LLEXT_BUF_LOADER((uint8_t *)dram_base +
448+
mod_offset, mod_size);
449+
450+
*mctx->ebl = tmp_ebl;
451+
}
435452

436453
/*
437454
* LLEXT linking is only needed once for all the "drivers" in the
438455
* module. This calls llext_load(), which also takes references to any
439456
* dependencies, sets up sections and retrieves buildinfo and
440457
* mod_manifest
441458
*/
442-
ret = llext_manager_link(&ebl.loader, mod_array[entry_index - inst_idx].name, mctx,
459+
ret = llext_manager_link(mod_array[entry_index - inst_idx].name, mctx,
443460
buildinfo, mod_manifest);
444461
if (ret < 0) {
445462
tr_err(&lib_manager_tr, "linking failed: %d", ret);

0 commit comments

Comments
 (0)