-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add dynamic vaspace #7285
Merged
Merged
Add dynamic vaspace #7285
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6029b5c
core: mmu: fix dynamic VA region dummy mapping
jenswi-linaro b078938
core: add nex_dyn_vaspace and tee_dyn_vaspace areas
jenswi-linaro 2a68514
Use malloc flags MAF_* in tee_mm.h
jenswi-linaro d3f9539
core: tee_mm.c: use malloc_flags() and free_flags()
jenswi-linaro 772b17c
core: add tee_mm_alloc_flags()
jenswi-linaro e45633a
core: mm: add phys_mem_alloc_flags()
jenswi-linaro 8cb7ab1
core: mm: add virt_page_alloc()
jenswi-linaro 832733f
core: arm: boot: call page_alloc_init()
jenswi-linaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause */ | ||
/* | ||
* Copyright (c) 2024, Linaro Limited | ||
*/ | ||
|
||
#ifndef __MM_PAGE_ALLOC_H | ||
#define __MM_PAGE_ALLOC_H | ||
|
||
#include <malloc_flags.h> | ||
#include <types_ext.h> | ||
#include <util.h> | ||
|
||
void nex_page_alloc_init(void); | ||
void page_alloc_init(void); | ||
|
||
vaddr_t virt_page_alloc(size_t count, uint32_t flags); | ||
|
||
#endif /*__MM_PAGE_ALLOC_H*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
/* | ||
* Copyright (c) 2024, Linaro Limited | ||
*/ | ||
|
||
#include <kernel/boot.h> | ||
#include <kernel/panic.h> | ||
#include <malloc.h> | ||
#include <mm/core_mmu.h> | ||
#include <mm/page_alloc.h> | ||
#include <mm/phys_mem.h> | ||
#include <mm/tee_mm.h> | ||
#include <string.h> | ||
#include <types_ext.h> | ||
|
||
static tee_mm_pool_t core_virt_nex_pool __nex_bss; | ||
static tee_mm_pool_t core_virt_tee_pool; | ||
|
||
static void init_virt_pool(tee_mm_pool_t *pool, uint32_t flags, | ||
enum teecore_memtypes memtype) | ||
{ | ||
vaddr_t start = 0; | ||
vaddr_t end = 0; | ||
|
||
core_mmu_get_mem_by_type(memtype, &start, &end); | ||
if (!start || !end) | ||
panic(); | ||
|
||
if (!tee_mm_init(pool, start, end - start, SMALL_PAGE_SHIFT, flags)) | ||
panic(); | ||
} | ||
|
||
void nex_page_alloc_init(void) | ||
{ | ||
init_virt_pool(&core_virt_nex_pool, TEE_MM_POOL_NEX_MALLOC, | ||
MEM_AREA_NEX_DYN_VASPACE); | ||
} | ||
|
||
void page_alloc_init(void) | ||
{ | ||
init_virt_pool(&core_virt_tee_pool, TEE_MM_POOL_NO_FLAGS, | ||
MEM_AREA_TEE_DYN_VASPACE); | ||
} | ||
|
||
vaddr_t virt_page_alloc(size_t count, uint32_t flags) | ||
{ | ||
enum teecore_memtypes memtype = 0; | ||
TEE_Result res = TEE_SUCCESS; | ||
tee_mm_pool_t *pool = NULL; | ||
tee_mm_entry_t *mmv = NULL; | ||
tee_mm_entry_t *mmp = NULL; | ||
size_t vcount = count; | ||
size_t pcount = count; | ||
vaddr_t va = 0; | ||
paddr_t pa = 0; | ||
|
||
if (IS_ENABLED(CFG_NS_VIRTUALIZATION) && (flags & MAF_NEX)) { | ||
pool = &core_virt_nex_pool; | ||
memtype = MEM_AREA_NEX_DYN_VASPACE; | ||
} else { | ||
pool = &core_virt_tee_pool; | ||
memtype = MEM_AREA_TEE_DYN_VASPACE; | ||
} | ||
|
||
if (flags & MAF_GUARD_HEAD) | ||
vcount++; | ||
if (flags & MAF_GUARD_TAIL) | ||
vcount++; | ||
|
||
/* We're allocating one extra page to use as unmapped guard */ | ||
mmv = tee_mm_alloc_flags(pool, vcount * SMALL_PAGE_SIZE, flags); | ||
if (!mmv) | ||
return 0; | ||
va = tee_mm_get_smem(mmv); | ||
if (flags & MAF_GUARD_HEAD) | ||
va += SMALL_PAGE_SIZE; | ||
|
||
mmp = phys_mem_alloc_flags(pcount * SMALL_PAGE_SIZE, flags); | ||
if (!mmp) | ||
goto err_free_mmv; | ||
pa = tee_mm_get_smem(mmp); | ||
assert(pa); | ||
|
||
res = core_mmu_map_contiguous_pages(va, pa, pcount, memtype); | ||
if (res) | ||
goto err; | ||
|
||
if (flags & MAF_ZERO_INIT) | ||
memset((void *)va, 0, pcount * SMALL_PAGE_SIZE); | ||
|
||
return va; | ||
err: | ||
tee_mm_free(mmp); | ||
err_free_mmv: | ||
tee_mm_free(mmv); | ||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should there be some kind of warning? Maybe a
DMSG()
.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.
No, this is normal. The alternative is to make sure that
struct tee_mmap_region
without an assigned physical address never has theattr
field set. I didn't think it was worth the effort to test for that in the other place(s).