Skip to contentSkip to conversation

x86/hvm: Conditionally leave CPUID Faulting active in HVM context

PATCH In review Andrew Cooper 3 participants 4 messages Jan 16, 2017 – Jan 24, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hvm: Conditionally leave CPUID Faulting active in HVM context

If the hardware supports faulting, and the guest has chosen to use it, leave faulting active in HVM context.

It is more efficient to have hardware convert CPUID to a #GP fault (which we don't intercept), than to take a VMExit and have Xen re-inject a #GP fault.

---
CC: Jan Beulich <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>

---
 xen/arch/x86/cpu/intel.c   |  5 +++--
 xen/arch/x86/hvm/vmx/vmx.c | 12 ++++++++++--
 2 files changed, 13 insertions(+), 4 deletions(-)
xen/arch/x86/cpu/intel.c +3 -2
index 2e11662..d0e380c 100644
@@ -175,8 +175,9 @@ static void intel_ctxt_switch_levelling(const struct vcpu *next)
 		 * generating the maximum full cpuid policy into Xen, at which
 		 * this problem will disappear.
 		 */
-		set_cpuid_faulting(nextd && is_pv_domain(nextd) &&
-				   !is_control_domain(nextd));
+		set_cpuid_faulting(nextd && !is_control_domain(nextd) &&
+				   (is_pv_domain(nextd) ||
+				    next->arch.cpuid_faulting));
 		return;
 	}
 
xen/arch/x86/hvm/vmx/vmx.c +10 -2
index 61925cf..19294cb 100644
@@ -2866,11 +2866,19 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)
         break;
 
     case MSR_INTEL_MISC_FEATURES_ENABLES:
+    {
+        bool old_cpuid_faulting = v->arch.cpuid_faulting;
+
         if ( msr_content & ~MSR_MISC_FEATURES_CPUID_FAULTING )
             goto gp_fault;
-        v->arch.cpuid_faulting =
-            !!(msr_content & MSR_MISC_FEATURES_CPUID_FAULTING);
+
+        v->arch.cpuid_faulting = msr_content & MSR_MISC_FEATURES_CPUID_FAULTING;
+
+        if ( cpu_has_cpuid_faulting &&
+             (old_cpuid_faulting ^ v->arch.cpuid_faulting) )
+            ctxt_switch_levelling(v);
         break;
+    }
 
     default:
         if ( passive_domain_do_wrmsr(msr, msr_content) )
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 8 lines
Quoted 1 line
Quoted 1 line · On 16.01.17 at 12:17, <[email protected]> wrote:

If the hardware supports faulting, and the guest has chosen to use it, leave faulting active in HVM context.

It is more efficient to have hardware convert CPUID to a #GP fault (which we don't intercept), than to take a VMExit and have Xen re-inject a #GP fault.

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

#2 lore raw
In reply to Andrew Cooper
Quoted 11 lines · Andrew Cooper

If the hardware supports faulting, and the guest has chosen to use it, leave faulting active in HVM context.

It is more efficient to have hardware convert CPUID to a #GP fault (which we don't intercept), than to take a VMExit and have Xen re-inject a #GP fault.

---
CC: Jan Beulich <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>

Ping VT-x ?

Quoted 37 lines
---
 xen/arch/x86/cpu/intel.c   |  5 +++--
 xen/arch/x86/hvm/vmx/vmx.c | 12 ++++++++++--
 2 files changed, 13 insertions(+), 4 deletions(-)
xen/arch/x86/cpu/intel.c +3 -2
index 2e11662..d0e380c 100644
@@ -175,8 +175,9 @@ static void intel_ctxt_switch_levelling(const struct vcpu *next)
 		 * generating the maximum full cpuid policy into Xen, at which
 		 * this problem will disappear.
 		 */
-		set_cpuid_faulting(nextd && is_pv_domain(nextd) &&
-				   !is_control_domain(nextd));
+		set_cpuid_faulting(nextd && !is_control_domain(nextd) &&
+				   (is_pv_domain(nextd) ||
+				    next->arch.cpuid_faulting));
 		return;
 	}
 
xen/arch/x86/hvm/vmx/vmx.c +4 -2
index 61925cf..19294cb 100644
@@ -2866,11 +2866,19 @@ static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content)
         break;
 
     case MSR_INTEL_MISC_FEATURES_ENABLES:
+    {
+        bool old_cpuid_faulting = v->arch.cpuid_faulting;
+
         if ( msr_content & ~MSR_MISC_FEATURES_CPUID_FAULTING )
             goto gp_fault;
-        v->arch.cpuid_faulting =
-            !!(msr_content & MSR_MISC_FEATURES_CPUID_FAULTING);
+

xen/arch/x86/hvm/vmx/vmx.c static int vmx_msr_write_intercept(unsigned int msr, uint64_t msr_content) · line 2884

Quoted 10 lines
xen/arch/x86/hvm/vmx/vmx.c +6 -0
+        v->arch.cpuid_faulting = msr_content & MSR_MISC_FEATURES_CPUID_FAULTING;
+
+        if ( cpu_has_cpuid_faulting &&
+             (old_cpuid_faulting ^ v->arch.cpuid_faulting) )
+            ctxt_switch_levelling(v);
         break;
+    }
 
     default:
         if ( passive_domain_do_wrmsr(msr, msr_content) )

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

Reviewed-by
#3 lore raw
Quoted 10 lines

From: Andrew Cooper [mailto:[email protected]]
Sent: Monday, January 23, 2017 10:41 PM

Quoted 6 lines · Andrew Cooper

If the hardware supports faulting, and the guest has chosen to use it, leave faulting active in HVM context.

It is more efficient to have hardware convert CPUID to a #GP fault (which we don't intercept), than to take a VMExit and have Xen re-inject a #GP fault.

Quoted 8 lines
Quoted 5 lines

---
CC: Jan Beulich <[email protected]>
CC: Jun Nakajima <[email protected]>
CC: Kevin Tian <[email protected]>

Ping VT-x ?

sorry overlooked this one:

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