From patchwork Wed Jun 18 18:46:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabriel L. Somlo" X-Patchwork-Id: 4378911 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B68CE9F433 for ; Wed, 18 Jun 2014 18:46:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C6BF92037B for ; Wed, 18 Jun 2014 18:46:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C5AF420377 for ; Wed, 18 Jun 2014 18:46:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754264AbaFRSqG (ORCPT ); Wed, 18 Jun 2014 14:46:06 -0400 Received: from mail-qc0-f180.google.com ([209.85.216.180]:34124 "EHLO mail-qc0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751349AbaFRSqE (ORCPT ); Wed, 18 Jun 2014 14:46:04 -0400 Received: by mail-qc0-f180.google.com with SMTP id r5so1193151qcx.39 for ; Wed, 18 Jun 2014 11:46:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:in-reply-to:user-agent; bh=aGqSMyIPqDClT3TWQCJI+jMUap7U/tsE7cwm4mJclgA=; b=BS4d2UXto2yBYgf4uvh/6PXzj/DwX/h7uzOqwF1Uy3+VwTa7T3nJU705rJWUi4dH4L 2s8DCXLkH9VJXY60Cu1S1cA+H1dBMzvLn5a9q5GLBpjN/4mSEV4C3hgp72tGUFLQ4Lqf BLLT1jcLdPYp9QF7Sr9GFCLwN6t2sWfs3CPG+Xy5t1sLaezzsLnLcGiUpHBeH9IR5S7C BK9Zno5zRTm/slqp38kX7Q4K1gt5sGlBKSl7gGqmTpU9nZLa6PR8/mABTfJdmKmzqJB7 m0Py0XqRb5vd4vd8vJ0y3T1TJo11pZe4vBeawNAQrVOCKB7si9pGMpk3Tnkujq3xZTPe uXyw== X-Received: by 10.140.26.179 with SMTP id 48mr5843489qgv.51.1403117163761; Wed, 18 Jun 2014 11:46:03 -0700 (PDT) Received: from ERROL.INI.CMU.EDU (ERROL.INI.CMU.EDU. [128.2.16.43]) by mx.google.com with ESMTPSA id j4sm4508396qaf.31.2014.06.18.11.46.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jun 2014 11:46:03 -0700 (PDT) Date: Wed, 18 Jun 2014 14:46:01 -0400 From: "Gabriel L. Somlo" To: Eric Northup Cc: Nadav Amit , Paolo Bonzini , gleb@kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , the arch/x86 maintainers , Linux Kernel Mailing List , KVM , joro@8bytes.org, mst@redhat.com, agraf@suse.de Subject: Re: [PATCH 3/3] KVM: x86: correct mwait and monitor emulation Message-ID: <20140618184601.GE1695@ERROL.INI.CMU.EDU> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FAKE_REPLY_C, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Jun 18, 2014 at 10:59:14AM -0700, Eric Northup wrote: > On Wed, Jun 18, 2014 at 7:19 AM, Nadav Amit wrote: > > mwait and monitor are currently handled as nop. Considering this behavior, they > > should still be handled correctly, i.e., check execution conditions and generate > > exceptions when required. mwait and monitor may also be executed in real-mode > > and are not handled in that case. This patch performs the emulation of > > monitor-mwait according to Intel SDM (other than checking whether interrupt can > > be used as a break event). > > > > Signed-off-by: Nadav Amit How about this instead (details in the commit log below) ? Please let me know what you think, and if you'd prefer me to send it out as a separate patch rather than a reply to this thread. Thanks, --Gabriel From 0375a0aceb54cdbc26a6c0e5b43c46324f830ec3 Mon Sep 17 00:00:00 2001 From: "Gabriel L. Somlo" Date: Wed, 18 Jun 2014 14:39:15 -0400 Subject: [PATCH] kvm: x86: revert "emulate monitor and mwait instructions as nop" This reverts commit 87c00572ba05aa8c9db118da75c608f47eb10b9e. OS X <= 10.7.* are the only known guests which realistically required this functionality. As it turns out, OS X can be told to forego using monitor/mwait by passing it "idlehalt=0" as a kernel argument, so we're better off removing this hack from KVM altogether. Signed-off-by: Gabriel L. Somlo Acked-by: Michael S. Tsirkin --- arch/x86/kvm/cpuid.c | 2 -- arch/x86/kvm/svm.c | 8 +++----- arch/x86/kvm/vmx.c | 10 ++++------ 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 38a0afe..17b42fa 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -283,8 +283,6 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, 0 /* Reserved */ | f_lm | F(3DNOWEXT) | F(3DNOW); /* cpuid 1.ecx */ const u32 kvm_supported_word4_x86_features = - /* NOTE: MONITOR (and MWAIT) are emulated as NOP, - * but *not* advertised to guests via CPUID ! */ F(XMM3) | F(PCLMULQDQ) | 0 /* DTES64, MONITOR */ | 0 /* DS-CPL, VMX, SMX, EST */ | 0 /* TM2 */ | F(SSSE3) | 0 /* CNXT-ID */ | 0 /* Reserved */ | diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index ec8366c..0e8ef20 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -3274,7 +3274,7 @@ static int pause_interception(struct vcpu_svm *svm) return 1; } -static int nop_interception(struct vcpu_svm *svm) +static int invalid_op_interception(struct vcpu_svm *svm) { skip_emulated_instruction(&(svm->vcpu)); return 1; @@ -3282,14 +3282,12 @@ static int nop_interception(struct vcpu_svm *svm) static int monitor_interception(struct vcpu_svm *svm) { - printk_once(KERN_WARNING "kvm: MONITOR instruction emulated as NOP!\n"); - return nop_interception(svm); + return invalid_op_interception(svm); } static int mwait_interception(struct vcpu_svm *svm) { - printk_once(KERN_WARNING "kvm: MWAIT instruction emulated as NOP!\n"); - return nop_interception(svm); + return invalid_op_interception(svm); } static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = { diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 801332e..577c7df 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -5672,22 +5672,20 @@ static int handle_pause(struct kvm_vcpu *vcpu) return 1; } -static int handle_nop(struct kvm_vcpu *vcpu) +static int handle_invalid_op(struct kvm_vcpu *vcpu) { - skip_emulated_instruction(vcpu); + kvm_queue_exception(vcpu, UD_VECTOR); return 1; } static int handle_mwait(struct kvm_vcpu *vcpu) { - printk_once(KERN_WARNING "kvm: MWAIT instruction emulated as NOP!\n"); - return handle_nop(vcpu); + return handle_invalid_op(vcpu); } static int handle_monitor(struct kvm_vcpu *vcpu) { - printk_once(KERN_WARNING "kvm: MONITOR instruction emulated as NOP!\n"); - return handle_nop(vcpu); + return handle_invalid_op(vcpu); } /*