fix: first vCPU runs in the VCPU_STATE_RUNNING

First vCPU was executing with the waiting state.
That is not correct, as such, use 'vcpu_set_running'.

Function vcpu_set_running has been changed to only
update the registers state in vCPU if provided any
arguments.

Change-Id: I039f023a66b3bf5871d23fb51b7855c1bdd55ff2
Signed-off-by: J-Alves <joao.alves@arm.com>
diff --git a/src/arch/aarch64/plat/psci/spmc.c b/src/arch/aarch64/plat/psci/spmc.c
index ff4bfd5..a8a2256 100644
--- a/src/arch/aarch64/plat/psci/spmc.c
+++ b/src/arch/aarch64/plat/psci/spmc.c
@@ -101,6 +101,7 @@
 
 	vcpu_secondary_reset_and_start(vcpu_locked, vcpu->vm->secondary_ep,
 				       0ULL);
+	vcpu_set_running(vcpu_locked, NULL);
 
 	/* vCPU restarts in runtime model for SP initialization. */
 	vcpu->rt_model = RTM_SP_INIT;
diff --git a/src/vcpu.c b/src/vcpu.c
index eb0edb0..d601994 100644
--- a/src/vcpu.c
+++ b/src/vcpu.c
@@ -261,17 +261,19 @@
 
 /**
  * Sets the vcpu in the VCPU_STATE_RUNNING.
- * With that, its register are set as "not available". In case the vCPU
- * was priorly in a waiting state it takes the arguments provided,
- * and writes them to the gp register state.
+ * With that, its register are set as "not available".
+ * If there are registers to be written to vCPU's context, do so.
+ * However, this action is restricted to WAITING and BLOCKED states,
+ * as such, assert accordingly.
  */
 void vcpu_set_running(struct vcpu_locked target_locked, struct ffa_value *args)
 {
 	struct vcpu *target_vcpu = target_locked.vcpu;
 
-	if (target_locked.vcpu->state == VCPU_STATE_WAITING) {
+	if (args != NULL) {
 		CHECK(target_vcpu->regs_available);
-		assert(args != NULL);
+		assert(target_vcpu->state == VCPU_STATE_WAITING ||
+		       target_vcpu->state == VCPU_STATE_BLOCKED);
 
 		arch_regs_set_retval(&target_vcpu->regs, *args);
 	}