Skip to content

Commit

Permalink
core: add pgt_clear_ctx_range()
Browse files Browse the repository at this point in the history
Adds pgt_clear_ctx_range() which clears the corresponding entries in
the active or cached translation tables of user mode context.

Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
jenswi-linaro committed Feb 24, 2021
1 parent 65fb909 commit 74cb1bd
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
4 changes: 3 additions & 1 deletion core/arch/arm/include/mm/pgt_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ struct ts_ctx;

struct pgt {
void *tbl;
#if defined(CFG_PAGED_USER_TA)
vaddr_t vabase;
#if defined(CFG_PAGED_USER_TA)
struct ts_ctx *ctx;
size_t num_used_entries;
#endif
Expand Down Expand Up @@ -61,6 +61,8 @@ void pgt_alloc(struct pgt_cache *pgt_cache, struct ts_ctx *owning_ctx,
vaddr_t begin, vaddr_t last);
void pgt_free(struct pgt_cache *pgt_cache, bool save_ctx);

void pgt_clear_ctx_range(struct pgt_cache *pgt_cache, struct ts_ctx *ctx,
vaddr_t begin, vaddr_t end);
#ifdef CFG_PAGED_USER_TA
void pgt_flush_ctx_range(struct pgt_cache *pgt_cache, struct ts_ctx *ctx,
vaddr_t begin, vaddr_t last);
Expand Down
54 changes: 52 additions & 2 deletions core/arch/arm/mm/pgt_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,63 @@ static void pgt_free_unlocked(struct pgt_cache *pgt_cache,
}
}

static struct pgt *pop_from_some_list(vaddr_t vabase __unused,
static struct pgt *pop_from_some_list(vaddr_t vabase,
struct ts_ctx *ctx __unused)
{
return pop_from_free_list();
struct pgt *p = pop_from_free_list();

if (p)
p->vabase = vabase;

return p;
}
#endif /*!CFG_PAGED_USER_TA*/

static void clear_ctx_range_from_list(struct pgt_cache *pgt_cache,
void *ctx __maybe_unused,
vaddr_t begin, vaddr_t end)
{
struct pgt *p = NULL;
#ifdef CFG_WITH_LPAE
uint64_t *tbl = NULL;
#else
uint32_t *tbl = NULL;
#endif
unsigned int idx = 0;
unsigned int n = 0;

SLIST_FOREACH(p, pgt_cache, link) {
vaddr_t b = MAX(p->vabase, begin);
vaddr_t e = MIN(p->vabase + CORE_MMU_PGDIR_SIZE, end);

#ifdef CFG_PAGED_USER_TA
if (p->ctx != ctx)
continue;
#endif
if (b >= e)
continue;

tbl = p->tbl;
idx = (b - p->vabase) / SMALL_PAGE_SIZE;
n = (e - b) / SMALL_PAGE_SIZE;
memset(tbl + idx, 0, n * sizeof(*tbl));
}
}

void pgt_clear_ctx_range(struct pgt_cache *pgt_cache, struct ts_ctx *ctx,
vaddr_t begin, vaddr_t end)
{
mutex_lock(&pgt_mu);

if (pgt_cache)
clear_ctx_range_from_list(pgt_cache, ctx, begin, end);
#ifdef CFG_PAGED_USER_TA
clear_ctx_range_from_list(&pgt_cache_list, ctx, begin, end);
#endif

mutex_unlock(&pgt_mu);
}

static bool pgt_alloc_unlocked(struct pgt_cache *pgt_cache, struct ts_ctx *ctx,
vaddr_t begin, vaddr_t last)
{
Expand Down

0 comments on commit 74cb1bd

Please sign in to comment.