mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-30 07:34:12 +08:00
1de111b51b
According to the SMCCC spec[1](7.5.2 Discovery) the
ARM_SMCCC_ARCH_WORKAROUND_1 function id only returns 0, 1, and
SMCCC_RET_NOT_SUPPORTED.
0 is "workaround required and safe to call this function"
1 is "workaround not required but safe to call this function"
SMCCC_RET_NOT_SUPPORTED is "might be vulnerable or might not be, who knows, I give up!"
SMCCC_RET_NOT_SUPPORTED might as well mean "workaround required, except
calling this function may not work because it isn't implemented in some
cases". Wonderful. We map this SMC call to
0 is SPECTRE_MITIGATED
1 is SPECTRE_UNAFFECTED
SMCCC_RET_NOT_SUPPORTED is SPECTRE_VULNERABLE
For KVM hypercalls (hvc), we've implemented this function id to return
SMCCC_RET_NOT_SUPPORTED, 0, and SMCCC_RET_NOT_REQUIRED. One of those
isn't supposed to be there. Per the code we call
arm64_get_spectre_v2_state() to figure out what to return for this
feature discovery call.
0 is SPECTRE_MITIGATED
SMCCC_RET_NOT_REQUIRED is SPECTRE_UNAFFECTED
SMCCC_RET_NOT_SUPPORTED is SPECTRE_VULNERABLE
Let's clean this up so that KVM tells the guest this mapping:
0 is SPECTRE_MITIGATED
1 is SPECTRE_UNAFFECTED
SMCCC_RET_NOT_SUPPORTED is SPECTRE_VULNERABLE
Note: SMCCC_RET_NOT_AFFECTED is 1 but isn't part of the SMCCC spec
Fixes: c118bbb527
("arm64: KVM: Propagate full Spectre v2 workaround state to KVM guests")
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Acked-by: Marc Zyngier <maz@kernel.org>
Acked-by: Will Deacon <will@kernel.org>
Cc: Andre Przywara <andre.przywara@arm.com>
Cc: Steven Price <steven.price@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: stable@vger.kernel.org
Link: https://developer.arm.com/documentation/den0028/latest [1]
Link: https://lore.kernel.org/r/20201023154751.1973872-1-swboyd@chromium.org
Signed-off-by: Will Deacon <will@kernel.org>
81 lines
1.8 KiB
C
81 lines
1.8 KiB
C
// 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);
|
|
long val = SMCCC_RET_NOT_SUPPORTED;
|
|
u32 feature;
|
|
gpa_t gpa;
|
|
|
|
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:
|
|
switch (arm64_get_spectre_v2_state()) {
|
|
case SPECTRE_VULNERABLE:
|
|
break;
|
|
case SPECTRE_MITIGATED:
|
|
val = SMCCC_RET_SUCCESS;
|
|
break;
|
|
case SPECTRE_UNAFFECTED:
|
|
val = SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED;
|
|
break;
|
|
}
|
|
break;
|
|
case ARM_SMCCC_ARCH_WORKAROUND_2:
|
|
switch (arm64_get_spectre_v4_state()) {
|
|
case SPECTRE_VULNERABLE:
|
|
break;
|
|
case SPECTRE_MITIGATED:
|
|
/*
|
|
* SSBS everywhere: Indicate no firmware
|
|
* support, as the SSBS support will be
|
|
* indicated to the guest and the default is
|
|
* safe.
|
|
*
|
|
* Otherwise, expose a permanent mitigation
|
|
* to the guest, and hide SSBS so that the
|
|
* guest stays protected.
|
|
*/
|
|
if (cpus_have_final_cap(ARM64_SSBS))
|
|
break;
|
|
fallthrough;
|
|
case SPECTRE_UNAFFECTED:
|
|
val = SMCCC_RET_NOT_REQUIRED;
|
|
break;
|
|
}
|
|
break;
|
|
case ARM_SMCCC_HV_PV_TIME_FEATURES:
|
|
val = SMCCC_RET_SUCCESS;
|
|
break;
|
|
}
|
|
break;
|
|
case ARM_SMCCC_HV_PV_TIME_FEATURES:
|
|
val = kvm_hypercall_pv_features(vcpu);
|
|
break;
|
|
case ARM_SMCCC_HV_PV_TIME_ST:
|
|
gpa = kvm_init_stolen_time(vcpu);
|
|
if (gpa != GPA_INVALID)
|
|
val = gpa;
|
|
break;
|
|
default:
|
|
return kvm_psci_call(vcpu);
|
|
}
|
|
|
|
smccc_set_retval(vcpu, val, 0, 0, 0);
|
|
return 1;
|
|
}
|