From daeea0369d17a7473953eecd6b5af4735ec12fcb Mon Sep 17 00:00:00 2001 From: Jerome Forissier Date: Fri, 3 Nov 2017 17:27:05 +0100 Subject: [PATCH] Add CFG_CONCURRENT_SINGLE_INSTANCE_TA Commit 2b07dcb97c5e ("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 Tested-by: Jerome Forissier (HiKey960) CC: Zeng Tao Acked-by: Jens Wiklander Reviewed-by: Etienne Carriere --- core/kernel/tee_ta_manager.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/core/kernel/tee_ta_manager.c b/core/kernel/tee_ta_manager.c index 1ac689da7f3..653047174ab 100644 --- a/core/kernel/tee_ta_manager.c +++ b/core/kernel/tee_ta_manager.c @@ -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 */ @@ -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) {