Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp5511454ybf; Thu, 5 Mar 2020 02:01:11 -0800 (PST) X-Google-Smtp-Source: ADFU+vu3AAErpyNqwmTjamXAGV8KKEo22kUdPn8dE/ESFclE2IDFIbynYz+AVl9gsRHdy90/YKAo X-Received: by 2002:a9d:5d0:: with SMTP id 74mr6069263otd.256.1583402471813; Thu, 05 Mar 2020 02:01:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583402471; cv=none; d=google.com; s=arc-20160816; b=Gs2wAi0G3yIOE7BbsI3a3LgZyzlgu2hFrneA7IioDjIZedTRkiQXQUhV3cohIoGRMP HALGU3Gj3ZxqKdkB6SSbm4eHOlEMPBK1yIVkSTcCORd8Uw23OM0/TgII3UtPAf9dIl6W /xZJr8Df8aRsNVyBzkFPk+CxbrHyEU5jlkFvj75+yhKTfJ6TTSO61V4lXtqSwsfNIU5y kC0tt68wGYDVZlwF55ae6F7IyvLonksLFeo8yxR+BjVeT4+RWnW1FWdRpgH31hPwZS2y /n3YwYP1ngijDaZnCJfVJSyr+frH94UEiO23e9Y6BaFR1ANMbj/CQLtpn9+foNdeBxa6 VR4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=9RO5Z++sVeyTOcH3VeZwciTspHH/AAmlH3xab31shbc=; b=aJTIpBbJ/GrhvgbitxZvO8EeMZlsqjSz4hV+3OmCu1ug9SnWKE9MnXovXiAO7ig3C4 uwQm7DvKa1oYAkXrcwDRVQwFp43LftG4mean052kqaD8GAA502wNdNYxZ2L3EFs1Fn1A PKgQ9aLXfxJy7lIVuuzmibaWfys6/+0XS7JkBOLhY0O7AHtCuK1G2XjxvD6NVL/EI97O w1hONfjEuvtq3BnHuUaqxXYD4nY97Yq4CMw2FC4QV6yqOwBlVEUMQADHG7pe5fTySCt+ 2Ykad9bKLWiqgeXG3+lzpantqxImNzGf0VLL5mca0W4cD6GLe7FVqnxcusvIMttchxYX hqcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id d22si1745148ote.183.2020.03.05.02.01.00; Thu, 05 Mar 2020 02:01:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727437AbgCEKAH (ORCPT + 99 others); Thu, 5 Mar 2020 05:00:07 -0500 Received: from mga12.intel.com ([192.55.52.136]:9294 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727053AbgCEKAF (ORCPT ); Thu, 5 Mar 2020 05:00:05 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2020 02:00:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,517,1574150400"; d="scan'208";a="234366740" Received: from snr.bj.intel.com ([10.240.193.90]) by orsmga008.jf.intel.com with ESMTP; 05 Mar 2020 01:59:57 -0800 From: Luwei Kang To: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, tglx@linutronix.de, bp@alien8.de, hpa@zytor.com, pbonzini@redhat.com, sean.j.christopherson@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, pawan.kumar.gupta@linux.intel.com, ak@linux.intel.com, thomas.lendacky@amd.com, fenghua.yu@intel.com, kan.liang@linux.intel.com, like.xu@linux.intel.com, Luwei Kang Subject: [PATCH v1 10/11] KVM: x86/pmu: Introduce the mask value for fixed counter Date: Fri, 6 Mar 2020 01:57:04 +0800 Message-Id: <1583431025-19802-11-git-send-email-luwei.kang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1583431025-19802-1-git-send-email-luwei.kang@intel.com> References: <1583431025-19802-1-git-send-email-luwei.kang@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The mask value of fixed counter control register should be dynamic adjust with the number of fixed counters. This patch introduce a variable that include the reserved bits of fix counter control register. Signed-off-by: Luwei Kang --- 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 35d230e..6f82fb7 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -471,6 +471,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 8161488..578b830 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -277,7 +277,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; } @@ -346,9 +346,11 @@ 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; + pmu->fixed_ctr_ctrl_mask = 0; pmu->counter_bitmask[KVM_PMC_GP] = 0; pmu->counter_bitmask[KVM_PMC_FIXED] = 0; pmu->version = 0; @@ -383,6 +385,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; -- 1.8.3.1