[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3 11/13] libs/guest: apply a featureset into a cpu policy


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Fri, 30 Apr 2021 17:52:09 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OI1adWYY6QWjkd1MdeyydMXNw87PB1TRtgvlJoP2W4k=; b=S+3lUaT7Gael4mYTXpOl0Pet7YyHf/HrrexAQHaFUx7mW/SAkNB1Y6318xX2Hyq/vMuFEpgFTSC5fHnJyenP5S2pREAwr30zpqkfrg8+2X/fMYwnBWTTxDdsHfj7p40YHh2otEiOdLzu0Wj5zDMKT9exElgi3eHEB+vUOj8NSxElSKXgv1NZoS1vizkOLCDRUsZ/WpLSGwpfeMCCY9vAyqyU6kyHYKgFtbemdZrbFH2xNscUhkUAMU5d7wjjRLE7tpj+VJ9cuZ60m64vCFSno6QL610lbxRjBaTa+eMFEpXmQzwyUochhK7GhLjw4/oc1hNM+PysQLhbtUhpkI40fA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fdnJhT2J92B9GqnWddqUg69BaP7eiOvqRLUY8P8HxD8rBjL7e6vHR8YVUPB/nQiR+vqmYYarvDMIZWjnmPF21DtIT/TEqTb/hP9Zx52VncJmPAl/yX/xWErKAFm2o5wWy+SmaJC3CMC6lvTJeVUR3B+LwpAaHioW7ENmHadcRsBfSawb3az9zZ4cOAp7XcIndrtDoM59cqb4VwU8SX0N4qGLeNQPU1LDDqh2jdoyZLrt2gqLjitcRYKfnNRS/TbgtwN7FBwaZjciI35TmdNgcbSZCxpbwnvtF/MqsGijJWxEwbVhJ1hPjEh1NK3OGlcYQKfSriQCDiteyXtZYszZqQ==
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 30 Apr 2021 15:54:51 +0000
  • Ironport-hdrordr: A9a23:qQR6t60fTFxk1sdjP4I+XwqjBTV3eYIsi2QD101hICF9Wvez0+ izgfUW0gL1gj4NWHcm3euNIrWEXGm0z/BIyKErF/OHUBP9sGWlaLtj44zr3iH6F0TFmdJ1/Z xLN5JzANiYNzRHpO7n/Qi1FMshytGb8KauwdzT1WtpUBsCUcFdxi1SYzzrdXFebg9AGJY/Cd 6g/cJBvTWtYjA6ac68C3kDUYH41qL2vbjhZgMLAANi1RmWgVqTmcLHOjW7/jNbaTNAxr8+7X PI+jaZ2oyPu+y2oyWsrlP7wI9RnLLau75+LeyKzvMYMzD9zjuvDb4RIYGqmBAQjKWR5E0xkN /Kyi1QTPhbz3/KZGm6rV/M9mDboU4TwkTvw1OZnnfvyPaRLFlRZrsj9OApByfx0EYusMpx16 hGxQuixudqJCjNgTjn4JzwXwxq/3DE0UYKq/IZjHBUTOIlGdlshLEYlXkldKsoLWbR7YAqF/ RWF8fM5PpaWkPyVQGpgkBfhPOrRXg9BRGAXwwrvdGUySFfmDRDw1If39F3pAZOyLsND71/o8 jUOKVhk79DCucQcKJGHe8EBe+6EHbETx7gOH+bSG6XWp0vCjbokdra8b817OaldNgj150pgq nMV1teqCobZ1/uIdfm5uwJzjn9BEGGGRj9wMBX4JZ0/pfmQqDwDCGFQFcy1+O9vvQkBNHBUf rbAuMXP9bTaU/VXapZ1Qz3XJdfbVMEVtcOh9o9U1WS5u3RLInHsfHabebzK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V6PlGoc6aTFWJNutrDQ oflyXgY+AFDqylKWxheoGu5je2sWLeAbBJyxi5cPJ91uBcCrusArKMwrcCnMO7wLpfnnuIlqsR wK+j6XQ8ZKjSs+Tb4ngzVflzn9FjneWz/yo2DmoK9MzB9qfYyuYXSO56zktGVWIIgB+KwevOZz lv4=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Pull out the code from xc_cpuid_apply_policy that applies a featureset
to a cpu policy and place it on it's own standalone function that's
part of the public interface.

No functional change intended.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
 tools/include/xenctrl.h         |  5 ++
 tools/libs/guest/xg_cpuid_x86.c | 95 ++++++++++++++++++++-------------
 2 files changed, 62 insertions(+), 38 deletions(-)

diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index ce0785f7654..3fef954d1d1 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -2639,6 +2639,11 @@ int xc_cpu_policy_legacy_topology(xc_interface *xch, 
xc_cpu_policy_t policy,
 int xc_cpu_policy_apply_cpuid(xc_interface *xch, xc_cpu_policy_t policy,
                               const struct xc_xend_cpuid *cpuid, bool hvm);
 
+/* Apply a featureset to the policy. */
+int xc_cpu_policy_apply_featureset(xc_interface *xch, xc_cpu_policy_t policy,
+                                   const uint32_t *featureset,
+                                   unsigned int nr_features);
+
 int xc_get_cpu_levelling_caps(xc_interface *xch, uint32_t *caps);
 int xc_get_cpu_featureset(xc_interface *xch, uint32_t index,
                           uint32_t *nr_features, uint32_t *featureset);
diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c
index d313a093af6..e2237e33709 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -477,46 +477,15 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t 
domid, bool restore,
 
     if ( featureset )
     {
-        uint32_t disabled_features[FEATURESET_NR_ENTRIES],
-            feat[FEATURESET_NR_ENTRIES] = {};
-        static const uint32_t deep_features[] = INIT_DEEP_FEATURES;
-        unsigned int i, b;
-
-        /*
-         * The user supplied featureset may be shorter or longer than
-         * FEATURESET_NR_ENTRIES.  Shorter is fine, and we will zero-extend.
-         * Longer is fine, so long as it only padded with zeros.
-         */
-        unsigned int user_len = min(FEATURESET_NR_ENTRIES + 0u, nr_features);
-
-        /* Check for truncated set bits. */
-        rc = -EOPNOTSUPP;
-        for ( i = user_len; i < nr_features; ++i )
-            if ( featureset[i] != 0 )
-                goto out;
-
-        memcpy(feat, featureset, sizeof(*featureset) * user_len);
-
-        /* Disable deep dependencies of disabled features. */
-        for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i )
-            disabled_features[i] = ~feat[i] & deep_features[i];
-
-        for ( b = 0; b < sizeof(disabled_features) * CHAR_BIT; ++b )
+        policy.cpuid = *p;
+        rc = xc_cpu_policy_apply_featureset(xch, &policy, featureset,
+                                            nr_features);
+        if ( rc )
         {
-            const uint32_t *dfs;
-
-            if ( !test_bit(b, disabled_features) ||
-                 !(dfs = x86_cpuid_lookup_deep_deps(b)) )
-                continue;
-
-            for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i )
-            {
-                feat[i] &= ~dfs[i];
-                disabled_features[i] &= ~dfs[i];
-            }
+            ERROR("Failed to apply featureset to policy");
+            goto out;
         }
-
-        cpuid_featureset_to_policy(feat, p);
+        *p = policy.cpuid;
     }
     else
     {
@@ -1108,3 +1077,53 @@ int xc_cpu_policy_legacy_topology(xc_interface *xch, 
xc_cpu_policy_t policy,
 
     return 0;
 }
+
+int xc_cpu_policy_apply_featureset(xc_interface *xch, xc_cpu_policy_t policy,
+                                   const uint32_t *featureset,
+                                   unsigned int nr_features)
+{
+    uint32_t disabled_features[FEATURESET_NR_ENTRIES],
+        feat[FEATURESET_NR_ENTRIES] = {};
+    static const uint32_t deep_features[] = INIT_DEEP_FEATURES;
+    unsigned int i, b;
+
+    /*
+     * The user supplied featureset may be shorter or longer than
+     * FEATURESET_NR_ENTRIES.  Shorter is fine, and we will zero-extend.
+     * Longer is fine, so long as it only padded with zeros.
+     */
+    unsigned int user_len = min(FEATURESET_NR_ENTRIES + 0u, nr_features);
+
+    /* Check for truncated set bits. */
+    for ( i = user_len; i < nr_features; ++i )
+        if ( featureset[i] != 0 )
+        {
+            errno = EOPNOTSUPP;
+            return -1;
+        }
+
+    memcpy(feat, featureset, sizeof(*featureset) * user_len);
+
+    /* Disable deep dependencies of disabled features. */
+    for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i )
+        disabled_features[i] = ~feat[i] & deep_features[i];
+
+    for ( b = 0; b < sizeof(disabled_features) * CHAR_BIT; ++b )
+    {
+        const uint32_t *dfs;
+
+        if ( !test_bit(b, disabled_features) ||
+             !(dfs = x86_cpuid_lookup_deep_deps(b)) )
+            continue;
+
+        for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i )
+        {
+            feat[i] &= ~dfs[i];
+            disabled_features[i] &= ~dfs[i];
+        }
+    }
+
+    cpuid_featureset_to_policy(feat, &policy->cpuid);
+
+    return 0;
+}
-- 
2.31.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.