commit 497437a527c37f41d8122cf48d96271c4510ad36 Author: Bohdan Hunko Date: Mon Oct 30 22:25:10 2023 +0200 SPM: Fix scheduling issue Signed-off-by: Bohdan Hunko diff --git a/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c b/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c index 51e4dcb01..3aaab9544 100644 --- a/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c +++ b/secure_fw/spm/cmsis_psa/tfm_core_svcalls_ipc.c @@ -161,6 +161,23 @@ uint32_t tfm_core_svc_handler(uint32_t *msp, uint32_t exc_return, tfm_core_panic(); } + /* Update Stack Pointer in partition context as it may have changed. + * This way if interrupt, that asserts partition signal, arrives during SVC + * call processing it will have correct context and will be able to + * correctly set r0 in context in tfm_arch_set_context_ret_code + * during thrd_next(). + * + * This solution should be revised in TFM-2242. + */ + if (svc_number == TFM_SVC_PSA_WAIT) { + struct partition_t *partition = GET_CURRENT_COMPONENT(); + /* Even tho tfm_additional_context_t is not present on the stack it + * needs to be accounted for to have uniform structure of frame between + * this case and case when frame is created by PendSV_Handler. + */ + partition->ctx_ctrl.sp = (uint32_t)svc_args - sizeof(struct tfm_additional_context_t); + } + switch (svc_number) { case TFM_SVC_SPM_INIT: exc_return = tfm_spm_init();