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/inc/hf/vcpu.h b/inc/hf/vcpu.h
index dbe6b94..398d9a8 100644
--- a/inc/hf/vcpu.h
+++ b/inc/hf/vcpu.h
@@ -354,16 +354,16 @@
vcpu_locked.vcpu->interrupts.enabled_and_pending_fiq_count;
}
-static inline void vcpu_call_chain_extend(struct vcpu *vcpu1,
- struct vcpu *vcpu2)
+static inline void vcpu_call_chain_extend(struct vcpu_locked vcpu1_locked,
+ struct vcpu_locked vcpu2_locked)
{
- vcpu1->call_chain.next_node = vcpu2;
- vcpu2->call_chain.prev_node = vcpu1;
+ vcpu1_locked.vcpu->call_chain.next_node = vcpu2_locked.vcpu;
+ vcpu2_locked.vcpu->call_chain.prev_node = vcpu1_locked.vcpu;
}
-static inline void vcpu_call_chain_remove_node(struct vcpu *vcpu1,
- struct vcpu *vcpu2)
+static inline void vcpu_call_chain_remove_node(struct vcpu_locked vcpu1_locked,
+ struct vcpu_locked vcpu2_locked)
{
- vcpu1->call_chain.prev_node = NULL;
- vcpu2->call_chain.next_node = NULL;
+ vcpu1_locked.vcpu->call_chain.prev_node = NULL;
+ vcpu2_locked.vcpu->call_chain.next_node = NULL;
}