Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: arm64: ARM_SMCCC_ARCH_WORKAROUND_1 doesn't return SMCCC_RET_NOT_REQUIRED

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: c118bbb52743 ("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>

authored by

Stephen Boyd and committed by
Will Deacon
1de111b5 0fa97e94

+3 -3
-2
arch/arm64/kernel/proton-pack.c
··· 135 135 return SPECTRE_VULNERABLE; 136 136 } 137 137 138 - #define SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED (1) 139 - 140 138 static enum mitigation_state spectre_v2_get_cpu_fw_mitigation_state(void) 141 139 { 142 140 int ret;
+1 -1
arch/arm64/kvm/hypercalls.c
··· 31 31 val = SMCCC_RET_SUCCESS; 32 32 break; 33 33 case SPECTRE_UNAFFECTED: 34 - val = SMCCC_RET_NOT_REQUIRED; 34 + val = SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED; 35 35 break; 36 36 } 37 37 break;
+2
include/linux/arm-smccc.h
··· 87 87 ARM_SMCCC_SMC_32, \ 88 88 0, 0x7fff) 89 89 90 + #define SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED 1 91 + 90 92 /* Paravirtualised time calls (defined by ARM DEN0057A) */ 91 93 #define ARM_SMCCC_HV_PV_TIME_FEATURES \ 92 94 ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \