Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp267211pxv; Wed, 21 Jul 2021 22:46:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzz80M8prRvRV21CL9Xc1xvaQ/emHB+wWxQywrgAZoFsZdngo0F+4P66ylUNnssQ8JvYwVH X-Received: by 2002:a02:8241:: with SMTP id q1mr34029356jag.134.1626932765076; Wed, 21 Jul 2021 22:46:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626932765; cv=none; d=google.com; s=arc-20160816; b=ufvo2tgG6ckwzBX/pRsR2Xmnf8UphsAZLalrbrTSwUdgynhZmEoILIbl48FQgk5b0H 4YorTmGbgsrUdG4yND34zzQpjzr0DNN0wW1knx9ZMz/TPUGLNDg8V45dC0eVyC2z7vdc Icu7edSAGD3iugJFC+FNqMWVf5CC4uuPHiKH9138voz1LW12n/dgUS0sltLGpGIU0l9R eZWxxlNKglghcPESW/j8/TRXUa4mKun3WLNUXHWcNyoJVAY76JSFNS3LPdXruLnDQ20l +CIcKFfKf07mIOAsWW3V2gpFmlXYweaj4YASc6N6KtiIDbJnu90sgVKIArGtV8VY/7wa c2tg== 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; bh=JWOFokWT8G11qyvaIEC5Rxb4vQ2Oov5HZWD1erUayl4=; b=tveSwG1476jrtZ4ORYLZk9Spkjgk/kufF0ooZy8+Xk1I5hZu7d0ReJuIfP34pcf3ho zmtLrGLUOK9gwXacTRhevs26Tikl4OIv02YaKl+nlhEse+bs9lhnZ9NRksh+J0csXQ8e ZcEQ7ytvTaoQ4qhCsHzuQZf552Z4v9Xko8lF/rpCNqxnaqyyOd0jlT0w43T6HHgaj4x9 8MeV26dlwD120CIsEqlM8nmVNT+0cPPUpZky/VCX4o30RLdjTwTEBR9OABxqLXaifQhg 0Bv7rQxCztf3lr7TYmQDypYoNHTeUkpWkPAFQ4VZZXrcdmKdU8jfEXkR1ECqx+QLnOhs NG0w== 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 w5si21241635ilu.14.2021.07.21.22.45.54; Wed, 21 Jul 2021 22:46:05 -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 S231200AbhGVFDV (ORCPT + 99 others); Thu, 22 Jul 2021 01:03:21 -0400 Received: from mga04.intel.com ([192.55.52.120]:10692 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230153AbhGVFDL (ORCPT ); Thu, 22 Jul 2021 01:03:11 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10052"; a="209672715" X-IronPort-AV: E=Sophos;i="5.84,260,1620716400"; d="scan'208";a="209672715" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2021 22:43:42 -0700 X-IronPort-AV: E=Sophos;i="5.84,260,1620716400"; d="scan'208";a="512372670" Received: from vmm_a4_icx.sh.intel.com (HELO localhost.localdomain) ([10.239.53.245]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2021 22:43:33 -0700 From: Zhu Lingshan To: peterz@infradead.org, pbonzini@redhat.com Cc: bp@alien8.de, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, kan.liang@linux.intel.com, ak@linux.intel.com, wei.w.wang@intel.com, eranian@google.com, liuxiangdong5@huawei.com, linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, like.xu.linux@gmail.com, boris.ostrvsky@oracle.com, Like Xu , Zhu Lingshan Subject: [PATCH V9 17/18] KVM: x86/cpuid: Refactor host/guest CPU model consistency check Date: Thu, 22 Jul 2021 13:41:58 +0800 Message-Id: <20210722054159.4459-18-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210722054159.4459-1-lingshan.zhu@intel.com> References: <20210722054159.4459-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Like Xu 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 Signed-off-by: Zhu Lingshan --- 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 c99edfff7f82..439ce776b9a0 100644 --- a/arch/x86/kvm/cpuid.h +++ b/arch/x86/kvm/cpuid.h @@ -143,6 +143,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 05bc218c08df..a77d5a5f2ba5 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 d8552dbece6f..d0af51c1389d 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2221,7 +2221,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 f8343cb18f37..26f2dd469ae7 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.27.0