KVM: arm64: Share context save and restore macros
authorAndrew Scull <ascull@google.com>
Tue, 15 Sep 2020 10:46:35 +0000 (11:46 +0100)
committerMarc Zyngier <maz@kernel.org>
Tue, 15 Sep 2020 17:39:03 +0000 (18:39 +0100)
To avoid duplicating the context save and restore macros, move them into
a shareable header.

Signed-off-by: Andrew Scull <ascull@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20200915104643.2543892-12-ascull@google.com
arch/arm64/include/asm/kvm_asm.h
arch/arm64/kvm/hyp/entry.S

index 4df2bd8..4e30738 100644 (file)
@@ -261,6 +261,45 @@ extern char __smccc_workaround_1_smc[__SMCCC_WORKAROUND_1_SMC_SZ];
        .popsection
 .endm
 
+#define CPU_XREG_OFFSET(x)     (CPU_USER_PT_REGS + 8*x)
+#define CPU_LR_OFFSET          CPU_XREG_OFFSET(30)
+#define CPU_SP_EL0_OFFSET      (CPU_LR_OFFSET + 8)
+
+/*
+ * We treat x18 as callee-saved as the host may use it as a platform
+ * register (e.g. for shadow call stack).
+ */
+.macro save_callee_saved_regs ctxt
+       str     x18,      [\ctxt, #CPU_XREG_OFFSET(18)]
+       stp     x19, x20, [\ctxt, #CPU_XREG_OFFSET(19)]
+       stp     x21, x22, [\ctxt, #CPU_XREG_OFFSET(21)]
+       stp     x23, x24, [\ctxt, #CPU_XREG_OFFSET(23)]
+       stp     x25, x26, [\ctxt, #CPU_XREG_OFFSET(25)]
+       stp     x27, x28, [\ctxt, #CPU_XREG_OFFSET(27)]
+       stp     x29, lr,  [\ctxt, #CPU_XREG_OFFSET(29)]
+.endm
+
+.macro restore_callee_saved_regs ctxt
+       // We require \ctxt is not x18-x28
+       ldr     x18,      [\ctxt, #CPU_XREG_OFFSET(18)]
+       ldp     x19, x20, [\ctxt, #CPU_XREG_OFFSET(19)]
+       ldp     x21, x22, [\ctxt, #CPU_XREG_OFFSET(21)]
+       ldp     x23, x24, [\ctxt, #CPU_XREG_OFFSET(23)]
+       ldp     x25, x26, [\ctxt, #CPU_XREG_OFFSET(25)]
+       ldp     x27, x28, [\ctxt, #CPU_XREG_OFFSET(27)]
+       ldp     x29, lr,  [\ctxt, #CPU_XREG_OFFSET(29)]
+.endm
+
+.macro save_sp_el0 ctxt, tmp
+       mrs     \tmp,   sp_el0
+       str     \tmp,   [\ctxt, #CPU_SP_EL0_OFFSET]
+.endm
+
+.macro restore_sp_el0 ctxt, tmp
+       ldr     \tmp,     [\ctxt, #CPU_SP_EL0_OFFSET]
+       msr     sp_el0, \tmp
+.endm
+
 #endif
 
 #endif /* __ARM_KVM_ASM_H__ */
index 4787fc8..afaa8d1 100644 (file)
@@ -7,7 +7,6 @@
 #include <linux/linkage.h>
 
 #include <asm/alternative.h>
-#include <asm/asm-offsets.h>
 #include <asm/assembler.h>
 #include <asm/fpsimdmacros.h>
 #include <asm/kvm.h>
 #include <asm/kvm_mmu.h>
 #include <asm/kvm_ptrauth.h>
 
-#define CPU_XREG_OFFSET(x)     (CPU_USER_PT_REGS + 8*x)
-#define CPU_SP_EL0_OFFSET      (CPU_XREG_OFFSET(30) + 8)
-
        .text
 
 /*
- * We treat x18 as callee-saved as the host may use it as a platform
- * register (e.g. for shadow call stack).
- */
-.macro save_callee_saved_regs ctxt
-       str     x18,      [\ctxt, #CPU_XREG_OFFSET(18)]
-       stp     x19, x20, [\ctxt, #CPU_XREG_OFFSET(19)]
-       stp     x21, x22, [\ctxt, #CPU_XREG_OFFSET(21)]
-       stp     x23, x24, [\ctxt, #CPU_XREG_OFFSET(23)]
-       stp     x25, x26, [\ctxt, #CPU_XREG_OFFSET(25)]
-       stp     x27, x28, [\ctxt, #CPU_XREG_OFFSET(27)]
-       stp     x29, lr,  [\ctxt, #CPU_XREG_OFFSET(29)]
-.endm
-
-.macro restore_callee_saved_regs ctxt
-       // We require \ctxt is not x18-x28
-       ldr     x18,      [\ctxt, #CPU_XREG_OFFSET(18)]
-       ldp     x19, x20, [\ctxt, #CPU_XREG_OFFSET(19)]
-       ldp     x21, x22, [\ctxt, #CPU_XREG_OFFSET(21)]
-       ldp     x23, x24, [\ctxt, #CPU_XREG_OFFSET(23)]
-       ldp     x25, x26, [\ctxt, #CPU_XREG_OFFSET(25)]
-       ldp     x27, x28, [\ctxt, #CPU_XREG_OFFSET(27)]
-       ldp     x29, lr,  [\ctxt, #CPU_XREG_OFFSET(29)]
-.endm
-
-.macro save_sp_el0 ctxt, tmp
-       mrs     \tmp,   sp_el0
-       str     \tmp,   [\ctxt, #CPU_SP_EL0_OFFSET]
-.endm
-
-.macro restore_sp_el0 ctxt, tmp
-       ldr     \tmp,     [\ctxt, #CPU_SP_EL0_OFFSET]
-       msr     sp_el0, \tmp
-.endm
-
-/*
  * u64 __guest_enter(struct kvm_vcpu *vcpu);
  */
 SYM_FUNC_START(__guest_enter)