summaryrefslogtreecommitdiff
path: root/arch/arm64/include/asm/kvm_asm.h
diff options
context:
space:
mode:
authorMarc Zyngier <maz@kernel.org>2020-06-10 18:27:46 +0300
committerMarc Zyngier <maz@kernel.org>2020-06-10 21:09:09 +0300
commit304e2989c93e941fa55b38c59c975d4acfb6e4a2 (patch)
treedaeb76913463f6a51ee0d62a3503dbf688311bfc /arch/arm64/include/asm/kvm_asm.h
parent07da1ffaa1373f99331712faa67a00b5b807dfe8 (diff)
downloadlinux-304e2989c93e941fa55b38c59c975d4acfb6e4a2.tar.xz
KVM: arm64: Move hyp_symbol_addr() to kvm_asm.h
Recent refactoring of the arm64 code make it awkward to have hyp_symbol_addr() in kvm_mmu.h. Instead, move it next to its main user, which is __hyp_this_cpu_ptr(). Signed-off-by: Marc Zyngier <maz@kernel.org>
Diffstat (limited to 'arch/arm64/include/asm/kvm_asm.h')
-rw-r--r--arch/arm64/include/asm/kvm_asm.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h
index d9b7da15dbca..352aaebf4198 100644
--- a/arch/arm64/include/asm/kvm_asm.h
+++ b/arch/arm64/include/asm/kvm_asm.h
@@ -82,6 +82,26 @@ extern u32 __kvm_get_mdcr_el2(void);
extern char __smccc_workaround_1_smc[__SMCCC_WORKAROUND_1_SMC_SZ];
/*
+ * Obtain the PC-relative address of a kernel symbol
+ * s: symbol
+ *
+ * The goal of this macro is to return a symbol's address based on a
+ * PC-relative computation, as opposed to a loading the VA from a
+ * constant pool or something similar. This works well for HYP, as an
+ * absolute VA is guaranteed to be wrong. Only use this if trying to
+ * obtain the address of a symbol (i.e. not something you obtained by
+ * following a pointer).
+ */
+#define hyp_symbol_addr(s) \
+ ({ \
+ typeof(s) *addr; \
+ asm("adrp %0, %1\n" \
+ "add %0, %0, :lo12:%1\n" \
+ : "=r" (addr) : "S" (&s)); \
+ addr; \
+ })
+
+/*
* Home-grown __this_cpu_{ptr,read} variants that always work at HYP,
* provided that sym is really a *symbol* and not a pointer obtained from
* a data structure. As for SHIFT_PERCPU_PTR(), the creative casting keeps