diff --git a/services/spd/trusty/trusty.c b/services/spd/trusty/trusty.c index 2af568e..cb28b2e 100644 --- a/services/spd/trusty/trusty.c +++ b/services/spd/trusty/trusty.c @@ -80,6 +80,8 @@ struct args trusty_init_context_stack(void **sp, void *new_stack); struct args trusty_context_switch_helper(void **sp, void *smc_params); +static uint32_t current_vmid; + static struct trusty_cpu_ctx *get_trusty_ctx(void) { return &trusty_cpu_ctx[plat_my_core_pos()]; @@ -231,6 +233,7 @@ uint64_t flags) { struct args ret; + uint32_t vmid = 0; if (is_caller_secure(flags)) { if (smc_fid == SMC_SC_NS_RETURN) { @@ -252,8 +255,21 @@ case SMC_FC_FIQ_EXIT: return trusty_fiq_exit(handle, x1, x2, x3); default: + if (is_hypervisor_mode()) + vmid = SMC_GET_GP(handle, CTX_GPREG_X7); + + if ((current_vmid != 0) && (current_vmid != vmid)) { + /* This message will cause SMC mechanism + * abnormal in multi-guest environment. + * Change it to WARN in case you need it. + */ + VERBOSE("Previous SMC not finished.\n"); + SMC_RET1(handle, SM_ERR_BUSY); + } + current_vmid = vmid; ret = trusty_context_switch(NON_SECURE, smc_fid, x1, x2, x3); + current_vmid = 0; SMC_RET1(handle, ret.r0); } }