diff options
author | Gabriel L. Somlo <gsomlo@gmail.com> | 2014-05-07 16:52:13 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2014-05-08 09:40:49 -0400 |
commit | 87c00572ba05aa8c9db118da75c608f47eb10b9e (patch) | |
tree | 484e8cc1da97c7302c739364ee0af9bd68cebb0e /arch/x86/kvm | |
parent | b63cf42fd1d8c18fab71222321aaf356f63089c9 (diff) |
kvm: x86: emulate monitor and mwait instructions as nop
Treat monitor and mwait instructions as nop, which is architecturally
correct (but inefficient) behavior. We do this to prevent misbehaving
guests (e.g. OS X <= 10.7) from crashing after they fail to check for
monitor/mwait availability via cpuid.
Since mwait-based idle loops relying on these nop-emulated instructions
would keep the host CPU pegged at 100%, do NOT advertise their presence
via cpuid, to prevent compliant guests from using them inadvertently.
Signed-off-by: Gabriel L. Somlo <somlo@cmu.edu>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm')
-rw-r--r-- | arch/x86/kvm/cpuid.c | 2 | ||||
-rw-r--r-- | arch/x86/kvm/svm.c | 28 | ||||
-rw-r--r-- | arch/x86/kvm/vmx.c | 20 |
3 files changed, 38 insertions, 12 deletions
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 17b42fabc842..38a0afe83c6b 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c | |||
@@ -283,6 +283,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, | |||
283 | 0 /* Reserved */ | f_lm | F(3DNOWEXT) | F(3DNOW); | 283 | 0 /* Reserved */ | f_lm | F(3DNOWEXT) | F(3DNOW); |
284 | /* cpuid 1.ecx */ | 284 | /* cpuid 1.ecx */ |
285 | const u32 kvm_supported_word4_x86_features = | 285 | const u32 kvm_supported_word4_x86_features = |
286 | /* NOTE: MONITOR (and MWAIT) are emulated as NOP, | ||
287 | * but *not* advertised to guests via CPUID ! */ | ||
286 | F(XMM3) | F(PCLMULQDQ) | 0 /* DTES64, MONITOR */ | | 288 | F(XMM3) | F(PCLMULQDQ) | 0 /* DTES64, MONITOR */ | |
287 | 0 /* DS-CPL, VMX, SMX, EST */ | | 289 | 0 /* DS-CPL, VMX, SMX, EST */ | |
288 | 0 /* TM2 */ | F(SSSE3) | 0 /* CNXT-ID */ | 0 /* Reserved */ | | 290 | 0 /* TM2 */ | F(SSSE3) | 0 /* CNXT-ID */ | 0 /* Reserved */ | |
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 7f4f9c2badae..0b7d58d0c5fb 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c | |||
@@ -2770,12 +2770,6 @@ static int xsetbv_interception(struct vcpu_svm *svm) | |||
2770 | return 1; | 2770 | return 1; |
2771 | } | 2771 | } |
2772 | 2772 | ||
2773 | static int invalid_op_interception(struct vcpu_svm *svm) | ||
2774 | { | ||
2775 | kvm_queue_exception(&svm->vcpu, UD_VECTOR); | ||
2776 | return 1; | ||
2777 | } | ||
2778 | |||
2779 | static int task_switch_interception(struct vcpu_svm *svm) | 2773 | static int task_switch_interception(struct vcpu_svm *svm) |
2780 | { | 2774 | { |
2781 | u16 tss_selector; | 2775 | u16 tss_selector; |
@@ -3287,6 +3281,24 @@ static int pause_interception(struct vcpu_svm *svm) | |||
3287 | return 1; | 3281 | return 1; |
3288 | } | 3282 | } |
3289 | 3283 | ||
3284 | static int nop_interception(struct vcpu_svm *svm) | ||
3285 | { | ||
3286 | skip_emulated_instruction(&(svm->vcpu)); | ||
3287 | return 1; | ||
3288 | } | ||
3289 | |||
3290 | static int monitor_interception(struct vcpu_svm *svm) | ||
3291 | { | ||
3292 | printk_once(KERN_WARNING "kvm: MONITOR instruction emulated as NOP!\n"); | ||
3293 | return nop_interception(svm); | ||
3294 | } | ||
3295 | |||
3296 | static int mwait_interception(struct vcpu_svm *svm) | ||
3297 | { | ||
3298 | printk_once(KERN_WARNING "kvm: MWAIT instruction emulated as NOP!\n"); | ||
3299 | return nop_interception(svm); | ||
3300 | } | ||
3301 | |||
3290 | static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = { | 3302 | static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = { |
3291 | [SVM_EXIT_READ_CR0] = cr_interception, | 3303 | [SVM_EXIT_READ_CR0] = cr_interception, |
3292 | [SVM_EXIT_READ_CR3] = cr_interception, | 3304 | [SVM_EXIT_READ_CR3] = cr_interception, |
@@ -3344,8 +3356,8 @@ static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = { | |||
3344 | [SVM_EXIT_CLGI] = clgi_interception, | 3356 | [SVM_EXIT_CLGI] = clgi_interception, |
3345 | [SVM_EXIT_SKINIT] = skinit_interception, | 3357 | [SVM_EXIT_SKINIT] = skinit_interception, |
3346 | [SVM_EXIT_WBINVD] = emulate_on_interception, | 3358 | [SVM_EXIT_WBINVD] = emulate_on_interception, |
3347 | [SVM_EXIT_MONITOR] = invalid_op_interception, | 3359 | [SVM_EXIT_MONITOR] = monitor_interception, |
3348 | [SVM_EXIT_MWAIT] = invalid_op_interception, | 3360 | [SVM_EXIT_MWAIT] = mwait_interception, |
3349 | [SVM_EXIT_XSETBV] = xsetbv_interception, | 3361 | [SVM_EXIT_XSETBV] = xsetbv_interception, |
3350 | [SVM_EXIT_NPF] = pf_interception, | 3362 | [SVM_EXIT_NPF] = pf_interception, |
3351 | }; | 3363 | }; |
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 61e818d80732..6f7463f53ed9 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -5650,12 +5650,24 @@ static int handle_pause(struct kvm_vcpu *vcpu) | |||
5650 | return 1; | 5650 | return 1; |
5651 | } | 5651 | } |
5652 | 5652 | ||
5653 | static int handle_invalid_op(struct kvm_vcpu *vcpu) | 5653 | static int handle_nop(struct kvm_vcpu *vcpu) |
5654 | { | 5654 | { |
5655 | kvm_queue_exception(vcpu, UD_VECTOR); | 5655 | skip_emulated_instruction(vcpu); |
5656 | return 1; | 5656 | return 1; |
5657 | } | 5657 | } |
5658 | 5658 | ||
5659 | static int handle_mwait(struct kvm_vcpu *vcpu) | ||
5660 | { | ||
5661 | printk_once(KERN_WARNING "kvm: MWAIT instruction emulated as NOP!\n"); | ||
5662 | return handle_nop(vcpu); | ||
5663 | } | ||
5664 | |||
5665 | static int handle_monitor(struct kvm_vcpu *vcpu) | ||
5666 | { | ||
5667 | printk_once(KERN_WARNING "kvm: MONITOR instruction emulated as NOP!\n"); | ||
5668 | return handle_nop(vcpu); | ||
5669 | } | ||
5670 | |||
5659 | /* | 5671 | /* |
5660 | * To run an L2 guest, we need a vmcs02 based on the L1-specified vmcs12. | 5672 | * To run an L2 guest, we need a vmcs02 based on the L1-specified vmcs12. |
5661 | * We could reuse a single VMCS for all the L2 guests, but we also want the | 5673 | * We could reuse a single VMCS for all the L2 guests, but we also want the |
@@ -6617,8 +6629,8 @@ static int (*const kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = { | |||
6617 | [EXIT_REASON_EPT_VIOLATION] = handle_ept_violation, | 6629 | [EXIT_REASON_EPT_VIOLATION] = handle_ept_violation, |
6618 | [EXIT_REASON_EPT_MISCONFIG] = handle_ept_misconfig, | 6630 | [EXIT_REASON_EPT_MISCONFIG] = handle_ept_misconfig, |
6619 | [EXIT_REASON_PAUSE_INSTRUCTION] = handle_pause, | 6631 | [EXIT_REASON_PAUSE_INSTRUCTION] = handle_pause, |
6620 | [EXIT_REASON_MWAIT_INSTRUCTION] = handle_invalid_op, | 6632 | [EXIT_REASON_MWAIT_INSTRUCTION] = handle_mwait, |
6621 | [EXIT_REASON_MONITOR_INSTRUCTION] = handle_invalid_op, | 6633 | [EXIT_REASON_MONITOR_INSTRUCTION] = handle_monitor, |
6622 | [EXIT_REASON_INVEPT] = handle_invept, | 6634 | [EXIT_REASON_INVEPT] = handle_invept, |
6623 | }; | 6635 | }; |
6624 | 6636 | ||