[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] x86 xsave: Adding back CPUID support for Xsave (version 2)



# HG changeset patch
# User Keir Fraser <keir@xxxxxxx>
# Date 1289813273 0
# Node ID 8af10bd7f2d0e9300f1bc68f7e2fb137fa839365
# Parent  388c44a636137ebed114ed314a5c599e5a467f9d
x86 xsave: Adding back CPUID support for Xsave (version 2)

XSave support via CPUID virtualization for both PV and HVM guests.

Signed-off-by: Shan Haitao <haitao.shan@xxxxxxxxx>
---
 tools/libxc/xc_cpuid_x86.c       |   30 ++++++++++++++++++++++++++----
 xen/arch/x86/hvm/hvm.c           |    7 +------
 xen/arch/x86/traps.c             |    6 +++++-
 xen/include/asm-x86/cpufeature.h |    1 +
 4 files changed, 33 insertions(+), 11 deletions(-)

diff -r 388c44a63613 -r 8af10bd7f2d0 tools/libxc/xc_cpuid_x86.c
--- a/tools/libxc/xc_cpuid_x86.c        Wed Nov 10 14:56:06 2010 +0000
+++ b/tools/libxc/xc_cpuid_x86.c        Mon Nov 15 09:27:53 2010 +0000
@@ -168,12 +168,20 @@ static void xc_cpuid_hvm_policy(
     xc_interface *xch, domid_t domid,
     const unsigned int *input, unsigned int *regs)
 {
+    DECLARE_DOMCTL;
     char brand[13];
     unsigned long pae;
-    int is_pae;
+    int is_pae, xsave_supported;
 
     xc_get_hvm_param(xch, domid, HVM_PARAM_PAE_ENABLED, &pae);
     is_pae = !!pae;
+
+    /* Detecting Xen's atitude towards XSAVE */
+    memset(&domctl, 0, sizeof(domctl));
+    domctl.cmd = XEN_DOMCTL_getvcpuextstate;
+    domctl.domain = domid;
+    do_domctl(xch, &domctl);
+    xsave_supported = (domctl.u.vcpuextstate.xfeature_mask != 0);
 
     switch ( input[0] )
     {
@@ -195,7 +203,10 @@ static void xc_cpuid_hvm_policy(
                     bitmaskof(X86_FEATURE_SSE4_1) |
                     bitmaskof(X86_FEATURE_SSE4_2) |
                     bitmaskof(X86_FEATURE_POPCNT) |
-                    bitmaskof(X86_FEATURE_AES));
+                    bitmaskof(X86_FEATURE_AES) |
+                    (xsave_supported)?
+                     (bitmaskof(X86_FEATURE_AVX) |
+                      bitmaskof(X86_FEATURE_XSAVE)) : 0);
 
         regs[2] |= bitmaskof(X86_FEATURE_HYPERVISOR);
 
@@ -280,7 +291,7 @@ static void xc_cpuid_pv_policy(
     const unsigned int *input, unsigned int *regs)
 {
     DECLARE_DOMCTL;
-    int guest_64bit, xen_64bit = hypervisor_is_64bit(xch);
+    int guest_64bit, xsave_supported, xen_64bit = hypervisor_is_64bit(xch);
     char brand[13];
 
     xc_cpuid_brand_get(brand);
@@ -290,6 +301,13 @@ static void xc_cpuid_pv_policy(
     domctl.cmd = XEN_DOMCTL_get_address_size;
     do_domctl(xch, &domctl);
     guest_64bit = (domctl.u.address_size.size == 64);
+
+    /* Detecting Xen's atitude towards XSAVE */
+    memset(&domctl, 0, sizeof(domctl));
+    domctl.cmd = XEN_DOMCTL_getvcpuextstate;
+    domctl.domain = domid;
+    do_domctl(xch, &domctl);
+    xsave_supported = (domctl.u.vcpuextstate.xfeature_mask != 0);
 
     if ( (input[0] & 0x7fffffff) == 1 )
     {
@@ -320,10 +338,14 @@ static void xc_cpuid_pv_policy(
         clear_bit(X86_FEATURE_TM2, regs[2]);
         if ( !guest_64bit )
             clear_bit(X86_FEATURE_CX16, regs[2]);
+        if ( !xsave_supported )
+        {
+            clear_bit(X86_FEATURE_XSAVE, regs[2]);
+            clear_bit(X86_FEATURE_AVX, regs[2]);
+        }
         clear_bit(X86_FEATURE_XTPR, regs[2]);
         clear_bit(X86_FEATURE_PDCM, regs[2]);
         clear_bit(X86_FEATURE_DCA, regs[2]);
-        clear_bit(X86_FEATURE_XSAVE, regs[2]);
         set_bit(X86_FEATURE_HYPERVISOR, regs[2]);
         break;
     case 0x80000001:
diff -r 388c44a63613 -r 8af10bd7f2d0 xen/arch/x86/hvm/hvm.c
--- a/xen/arch/x86/hvm/hvm.c    Wed Nov 10 14:56:06 2010 +0000
+++ b/xen/arch/x86/hvm/hvm.c    Mon Nov 15 09:27:53 2010 +0000
@@ -2089,15 +2089,10 @@ void hvm_cpuid(unsigned int input, unsig
         if ( vlapic_hw_disabled(vcpu_vlapic(v)) )
             __clear_bit(X86_FEATURE_APIC & 31, edx);
 
-        /* Fix up XSAVE and OSXSAVE. */
-        *ecx &= ~(bitmaskof(X86_FEATURE_XSAVE) |
-                  bitmaskof(X86_FEATURE_OSXSAVE));
+        /* Fix up OSXSAVE. */
         if ( cpu_has_xsave )
-        {
-            *ecx |= bitmaskof(X86_FEATURE_XSAVE);
             *ecx |= (v->arch.hvm_vcpu.guest_cr[4] & X86_CR4_OSXSAVE) ?
                      bitmaskof(X86_FEATURE_OSXSAVE) : 0;
-        }
         break;
     case 0xb:
         /* Fix the x2APIC identifier. */
diff -r 388c44a63613 -r 8af10bd7f2d0 xen/arch/x86/traps.c
--- a/xen/arch/x86/traps.c      Wed Nov 10 14:56:06 2010 +0000
+++ b/xen/arch/x86/traps.c      Mon Nov 15 09:27:53 2010 +0000
@@ -795,7 +795,11 @@ static void pv_cpuid(struct cpu_user_reg
         __clear_bit(X86_FEATURE_XTPR % 32, &c);
         __clear_bit(X86_FEATURE_PDCM % 32, &c);
         __clear_bit(X86_FEATURE_DCA % 32, &c);
-        __clear_bit(X86_FEATURE_XSAVE % 32, &c);
+        if ( !cpu_has_xsave )
+        {
+            __clear_bit(X86_FEATURE_XSAVE % 32, &c);
+            __clear_bit(X86_FEATURE_AVX % 32, &c);
+        }
         if ( !cpu_has_apic )
            __clear_bit(X86_FEATURE_X2APIC % 32, &c);
         __set_bit(X86_FEATURE_HYPERVISOR % 32, &c);
diff -r 388c44a63613 -r 8af10bd7f2d0 xen/include/asm-x86/cpufeature.h
--- a/xen/include/asm-x86/cpufeature.h  Wed Nov 10 14:56:06 2010 +0000
+++ b/xen/include/asm-x86/cpufeature.h  Mon Nov 15 09:27:53 2010 +0000
@@ -102,6 +102,7 @@
 #define X86_FEATURE_TSC_DEADLINE (4*32+24) /* "tdt" TSC Deadline Timer */
 #define X86_FEATURE_XSAVE      (4*32+26) /* XSAVE/XRSTOR/XSETBV/XGETBV */
 #define X86_FEATURE_OSXSAVE    (4*32+27) /* OSXSAVE */
+#define X86_FEATURE_AVX        (4*32+28) /* Advanced Vector Extensions */
 #define X86_FEATURE_HYPERVISOR (4*32+31) /* Running under some hypervisor */
 
 /* VIA/Cyrix/Centaur-defined CPU features, CPUID level 0xC0000001, word 5 */

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.