Skip to content

Commit

Permalink
core: deprecate TA property flags EXEC_DDR and USER_MODE
Browse files Browse the repository at this point in the history
TA property flags TA_FLAG_EXEC_DDR and TA_FLAG_USER_MODE were
not really useful in the OP-TEE and now they are meaningless.

Define the mask of flags a TA may pretend to and assert loaded
TAs do not expect flags set outside of the defined supported bit
flags.

Fix gmon.h against duplicate round macros.

Signed-off-by: Etienne Carriere <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
Acked-by: Jerome Forissier <[email protected]>
  • Loading branch information
etienne-lms authored and jenswi-linaro-adm committed Apr 5, 2018
1 parent 027f050 commit 387b0ee
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 65 deletions.
9 changes: 1 addition & 8 deletions core/arch/arm/kernel/elf_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,7 @@ static TEE_Result load_head(struct elf_load_state *state, size_t head_size)
if (ADD_OVERFLOW(phdr.p_vaddr, phdr.p_memsz, &state->vasize))
return TEE_ERROR_SECURITY;

/*
* Read .ta_head from first segment, make sure the segment is large
* enough. We're only interested in seeing that the
* TA_FLAG_EXEC_DDR flag is set. If that's true we set that flag in
* the TA context to enable mapping the TA. Later when this
* function has returned and the hash has been verified the flags
* field will be updated with eventual other flags.
*/
/* Read .ta_head from first segment if the segment is large enough */
if (ptload0.p_filesz < head_size)
return TEE_ERROR_BAD_FORMAT;
res = alloc_and_copy_to(&p, state, ptload0.p_offset, head_size);
Expand Down
66 changes: 20 additions & 46 deletions core/arch/arm/kernel/user_ta.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,6 @@ static TEE_Result load_elf(struct user_ta_ctx *utc,
goto out;
}

/* Currently all TA must execute from DDR */
if (!(ta_head->flags & TA_FLAG_EXEC_DDR)) {
res = TEE_ERROR_BAD_FORMAT;
goto out;
}
/* Temporary assignment to setup memory mapping */
utc->ctx.flags = TA_FLAG_EXEC_DDR;

/* Ensure proper aligment of stack */
utc->mobj_stack = alloc_ta_mem(ROUNDUP(ta_head->stack_size,
STACK_ALIGNMENT));
Expand Down Expand Up @@ -279,10 +271,6 @@ static TEE_Result ta_load(const TEE_UUID *uuid,
struct tee_ta_ctx **ta_ctx)
{
TEE_Result res;
uint32_t mandatory_flags = TA_FLAG_USER_MODE | TA_FLAG_EXEC_DDR;
uint32_t optional_flags = mandatory_flags | TA_FLAG_SINGLE_INSTANCE |
TA_FLAG_MULTI_SESSION | TA_FLAG_SECURE_DATA_PATH |
TA_FLAG_INSTANCE_KEEP_ALIVE | TA_FLAG_CACHE_MAINTENANCE;
struct user_ta_ctx *utc = NULL;
struct ta_head *ta_head;
struct user_ta_store_handle *ta_handle = NULL;
Expand Down Expand Up @@ -319,11 +307,9 @@ static TEE_Result ta_load(const TEE_UUID *uuid,
goto error_return;
}

/* check input flags bitmask consistency and save flags */
if ((ta_head->flags & optional_flags) != ta_head->flags ||
(ta_head->flags & mandatory_flags) != mandatory_flags) {
EMSG("TA flag issue: flags=%x optional=%x mandatory=%x",
ta_head->flags, optional_flags, mandatory_flags);
if (ta_head->flags & ~TA_FLAGS_MASK) {
EMSG("Invalid TA flag(s) 0x%" PRIx32,
ta_head->flags & ~TA_FLAGS_MASK);
res = TEE_ERROR_BAD_FORMAT;
goto error_return;
}
Expand Down Expand Up @@ -432,9 +418,6 @@ static TEE_Result user_ta_enter(TEE_ErrorOrigin *err,
struct tee_ta_session *s __maybe_unused;
void *param_va[TEE_NUM_PARAMS] = { NULL };

if (!(utc->ctx.flags & TA_FLAG_EXEC_DDR))
panic("TA does not exec in DDR");

/* Map user space memory */
res = tee_mmu_map_param(utc, param, param_va);
if (res != TEE_SUCCESS)
Expand Down Expand Up @@ -539,37 +522,28 @@ static void user_ta_dump_state(struct tee_ta_ctx *ctx)
}
KEEP_PAGER(user_ta_dump_state);

static void release_ta_memory_by_mobj(struct mobj *mobj)
{
void *va;

if (!mobj)
return;

va = mobj_get_va(mobj, 0);
if (!va)
return;

memset(va, 0, mobj->size);
cache_op_inner(DCACHE_AREA_CLEAN, va, mobj->size);
}

static void user_ta_ctx_destroy(struct tee_ta_ctx *ctx)
{
struct user_ta_ctx *utc = to_user_ta_ctx(ctx);

tee_pager_rem_uta_areas(utc);

/*
* Clean all traces of the TA, both RO and RW data.
* No L2 cache maintenance to avoid sync problems
*/
if (ctx->flags & TA_FLAG_EXEC_DDR) {
void *va;

if (utc->mobj_code) {
va = mobj_get_va(utc->mobj_code, 0);
if (va) {
memset(va, 0, utc->mobj_code->size);
cache_op_inner(DCACHE_AREA_CLEAN, va,
utc->mobj_code->size);
}
}

if (utc->mobj_stack) {
va = mobj_get_va(utc->mobj_stack, 0);
if (va) {
memset(va, 0, utc->mobj_stack->size);
cache_op_inner(DCACHE_AREA_CLEAN, va,
utc->mobj_stack->size);
}
}
}
release_ta_memory_by_mobj(utc->mobj_code);
release_ta_memory_by_mobj(utc->mobj_stack);

/*
* Close sessions opened by this TA
Expand Down
7 changes: 1 addition & 6 deletions lib/libutee/arch/arm/gprof/gmon.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#define GMON_H

#include <stdint.h>
#include <util.h>

/* Exported by the TA linker script */
extern uint8_t __text_start[];
Expand Down Expand Up @@ -163,12 +164,6 @@ struct rawarc {
long raw_count;
};

/*
* General rounding functions.
*/
#define ROUNDDOWN(x, y) (((x)/(y))*(y))
#define ROUNDUP(x, y) ((((x)+(y)-1)/(y))*(y))

/*
* The profiling data structures are housed in this structure.
*/
Expand Down
12 changes: 8 additions & 4 deletions lib/libutee/include/user_ta_header.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2014, STMicroelectronics International N.V.
* All rights reserved.
* Copyright (c) 2018, Linaro Limited.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -30,10 +30,8 @@
#define USER_TA_HEADER_H

#include <tee_api_types.h>
#include <util.h>


#define TA_FLAG_USER_MODE (1 << 0)
#define TA_FLAG_EXEC_DDR (1 << 1)
#define TA_FLAG_SINGLE_INSTANCE (1 << 2)
#define TA_FLAG_MULTI_SESSION (1 << 3)
#define TA_FLAG_INSTANCE_KEEP_ALIVE (1 << 4) /* remains after last close */
Expand All @@ -46,6 +44,12 @@
*/
#define TA_FLAG_CONCURRENT (1 << 8)

#define TA_FLAGS_MASK GENMASK_32(8, 2)

/* Deprecated macros that will be removed in the 3.2 release */
#define TA_FLAG_USER_MODE 0
#define TA_FLAG_EXEC_DDR 0

union ta_head_func_ptr {
uint64_t ptr64;
struct ta_head_func_ptr32 {
Expand Down
2 changes: 1 addition & 1 deletion ta/arch/arm/user_ta_header.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const struct ta_head ta_head __section(".ta_head") = {
* must be enlarged
*/
.stack_size = TA_STACK_SIZE + TA_FRAMEWORK_STACK_SIZE,
.flags = TA_FLAG_USER_MODE | TA_FLAGS,
.flags = TA_FLAGS,
#ifdef __ILP32__
/*
* This workaround is neded on 32-bit because it seems we can't
Expand Down

0 comments on commit 387b0ee

Please sign in to comment.