Skip to content

Commit 2cfe892

Browse files
Marc Zyngiergregkh
authored andcommitted
arm/arm64: KVM: Turn kvm_psci_version into a static inline
Commit a4097b3 upstream. We're about to need kvm_psci_version in HYP too. So let's turn it into a static inline, and pass the kvm structure as a second parameter (so that HYP can do a kern_hyp_va on it). Tested-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 98be716 commit 2cfe892

3 files changed

Lines changed: 34 additions & 19 deletions

File tree

‎arch/arm64/kvm/hyp/switch.c‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <linux/jump_label.h>
2020
#include <uapi/linux/psci.h>
2121

22+
#include <kvm/arm_psci.h>
23+
2224
#include <asm/kvm_asm.h>
2325
#include <asm/kvm_emulate.h>
2426
#include <asm/kvm_hyp.h>
@@ -325,14 +327,16 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu)
325327

326328
if (exit_code == ARM_EXCEPTION_TRAP &&
327329
(kvm_vcpu_trap_get_class(vcpu) == ESR_ELx_EC_HVC64 ||
328-
kvm_vcpu_trap_get_class(vcpu) == ESR_ELx_EC_HVC32) &&
329-
vcpu_get_reg(vcpu, 0) == PSCI_0_2_FN_PSCI_VERSION) {
330-
u64 val = PSCI_RET_NOT_SUPPORTED;
331-
if (test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features))
332-
val = 2;
333-
334-
vcpu_set_reg(vcpu, 0, val);
335-
goto again;
330+
kvm_vcpu_trap_get_class(vcpu) == ESR_ELx_EC_HVC32)) {
331+
u32 val = vcpu_get_reg(vcpu, 0);
332+
333+
if (val == PSCI_0_2_FN_PSCI_VERSION) {
334+
val = kvm_psci_version(vcpu, kern_hyp_va(vcpu->kvm));
335+
if (unlikely(val == KVM_ARM_PSCI_0_1))
336+
val = PSCI_RET_NOT_SUPPORTED;
337+
vcpu_set_reg(vcpu, 0, val);
338+
goto again;
339+
}
336340
}
337341

338342
if (static_branch_unlikely(&vgic_v2_cpuif_trap) &&

‎include/kvm/arm_psci.h‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#ifndef __KVM_ARM_PSCI_H__
1919
#define __KVM_ARM_PSCI_H__
2020

21+
#include <linux/kvm_host.h>
2122
#include <uapi/linux/psci.h>
2223

2324
#define KVM_ARM_PSCI_0_1 PSCI_VERSION(0, 1)
@@ -26,7 +27,25 @@
2627

2728
#define KVM_ARM_PSCI_LATEST KVM_ARM_PSCI_1_0
2829

29-
int kvm_psci_version(struct kvm_vcpu *vcpu);
30+
/*
31+
* We need the KVM pointer independently from the vcpu as we can call
32+
* this from HYP, and need to apply kern_hyp_va on it...
33+
*/
34+
static inline int kvm_psci_version(struct kvm_vcpu *vcpu, struct kvm *kvm)
35+
{
36+
/*
37+
* Our PSCI implementation stays the same across versions from
38+
* v0.2 onward, only adding the few mandatory functions (such
39+
* as FEATURES with 1.0) that are required by newer
40+
* revisions. It is thus safe to return the latest.
41+
*/
42+
if (test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features))
43+
return KVM_ARM_PSCI_LATEST;
44+
45+
return KVM_ARM_PSCI_0_1;
46+
}
47+
48+
3049
int kvm_hvc_call_handler(struct kvm_vcpu *vcpu);
3150

3251
#endif /* __KVM_ARM_PSCI_H__ */

‎virt/kvm/arm/psci.c‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu)
123123
if (!vcpu)
124124
return PSCI_RET_INVALID_PARAMS;
125125
if (!vcpu->arch.power_off) {
126-
if (kvm_psci_version(source_vcpu) != KVM_ARM_PSCI_0_1)
126+
if (kvm_psci_version(source_vcpu, kvm) != KVM_ARM_PSCI_0_1)
127127
return PSCI_RET_ALREADY_ON;
128128
else
129129
return PSCI_RET_INVALID_PARAMS;
@@ -232,14 +232,6 @@ static void kvm_psci_system_reset(struct kvm_vcpu *vcpu)
232232
kvm_prepare_system_event(vcpu, KVM_SYSTEM_EVENT_RESET);
233233
}
234234

235-
int kvm_psci_version(struct kvm_vcpu *vcpu)
236-
{
237-
if (test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features))
238-
return KVM_ARM_PSCI_LATEST;
239-
240-
return KVM_ARM_PSCI_0_1;
241-
}
242-
243235
static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu)
244236
{
245237
struct kvm *kvm = vcpu->kvm;
@@ -397,7 +389,7 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu)
397389
*/
398390
static int kvm_psci_call(struct kvm_vcpu *vcpu)
399391
{
400-
switch (kvm_psci_version(vcpu)) {
392+
switch (kvm_psci_version(vcpu, vcpu->kvm)) {
401393
case KVM_ARM_PSCI_1_0:
402394
return kvm_psci_1_0_call(vcpu);
403395
case KVM_ARM_PSCI_0_2:

0 commit comments

Comments
 (0)