From patchwork Tue Dec 15 04:45:26 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 67499 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nBF4jX3w019770 for ; Tue, 15 Dec 2009 04:45:34 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754298AbZLOEpb (ORCPT ); Mon, 14 Dec 2009 23:45:31 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754621AbZLOEpa (ORCPT ); Mon, 14 Dec 2009 23:45:30 -0500 Received: from mga09.intel.com ([134.134.136.24]:59874 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753624AbZLOEp3 (ORCPT ); Mon, 14 Dec 2009 23:45:29 -0500 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 14 Dec 2009 20:44:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.47,398,1257148800"; d="scan'208";a="578936680" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.36.76]) by orsmga001.jf.intel.com with ESMTP; 14 Dec 2009 20:45:09 -0800 Received: from yasker by syang10-desktop with local (Exim 4.69) (envelope-from ) id 1NKPHr-0001nc-HO; Tue, 15 Dec 2009 12:45:27 +0800 From: Sheng Yang To: Marcelo Tosatti , Avi Kivity Cc: kvm@vger.kernel.org, Sheng Yang Subject: [PATCH] KVM: VMX: Trap and invalid MWAIT/MONITOR instruction Date: Tue, 15 Dec 2009 12:45:26 +0800 Message-Id: <1260852326-6890-1-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.6.3.3 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 2b49454..8f6b011 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -251,6 +251,7 @@ enum vmcs_field { #define EXIT_REASON_MSR_READ 31 #define EXIT_REASON_MSR_WRITE 32 #define EXIT_REASON_MWAIT_INSTRUCTION 36 +#define EXIT_REASON_MONITOR_INSTRUCTION 39 #define EXIT_REASON_PAUSE_INSTRUCTION 40 #define EXIT_REASON_MCE_DURING_VMENTRY 41 #define EXIT_REASON_TPR_BELOW_THRESHOLD 43 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 9a0a2cf..da7e76b 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -1224,6 +1224,8 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf) CPU_BASED_USE_IO_BITMAPS | CPU_BASED_MOV_DR_EXITING | CPU_BASED_USE_TSC_OFFSETING | + CPU_BASED_MWAIT_EXITING | + CPU_BASED_MONITOR_EXITING | CPU_BASED_INVLPG_EXITING; opt = CPU_BASED_TPR_SHADOW | CPU_BASED_USE_MSR_BITMAPS | @@ -3415,6 +3417,12 @@ static int handle_pause(struct kvm_vcpu *vcpu) return 1; } +static int handle_invalid_op(struct kvm_vcpu *vcpu) +{ + kvm_queue_exception(vcpu, UD_VECTOR); + return 1; +} + /* * The exit handlers return 1 if the exit was handled fully and guest execution * may resume. Otherwise they set the kvm_run parameter to indicate what needs @@ -3452,6 +3460,8 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = { [EXIT_REASON_EPT_VIOLATION] = handle_ept_violation, [EXIT_REASON_EPT_MISCONFIG] = handle_ept_misconfig, [EXIT_REASON_PAUSE_INSTRUCTION] = handle_pause, + [EXIT_REASON_MWAIT_INSTRUCTION] = handle_invalid_op, + [EXIT_REASON_MONITOR_INSTRUCTION] = handle_invalid_op, }; static const int kvm_vmx_max_exit_handlers =