Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3350510pxf; Sun, 28 Mar 2021 22:54:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrnonDlXXADDIeedQgQ/Wzii1a7HntRAq+r5yCZRejB/0THbmV8VjiDi1f0eGKbdoNnEnk X-Received: by 2002:a05:6402:d07:: with SMTP id eb7mr26270351edb.242.1616997243530; Sun, 28 Mar 2021 22:54:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616997243; cv=none; d=google.com; s=arc-20160816; b=oFYlHXMn49TzjSoNyY3QHmZ6qPcTB5e5vYDRCykqUXs6kRyFZAQO8TL37+mfHjVz03 SnGHTEfgp9siJHDjBwFTYt/WstE0WbtLl1JOVHBuvtTgJ20nmcYOG+KFsbRAe7R4Vywy SLIWCymM3HXmVL4qpG4B/jnqESAEG6CQ6gIDkAuPwM1JOQfJv/YJ6h8y0OnFZdd6Nd4H jN3WpCvU4nXtBhMu5xaYYT7FV+lMD2Fe63o89/bTx3A2ATrr/IsIkqX4Diq9BUpnXEIx F8dD5Ek54Iqtd0oGt7I60Wkct+N+Gx9PTuOqSOg7oNQKoLF5cR7S+ElR03dwrgk+bXJq URdg== 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=8+FtTqpnU0mY8BgkOB1BvIiQtLfvlP5Rw7Zhn18KQVk=; b=ykHn6AKMWMJVDUCndetTZqJ8X3tTymK1+XQdkj61T1S/jchmVIAwnZUIupm0ARtL/t ECTeyGXtjZKN8rwHHHSbT90M9ZHwOWbPO8KuE7zCnTnmqo2IwgQP139x+TMBB5ZwilLY T+fkcnLSZSv/dtSadJUGvAlvWpa0aJ0WTsE8TJDTGLgIPgDbC5CQJmhU81z04cgumYwy Y83nsg3M2T5yWaBh5tNvYRif6oKfaY4nfMn9UYrSLhj27PFH0imWar/vj6caYkH44URL ha928EwbR77AZfqSVJz0BlN4Cjw8gZVPSID1HVCMgIIYGhNAmAR08tXaxdcllH5mjJz+ 2oFQ== 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 z4si12406254ejf.253.2021.03.28.22.53.41; Sun, 28 Mar 2021 22:54:03 -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 S231142AbhC2FuP (ORCPT + 99 others); Mon, 29 Mar 2021 01:50:15 -0400 Received: from mga07.intel.com ([134.134.136.100]:15632 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230467AbhC2Fto (ORCPT ); Mon, 29 Mar 2021 01:49:44 -0400 IronPort-SDR: 5Jj99WrmJW87X5fxZABJbfd8GgVJ2388wr9M5Ri+kalwluSUKOhE/zogwKaSIPqXVtbgIqu8+/ OcebfcrX8sWA== X-IronPort-AV: E=McAfee;i="6000,8403,9937"; a="255478737" X-IronPort-AV: E=Sophos;i="5.81,285,1610438400"; d="scan'208";a="255478737" 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:49:43 -0700 IronPort-SDR: tgjjlDhyxqrTjb1XVW9XO4AVhFMJ6qZv84B2xpffh+CKPcIk7hDzXyjOPXjST2W7CvHPP3r1kW HZlKfNJFqLyA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,285,1610438400"; d="scan'208";a="417506759" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by orsmga008.jf.intel.com with ESMTP; 28 Mar 2021 22:49:39 -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 , Luwei Kang Subject: [PATCH v4 05/16] KVM: x86/pmu: Introduce the ctrl_mask value for fixed counter Date: Mon, 29 Mar 2021 13:41:26 +0800 Message-Id: <20210329054137.120994-6-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 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 | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index a52f973bdff6..c560960544a3 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -444,6 +444,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 d9dbebe03cae..ac7fe714e6c1 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -400,7 +400,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; } @@ -470,6 +470,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; @@ -477,6 +478,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) @@ -511,6 +513,8 @@ 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->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