KVM: arm64: Remove patching of fn pointers in hyp
authorDavid Brazdil <dbrazdil@google.com>
Tue, 5 Jan 2021 18:05:40 +0000 (18:05 +0000)
committerMarc Zyngier <maz@kernel.org>
Sat, 23 Jan 2021 14:01:00 +0000 (14:01 +0000)
Storing a function pointer in hyp now generates relocation information
used at early boot to convert the address to hyp VA. The existing
alternative-based conversion mechanism is therefore obsolete. Remove it
and simplify its users.

Acked-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: David Brazdil <dbrazdil@google.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20210105180541.65031-8-dbrazdil@google.com
arch/arm64/include/asm/kvm_mmu.h
arch/arm64/kernel/image-vars.h
arch/arm64/kvm/hyp/nvhe/hyp-main.c
arch/arm64/kvm/va_layout.c

index adadc468cc71547b8caa32eb5ed136d11c3ba7d0..90873851f677a1ddc3adfd4137ef6ae0f72d2577 100644 (file)
@@ -135,24 +135,6 @@ static __always_inline unsigned long __kern_hyp_va(unsigned long v)
 
 #define kern_hyp_va(v)         ((typeof(v))(__kern_hyp_va((unsigned long)(v))))
 
-static __always_inline unsigned long __kimg_hyp_va(unsigned long v)
-{
-       unsigned long offset;
-
-       asm volatile(ALTERNATIVE_CB("movz %0, #0\n"
-                                   "movk %0, #0, lsl #16\n"
-                                   "movk %0, #0, lsl #32\n"
-                                   "movk %0, #0, lsl #48\n",
-                                   kvm_update_kimg_phys_offset)
-                    : "=r" (offset));
-
-       return __kern_hyp_va((v - offset) | PAGE_OFFSET);
-}
-
-#define kimg_fn_hyp_va(v)      ((typeof(*v))(__kimg_hyp_va((unsigned long)(v))))
-
-#define kimg_fn_ptr(x) (typeof(x) **)(x)
-
 /*
  * We currently support using a VM-specified IPA size. For backward
  * compatibility, the default IPA size is fixed to 40bits.
index f676243abac62efa99d63369c403d95d61db2d3f..23f1a557bd9f04fb61c90d2428fcc12ecca127ac 100644 (file)
@@ -64,7 +64,6 @@ __efistub__ctype              = _ctype;
 /* Alternative callbacks for init-time patching of nVHE hyp code. */
 KVM_NVHE_ALIAS(kvm_patch_vector_branch);
 KVM_NVHE_ALIAS(kvm_update_va_mask);
-KVM_NVHE_ALIAS(kvm_update_kimg_phys_offset);
 KVM_NVHE_ALIAS(kvm_get_kimage_voffset);
 
 /* Global kernel state accessed by nVHE hyp code. */
index a906f9e2ff34fba2d5588263b1f024e23b09963d..f012f8665ecc1c6a0510bf25705b738f5660a077 100644 (file)
@@ -108,9 +108,9 @@ static void handle___vgic_v3_restore_aprs(struct kvm_cpu_context *host_ctxt)
 
 typedef void (*hcall_t)(struct kvm_cpu_context *);
 
-#define HANDLE_FUNC(x) [__KVM_HOST_SMCCC_FUNC_##x] = kimg_fn_ptr(handle_##x)
+#define HANDLE_FUNC(x) [__KVM_HOST_SMCCC_FUNC_##x] = (hcall_t)handle_##x
 
-static const hcall_t *host_hcall[] = {
+static const hcall_t host_hcall[] = {
        HANDLE_FUNC(__kvm_vcpu_run),
        HANDLE_FUNC(__kvm_flush_vm_context),
        HANDLE_FUNC(__kvm_tlb_flush_vmid_ipa),
@@ -130,7 +130,6 @@ static const hcall_t *host_hcall[] = {
 static void handle_host_hcall(struct kvm_cpu_context *host_ctxt)
 {
        DECLARE_REG(unsigned long, id, host_ctxt, 0);
-       const hcall_t *kfn;
        hcall_t hfn;
 
        id -= KVM_HOST_SMCCC_ID(0);
@@ -138,13 +137,11 @@ static void handle_host_hcall(struct kvm_cpu_context *host_ctxt)
        if (unlikely(id >= ARRAY_SIZE(host_hcall)))
                goto inval;
 
-       kfn = host_hcall[id];
-       if (unlikely(!kfn))
+       hfn = host_hcall[id];
+       if (unlikely(!hfn))
                goto inval;
 
        cpu_reg(host_ctxt, 0) = SMCCC_RET_SUCCESS;
-
-       hfn = kimg_fn_hyp_va(kfn);
        hfn(host_ctxt);
 
        return;
index fee7dcd95d73198c600c14eeb80f841f956cd658..978301392d678710139c15957ac0bbf404d146ee 100644 (file)
@@ -283,12 +283,6 @@ static void generate_mov_q(u64 val, __le32 *origptr, __le32 *updptr, int nr_inst
        *updptr++ = cpu_to_le32(insn);
 }
 
-void kvm_update_kimg_phys_offset(struct alt_instr *alt,
-                                __le32 *origptr, __le32 *updptr, int nr_inst)
-{
-       generate_mov_q(kimage_voffset + PHYS_OFFSET, origptr, updptr, nr_inst);
-}
-
 void kvm_get_kimage_voffset(struct alt_instr *alt,
                            __le32 *origptr, __le32 *updptr, int nr_inst)
 {