hypercalls.c 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2019 Arm Ltd.

#include <linux/arm-smccc.h>
#include <linux/kvm_host.h>

#include <asm/kvm_emulate.h>

#include <kvm/arm_hypercalls.h>
#include <kvm/arm_psci.h>

int kvm_hvc_call_handler(struct kvm_vcpu *vcpu)
{
	u32 func_id = smccc_get_function(vcpu);
15
	long val = SMCCC_RET_NOT_SUPPORTED;
16
	u32 feature;
17
	gpa_t gpa;
18 19 20 21 22 23 24 25 26

	switch (func_id) {
	case ARM_SMCCC_VERSION_FUNC_ID:
		val = ARM_SMCCC_VERSION_1_1;
		break;
	case ARM_SMCCC_ARCH_FEATURES_FUNC_ID:
		feature = smccc_get_arg1(vcpu);
		switch (feature) {
		case ARM_SMCCC_ARCH_WORKAROUND_1:
27 28
			switch (arm64_get_spectre_v2_state()) {
			case SPECTRE_VULNERABLE:
29
				break;
30
			case SPECTRE_MITIGATED:
31 32
				val = SMCCC_RET_SUCCESS;
				break;
33
			case SPECTRE_UNAFFECTED:
34 35 36 37 38
				val = SMCCC_RET_NOT_REQUIRED;
				break;
			}
			break;
		case ARM_SMCCC_ARCH_WORKAROUND_2:
39 40 41
			switch (arm64_get_ssbd_state()) {
			case ARM64_SSBD_FORCE_DISABLE:
			case ARM64_SSBD_UNKNOWN:
42
				break;
43 44 45
			case ARM64_SSBD_KERNEL:
			case ARM64_SSBD_FORCE_ENABLE:
			case ARM64_SSBD_MITIGATED:
46 47 48 49
				val = SMCCC_RET_NOT_REQUIRED;
				break;
			}
			break;
50 51 52
		case ARM_SMCCC_HV_PV_TIME_FEATURES:
			val = SMCCC_RET_SUCCESS;
			break;
53 54
		}
		break;
55 56 57
	case ARM_SMCCC_HV_PV_TIME_FEATURES:
		val = kvm_hypercall_pv_features(vcpu);
		break;
58 59 60 61 62
	case ARM_SMCCC_HV_PV_TIME_ST:
		gpa = kvm_init_stolen_time(vcpu);
		if (gpa != GPA_INVALID)
			val = gpa;
		break;
63 64 65 66 67 68 69
	default:
		return kvm_psci_call(vcpu);
	}

	smccc_set_retval(vcpu, val, 0, 0, 0);
	return 1;
}