[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250930103130.197534-13-suzuki.poulose@arm.com>
Date: Tue, 30 Sep 2025 11:31:26 +0100
From: Suzuki K Poulose <suzuki.poulose@....com>
To: kvmarm@...ts.linux.dev
Cc: kvm@...r.kernel.org,
linux-kernel@...r.kernel.org,
will@...nel.org,
oliver.upton@...ux.dev,
maz@...nel.org,
alexandru.elisei@....com,
aneesh.kumar@...nel.org,
steven.price@....com,
tabba@...gle.com,
Suzuki K Poulose <suzuki.poulose@....com>
Subject: [PATCH kvmtool v4 11/15] arm64: psci: Implement CPU_ON
From: Oliver Upton <oliver.upton@...ux.dev>
Add support for the PSCI CPU_ON call, wherein a caller can power on a
targeted CPU and reset it with the provided context (i.e. entrypoint and
context id). Rely on the KVM_ARM_VCPU_INIT ioctl, which has the effect
of an architectural warm reset, to do the heavy lifting.
Signed-off-by: Oliver Upton <oliver.upton@...ux.dev>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@....com>
---
arm64/psci.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/arm64/psci.c b/arm64/psci.c
index 72429b36..14c98639 100644
--- a/arm64/psci.c
+++ b/arm64/psci.c
@@ -18,6 +18,8 @@ static void psci_features(struct kvm_cpu *vcpu, struct arm_smccc_res *res)
case PSCI_0_2_FN_CPU_SUSPEND:
case PSCI_0_2_FN64_CPU_SUSPEND:
case PSCI_0_2_FN_CPU_OFF:
+ case PSCI_0_2_FN_CPU_ON:
+ case PSCI_0_2_FN64_CPU_ON:
case ARM_SMCCC_VERSION_FUNC_ID:
res->a0 = PSCI_RET_SUCCESS;
break;
@@ -47,6 +49,68 @@ static void cpu_off(struct kvm_cpu *vcpu, struct arm_smccc_res *res)
die_perror("KVM_SET_MP_STATE failed");
}
+static void reset_cpu_with_context(struct kvm_cpu *vcpu, u64 entry_addr, u64 ctx_id)
+{
+ struct kvm_one_reg reg;
+
+ if (ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu->init))
+ die_perror("KVM_ARM_VCPU_INIT failed");
+
+ reg = (struct kvm_one_reg) {
+ .id = ARM64_CORE_REG(regs.pc),
+ .addr = (u64)&entry_addr,
+ };
+ if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®))
+ die_perror("KVM_SET_ONE_REG failed");
+
+ reg = (struct kvm_one_reg) {
+ .id = ARM64_CORE_REG(regs.regs[0]),
+ .addr = (u64)&ctx_id,
+ };
+ if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®))
+ die_perror("KVM_SET_ONE_REG failed");
+}
+
+static bool psci_valid_affinity(u64 affinity)
+{
+ return !(affinity & ~ARM_MPIDR_HWID_BITMASK);
+}
+
+static void cpu_on(struct kvm_cpu *vcpu, struct arm_smccc_res *res)
+{
+ u64 target_mpidr = smccc_get_arg(vcpu, 1);
+ u64 entry_addr = smccc_get_arg(vcpu, 2);
+ u64 ctx_id = smccc_get_arg(vcpu, 3);
+ struct kvm_mp_state mp_state;
+ struct kvm_cpu *target;
+
+ if (!psci_valid_affinity(target_mpidr)) {
+ res->a0 = PSCI_RET_INVALID_PARAMS;
+ return;
+ }
+
+ kvm__pause(vcpu->kvm);
+
+ target = kvm__arch_mpidr_to_vcpu(vcpu->kvm, target_mpidr);
+ if (!target) {
+ res->a0 = PSCI_RET_INVALID_PARAMS;
+ goto out_continue;
+ }
+
+ if (ioctl(target->vcpu_fd, KVM_GET_MP_STATE, &mp_state))
+ die_perror("KVM_GET_MP_STATE failed");
+
+ if (mp_state.mp_state != KVM_MP_STATE_STOPPED) {
+ res->a0 = PSCI_RET_ALREADY_ON;
+ goto out_continue;
+ }
+
+ reset_cpu_with_context(target, entry_addr, ctx_id);
+ res->a0 = PSCI_RET_SUCCESS;
+out_continue:
+ kvm__continue(vcpu->kvm);
+}
+
void handle_psci(struct kvm_cpu *vcpu, struct arm_smccc_res *res)
{
switch (vcpu->kvm_run->hypercall.nr) {
@@ -63,6 +127,10 @@ void handle_psci(struct kvm_cpu *vcpu, struct arm_smccc_res *res)
case PSCI_0_2_FN_CPU_OFF:
cpu_off(vcpu, res);
break;
+ case PSCI_0_2_FN_CPU_ON:
+ case PSCI_0_2_FN64_CPU_ON:
+ cpu_on(vcpu, res);
+ break;
default:
res->a0 = PSCI_RET_NOT_SUPPORTED;
}
--
2.43.0
Powered by blists - more mailing lists