refactor: pass locked vcpu structures to ff-a helper functions

While handling FF-A ABI call, hafnium has to alter the state of
multiple vCPUs. It is necessary for hafnium to lock the vCPUs (to
protect from concurrent accesses due to execution on other physical
cores) before modifying its properties and unlock once done.

Currently, this is done in a piecemeal approach which could lead to
deadlocks. This patch refactors the helper functions to receive
locked vCPU(s) by locking them as early as possible and unlocking
only at the tail end of FF-A ABI handler.

Also, in order to adhere to the rule stating a VM's lock must be
acquired before any of its vCPU's lock, this patch makes few changes
to momentarily release vCPU lock and acquire the lock immediately.

Signed-off-by: Madhukar Pappireddy <madhukar.pappireddy@arm.com>
Change-Id: I392f053f7384d7c34f22924a57a6d8e9f62ddb2e
diff --git a/src/arch/aarch64/hypervisor/handler.c b/src/arch/aarch64/hypervisor/handler.c
index 1ee1f3d..0204429 100644
--- a/src/arch/aarch64/hypervisor/handler.c
+++ b/src/arch/aarch64/hypervisor/handler.c
@@ -590,9 +590,14 @@
 	case FFA_MSG_WAIT_32:
 		*args = api_ffa_msg_wait(current, next, args);
 		return true;
-	case FFA_MSG_POLL_32:
-		*args = api_ffa_msg_recv(false, current, next);
+	case FFA_MSG_POLL_32: {
+		struct vcpu_locked current_locked;
+
+		current_locked = vcpu_lock(current);
+		*args = api_ffa_msg_recv(false, current_locked, next);
+		vcpu_unlock(&current_locked);
 		return true;
+	}
 	case FFA_RUN_32:
 		*args = api_ffa_run(ffa_vm_id(*args), ffa_vcpu_index(*args),
 				    current, next);
@@ -1120,7 +1125,7 @@
 		current_vcpu->priority_mask = pmr;
 		ret = api_interrupt_inject_locked(current_locked,
 						  HF_MANAGED_EXIT_INTID,
-						  current_vcpu, NULL);
+						  current_locked, NULL);
 		if (ret != 0) {
 			panic("Failed to inject managed exit interrupt\n");
 		}