xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] x86/cpuid: do not expand max leaves on restore
@ 2021-04-23 13:17 Roger Pau Monne
  2021-04-23 13:25 ` Jan Beulich
  0 siblings, 1 reply; 2+ messages in thread
From: Roger Pau Monne @ 2021-04-23 13:17 UTC (permalink / raw)
  To: xen-devel; +Cc: Roger Pau Monne, Ian Jackson, Wei Liu, Andrew Cooper

When restoring limit the maximum leaves to the ones supported by Xen
4.12 in order to not expand the maximum leaves a guests sees. Note
this is unlikely to cause real issues.

Guests restored from Xen versions 4.13 or greater will contain CPUID
data on the stream that will override the values set by
xc_cpuid_apply_policy.

Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 - Fix commit message.
 - Adjust max feature subleaf to 0.
 - Move and amend comments.
---
 tools/libs/guest/xg_cpuid_x86.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c
index 5ea69ad3d51..bf9a3750b58 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -498,18 +498,23 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
         goto out;
     }
 
-    /*
-     * Account for feature which have been disabled by default since Xen 4.13,
-     * so migrated-in VM's don't risk seeing features disappearing.
-     */
     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);
     }
 
     if ( featureset )
-- 
2.30.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] x86/cpuid: do not expand max leaves on restore
  2021-04-23 13:17 [PATCH v2] x86/cpuid: do not expand max leaves on restore Roger Pau Monne
@ 2021-04-23 13:25 ` Jan Beulich
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Beulich @ 2021-04-23 13:25 UTC (permalink / raw)
  To: Roger Pau Monne; +Cc: Ian Jackson, Wei Liu, Andrew Cooper, xen-devel

On 23.04.2021 15:17, Roger Pau Monne wrote:
> When restoring limit the maximum leaves to the ones supported by Xen
> 4.12 in order to not expand the maximum leaves a guests sees. Note
> this is unlikely to cause real issues.
> 
> Guests restored from Xen versions 4.13 or greater will contain CPUID
> data on the stream that will override the values set by
> xc_cpuid_apply_policy.
> 
> Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>

Thanks, looks plausible to me, so
Acked-by: Jan Beulich <jbeulich@suse.com>

Jan


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-23 13:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-23 13:17 [PATCH v2] x86/cpuid: do not expand max leaves on restore Roger Pau Monne
2021-04-23 13:25 ` Jan Beulich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).