From a4cc85c129d031d9c887cf59b1baeaef18a43010 Mon Sep 17 00:00:00 2001 From: Subhasish Ghosh Date: Thu, 9 Dec 2021 15:41:37 +0000 Subject: [PATCH] fix(rmmd/sve): enable/disable SVE/FPU for Realms This patch enable/disable SVE/FPU for Realms depending upon it's state in NS. When this feature is enabled, traps to EL3 on SVE/FPU access from Realms are disabled. However, RMM must ensure that the Realm <-> NS SVE/FPU registers are not corrupted by each other and Realms do not leak information to NS. Change-Id: I0a27a055787976507017b72879ba6458f066624e Signed-off-by: Subhasish Ghosh --- services/std_svc/rmmd/rmmd_main.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/services/std_svc/rmmd/rmmd_main.c b/services/std_svc/rmmd/rmmd_main.c index e9004c791..c4ea706d5 100644 --- a/services/std_svc/rmmd/rmmd_main.c +++ b/services/std_svc/rmmd/rmmd_main.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "rmmd_initial_context.h" #include "rmmd_private.h" @@ -111,6 +112,26 @@ static void rmm_el2_context_init(el2_sysregs_t *regs) regs->ctx_regs[CTX_SCTLR_EL2 >> 3] = SCTLR_EL2_RES1; } +/******************************************************************************* + * Enable architecture extensions on first entry to Realm world. + ******************************************************************************/ +static void manage_extensions_realm(cpu_context_t *ctx) +{ +#if ENABLE_SVE_FOR_NS + /* + * Enable SVE and FPU in realm context when it is enabled for NS. + * Realm manager must ensure that the SVE and FPU register + * contexts are properly managed. + */ + sve_enable(ctx); +#else + /* + * Disable SVE and FPU in realm context when it is disabled for NS. + */ + sve_disable(ctx); +#endif /* ENABLE_SVE_FOR_NS */ +} + /******************************************************************************* * Jump to the RMM for the first time. ******************************************************************************/ @@ -124,6 +145,9 @@ static int32_t rmm_init(void) INFO("RMM init start.\n"); ctx->state = RMM_STATE_RESET; + /* Enable architecture extensions */ + manage_extensions_realm(&ctx->cpu_ctx); + /* Initialize RMM EL2 context. */ rmm_el2_context_init(&ctx->cpu_ctx.el2_sysregs_ctx); @@ -281,6 +305,9 @@ static void *rmmd_cpu_on_finish_handler(const void *arg) /* Initialise RMM context with this entry point information */ cm_setup_context(&ctx->cpu_ctx, rmm_ep_info); + /* Enable architecture extensions */ + manage_extensions_realm(&ctx->cpu_ctx); + /* Initialize RMM EL2 context. */ rmm_el2_context_init(&ctx->cpu_ctx.el2_sysregs_ctx);