]> xenbits.xensource.com Git - people/sstabellini/xen-unstable.git/.git/commitdiff
xen: turn color_guest_config.colors into a bitmask
authorStefano Stabellini <sstabellini@kernel.org>
Wed, 11 Dec 2019 02:03:09 +0000 (18:03 -0800)
committerLuca Miccio <206497@studenti.unimore.it>
Mon, 6 Jan 2020 14:07:36 +0000 (15:07 +0100)
It is unnecessary to use an array as a hypercall parameter in this case
when a simple bitmark suffices. It has also the benefit of making it
much easier to call the same hypercall implmentation functions
internally within Xen for dom0less domains (we can remove the special
case for dom0less VMs in arch_domain_create).

Make sure to use "ULL" to check bits in the bitmask as it is 64 bits.

Also fix a couple of code style issues.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com>
tools/libxl/libxl_arm.c
xen/arch/arm/domain.c
xen/arch/arm/domain_build.c
xen/include/public/arch-arm.h

index b6c9ab070683e412b811c8f63da97d391ff67faa..7bd358102d451f134142a8191b8278cdb2c5dd6f 100644 (file)
@@ -102,8 +102,11 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
         return ERROR_FAIL;
     }
 
-    xc_config->colors.max_colors = d_config->b_info.num_colors;
-    set_xen_guest_handle_raw(xc_config->colors.colors, d_config->b_info.colors);
+    config->arch.colors.max_colors = d_config->b_info.num_colors;
+    config->arch.colors.colors = 0;
+    for (i = 0; i < d_config->b_info.num_colors; i++)
+        config->arch.colors.colors |= ((unsigned long long)1 <<
+                                     d_config->b_info.colors[i]);
     LOG(DEBUG, "Setup domain colors");
 
     return 0;
index 36056960f8111d025ade57bead799288d22ee8f8..480eaf9a8ae6d870221afd83915100ac048d2f05 100644 (file)
@@ -768,8 +768,11 @@ int arch_domain_create(struct domain *d,
     }
     else
     {
+        int i, k;
+
         d->colors = xzalloc_array(uint32_t, config->arch.colors.max_colors);
-        if ( !d->colors ){
+        if ( !d->colors )
+        {
             rc = -ENOMEM;
             printk(XENLOG_ERR "Failed to alloc colors for dom%u\n",
                    d->domain_id);
@@ -777,17 +780,10 @@ int arch_domain_create(struct domain *d,
         }
 
         d->max_colors = config->arch.colors.max_colors;
-        if ( d->domain_id <= max_init_domid )
-            memcpy(d->colors, config->arch.colors.colors.p, d->max_colors * sizeof(uint32_t));
-        else
+        for ( i = 0, k = 0; k < d->max_colors && i < 64; i++ )
         {
-            rc = copy_from_guest(d->colors, config->arch.colors.colors, d->max_colors);
-            if ( rc != 0 )
-            {
-                rc = -EINVAL;
-                printk(XENLOG_ERR "Failed to copy colors for dom%u\n", d->domain_id);
-                goto fail;
-            }
+            if ( config->arch.colors.colors & (1ULL << i) )
+                d->colors[k++] = i;
         }
     }
 
index 940ee993e8353c5d2bc874b3194e1094abecd4be..8e4b76c01130c28817973571ece79c18a00a5d86 100644 (file)
@@ -2446,7 +2446,6 @@ void __init create_domUs(void)
     struct dt_device_node *node;
     const struct dt_device_node *chosen = dt_find_node_by_path("/chosen");
     u64 col_val = 0;
-    uint32_t *colors = NULL;
     int rc;
 
     BUG_ON(chosen == NULL);
@@ -2485,10 +2484,11 @@ void __init create_domUs(void)
         }
 
         d_cfg.arch.colors.max_colors = 0;
+        d_cfg.arch.colors.colors = 0ULL;
         rc = dt_property_read_u64(node, "colors", &col_val);
         if ( rc && col_val )
         {
-            int i, k;
+            int i;
 
             if ( !get_max_colors() )
                 panic("Coloring requested but no colors configuration found!\n");
@@ -2499,17 +2499,10 @@ void __init create_domUs(void)
             printk("Colored configuration: 0x%"PRIx64"\n", col_val);
 
             /* Calculate number of bit set */
-            for ( i = 0; i < get_max_colors(); i++)
-                if ( col_val & (1 << i) )
+            for ( i = 0; i < 64; i++)
+                if ( col_val & (1ULL << i) )
                     d_cfg.arch.colors.max_colors++;
-
-            colors = xzalloc_array(uint32_t, d_cfg.arch.colors.max_colors);
-            if ( !colors )
-                panic("Cannot allocate memory");
-            for ( i = 0, k = 0; k < d_cfg.arch.colors.max_colors; i++ )
-                if ( col_val & (1 << i) )
-                    colors[k++] = i;
-            set_xen_guest_handle(d_cfg.arch.colors.colors, colors);
+            d_cfg.arch.colors.colors = col_val;
         }
 
         d = domain_create(++max_init_domid, &d_cfg, false);
@@ -2523,7 +2516,6 @@ void __init create_domUs(void)
             panic("Could not set up domain %s\n", dt_node_name(node));
 
         domain_unpause_by_systemcontroller(d);
-        xfree(colors);
     }
 }
 
index 66dde535a9a90957a4e606a79594755a593796b4..558e1e74aa2aeb2fc6f5cde6f0279ca212a0e467 100644 (file)
@@ -299,11 +299,9 @@ struct vcpu_guest_context {
 typedef struct vcpu_guest_context vcpu_guest_context_t;
 DEFINE_XEN_GUEST_HANDLE(vcpu_guest_context_t);
 
-__DEFINE_XEN_GUEST_HANDLE(col, uint32_t);
-
 struct color_guest_config {
     uint32_t max_colors;
-    XEN_GUEST_HANDLE(col) colors;
+    uint64_t colors;
 };
 
 /*