From 799029c7c4cf03336e543f59939fb3baa8b31eed Mon Sep 17 00:00:00 2001 From: Jens Wiklander Date: Fri, 13 Sep 2024 11:48:34 +0200 Subject: [PATCH] core: initialize guest physical memory early Initialize guest physical memory in virt_guest_created() before the first entry into the guest from normal world. This replaces the call to core_mmu_init_phys_mem() in init_tee_runtime(). Remove unused code in core_mmu_init_phys_mem() and the now unused functions core_mmu_get_ta_range() and virt_get_ta_ram(). Signed-off-by: Jens Wiklander --- core/arch/arm/kernel/boot.c | 3 -- core/arch/arm/kernel/virtualization.c | 12 ++----- core/include/kernel/virtualization.h | 9 ----- core/include/mm/core_mmu.h | 7 ---- core/mm/core_mmu.c | 48 +-------------------------- 5 files changed, 3 insertions(+), 76 deletions(-) diff --git a/core/arch/arm/kernel/boot.c b/core/arch/arm/kernel/boot.c index 76fd312c185..2f9185da039 100644 --- a/core/arch/arm/kernel/boot.c +++ b/core/arch/arm/kernel/boot.c @@ -861,9 +861,6 @@ static void update_external_dt(void) void init_tee_runtime(void) { - if (IS_ENABLED(CFG_NS_VIRTUALIZATION)) - core_mmu_init_phys_mem(); - /* * With virtualization we call this function when creating the * OP-TEE partition instead. diff --git a/core/arch/arm/kernel/virtualization.c b/core/arch/arm/kernel/virtualization.c index 456e6c040dc..3d0cab0b71a 100644 --- a/core/arch/arm/kernel/virtualization.c +++ b/core/arch/arm/kernel/virtualization.c @@ -322,6 +322,8 @@ TEE_Result virt_guest_created(uint16_t guest_id) set_current_prtn(prtn); malloc_add_pool(__heap1_start, __heap1_end - __heap1_start); + phys_mem_init(0, 0, tee_mm_get_smem(prtn->ta_ram), + tee_mm_get_bytes(prtn->ta_ram)); /* Initialize threads */ thread_init_threads(); /* Do the preinitcalls */ @@ -559,16 +561,6 @@ struct memory_map *virt_get_memory_map(void) return &prtn->mem_map; } -void virt_get_ta_ram(vaddr_t *start, vaddr_t *end) -{ - struct guest_partition *prtn = get_current_prtn(); - - *start = (vaddr_t)phys_to_virt(tee_mm_get_smem(prtn->ta_ram), - MEM_AREA_SEC_RAM_OVERALL, - tee_mm_get_bytes(prtn->ta_ram)); - *end = *start + tee_mm_get_bytes(prtn->ta_ram); -} - #ifdef CFG_CORE_SEL1_SPMC static int find_cookie(struct guest_partition *prtn, uint64_t cookie) { diff --git a/core/include/kernel/virtualization.h b/core/include/kernel/virtualization.h index 62b2c452398..865899bb21d 100644 --- a/core/include/kernel/virtualization.h +++ b/core/include/kernel/virtualization.h @@ -90,13 +90,6 @@ void virt_init_memory(struct memory_map *mem_map, paddr_t secmem0_base, */ struct memory_map *virt_get_memory_map(void); -/** - * virt_get_ta_ram() - get TA RAM mapping for current VM - * @start: beginning of TA RAM returned here - * @end: end of TA RAM returned here - */ -void virt_get_ta_ram(vaddr_t *start, vaddr_t *end); - /** * virt_get_current_guest_id() - return current guest ID * @@ -201,8 +194,6 @@ static inline TEE_Result virt_set_guest(uint16_t guest_id __unused) static inline void virt_unset_guest(void) { } static inline void virt_on_stdcall(void) { } static inline struct memory_map *virt_get_memory_map(void) { return NULL; } -static inline void -virt_get_ta_ram(vaddr_t *start __unused, vaddr_t *end __unused) { } static inline void virt_init_memory(struct memory_map *mem_map __unused, paddr_t secmem0_base __unused, paddr_size_t secmem0_size __unused, diff --git a/core/include/mm/core_mmu.h b/core/include/mm/core_mmu.h index 60aea531139..cdbc0fedefb 100644 --- a/core/include/mm/core_mmu.h +++ b/core/include/mm/core_mmu.h @@ -687,13 +687,6 @@ void core_mmu_set_secure_memory(paddr_t base, size_t size); */ void core_mmu_get_secure_memory(paddr_t *base, paddr_size_t *size); -/* - * core_mmu_get_ta_range() - get physical memory range reserved for TAs - * @base: [out] range base address ref or NULL - * @size: [out] range size ref or NULL - */ -void core_mmu_get_ta_range(paddr_t *base, size_t *size); - #endif /*__ASSEMBLER__*/ #endif /* __MM_CORE_MMU_H */ diff --git a/core/mm/core_mmu.c b/core/mm/core_mmu.c index 699d9625928..6787a8ac07c 100644 --- a/core/mm/core_mmu.c +++ b/core/mm/core_mmu.c @@ -193,40 +193,6 @@ void core_mmu_set_secure_memory(paddr_t base, size_t size) secure_only[0].size = size; } -void core_mmu_get_ta_range(paddr_t *base, size_t *size) -{ - paddr_t b = 0; - size_t s = 0; - - static_assert(!(TEE_RAM_VA_SIZE % SMALL_PAGE_SIZE)); -#ifdef TA_RAM_START - b = TA_RAM_START; - s = TA_RAM_SIZE; -#else - static_assert(ARRAY_SIZE(secure_only) <= 2); - if (ARRAY_SIZE(secure_only) == 1) { - vaddr_t load_offs = 0; - - assert(core_mmu_tee_load_pa >= secure_only[0].paddr); - load_offs = core_mmu_tee_load_pa - secure_only[0].paddr; - - assert(secure_only[0].size > - load_offs + TEE_RAM_VA_SIZE + TEE_SDP_TEST_MEM_SIZE); - b = secure_only[0].paddr + load_offs + TEE_RAM_VA_SIZE; - s = secure_only[0].size - load_offs - TEE_RAM_VA_SIZE - - TEE_SDP_TEST_MEM_SIZE; - } else { - assert(secure_only[1].size > TEE_SDP_TEST_MEM_SIZE); - b = secure_only[1].paddr; - s = secure_only[1].size - TEE_SDP_TEST_MEM_SIZE; - } -#endif - if (base) - *base = b; - if (size) - *size = s; -} - static struct memory_map *get_memory_map(void) { if (IS_ENABLED(CFG_NS_VIRTUALIZATION)) { @@ -2712,19 +2678,7 @@ void core_mmu_init_phys_mem(void) paddr_t ps = 0; size_t size = 0; - /* - * Get virtual addr/size of RAM where TA are loaded/executedNSec - * shared mem allocated from teecore. - */ - if (IS_ENABLED(CFG_NS_VIRTUALIZATION)) { - vaddr_t s = 0; - vaddr_t e = 0; - - virt_get_ta_ram(&s, &e); - ps = virt_to_phys((void *)s); - size = e - s; - phys_mem_init(0, 0, ps, size); - } else { + if (!IS_ENABLED(CFG_NS_VIRTUALIZATION)) { #ifdef CFG_WITH_PAGER /* * The pager uses all core memory so there's no need to add