feat: adapt vcpu operational mode to interpret newly added states
With a set of newly introduced states for a vCPU to allow fine grain
tracking of lifecycle of a partition, we have to slightly extend the
notion of a vCPU being ON and OFF.
This patch adds necessary support and refactors helpers to interpret
if a vCPU is in ON or OFF from a operational mode perspective. For
example, VCPU_STATE_STARTING is also considered as OFF since partition
manager has not yet scheduled the vCPU on a physical CPU.
Change-Id: I03aeca4ecb83c28e6cb7897ad0e2a51b315e16b0
Signed-off-by: Madhukar Pappireddy <madhukar.pappireddy@arm.com>
diff --git a/inc/hf/vcpu.h b/inc/hf/vcpu.h
index 85d4b9f..0c12324 100644
--- a/inc/hf/vcpu.h
+++ b/inc/hf/vcpu.h
@@ -270,7 +270,7 @@
struct two_vcpu_locked vcpu_lock_both(struct vcpu *vcpu1, struct vcpu *vcpu2);
void vcpu_unlock(struct vcpu_locked *locked);
void vcpu_init(struct vcpu *vcpu, struct vm *vm);
-void vcpu_on(struct vcpu_locked vcpu, ipaddr_t entry, uintreg_t arg);
+void vcpu_prepare(struct vcpu_locked vcpu, ipaddr_t entry, uintreg_t arg);
ffa_vcpu_index_t vcpu_index(const struct vcpu *vcpu);
bool vcpu_is_off(struct vcpu_locked vcpu);
bool vcpu_secondary_reset_and_start(struct vcpu_locked vcpu_locked,
diff --git a/src/arch/aarch64/hypervisor/psci_handler.c b/src/arch/aarch64/hypervisor/psci_handler.c
index 4702301..5f571ce 100644
--- a/src/arch/aarch64/hypervisor/psci_handler.c
+++ b/src/arch/aarch64/hypervisor/psci_handler.c
@@ -169,7 +169,7 @@
vcpu_target = vm_get_vcpu(vcpu->vm, cpu_index(c));
vcpu_locked = vcpu_lock(vcpu_target);
- vcpu_on(vcpu_locked, ipa_init(arg1), arg2);
+ vcpu_prepare(vcpu_locked, ipa_init(arg1), arg2);
vcpu_unlock(&vcpu_locked);
/*
diff --git a/src/load.c b/src/load.c
index d782904..219c99b 100644
--- a/src/load.c
+++ b/src/load.c
@@ -417,7 +417,7 @@
vm_update_boot(vm);
vcpu_locked = vcpu_lock(vm_get_vcpu(vm, 0));
- vcpu_on(vcpu_locked, primary_entry, params->kernel_arg);
+ vcpu_prepare(vcpu_locked, primary_entry, params->kernel_arg);
vcpu_unlock(&vcpu_locked);
ret = true;
diff --git a/src/vcpu.c b/src/vcpu.c
index 522973d..ba52d3b 100644
--- a/src/vcpu.c
+++ b/src/vcpu.c
@@ -79,12 +79,12 @@
/**
* Initialise the registers for the given vCPU and set the state to
- * VCPU_STATE_WAITING. The caller must hold the vCPU lock while calling this.
+ * VCPU_STATE_CREATED. The caller must hold the vCPU lock while calling this.
*/
-void vcpu_on(struct vcpu_locked vcpu, ipaddr_t entry, uintreg_t arg)
+void vcpu_prepare(struct vcpu_locked vcpu, ipaddr_t entry, uintreg_t arg)
{
arch_regs_set_pc_arg(&vcpu.vcpu->regs, entry, arg);
- vcpu.vcpu->state = VCPU_STATE_WAITING;
+ vcpu.vcpu->state = VCPU_STATE_CREATED;
}
ffa_vcpu_index_t vcpu_index(const struct vcpu *vcpu)
@@ -101,10 +101,14 @@
* purposes of PSCI, because according to the PSCI specification (section
* 5.7.1) a core is only considered to be off if it has been turned off
* with a CPU_OFF call or hasn't yet been turned on with a CPU_ON call.
+ * Note that vCPU is considered to be off until it makes the transition
+ * to STARTING state.
*/
bool vcpu_is_off(struct vcpu_locked vcpu)
{
- return (vcpu.vcpu->state == VCPU_STATE_OFF);
+ return (vcpu.vcpu->state == VCPU_STATE_OFF ||
+ vcpu.vcpu->state == VCPU_STATE_CREATED ||
+ vcpu.vcpu->state == VCPU_STATE_NULL);
}
/**
@@ -130,7 +134,7 @@
* pCPU it is running on.
*/
arch_regs_reset(vcpu_locked.vcpu);
- vcpu_on(vcpu_locked, entry, arg);
+ vcpu_prepare(vcpu_locked, entry, arg);
}
return vcpu_was_off;