Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp434335pxb; Wed, 14 Apr 2021 20:25:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzK7izNVG8Xt0rgBwIsjrHgQ4iLKMggy0Kz0flHiZDE4rCxhN2JgW0TXNWHdkDv3FZHKZIF X-Received: by 2002:aa7:c351:: with SMTP id j17mr1578674edr.199.1618457151294; Wed, 14 Apr 2021 20:25:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618457151; cv=none; d=google.com; s=arc-20160816; b=kQ9U/MsNq7UCcvuKa0gSlUJVWDKqcDs1+9PsRt5jmjUOfzB7KssN+R/QvGOm+8McR6 7/YUdtXRge63Xt/aM4nREGuxnL7XCdOmZPOSJCl3gpx9lh1ZZSA0TmbI8FYpxImiJHI/ 8JY+4UhiCUdkjrD/+IP9l494tNuo2HFjybDWjtBX8L7T7oCtFYSP+EsYb4bPZXy3DR5N 51Ebix9/xIz+4AcN67jBfOS21bIEK6j7KOYK4bgeIpbQ8YYzmITz2Krge3GIdgPAD65A uaU8O6h97rdUeX6k8pm6VooFR8t/OEncyKBmnoUBO4+TI/B73FtyW2vr1zOWkqr8UU6j hOFQ== 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=n5DTy7ZIdzHucFNlm6aMyybIly/WkM894QpEWUA61/I=; b=IIKd9izkWq0rMS/6LqVssVzFEVwXI02I6X0JT7iMcTZXrnaWa2sbnYZ75DefXXIkJr 7/7CCUuWV6PtwcRV6I/paxYavniOcJ/TSJ20Zm83HEu/6BdJWNiwwZ2c5l8mBg43XwCE OxHQDaNxPHywXTaQIK6ATNLq/a+SwUFBnIQbDZSUXpk7luIT2Xz7wGGFEcWzt2ni5Q9Q Y4Q4wTRC5nyQeWz8M89sh4zWSp3nP+QpJjyMKeUtmC3kcSHYnAa/I9KyCN6CzfbwgOJp NsLSqcsnroie3WHfD5jx52XetzwhK8YBL8tz2mwf6TESgDKC8yOzcyHjbmQGSvsZe8m6 tg4w== 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 o15si1061241ejx.42.2021.04.14.20.25.28; Wed, 14 Apr 2021 20:25:51 -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 S230249AbhDODWC (ORCPT + 99 others); Wed, 14 Apr 2021 23:22:02 -0400 Received: from mga01.intel.com ([192.55.52.88]:10590 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230136AbhDODVq (ORCPT ); Wed, 14 Apr 2021 23:21:46 -0400 IronPort-SDR: Uu2kU8BD/I/SuvubUb88bu73+aATpqha7HABB0Xxh6BQbgrrdP0JTl2bnMMJ/K7QrbiuhJ8xV6 FpmA3vs5Chag== X-IronPort-AV: E=McAfee;i="6200,9189,9954"; a="215281599" X-IronPort-AV: E=Sophos;i="5.82,223,1613462400"; d="scan'208";a="215281599" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Apr 2021 20:21:23 -0700 IronPort-SDR: +eFHz5iHXwAP6sAj0l5Y4D4tfnIJGxGHDgNRWm21cwpso2OBDyaKiD2pp7pjiD7DN4YP4MvuRE wS+1aaCBJXag== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,223,1613462400"; d="scan'208";a="425014129" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by orsmga008.jf.intel.com with ESMTP; 14 Apr 2021 20:21:20 -0700 From: Like Xu To: peterz@infradead.org, Paolo Bonzini , Sean Christopherson Cc: andi@firstfloor.org, kan.liang@linux.intel.com, wei.w.wang@intel.com, eranian@google.com, liuxiangdong5@huawei.com, Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Like Xu Subject: [PATCH v5 15/16] KVM: x86/cpuid: Refactor host/guest CPU model consistency check Date: Thu, 15 Apr 2021 11:20:15 +0800 Message-Id: <20210415032016.166201-16-like.xu@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210415032016.166201-1-like.xu@linux.intel.com> References: <20210415032016.166201-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 For the same purpose, the leagcy intel_pmu_lbr_is_compatible() can be renamed for reuse by more callers, and remove the comment about LBR use case can be deleted by the way. Signed-off-by: Like Xu --- arch/x86/kvm/cpuid.h | 5 +++++ arch/x86/kvm/vmx/pmu_intel.c | 12 +----------- arch/x86/kvm/vmx/vmx.c | 2 +- arch/x86/kvm/vmx/vmx.h | 1 - 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h index ded84d244f19..3114ecff8080 100644 --- a/arch/x86/kvm/cpuid.h +++ b/arch/x86/kvm/cpuid.h @@ -278,6 +278,11 @@ static inline int guest_cpuid_model(struct kvm_vcpu *vcpu) return x86_model(best->eax); } +static inline bool cpuid_model_is_consistent(struct kvm_vcpu *vcpu) +{ + return boot_cpu_data.x86_model == guest_cpuid_model(vcpu); +} + static inline int guest_cpuid_stepping(struct kvm_vcpu *vcpu) { struct kvm_cpuid_entry2 *best; diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index fb297ffb5481..31e0e5e7d5a5 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -173,16 +173,6 @@ static inline struct kvm_pmc *get_fw_gp_pmc(struct kvm_pmu *pmu, u32 msr) return get_gp_pmc(pmu, msr, MSR_IA32_PMC0); } -bool intel_pmu_lbr_is_compatible(struct kvm_vcpu *vcpu) -{ - /* - * As a first step, a guest could only enable LBR feature if its - * cpu model is the same as the host because the LBR registers - * would be pass-through to the guest and they're model specific. - */ - return boot_cpu_data.x86_model == guest_cpuid_model(vcpu); -} - bool intel_pmu_lbr_is_enabled(struct kvm_vcpu *vcpu) { struct x86_pmu_lbr *lbr = vcpu_to_lbr_records(vcpu); @@ -578,7 +568,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) nested_vmx_pmu_entry_exit_ctls_update(vcpu); - if (intel_pmu_lbr_is_compatible(vcpu)) + if (cpuid_model_is_consistent(vcpu)) x86_perf_get_lbr(&lbr_desc->records); else lbr_desc->records.nr = 0; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 4f0e35a0cd0f..5ad12bb76296 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2258,7 +2258,7 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) if ((data & PMU_CAP_LBR_FMT) != (vmx_get_perf_capabilities() & PMU_CAP_LBR_FMT)) return 1; - if (!intel_pmu_lbr_is_compatible(vcpu)) + if (!cpuid_model_is_consistent(vcpu)) return 1; } ret = kvm_set_msr_common(vcpu, msr_info); diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index 1311f67046aa..28a588d83a01 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -97,7 +97,6 @@ union vmx_exit_reason { #define vcpu_to_lbr_records(vcpu) (&to_vmx(vcpu)->lbr_desc.records) void intel_pmu_cross_mapped_check(struct kvm_pmu *pmu); -bool intel_pmu_lbr_is_compatible(struct kvm_vcpu *vcpu); bool intel_pmu_lbr_is_enabled(struct kvm_vcpu *vcpu); int intel_pmu_create_guest_lbr_event(struct kvm_vcpu *vcpu); -- 2.30.2