Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13819485pxu; Mon, 4 Jan 2021 05:28:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJyU10A6o6tUtZ6Vml82lrfAI5M26/WWaPLsNvJI1ctO783+ZQYawkwc9nbQ5qSvf+AdMUbT X-Received: by 2002:aa7:c3c2:: with SMTP id l2mr69559308edr.15.1609766919832; Mon, 04 Jan 2021 05:28:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609766919; cv=none; d=google.com; s=arc-20160816; b=wskJG9EZBlTOHdSmqu+Om+gCrk+wwwK8OoJ74ReioZWOKwr9IAGKKBfBrOgpAE9zGy j4lGD3mczo15qUDL5Q2x/AaEZoVI4LiuxnfDpB/7LF5HWztoL6cRTXj6O13lMhd6KZ+V UAb8DixLHivfS6kTz4C3ev5wt2QlW0UJwYdXSHOrNS0JDoejA16yH9lTrdIBUsA8cnAQ yEAwPLM6Sz/EPVDBiTwai1zQyxXkfX53ngvH2bxecsniinnZNEhKppKNjoKhSyseTBIL XIUhAqVh8mr4q2Y0W1dGc+YYp/gvdVBk5xJVRYKaC7TemlaugrniB7641JQmscp/9Z/h ovtw== 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=AllFjUkqx8qtKU13oQayDzP+6ha8YIEEJWPS3JBRaIQ=; b=Ot+u+xgnD1X1fF2M1iw629kR8BnKLYJXOTN8dp2U5EzFQ0KioPcRFcqa2hmXV27V3E OAaxC6w/q2igi+CVwa4UX0n/ckJ/c3cYwVqi256bh+Ve8BLc3slyYoUlVdmsu9G+2e1r MVkbB3NPQnTck/gwQ+WsGm/Uu+BliUJuhee/RHFxeRhMaUX1eYGvUqtayhzg2b8V9yo3 avweKnnXpPOtuR+V9hjRL3iMULQypf3q8kiSWKndzsrnFfxtz6MMxo4gGf81oKaJ1Rk4 2W4hn5XvyBak2VNUvBW6r4Anlnf2kdDNiJHMv8CO51ARWcWfdoSr9QHCGv1KYFGuJcqY 8dtg== 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 f12si30956969ejl.311.2021.01.04.05.28.16; Mon, 04 Jan 2021 05:28:39 -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 S1726829AbhADNZG (ORCPT + 99 others); Mon, 4 Jan 2021 08:25:06 -0500 Received: from mga07.intel.com ([134.134.136.100]:23242 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726502AbhADNZG (ORCPT ); Mon, 4 Jan 2021 08:25:06 -0500 IronPort-SDR: K19kWVwiNwdgeFMutuj656poW81BP5PHcWRsnA4Y1nJuFURuOEoER0XOJWHT+mZaDiwJeIvo0p 66/uBEF0Y0vg== X-IronPort-AV: E=McAfee;i="6000,8403,9853"; a="241034307" X-IronPort-AV: E=Sophos;i="5.78,474,1599548400"; d="scan'208";a="241034307" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2021 05:22:09 -0800 IronPort-SDR: 3ebCMttWEu0hHlfGTizcNBkoL+uYEPgbYT0/P/KSd3sqqn9oSmrtGUXTHnV33WOsL9wpZdNaep t2gs1npCVonQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,474,1599548400"; d="scan'208";a="461944539" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by fmsmga001.fm.intel.com with ESMTP; 04 Jan 2021 05:22:05 -0800 From: Like Xu To: Peter Zijlstra , Paolo Bonzini , eranian@google.com, kvm@vger.kernel.org Cc: Ingo Molnar , Sean Christopherson , Thomas Gleixner , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Andi Kleen , Kan Liang , wei.w.wang@intel.com, luwei.kang@intel.com, linux-kernel@vger.kernel.org Subject: [PATCH v3 03/17] KVM: x86/pmu: Introduce the ctrl_mask value for fixed counter Date: Mon, 4 Jan 2021 21:15:28 +0800 Message-Id: <20210104131542.495413-4-like.xu@linux.intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104131542.495413-1-like.xu@linux.intel.com> References: <20210104131542.495413-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 39707e72b062..94c8bfee4a82 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.29.2