arm64: KVM: Add HYP per-cpu accessors
authorMarc Zyngier <marc.zyngier@arm.com>
Fri, 20 Jul 2018 09:56:31 +0000 (10:56 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 22 Jul 2018 12:27:42 +0000 (14:27 +0200)
commit 85478bab409171de501b719971fd25a3d5d639f9 upstream.

As we're going to require to access per-cpu variables at EL2,
let's craft the minimum set of accessors required to implement
reading a per-cpu variable, relying on tpidr_el2 to contain the
per-cpu offset.

Reviewed-by: Christoffer Dall <christoffer.dall@arm.com>
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/arm64/include/asm/kvm_asm.h

index 217630dc51c9c57b32e2b805f5b05183a01aaa9f..b3b4a03f2d2f8636d8be58904271bf23420ba10f 100644 (file)
@@ -66,14 +66,37 @@ extern u32 __kvm_get_mdcr_el2(void);
 
 extern u32 __init_stage2_translation(void);
 
+/* Home-grown __this_cpu_{ptr,read} variants that always work at HYP */
+#define __hyp_this_cpu_ptr(sym)                                                \
+       ({                                                              \
+               void *__ptr = hyp_symbol_addr(sym);                     \
+               __ptr += read_sysreg(tpidr_el2);                        \
+               (typeof(&sym))__ptr;                                    \
+        })
+
+#define __hyp_this_cpu_read(sym)                                       \
+       ({                                                              \
+               *__hyp_this_cpu_ptr(sym);                               \
+        })
+
 #else /* __ASSEMBLY__ */
 
-.macro get_host_ctxt reg, tmp
-       adr_l   \reg, kvm_host_cpu_state
+.macro hyp_adr_this_cpu reg, sym, tmp
+       adr_l   \reg, \sym
        mrs     \tmp, tpidr_el2
        add     \reg, \reg, \tmp
 .endm
 
+.macro hyp_ldr_this_cpu reg, sym, tmp
+       adr_l   \reg, \sym
+       mrs     \tmp, tpidr_el2
+       ldr     \reg,  [\reg, \tmp]
+.endm
+
+.macro get_host_ctxt reg, tmp
+       hyp_adr_this_cpu \reg, kvm_host_cpu_state, \tmp
+.endm
+
 .macro get_vcpu_ptr vcpu, ctxt
        get_host_ctxt \ctxt, \vcpu
        ldr     \vcpu, [\ctxt, #HOST_CONTEXT_VCPU]