All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/PV: hide features dependent on XSAVE when booted with "no-xsave"
@ 2015-11-27 11:05 Jan Beulich
  2015-11-27 15:05 ` Andrew Cooper
  0 siblings, 1 reply; 12+ messages in thread
From: Jan Beulich @ 2015-11-27 11:05 UTC (permalink / raw)
  To: xen-devel; +Cc: Andrew Cooper, Keir Fraser

[-- Attachment #1: Type: text/plain, Size: 3758 bytes --]

... or when the guest has the XSAVE feature hidden by CPUID policy.
Not doing so is at best confusing to guests.

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

--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -827,18 +827,22 @@ void pv_cpuid(struct cpu_user_regs *regs
     uint32_t a, b, c, d;
     struct vcpu *curr = current;
     struct domain *currd = curr->domain;
+    bool_t guest_has_xsave = cpu_has_xsave;
 
     a = regs->eax;
-    b = regs->ebx;
     c = regs->ecx;
-    d = regs->edx;
 
     if ( !is_control_domain(currd) && !is_hardware_domain(currd) )
     {
         unsigned int cpuid_leaf = a, sub_leaf = c;
 
-        if ( !cpuid_hypervisor_leaves(a, c, &a, &b, &c, &d) )
-            domain_cpuid(currd, a, c, &a, &b, &c, &d);
+        if ( guest_has_xsave )
+        {
+            domain_cpuid(currd, 1, 0, &d, &d, &c, &d);
+            if ( !(c & cpufeat_mask(X86_FEATURE_XSAVE)) )
+                guest_has_xsave = 0;
+        }
+        domain_cpuid(currd, a, sub_leaf, &a, &b, &c, &d);
 
         switch ( cpuid_leaf )
         {
@@ -860,13 +864,12 @@ void pv_cpuid(struct cpu_user_regs *regs
                         b = _eax + _ebx;
                 }
             }
-            goto xstate;
+            break;
         }
         }
-        goto out;
     }
-
-    cpuid_count(a, c, &a, &b, &c, &d);
+    else
+        cpuid_count(a, c, &a, &b, &c, &d);
 
     if ( (regs->eax & 0x7fffffff) == 0x00000001 )
     {
@@ -907,11 +910,11 @@ void pv_cpuid(struct cpu_user_regs *regs
         __clear_bit(X86_FEATURE_PDCM % 32, &c);
         __clear_bit(X86_FEATURE_PCID % 32, &c);
         __clear_bit(X86_FEATURE_DCA % 32, &c);
-        if ( !cpu_has_xsave )
-        {
-            __clear_bit(X86_FEATURE_XSAVE % 32, &c);
-            __clear_bit(X86_FEATURE_AVX % 32, &c);
-        }
+        if ( !guest_has_xsave )
+            c &= ~(cpufeat_mask(X86_FEATURE_XSAVE) |
+                   cpufeat_mask(X86_FEATURE_OSXSAVE) |
+                   cpufeat_mask(X86_FEATURE_AVX) |
+                   cpufeat_mask(X86_FEATURE_F16C));
         if ( !cpu_has_apic )
            __clear_bit(X86_FEATURE_X2APIC % 32, &c);
         __set_bit(X86_FEATURE_HYPERVISOR % 32, &c);
@@ -921,7 +924,7 @@ void pv_cpuid(struct cpu_user_regs *regs
         if ( regs->_ecx == 0 )
             b &= (cpufeat_mask(X86_FEATURE_BMI1) |
                   cpufeat_mask(X86_FEATURE_HLE)  |
-                  cpufeat_mask(X86_FEATURE_AVX2) |
+                  (guest_has_xsave ? cpufeat_mask(X86_FEATURE_AVX2) : 0) |
                   cpufeat_mask(X86_FEATURE_BMI2) |
                   cpufeat_mask(X86_FEATURE_ERMS) |
                   cpufeat_mask(X86_FEATURE_RTM)  |
@@ -934,8 +937,7 @@ void pv_cpuid(struct cpu_user_regs *regs
         break;
 
     case XSTATE_CPUID:
-    xstate:
-        if ( !cpu_has_xsave )
+        if ( !guest_has_xsave )
             goto unsupported;
         if ( regs->_ecx == 1 )
         {
@@ -966,6 +968,9 @@ void pv_cpuid(struct cpu_user_regs *regs
         __clear_bit(X86_FEATURE_SKINIT % 32, &c);
         __clear_bit(X86_FEATURE_WDT % 32, &c);
         __clear_bit(X86_FEATURE_LWP % 32, &c);
+        if ( !guest_has_xsave )
+            c &= ~(cpufeat_mask(X86_FEATURE_XOP) |
+                   cpufeat_mask(X86_FEATURE_FMA4));
         __clear_bit(X86_FEATURE_NODEID_MSR % 32, &c);
         __clear_bit(X86_FEATURE_TOPOEXT % 32, &c);
         __clear_bit(X86_FEATURE_MWAITX % 32, &c);
@@ -989,7 +994,6 @@ void pv_cpuid(struct cpu_user_regs *regs
         break;
     }
 
- out:
     /* VPMU may decide to modify some of the leaves */
     vpmu_do_cpuid(regs->eax, &a, &b, &c, &d);
 




[-- Attachment #2: x86-PV-hide-AVX2-without-XSAVE.patch --]
[-- Type: text/plain, Size: 3824 bytes --]

x86/PV: hide features dependent on XSAVE when booted with "no-xsave"

... or when the guest has the XSAVE feature hidden by CPUID policy.
Not doing so is at best confusing to guests.

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

--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -827,18 +827,22 @@ void pv_cpuid(struct cpu_user_regs *regs
     uint32_t a, b, c, d;
     struct vcpu *curr = current;
     struct domain *currd = curr->domain;
+    bool_t guest_has_xsave = cpu_has_xsave;
 
     a = regs->eax;
-    b = regs->ebx;
     c = regs->ecx;
-    d = regs->edx;
 
     if ( !is_control_domain(currd) && !is_hardware_domain(currd) )
     {
         unsigned int cpuid_leaf = a, sub_leaf = c;
 
-        if ( !cpuid_hypervisor_leaves(a, c, &a, &b, &c, &d) )
-            domain_cpuid(currd, a, c, &a, &b, &c, &d);
+        if ( guest_has_xsave )
+        {
+            domain_cpuid(currd, 1, 0, &d, &d, &c, &d);
+            if ( !(c & cpufeat_mask(X86_FEATURE_XSAVE)) )
+                guest_has_xsave = 0;
+        }
+        domain_cpuid(currd, a, sub_leaf, &a, &b, &c, &d);
 
         switch ( cpuid_leaf )
         {
@@ -860,13 +864,12 @@ void pv_cpuid(struct cpu_user_regs *regs
                         b = _eax + _ebx;
                 }
             }
-            goto xstate;
+            break;
         }
         }
-        goto out;
     }
-
-    cpuid_count(a, c, &a, &b, &c, &d);
+    else
+        cpuid_count(a, c, &a, &b, &c, &d);
 
     if ( (regs->eax & 0x7fffffff) == 0x00000001 )
     {
@@ -907,11 +910,11 @@ void pv_cpuid(struct cpu_user_regs *regs
         __clear_bit(X86_FEATURE_PDCM % 32, &c);
         __clear_bit(X86_FEATURE_PCID % 32, &c);
         __clear_bit(X86_FEATURE_DCA % 32, &c);
-        if ( !cpu_has_xsave )
-        {
-            __clear_bit(X86_FEATURE_XSAVE % 32, &c);
-            __clear_bit(X86_FEATURE_AVX % 32, &c);
-        }
+        if ( !guest_has_xsave )
+            c &= ~(cpufeat_mask(X86_FEATURE_XSAVE) |
+                   cpufeat_mask(X86_FEATURE_OSXSAVE) |
+                   cpufeat_mask(X86_FEATURE_AVX) |
+                   cpufeat_mask(X86_FEATURE_F16C));
         if ( !cpu_has_apic )
            __clear_bit(X86_FEATURE_X2APIC % 32, &c);
         __set_bit(X86_FEATURE_HYPERVISOR % 32, &c);
@@ -921,7 +924,7 @@ void pv_cpuid(struct cpu_user_regs *regs
         if ( regs->_ecx == 0 )
             b &= (cpufeat_mask(X86_FEATURE_BMI1) |
                   cpufeat_mask(X86_FEATURE_HLE)  |
-                  cpufeat_mask(X86_FEATURE_AVX2) |
+                  (guest_has_xsave ? cpufeat_mask(X86_FEATURE_AVX2) : 0) |
                   cpufeat_mask(X86_FEATURE_BMI2) |
                   cpufeat_mask(X86_FEATURE_ERMS) |
                   cpufeat_mask(X86_FEATURE_RTM)  |
@@ -934,8 +937,7 @@ void pv_cpuid(struct cpu_user_regs *regs
         break;
 
     case XSTATE_CPUID:
-    xstate:
-        if ( !cpu_has_xsave )
+        if ( !guest_has_xsave )
             goto unsupported;
         if ( regs->_ecx == 1 )
         {
@@ -966,6 +968,9 @@ void pv_cpuid(struct cpu_user_regs *regs
         __clear_bit(X86_FEATURE_SKINIT % 32, &c);
         __clear_bit(X86_FEATURE_WDT % 32, &c);
         __clear_bit(X86_FEATURE_LWP % 32, &c);
+        if ( !guest_has_xsave )
+            c &= ~(cpufeat_mask(X86_FEATURE_XOP) |
+                   cpufeat_mask(X86_FEATURE_FMA4));
         __clear_bit(X86_FEATURE_NODEID_MSR % 32, &c);
         __clear_bit(X86_FEATURE_TOPOEXT % 32, &c);
         __clear_bit(X86_FEATURE_MWAITX % 32, &c);
@@ -989,7 +994,6 @@ void pv_cpuid(struct cpu_user_regs *regs
         break;
     }
 
- out:
     /* VPMU may decide to modify some of the leaves */
     vpmu_do_cpuid(regs->eax, &a, &b, &c, &d);
 

[-- Attachment #3: Type: text/plain, Size: 126 bytes --]

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

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

end of thread, other threads:[~2015-11-30 18:02 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-27 11:05 [PATCH] x86/PV: hide features dependent on XSAVE when booted with "no-xsave" Jan Beulich
2015-11-27 15:05 ` Andrew Cooper
2015-11-30 10:01   ` Jan Beulich
2015-11-30 10:46     ` Andrew Cooper
2015-11-30 11:08       ` Jan Beulich
2015-11-30 11:10         ` Andrew Cooper
2015-11-30 11:30           ` Jan Beulich
2015-11-30 13:36             ` Andrew Cooper
2015-11-30 15:22               ` Jan Beulich
2015-11-30 15:38                 ` Andrew Cooper
2015-11-30 16:00                   ` Jan Beulich
2015-11-30 18:01                     ` Andrew Cooper

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.