xref: /linux/arch/arm64/kvm/hypercalls.c (revision 002dff36acfba3476b685a09f78ffb7c452f5951)
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2019 Arm Ltd.
3 
4 #include <linux/arm-smccc.h>
5 #include <linux/kvm_host.h>
6 
7 #include <asm/kvm_emulate.h>
8 
9 #include <kvm/arm_hypercalls.h>
10 #include <kvm/arm_psci.h>
11 
12 int kvm_hvc_call_handler(struct kvm_vcpu *vcpu)
13 {
14 	u32 func_id = smccc_get_function(vcpu);
15 	long val = SMCCC_RET_NOT_SUPPORTED;
16 	u32 feature;
17 	gpa_t gpa;
18 
19 	switch (func_id) {
20 	case ARM_SMCCC_VERSION_FUNC_ID:
21 		val = ARM_SMCCC_VERSION_1_1;
22 		break;
23 	case ARM_SMCCC_ARCH_FEATURES_FUNC_ID:
24 		feature = smccc_get_arg1(vcpu);
25 		switch (feature) {
26 		case ARM_SMCCC_ARCH_WORKAROUND_1:
27 			switch (kvm_arm_harden_branch_predictor()) {
28 			case KVM_BP_HARDEN_UNKNOWN:
29 				break;
30 			case KVM_BP_HARDEN_WA_NEEDED:
31 				val = SMCCC_RET_SUCCESS;
32 				break;
33 			case KVM_BP_HARDEN_NOT_REQUIRED:
34 				val = SMCCC_RET_NOT_REQUIRED;
35 				break;
36 			}
37 			break;
38 		case ARM_SMCCC_ARCH_WORKAROUND_2:
39 			switch (kvm_arm_have_ssbd()) {
40 			case KVM_SSBD_FORCE_DISABLE:
41 			case KVM_SSBD_UNKNOWN:
42 				break;
43 			case KVM_SSBD_KERNEL:
44 				val = SMCCC_RET_SUCCESS;
45 				break;
46 			case KVM_SSBD_FORCE_ENABLE:
47 			case KVM_SSBD_MITIGATED:
48 				val = SMCCC_RET_NOT_REQUIRED;
49 				break;
50 			}
51 			break;
52 		case ARM_SMCCC_HV_PV_TIME_FEATURES:
53 			val = SMCCC_RET_SUCCESS;
54 			break;
55 		}
56 		break;
57 	case ARM_SMCCC_HV_PV_TIME_FEATURES:
58 		val = kvm_hypercall_pv_features(vcpu);
59 		break;
60 	case ARM_SMCCC_HV_PV_TIME_ST:
61 		gpa = kvm_init_stolen_time(vcpu);
62 		if (gpa != GPA_INVALID)
63 			val = gpa;
64 		break;
65 	default:
66 		return kvm_psci_call(vcpu);
67 	}
68 
69 	smccc_set_retval(vcpu, val, 0, 0, 0);
70 	return 1;
71 }
72