Have vm_secondary_start_vcpu take vcpu rather than index.
This simplifies it, and the caller already has to check the index.
There's also no need to check whether the VM is the primary, as we
already assume it is a secondary anyway.
Change-Id: I0edd2a273fef3d4098e7c45ac7a1e81d1416844b
diff --git a/src/cpu.c b/src/cpu.c
index 56d76a4..2c7bef2 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -181,6 +181,27 @@
}
/**
+ * Starts a vCPU of a secondary VM.
+ */
+void vcpu_secondary_reset_and_start(struct vcpu *vcpu, ipaddr_t entry,
+ uintreg_t arg)
+{
+ struct vm *vm = vcpu->vm;
+
+ assert(vm->id != HF_PRIMARY_VM_ID);
+
+ /*
+ * Set vCPU registers to a clean state ready for boot. As this is a
+ * secondary which can migrate between pCPUs, the ID of the vCPU is
+ * defined as the index and does not match the ID of the pCPU it is
+ * running on.
+ */
+ arch_regs_reset(&vcpu->regs, false, vm->id, vcpu_index(vcpu),
+ vm->ptable.root);
+ vcpu_on(vcpu, entry, arg);
+}
+
+/**
* Handles a page fault. It does so by determining if it's a legitimate or
* spurious fault, and recovering from the latter.
*
diff --git a/src/load.c b/src/load.c
index 0f71770..56751aa 100644
--- a/src/load.c
+++ b/src/load.c
@@ -285,6 +285,7 @@
ipaddr_t secondary_entry;
const char *p;
struct vm *vm;
+ struct vcpu *vcpu;
dlog("Loading ");
for (p = name.next; p != name.limit; ++p) {
@@ -348,8 +349,9 @@
dlog("Loaded with %u vcpus, entry at 0x%x\n", cpu,
pa_addr(secondary_mem_begin));
- vm_secondary_start_vcpu(
- vm, 0, secondary_entry,
+ vcpu = &vm->vcpus[0];
+ vcpu_secondary_reset_and_start(
+ vcpu, secondary_entry,
pa_difference(secondary_mem_begin, secondary_mem_end));
}
diff --git a/src/vm.c b/src/vm.c
index 532d5a2..f2bbe78 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -102,28 +102,3 @@
sl_unlock(&locked->vm->lock);
locked->vm = NULL;
}
-
-/**
- * Starts a vCPU of a secondary VM.
- *
- * TODO: Shall we use index or id here?
- */
-void vm_secondary_start_vcpu(struct vm *vm, size_t index, ipaddr_t entry,
- uintreg_t arg)
-{
- struct vcpu *vcpu = &vm->vcpus[index];
-
- if (index >= vm->vcpu_count) {
- return;
- }
-
- /*
- * Set vCPU registers to a clean state ready for boot. As this is a
- * secondary which can migrate between pCPUs, the ID of the vCPU is
- * defined as the index and does not match the ID of the pCPU it is
- * running on.
- */
- arch_regs_reset(&vcpu->regs, vm->id == HF_PRIMARY_VM_ID, vm->id, index,
- vm->ptable.root);
- vcpu_on(vcpu, entry, arg);
-}