-
Notifications
You must be signed in to change notification settings - Fork 357
schedule: zephyr_ll_user: improve heap init and make it usable from user-space #10807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9681d96
a363950
c1ccb87
214fe97
5985e24
a18b5ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,9 +99,26 @@ void rfree(void *ptr); | |
| */ | ||
| void l3_heap_save(void); | ||
|
|
||
| void *z_impl_sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes, | ||
| size_t alignment); | ||
|
|
||
| void z_impl_sof_heap_free(struct k_heap *heap, void *addr); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm, just occurred to me - I think these declarations are already present in that zephyr/syscalls/alloc.h inccluded below? So maybe they're only needed here under the |
||
|
|
||
| /* | ||
| * This is ugly to define the signatures twice, but this | ||
| * is required to support userspace builds that do not export alloc. | ||
| */ | ||
| #ifdef CONFIG_SOF_USERSPACE_INTERFACE_ALLOC | ||
| __syscall void *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes, | ||
| size_t alignment); | ||
| __syscall void sof_heap_free(struct k_heap *heap, void *addr); | ||
| #include <zephyr/syscalls/alloc.h> | ||
| #else | ||
| void *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes, | ||
| size_t alignment); | ||
| void sof_heap_free(struct k_heap *heap, void *addr); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in other such cases we did |
||
| #endif | ||
|
|
||
| #if CONFIG_SOF_FULL_ZEPHYR_APPLICATION | ||
| struct k_heap *sof_sys_heap_get(void); | ||
| #else | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // | ||
| // Copyright(c) 2026 Intel Corporation. | ||
|
|
||
| #include <rtos/alloc.h> | ||
| #include <sof/schedule/ll_schedule_domain.h> | ||
| #include <zephyr/kernel.h> | ||
| #include <zephyr/internal/syscall_handler.h> | ||
|
|
||
| static inline void *z_vrfy_sof_heap_alloc(struct k_heap *heap, uint32_t flags, | ||
| size_t bytes, size_t alignment) | ||
| { | ||
| /* reject flags that bypass heap isolation */ | ||
| K_OOPS(flags & (SOF_MEM_FLAG_LARGE_BUFFER | SOF_MEM_FLAG_USER_SHARED_BUFFER)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hm, we also have |
||
|
|
||
| /* user-space use of sof_heap_alloc() limited to this single heap */ | ||
| K_OOPS(!zephyr_ll_user_heap_verify(heap)); | ||
|
|
||
| return z_impl_sof_heap_alloc(heap, flags, bytes, alignment); | ||
| } | ||
| #include <zephyr/syscalls/sof_heap_alloc_mrsh.c> | ||
|
|
||
| static inline void z_vrfy_sof_heap_free(struct k_heap *heap, void *addr) | ||
| { | ||
| /* user-space use of sof_heap_alloc() limited to this single heap */ | ||
| K_OOPS(!zephyr_ll_user_heap_verify(heap)); | ||
|
|
||
| if (addr) { | ||
| uintptr_t start = (uintptr_t)heap->heap.init_mem; | ||
| uintptr_t addr_uc = (uintptr_t)sys_cache_uncached_ptr_get(addr); | ||
| K_OOPS(addr_uc < start || addr_uc >= start + heap->heap.init_bytes); | ||
| K_OOPS(K_SYSCALL_MEMORY_WRITE(addr, 1)); | ||
| } | ||
| z_impl_sof_heap_free(heap, addr); | ||
| } | ||
| #include <zephyr/syscalls/sof_heap_free_mrsh.c> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could this be
? Advantage -
const,.rodata, potential disadvantage - you'd need to make sure not to try to use it before the heap is initialised. But that should be easy enough to check too, e.g. by checking the.heap.init_mempointer. Can be a follow-up