Skip to content

Commit 5224f8b

Browse files
committed
library_manager: Guard DRAM store/restore with CONFIG_ADSP_IMR_CONTEXT_SAVE
When ADSP IMR context save is disabled (CONFIG_ADSP_IMR_CONTEXT_SAVE=n), the HP-SRAM and L3 heap memory are lost during PM runtime suspend/resume. However, the LLEXT library manager state `lib_manager_dram` resides in the persistent IMR data section (`__imrdata`) and retains stale pointers (such as `lib_manager_dram.ctx` pointing to the now-invalid L3 heap address from the first boot). On resume, `llext_manager_restore_from_dram()` would try to restore libraries from these stale pointers, causing register window underflows and fatal exceptions (EXCCAUSE_ILLEGAL) when executing scheduler work queues on subsequent IPC handling. Guard `llext_manager_store_to_dram()` and `llext_manager_restore_from_dram()` with `IS_ENABLED(CONFIG_ADSP_IMR_CONTEXT_SAVE)`. If context save is disabled, the library manager cleanly re-initializes on resume boot, forcing libraries to reload correctly. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 3347ddc commit 5224f8b

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/library_manager/llext_manager_dram.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ __imrdata static struct lib_manager_dram_storage lib_manager_dram;
3535
/* Store LLEXT manager context in DRAM to be restored during the next boot. */
3636
int llext_manager_store_to_dram(void)
3737
{
38+
/*
39+
* If IMR context save is disabled, HP-SRAM and L3 heap memory are lost
40+
* on suspend/resume, but IMR remains persistent. Skip saving to avoid
41+
* restoring stale pointers.
42+
*/
43+
if (!IS_ENABLED(CONFIG_ADSP_IMR_CONTEXT_SAVE)) {
44+
return 0;
45+
}
46+
3847
struct ext_library *_ext_lib = ext_lib_get();
3948
unsigned int i, j, k, l, n_lib, n_mod, n_llext, n_sect, n_sym;
4049
size_t buf_size;
@@ -161,6 +170,15 @@ int llext_manager_store_to_dram(void)
161170

162171
int llext_manager_restore_from_dram(void)
163172
{
173+
/*
174+
* If IMR context save is disabled, the L3 heap and HP-SRAM memory were lost.
175+
* The saved context will contain stale pointers, so cleanly re-initialize instead.
176+
*/
177+
if (!IS_ENABLED(CONFIG_ADSP_IMR_CONTEXT_SAVE)) {
178+
lib_manager_init();
179+
return 0;
180+
}
181+
164182
lib_manager_init();
165183

166184
struct ext_library *_ext_lib = ext_lib_get();

zephyr/lib/alloc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,11 @@ static int heap_init(void)
838838

839839
arch_mem_map(l3_heap_start, va, l3_heap_size, K_MEM_PERM_RW | K_MEM_CACHE_WB);
840840
#endif
841-
if (l3_heap_copy.heap.heap) {
841+
/*
842+
* If IMR context save is disabled, the L3 heap memory is lost during
843+
* suspend/resume, so do not restore from the stale copy.
844+
*/
845+
if (IS_ENABLED(CONFIG_ADSP_IMR_CONTEXT_SAVE) && l3_heap_copy.heap.heap) {
842846
l3_heap = l3_heap_copy;
843847
} else {
844848
l3_heap.heap.init_mem = l3_heap_start;

0 commit comments

Comments
 (0)