Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM/ARM64: KVM: Fix CPU_ON emulation for PSCI v0.2

As-per PSCI v0.2, the source CPU provides physical address of
"entry point" and "context id" for starting a target CPU. Also,
if target CPU is already running then we should return ALREADY_ON.

Current emulation of CPU_ON function does not consider physical
address of "context id" and returns INVALID_PARAMETERS if target
CPU is already running.

This patch updates kvm_psci_vcpu_on() such that it works for both
PSCI v0.1 and PSCI v0.2.

Signed-off-by: Anup Patel <anup.patel@linaro.org>
Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org>
Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>

authored by

Anup Patel and committed by
Christoffer Dall
aa8aeefe bab0b430

+14 -1
+14 -1
arch/arm/kvm/psci.c
··· 48 48 struct kvm_vcpu *vcpu = NULL, *tmp; 49 49 wait_queue_head_t *wq; 50 50 unsigned long cpu_id; 51 + unsigned long context_id; 51 52 unsigned long mpidr; 52 53 phys_addr_t target_pc; 53 54 int i; ··· 69 68 * Make sure the caller requested a valid CPU and that the CPU is 70 69 * turned off. 71 70 */ 72 - if (!vcpu || !vcpu->arch.pause) 71 + if (!vcpu) 73 72 return PSCI_RET_INVALID_PARAMS; 73 + if (!vcpu->arch.pause) { 74 + if (kvm_psci_version(source_vcpu) != KVM_ARM_PSCI_0_1) 75 + return PSCI_RET_ALREADY_ON; 76 + else 77 + return PSCI_RET_INVALID_PARAMS; 78 + } 74 79 75 80 target_pc = *vcpu_reg(source_vcpu, 2); 81 + context_id = *vcpu_reg(source_vcpu, 3); 76 82 77 83 kvm_reset_vcpu(vcpu); 78 84 ··· 94 86 kvm_vcpu_set_be(vcpu); 95 87 96 88 *vcpu_pc(vcpu) = target_pc; 89 + /* 90 + * NOTE: We always update r0 (or x0) because for PSCI v0.1 91 + * the general puspose registers are undefined upon CPU_ON. 92 + */ 93 + *vcpu_reg(vcpu, 0) = context_id; 97 94 vcpu->arch.pause = false; 98 95 smp_mb(); /* Make sure the above is visible */ 99 96