[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 06/12] libs/guest: make a cpu policy compatible with older Xen versions
- To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
- Date: Mon, 29 Nov 2021 16:33:49 +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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pRaYIUfkMkzZXE8d3moJMkHiUafesA///nNUwZGhtBY=; b=BZxhq1icNMM1CoGq/O/DCn/hcTQR1pjO1jIeglGADsUqvHWg3Omi160fA+6TiucuqhwBRmNYBT8CXFD+XsMhDWS5DX1BpPAwk1JUmDwecxsptfVqS4+UeZoaT7lDFnsd69RG0GL3zZzyRbpD8BMy4/O7+64XzJovUDoAWBD74flrj7mc07H4qatuQX8XnttbhLabxEWrCHt9ulaLyVhjvE2LJX/eCw6ncGmLOiVpUd04wpDfgUtz0edtqzBJw4/LKS5fh53+br+NtBiGoIThbOuJihG9kml7ioQQoMfaCP2WFhvzYJnLAyjm7tbSm0MdV5XeaK3RC1Mm1eH1kYEg/w==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eRKdf7KKkrxDGMwsu5FSTEHYAtfqQdnkVt065obFHAna4G2DD7WoQe6BjMdHo3KRNCko9Lq490YvTSElJwVlp2RnzF3cLgE3pElH7XhEYvmT8dDwkttrLEQxykDyLiTKcdwo3P2TBo+PYXkGFhevVSKY+O19rpfqunxtlG2wrO8oA0i6KotvbFKQ7IBdKtai89X6D0LMDf2JDVBttrcaRs3zCYQ/vDaeeiXtUWmuRIr/KqFWLHxhSAs+ULbrjrCpZ9Ue4BRCzuwfLzz9g/G94KlGaTAelYXEDyVYwJTyE3GflOEDuRUocpzY/EvKdXGaiqrUwzkHuo9SHg36i45MUQ==
- Authentication-results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
- Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
- Delivery-date: Mon, 29 Nov 2021 15:35:54 +0000
- Ironport-data: A9a23:sEYrqaj7KaYYKaZorcB8sEh7X161gxcKZh0ujC45NGQN5FlHY01je htvUGmPOv+LZWH1fdl1Ydi/8kgFv8OBx9ZiHgVuqC9jQSwb9cadCdqndUqhZCn6wu8v7a5EA 2fyTvGacajYm1eF/k/F3oAMKRCQ7InQLlbGILes1htZGEk0F0/NtTo5w7Rg29cy0IDga++wk YiaT/P3aQfNNwFcagr424rbwP+4lK2v0N+wlgVWicFj5DcypVFMZH4sDfjZw0/DaptVBoaHq 9Prl9lVyI97EyAFUbtJmp6jGqEDryW70QKm0hK6UID66vROS7BbPg/W+5PwZG8O4whlkeydx /1Mm77pciAJb5HVv/g2Wj1JNh5nMpJZreqvzXiX6aR/zmXDenrohf5vEFs3LcsT/eMf7WNmr KJCbmpXN1ba2rzwkOnTpupE36zPKOHxO4wSoDd4xCzxBvc6W5HTBa7N4Le02R9t1psVRqqAO KL1bxIwayT+QkZ2Ym0eL8wFrO20tGvaMCxh/Qf9Sa0fvDGIkV0ZPKLWGMXRUsyHQ4NShEnwj mDJ5WPiGTkBKceSjzGC9xqEluLJ2C/2Ro8WPLm57eJxxk2ewHQJDx8bXkf9puO24ma/RNB3O 0ES4jApr6U56AqsVNaVYvGjiCfa5FhGAYMWSrBkrlHWokbJ3+qHLmkqbGd6T/x3iNYRWRcj8 k6soMrmOiM65dV5Vkmh3ruT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DReLxBsbr3gJxAx92utUuFJTsaFZ2IhD0JbTpzfHcGITWvUvECZe WhD4d81nCdUEVSSv7+KmgOXuDFqdGOvJX6YSQeDxpizAWVlzun5JPzDhDdh34lIn9y6IZn1V KAvx3y562lvf3+4hjA11XL55ATvNf60NNMCOGFl8BQADTxjQSDYphnRtS5zX0IidDqzGxvvM jHoh8mMcg2w3TNflutqR+o4AXk2CZG0Q6q9XaoxV/Y5eDpTjMzDMRMwahDdAHC1kYmtNZglI pWwmOwrfNsfFL9tRW4w+KNewBhl0Kyr3Znu/UUlWZjXYwXb6IUhZAD/XlSDIwLEEvBmc4a+d FVfYLhDcttABGnhyizhBgr/DXsZAV9Iv6+eDlDhiTPuAIm2EyQzCMjtboidzk7hdUAoqJ/lp b525JT5cZzp/8tHNFA7dg6ML6K4xT2MGrx2UKpUBza/fI8SjnwQ6Ce2sRA2AjtQu1P8KcP
- Ironport-sdr: xHD3hhj+UiJhUNcAMyQWh+LDAKPr0F4m4CZbU+qxvnr9rkTweD99LLn8BgQ9In7wABF/Q6vFky gh5yEG45JDUKV/7omeNXXVW55fxgs2//Bqec4CAGZvvzO/nftgl48mHEuU++fxI0UmYeC3cj+A YUFEbuP3lgqjbH9GDcIqKzTlWc2C/6uLkW8+bl3RZr76Pb/pvo5hIKP9eOhpH1DHBadBMKBmxd OaqnOrj+KU5B/gwHYQmwVIICpFw7xn9arLHjxWS0iEpLOitA3inUhLvmfIaQQKG4jR7XDsi3GZ uZ14+M14+H3en7Anp+hSDotL
- 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 | 62 ++++++++++++++++++++++++---------
2 files changed, 49 insertions(+), 17 deletions(-)
diff --git a/tools/include/xenguest.h b/tools/include/xenguest.h
index 2672fd043c..281454dc60 100644
--- a/tools/include/xenguest.h
+++ b/tools/include/xenguest.h
@@ -817,6 +817,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 859c885c15..bcbf9576c4 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -432,6 +432,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);
@@ -496,23 +497,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);
- p->feat.hle = test_bit(X86_FEATURE_HLE, host_featureset);
- p->feat.rtm = test_bit(X86_FEATURE_RTM, 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, 0x8000001c);
+ policy.cpuid = *p;
+ xc_cpu_policy_make_compat_4_12(xch, &policy, di.hvm);
+ *p = policy.cpuid;
}
if ( featureset )
@@ -916,3 +903,44 @@ 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;
+ policy->cpuid.feat.hle = host->cpuid.feat.hle;
+ policy->cpuid.feat.rtm = host->cpuid.feat.rtm;
+
+ 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, 0x8000001c);
+
+ out:
+ xc_cpu_policy_destroy(host);
+ return rc;
+}
--
2.33.0
|