Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp415101ybg; Sun, 26 Jul 2020 08:35:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtNx3oWjX+jVSK0HmxGiphAI/xE9Ixot+lhcvsGpGcsBC7XqPmonegaFSOWRFDfsq6vCfH X-Received: by 2002:a05:6402:787:: with SMTP id d7mr17208909edy.46.1595777716743; Sun, 26 Jul 2020 08:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595777716; cv=none; d=google.com; s=arc-20160816; b=dL39Ff2q5iVTuBbziEty03FDLk+opIISHpyyllHhHS3hSuH/UbvaKOpjpPL+YfDPVM 674JVq48YmpPlqELyHgais1d/N+PuK4PM8v2EdKVLVcKy3cIGnvgW0cWN4uFm4MPwjzq UzlPAJTkFugbpHk2pElSmAd9ZESf+HJ1keFQTSgikCP19lXy8Q8/xBqynU64eXaCi7su fx4dlE2aarOh/0FqqozvJHDGG2px15nG8cJiYRCNJTWFF65248L8r+7FpkH0I/PDTabv 6n+3DPBohGcb3XB+V/jZ7Adv221sdk3B56VRPicYp3RTzYKFHvEqnyIsuhBWp9c5D7Z1 lxDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=Y9+ZG9KlydVDwfAno1OHzL723VNSaAENgl044ATPn5M=; b=Oh3Qdsn+yKGSctgKSKtnUVfc6cEbdyfv1ztahQQOSgqZ6EnMdX2yJQkwGWQzKHEVfx xTAt12GWvhYZoOmhr02z3Z94R9fLzHWBn5xi/42827A076axw1DEoM7Kg0oQXL+EDiv7 VRYyhTPZ+fMQy23/zk030KY6mBCocF95gbg+tFKa7cZb+GC4pIynHDjojvOnmy6NR1G7 ILsW+1BFDSZcJpt7titTo18IXsshwdeeyTi+alkZ82HRWF0UGl1+xOb+24UMiNlrnPKD DPbuikQyy9OoVjdRPXFe6TLdwuJPmA0gSqlygV2eMZWGo2KVbRTRYPQQ4jMAPcxOuLLd xmwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a6si2648256edr.403.2020.07.26.08.34.55; Sun, 26 Jul 2020 08:35:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726891AbgGZPeo (ORCPT + 99 others); Sun, 26 Jul 2020 11:34:44 -0400 Received: from mga03.intel.com ([134.134.136.65]:17603 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726065AbgGZPen (ORCPT ); Sun, 26 Jul 2020 11:34:43 -0400 IronPort-SDR: ECY5LGkiLdUzWsO8mRFUWRz/kk3XSoYFko3mo3QIDVoS9P/Vz2NVKR4I2EXsTiVNrPnLzAmfpv emf6YvGMJjTA== X-IronPort-AV: E=McAfee;i="6000,8403,9694"; a="150890960" X-IronPort-AV: E=Sophos;i="5.75,399,1589266800"; d="scan'208";a="150890960" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2020 08:34:42 -0700 IronPort-SDR: xBe0in7NsNEsZ7F3QCwY1vi0YOcZ1oSNWfNDlYpizimvoN59TFVVIOuZUpK5u4Z31jSsaE4Co5 0wyQkgLgjfog== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,399,1589266800"; d="scan'208";a="303177505" Received: from sqa-gate.sh.intel.com (HELO clx-ap-likexu.tsp.org) ([10.239.48.212]) by orsmga002.jf.intel.com with ESMTP; 26 Jul 2020 08:34:40 -0700 From: Like Xu To: Paolo Bonzini , Vitaly Kuznetsov , Jim Mattson , kvm@vger.kernel.org Cc: Sean Christopherson , Wanpeng Li , Joerg Roedel , linux-kernel@vger.kernel.org, Like Xu Subject: [PATCH v13 01/10] KVM: x86: Move common set/get handler of MSR_IA32_DEBUGCTLMSR to VMX Date: Sun, 26 Jul 2020 23:32:19 +0800 Message-Id: <20200726153229.27149-2-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200726153229.27149-1-like.xu@linux.intel.com> References: <20200726153229.27149-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org SVM already has specific handlers of MSR_IA32_DEBUGCTLMSR in the svm_get/set_msr, so the x86 common part can be safely moved to VMX. Add vmx_supported_debugctl() to refactor the throwing logic of #GP. Signed-off-by: Like Xu --- arch/x86/kvm/vmx/capabilities.h | 5 +++++ arch/x86/kvm/vmx/vmx.c | 11 ++++++++--- arch/x86/kvm/x86.c | 13 ------------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h index 4bbd8b448d22..c199885af7c7 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -378,4 +378,9 @@ static inline u64 vmx_get_perf_capabilities(void) return PMU_CAP_FW_WRITES; } +static inline u64 vmx_supported_debugctl(void) +{ + return DEBUGCTLMSR_LBR | DEBUGCTLMSR_BTF; +} + #endif /* __KVM_X86_VMX_CAPS_H */ diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 1bb59ae5016d..dcde73a230c6 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1956,6 +1956,9 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) !guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP)) return 1; goto find_shared_msr; + case MSR_IA32_DEBUGCTLMSR: + msr_info->data = 0; + break; default: find_shared_msr: msr = find_msr_entry(vmx, msr_info->index); @@ -2034,9 +2037,11 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) VM_EXIT_SAVE_DEBUG_CONTROLS) get_vmcs12(vcpu)->guest_ia32_debugctl = data; - ret = kvm_set_msr_common(vcpu, msr_info); - break; - + if (data & ~vmx_supported_debugctl()) + return 1; + vcpu_unimpl(vcpu, "%s: MSR_IA32_DEBUGCTLMSR 0x%llx, nop\n", + __func__, data); + return 0; case MSR_IA32_BNDCFGS: if (!kvm_mpx_supported() || (!msr_info->host_initiated && diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 95ef62922869..c79953b49c77 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2897,18 +2897,6 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) return 1; } break; - case MSR_IA32_DEBUGCTLMSR: - if (!data) { - /* We support the non-activated case already */ - break; - } else if (data & ~(DEBUGCTLMSR_LBR | DEBUGCTLMSR_BTF)) { - /* Values other than LBR and BTF are vendor-specific, - thus reserved and should throw a #GP */ - return 1; - } - vcpu_unimpl(vcpu, "%s: MSR_IA32_DEBUGCTLMSR 0x%llx, nop\n", - __func__, data); - break; case 0x200 ... 0x2ff: return kvm_mtrr_set_msr(vcpu, msr, data); case MSR_IA32_APICBASE: @@ -3167,7 +3155,6 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) switch (msr_info->index) { case MSR_IA32_PLATFORM_ID: case MSR_IA32_EBL_CR_POWERON: - case MSR_IA32_DEBUGCTLMSR: case MSR_IA32_LASTBRANCHFROMIP: case MSR_IA32_LASTBRANCHTOIP: case MSR_IA32_LASTINTFROMIP: -- 2.21.3