schedule: zephyr_ll_user: improve heap init and make it usable from user-space#10807
schedule: zephyr_ll_user: improve heap init and make it usable from user-space#10807kv2019i wants to merge 4 commits into
Conversation
Separate the state for LL scheduler memory into kernel and user accessible resources. The pointer to the LL heap must be accessible from user-space, so that user space can allocate memory and pass the heap pointer as argument. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
|
For context, part of #10558 |
There was a problem hiding this comment.
Pull request overview
This PR extends the Zephyr userspace support to provide a dedicated, shared low-latency (LL) userspace heap with embedded k_heap metadata, enabling safer use from userspace syscall verification paths and making the LL heap pointer accessible from userspace.
Changes:
- Add
sys_user_heap_init()/sys_user_heap_remove()to allocate/free a single page-aligned region containing bothstruct k_heapand its backing buffer. - Introduce
CONFIG_SOF_ZEPHYR_SYS_USER_HEAP_SIZEto configure the shared LL userspace heap size. - Update the LL userspace scheduler resources to use the new heap and expose the heap pointer via a sysuser app-memory section, plus attach the sysuser partition to the LL domain.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| zephyr/lib/userspace_helper.c | Adds shared LL userspace heap init/free with embedded k_heap metadata. |
| zephyr/Kconfig | Adds configurable size option for the shared LL userspace heap. |
| zephyr/include/rtos/userspace_helper.h | Exposes the new heap APIs and documents behavior/usage. |
| src/schedule/zephyr_ll_user.c | Switches LL heap init to the new API and exposes a userspace-accessible heap pointer/partition. |
| struct k_heap *module_driver_heap_init(void); | ||
|
|
||
| /** | ||
| * Initialize private processing module heap with embedded metadata. |
| * Free private processing module heap allocated by | ||
| * sys_user_heap_init(). | ||
| * @param mod_drv_heap pointer to the k_heap structure. |
| const size_t alloc_size = CONFIG_SOF_ZEPHYR_SYS_USER_HEAP_SIZE; | ||
| const size_t prefix_size = ALIGN_UP(sizeof(struct k_heap), 4); | ||
| const size_t kheap_size = alloc_size - prefix_size; |
| void sys_user_heap_remove(struct k_heap *mod_drv_heap) | ||
| { | ||
| if (mod_drv_heap) | ||
| rfree(mod_drv_heap); |
| /* store a user-accessible pointer */ | ||
| zephyr_ll_heap = ll_mem_resources.heap; | ||
|
|
||
| /* attach common partition to LL domain */ | ||
| user_memory_attach_common_partition(zephyr_ll_mem_domain()); | ||
| user_memory_attach_system_user_partition(zephyr_ll_mem_domain()); |
There was a problem hiding this comment.
The existing user_memory_attach() calls don't check the errors, so I prefer to leave them out here as well. We get decent errors for access permissions nowadays, so if this fails, we get a good error anyways.
For user-space LL scheduler to implement full life-cycle for modules, including calls to mod_free(). This requires that heap metadata is also part of the memory partition mapped to the user-thread. Implement a new sys_user_heap_init() that allocates both the heap buffer and its metadata, into single contiguous allocation, and returns the resulting object. This then allows caller to map both metadata and the heap to a user-space thread. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Use the new sys_user_heap_init() interface to allocate the system user heap for LL scheduler. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Only double-map the LL resources if CONFIG_CACHE_HAS_MIRRORED_MEMORY_REGIONS is set. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
60a5e56 to
105633d
Compare
|
V2 pushed:
|
|
I do not understand why you allocate the |
|
@softwarecki wrote:
You are completely right. I've been today working on upstream ready version of b11d04d , and adding the z_vrfy logic for sof_heap_alloc, and well, this approach doesn't work in the end. I was planning to verify the kernel objects before entering kernel mode, but alas, not working. |
|
If you plan to place |
Series that expands the LL/system-user heap implementation and prepares for use from user-space.