Skip to content

Commit

Permalink
core: invalidate common RAM regions b/w TA and TEE
Browse files Browse the repository at this point in the history
Invalidate overlapping RAM regions between TA and TEE when physical
relocation is enabled.

Signed-off-by: Seonghyun Park <seonghp@amazon.com>
  • Loading branch information
seonghp committed Feb 26, 2024
1 parent 8cf0576 commit 24b1efd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
6 changes: 5 additions & 1 deletion core/include/mm/tee_mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ struct _tee_mm_entry_t {
struct _tee_mm_pool_t *pool;
struct _tee_mm_entry_t *next;
uint32_t offset; /* offset in pages/sections */
uint32_t size; /* size in pages/sections */
uint32_t size:31; /* size in pages/sections */
uint32_t valid:1;
};
typedef struct _tee_mm_entry_t tee_mm_entry_t;

Expand Down Expand Up @@ -87,6 +88,9 @@ tee_mm_entry_t *tee_mm_alloc(tee_mm_pool_t *pool, size_t size);
/* Allocate supplied memory range if it's free */
tee_mm_entry_t *tee_mm_alloc2(tee_mm_pool_t *pool, paddr_t base, size_t size);

/* Invalidate supplied memory range */
void tee_mm_invalidate(tee_mm_pool_t *pool, paddr_t base, size_t size);

/*
* Frees the entry in the paged virtual address space pointed to by the
* input parameter p
Expand Down
11 changes: 5 additions & 6 deletions core/mm/core_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2594,10 +2594,9 @@ void core_mmu_init_ta_ram(void)
tee_mm_init(&tee_mm_sec_ddr, ps, size, CORE_MMU_USER_CODE_SHIFT,
TEE_MM_POOL_NO_FLAGS);

/*
* FIXME(correctness): this entry should not be counted as valid
* memory entry by memory usage monitor.
*/
unused = tee_mm_alloc2(&tee_mm_sec_ddr, core_mmu_tee_load_pa,
CORE_MMU_PGDIR_SIZE);
if (IS_ENABLED(CFG_CORE_PHYS_RELOCATABLE) &&
!IS_ENABLED(CFG_CORE_SEL2_SPMC)) {
tee_mm_invalidate(&tee_mm_sec_ddr, core_mmu_tee_load_pa,
TEE_RAM_VA_SIZE);
}
}
18 changes: 16 additions & 2 deletions core/mm/tee_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ static size_t tee_mm_stats_allocated(tee_mm_pool_t *pool)

entry = pool->entry;
while (entry) {
sz += entry->size;
if (entry->valid)
sz += entry->size;

entry = entry->next;
}

Expand Down Expand Up @@ -246,7 +248,8 @@ static inline bool fit_in_gap(tee_mm_pool_t *pool, tee_mm_entry_t *e,
return true;
}

tee_mm_entry_t *tee_mm_alloc2(tee_mm_pool_t *pool, paddr_t base, size_t size)
static tee_mm_entry_t *tee_mm_claim(tee_mm_pool_t *pool, paddr_t base,
size_t size, bool valid)
{
tee_mm_entry_t *entry;
paddr_t offslo;
Expand Down Expand Up @@ -291,6 +294,7 @@ tee_mm_entry_t *tee_mm_alloc2(tee_mm_pool_t *pool, paddr_t base, size_t size)
mm->offset = offslo;
mm->size = offshi - offslo;
mm->pool = pool;
mm->valid = valid;

update_max_allocated(pool);
cpu_spin_unlock_xrestore(&pool->lock, exceptions);
Expand All @@ -301,6 +305,16 @@ tee_mm_entry_t *tee_mm_alloc2(tee_mm_pool_t *pool, paddr_t base, size_t size)
return NULL;
}

tee_mm_entry_t *tee_mm_alloc2(tee_mm_pool_t *pool, paddr_t base, size_t size)
{
return tee_mm_claim(pool, base, size, true);
}

void tee_mm_invalidate(tee_mm_pool_t *pool, paddr_t base, size_t size)
{
(void)tee_mm_claim(pool, base, size, false);
}

void tee_mm_free(tee_mm_entry_t *p)
{
tee_mm_entry_t *entry;
Expand Down

0 comments on commit 24b1efd

Please sign in to comment.