Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3350471pxf; Sun, 28 Mar 2021 22:53:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJykfs+ayRq4fHT2M5lEhDWvhuU+655eEOjGTN2UMLW8fbeIWQ3jSIox0AOal8nJ7sjLvhm7 X-Received: by 2002:aa7:c5c4:: with SMTP id h4mr26060908eds.375.1616997232753; Sun, 28 Mar 2021 22:53:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616997232; cv=none; d=google.com; s=arc-20160816; b=0icpdB+Jv2LVqcCJtWW67toDRHsdaZmzv019+MI8cQ5PAdZaKptFzM9LLsrUYv4K8Q yOm+2KNSP9zqcfzI3GjXfOB+oIuzZqzw4SKrk4Rxtr0zipPP2YnEHcBU+2h43EvcJI5Z Jr6meB67rd12LqA/fJ6NcP9+OU3idxyoyHRa8/eUqo8DcFUCX19PBcYKsgd0mDm2nEou MqhZAHYvchFhyix6Sk+g5GAr0Ap4WfICLEIeV28ju4tzM5Ko8LJX71UoZnf0SVCMVQty ZrVj13n7ixO7zHtP7CjX0yyiSyh8OssiXTqj5xIYSlq+2nI86AbTmysdNdM8UXMqoUKL QIEg== 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=ptx4kRQyKqmwAc63ah8g7PLiVVC6hSMBUd0ZUCSNGTk=; b=ILTOY/oCxqXAVjqMUnq3NMENmdhz4WWnbcw+3BQI5ujnEyiz3zqRDZJmZ+BqCksNbK 4J5GTkpd4t6Q7B3jdHSwbVU6LUFymzQUv/ZeW+hB35TvsMg/xtMpp969PnEWpEoAbBhO aOUrIftfex6i3Nw4Oeu5QdEmH804Y/9I/PKzs/BrjN7kU7xPXtXWivE7mtZuzKKwHpyi 5bv53c7NTYuNcw9JytfNqEUv9f6JJm7P/1bOPOHATHh5RYl2amUDm8nKjT5CCYN+q4ZL z9yv5DuAXHKVd0GwSAEOykgFh1zyL13VY3xalyuBuhiRTNYDgaAg1Hwj7uo0Uqx5SvMk 9lOQ== 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 k13si13135299edr.48.2021.03.28.22.53.30; Sun, 28 Mar 2021 22:53:52 -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 S231703AbhC2FvQ (ORCPT + 99 others); Mon, 29 Mar 2021 01:51:16 -0400 Received: from mga07.intel.com ([134.134.136.100]:15681 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231442AbhC2Fuh (ORCPT ); Mon, 29 Mar 2021 01:50:37 -0400 IronPort-SDR: k1oZvzMybY2MV0//X4FrKg+lu2ZBZ5YnKoo4P1tphJsgxBLqFO3ErWaOCT5qyA/qXBMApYh1CX L7t0FrGWj2jA== X-IronPort-AV: E=McAfee;i="6000,8403,9937"; a="255478770" X-IronPort-AV: E=Sophos;i="5.81,285,1610438400"; d="scan'208";a="255478770" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2021 22:50:22 -0700 IronPort-SDR: NUE/R4DsJ3WC0jk1HO4l75ZMOOYgfVYr7WXaJ+9owm+2r+fCVOS/+IAWuvPJ7D46kkVXBclzla frR9kLMM5d1Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,285,1610438400"; d="scan'208";a="417507172" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by orsmga008.jf.intel.com with ESMTP; 28 Mar 2021 22:50:17 -0700 From: Like Xu To: peterz@infradead.org, Sean Christopherson , Paolo Bonzini Cc: eranian@google.com, andi@firstfloor.org, kan.liang@linux.intel.com, wei.w.wang@intel.com, Wanpeng Li , Vitaly Kuznetsov , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Like Xu Subject: [PATCH v4 15/16] KVM: x86/cpuid: Refactor host/guest CPU model consistency check Date: Mon, 29 Mar 2021 13:41:36 +0800 Message-Id: <20210329054137.120994-16-like.xu@linux.intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210329054137.120994-1-like.xu@linux.intel.com> References: <20210329054137.120994-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() could be renamed for reuse by more callers for the same purpose and remove the comment about LBR use case incidentally. 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 2a0c5064497f..fb478fb45b9e 100644 --- a/arch/x86/kvm/cpuid.h +++ b/arch/x86/kvm/cpuid.h @@ -270,6 +270,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 3c1ee59571d9..4fe13cf80bb5 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); @@ -576,7 +566,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 966fa7962808..b0f2cb790359 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2259,7 +2259,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 0029aaad8eda..d214b6c43886 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.29.2