From 8f60d99f44f3f75108f7cf707e8d1c8f6ef33be0 Mon Sep 17 00:00:00 2001 From: Rakshit Goyal Date: Thu, 6 Feb 2025 11:58:53 +0000 Subject: [PATCH] fix(spmd): prevent SIMD context loss When SPMD_SPM_AT_SEL2 is enabled, saving and restoring the SIMD context is not needed because the SPMC handles it. The function spmd_secure_interrupt_handler incorrectly restores the SWD SIMD context before entering the SPMC without saving the NWD SIMD context, leading to its loss. Furthermore, the SWD SIMD context is saved after returning from the SPMC which is unnecessary. This commit prevents the restoration of the SWD SIMD context before SPMC entry and the saving of the SWD SIMD context after returning from the SPMC when SPMD_SPM_AT_SEL2 is enabled. This ensures the preservation of the NWD SIMD context. Change-Id: I16a3e698e61da7019b3a670475e542d1690a5dd9 Signed-off-by: Rakshit Goyal --- services/std_svc/spmd/spmd_main.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/services/std_svc/spmd/spmd_main.c b/services/std_svc/spmd/spmd_main.c index 4d82991a2..94634f267 100644 --- a/services/std_svc/spmd/spmd_main.c +++ b/services/std_svc/spmd/spmd_main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2024, Arm Limited and Contributors. All rights reserved. + * Copyright (c) 2020-2025, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -222,6 +222,7 @@ static uint64_t spmd_secure_interrupt_handler(uint32_t id, * in this scenario where execution was trapped to EL3 due to FIQ. */ simd_ctx_save(NON_SECURE, false); + simd_ctx_restore(SECURE); #endif #endif @@ -238,14 +239,8 @@ static uint64_t spmd_secure_interrupt_handler(uint32_t id, /* Mark current core as handling a secure interrupt. */ ctx->secure_interrupt_ongoing = true; -#if CTX_INCLUDE_FPREGS || CTX_INCLUDE_SVE_REGS - simd_ctx_restore(SECURE); -#endif rc = spmd_spm_core_sync_entry(ctx); -#if CTX_INCLUDE_FPREGS || CTX_INCLUDE_SVE_REGS - simd_ctx_save(SECURE, false); -#endif if (rc != 0ULL) { ERROR("%s failed (%" PRId64 ") on CPU%u\n", __func__, rc, plat_my_core_pos()); } @@ -258,6 +253,7 @@ static uint64_t spmd_secure_interrupt_handler(uint32_t id, cm_el1_sysregs_context_restore(NON_SECURE); #if CTX_INCLUDE_FPREGS || CTX_INCLUDE_SVE_REGS + simd_ctx_save(SECURE, false); simd_ctx_restore(NON_SECURE); #endif #endif