arm/hypercall: Use the common hcall_preempted boolean
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 14 Feb 2017 17:56:33 +0000 (17:56 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 16 Feb 2017 14:15:25 +0000 (14:15 +0000)
With hcall_preempted having just been made common, ARM can use use it to
simplify its hypercall handling.

This simplifies the continuation logic and removes the risk of accidentally
skipping multiple instructions.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Julien Grall <julien.grall@arm.com>
xen/arch/arm/domain.c
xen/arch/arm/traps.c

index 0010b8ff03af37f0cd81e58b9d6400706ced6022..ee803346a87a070059383046544156fa224b8970 100644 (file)
@@ -348,17 +348,12 @@ void sync_vcpu_execstate(struct vcpu *v)
 
 void hypercall_cancel_continuation(void)
 {
-    struct cpu_user_regs *regs = guest_cpu_user_regs();
     struct mc_state *mcs = &current->mc_state;
 
     if ( mcs->flags & MCSF_in_multicall )
-    {
         __clear_bit(_MCSF_call_preempted, &mcs->flags);
-    }
     else
-    {
-        regs->pc += 4; /* undo re-execute 'hvc #XEN_HYPERCALL_TAG' */
-    }
+        current->hcall_preempted = false;
 }
 
 unsigned long hypercall_create_continuation(
@@ -390,8 +385,7 @@ unsigned long hypercall_create_continuation(
     {
         regs = guest_cpu_user_regs();
 
-        /* Ensure the hypercall trap instruction is re-executed. */
-        regs->pc -= 4;  /* re-execute 'hvc #XEN_HYPERCALL_TAG' */
+        current->hcall_preempted = true;
 
 #ifdef CONFIG_ARM_64
         if ( !is_32bit_domain(current->domain) )
index 718e820f094ea767e4d4b129b11ff5eee4cc4874..729b012417f11954d6f1870c8ddcfcf424ed54f1 100644 (file)
@@ -1453,9 +1453,6 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,
                               unsigned long iss)
 {
     arm_hypercall_fn_t call = NULL;
-#ifndef NDEBUG
-    register_t orig_pc = regs->pc;
-#endif
 
     BUILD_BUG_ON(NR_hypercalls < ARRAY_SIZE(arm_hypercall_table) );
 
@@ -1469,6 +1466,8 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,
         return;
     }
 
+    current->hcall_preempted = false;
+
     perfc_incra(hypercalls, *nr);
     call = arm_hypercall_table[*nr].fn;
     if ( call == NULL )
@@ -1480,12 +1479,9 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,
     HYPERCALL_RESULT_REG(regs) = call(HYPERCALL_ARGS(regs));
 
 #ifndef NDEBUG
-    /*
-     * Clobber argument registers only if pc is unchanged, otherwise
-     * this is a hypercall continuation.
-     */
-    if ( orig_pc == regs->pc )
+    if ( !current->hcall_preempted )
     {
+        /* Deliberately corrupt parameter regs used by this hypercall. */
         switch ( arm_hypercall_table[*nr].nr_args ) {
         case 5: HYPERCALL_ARG5(regs) = 0xDEADBEEF;
         case 4: HYPERCALL_ARG4(regs) = 0xDEADBEEF;
@@ -1498,6 +1494,10 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr,
         *nr = 0xDEADBEEF;
     }
 #endif
+
+    /* Ensure the hypercall trap instruction is re-executed. */
+    if ( current->hcall_preempted )
+        regs->pc -= 4;  /* re-execute 'hvc #XEN_HYPERCALL_TAG' */
 }
 
 static bool check_multicall_32bit_clean(struct multicall_entry *multi)