x86/domctl: Make XEN_DOMCTL_set_address_size singleshot
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 7 Dec 2016 17:48:27 +0000 (17:48 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 6 Jan 2017 19:22:01 +0000 (19:22 +0000)
Toolstacks (including some out-of-tree ones) use XEN_DOMCTL_set_address_size
at most once per domain, and it ends up having a destructive effect on the
available CPUID policy for a domain.

To avoid ordering issues between altering the policy via domctl, and the
constructive effects which would have to happen from switching back to native,
explicitly reject this case.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/domain.c
xen/arch/x86/domctl.c
xen/include/xen/compat.h

index 11fa3795fa504f8872baa43ce66733159b115af4..939318718f30dbcb8c96bddd5d45ae5f6b5befe4 100644 (file)
@@ -322,43 +322,12 @@ static void release_compat_l4(struct vcpu *v)
     v->arch.guest_table_user = pagetable_null();
 }
 
-static inline int may_switch_mode(struct domain *d)
-{
-    return (!is_hvm_domain(d) && (d->tot_pages == 0));
-}
-
-int switch_native(struct domain *d)
-{
-    struct vcpu *v;
-
-    if ( !may_switch_mode(d) )
-        return -EACCES;
-    if ( !is_pv_32bit_domain(d) && !is_pvh_32bit_domain(d) )
-        return 0;
-
-    d->arch.is_32bit_pv = d->arch.has_32bit_shinfo = 0;
-
-    for_each_vcpu( d, v )
-    {
-        free_compat_arg_xlat(v);
-
-        if ( !is_pvh_domain(d) )
-            release_compat_l4(v);
-        else
-            hvm_set_mode(v, 8);
-    }
-
-    d->arch.x87_fip_width = cpu_has_fpu_sel ? 0 : 8;
-
-    return 0;
-}
-
 int switch_compat(struct domain *d)
 {
     struct vcpu *v;
     int rc;
 
-    if ( !may_switch_mode(d) )
+    if ( is_hvm_domain(d) || d->tot_pages != 0 )
         return -EACCES;
     if ( is_pv_32bit_domain(d) || is_pvh_32bit_domain(d) )
         return 0;
index b0df4a9cae8c2ec51842fd03f1476b6e337483c9..ab141b106673e114f3c004f09619bbcae1a9a7b3 100644 (file)
@@ -514,18 +514,13 @@ long arch_do_domctl(
         break;
 
     case XEN_DOMCTL_set_address_size:
-        switch ( domctl->u.address_size.size )
-        {
-        case 32:
+        if ( ((domctl->u.address_size.size == 64) && !d->arch.is_32bit_pv) ||
+             ((domctl->u.address_size.size == 32) && d->arch.is_32bit_pv) )
+            ret = 0;
+        else if ( domctl->u.address_size.size == 32 )
             ret = switch_compat(d);
-            break;
-        case 64:
-            ret = switch_native(d);
-            break;
-        default:
-            ret = (domctl->u.address_size.size == BITS_PER_LONG) ? 0 : -EINVAL;
-            break;
-        }
+        else
+            ret = -EINVAL;
         break;
 
     case XEN_DOMCTL_get_address_size:
index ce913ac292b74e2bb57fd16dc5b6eee7e3deddb1..08683505f55ba7e9cc024e50fb505b3a8d83cef8 100644 (file)
@@ -231,7 +231,6 @@ struct vcpu_runstate_info;
 void xlat_vcpu_runstate_info(struct vcpu_runstate_info *);
 
 int switch_compat(struct domain *);
-int switch_native(struct domain *);
 
 #else