All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools/libxc: Fix the reported max_leaf values for PV guests
@ 2017-01-11 12:44 Andrew Cooper
  2017-01-11 13:41 ` Jan Beulich
  2017-01-11 14:32 ` Wei Liu
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Cooper @ 2017-01-11 12:44 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Ian Jackson, Wei Liu, Jan Beulich

When iterating through CPUID leaves to generating a policy, libxc will clip
itself at the hardcoded maxima, meaning that no data outside of the hardcoded
maxima are provided to Xen (in turn, causing Xen to return zeros if these
leaves are requested.)

The HVM code also clips the max_leaf data reported to the guest, but the PV
side didn't.

This results in a PV guest using the emulated CPUID, or via Xen using CPUID
faulting, to observe a max_leaf higher than the toolstack wants, although with
zeros being returned in the intervening leaves.

Fix the PV side to behave like the HVM side, and clip the max_leaf values in
leaf 0 and 0x80000000.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>

This should be backported to stable trees.

Discovered during my hypervisor-side work which does properly clip the
max_leaf values reported, at which point my diff against the guest-observable
CPUID information at the beginning of the series suddenly became non-zero.
---
 tools/libxc/xc_cpuid_x86.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c
index e9e3691..b32001b3 100644
--- a/tools/libxc/xc_cpuid_x86.c
+++ b/tools/libxc/xc_cpuid_x86.c
@@ -615,6 +615,11 @@ static void xc_cpuid_pv_policy(xc_interface *xch,
 {
     switch ( input[0] )
     {
+    case 0x00000000:
+        if ( regs[0] > DEF_MAX_BASE )
+            regs[0] = DEF_MAX_BASE;
+        break;
+
     case 0x00000001:
     {
         /* Host topology exposed to PV guest.  Provide host value. */
@@ -655,6 +660,16 @@ static void xc_cpuid_pv_policy(xc_interface *xch,
         xc_cpuid_config_xsave(xch, info, input, regs);
         break;
 
+    case 0x80000000:
+    {
+        unsigned int max = info->vendor == VENDOR_AMD
+            ? DEF_MAX_AMDEXT : DEF_MAX_INTELEXT;
+
+        if ( regs[0] > max )
+            regs[0] = max;
+        break;
+    }
+
     case 0x80000001:
     {
         /* Host topology exposed to PV guest.  Provide host CMP_LEGACY value. */
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* Re: [PATCH] tools/libxc: Fix the reported max_leaf values for PV guests
  2017-01-11 12:44 [PATCH] tools/libxc: Fix the reported max_leaf values for PV guests Andrew Cooper
@ 2017-01-11 13:41 ` Jan Beulich
  2017-01-11 14:32 ` Wei Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2017-01-11 13:41 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Ian Jackson, Wei Liu, Xen-devel

>>> On 11.01.17 at 13:44, <andrew.cooper3@citrix.com> wrote:
> When iterating through CPUID leaves to generating a policy, libxc will clip
> itself at the hardcoded maxima, meaning that no data outside of the hardcoded
> maxima are provided to Xen (in turn, causing Xen to return zeros if these
> leaves are requested.)
> 
> The HVM code also clips the max_leaf data reported to the guest, but the PV
> side didn't.
> 
> This results in a PV guest using the emulated CPUID, or via Xen using CPUID
> faulting, to observe a max_leaf higher than the toolstack wants, although with
> zeros being returned in the intervening leaves.
> 
> Fix the PV side to behave like the HVM side, and clip the max_leaf values in
> leaf 0 and 0x80000000.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

* Re: [PATCH] tools/libxc: Fix the reported max_leaf values for PV guests
  2017-01-11 12:44 [PATCH] tools/libxc: Fix the reported max_leaf values for PV guests Andrew Cooper
  2017-01-11 13:41 ` Jan Beulich
@ 2017-01-11 14:32 ` Wei Liu
  1 sibling, 0 replies; 3+ messages in thread
From: Wei Liu @ 2017-01-11 14:32 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Wei Liu, Ian Jackson, Jan Beulich, Xen-devel

On Wed, Jan 11, 2017 at 12:44:41PM +0000, Andrew Cooper wrote:
> When iterating through CPUID leaves to generating a policy, libxc will clip
> itself at the hardcoded maxima, meaning that no data outside of the hardcoded
> maxima are provided to Xen (in turn, causing Xen to return zeros if these
> leaves are requested.)
> 
> The HVM code also clips the max_leaf data reported to the guest, but the PV
> side didn't.
> 
> This results in a PV guest using the emulated CPUID, or via Xen using CPUID
> faulting, to observe a max_leaf higher than the toolstack wants, although with
> zeros being returned in the intervening leaves.
> 
> Fix the PV side to behave like the HVM side, and clip the max_leaf values in
> leaf 0 and 0x80000000.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Acked-by: Wei Liu <wei.liu2@citrix.com>

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

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

end of thread, other threads:[~2017-01-11 14:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-11 12:44 [PATCH] tools/libxc: Fix the reported max_leaf values for PV guests Andrew Cooper
2017-01-11 13:41 ` Jan Beulich
2017-01-11 14:32 ` Wei Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.