jintack

Untitled

Feb 19th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.48 KB | None | 0 0
  1. diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
  2. index 14a2e61..6c29fc0 100644
  3. --- a/arch/arm/kvm/arm.c
  4. +++ b/arch/arm/kvm/arm.c
  5. @@ -436,6 +436,8 @@ static void update_vttbr(struct kvm *kvm)
  6.                  * shareable domain to make sure all data structures are
  7.                  * clean.
  8.                  */
  9. +
  10. +               asm volatile("hvc #0x7104");
  11.                 kvm_call_hyp(__kvm_flush_vm_context);
  12.         }
  13.  
  14. @@ -562,13 +564,16 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
  15.  
  16.         ret = 1;
  17.         run->exit_reason = KVM_EXIT_UNKNOWN;
  18. +       asm volatile("hvc #0x7100");
  19.         while (ret > 0) {
  20.                 /*
  21.                  * Check conditions before entering the guest
  22.                  */
  23.                 cond_resched();
  24.  
  25. +               asm volatile("hvc #0x7101");
  26.                 update_vttbr(vcpu->kvm);
  27. +               asm volatile("hvc #0x7102");
  28.  
  29.                 if (vcpu->arch.power_off || vcpu->arch.pause)
  30.                         vcpu_sleep(vcpu);
  31. @@ -610,6 +615,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
  32.                 __kvm_guest_enter();
  33.                 vcpu->mode = IN_GUEST_MODE;
  34.  
  35. +               asm volatile("hvc #0x7103");
  36.                 ret = kvm_call_hyp(__kvm_vcpu_run, vcpu);
  37.  
  38.                 vcpu->mode = OUTSIDE_GUEST_MODE;
  39. diff --git a/arch/arm64/kvm/hyp-init.S b/arch/arm64/kvm/hyp-init.S
  40. index b27ca9b..35f4510 100644
  41. --- a/arch/arm64/kvm/hyp-init.S
  42. +++ b/arch/arm64/kvm/hyp-init.S
  43. @@ -202,6 +202,7 @@ merged:
  44.  #ifndef CONFIG_EL1_HYP
  45.         eret
  46.  #else
  47. +       hvc     #0x7001
  48.         hvc     #0x6000
  49.  #endif
  50.  ENDPROC(__kvm_hyp_init)
  51. diff --git a/arch/arm64/kvm/hyp/entry.S b/arch/arm64/kvm/hyp/entry.S
  52. index 1042d7e..7289ae6 100644
  53. --- a/arch/arm64/kvm/hyp/entry.S
  54. +++ b/arch/arm64/kvm/hyp/entry.S
  55. @@ -57,19 +57,24 @@ ENTRY(__guest_enter)
  56.         // x0: vcpu
  57.         // x1: host/guest context
  58.         // x2-x18: clobbered by macros
  59. +       hvc     #0x7777
  60.  
  61.         // Store the host regs
  62.         save_callee_saved_regs x1
  63.  
  64. +       hvc     #0x7778
  65.         // Preserve vcpu & host_ctxt for use at exit time
  66.         stp     x0, x1, [sp, #-16]!
  67.  
  68. +       hvc     #0x7679
  69.         add     x1, x0, #VCPU_CONTEXT
  70.  
  71. +       hvc     #0x7779
  72.         // Prepare x0-x1 for later restore by pushing them onto the stack
  73.         ldp     x2, x3, [x1, #CPU_XREG_OFFSET(0)]
  74.         stp     x2, x3, [sp, #-16]!
  75.  
  76. +       hvc     #0x7780
  77.         // x2-x18
  78.         ldp     x2, x3,   [x1, #CPU_XREG_OFFSET(2)]
  79.         ldp     x4, x5,   [x1, #CPU_XREG_OFFSET(4)]
  80. @@ -81,12 +86,15 @@ ENTRY(__guest_enter)
  81.         ldp     x16, x17, [x1, #CPU_XREG_OFFSET(16)]
  82.         ldr     x18,      [x1, #CPU_XREG_OFFSET(18)]
  83.  
  84. +       hvc     #0x7781
  85.         // x19-x29, lr
  86.         restore_callee_saved_regs x1
  87.  
  88. +       hvc     #0x7782
  89.         // Last bits of the 64bit state
  90.         ldp     x0, x1, [sp], #16
  91.  
  92. +       hvc     #0x7783
  93.         // Do not touch any register after this!
  94.  #ifndef CONFIG_EL1_HYP
  95.  #ifndef CONFIG_EL1_HYP
  96.         eret
  97. diff --git a/arch/arm64/kvm/hyp/hyp-entry.S b/arch/arm64/kvm/hyp/hyp-entry.S
  98. index c81fcd0..e758596 100644
  99. --- a/arch/arm64/kvm/hyp/hyp-entry.S
  100. +++ b/arch/arm64/kvm/hyp/hyp-entry.S
  101. @@ -39,6 +39,7 @@
  102.  .endm
  103.  
  104.  el1_sync:                              // Guest trapped into EL2
  105. +       hvc #0x7099
  106.         save_x0_to_x3
  107.  
  108.  #ifndef CONFIG_EL1_HYP
  109. @@ -58,24 +59,30 @@ el1_sync:                           // Guest trapped into EL2
  110.  #endif
  111.         cbnz    x3, el1_trap            // called HVC
  112.  
  113. +       hvc #0x7098
  114.         /* Here, we're pretty sure the host called HVC. */
  115.         restore_x0_to_x3
  116. +       hvc #0x7097
  117.  
  118.         /* Check for __hyp_get_vectors */
  119.         cbnz    x0, 1f
  120. +       hvc #0x7096
  121.  #ifndef CONFIG_EL1_HYP
  122.         mrs     x0, vbar_el2
  123.  #else
  124.         hvc     #0xd3e0
  125.  #endif
  126. +       hvc #0x7095
  127.         b       2f
  128.  
  129.  1:     stp     lr, xzr, [sp, #-16]!
  130. +       hvc #0x7094
  131.  
  132.         /*
  133.          * Compute the function address in EL2, and shuffle the parameters.
  134.          */
  135.         kern_hyp_va     x0
  136. +       hvc #0x7093
  137.         mov     lr, x0
  138.         mov     x0, x1
  139.         mov     x1, x2
  140. diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
  141. index bf53131..dcf0f53 100644
  142. --- a/arch/arm64/kvm/hyp/switch.c
  143. +++ b/arch/arm64/kvm/hyp/switch.c
  144. @@ -16,6 +16,7 @@
  145.   */
  146.  
  147.  #include "hyp.h"
  148. +#include <asm/hvc_encoding.h>
  149.  
  150.  static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu)
  151.  {
  152. @@ -33,25 +34,45 @@ static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu)
  153.                 write_sysreg(1 << 30, fpexc32_el2);
  154.                 isb();
  155.         }
  156. +#ifndef CONFIG_EL1_HYP
  157.         write_sysreg(val, hcr_el2);
  158.         /* Trap on AArch32 cp15 c15 accesses (EL1 or EL0) */
  159.         write_sysreg(1 << 15, hstr_el2);
  160.         write_sysreg(CPTR_EL2_TTA | CPTR_EL2_TFP, cptr_el2);
  161.         write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2);
  162. +#else
  163. +       write_s_sysreg(val, S_HCR_EL2);
  164. +       /* Trap on AArch32 cp15 c15 accesses (EL1 or EL0) */
  165. +       write_s_sysreg(1 << 15, S_HSTR_EL2);
  166. +       write_s_sysreg(CPTR_EL2_TTA | CPTR_EL2_TFP, S_CPTR_EL2);
  167. +       write_s_sysreg(vcpu->arch.mdcr_el2, S_MDCR_EL2);
  168. +#endif
  169.  }
  170.  
  171.  static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu)
  172.  {
  173. +#ifndef CONFIG_EL1_HYP
  174.         write_sysreg(HCR_RW, hcr_el2);
  175.         write_sysreg(0, hstr_el2);
  176.         write_sysreg(read_sysreg(mdcr_el2) & MDCR_EL2_HPMN_MASK, mdcr_el2);
  177.         write_sysreg(0, cptr_el2);
  178. +#else
  179. +       write_s_sysreg(HCR_RW, S_HCR_EL2);
  180. +       write_s_sysreg(0, S_HSTR_EL2);
  181. +       write_s_sysreg(read_sysreg(mdcr_el2) & MDCR_EL2_HPMN_MASK, S_MDCR_EL2);
  182. +       write_s_sysreg(0, S_CPTR_EL2);
  183. +#endif
  184.  }
  185.  
  186.  static void __hyp_text __activate_vm(struct kvm_vcpu *vcpu)
  187.  {
  188.         struct kvm *kvm = kern_hyp_va(vcpu->kvm);
  189. +       asm volatile("hvc #0x7010");
  190. +#ifndef CONFIG_EL1_HYP
  191.         write_sysreg(kvm->arch.vttbr, vttbr_el2);
  192. +#else
  193. +       write_s_sysreg(kvm->arch.vttbr, S_VTTBR_EL2);
  194. +#endif
  195.  }
  196.  
  197.  static void __hyp_text __deactivate_vm(struct kvm_vcpu *vcpu)
  198. @@ -93,7 +114,11 @@ static int __hyp_text __guest_run(struct kvm_vcpu *vcpu)
  199.         u64 exit_code;
  200.  
  201.         vcpu = kern_hyp_va(vcpu);
  202. +#ifndef CONFIG_EL1_HYP
  203.         write_sysreg(vcpu, tpidr_el2);
  204. +#else
  205. +       write_s_sysreg(vcpu, S_TPIDR_EL2);
  206. +#endif
  207.  
  208.         host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context);
  209.         guest_ctxt = &vcpu->arch.ctxt;
  210. @@ -115,7 +140,9 @@ static int __hyp_text __guest_run(struct kvm_vcpu *vcpu)
  211.          * We must restore the 32-bit state before the sysregs, thanks
  212.          * to Cortex-A57 erratum #852523.
  213.          */
  214. +#ifndef CONFIG_EL1_HYP
  215.         __sysreg32_restore_state(vcpu);
  216. +#endif
  217.         __sysreg_restore_state(guest_ctxt);
  218.  #ifndef CONFIG_EL1_HYP
  219.         __debug_restore_state(vcpu, kern_hyp_va(vcpu->arch.debug_ptr), guest_ctxt);
  220. diff --git a/arch/arm64/kvm/hyp/tlb.c b/arch/arm64/kvm/hyp/tlb.c
  221. index 2a7e0d8..94ca6df 100644
  222. --- a/arch/arm64/kvm/hyp/tlb.c
  223. +++ b/arch/arm64/kvm/hyp/tlb.c
  224. @@ -71,9 +71,15 @@ __alias(__tlb_flush_vmid) void __kvm_tlb_flush_vmid(struct kvm *kvm);
  225.  
  226.  static void __hyp_text __tlb_flush_vm_context(void)
  227.  {
  228. +       asm volatile("hvc     #0x7092");
  229.         dsb(ishst);
  230. +#ifndef CONFIG_EL1_HYP
  231.         asm volatile("tlbi alle1is      \n"
  232.                      "ic ialluis          ": : );
  233. +#else
  234. +       asm volatile("hvc     #0x5000   \n"
  235. +                    "ic ialluis          ": : );
  236. +#endif
  237.         dsb(ish);
  238.  }
Advertisement
Add Comment
Please, Sign In to add comment