Skip to contentSkip to conversation

tools/libxc: Fix the reported max_leaf values for PV guests

PATCH In review Andrew Cooper 3 participants 3 messages Jan 11, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/libxc: Fix the reported max_leaf values for PV guests

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.

---
CC: Jan Beulich <[email protected]>
CC: Ian Jackson <[email protected]>
CC: Wei Liu <[email protected]>

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(+)
tools/libxc/xc_cpuid_x86.c +15 -0
index e9e3691..b32001b3 100644
@@ -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. */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 11.01.17 at 13:44, <[email protected]> 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.

Quoted 8 lines

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.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Acked-by on v1 1/1
#2 lore raw
In reply to Andrew Cooper
Quoted 8 lines · Andrew Cooper

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.

Quoted 8 lines

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.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel