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

[PATCH v4 05/10] libs/guest: make a cpu policy compatible with older Xen versions


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Fri, 7 May 2021 13:04:17 +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=v1TbxRetccB3cqkr4MGIU/LGmnU1UmJDCQ3gYxtvhWg=; b=KNl9EbkDfJ/eVyq90odXqQsnEOIVgKOv6PGczUZtpQpMsyyyeKCg78P+kITAfCHnS60zGpUCS0E9SCUVNKYs2R9VpEV+Jemz7dtsbymu7/YVYoqQMuSDZTgBAxDikrpQho8xqdLuWf+Wo2CXdlLEgmDq8RZVgtlPuFweAc8EhwRdenprJljyebef673uBmTBXrID7YS8JPzvzV/wUfkJJAM9IJWPFXjdh9bAXFsviKBXdYYiM5vaJP2cq45TKiVLLNAX086XA3G+4R3ZcDiRfBvrxjozHHLvfveh5p8X0JIDNg8oa1QzzrtEIeMoobrGsk18TmmeWtpvTNwpC/qw3w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SwW2R73A/0+ioVdnKEkHQHsR7vMSjrqBtJ2MkI6uowitw7PkCupMOUGHkwBa8SlzfIxB1dawC9P3Rn/WnwdP3+dF1wdEWXT9vrP5JDuE1JTxvxeMF5w5vEBKKcB8WHBJQvuv4HW1cgbyAVaiQsEkDTWpaUXuCFYOQDY5GZjFcubOn5iP/qoYQvagpH4BRGvsByQ+WIggs+KgipPiZiJy9/i2psHr8EyGSEFKTHouZEsAAyZ//W63rvax7QvAsosYzAIG0Hy4TGvTIdlWRGpI6Ay7k2QRC465ltySk+bn3RIzerzXaJe3zeUPI89v/HObxrrFnKeXWkW5eHH1Di137A==
  • Authentication-results: esa3.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, 07 May 2021 11:07:19 +0000
  • Ironport-hdrordr: A9a23:/50QaKs7KHJAbbCB6XXX9Z807skCRIMji2hC6mlwRA09TyXGra 2TdaUgvyMc1gx7ZJh5o6H5BEDyewKmyXcV2/hbAV7GZmXbUQSTXeVfBOfZogEIXheOj9K1tp 0QOZSWaueAamSS5PySiGbXLz9j+qjgzEnCv5a8854Zd3AOV0gW1XYaNu/0KC1LbTgDIaB8OI uX58JBqTblU28QdN6HCn4MWPWGj8HXlbr9CCR2SyIP2U2rt3eF+bT6Gx+X0lM1SDVU24ov9m DDjkjQ+rijifem0RXRvlWjoKi+2eGRhOerNvb8yvT9GQ+cyTpAo74RGYFqiQpF4d1HLmxa1e Uk7S1Qe/iboEmhBF1d6SGdpjUIlgxepkMKgGXo/UfLsIj3Qik3BNFGgp8cehzF61A4tNU5y6 5T2XmF3qAney8osR6Nk+QgbSsa4XZcYEBS4tL7hEYvGLf2qIUh2LD32XklWKvoMBiKmbzPId Mefv00vswmD29yR0qpzlWH7ubcIUgOIg==
  • Ironport-sdr: wBLs1wbGBlphFIMXsJra93bid4GkQexU8WJqk2kgcZC+JcxMxYIUsQW5WyMab5z+kY4Bm/1F6P AIxsXPswh9K1ClVbsKYj+z6sy4aQWSMIi1WEHNJI0JRvEgOdA06qvhUYt42l11lur6Wi/kIcBS y65/M3lZKyEU/TfgcEp5dwEouxFAYQunc+3Sht4qCMTfuZy6YRMMaqh9634ye1enSfMCOIpjjK i7w/faXl7Nf6s+sedB19DtbS4eSOBZ89vJ8IWRtYJOoekh9boOB1yY12AkZ56Si/AY05zqHtGp ut0=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Older Xen versions used to expose some CPUID bits which are no longer
exposed by default. In order to keep a compatible behavior with
guests migrated from versions of Xen that don't encode the CPUID data
on the migration stream introduce a function that sets the same bits
as older Xen versions.

This is pulled out from xc_cpuid_apply_policy which already has this
logic present.

