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 (arm64_get_spectre_v2_state()) {
28 case SPECTRE_VULNERABLE
:
30 case SPECTRE_MITIGATED
:
31 val
= SMCCC_RET_SUCCESS
;
33 case SPECTRE_UNAFFECTED
:
34 val
= SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED
;
38 case ARM_SMCCC_ARCH_WORKAROUND_2
:
39 switch (arm64_get_spectre_v4_state()) {
40 case SPECTRE_VULNERABLE
:
42 case SPECTRE_MITIGATED
:
44 * SSBS everywhere: Indicate no firmware
45 * support, as the SSBS support will be
46 * indicated to the guest and the default is
49 * Otherwise, expose a permanent mitigation
50 * to the guest, and hide SSBS so that the
51 * guest stays protected.
53 if (cpus_have_final_cap(ARM64_SSBS
))
56 case SPECTRE_UNAFFECTED
:
57 val
= SMCCC_RET_NOT_REQUIRED
;
61 case ARM_SMCCC_HV_PV_TIME_FEATURES
:
62 val
= SMCCC_RET_SUCCESS
;
66 case ARM_SMCCC_HV_PV_TIME_FEATURES
:
67 val
= kvm_hypercall_pv_features(vcpu
);
69 case ARM_SMCCC_HV_PV_TIME_ST
:
70 gpa
= kvm_init_stolen_time(vcpu
);
71 if (gpa
!= GPA_INVALID
)
75 return kvm_psci_call(vcpu
);
78 smccc_set_retval(vcpu
, val
, 0, 0, 0);