ARM: KVM: Allow the main HYP code to use the init hyp stub implementation
authorMarc Zyngier <marc.zyngier@arm.com>
Mon, 3 Apr 2017 18:37:55 +0000 (19:37 +0100)
committerChristoffer Dall <cdall@linaro.org>
Sun, 9 Apr 2017 14:49:29 +0000 (07:49 -0700)
We now have a full hyp-stub implementation in the KVM init code,
but the main KVM code only supports HVC_GET_VECTORS, which is not
enough.

Instead of reinventing the wheel, let's reuse the init implementation
by branching to the idmap page when called with a hyp-stub hypercall.

Tested-by: Keerthy <j-keerthy@ti.com>
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <cdall@linaro.org>
arch/arm/kvm/hyp/hyp-entry.S

index 1f8db7d21fc55be8621c70708d9ba72a49373953..a35baa81fd2323e7e43c1ec16f551a1dd618d268 100644 (file)
@@ -126,11 +126,30 @@ hyp_hvc:
         */
        pop     {r0, r1, r2}
 
-       /* Check for __hyp_get_vectors */
-       cmp     r0, #HVC_GET_VECTORS
-       mrceq   p15, 4, r0, c12, c0, 0  @ get HVBAR
-       beq     1f
+       /*
+        * Check if we have a kernel function, which is guaranteed to be
+        * bigger than the maximum hyp stub hypercall
+        */
+       cmp     r0, #HVC_STUB_HCALL_NR
+       bhs     1f
 
+       /*
+        * Not a kernel function, treat it as a stub hypercall.
+        * Compute the physical address for __kvm_handle_stub_hvc
+        * (as the code lives in the idmaped page) and branch there.
+        * We hijack ip (r12) as a tmp register.
+        */
+       push    {r1}
+       ldr     r1, =kimage_voffset
+       ldr     r1, [r1]
+       ldr     ip, =__kvm_handle_stub_hvc
+       sub     ip, ip, r1
+THUMB( add     ip, ip, #1)
+       pop     {r1}
+
+       bx      ip
+
+1:
        push    {lr}
 
        mov     lr, r0
@@ -142,7 +161,7 @@ THUMB(      orr     lr, #1)
        blx     lr                      @ Call the HYP function
 
        pop     {lr}
-1:     eret
+       eret
 
 guest_trap:
        load_vcpu r0                    @ Load VCPU pointer to r0