Commit 247bc166 authored by David Brazdil's avatar David Brazdil Committed by Marc Zyngier

KVM: arm64: Remove hyp_symbol_addr

Hyp code used the hyp_symbol_addr helper to force PC-relative addressing
because absolute addressing results in kernel VAs due to the way hyp
code is linked. This is not true anymore, so remove the helper and
update all of its users.
Acked-by: default avatarArd Biesheuvel <ardb@kernel.org>
Signed-off-by: default avatarDavid Brazdil <dbrazdil@google.com>
Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210105180541.65031-9-dbrazdil@google.com
parent 537db4af
...@@ -199,32 +199,6 @@ extern void __vgic_v3_init_lrs(void); ...@@ -199,32 +199,6 @@ extern void __vgic_v3_init_lrs(void);
extern u32 __kvm_get_mdcr_el2(void); extern u32 __kvm_get_mdcr_el2(void);
#if defined(GCC_VERSION) && GCC_VERSION < 50000
#define SYM_CONSTRAINT "i"
#else
#define SYM_CONSTRAINT "S"
#endif
/*
* 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) : SYM_CONSTRAINT (&s)); \
addr; \
})
#define __KVM_EXTABLE(from, to) \ #define __KVM_EXTABLE(from, to) \
" .pushsection __kvm_ex_table, \"a\"\n" \ " .pushsection __kvm_ex_table, \"a\"\n" \
" .align 3\n" \ " .align 3\n" \
......
...@@ -505,8 +505,8 @@ static inline void __kvm_unexpected_el2_exception(void) ...@@ -505,8 +505,8 @@ static inline void __kvm_unexpected_el2_exception(void)
struct exception_table_entry *entry, *end; struct exception_table_entry *entry, *end;
unsigned long elr_el2 = read_sysreg(elr_el2); unsigned long elr_el2 = read_sysreg(elr_el2);
entry = hyp_symbol_addr(__start___kvm_ex_table); entry = &__start___kvm_ex_table;
end = hyp_symbol_addr(__stop___kvm_ex_table); end = &__stop___kvm_ex_table;
while (entry < end) { while (entry < end) {
addr = (unsigned long)&entry->insn + entry->insn; addr = (unsigned long)&entry->insn + entry->insn;
......
...@@ -33,8 +33,8 @@ unsigned long __hyp_per_cpu_offset(unsigned int cpu) ...@@ -33,8 +33,8 @@ unsigned long __hyp_per_cpu_offset(unsigned int cpu)
if (cpu >= ARRAY_SIZE(kvm_arm_hyp_percpu_base)) if (cpu >= ARRAY_SIZE(kvm_arm_hyp_percpu_base))
hyp_panic(); hyp_panic();
cpu_base_array = (unsigned long *)hyp_symbol_addr(kvm_arm_hyp_percpu_base); cpu_base_array = (unsigned long *)&kvm_arm_hyp_percpu_base;
this_cpu_base = kern_hyp_va(cpu_base_array[cpu]); this_cpu_base = kern_hyp_va(cpu_base_array[cpu]);
elf_base = (unsigned long)hyp_symbol_addr(__per_cpu_start); elf_base = (unsigned long)&__per_cpu_start;
return this_cpu_base - elf_base; return this_cpu_base - elf_base;
} }
...@@ -134,8 +134,8 @@ static int psci_cpu_on(u64 func_id, struct kvm_cpu_context *host_ctxt) ...@@ -134,8 +134,8 @@ static int psci_cpu_on(u64 func_id, struct kvm_cpu_context *host_ctxt)
if (cpu_id == INVALID_CPU_ID) if (cpu_id == INVALID_CPU_ID)
return PSCI_RET_INVALID_PARAMS; return PSCI_RET_INVALID_PARAMS;
boot_args = per_cpu_ptr(hyp_symbol_addr(cpu_on_args), cpu_id); boot_args = per_cpu_ptr(&cpu_on_args, cpu_id);
init_params = per_cpu_ptr(hyp_symbol_addr(kvm_init_params), cpu_id); init_params = per_cpu_ptr(&kvm_init_params, cpu_id);
/* Check if the target CPU is already being booted. */ /* Check if the target CPU is already being booted. */
if (!try_acquire_boot_args(boot_args)) if (!try_acquire_boot_args(boot_args))
...@@ -146,7 +146,7 @@ static int psci_cpu_on(u64 func_id, struct kvm_cpu_context *host_ctxt) ...@@ -146,7 +146,7 @@ static int psci_cpu_on(u64 func_id, struct kvm_cpu_context *host_ctxt)
wmb(); wmb();
ret = psci_call(func_id, mpidr, ret = psci_call(func_id, mpidr,
__hyp_pa(hyp_symbol_addr(kvm_hyp_cpu_entry)), __hyp_pa(&kvm_hyp_cpu_entry),
__hyp_pa(init_params)); __hyp_pa(init_params));
/* If successful, the lock will be released by the target CPU. */ /* If successful, the lock will be released by the target CPU. */
...@@ -165,8 +165,8 @@ static int psci_cpu_suspend(u64 func_id, struct kvm_cpu_context *host_ctxt) ...@@ -165,8 +165,8 @@ static int psci_cpu_suspend(u64 func_id, struct kvm_cpu_context *host_ctxt)
struct psci_boot_args *boot_args; struct psci_boot_args *boot_args;
struct kvm_nvhe_init_params *init_params; struct kvm_nvhe_init_params *init_params;
boot_args = this_cpu_ptr(hyp_symbol_addr(suspend_args)); boot_args = this_cpu_ptr(&suspend_args);
init_params = this_cpu_ptr(hyp_symbol_addr(kvm_init_params)); init_params = this_cpu_ptr(&kvm_init_params);
/* /*
* No need to acquire a lock before writing to boot_args because a core * No need to acquire a lock before writing to boot_args because a core
...@@ -180,7 +180,7 @@ static int psci_cpu_suspend(u64 func_id, struct kvm_cpu_context *host_ctxt) ...@@ -180,7 +180,7 @@ static int psci_cpu_suspend(u64 func_id, struct kvm_cpu_context *host_ctxt)
* point if it is a deep sleep state. * point if it is a deep sleep state.
*/ */
return psci_call(func_id, power_state, return psci_call(func_id, power_state,
__hyp_pa(hyp_symbol_addr(kvm_hyp_cpu_resume)), __hyp_pa(&kvm_hyp_cpu_resume),
__hyp_pa(init_params)); __hyp_pa(init_params));
} }
...@@ -192,8 +192,8 @@ static int psci_system_suspend(u64 func_id, struct kvm_cpu_context *host_ctxt) ...@@ -192,8 +192,8 @@ static int psci_system_suspend(u64 func_id, struct kvm_cpu_context *host_ctxt)
struct psci_boot_args *boot_args; struct psci_boot_args *boot_args;
struct kvm_nvhe_init_params *init_params; struct kvm_nvhe_init_params *init_params;
boot_args = this_cpu_ptr(hyp_symbol_addr(suspend_args)); boot_args = this_cpu_ptr(&suspend_args);
init_params = this_cpu_ptr(hyp_symbol_addr(kvm_init_params)); init_params = this_cpu_ptr(&kvm_init_params);
/* /*
* No need to acquire a lock before writing to boot_args because a core * No need to acquire a lock before writing to boot_args because a core
...@@ -204,7 +204,7 @@ static int psci_system_suspend(u64 func_id, struct kvm_cpu_context *host_ctxt) ...@@ -204,7 +204,7 @@ static int psci_system_suspend(u64 func_id, struct kvm_cpu_context *host_ctxt)
/* Will only return on error. */ /* Will only return on error. */
return psci_call(func_id, return psci_call(func_id,
__hyp_pa(hyp_symbol_addr(kvm_hyp_cpu_resume)), __hyp_pa(&kvm_hyp_cpu_resume),
__hyp_pa(init_params), 0); __hyp_pa(init_params), 0);
} }
...@@ -213,12 +213,12 @@ asmlinkage void __noreturn kvm_host_psci_cpu_entry(bool is_cpu_on) ...@@ -213,12 +213,12 @@ asmlinkage void __noreturn kvm_host_psci_cpu_entry(bool is_cpu_on)
struct psci_boot_args *boot_args; struct psci_boot_args *boot_args;
struct kvm_cpu_context *host_ctxt; struct kvm_cpu_context *host_ctxt;
host_ctxt = &this_cpu_ptr(hyp_symbol_addr(kvm_host_data))->host_ctxt; host_ctxt = &this_cpu_ptr(&kvm_host_data)->host_ctxt;
if (is_cpu_on) if (is_cpu_on)
boot_args = this_cpu_ptr(hyp_symbol_addr(cpu_on_args)); boot_args = this_cpu_ptr(&cpu_on_args);
else else
boot_args = this_cpu_ptr(hyp_symbol_addr(suspend_args)); boot_args = this_cpu_ptr(&suspend_args);
cpu_reg(host_ctxt, 0) = boot_args->r0; cpu_reg(host_ctxt, 0) = boot_args->r0;
write_sysreg_el2(boot_args->pc, SYS_ELR); write_sysreg_el2(boot_args->pc, SYS_ELR);
......
...@@ -64,7 +64,7 @@ int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu) ...@@ -64,7 +64,7 @@ int __vgic_v2_perform_cpuif_access(struct kvm_vcpu *vcpu)
} }
rd = kvm_vcpu_dabt_get_rd(vcpu); rd = kvm_vcpu_dabt_get_rd(vcpu);
addr = hyp_symbol_addr(kvm_vgic_global_state)->vcpu_hyp_va; addr = kvm_vgic_global_state.vcpu_hyp_va;
addr += fault_ipa - vgic->vgic_cpu_base; addr += fault_ipa - vgic->vgic_cpu_base;
if (kvm_vcpu_dabt_iswrite(vcpu)) { if (kvm_vcpu_dabt_iswrite(vcpu)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment