Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2900374pxb; Sun, 8 Nov 2020 18:19:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJwjTNJ7vOQLigcP5wCo3cqxA47eG4Qy6rMTrwH/oBoo3Pl+BI+VAW/J2YiIaoQocpEZUoJh X-Received: by 2002:a17:906:814:: with SMTP id e20mr12658500ejd.514.1604888357119; Sun, 08 Nov 2020 18:19:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604888357; cv=none; d=google.com; s=arc-20160816; b=uZwBBO2MOSlEJpSb7P8q/alS95fhKMZhnaRD7+jr1q7JJznPu9TIZWyAv2XuaX8wfl 0hRHOIhsiXtpBgnx5LdD/WM0Y76g+URP6PJ7hc3d2Hagoy0+SGw7AAzg9S1FNvCpbIyu DIua/RM7cOWa81xSyorWo0LWJSUYgj/Cj119R7tItxI+d7rDi+A3fYb6lznapZLmGzyd dB+7R2UhpYSlGPeUqg1tRRacoDY8pBW9kLhLg2lEMsmWJpPhXq3CJNAvfoBcTK4JtC39 V2TSgyDQnYMm8lKcbFlZXEK3Q6dY9e0nbheaO5praK9O5XpsD8cSRXQzHKhcWosqdmqc iuNw== 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=TUHGlISoM2qMvLxeQLpAO4ccsh0zHC73dcEX2X4XJdU=; b=bAykzs/N9QyPQhgnGM49QSPXbf3C+4qsC0YvlzVboDei8+eer/7Ui2oNwlhKYRMbqv SpgfuihHnayCPGa25tg7P48S9OWzk6ONguzpMIth39Dj7GnhLbzNosQ5bvewpq+9lfRb jrx9R5mFFyLPn2YC+3nnpahb8SZoNjFM96vyfp6ugIrJX6CdFgssq9/1F+h0ICf1fmD1 CrWajjX4KU+m6TMnNhem8O1XK2kl0nSLCALGxcl4CDI5cCHZNdRhxtmKyd4tCd/7Caaa M5we2XZYcmjcCbaZ3v4yAnWkP9ViIvmrlXCpxkXun86l/bE4Vldt97SHaM3geXhwcYx3 yFMA== 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 mc11si6024274ejb.154.2020.11.08.18.18.54; Sun, 08 Nov 2020 18:19:17 -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 S1729288AbgKICRD (ORCPT + 99 others); Sun, 8 Nov 2020 21:17:03 -0500 Received: from mga01.intel.com ([192.55.52.88]:64875 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729219AbgKICRC (ORCPT ); Sun, 8 Nov 2020 21:17:02 -0500 IronPort-SDR: M5jBvCWBr+UVU/eTjGhxpqgiS/zZzLUahPaYMoGIIPhoYivTThISokP65MZ8q0r5Q7LgnrSHlS g5SaVmNqwWZw== X-IronPort-AV: E=McAfee;i="6000,8403,9799"; a="187684577" X-IronPort-AV: E=Sophos;i="5.77,462,1596524400"; d="scan'208";a="187684577" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2020 18:17:01 -0800 IronPort-SDR: UWXbTU+0puBWEbU3Iq4QepWm79pXePal2ky9xSlxjggEYv9APmYDZJJM3UoAx+Fhm2cUxXEv68 aYPDxj/5i9sA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,462,1596524400"; d="scan'208";a="540646143" Received: from e5-2699-v4-likexu.sh.intel.com ([10.239.48.39]) by orsmga005.jf.intel.com with ESMTP; 08 Nov 2020 18:16:57 -0800 From: Like Xu To: Peter Zijlstra , Paolo Bonzini , kvm@vger.kernel.org Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Kan Liang , luwei.kang@intel.com, Thomas Gleixner , wei.w.wang@intel.com, Tony Luck , Stephane Eranian , Mark Gross , Srinivas Pandruvada , linux-kernel@vger.kernel.org Subject: [PATCH v2 03/17] KVM: x86/pmu: Introduce the ctrl_mask value for fixed counter Date: Mon, 9 Nov 2020 10:12:40 +0800 Message-Id: <20201109021254.79755-4-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201109021254.79755-1-like.xu@linux.intel.com> References: <20201109021254.79755-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 The mask value of fixed counter control register should be dynamic adjusted with the number of fixed counters. This patch introduces a variable that includes the reserved bits of fixed counter control registers. This is needed for later Ice Lake fixed counter changes. Co-developed-by: Luwei Kang Signed-off-by: Luwei Kang Signed-off-by: Like Xu --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/vmx/pmu_intel.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index d44858b69353..505f9b39c423 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -433,6 +433,7 @@ struct kvm_pmu { unsigned nr_arch_fixed_counters; unsigned available_event_types; u64 fixed_ctr_ctrl; + u64 fixed_ctr_ctrl_mask; u64 global_ctrl; u64 global_status; u64 global_ovf_ctrl; diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index 7c18c85328da..50047114c298 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -253,7 +253,7 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) case MSR_CORE_PERF_FIXED_CTR_CTRL: if (pmu->fixed_ctr_ctrl == data) return 0; - if (!(data & 0xfffffffffffff444ull)) { + if (!(data & pmu->fixed_ctr_ctrl_mask)) { reprogram_fixed_counters(pmu, data); return 0; } @@ -320,6 +320,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) struct kvm_cpuid_entry2 *entry; union cpuid10_eax eax; union cpuid10_edx edx; + int i; pmu->nr_arch_gp_counters = 0; pmu->nr_arch_fixed_counters = 0; @@ -327,6 +328,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) pmu->counter_bitmask[KVM_PMC_FIXED] = 0; pmu->version = 0; pmu->reserved_bits = 0xffffffff00200000ull; + pmu->fixed_ctr_ctrl_mask = ~0ull; entry = kvm_find_cpuid_entry(vcpu, 0xa, 0); if (!entry) @@ -358,6 +360,9 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) ((u64)1 << edx.split.bit_width_fixed) - 1; } + for (i = 0; i < pmu->nr_arch_fixed_counters; i++) + pmu->fixed_ctr_ctrl_mask |= (0xbull << (i * 4)); + pmu->fixed_ctr_ctrl_mask = ~pmu->fixed_ctr_ctrl_mask; pmu->global_ctrl = ((1ull << pmu->nr_arch_gp_counters) - 1) | (((1ull << pmu->nr_arch_fixed_counters) - 1) << INTEL_PMC_IDX_FIXED); pmu->global_ctrl_mask = ~pmu->global_ctrl; -- 2.21.3