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

[PATCH 16/21] libs/guest: make a cpu policy compatible with older Xen versions


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Tue, 23 Mar 2021 10:58:44 +0100
  • 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=RlUBOnVeSatdTasqz2pA02ppHxyAvCsUzYnjh93s6fw=; b=cDwW2TkyvklVbV/GUeHZ5rSFJBVkXYCCLmuBNrySCGsIzgX6EFrhEQlExMVDfZg6Kef3MJ1837WC+/E6s34s6d3XRHvDfBH3SiV+KDxWwvjOcRNWhV0xlvxJW6k/Ez5Kjx9TRiM/Ao/J4MfF8Hyq2TM0M00JJ4CFyS55DmJQvmKO8DeDrAMUN09X/cymIVeYmQEaLAuTSL8FKvZ9dcnimm026j03IAK/IoJxvccVtc1GE1hQE+FFAm5jiMyTbjq1+JJFOaCWP2VP7qs8eq00T47MyHkgb4pQz7uWbHezMH5ouhLGyhuNilHtRb6c3P+0xmprfBOE2LptmjZ1Rs+4ww==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DxSIYiAohgbBF0klDtKHYdqWnvupqP8/NIagBMTq/1K3i5VSj4ev5jxYli4LWqRrivluWM8r/bqeExtddt+SLCRYkVX+lLePKkFbZFNem/qV7btpHUvt0SWCkUoK0h1I7RWR6EBTkxAsu3zySFySKLA3SRvVnoWNC0i1VRUprBAVgN51/gGZnSMPkX4J6SEL59hQhNgtVNCpslf8lFwRK8kHhIyUCJWnwhi0cVoEydHWuoBBDMcwrNE7y232aaxGH3nt1ton7E1ox+9vn5jeP3GUhDMRPL+mqaAPFgqV4wCggGu9hFEMLiWWEpGdyAR1ZbhO2ToP+YpPVmzg09pXew==
  • Authentication-results: esa1.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: Tue, 23 Mar 2021 10:01:30 +0000
  • Ironport-hdrordr: A9a23:qPcfFq8VxUJWanqOmeZuk+EKdb1zdoIgy1knxilNYDRIb82VkN 2vlvwH1RnyzA0cQm0khMroAsS9aFnXnKQU3aA6O7C+UA76/Fa5NY0K1/qH/xTMOQ3bstRc26 BpbrRkBLTLZ2RSoM7m7GCDfOoI78KA9MmT69v261dIYUVUZ7p77wF/Yzzrd3FeYAVdH5I2GN 69y6N81lmdUE8aZMi6GXUJNtKrz7H2vanrfAIcAFof4BSO5AnC1JfBDxOa0h0COgk/o4sKzG 6tqW3Ez5Tmid6X4Fv212jf75NZ8eGRt+drNYi3peU+bhnpggasTox9V7OFpyBdmpDS1H8a1O Pijj1lE8Nv627AXmzdm2qT5yDQlAwAxlWn6ViEjWDtqcb0LQhKdfZptMZiXTbyr28D1esMt5 5j7iaimLd8SS7kpmDb4ePFUhl7/3DE2kYKoKoooFF0FbcFZKQ5l/14wGplVK0uMQjd844dHO xnHKjnlYxrWGLfVXzfs2V1qebcJ0gbL1ODSkgGjMSfzyJbqnB/11cZ38wShB47heoAd6U=
  • Ironport-sdr: A4PPknK72bCwVwF9v6geA7W2A7lMdgdjTAMz15nEfD9Kj1Gr6XGnJSfhtLEbNdHZdNLKeNy1n2 8Wk3a+dIhabJ8yjtw04s1FsZ4G4n20cB8xdSUjmt51ZBEdaCyl3ONnKtx9JN9MEuognNF60QE9 gOKI95DXJy2UU4lO66JVhYGd3Rwlg0PXjjtNt3sTXlRtezTkixazO/ulZBO4hz9x6bhIHIy8lu 8BYAGVoWZdcexSRa2FtUSVPGBIFTAi4A4s+9es3p2fKdbtQCE6dNtbfDFhV+yOuoygvvOD8Qz5 hTk=
  • 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>
---
 tools/include/xenctrl.h         |  4 ++++
 tools/libs/guest/xg_cpuid_x86.c | 39 ++++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index 5f3e5e17e9d..6f7158156fa 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -2627,6 +2627,10 @@ int xc_cpu_policy_calc_compatible(xc_interface *xch,
                                   const xc_cpu_policy_t p2,
                                   xc_cpu_policy_t out);
 
+/* Make a policy compatible with previous Xen versions. */
+int xc_cpu_policy_make_compatible(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 4afca3249ba..2abaf400a2b 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -436,6 +436,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 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);
@@ -504,12 +505,8 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t 
domid, bool restore,
      */
     if ( restore )
     {
-        p->basic.rdrand = test_bit(X86_FEATURE_RDRAND, host_featureset);
-
-        if ( di.hvm )
-        {
-            p->feat.mpx = test_bit(X86_FEATURE_MPX, host_featureset);
-        }
+        policy.cpuid = p;
+        xc_cpu_policy_make_compatible(xch, &policy, di.hvm);
     }
 
     if ( featureset )
@@ -1230,3 +1227,33 @@ int xc_cpu_policy_calc_compatible(xc_interface *xch,
 
     return rc;
 }
+
+int xc_cpu_policy_make_compatible(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;
+    }
+
+    policy->cpuid->basic.rdrand = host->cpuid->basic.rdrand;
+
+    if ( hvm )
+        policy->cpuid->feat.mpx = host->cpuid->feat.mpx;
+
+ out:
+    xc_cpu_policy_destroy(host);
+    return rc;
+}
-- 
2.30.1




 


Rackspace

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