Skip to content

Commit

Permalink
core: initialize guest physical memory early
Browse files Browse the repository at this point in the history
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 <jens.wiklander@linaro.org>
  • Loading branch information
jenswi-linaro committed Sep 13, 2024
1 parent 3a9b8b9 commit 799029c
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 76 deletions.
3 changes: 0 additions & 3 deletions core/arch/arm/kernel/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 2 additions & 10 deletions core/arch/arm/kernel/virtualization.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
{
Expand Down
9 changes: 0 additions & 9 deletions core/include/kernel/virtualization.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions core/include/mm/core_mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
48 changes: 1 addition & 47 deletions core/mm/core_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 >