x86/hvm: Improve physdev_op hypercall dispatching
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 13 Feb 2017 11:49:30 +0000 (11:49 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 14 Feb 2017 14:34:27 +0000 (14:34 +0000)
hvm_physdev_op() and hvm_physdev_op_compat32() are almost identical, but there
is no need to have two functions instantiated at the end of different function
pointers.

Combine the two into a single hvm_physdev_op() and dispatch to
{do,compat}_physdev_op() based on the hcall_64bit setting.

This also fixes an inconsistency where 64bit PVH hardware domains were
permitted access to extra physdev ops, but 32bit domains weren't.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/hvm/hypercall.c

index 85fa92d342c47b627f9501a72d10e88ede7ef3d3..5dbd54adafc626f7f05e6eb8f5a64412274506ae 100644 (file)
@@ -73,10 +73,12 @@ static long hvm_grant_table_op(
 
 static long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
+    const struct vcpu *curr = current;
+
     switch ( cmd )
     {
     default:
-        if ( !is_pvh_vcpu(current) || !is_hardware_domain(current->domain) )
+        if ( !is_pvh_vcpu(curr) || !is_hardware_domain(curr->domain) )
             return -ENOSYS;
         /* fall through */
     case PHYSDEVOP_map_pirq:
@@ -84,26 +86,13 @@ static long hvm_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     case PHYSDEVOP_eoi:
     case PHYSDEVOP_irq_status_query:
     case PHYSDEVOP_get_free_pirq:
-        return do_physdev_op(cmd, arg);
-    }
-}
-
-static long hvm_physdev_op_compat32(
-    int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
-{
-    switch ( cmd )
-    {
-        case PHYSDEVOP_map_pirq:
-        case PHYSDEVOP_unmap_pirq:
-        case PHYSDEVOP_eoi:
-        case PHYSDEVOP_irq_status_query:
-        case PHYSDEVOP_get_free_pirq:
-            return compat_physdev_op(cmd, arg);
-        break;
-    default:
-            return -ENOSYS;
         break;
     }
+
+    if ( curr->arch.hvm_vcpu.hcall_64bit )
+        return do_physdev_op(cmd, arg);
+    else
+        return compat_physdev_op(cmd, arg);
 }
 
 #define HYPERCALL(x)                                         \
@@ -118,15 +107,13 @@ static long hvm_physdev_op_compat32(
     [ __HYPERVISOR_ ## x ] = { (hypercall_fn_t *) do_ ## x,  \
                                (hypercall_fn_t *) compat_ ## x }
 
-#define do_physdev_op         hvm_physdev_op
-#define compat_physdev_op     hvm_physdev_op_compat32
 #define do_arch_1             paging_domctl_continuation
 
 static const hypercall_table_t hvm_hypercall_table[] = {
     HVM_CALL(memory_op),
     HVM_CALL(grant_table_op),
     COMPAT_CALL(vcpu_op),
-    COMPAT_CALL(physdev_op),
+    HVM_CALL(physdev_op),
     COMPAT_CALL(xen_version),
     HYPERCALL(console_io),
     HYPERCALL(event_channel_op),
@@ -146,8 +133,6 @@ static const hypercall_table_t hvm_hypercall_table[] = {
     HYPERCALL(arch_1)
 };
 
-#undef do_physdev_op
-#undef compat_physdev_op
 #undef do_arch_1
 
 #undef HYPERCALL