fix(spmd): avoid restoring ctx during first entry into spmc
In function cm_el2_sysregs_context_restore() the secure context was not
restored when first time entering into SPMC because SCR_EL3.EEL2 was set
just before entering SPMC for first time. With following change, EEL2
bit is set during RESET causing context being restored during first
entry into SPMC.
https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/27170
The ICC_SRE_EL2 register is part of EL2 context and gets initialized
properly in SPMC, So restoring this before SPMC init is wrong.
Because setting of EEL2 was deferred, this issue was hidden and it
popped up after EEL2 was set at RESET.
The ideal solution is what is done in master branch, but considering
this is LTS branch, we need to come up with least invasive change to
avoid having conflicts in future when cherry-picking other security
patches from master.
Signed-off-by: Manish Pandey <manish.pandey2@arm.com>
Change-Id: I368088ece60826fd7a6aa423ba584a89d32fccdc
diff --git a/services/std_svc/spmd/spmd_main.c b/services/std_svc/spmd/spmd_main.c
index 7e6c89d..a7eb893 100644
--- a/services/std_svc/spmd/spmd_main.c
+++ b/services/std_svc/spmd/spmd_main.c
@@ -123,7 +123,10 @@
/* Restore the context assigned above */
#if SPMD_SPM_AT_SEL2
- cm_el2_sysregs_context_restore(SECURE);
+ /* Avoid restoring ctx during SPMC init */
+ if (spmc_ctx->state != SPMC_STATE_ON_PENDING) {
+ cm_el2_sysregs_context_restore(SECURE);
+ }
#else
cm_el1_sysregs_context_restore(SECURE);
#endif