Skip to content

Commit b4f18c0

Browse files
Marc Zyngierctmarinas
authored andcommitted
arm64: KVM: Handle guest's ARCH_WORKAROUND_2 requests
In order to forward the guest's ARCH_WORKAROUND_2 calls to EL3, add a small(-ish) sequence to handle it at EL2. Special care must be taken to track the state of the guest itself by updating the workaround flags. We also rely on patching to enable calls into the firmware. Note that since we need to execute branches, this always executes after the Spectre-v2 mitigation has been applied. Reviewed-by: Mark Rutland <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent 55e3748 commit b4f18c0

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

arch/arm64/kernel/asm-offsets.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ int main(void)
136136
#ifdef CONFIG_KVM_ARM_HOST
137137
DEFINE(VCPU_CONTEXT, offsetof(struct kvm_vcpu, arch.ctxt));
138138
DEFINE(VCPU_FAULT_DISR, offsetof(struct kvm_vcpu, arch.fault.disr_el1));
139+
DEFINE(VCPU_WORKAROUND_FLAGS, offsetof(struct kvm_vcpu, arch.workaround_flags));
139140
DEFINE(CPU_GP_REGS, offsetof(struct kvm_cpu_context, gp_regs));
140141
DEFINE(CPU_USER_PT_REGS, offsetof(struct kvm_regs, regs));
141142
DEFINE(CPU_FP_REGS, offsetof(struct kvm_regs, fp_regs));

arch/arm64/kvm/hyp/hyp-entry.S

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,44 @@ el1_hvc_guest:
106106
*/
107107
ldr x1, [sp] // Guest's x0
108108
eor w1, w1, #ARM_SMCCC_ARCH_WORKAROUND_1
109+
cbz w1, wa_epilogue
110+
111+
/* ARM_SMCCC_ARCH_WORKAROUND_2 handling */
112+
eor w1, w1, #(ARM_SMCCC_ARCH_WORKAROUND_1 ^ \
113+
ARM_SMCCC_ARCH_WORKAROUND_2)
109114
cbnz w1, el1_trap
110-
mov x0, x1
115+
116+
#ifdef CONFIG_ARM64_SSBD
117+
alternative_cb arm64_enable_wa2_handling
118+
b wa2_end
119+
alternative_cb_end
120+
get_vcpu_ptr x2, x0
121+
ldr x0, [x2, #VCPU_WORKAROUND_FLAGS]
122+
123+
// Sanitize the argument and update the guest flags
124+
ldr x1, [sp, #8] // Guest's x1
125+
clz w1, w1 // Murphy's device:
126+
lsr w1, w1, #5 // w1 = !!w1 without using
127+
eor w1, w1, #1 // the flags...
128+
bfi x0, x1, #VCPU_WORKAROUND_2_FLAG_SHIFT, #1
129+
str x0, [x2, #VCPU_WORKAROUND_FLAGS]
130+
131+
/* Check that we actually need to perform the call */
132+
hyp_ldr_this_cpu x0, arm64_ssbd_callback_required, x2
133+
cbz x0, wa2_end
134+
135+
mov w0, #ARM_SMCCC_ARCH_WORKAROUND_2
136+
smc #0
137+
138+
/* Don't leak data from the SMC call */
139+
mov x3, xzr
140+
wa2_end:
141+
mov x2, xzr
142+
mov x1, xzr
143+
#endif
144+
145+
wa_epilogue:
146+
mov x0, xzr
111147
add sp, sp, #16
112148
eret
113149

0 commit comments

Comments
 (0)