Skip to content

Commit

Permalink
Add CFG_CONCURRENT_SINGLE_INSTANCE_TA
Browse files Browse the repository at this point in the history
Commit 2b07dcb ("core: avoid deadlocks caused by single-instance
TA") introduces a lock that allows only one single instance TA to be
executing at any time. While it does address the risk of deadlock that
can arise when several single instance TAs call each other, it also
puts a serious performance limitation on multi-core platforms, which
could otherwise execute several unrelated single instance TAs
simultaneously.

This commit makes the single instance lock optional. By setting
CFG_CONCURRENT_SINGLE_INSTANCE_TA=y, the lock is disabled and TAs are
allowed to run concurrently. In the future, we may implement a deadlock
detection algorithm; in the meantime, this simple solution should be
enough to cover the current use cases.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (HiKey960)
CC: Zeng Tao <prime.zeng@hisilicon.com>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
  • Loading branch information
jforissier committed Nov 13, 2017
1 parent bd3efa2 commit daeea03
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion core/kernel/tee_ta_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,28 @@

/* This mutex protects the critical section in tee_ta_init_session */
struct mutex tee_ta_mutex = MUTEX_INITIALIZER;
struct tee_ta_ctx_head tee_ctxes = TAILQ_HEAD_INITIALIZER(tee_ctxes);

#ifndef CFG_CONCURRENT_SINGLE_INSTANCE_TA
static struct condvar tee_ta_cv = CONDVAR_INITIALIZER;
static int tee_ta_single_instance_thread = THREAD_ID_INVALID;
static size_t tee_ta_single_instance_count;
struct tee_ta_ctx_head tee_ctxes = TAILQ_HEAD_INITIALIZER(tee_ctxes);
#endif

#ifdef CFG_CONCURRENT_SINGLE_INSTANCE_TA
static void lock_single_instance(void)
{
}

static void unlock_single_instance(void)
{
}

static bool has_single_instance_lock(void)
{
return false;
}
#else
static void lock_single_instance(void)
{
/* Requires tee_ta_mutex to be held */
Expand Down Expand Up @@ -93,6 +110,7 @@ static bool has_single_instance_lock(void)
/* Requires tee_ta_mutex to be held */
return tee_ta_single_instance_thread == thread_get_id();
}
#endif

static bool tee_ta_try_set_busy(struct tee_ta_ctx *ctx)
{
Expand Down

0 comments on commit daeea03

Please sign in to comment.