From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44412C10F12 for ; Mon, 15 Apr 2019 18:17:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1CF22205ED for ; Mon, 15 Apr 2019 18:17:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727780AbfDOSRE (ORCPT ); Mon, 15 Apr 2019 14:17:04 -0400 Received: from mga11.intel.com ([192.55.52.93]:33208 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726182AbfDOSRE (ORCPT ); Mon, 15 Apr 2019 14:17:04 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Apr 2019 11:17:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,354,1549958400"; d="scan'208";a="134562955" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.181]) by orsmga008.jf.intel.com with ESMTP; 15 Apr 2019 11:17:03 -0700 Date: Mon, 15 Apr 2019 11:17:03 -0700 From: Sean Christopherson To: Liran Alon Cc: pbonzini@redhat.com, rkrcmar@redhat.com, kvm@vger.kernel.org, Boris Ostrovsky Subject: Re: [PATCH] KVM: VMX: Nop emulation of MSR_IA32_POWER_CTL Message-ID: <20190415181702.GH24010@linux.intel.com> References: <20190415154526.64709-1-liran.alon@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190415154526.64709-1-liran.alon@oracle.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Mon, Apr 15, 2019 at 06:45:26PM +0300, Liran Alon wrote: > Since commits 668fffa3f838 ("kvm: better MWAIT emulation for guests”) > and 4d5422cea3b6 ("KVM: X86: Provide a capability to disable MWAIT intercepts”), > KVM was modified to allow an admin to configure certain guests to execute > MONITOR/MWAIT inside guest without being intercepted by host. > > This is useful in case admin wishes to allocate a dedicated logical > processor for each vCPU thread. Thus, making it safe for guest to > completely control the power-state of the logical processor. > > The ability to use this new KVM capability was introduced to QEMU by > commits 6f131f13e68d ("kvm: support -overcommit cpu-pm=on|off”) and > 2266d4431132 ("i386/cpu: make -cpu host support monitor/mwait”). > > However, exposing MONITOR/MWAIT to a Linux guest may cause it's intel_idle ^^^^ its English is a wonderful language... > kernel module to execute c1e_promotion_disable() which will attempt to > RDMSR/WRMSR from/to MSR_IA32_POWER_CTL to manipulate the "C1E Enable" > bit. This behaviour was introduced by commit > 32e9518005c8 ("intel_idle: export both C1 and C1E”). Technically, I think this is a Qemu bug. KVM reports all zeros for CPUID_MWAIT_LEAF when userspace queries KVM_GET_SUPPORTED_CPUID and KVM_GET_EMULATED_CPUID. And I think that's correct/desired, supporting MONITOR/MWAIT sub-features should be a separate enabling patch set. Note, there is a virtualization hole regarding MWAIT as KVM can't intercept MWAIT when executed with unsupported hints/features, but I don't think that absolves Qemu of wrongdoing. > Becuase KVM doesn't emulate this MSR, running KVM with ignore_msrs=0 > will cause the above guest behaviour to raise a #GP which will cause > guest to kernel panic. > > Therefore, add support for nop emulation of MSR_IA32_POWER_CTL to > avoid #GP in guest in this scenario. > > Future commits can optimise emulation further by reflecting guest > MSR changes to host MSR to provide guest with the ability to > fine-tune the dedicated logical processor power-state. > > Reviewed-by: Boris Ostrovsky > Signed-off-by: Liran Alon > --- > arch/x86/kvm/vmx/vmx.c | 6 ++++++ > arch/x86/kvm/vmx/vmx.h | 2 ++ > arch/x86/kvm/x86.c | 1 + > 3 files changed, 9 insertions(+) > > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 2634ee8c9dc8..6246d782b746 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -1696,6 +1696,9 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > case MSR_IA32_SYSENTER_ESP: > msr_info->data = vmcs_readl(GUEST_SYSENTER_ESP); > break; > + case MSR_IA32_POWER_CTL: > + msr_info->data = vmx->msr_ia32_power_ctl; > + break; > case MSR_IA32_BNDCFGS: > if (!kvm_mpx_supported() || > (!msr_info->host_initiated && > @@ -1826,6 +1829,9 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > case MSR_IA32_SYSENTER_ESP: > vmcs_writel(GUEST_SYSENTER_ESP, data); > break; > + case MSR_IA32_POWER_CTL: > + vmx->msr_ia32_power_ctl = data; > + break; > case MSR_IA32_BNDCFGS: > if (!kvm_mpx_supported() || > (!msr_info->host_initiated && If KVM does go the route of advertising MWAIT/MONITOR sub-features, then I think the MSR needs to be emulated on both Intel and AMD. Glancing through drivers/idle/intel_idle.c, I don't see anything that prevents it from successfully probing an "Intel" vCPU that is being emulated on AMD hardware. > diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h > index 99328954c2fc..e9772850a2a1 100644 > --- a/arch/x86/kvm/vmx/vmx.h > +++ b/arch/x86/kvm/vmx/vmx.h > @@ -259,6 +259,8 @@ struct vcpu_vmx { > > unsigned long host_debugctlmsr; > > + u64 msr_ia32_power_ctl; > + > /* > * Only bits masked by msr_ia32_feature_control_valid_bits can be set in > * msr_ia32_feature_control. FEATURE_CONTROL_LOCKED is always included > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 02c8e095a239..39ee4087f954 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -1167,6 +1167,7 @@ static u32 emulated_msrs[] = { > MSR_PLATFORM_INFO, > MSR_MISC_FEATURES_ENABLES, > MSR_AMD64_VIRT_SPEC_CTRL, > + MSR_IA32_POWER_CTL, > }; > > static unsigned num_emulated_msrs; > -- > 2.20.1 >