]> xenbits.xensource.com Git - people/iwj/xen.git/commitdiff
tools/libxc: Pre-cleanup for xc_cpuid_{set,apply_policy}()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 10 Sep 2019 15:59:20 +0000 (16:59 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 26 Sep 2019 12:40:18 +0000 (13:40 +0100)
This patch is broken out just to simplify the following two.

For xc_cpuid_set(), document how the 's' and 'k' options works because it is
quite subtle.  Replace a memset() with a for loop of 4 explicit NULL
assigments.  This mirrors the free()'s in the fail path.

For xc_cpuid_apply_policy(), const-ify the featureset pointer.  It isn't
written to, and was never intended to be mutable.

Drop three pieces of trailing whitespace.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-acked-by: Juergen Gross <jgross@suse.com>
tools/libxc/include/xenctrl.h
tools/libxc/xc_cpuid_x86.c

index 0da437318e52d401e38f6acaa8265656e69aa338..f4431687b3da9cf573d659450c8ff70ca6ecabce 100644 (file)
@@ -1800,7 +1800,7 @@ int xc_cpuid_set(xc_interface *xch,
                  char **config_transformed);
 int xc_cpuid_apply_policy(xc_interface *xch,
                           uint32_t domid,
-                          uint32_t *featureset,
+                          const uint32_t *featureset,
                           unsigned int nr_features);
 int xc_mca_op(xc_interface *xch, struct xen_mc *mc);
 int xc_mca_op_inject_v2(xc_interface *xch, unsigned int flags,
index b7f19409005fbbcf50f4fd681d10dd817c2589d8..226edc0c342c496d9260509f0ed0b16b5c9450f9 100644 (file)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * xc_cpuid_x86.c 
+ * xc_cpuid_x86.c
  *
  * Compute cpuid of a domain.
  *
@@ -336,7 +336,7 @@ static void cpuid(const unsigned int *input, unsigned int *regs)
 
 static int get_cpuid_domain_info(xc_interface *xch, uint32_t domid,
                                  struct cpuid_domain_info *info,
-                                 uint32_t *featureset,
+                                 const uint32_t *featureset,
                                  unsigned int nr_features)
 {
     struct xen_domctl domctl = {};
@@ -824,8 +824,7 @@ static void sanitise_featureset(struct cpuid_domain_info *info)
 }
 
 int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
-                          uint32_t *featureset,
-                          unsigned int nr_features)
+                          const uint32_t *featureset, unsigned int nr_features)
 {
     struct cpuid_domain_info info = {};
     unsigned int input[2] = { 0, 0 }, regs[4];
@@ -915,7 +914,7 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid,
  *   'k' -> pass through host value
  *   's' -> pass through the first time and then keep the same value
  *          across save/restore and migration.
- * 
+ *
  * For 's' and 'x' the configuration is overwritten with the value applied.
  */
 int xc_cpuid_set(
@@ -926,7 +925,8 @@ int xc_cpuid_set(
     unsigned int i, j, regs[4], polregs[4];
     struct cpuid_domain_info info = {};
 
-    memset(config_transformed, 0, 4 * sizeof(*config_transformed));
+    for ( i = 0; i < 4; ++i )
+        config_transformed[i] = NULL;
 
     rc = get_cpuid_domain_info(xch, domid, &info, NULL, 0);
     if ( rc )
@@ -944,7 +944,7 @@ int xc_cpuid_set(
             regs[i] = polregs[i];
             continue;
         }
-        
+
         config_transformed[i] = calloc(33, 1); /* 32 bits, NUL terminator. */
         if ( config_transformed[i] == NULL )
         {
@@ -952,6 +952,13 @@ int xc_cpuid_set(
             goto fail;
         }
 
+        /*
+         * Notes for following this algorithm:
+         *
+         * While it will accept any leaf data, it only makes sense to use on
+         * feature leaves.  regs[] initially contains the host values.  This,
+         * with the fall-through chain, is how the 's' and 'k' options work.
+         */
         for ( j = 0; j < 32; j++ )
         {
             unsigned char val = !!((regs[i] & (1U << (31 - j))));