Add helper function to check whether VM ID is in current world.
Assert that vCPU is in the right world before switching to it.
Change-Id: I5f994c63ec97058a52adf7dba04a88e6e69b1b25
Signed-off-by: Andrew Walbran <qwandor@google.com>
diff --git a/src/vm.c b/src/vm.c
index 2ad3516..fbbdc9f 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -201,6 +201,17 @@
}
/**
+ * Return whether the given VM ID represents an entity in the current world:
+ * i.e. the hypervisor or a normal world VM when running in the normal world, or
+ * the SPM or an SP when running in the secure world.
+ */
+bool vm_id_is_current_world(ffa_vm_id_t vm_id)
+{
+ return (vm_id & HF_VM_ID_WORLD_MASK) !=
+ (HF_OTHER_WORLD_ID & HF_VM_ID_WORLD_MASK);
+}
+
+/**
* Map a range of addresses to the VM in both the MMU and the IOMMU.
*
* mm_vm_defrag should always be called after a series of page table updates,