xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/cpuid: do not expand max leaves on restore
@ 2021-04-23 10:54 Roger Pau Monne
  2021-04-23 12:41 ` Jan Beulich
  0 siblings, 1 reply; 3+ messages in thread
From: Roger Pau Monne @ 2021-04-23 10:54 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.13 in order to not expand the maximum leaf 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>
---
 tools/libs/guest/xg_cpuid_x86.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x86.c
index 5ea69ad3d51..9296fdc34bd 100644
--- a/tools/libs/guest/xg_cpuid_x86.c
+++ b/tools/libs/guest/xg_cpuid_x86.c
@@ -510,6 +510,11 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
         {
             p->feat.mpx = test_bit(X86_FEATURE_MPX, host_featureset);
         }
+
+        /* Clamp maximum leaves to the supported ones on 4.13. */
+        p->basic.max_leaf = min(p->basic.max_leaf, 0xdu);
+        p->feat.max_subleaf = min(p->feat.max_subleaf, 1u);
+        p->extd.max_leaf = min(p->extd.max_leaf, 0x1cu);
     }
 
     if ( featureset )
-- 
2.30.1



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

* Re: [PATCH] x86/cpuid: do not expand max leaves on restore
  2021-04-23 10:54 [PATCH] x86/cpuid: do not expand max leaves on restore Roger Pau Monne
@ 2021-04-23 12:41 ` Jan Beulich
  2021-04-23 12:47   ` Roger Pau Monné
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2021-04-23 12:41 UTC (permalink / raw)
  To: Roger Pau Monne; +Cc: Ian Jackson, Wei Liu, Andrew Cooper, xen-devel

On 23.04.2021 12:54, Roger Pau Monne wrote:
> When restoring limit the maximum leaves to the ones supported by Xen
> 4.13 in order to not expand the maximum leaf a guests sees. Note this
> is unlikely to cause real issues.

Why 4.13 (and not 4.12) here when ...

> 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.

... 4.13 already communicates the values?

> --- a/tools/libs/guest/xg_cpuid_x86.c
> +++ b/tools/libs/guest/xg_cpuid_x86.c
> @@ -510,6 +510,11 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t domid, bool restore,
>          {
>              p->feat.mpx = test_bit(X86_FEATURE_MPX, host_featureset);
>          }
> +
> +        /* Clamp maximum leaves to the supported ones on 4.13. */

Same aspect here then. (While not being a native speaker, it
would still seem to me that flipping "supported" and "ones"
would read slightly more clearly.)

> +        p->basic.max_leaf = min(p->basic.max_leaf, 0xdu);
> +        p->feat.max_subleaf = min(p->feat.max_subleaf, 1u);
> +        p->extd.max_leaf = min(p->extd.max_leaf, 0x1cu);
>      }

With this I think the comment ahead of the enclosing if() wants
either amending or moving immediately inside the if()'s body.

Jan


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

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

On Fri, Apr 23, 2021 at 02:41:32PM +0200, Jan Beulich wrote:
> On 23.04.2021 12:54, Roger Pau Monne wrote:
> > When restoring limit the maximum leaves to the ones supported by Xen
> > 4.13 in order to not expand the maximum leaf a guests sees. Note this
> > is unlikely to cause real issues.
> 
> Why 4.13 (and not 4.12) here when ...
> 
> > 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.
> 
> ... 4.13 already communicates the values?

Urg, yes, my bad. This should have been limited to the max leaves
supported by 4.12, not 4.13.

Let me send a new version also incorporating the feedback from below.

Thanks, Roger.


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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-23 10:54 [PATCH] x86/cpuid: do not expand max leaves on restore Roger Pau Monne
2021-04-23 12:41 ` Jan Beulich
2021-04-23 12:47   ` Roger Pau Monné

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).