Skip to content

Commit 761633a

Browse files
committed
userspace: proxy: Add partition for k_heap struct
Add a memory partition for the module driver heap k_heap structure to the module's memory domain to allow it to be referenced by syscalls. When a new memory domain is created, only L2 entries mapped with OPTION_SAVE_ATTRS are copied. Memory mapped dynamically during firmware execution is not accessible in new memory domains by default. Update the code to reflect the removal of memory double mapping in Zephyr by replacing the CONFIG_XTENSA_MMU_DOUBLE_MAP with a simple CONFIG_SOF_ZEPHYR_HEAP_CACHED check. Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
1 parent 7fa81f8 commit 761633a

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/audio/module_adapter/library/userspace_proxy.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,24 @@ static int userspace_proxy_memory_init(struct userspace_context *user_ctx,
276276
tr_dbg(&userspace_proxy_tr, "Heap partition %#lx + %zx, attr = %u",
277277
heap_part.start, heap_part.size, heap_part.attr);
278278

279-
#if !defined(CONFIG_XTENSA_MMU_DOUBLE_MAP) && defined(CONFIG_SOF_ZEPHYR_HEAP_CACHED)
280-
#define HEAP_PART_CACHED
279+
/* When a new memory domain is created, only the "factory" entries from the L2 page
280+
* tables are copied. Memory that was dynamically mapped during firmware execution
281+
* will not be accessible from the new domain. The k_heap structure (drv->user_heap)
282+
* resides in such dynamically mapped memory, so we must explicitly add a partition
283+
* for it to ensure that syscalls can access this structure from the userspace domain.
284+
*/
285+
struct k_mem_partition heap_struct_part;
286+
287+
k_mem_region_align(&heap_struct_part.start, &heap_struct_part.size,
288+
POINTER_TO_UINT(drv->user_heap),
289+
sizeof(*drv->user_heap), CONFIG_MM_DRV_PAGE_SIZE);
290+
heap_struct_part.attr = K_MEM_PARTITION_P_RW_U_NA |
291+
user_get_partition_attr(heap_struct_part.start);
292+
293+
tr_err(&userspace_proxy_tr, "Heap struct partition %#lx + %zx, attr = %u",
294+
heap_struct_part.start, heap_struct_part.size, heap_struct_part.attr);
295+
296+
#if defined(CONFIG_SOF_ZEPHYR_HEAP_CACHED)
281297
/* Add cached module private heap to memory partitions */
282298
struct k_mem_partition heap_cached_part = {
283299
.attr = K_MEM_PARTITION_P_RW_U_RW | XTENSA_MMU_CACHED_WB
@@ -296,10 +312,11 @@ static int userspace_proxy_memory_init(struct userspace_context *user_ctx,
296312
* These include ops structures marked with APP_TASK_DATA.
297313
*/
298314
&common_partition,
299-
#ifdef HEAP_PART_CACHED
315+
#ifdef CONFIG_SOF_ZEPHYR_HEAP_CACHED
300316
&heap_cached_part,
301317
#endif
302-
&heap_part
318+
&heap_part,
319+
&heap_struct_part
303320
};
304321

305322
tr_dbg(&userspace_proxy_tr, "Common partition %#lx + %zx, attr = %u",

zephyr/lib/userspace_helper.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include <sof/lib/dai.h>
2424
#include <sof/lib/dma.h>
2525

26-
#define MODULE_DRIVER_HEAP_CACHED CONFIG_SOF_ZEPHYR_HEAP_CACHED
27-
2826
/* Zephyr includes */
2927
#include <zephyr/kernel.h>
3028
#include <zephyr/app_memory/app_memdomain.h>

0 commit comments

Comments
 (0)