Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp14942pxb; Thu, 7 Jan 2021 17:46:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJw55EWiw8G6JM+HcVh4sIRZXNNeASKV5S91fjeAGuy6cdlxs5U6VYi8o1AoDAjAksbBOtyE X-Received: by 2002:a17:906:7146:: with SMTP id z6mr1079088ejj.379.1610070404541; Thu, 07 Jan 2021 17:46:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610070404; cv=none; d=google.com; s=arc-20160816; b=JgEzpKCHY8FbptOpJ2HimuSPdPFhMQ6gv3cwSYKeWz63XucCJ1wzzhWvsTI0Jlrcss 43/a0M7NqXshr99qmg+/2DhhKdXVg0/oWxLny7dPo6G8KQMHZOhopPmNXa7OLND/n5al h7gba0qdzLxby0P53VDp222jR+5Zxq0wy5xWS5Ii27uuO6lEsbfMFOCfgfaKJh7fXqva QMWyZOxwuphhvaX6FIYDOySwIxPD44+NwRRDpFB+HiG3DrDJmGJdn194nd/q14zbD9lI R2Y2WWwgxZyjkMDZ5ahurxr6oX9hzmiIrla9Znaf9ynpikuY+y/YSoEDNy7Wry9fe2gu 3Bhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=WGQ5lBbPOxOB0SVtuRDHTtPSH9YHah7AZBBJVXyR8V0=; b=JH9zMNItNv9Kd22Z8QT/EAeGqiZ5hPDqhJv0z5xj2MX+MPrKxe2fVKv6ElJ0grnZst FALoMzxZPEYe3Aldfz2VrfuqZZIQ1o7Sd0PQIVf+ac3iCXXdOX5q/3RpbKsWM4rtUz1D M3oKC+/8o6q14nO+tpxbBpmhGEMzpxeYfMM3+9aTRz9W0EhDE2fUNs8mHt4eZ6NtesMP ZXNgEloexdEuipni+JN2CxWHuiICPobEFS/te9HJvdoc97L5pKj5QK97/CAOmJoIlh0Y Hg9qURkqeysuqYq71++xwB4BZOPCbvZZ24pxxeAN5mxOzu6vou6zRtqUyvr/Y9Bw1AY/ f5bQ== 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 q16si2937718ejd.199.2021.01.07.17.46.20; Thu, 07 Jan 2021 17:46:44 -0800 (PST) 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 S1729838AbhAHBox (ORCPT + 99 others); Thu, 7 Jan 2021 20:44:53 -0500 Received: from mga09.intel.com ([134.134.136.24]:27995 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727634AbhAHBow (ORCPT ); Thu, 7 Jan 2021 20:44:52 -0500 IronPort-SDR: r3kZaOV3eb1wCpUjQmMdY5JteWHyMpwONl2aMpt9v86WU6bVUL71H1hFEinob5vQAELsXSlBKB tJY7CrDV1Sqw== X-IronPort-AV: E=McAfee;i="6000,8403,9857"; a="177672373" X-IronPort-AV: E=Sophos;i="5.79,330,1602572400"; d="scan'208";a="177672373" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jan 2021 17:43:06 -0800 IronPort-SDR: IiVdmPrNfR8tCmm1dCXV3J6sO4HudquLXC/+/skJNlCoZI++9680SGYcjdSeF3eiG02ECHZQ1N zhKImGW8G+lg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,330,1602572400"; d="scan'208";a="379938023" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by orsmga008.jf.intel.com with ESMTP; 07 Jan 2021 17:43:03 -0800 From: Like Xu To: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , ak@linux.intel.com, wei.w.wang@intel.com, kan.liang@intel.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RESEND v13 01/10] KVM: x86: Move common set/get handler of MSR_IA32_DEBUGCTLMSR to VMX Date: Fri, 8 Jan 2021 09:36:55 +0800 Message-Id: <20210108013704.134985-2-like.xu@linux.intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210108013704.134985-1-like.xu@linux.intel.com> References: <20210108013704.134985-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Andi Kleen --- arch/x86/kvm/vmx/capabilities.h | 5 +++++ arch/x86/kvm/vmx/vmx.c | 19 ++++++++++++++++--- arch/x86/kvm/x86.c | 13 ------------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h index 3a1861403d73..a58cf3655351 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 2af05d3b0590..23b46327527e 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1924,6 +1924,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_uret_msr; + case MSR_IA32_DEBUGCTLMSR: + msr_info->data = 0; + break; default: find_uret_msr: msr = vmx_find_uret_msr(vmx, msr_info->index); @@ -2002,9 +2005,19 @@ 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) { + /* We support the non-activated case already */ + return 0; + } else if (data & ~vmx_supported_debugctl()) { + /* + * 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); + 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 0287840b93e0..c765fd72a66c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3063,18 +3063,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; - } else if (report_ignored_msrs) - 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: @@ -3347,7 +3335,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.29.2