From patchwork Thu Jun 19 13:59:35 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: 4383371 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 DB7F39F390 for ; Thu, 19 Jun 2014 13:59:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DCA1320394 for ; Thu, 19 Jun 2014 13:59:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C357220320 for ; Thu, 19 Jun 2014 13:59:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756521AbaFSN7j (ORCPT ); Thu, 19 Jun 2014 09:59:39 -0400 Received: from mail-qg0-f50.google.com ([209.85.192.50]:36282 "EHLO mail-qg0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755195AbaFSN7i (ORCPT ); Thu, 19 Jun 2014 09:59:38 -0400 Received: by mail-qg0-f50.google.com with SMTP id j5so2111988qga.37 for ; Thu, 19 Jun 2014 06:59:37 -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:user-agent; bh=196LsKsdLYjnA1PVSsfuMICeNOdJ5txv2cQCaQXatmE=; b=0bf59GaXaMxIfzgTATUbcOSmMqyWRZlN951wSjevc0Fmm4wf8ySUB1UqRsY9vA1VFT u4lOoHW/LxXWBgAmfdlz4e2mFwT9T1lzh+JdFDQbzsv+llHG+K07ZY9tenRkoIPaNN4S xfYxYCdlyUZjSm1rRa0jK1Yz1nDzY9iG3FxeMDVhzIrOQtCHBBebHPWhXsYCuI6Ek03F +Uu6xE2RdRJczlI1u8E2ZraIH0swC50mp5YeOjRiis8rUWzIs7WOOgxp2uApsgRv8ALb BVYyAYYM3ZSZ6iliDckA63KgBfMbkG9dcKRzz9ha54HMFL2C1tfAGh/6H1GfdjWTQr1+ PYZg== X-Received: by 10.224.79.138 with SMTP id p10mr7627679qak.36.1403186377781; Thu, 19 Jun 2014 06:59:37 -0700 (PDT) Received: from ERROL.INI.CMU.EDU (ERROL.INI.CMU.EDU. [128.2.16.43]) by mx.google.com with ESMTPSA id n12sm3294538qga.9.2014.06.19.06.59.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jun 2014 06:59:37 -0700 (PDT) Date: Thu, 19 Jun 2014 09:59:35 -0400 From: "Gabriel L. Somlo" To: KVM Cc: "Michael S. Tsirkin" , Gleb Natapov , Eric Northup , Nadav Amit , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , the arch/x86 maintainers , Linux Kernel Mailing List , nadav.amit@gmail.com, joro@8bytes.org, agraf@suse.de Subject: [PATCH] Revert "kvm: x86: emulate monitor and mwait instructions as nop" Message-ID: <20140619135935.GG1695@ERROL.INI.CMU.EDU> MIME-Version: 1.0 Content-Disposition: inline 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=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, 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 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, at least for now. Signed-off-by: Gabriel L. Somlo Acked-by: Michael S. Tsirkin --- OK, here's the formal proposal to revert my original monitor/mwait hack... I wish I knew about the "idlehalt=0" before I submitted it, but such is life. Depending on how those of you higher up the food chain feel, I can tolerate leaving the hack in if it's never on by default (i.e. no CPUID advertisement), but would feel better if we could simply undo this until we have a better solution, something less controversial... Thanks, and sorry for all the noise, Gabriel arch/x86/kvm/cpuid.c | 2 -- arch/x86/kvm/svm.c | 28 ++++++++-------------------- arch/x86/kvm/vmx.c | 20 ++++---------------- 3 files changed, 12 insertions(+), 38 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..6b88b6a 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -2763,6 +2763,12 @@ static int xsetbv_interception(struct vcpu_svm *svm) return 1; } +static int invalid_op_interception(struct vcpu_svm *svm) +{ + kvm_queue_exception(&svm->vcpu, UD_VECTOR); + return 1; +} + static int task_switch_interception(struct vcpu_svm *svm) { u16 tss_selector; @@ -3274,24 +3280,6 @@ static int pause_interception(struct vcpu_svm *svm) return 1; } -static int nop_interception(struct vcpu_svm *svm) -{ - skip_emulated_instruction(&(svm->vcpu)); - return 1; -} - -static int monitor_interception(struct vcpu_svm *svm) -{ - printk_once(KERN_WARNING "kvm: MONITOR instruction emulated as NOP!\n"); - return nop_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); -} - static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = { [SVM_EXIT_READ_CR0] = cr_interception, [SVM_EXIT_READ_CR3] = cr_interception, @@ -3349,8 +3337,8 @@ static int (*const svm_exit_handlers[])(struct vcpu_svm *svm) = { [SVM_EXIT_CLGI] = clgi_interception, [SVM_EXIT_SKINIT] = skinit_interception, [SVM_EXIT_WBINVD] = emulate_on_interception, - [SVM_EXIT_MONITOR] = monitor_interception, - [SVM_EXIT_MWAIT] = mwait_interception, + [SVM_EXIT_MONITOR] = invalid_op_interception, + [SVM_EXIT_MWAIT] = invalid_op_interception, [SVM_EXIT_XSETBV] = xsetbv_interception, [SVM_EXIT_NPF] = pf_interception, }; diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 801332e..163958f 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -5672,24 +5672,12 @@ 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); -} - -static int handle_monitor(struct kvm_vcpu *vcpu) -{ - printk_once(KERN_WARNING "kvm: MONITOR instruction emulated as NOP!\n"); - return handle_nop(vcpu); -} - /* * To run an L2 guest, we need a vmcs02 based on the L1-specified vmcs12. * We could reuse a single VMCS for all the L2 guests, but we also want the @@ -6651,8 +6639,8 @@ static int (*const 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_mwait, - [EXIT_REASON_MONITOR_INSTRUCTION] = handle_monitor, + [EXIT_REASON_MWAIT_INSTRUCTION] = handle_invalid_op, + [EXIT_REASON_MONITOR_INSTRUCTION] = handle_invalid_op, [EXIT_REASON_INVEPT] = handle_invept, };