Merge branch 'v4.4/topic/hibernate' into linux-linaro-lsk-v4.4
authorAlex Shi <alex.shi@linaro.org>
Mon, 14 Nov 2016 13:20:48 +0000 (21:20 +0800)
committerAlex Shi <alex.shi@linaro.org>
Mon, 14 Nov 2016 13:20:48 +0000 (21:20 +0800)
Conflicts:
conflicts are almost come from mm-kaslr, focus on mm
arch/arm64/include/asm/cpufeature.h
arch/arm64/include/asm/pgtable.h
arch/arm64/kernel/Makefile
arch/arm64/kernel/cpufeature.c
arch/arm64/kernel/head.S
arch/arm64/kernel/suspend.c
arch/arm64/kernel/vmlinux.lds.S
arch/arm64/kvm/hyp.S
arch/arm64/mm/init.c
arch/arm64/mm/mmu.c
arch/arm64/mm/proc-macros.S

17 files changed:
1  2 
arch/arm/Kconfig
arch/arm/kvm/arm.c
arch/arm64/Kconfig
arch/arm64/include/asm/assembler.h
arch/arm64/include/asm/cpufeature.h
arch/arm64/include/asm/kvm_asm.h
arch/arm64/include/asm/kvm_host.h
arch/arm64/include/asm/memory.h
arch/arm64/include/asm/sysreg.h
arch/arm64/kernel/Makefile
arch/arm64/kernel/arm64ksyms.c
arch/arm64/kernel/cpufeature.c
arch/arm64/kernel/head.S
arch/arm64/kernel/setup.c
arch/arm64/kernel/sleep.S
arch/arm64/kernel/vmlinux.lds.S
arch/arm64/kvm/hyp.S

index 51f1775e3adbea19c648036e215ee512e682d1f3,61d7eb3c1ff5c00e1db491eae128544c7a764c32..9049ac023bee94dd6458b3bf2a4bebcbe9d5f593
@@@ -35,9 -35,9 +35,10 @@@ config AR
        select HAVE_ARCH_BITREVERSE if (CPU_32v7M || CPU_32v7) && !CPU_32v6
        select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32
        select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32
 +      select HAVE_ARCH_HARDENED_USERCOPY
        select HAVE_ARCH_SECCOMP_FILTER if (AEABI && !OABI_COMPAT)
        select HAVE_ARCH_TRACEHOOK
+       select HAVE_ARM_SMCCC if CPU_V7
        select HAVE_BPF_JIT
        select HAVE_CC_STACKPROTECTOR
        select HAVE_CONTEXT_TRACKING
index c17cb14f368b5b93924d683cb21e818a60dabcf8,30c9f7b4250557c0567dcb01ae6478fff3b2d32f..5aafc90c436b032bfc16b4f4f8980b944151ac97
@@@ -967,9 -979,10 +979,10 @@@ static void cpu_init_hyp_mode(void *dum
        pgd_ptr = kvm_mmu_get_httbr();
        stack_page = __this_cpu_read(kvm_arm_hyp_stack_page);
        hyp_stack_ptr = stack_page + PAGE_SIZE;
 -      vector_ptr = (unsigned long)__kvm_hyp_vector;
 +      vector_ptr = (unsigned long)kvm_ksym_ref(__kvm_hyp_vector);
  
        __cpu_init_hyp_mode(boot_pgd_ptr, pgd_ptr, hyp_stack_ptr, vector_ptr);
+       __cpu_init_stage2();
  
        kvm_arm_init_debug();
  }
Simple merge
index 9ea846ded55cc6aee3532e392445c539245fe29f,3c6d0df4b6bbead7c628db45fcdab4ba5bbc87d1..290e13428f4a1c6b1b9425938a80dcd69460e592
@@@ -200,17 -196,102 +203,113 @@@ lr    .req    x30             // link registe
        str     \src, [\tmp, :lo12:\sym]
        .endm
  
 +      /*
 +       * @sym: The name of the per-cpu variable
 +       * @reg: Result of per_cpu(sym, smp_processor_id())
 +       * @tmp: scratch register
 +       */
 +      .macro this_cpu_ptr, sym, reg, tmp
 +      adr_l   \reg, \sym
 +      mrs     \tmp, tpidr_el1
 +      add     \reg, \reg, \tmp
 +      .endm
 +
