1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2019 Arm Ltd.
4 #include <linux/arm-smccc.h>
5 #include <linux/kvm_host.h>
7 #include <asm/kvm_emulate.h>
9 #include <kvm/arm_hypercalls.h>
10 #include <kvm/arm_psci.h>
12 int kvm_hvc_call_handler(struct kvm_vcpu
*vcpu
)
14 u32 func_id
= smccc_get_function(vcpu
);
15 long val
= SMCCC_RET_NOT_SUPPORTED
;
20 case ARM_SMCCC_VERSION_FUNC_ID
:
21 val
= ARM_SMCCC_VERSION_1_1
;
23 case ARM_SMCCC_ARCH_FEATURES_FUNC_ID
:
24 feature
= smccc_get_arg1(vcpu
);
26 case ARM_SMCCC_ARCH_WORKAROUND_1
:
27 switch (kvm_arm_harden_branch_predictor()) {
28 case KVM_BP_HARDEN_UNKNOWN
:
30 case KVM_BP_HARDEN_WA_NEEDED
:
31 val
= SMCCC_RET_SUCCESS
;
33 case KVM_BP_HARDEN_NOT_REQUIRED
:
34 val
= SMCCC_RET_NOT_REQUIRED
;
38 case ARM_SMCCC_ARCH_WORKAROUND_2
:
39 switch (kvm_arm_have_ssbd()) {
40 case KVM_SSBD_FORCE_DISABLE
:
41 case KVM_SSBD_UNKNOWN
:
44 val
= SMCCC_RET_SUCCESS
;
46 case KVM_SSBD_FORCE_ENABLE
:
47 case KVM_SSBD_MITIGATED
:
48 val
= SMCCC_RET_NOT_REQUIRED
;
52 case ARM_SMCCC_HV_PV_TIME_FEATURES
:
53 val
= SMCCC_RET_SUCCESS
;
57 case ARM_SMCCC_HV_PV_TIME_FEATURES
:
58 val
= kvm_hypercall_pv_features(vcpu
);
60 case ARM_SMCCC_HV_PV_TIME_ST
:
61 gpa
= kvm_init_stolen_time(vcpu
);
62 if (gpa
!= GPA_INVALID
)
66 return kvm_psci_call(vcpu
);
69 smccc_set_retval(vcpu
, val
, 0, 0, 0);