-
Notifications
You must be signed in to change notification settings - Fork 349
Move virtual region creation from Zephyr to SOF, add virtual memory regions protection #10124
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
Changes from all commits
e738f1c
81837be
9578375
6bd7a05
6cdf069
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 |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| #include <rtos/spinlock.h> | ||
| #include <sof/lib/cpu-clk-manager.h> | ||
| #include <sof/lib_manager.h> | ||
| #include <sof/lib/regions_mm.h> | ||
| #include <sof/llext_manager.h> | ||
| #include <sof/audio/module_adapter/module/generic.h> | ||
| #include <sof/audio/module_adapter/module/modules.h> | ||
|
|
@@ -35,6 +36,7 @@ | |
| #include <rimage/sof/user/manifest.h> | ||
| #include <module/module/api_ver.h> | ||
|
|
||
| #include <adsp_memory_regions.h> | ||
| #include <errno.h> | ||
| #include <stdbool.h> | ||
| #include <stddef.h> | ||
|
|
@@ -55,13 +57,13 @@ static int llext_manager_update_flags(void __sparse_cache *vma, size_t size, uin | |
| ALIGN_UP(pre_pad_size + size, PAGE_SZ), flags); | ||
| } | ||
|
|
||
| static int llext_manager_align_map(void __sparse_cache *vma, size_t size, uint32_t flags) | ||
| static int llext_manager_align_map(const struct sys_mm_drv_region *virtual_region, | ||
| void __sparse_cache *vma, size_t size, uint32_t flags) | ||
| { | ||
| size_t pre_pad_size = (uintptr_t)vma & (PAGE_SZ - 1); | ||
| void *aligned_vma = (__sparse_force uint8_t *)vma - pre_pad_size; | ||
|
|
||
| return sys_mm_drv_map_region(aligned_vma, POINTER_TO_UINT(NULL), | ||
| ALIGN_UP(pre_pad_size + size, PAGE_SZ), flags); | ||
| return sys_mm_drv_map_region_safe(virtual_region, aligned_vma, POINTER_TO_UINT(NULL), | ||
| ALIGN_UP(pre_pad_size + size, PAGE_SZ), flags); | ||
| } | ||
|
|
||
| static int llext_manager_align_unmap(void __sparse_cache *vma, size_t size) | ||
|
|
@@ -91,15 +93,21 @@ static void llext_manager_detached_update_flags(void __sparse_cache *vma, | |
| * sections that belong to the specified 'region' and are contained in the | ||
| * memory range, then remap the same area according to the 'flags' parameter. | ||
| */ | ||
| static int llext_manager_load_data_from_storage(const struct llext_loader *ldr, | ||
| static int llext_manager_load_data_from_storage(const struct sys_mm_drv_region *virtual_region, | ||
| const struct llext_loader *ldr, | ||
| const struct llext *ext, | ||
| enum llext_mem region, | ||
| void __sparse_cache *vma, | ||
| size_t size, uint32_t flags) | ||
| { | ||
| unsigned int i; | ||
| const void *region_addr; | ||
| int ret = llext_manager_align_map(vma, size, SYS_MM_MEM_PERM_RW); | ||
|
|
||
| /* check if there region to be mapped exists */ | ||
| if (size == 0) | ||
| return 0; | ||
|
|
||
| int ret = llext_manager_align_map(virtual_region, vma, size, SYS_MM_MEM_PERM_RW); | ||
|
|
||
| if (ret < 0) { | ||
| tr_err(&lib_manager_tr, "cannot map %u of %p", size, (__sparse_force void *)vma); | ||
|
|
@@ -238,14 +246,25 @@ static int llext_manager_load_module(struct lib_manager_module *mctx) | |
| const struct llext_loader *ldr = &mctx->ebl->loader; | ||
| const struct llext *ext = mctx->llext; | ||
|
|
||
| /* find dedicated virtual memory zone */ | ||
| const struct sys_mm_drv_region *virtual_memory_regions = sys_mm_drv_query_memory_regions(); | ||
| const struct sys_mm_drv_region *virtual_region; | ||
|
|
||
| SYS_MM_DRV_MEMORY_REGION_FOREACH(virtual_memory_regions, virtual_region) { | ||
| if (virtual_region->attr == VIRTUAL_REGION_LLEXT_LIBRARIES_ATTR) | ||
| break; | ||
| } | ||
| if (!virtual_region || !virtual_region->size) | ||
| return -EFAULT; | ||
|
|
||
| /* Copy Code */ | ||
| ret = llext_manager_load_data_from_storage(ldr, ext, LLEXT_MEM_TEXT, | ||
| ret = llext_manager_load_data_from_storage(virtual_region, ldr, ext, LLEXT_MEM_TEXT, | ||
| va_base_text, text_size, SYS_MM_MEM_PERM_EXEC); | ||
| if (ret < 0) | ||
| return ret; | ||
|
|
||
| /* Copy read-only data */ | ||
| ret = llext_manager_load_data_from_storage(ldr, ext, LLEXT_MEM_RODATA, | ||
| ret = llext_manager_load_data_from_storage(virtual_region, ldr, ext, LLEXT_MEM_RODATA, | ||
| va_base_rodata, rodata_size, 0); | ||
| if (ret < 0) | ||
| goto e_text; | ||
|
|
@@ -256,7 +275,7 @@ static int llext_manager_load_module(struct lib_manager_module *mctx) | |
| * spans over the BSS area as well, so the mapping will cover | ||
| * both, but only LLEXT_MEM_DATA sections will be copied. | ||
| */ | ||
| ret = llext_manager_load_data_from_storage(ldr, ext, LLEXT_MEM_DATA, | ||
| ret = llext_manager_load_data_from_storage(virtual_region, ldr, ext, LLEXT_MEM_DATA, | ||
| va_base_data, data_size, SYS_MM_MEM_PERM_RW); | ||
| if (ret < 0) | ||
| goto e_rodata; | ||
|
|
@@ -806,3 +825,17 @@ bool comp_is_llext(struct comp_dev *comp) | |
|
|
||
| return mod && module_is_llext(mod); | ||
| } | ||
|
|
||
| static int llext_memory_region_init(void) | ||
| { | ||
| int ret; | ||
|
|
||
| /* add a region for loadable libraries */ | ||
| ret = adsp_add_virtual_memory_region(CONFIG_LIBRARY_BASE_ADDRESS, | ||
| CONFIG_LIBRARY_REGION_SIZE, | ||
| VIRTUAL_REGION_LLEXT_LIBRARIES_ATTR); | ||
|
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.
|
||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| SYS_INIT(llext_memory_region_init, POST_KERNEL, 1); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,7 @@ manifest: | |
|
|
||
|
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. This could have the usual commit style for west.yml updates. |
||
| - name: zephyr | ||
| repo-path: zephyr | ||
| revision: c99605126cd9cce5684ddd9ad56aed5292004867 | ||
| revision: 8843fd9fe1800164fbb5221d95d1eba7d0699458 | ||
|
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. isn't this breaking bisection? If so, it should be merged with the changes that switch SOF over to the new API |
||
| remote: zephyrproject | ||
|
|
||
| # Import some projects listed in zephyr/west.yml@revision | ||
|
|
||
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.
I think the west update needs to come before this, or bisect is broken.
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.
so it does...

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.
@kv2019i I think it's the opposite - moving to the new Zephyr option without updating SOF to it seems to break bisection to me #10124 (comment)