No functional change intended.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
Changes since v3:
 - Rename function to xc_cpu_policy_make_compat_4_12.

Changes since v1:
 - Move comments and explicitly mention pre-4.13 Xen.
---
 tools/include/xenguest.h        |  4 +++
 tools/libs/guest/xg_cpuid_x86.c | 58 ++++++++++++++++++++++++---------
 2 files changed, 47 insertions(+), 15 deletions(-)

diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h
index 8e8461b0660..576e976d069 100644
--- a/tools/include/xenguest.h
+++ b/tools/include/xenguest.h
@@ -754,6 +754,10 @@ int xc_cpu_policy_get_msr(xc_interface *xch, const 
xc_cpu_policy_t *policy,
 bool xc_cpu_policy_is_compatible(xc_interface *xch, xc_cpu_policy_t *host,
                                  xc_cpu_policy_t *guest);
 
+/* Make a policy compatible with pre-4.13 Xen versions. */
+int xc_cpu_policy_make_compat_4_12(xc_interface *xch, xc_cpu_policy_t *policy,
+                                   bool hvm);
+
 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 cdfc79a86e7..fccbc54a400 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -441,6 +441,7 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t 
domid, bool restore,
     unsigned int i, nr_leaves, nr_msrs;
     xen_cpuid_leaf_t *leaves = NULL;
     struct cpuid_policy *p = NULL;
+    struct xc_cpu_policy policy = { };
     uint32_t err_leaf = -1, err_subleaf = -1, err_msr = -1;
     uint32_t host_featureset[FEATURESET_NR_ENTRIES] = {};
     uint32_t len = ARRAY_SIZE(host_featureset);
@@ -505,21 +506,9 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t 
domid, bool restore,
 
     if ( restore )
     {
-        /*
-         * Account for feature which have been disabled by default since Xen 
4.13,
-         * so migrated-in VM's don't risk seeing features disappearing.
-         */
-        p->basic.rdrand = test_bit(X86_FEATURE_RDRAND, host_featureset);
-
-        if ( di.hvm )
-        {
-            p->feat.mpx = test_bit(X86_FEATURE_MPX, host_featureset);
-        }
-
-        /* Clamp maximum leaves to the ones supported on 4.12. */
-        p->basic.max_leaf = min(p->basic.max_leaf, 0xdu);
-        p->feat.max_subleaf = 0;
-        p->extd.max_leaf = min(p->extd.max_leaf, 0x1cu);
+        policy.cpuid = *p;
+        xc_cpu_policy_make_compat_4_12(xch, &policy, di.hvm);
+        *p = policy.cpuid;
     }
 
     if ( featureset )
@@ -921,3 +910,42 @@ bool xc_cpu_policy_is_compatible(xc_interface *xch, 
xc_cpu_policy_t *host,
 
     return false;
 }
+
+int xc_cpu_policy_make_compat_4_12(xc_interface *xch, xc_cpu_policy_t *policy,
+                                   bool hvm)
+{
+    xc_cpu_policy_t *host;
+    int rc;
+
+    host = xc_cpu_policy_init();
+    if ( !host )
+    {
+        errno = ENOMEM;
+        return -1;
+    }
+
+    rc = xc_cpu_policy_get_system(xch, XEN_SYSCTL_cpu_policy_host, host);
+    if ( rc )
+    {
+        ERROR("Failed to get host policy");
+        goto out;
+    }
+
+    /*
+     * Account for features which have been disabled by default since Xen 4.13,
+     * so migrated-in VM's don't risk seeing features disappearing.
+     */
+    policy->cpuid.basic.rdrand = host->cpuid.basic.rdrand;
+
+    if ( hvm )
+        policy->cpuid.feat.mpx = host->cpuid.feat.mpx;
+
+    /* Clamp maximum leaves to the ones supported on pre-4.13. */
+    policy->cpuid.basic.max_leaf = min(policy->cpuid.basic.max_leaf, 0xdu);
+    policy->cpuid.feat.max_subleaf = 0;
+    policy->cpuid.extd.max_leaf = min(policy->cpuid.extd.max_leaf, 0x1cu);
+
+ out:
+    xc_cpu_policy_destroy(host);
+    return rc;
+}
-- 
2.31.1




 


Rackspace

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