]> xenbits.xensource.com Git - xen.git/commitdiff
Fix PV CPUID virtualization of XSave
authorShan Haitao <haitao.shan@intel.com>
Wed, 7 Mar 2012 07:55:10 +0000 (07:55 +0000)
committerShan Haitao <haitao.shan@intel.com>
Wed, 7 Mar 2012 07:55:10 +0000 (07:55 +0000)
The patch will fix XSave CPUID virtualization for PV guests. The XSave
area size returned by CPUID leaf D is changed dynamically depending on
the XCR0. Tools/libxc only assigns a static value. The fix will adjust
xsave area size during runtime.

Note: This fix is already in HVM cpuid virtualization. And Dom0 is not
affected, either.

Signed-off-by: Shan Haitao <haitao.shan@intel.com>
xen-unstable changeset:   23853:b78235de5c64
xen-unstable date:        Sun Sep 18 00:01:58 2011 +0100

x86: Further fixes for xsave leaf in pv_cpuid().

Signed-off-by: Shan Haitao <haitao.shan@intel.com>
Committed-by: Keir Fraser <keir@xen.org>
xen-unstable changeset:   23955:bbde1453cbd9
xen-unstable date:        Thu Oct 13 15:58:55 2011 +0100

xen/arch/x86/hvm/hvm.c
xen/arch/x86/traps.c

index 4c9b874c2cf8d1e7f1666f67790c27faa5531506..b7d6ffa163c83b96210e945239e95858206d566d 100644 (file)
@@ -2230,7 +2230,7 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx,
         {
             /* reset EBX to default value first */
             *ebx = XSAVE_AREA_MIN_SIZE; 
-            for ( sub_leaf = 2; sub_leaf < 64; sub_leaf++ )
+            for ( sub_leaf = 2; sub_leaf < 63; sub_leaf++ )
             {
                 if ( !(v->arch.xcr0 & (1ULL << sub_leaf)) )
                     continue;
index b8abd3781df1f87e83a397ba9c5cc4f9c06aef1c..00837d468a3289a688ed1efae0f1852b1792111c 100644 (file)
@@ -734,8 +734,34 @@ static void pv_cpuid(struct cpu_user_regs *regs)
 
     if ( current->domain->domain_id != 0 )
     {
+        unsigned int cpuid_leaf = a, sub_leaf = c;
+
         if ( !cpuid_hypervisor_leaves(a, c, &a, &b, &c, &d) )
             domain_cpuid(current->domain, a, c, &a, &b, &c, &d);
+
+        switch ( cpuid_leaf )
+        {
+        case 0xd:
+        {
+            unsigned int _eax, _ebx, _ecx, _edx;
+            /* EBX value of main leaf 0 depends on enabled xsave features */
+            if ( sub_leaf == 0 && current->arch.xcr0 )
+            {
+                /* reset EBX to default value first */
+                b = XSAVE_AREA_MIN_SIZE;
+                for ( sub_leaf = 2; sub_leaf < 63; sub_leaf++ )
+                {
+                    if ( !(current->arch.xcr0 & (1ULL << sub_leaf)) )
+                        continue;
+                    domain_cpuid(current->domain, cpuid_leaf, sub_leaf,
+                                 &_eax, &_ebx, &_ecx, &_edx);
+                    if ( (_eax + _ebx) > b )
+                        b = _eax + _ebx;
+                }
+            }
+        break;
+        }
+        }
         goto out;
     }