+ /*
+  * vma_vm_mm - get mm pointer from vma pointer (vma->vm_mm)
+  */
+       .macro  vma_vm_mm, rd, rn
+       ldr     \rd, [\rn, #VMA_VM_MM]
+       .endm
+ /*
+  * mmid - get context id from mm pointer (mm->context.id)
+  */
+       .macro  mmid, rd, rn
+       ldr     \rd, [\rn, #MM_CONTEXT_ID]
+       .endm
+ /*
+  * dcache_line_size - get the minimum D-cache line size from the CTR register.
+  */
+       .macro  dcache_line_size, reg, tmp
+       mrs     \tmp, ctr_el0                   // read CTR
+       ubfm    \tmp, \tmp, #16, #19            // cache line size encoding
+       mov     \reg, #4                        // bytes per word
+       lsl     \reg, \reg, \tmp                // actual cache line size
+       .endm
+ /*
+  * icache_line_size - get the minimum I-cache line size from the CTR register.
+  */
+       .macro  icache_line_size, reg, tmp
+       mrs     \tmp, ctr_el0                   // read CTR
+       and     \tmp, \tmp, #0xf                // cache line size encoding
+       mov     \reg, #4                        // bytes per word
+       lsl     \reg, \reg, \tmp                // actual cache line size
+       .endm
+ /*
+  * tcr_set_idmap_t0sz - update TCR.T0SZ so that we can load the ID map
+  */
+       .macro  tcr_set_idmap_t0sz, valreg, tmpreg
+ #ifndef CONFIG_ARM64_VA_BITS_48
+       ldr_l   \tmpreg, idmap_t0sz
+       bfi     \valreg, \tmpreg, #TCR_T0SZ_OFFSET, #TCR_TxSZ_WIDTH
+ #endif
+       .endm
+ /*
+  * Macro to perform a data cache maintenance for the interval
+  * [kaddr, kaddr + size)
+  *
+  *    op:             operation passed to dc instruction
+  *    domain:         domain used in dsb instruciton
+  *    kaddr:          starting virtual address of the region
+  *    size:           size of the region
+  *    Corrupts:       kaddr, size, tmp1, tmp2
+  */
+       .macro dcache_by_line_op op, domain, kaddr, size, tmp1, tmp2
+       dcache_line_size \tmp1, \tmp2
+       add     \size, \kaddr, \size
+       sub     \tmp2, \tmp1, #1
+       bic     \kaddr, \kaddr, \tmp2
+ 9998: dc      \op, \kaddr
+       add     \kaddr, \kaddr, \tmp1
+       cmp     \kaddr, \size
+       b.lo    9998b
+       dsb     \domain
+       .endm
+ /*
+  * reset_pmuserenr_el0 - reset PMUSERENR_EL0 if PMUv3 present
+  */
+       .macro  reset_pmuserenr_el0, tmpreg
+       mrs     \tmpreg, id_aa64dfr0_el1        // Check ID_AA64DFR0_EL1 PMUVer
+       sbfx    \tmpreg, \tmpreg, #8, #4
+       cmp     \tmpreg, #1                     // Skip if no PMU present
+       b.lt    9000f
+       msr     pmuserenr_el0, xzr              // Disable PMU access from EL0
+ 9000:
+       .endm
+ /*
+  * copy_page - copy src to dest using temp registers t1-t8
+  */
+       .macro copy_page dest:req src:req t1:req t2:req t3:req t4:req t5:req t6:req t7:req t8:req
+ 9998: ldp     \t1, \t2, [\src]
+       ldp     \t3, \t4, [\src, #16]
+       ldp     \t5, \t6, [\src, #32]
+       ldp     \t7, \t8, [\src, #48]
+       add     \src, \src, #64
+       stnp    \t1, \t2, [\dest]
+       stnp    \t3, \t4, [\dest, #16]
+       stnp    \t5, \t6, [\dest, #32]
+       stnp    \t7, \t8, [\dest, #48]
+       add     \dest, \dest, #64
+       tst     \src, #(PAGE_SIZE - 1)
+       b.ne    9998b
+       .endm
  /*
   * Annotate a function as position independent, i.e., safe to be called before
   * the kernel virtual mapping is activated.
index 672783a7fa3b5f75d2b59fc6863eeb34afd0766c,f1a134900ae5779dfacef0d0ec1bd5e9fbd34dca..308d96eaeeaeb0e8fc2f3e54c6a11fb3882a15a6
  #define ARM64_HAS_LSE_ATOMICS                 5
  #define ARM64_WORKAROUND_CAVIUM_23154         6
  #define ARM64_WORKAROUND_834220                       7
 -#define ARM64_WORKAROUND_CAVIUM_27456         8
 +#define ARM64_HAS_NO_HW_PREFETCH              8
 +#define ARM64_HAS_UAO                         9
 +#define ARM64_ALT_PAN_NOT_UAO                 10
  
 -/* #define ARM64_HAS_NO_HW_PREFETCH           8 */
 -/* #define ARM64_HAS_UAO                      9 */
 -/* #define ARM64_ALT_PAN_NOT_UAO              10 */
 -#define ARM64_HAS_VIRT_HOST_EXTN              11
 -
 -#define ARM64_NCAPS                           12
 +#define ARM64_WORKAROUND_CAVIUM_27456         11
- #define ARM64_NCAPS                           12
++#define ARM64_HAS_VIRT_HOST_EXTN              12
++#define ARM64_NCAPS                           13
  
  #ifndef __ASSEMBLY__
  
Simple merge
index 90c6368ad7c859bbc101d88f5273d33380c8d35a,1b37b5d5092fc4dd53a9f186f5ec70df96dc0f26..bbdaa56c22244cfcc119ea403ab813424c8fed6c
@@@ -243,10 -322,14 +322,14 @@@ static inline void __cpu_init_hyp_mode(
         * Call initialization code, and switch to the full blown
         * HYP code.
         */
 -      kvm_call_hyp((void *)boot_pgd_ptr, pgd_ptr,
 -                   hyp_stack_ptr, vector_ptr);
 +      __kvm_call_hyp((void *)boot_pgd_ptr, pgd_ptr,
 +                     hyp_stack_ptr, vector_ptr);
  }
  
+ static inline void __cpu_init_stage2(void)
+ {
+ }
  static inline void kvm_arch_hardware_disable(void) {}
  static inline void kvm_arch_hardware_unsetup(void) {}
  static inline void kvm_arch_sync_events(struct kvm *kvm) {}
index 12f8a00fb3f1767a645a04358dcaca08fd4f6b43,5773a6629f106e58039e2cd44834b2df608b3152..d776037d199fa4ca0257ba6cf5beda36d001d6e2
  
  #define TASK_UNMAPPED_BASE    (PAGE_ALIGN(TASK_SIZE / 4))
  
+ #define KERNEL_START      _text
+ #define KERNEL_END        _end
 +/*
 + * The size of the KASAN shadow region. This should be 1/8th of the
 + * size of the entire kernel virtual address space.
 + */
 +#ifdef CONFIG_KASAN
 +#define KASAN_SHADOW_SIZE     (UL(1) << (VA_BITS - 3))
 +#else
 +#define KASAN_SHADOW_SIZE     (0)
 +#endif
 +
  /*
   * Physical vs virtual RAM address space conversion.  These are
   * private definitions which should NOT be used outside memory.h
index b9fd8ec790336569ee8fdedb4573e25b3045c29b,99dac2f9f21af66e2a564be9a1a24e24c478bf40..0961a24e8d4891bdf976f7cf1d39a39cd31cc229
  
  #define SET_PSTATE_PAN(x) __inst_arm(0xd5000000 | REG_PSTATE_PAN_IMM |\
                                     (!!x)<<8 | 0x1f)
 +#define SET_PSTATE_UAO(x) __inst_arm(0xd5000000 | REG_PSTATE_UAO_IMM |\
 +                                   (!!x)<<8 | 0x1f)
  
- /* SCTLR_EL1 */
- #define SCTLR_EL1_CP15BEN     (0x1 << 5)
- #define SCTLR_EL1_SED         (0x1 << 8)
- #define SCTLR_EL1_SPAN                (0x1 << 23)
+ /* Common SCTLR_ELx flags. */
+ #define SCTLR_ELx_EE    (1 << 25)
+ #define SCTLR_ELx_I   (1 << 12)
+ #define SCTLR_ELx_SA  (1 << 3)
+ #define SCTLR_ELx_C   (1 << 2)
+ #define SCTLR_ELx_A   (1 << 1)
+ #define SCTLR_ELx_M   1
+ #define SCTLR_ELx_FLAGS       (SCTLR_ELx_M | SCTLR_ELx_A | SCTLR_ELx_C | \
+                        SCTLR_ELx_SA | SCTLR_ELx_I)
+ /* SCTLR_EL1 specific flags. */
+ #define SCTLR_EL1_SPAN                (1 << 23)
+ #define SCTLR_EL1_SED         (1 << 8)
+ #define SCTLR_EL1_CP15BEN     (1 << 5)
  
  
  /* id_aa64isar0 */
  
  #else
  
+ #include <linux/types.h>
  asm(
  "     .irp    num,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30\n"
 -"     .equ    __reg_num_x\\num, \\num\n"
 +"     .equ    .L__reg_num_x\\num, \\num\n"
  "     .endr\n"
 -"     .equ    __reg_num_xzr, 31\n"
 +"     .equ    .L__reg_num_xzr, 31\n"
  "\n"
  "     .macro  mrs_s, rt, sreg\n"
 -"     .inst   0xd5200000|(\\sreg)|(__reg_num_\\rt)\n"
 +"     .inst   0xd5200000|(\\sreg)|(.L__reg_num_\\rt)\n"
  "     .endm\n"
  "\n"
  "     .macro  msr_s, sreg, rt\n"
index 69b15d97fb83b1b853b32407a97ad0e8ec37ce37,ee2ffacdaa44eef0c47b7d0cd2ec16845a5c28a9..20bcc2db06bfab77cc0793af96b7ce051d321e10
@@@ -41,8 -40,9 +41,10 @@@ arm64-obj-$(CONFIG_EFI)                      += efi.o efi-
  arm64-obj-$(CONFIG_PCI)                       += pci.o
  arm64-obj-$(CONFIG_ARMV8_DEPRECATED)  += armv8_deprecated.o
  arm64-obj-$(CONFIG_ACPI)              += acpi.o
- arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL)       += acpi_parking_protocol.o
 +arm64-obj-$(CONFIG_RANDOMIZE_BASE)    += kaslr.o
+ arm64-obj-$(CONFIG_HIBERNATION)               += hibernate.o hibernate-asm.o
+ arm64-obj-$(CONFIG_ARM64_ACPI_PARKING_PROTOCOL)       += acpi_parking_protocol.o
+ arm64-obj-$(CONFIG_PARAVIRT)          += paravirt.o
  
  obj-y                                 += $(arm64-obj-y) vdso/ probes/
  obj-m                                 += $(arm64-obj-m)
Simple merge
index 7566cad9fa1da5a882ada85b5801a8ae33f4da0c,ab68e7c9808d1c6e7168f38749f39e543b759394..24ecbeb733ed354f24be2d11fcfb9eba3ddd939c
@@@ -634,18 -622,11 +635,23 @@@ static bool has_useable_gicv3_cpuif(con
        return has_sre;
  }
  
 +static bool has_no_hw_prefetch(const struct arm64_cpu_capabilities *entry)
 +{
 +      u32 midr = read_cpuid_id();
 +      u32 rv_min, rv_max;
 +
 +      /* Cavium ThunderX pass 1.x and 2.x */
 +      rv_min = 0;
 +      rv_max = (1 << MIDR_VARIANT_SHIFT) | MIDR_REVISION_MASK;
 +
 +      return MIDR_IS_CPU_MODEL_RANGE(midr, MIDR_THUNDERX, rv_min, rv_max);
 +}
 +
+ static bool runs_at_el2(const struct arm64_cpu_capabilities *entry)
+ {
+       return is_kernel_in_hyp_mode();
+ }
  static const struct arm64_cpu_capabilities arm64_features[] = {
        {
                .desc = "GIC system register CPU interface",
                .min_field_value = 2,
        },
  #endif /* CONFIG_AS_LSE && CONFIG_ARM64_LSE_ATOMICS */
 +      {
 +              .desc = "Software prefetching using PRFM",
 +              .capability = ARM64_HAS_NO_HW_PREFETCH,
 +              .matches = has_no_hw_prefetch,
 +      },
 +#ifdef CONFIG_ARM64_UAO
 +      {
 +              .desc = "User Access Override",
 +              .capability = ARM64_HAS_UAO,
 +              .matches = has_cpuid_feature,
 +              .sys_reg = SYS_ID_AA64MMFR2_EL1,
 +              .field_pos = ID_AA64MMFR2_UAO_SHIFT,
 +              .min_field_value = 1,
 +              .enable = cpu_enable_uao,
 +      },
 +#endif /* CONFIG_ARM64_UAO */
 +#ifdef CONFIG_ARM64_PAN
 +      {
 +              .capability = ARM64_ALT_PAN_NOT_UAO,
 +              .matches = cpufeature_pan_not_uao,
 +      },
 +#endif /* CONFIG_ARM64_PAN */
+       {
+               .desc = "Virtualization Host Extensions",
+               .capability = ARM64_HAS_VIRT_HOST_EXTN,
+               .matches = runs_at_el2,
+       },
        {},
  };
  
index 9e4fe1b6336f02d28966981f80a4a201e32ec747,79cf6059ea503eb5f2c5d45a7a7eb63be1cb226d..029c466eaa4c68cad67da330be9024ccfbbd82b4
@@@ -666,8 -624,7 +663,8 @@@ ENDPROC(__secondary_switched
   * If it isn't, park the CPU
   */
        .section        ".idmap.text", "ax"
- __enable_mmu:
+ ENTRY(__enable_mmu)
 +      mrs     x18, sctlr_el1                  // preserve old SCTLR_EL1 value
        mrs     x1, ID_AA64MMFR0_EL1
        ubfx    x2, x1, #ID_AA64MMFR0_TGRAN_SHIFT, 4
        cmp     x2, #ID_AA64MMFR0_TGRAN_SUPPORTED
Simple merge
index e33fe33876ab3804f2c6dcd6c5458e576596ef24,b7d8f814caaf4bee06b39e8f35902adaa9c6cabc..c2bf5a58039f1b7f749912bc18f58bf5007e80fb
@@@ -166,20 -117,24 +117,27 @@@ ENTRY(_cpu_resume
        ldp     w5, w6, [x8, #(MPIDR_HASH_SHIFTS + 8)]
        compute_mpidr_hash x7, x3, x4, x5, x6, x1, x2
          /* x7 contains hash index, let's use it to grab context pointer */
-       ldr_l   x0, sleep_save_sp + SLEEP_SAVE_SP_PHYS
+       ldr_l   x0, sleep_save_stash
        ldr     x0, [x0, x7, lsl #3]
+       add     x29, x0, #SLEEP_STACK_DATA_CALLEE_REGS
+       add     x0, x0, #SLEEP_STACK_DATA_SYSTEM_REGS
        /* load sp from context */
        ldr     x2, [x0, #CPU_CTX_SP]
-       /* load physical address of identity map page table in x1 */
-       adrp    x1, idmap_pg_dir
        mov     sp, x2
 +      /* save thread_info */
 +      and     x2, x2, #~(THREAD_SIZE - 1)
 +      msr     sp_el0, x2
        /*
-        * cpu_do_resume expects x0 to contain context physical address
-        * pointer and x1 to contain physical address of 1:1 page tables
+        * cpu_do_resume expects x0 to contain context address pointer
         */
-       bl      cpu_do_resume           // PC relative jump, MMU off
-       b       cpu_resume_mmu          // Resume MMU, never returns
- ENDPROC(cpu_resume)
+       bl      cpu_do_resume
+       ldp     x19, x20, [x29, #16]
+       ldp     x21, x22, [x29, #32]
+       ldp     x23, x24, [x29, #48]
+       ldp     x25, x26, [x29, #64]
+       ldp     x27, x28, [x29, #80]
+       ldp     x29, lr, [x29]
+       mov     x0, #0
+       ret
+ ENDPROC(_cpu_resume)
Simple merge
index 309e3479dc2c48fb47ca28a44b81e9d06b73e7bf,0689a74e6ba0b493ffc669448e34b34579c9f5ec..48f19a37b3df552a08db7b186a65ae4fad4b32e4
  #include <linux/linkage.h>
  
  #include <asm/alternative.h>
- #include <asm/asm-offsets.h>
  #include <asm/assembler.h>
  #include <asm/cpufeature.h>
- #include <asm/debug-monitors.h>
- #include <asm/esr.h>
- #include <asm/fpsimdmacros.h>
- #include <asm/kvm.h>
- #include <asm/kvm_arm.h>
- #include <asm/kvm_asm.h>
- #include <asm/kvm_mmu.h>
- #include <asm/memory.h>
- #define CPU_GP_REG_OFFSET(x)  (CPU_GP_REGS + x)
- #define CPU_XREG_OFFSET(x)    CPU_GP_REG_OFFSET(CPU_USER_PT_REGS + 8*x)
- #define CPU_SPSR_OFFSET(x)    CPU_GP_REG_OFFSET(CPU_SPSR + 8*x)
- #define CPU_SYSREG_OFFSET(x)  (CPU_SYSREGS + 8*x)
-       .text
-       .pushsection    .hyp.text, "ax"
-       .align  PAGE_SHIFT
- .macro save_common_regs
-       // x2: base address for cpu context
-       // x3: tmp register
-       add     x3, x2, #CPU_XREG_OFFSET(19)
-       stp     x19, x20, [x3]
-       stp     x21, x22, [x3, #16]
-       stp     x23, x24, [x3, #32]
-       stp     x25, x26, [x3, #48]
-       stp     x27, x28, [x3, #64]
-       stp     x29, lr, [x3, #80]
-       mrs     x19, sp_el0
-       mrs     x20, elr_el2            // pc before entering el2
-       mrs     x21, spsr_el2           // pstate before entering el2
-       stp     x19, x20, [x3, #96]
-       str     x21, [x3, #112]
-       mrs     x22, sp_el1
-       mrs     x23, elr_el1
-       mrs     x24, spsr_el1
-       str     x22, [x2, #CPU_GP_REG_OFFSET(CPU_SP_EL1)]
-       str     x23, [x2, #CPU_GP_REG_OFFSET(CPU_ELR_EL1)]
-       str     x24, [x2, #CPU_SPSR_OFFSET(KVM_SPSR_EL1)]
- .endm
- .macro restore_common_regs
-       // x2: base address for cpu context
-       // x3: tmp register
-       ldr     x22, [x2, #CPU_GP_REG_OFFSET(CPU_SP_EL1)]
-       ldr     x23, [x2, #CPU_GP_REG_OFFSET(CPU_ELR_EL1)]
-       ldr     x24, [x2, #CPU_SPSR_OFFSET(KVM_SPSR_EL1)]
-       msr     sp_el1, x22
-       msr     elr_el1, x23
-       msr     spsr_el1, x24
-       add     x3, x2, #CPU_XREG_OFFSET(31)    // SP_EL0
-       ldp     x19, x20, [x3]
-       ldr     x21, [x3, #16]
-       msr     sp_el0, x19
-       msr     elr_el2, x20            // pc on return from el2
-       msr     spsr_el2, x21           // pstate on return from el2
-       add     x3, x2, #CPU_XREG_OFFSET(19)
-       ldp     x19, x20, [x3]
-       ldp     x21, x22, [x3, #16]
-       ldp     x23, x24, [x3, #32]
-       ldp     x25, x26, [x3, #48]
-       ldp     x27, x28, [x3, #64]
-       ldp     x29, lr, [x3, #80]
- .endm
- .macro save_host_regs
-       save_common_regs
- .endm
- .macro restore_host_regs
-       restore_common_regs
- .endm
- .macro save_fpsimd
-       // x2: cpu context address
-       // x3, x4: tmp regs
-       add     x3, x2, #CPU_GP_REG_OFFSET(CPU_FP_REGS)
-       fpsimd_save x3, 4
- .endm
- .macro restore_fpsimd
-       // x2: cpu context address
-       // x3, x4: tmp regs
-       add     x3, x2, #CPU_GP_REG_OFFSET(CPU_FP_REGS)
-       fpsimd_restore x3, 4
- .endm
- .macro save_guest_regs
-       // x0 is the vcpu address
-       // x1 is the return code, do not corrupt!
-       // x2 is the cpu context
-       // x3 is a tmp register
-       // Guest's x0-x3 are on the stack
-       // Compute base to save registers
-       add     x3, x2, #CPU_XREG_OFFSET(4)
-       stp     x4, x5, [x3]
-       stp     x6, x7, [x3, #16]
-       stp     x8, x9, [x3, #32]
-       stp     x10, x11, [x3, #48]
-       stp     x12, x13, [x3, #64]
-       stp     x14, x15, [x3, #80]
-       stp     x16, x17, [x3, #96]
-       str     x18, [x3, #112]
-       pop     x6, x7                  // x2, x3
-       pop     x4, x5                  // x0, x1
-       add     x3, x2, #CPU_XREG_OFFSET(0)
-       stp     x4, x5, [x3]
-       stp     x6, x7, [x3, #16]
-       save_common_regs
- .endm
- .macro restore_guest_regs
-       // x0 is the vcpu address.
-       // x2 is the cpu context
-       // x3 is a tmp register
-       // Prepare x0-x3 for later restore
-       add     x3, x2, #CPU_XREG_OFFSET(0)
-       ldp     x4, x5, [x3]
-       ldp     x6, x7, [x3, #16]
-       push    x4, x5          // Push x0-x3 on the stack
-       push    x6, x7
-       // x4-x18
-       ldp     x4, x5, [x3, #32]
-       ldp     x6, x7, [x3, #48]
-       ldp     x8, x9, [x3, #64]
-       ldp     x10, x11, [x3, #80]
-       ldp     x12, x13, [x3, #96]
-       ldp     x14, x15, [x3, #112]
-       ldp     x16, x17, [x3, #128]
-       ldr     x18, [x3, #144]
-       // x19-x29, lr, sp*, elr*, spsr*
-       restore_common_regs
-       // Last bits of the 64bit state
-       pop     x2, x3
-       pop     x0, x1
-       // Do not touch any register after this!
- .endm
- /*
-  * Macros to perform system register save/restore.
-  *
-  * Ordering here is absolutely critical, and must be kept consistent
-  * in {save,restore}_sysregs, {save,restore}_guest_32bit_state,
-  * and in kvm_asm.h.
-  *
-  * In other words, don't touch any of these unless you know what
-  * you are doing.
-  */
- .macro save_sysregs
-       // x2: base address for cpu context
-       // x3: tmp register
-       add     x3, x2, #CPU_SYSREG_OFFSET(MPIDR_EL1)
-       mrs     x4,     vmpidr_el2
-       mrs     x5,     csselr_el1
-       mrs     x6,     sctlr_el1
-       mrs     x7,     actlr_el1
-       mrs     x8,     cpacr_el1
-       mrs     x9,     ttbr0_el1
-       mrs     x10,    ttbr1_el1
-       mrs     x11,    tcr_el1
-       mrs     x12,    esr_el1
-       mrs     x13,    afsr0_el1
-       mrs     x14,    afsr1_el1
-       mrs     x15,    far_el1
-       mrs     x16,    mair_el1
-       mrs     x17,    vbar_el1
-       mrs     x18,    contextidr_el1
-       mrs     x19,    tpidr_el0
-       mrs     x20,    tpidrro_el0
-       mrs     x21,    tpidr_el1
-       mrs     x22,    amair_el1
-       mrs     x23,    cntkctl_el1
-       mrs     x24,    par_el1
-       mrs     x25,    mdscr_el1
-       stp     x4, x5, [x3]
-       stp     x6, x7, [x3, #16]
-       stp     x8, x9, [x3, #32]
-       stp     x10, x11, [x3, #48]
-       stp     x12, x13, [x3, #64]
-       stp     x14, x15, [x3, #80]
-       stp     x16, x17, [x3, #96]
-       stp     x18, x19, [x3, #112]
-       stp     x20, x21, [x3, #128]
-       stp     x22, x23, [x3, #144]
-       stp     x24, x25, [x3, #160]
- .endm
- .macro save_debug type
-       // x4: pointer to register set
-       // x5: number of registers to skip
-       // x6..x22 trashed
-       adr     x22, 1f
-       add     x22, x22, x5, lsl #2
-       br      x22
- 1:
-       mrs     x21, \type\()15_el1
-       mrs     x20, \type\()14_el1
-       mrs     x19, \type\()13_el1
-       mrs     x18, \type\()12_el1
-       mrs     x17, \type\()11_el1
-       mrs     x16, \type\()10_el1
-       mrs     x15, \type\()9_el1
-       mrs     x14, \type\()8_el1
-       mrs     x13, \type\()7_el1
-       mrs     x12, \type\()6_el1
-       mrs     x11, \type\()5_el1
-       mrs     x10, \type\()4_el1
-       mrs     x9, \type\()3_el1
-       mrs     x8, \type\()2_el1
-       mrs     x7, \type\()1_el1
-       mrs     x6, \type\()0_el1
-       adr     x22, 1f
-       add     x22, x22, x5, lsl #2
-       br      x22
- 1:
-       str     x21, [x4, #(15 * 8)]
-       str     x20, [x4, #(14 * 8)]
-       str     x19, [x4, #(13 * 8)]
-       str     x18, [x4, #(12 * 8)]
-       str     x17, [x4, #(11 * 8)]
-       str     x16, [x4, #(10 * 8)]
-       str     x15, [x4, #(9 * 8)]
-       str     x14, [x4, #(8 * 8)]
-       str     x13, [x4, #(7 * 8)]
-       str     x12, [x4, #(6 * 8)]
-       str     x11, [x4, #(5 * 8)]
-       str     x10, [x4, #(4 * 8)]
-       str     x9, [x4, #(3 * 8)]
-       str     x8, [x4, #(2 * 8)]
-       str     x7, [x4, #(1 * 8)]
-       str     x6, [x4, #(0 * 8)]
- .endm
- .macro restore_sysregs
-       // x2: base address for cpu context
-       // x3: tmp register
-       add     x3, x2, #CPU_SYSREG_OFFSET(MPIDR_EL1)
-       ldp     x4, x5, [x3]
-       ldp     x6, x7, [x3, #16]
-       ldp     x8, x9, [x3, #32]
-       ldp     x10, x11, [x3, #48]
-       ldp     x12, x13, [x3, #64]
-       ldp     x14, x15, [x3, #80]
-       ldp     x16, x17, [x3, #96]
-       ldp     x18, x19, [x3, #112]
-       ldp     x20, x21, [x3, #128]
-       ldp     x22, x23, [x3, #144]
-       ldp     x24, x25, [x3, #160]
-       msr     vmpidr_el2,     x4
-       msr     csselr_el1,     x5
-       msr     sctlr_el1,      x6
-       msr     actlr_el1,      x7
-       msr     cpacr_el1,      x8
-       msr     ttbr0_el1,      x9
-       msr     ttbr1_el1,      x10
-       msr     tcr_el1,        x11
-       msr     esr_el1,        x12
-       msr     afsr0_el1,      x13
-       msr     afsr1_el1,      x14
-       msr     far_el1,        x15
-       msr     mair_el1,       x16
-       msr     vbar_el1,       x17
-       msr     contextidr_el1, x18
-       msr     tpidr_el0,      x19
-       msr     tpidrro_el0,    x20
-       msr     tpidr_el1,      x21
-       msr     amair_el1,      x22
-       msr     cntkctl_el1,    x23
-       msr     par_el1,        x24
-       msr     mdscr_el1,      x25
- .endm
- .macro restore_debug type
-       // x4: pointer to register set
-       // x5: number of registers to skip
-       // x6..x22 trashed
-       adr     x22, 1f
-       add     x22, x22, x5, lsl #2
-       br      x22
- 1:
-       ldr     x21, [x4, #(15 * 8)]
-       ldr     x20, [x4, #(14 * 8)]
-       ldr     x19, [x4, #(13 * 8)]
-       ldr     x18, [x4, #(12 * 8)]
-       ldr     x17, [x4, #(11 * 8)]
-       ldr     x16, [x4, #(10 * 8)]
-       ldr     x15, [x4, #(9 * 8)]
-       ldr     x14, [x4, #(8 * 8)]
-       ldr     x13, [x4, #(7 * 8)]
-       ldr     x12, [x4, #(6 * 8)]
-       ldr     x11, [x4, #(5 * 8)]
-       ldr     x10, [x4, #(4 * 8)]
-       ldr     x9, [x4, #(3 * 8)]
-       ldr     x8, [x4, #(2 * 8)]
-       ldr     x7, [x4, #(1 * 8)]
-       ldr     x6, [x4, #(0 * 8)]
-       adr     x22, 1f
-       add     x22, x22, x5, lsl #2
-       br      x22
- 1:
-       msr     \type\()15_el1, x21
-       msr     \type\()14_el1, x20
-       msr     \type\()13_el1, x19
-       msr     \type\()12_el1, x18
-       msr     \type\()11_el1, x17
-       msr     \type\()10_el1, x16
-       msr     \type\()9_el1, x15
-       msr     \type\()8_el1, x14
-       msr     \type\()7_el1, x13
-       msr     \type\()6_el1, x12
-       msr     \type\()5_el1, x11
-       msr     \type\()4_el1, x10
-       msr     \type\()3_el1, x9
-       msr     \type\()2_el1, x8
-       msr     \type\()1_el1, x7
-       msr     \type\()0_el1, x6
- .endm
- .macro skip_32bit_state tmp, target
-       // Skip 32bit state if not needed
-       mrs     \tmp, hcr_el2
-       tbnz    \tmp, #HCR_RW_SHIFT, \target
- .endm
- .macro skip_tee_state tmp, target
-       // Skip ThumbEE state if not needed
-       mrs     \tmp, id_pfr0_el1
-       tbz     \tmp, #12, \target
- .endm
- .macro skip_debug_state tmp, target
-       ldr     \tmp, [x0, #VCPU_DEBUG_FLAGS]
-       tbz     \tmp, #KVM_ARM64_DEBUG_DIRTY_SHIFT, \target
- .endm
- /*
-  * Branch to target if CPTR_EL2.TFP bit is set (VFP/SIMD trapping enabled)
-  */
- .macro skip_fpsimd_state tmp, target
-       mrs     \tmp, cptr_el2
-       tbnz    \tmp, #CPTR_EL2_TFP_SHIFT, \target
- .endm
- .macro compute_debug_state target
-       // Compute debug state: If any of KDE, MDE or KVM_ARM64_DEBUG_DIRTY
-       // is set, we do a full save/restore cycle and disable trapping.
-       add     x25, x0, #VCPU_CONTEXT
-       // Check the state of MDSCR_EL1
-       ldr     x25, [x25, #CPU_SYSREG_OFFSET(MDSCR_EL1)]
-       and     x26, x25, #DBG_MDSCR_KDE
-       and     x25, x25, #DBG_MDSCR_MDE
-       adds    xzr, x25, x26
-       b.eq    9998f           // Nothing to see there
-       // If any interesting bits was set, we must set the flag
-       mov     x26, #KVM_ARM64_DEBUG_DIRTY
-       str     x26, [x0, #VCPU_DEBUG_FLAGS]
-       b       9999f           // Don't skip restore
- 9998:
-       // Otherwise load the flags from memory in case we recently
-       // trapped
-       skip_debug_state x25, \target
- 9999:
- .endm
- .macro save_guest_32bit_state
-       skip_32bit_state x3, 1f
-       add     x3, x2, #CPU_SPSR_OFFSET(KVM_SPSR_ABT)
-       mrs     x4, spsr_abt
-       mrs     x5, spsr_und
-       mrs     x6, spsr_irq
-       mrs     x7, spsr_fiq
-       stp     x4, x5, [x3]
-       stp     x6, x7, [x3, #16]
-       add     x3, x2, #CPU_SYSREG_OFFSET(DACR32_EL2)
-       mrs     x4, dacr32_el2
-       mrs     x5, ifsr32_el2
-       stp     x4, x5, [x3]
-       skip_fpsimd_state x8, 2f
-       mrs     x6, fpexc32_el2
-       str     x6, [x3, #16]
- 2:
-       skip_debug_state x8, 1f
-       mrs     x7, dbgvcr32_el2
-       str     x7, [x3, #24]
- 1:
- .endm
- .macro restore_guest_32bit_state
-       skip_32bit_state x3, 1f
-       add     x3, x2, #CPU_SPSR_OFFSET(KVM_SPSR_ABT)
-       ldp     x4, x5, [x3]
-       ldp     x6, x7, [x3, #16]
-       msr     spsr_abt, x4
-       msr     spsr_und, x5
-       msr     spsr_irq, x6
-       msr     spsr_fiq, x7
-       add     x3, x2, #CPU_SYSREG_OFFSET(DACR32_EL2)
-       ldp     x4, x5, [x3]
-       msr     dacr32_el2, x4
-       msr     ifsr32_el2, x5
-       skip_debug_state x8, 1f
-       ldr     x7, [x3, #24]
-       msr     dbgvcr32_el2, x7
- 1:
- .endm
- .macro activate_traps
-       ldr     x2, [x0, #VCPU_HCR_EL2]
-       /*
-        * We are about to set CPTR_EL2.TFP to trap all floating point
-        * register accesses to EL2, however, the ARM ARM clearly states that
-        * traps are only taken to EL2 if the operation would not otherwise
-        * trap to EL1.  Therefore, always make sure that for 32-bit guests,
-        * we set FPEXC.EN to prevent traps to EL1, when setting the TFP bit.
-        */
-       tbnz    x2, #HCR_RW_SHIFT, 99f // open code skip_32bit_state
-       mov     x3, #(1 << 30)
-       msr     fpexc32_el2, x3
-       isb
- 99:
-       msr     hcr_el2, x2
-       mov     x2, #CPTR_EL2_TTA
-       orr     x2, x2, #CPTR_EL2_TFP
-       msr     cptr_el2, x2
-       mov     x2, #(1 << 15)  // Trap CP15 Cr=15
-       msr     hstr_el2, x2
-       // Monitor Debug Config - see kvm_arm_setup_debug()
-       ldr     x2, [x0, #VCPU_MDCR_EL2]
-       msr     mdcr_el2, x2
- .endm
- .macro deactivate_traps
-       mov     x2, #HCR_RW
-       msr     hcr_el2, x2
-       msr     hstr_el2, xzr
-       mrs     x2, mdcr_el2
-       and     x2, x2, #MDCR_EL2_HPMN_MASK
-       msr     mdcr_el2, x2
- .endm
- .macro activate_vm
-       ldr     x1, [x0, #VCPU_KVM]
-       kern_hyp_va     x1
-       ldr     x2, [x1, #KVM_VTTBR]
-       msr     vttbr_el2, x2
- .endm
- .macro deactivate_vm
-       msr     vttbr_el2, xzr
- .endm
- /*
-  * Call into the vgic backend for state saving
-  */
- .macro save_vgic_state
- alternative_if_not ARM64_HAS_SYSREG_GIC_CPUIF
-       bl      __save_vgic_v2_state
- alternative_else
-       bl      __save_vgic_v3_state
- alternative_endif
-       mrs     x24, hcr_el2
-       mov     x25, #HCR_INT_OVERRIDE
-       neg     x25, x25
-       and     x24, x24, x25
-       msr     hcr_el2, x24
- .endm
- /*
-  * Call into the vgic backend for state restoring
-  */
- .macro restore_vgic_state
-       mrs     x24, hcr_el2
-       ldr     x25, [x0, #VCPU_IRQ_LINES]
-       orr     x24, x24, #HCR_INT_OVERRIDE
-       orr     x24, x24, x25
-       msr     hcr_el2, x24
- alternative_if_not ARM64_HAS_SYSREG_GIC_CPUIF
-       bl      __restore_vgic_v2_state
- alternative_else
-       bl      __restore_vgic_v3_state
- alternative_endif
- .endm
- .macro save_timer_state
-       // x0: vcpu pointer
-       ldr     x2, [x0, #VCPU_KVM]
-       kern_hyp_va x2
-       ldr     w3, [x2, #KVM_TIMER_ENABLED]
-       cbz     w3, 1f
-       mrs     x3, cntv_ctl_el0
-       and     x3, x3, #3
-       str     w3, [x0, #VCPU_TIMER_CNTV_CTL]
-       isb
-       mrs     x3, cntv_cval_el0
-       str     x3, [x0, #VCPU_TIMER_CNTV_CVAL]
- 1:
-       // Disable the virtual timer
-       msr     cntv_ctl_el0, xzr
-       // Allow physical timer/counter access for the host
-       mrs     x2, cnthctl_el2
-       orr     x2, x2, #3
-       msr     cnthctl_el2, x2
-       // Clear cntvoff for the host
-       msr     cntvoff_el2, xzr
- .endm
- .macro restore_timer_state
-       // x0: vcpu pointer
-       // Disallow physical timer access for the guest
-       // Physical counter access is allowed
-       mrs     x2, cnthctl_el2
-       orr     x2, x2, #1
-       bic     x2, x2, #2
-       msr     cnthctl_el2, x2
-       ldr     x2, [x0, #VCPU_KVM]
-       kern_hyp_va x2
-       ldr     w3, [x2, #KVM_TIMER_ENABLED]
-       cbz     w3, 1f
-       ldr     x3, [x2, #KVM_TIMER_CNTVOFF]
-       msr     cntvoff_el2, x3
-       ldr     x2, [x0, #VCPU_TIMER_CNTV_CVAL]
-       msr     cntv_cval_el0, x2
-       isb
-       ldr     w2, [x0, #VCPU_TIMER_CNTV_CTL]
-       and     x2, x2, #3
-       msr     cntv_ctl_el0, x2
- 1:
- .endm
- __save_sysregs:
-       save_sysregs
-       ret
- __restore_sysregs:
-       restore_sysregs
-       ret
- /* Save debug state */
- __save_debug:
-       // x2: ptr to CPU context
-       // x3: ptr to debug reg struct
-       // x4/x5/x6-22/x24-26: trashed
-       mrs     x26, id_aa64dfr0_el1
-       ubfx    x24, x26, #12, #4       // Extract BRPs
-       ubfx    x25, x26, #20, #4       // Extract WRPs
-       mov     w26, #15
-       sub     w24, w26, w24           // How many BPs to skip
-       sub     w25, w26, w25           // How many WPs to skip
-       mov     x5, x24
-       add     x4, x3, #DEBUG_BCR
-       save_debug dbgbcr
-       add     x4, x3, #DEBUG_BVR
-       save_debug dbgbvr
-       mov     x5, x25
-       add     x4, x3, #DEBUG_WCR
-       save_debug dbgwcr
-       add     x4, x3, #DEBUG_WVR
-       save_debug dbgwvr
-       mrs     x21, mdccint_el1
-       str     x21, [x2, #CPU_SYSREG_OFFSET(MDCCINT_EL1)]
-       ret
- /* Restore debug state */
- __restore_debug:
-       // x2: ptr to CPU context
-       // x3: ptr to debug reg struct
-       // x4/x5/x6-22/x24-26: trashed
-       mrs     x26, id_aa64dfr0_el1
-       ubfx    x24, x26, #12, #4       // Extract BRPs
-       ubfx    x25, x26, #20, #4       // Extract WRPs
-       mov     w26, #15
-       sub     w24, w26, w24           // How many BPs to skip
-       sub     w25, w26, w25           // How many WPs to skip
-       mov     x5, x24
-       add     x4, x3, #DEBUG_BCR
-       restore_debug dbgbcr
-       add     x4, x3, #DEBUG_BVR
-       restore_debug dbgbvr
-       mov     x5, x25
-       add     x4, x3, #DEBUG_WCR
-       restore_debug dbgwcr
-       add     x4, x3, #DEBUG_WVR
-       restore_debug dbgwvr
-       ldr     x21, [x2, #CPU_SYSREG_OFFSET(MDCCINT_EL1)]
-       msr     mdccint_el1, x21
-       ret
- __save_fpsimd:
-       skip_fpsimd_state x3, 1f
-       save_fpsimd
- 1:    ret
- __restore_fpsimd:
-       skip_fpsimd_state x3, 1f
-       restore_fpsimd
- 1:    ret
- switch_to_guest_fpsimd:
-       push    x4, lr
-       mrs     x2, cptr_el2
-       bic     x2, x2, #CPTR_EL2_TFP
-       msr     cptr_el2, x2
-       isb
-       mrs     x0, tpidr_el2
-       ldr     x2, [x0, #VCPU_HOST_CONTEXT]
-       kern_hyp_va x2
-       bl __save_fpsimd
-       add     x2, x0, #VCPU_CONTEXT
-       bl __restore_fpsimd
-       skip_32bit_state x3, 1f
-       ldr     x4, [x2, #CPU_SYSREG_OFFSET(FPEXC32_EL2)]
-       msr     fpexc32_el2, x4
- 1:
-       pop     x4, lr
-       pop     x2, x3
-       pop     x0, x1
-       eret
- /*
-  * u64 __kvm_vcpu_run(struct kvm_vcpu *vcpu);
-  *
-  * This is the world switch. The first half of the function
-  * deals with entering the guest, and anything from __kvm_vcpu_return
-  * to the end of the function deals with reentering the host.
-  * On the enter path, only x0 (vcpu pointer) must be preserved until
-  * the last moment. On the exit path, x0 (vcpu pointer) and x1 (exception
-  * code) must both be preserved until the epilogue.
-  * In both cases, x2 points to the CPU context we're saving/restoring from/to.
-  */
- ENTRY(__kvm_vcpu_run)
-       kern_hyp_va     x0
-       msr     tpidr_el2, x0   // Save the vcpu register
-       // Host context
-       ldr     x2, [x0, #VCPU_HOST_CONTEXT]
-       kern_hyp_va x2
-       save_host_regs
-       bl __save_sysregs
-       compute_debug_state 1f
-       add     x3, x0, #VCPU_HOST_DEBUG_STATE
-       bl      __save_debug
- 1:
-       activate_traps
-       activate_vm
-       restore_vgic_state
-       restore_timer_state
-       // Guest context
-       add     x2, x0, #VCPU_CONTEXT
-       // We must restore the 32-bit state before the sysregs, thanks
-       // to Cortex-A57 erratum #852523.
-       restore_guest_32bit_state
-       bl __restore_sysregs
-       skip_debug_state x3, 1f
-       ldr     x3, [x0, #VCPU_DEBUG_PTR]
-       kern_hyp_va x3
-       bl      __restore_debug
- 1:
-       restore_guest_regs
-       // That's it, no more messing around.
-       eret
- __kvm_vcpu_return:
-       // Assume x0 is the vcpu pointer, x1 the return code
-       // Guest's x0-x3 are on the stack
-       // Guest context
-       add     x2, x0, #VCPU_CONTEXT
-       save_guest_regs
-       bl __save_fpsimd
-       bl __save_sysregs
-       skip_debug_state x3, 1f
-       ldr     x3, [x0, #VCPU_DEBUG_PTR]
-       kern_hyp_va x3
-       bl      __save_debug
- 1:
-       save_guest_32bit_state
-       save_timer_state
-       save_vgic_state
-       deactivate_traps
-       deactivate_vm
-       // Host context
-       ldr     x2, [x0, #VCPU_HOST_CONTEXT]
-       kern_hyp_va x2
-       bl __restore_sysregs
-       bl __restore_fpsimd
-       /* Clear FPSIMD and Trace trapping */
-       msr     cptr_el2, xzr
-       skip_debug_state x3, 1f
-       // Clear the dirty flag for the next run, as all the state has
-       // already been saved. Note that we nuke the whole 64bit word.
-       // If we ever add more flags, we'll have to be more careful...
-       str     xzr, [x0, #VCPU_DEBUG_FLAGS]
-       add     x3, x0, #VCPU_HOST_DEBUG_STATE
-       bl      __restore_debug
- 1:
-       restore_host_regs
-       mov     x0, x1
-       ret
- END(__kvm_vcpu_run)
- // void __kvm_tlb_flush_vmid_ipa(struct kvm *kvm, phys_addr_t ipa);
- ENTRY(__kvm_tlb_flush_vmid_ipa)
-       dsb     ishst
-       kern_hyp_va     x0
-       ldr     x2, [x0, #KVM_VTTBR]
-       msr     vttbr_el2, x2
-       isb
-       /*
-        * We could do so much better if we had the VA as well.
-        * Instead, we invalidate Stage-2 for this IPA, and the
-        * whole of Stage-1. Weep...
-        */
-       lsr     x1, x1, #12
-       tlbi    ipas2e1is, x1
-       /*
-        * We have to ensure completion of the invalidation at Stage-2,
-        * since a table walk on another CPU could refill a TLB with a
-        * complete (S1 + S2) walk based on the old Stage-2 mapping if
-        * the Stage-1 invalidation happened first.
-        */
-       dsb     ish
-       tlbi    vmalle1is
-       dsb     ish
-       isb
-       msr     vttbr_el2, xzr
-       ret
- ENDPROC(__kvm_tlb_flush_vmid_ipa)
- /**
-  * void __kvm_tlb_flush_vmid(struct kvm *kvm) - Flush per-VMID TLBs
-  * @struct kvm *kvm - pointer to kvm structure
-  *
-  * Invalidates all Stage 1 and 2 TLB entries for current VMID.
-  */
- ENTRY(__kvm_tlb_flush_vmid)
-       dsb     ishst
-       kern_hyp_va     x0
-       ldr     x2, [x0, #KVM_VTTBR]
-       msr     vttbr_el2, x2
-       isb
-       tlbi    vmalls12e1is
-       dsb     ish
-       isb
-       msr     vttbr_el2, xzr
-       ret
- ENDPROC(__kvm_tlb_flush_vmid)
- ENTRY(__kvm_flush_vm_context)
-       dsb     ishst
-       tlbi    alle1is
-       ic      ialluis
-       dsb     ish
-       ret
- ENDPROC(__kvm_flush_vm_context)
- __kvm_hyp_panic:
-       // Stash PAR_EL1 before corrupting it in __restore_sysregs
-       mrs     x0, par_el1
-       push    x0, xzr
-       // Guess the context by looking at VTTBR:
-       // If zero, then we're already a host.
-       // Otherwise restore a minimal host context before panicing.
-       mrs     x0, vttbr_el2
-       cbz     x0, 1f
-       mrs     x0, tpidr_el2
-       deactivate_traps
-       deactivate_vm
-       ldr     x2, [x0, #VCPU_HOST_CONTEXT]
-       kern_hyp_va x2
-       bl __restore_sysregs
-       /*
-        * Make sure we have a valid host stack, and don't leave junk in the
-        * frame pointer that will give us a misleading host stack unwinding.
-        */
-       ldr     x22, [x2, #CPU_GP_REG_OFFSET(CPU_SP_EL1)]
-       msr     sp_el1, x22
-       mov     x29, xzr
- 1:    adr     x0, __hyp_panic_str
-       adr     x1, 2f
-       ldp     x2, x3, [x1]
-       sub     x0, x0, x2
-       add     x0, x0, x3
-       mrs     x1, spsr_el2
-       mrs     x2, elr_el2
-       mrs     x3, esr_el2
-       mrs     x4, far_el2
-       mrs     x5, hpfar_el2
-       pop     x6, xzr         // active context PAR_EL1
-       mrs     x7, tpidr_el2
-       mov     lr, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT |\
-                     PSR_MODE_EL1h)
-       msr     spsr_el2, lr
-       ldr     lr, =panic
-       msr     elr_el2, lr
-       eret
-       .align  3
- 2:    .quad   HYP_PAGE_OFFSET
-       .quad   PAGE_OFFSET
- ENDPROC(__kvm_hyp_panic)
- __hyp_panic_str:
-       .ascii  "HYP panic:\nPS:%08x PC:%016x ESR:%08x\nFAR:%016x HPFAR:%016x PAR:%016x\nVCPU:%p\n\0"
-       .align  2
  
  /*
 - * u64 kvm_call_hyp(void *hypfn, ...);
 + * u64 __kvm_call_hyp(void *hypfn, ...);
   *
   * This is not really a variadic function in the classic C-way and care must
   * be taken when calling this to ensure parameters are passed in registers
   * used to implement __hyp_get_vectors in the same way as in
   * arch/arm64/kernel/hyp_stub.S.
   */
 -ENTRY(kvm_call_hyp)
 +ENTRY(__kvm_call_hyp)
+ alternative_if_not ARM64_HAS_VIRT_HOST_EXTN   
        hvc     #0
        ret
- ENDPROC(__kvm_call_hyp)
- .macro invalid_vector label, target
-       .align  2
- \label:
-       b \target
- ENDPROC(\label)
- .endm
-       /* None of these should ever happen */
-       invalid_vector  el2t_sync_invalid, __kvm_hyp_panic
-       invalid_vector  el2t_irq_invalid, __kvm_hyp_panic
-       invalid_vector  el2t_fiq_invalid, __kvm_hyp_panic
-       invalid_vector  el2t_error_invalid, __kvm_hyp_panic
-       invalid_vector  el2h_sync_invalid, __kvm_hyp_panic
-       invalid_vector  el2h_irq_invalid, __kvm_hyp_panic
-       invalid_vector  el2h_fiq_invalid, __kvm_hyp_panic
-       invalid_vector  el2h_error_invalid, __kvm_hyp_panic
-       invalid_vector  el1_sync_invalid, __kvm_hyp_panic
-       invalid_vector  el1_irq_invalid, __kvm_hyp_panic
-       invalid_vector  el1_fiq_invalid, __kvm_hyp_panic
-       invalid_vector  el1_error_invalid, __kvm_hyp_panic
- el1_sync:                                     // Guest trapped into EL2
-       push    x0, x1
-       push    x2, x3
-       mrs     x1, esr_el2
-       lsr     x2, x1, #ESR_ELx_EC_SHIFT
-       cmp     x2, #ESR_ELx_EC_HVC64
-       b.ne    el1_trap
-       mrs     x3, vttbr_el2                   // If vttbr is valid, the 64bit guest
-       cbnz    x3, el1_trap                    // called HVC
-       /* Here, we're pretty sure the host called HVC. */
-       pop     x2, x3
-       pop     x0, x1
-       /* Check for __hyp_get_vectors */
-       cbnz    x0, 1f
-       mrs     x0, vbar_el2
-       b       2f
- 1:    push    lr, xzr
-       /*
-        * Compute the function address in EL2, and shuffle the parameters.
-        */
-       kern_hyp_va     x0
-       mov     lr, x0
-       mov     x0, x1
-       mov     x1, x2
-       mov     x2, x3
-       blr     lr
-       pop     lr, xzr
- 2:    eret
- el1_trap:
-       /*
-        * x1: ESR
-        * x2: ESR_EC
-        */
-       /* Guest accessed VFP/SIMD registers, save host, restore Guest */
-       cmp     x2, #ESR_ELx_EC_FP_ASIMD
-       b.eq    switch_to_guest_fpsimd
-       cmp     x2, #ESR_ELx_EC_DABT_LOW
-       mov     x0, #ESR_ELx_EC_IABT_LOW
-       ccmp    x2, x0, #4, ne
-       b.ne    1f              // Not an abort we care about
-       /* This is an abort. Check for permission fault */
- alternative_if_not ARM64_WORKAROUND_834220
-       and     x2, x1, #ESR_ELx_FSC_TYPE
-       cmp     x2, #FSC_PERM
-       b.ne    1f              // Not a permission fault
  alternative_else
-       nop                     // Use the permission fault path to
-       nop                     // check for a valid S1 translation,
-       nop                     // regardless of the ESR value.
+       b       __vhe_hyp_call
+       nop
  alternative_endif
-       /*
-        * Check for Stage-1 page table walk, which is guaranteed
-        * to give a valid HPFAR_EL2.
-        */
-       tbnz    x1, #7, 1f      // S1PTW is set
-       /* Preserve PAR_EL1 */
-       mrs     x3, par_el1
-       push    x3, xzr
-       /*
-        * Permission fault, HPFAR_EL2 is invalid.
-        * Resolve the IPA the hard way using the guest VA.
-        * Stage-1 translation already validated the memory access rights.
-        * As such, we can use the EL1 translation regime, and don't have
-        * to distinguish between EL0 and EL1 access.
-        */
-       mrs     x2, far_el2
-       at      s1e1r, x2
-       isb
-       /* Read result */
-       mrs     x3, par_el1
-       pop     x0, xzr                 // Restore PAR_EL1 from the stack
-       msr     par_el1, x0
-       tbnz    x3, #0, 3f              // Bail out if we failed the translation
-       ubfx    x3, x3, #12, #36        // Extract IPA
-       lsl     x3, x3, #4              // and present it like HPFAR
-       b       2f
- 1:    mrs     x3, hpfar_el2
-       mrs     x2, far_el2
- 2:    mrs     x0, tpidr_el2
-       str     w1, [x0, #VCPU_ESR_EL2]
-       str     x2, [x0, #VCPU_FAR_EL2]
-       str     x3, [x0, #VCPU_HPFAR_EL2]
-       mov     x1, #ARM_EXCEPTION_TRAP
-       b       __kvm_vcpu_return
-       /*
-        * Translation failed. Just return to the guest and
-        * let it fault again. Another CPU is probably playing
-        * behind our back.
-        */
- 3:    pop     x2, x3
-       pop     x0, x1
-       eret
- el1_irq:
-       push    x0, x1
-       push    x2, x3
-       mrs     x0, tpidr_el2
-       mov     x1, #ARM_EXCEPTION_IRQ
-       b       __kvm_vcpu_return
-       .ltorg
-       .align 11
- ENTRY(__kvm_hyp_vector)
-       ventry  el2t_sync_invalid               // Synchronous EL2t
-       ventry  el2t_irq_invalid                // IRQ EL2t
-       ventry  el2t_fiq_invalid                // FIQ EL2t
-       ventry  el2t_error_invalid              // Error EL2t
-       ventry  el2h_sync_invalid               // Synchronous EL2h
-       ventry  el2h_irq_invalid                // IRQ EL2h
-       ventry  el2h_fiq_invalid                // FIQ EL2h
-       ventry  el2h_error_invalid              // Error EL2h
-       ventry  el1_sync                        // Synchronous 64-bit EL1
-       ventry  el1_irq                         // IRQ 64-bit EL1
-       ventry  el1_fiq_invalid                 // FIQ 64-bit EL1
-       ventry  el1_error_invalid               // Error 64-bit EL1
-       ventry  el1_sync                        // Synchronous 32-bit EL1
-       ventry  el1_irq                         // IRQ 32-bit EL1
-       ventry  el1_fiq_invalid                 // FIQ 32-bit EL1
-       ventry  el1_error_invalid               // Error 32-bit EL1
- ENDPROC(__kvm_hyp_vector)
- ENTRY(__kvm_get_mdcr_el2)
-       mrs     x0, mdcr_el2
-       ret
- ENDPROC(__kvm_get_mdcr_el2)
-       .popsection
 -ENDPROC(kvm_call_hyp)
++ENDPROC(__kvm_call_hyp)