Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3127112pxj; Mon, 10 May 2021 19:45:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZ32WynK7/kcnYq9AT7saix8JYX8u+Oos+mW0icBFLKFMjkfrI1lqeWRpdU9/7KEA8x68L X-Received: by 2002:a05:6402:702:: with SMTP id w2mr18641661edx.85.1620701108476; Mon, 10 May 2021 19:45:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620701108; cv=none; d=google.com; s=arc-20160816; b=hSPKUDuQ5NOEY7Nkkn6ZO1hfCcAemR9lVxzjGp3WzwgMw6nngLMP28kgo1iIJXvVdm vehY3Z4hxe/LmocxCVPLBKjnjXoPN6Zv0wJmwIaWwE4G8h/umxzZAnNHhz0aSr3Z5+Jx nVvXHjqbinGvnOvdhcaPis7GxkOR1Xea4AXo7Kqgh0Dd7VIfnx2JtfmLu9vUpwUr5IJc UWBYJBQzkV9Sz4a8phyCBzilO+HszOW17uT3t7VLHKXkJxHdUxFG3tYRlY1ZooCB5UpO zEjlKx0IdnLIX5QbT3S1M201cIqBkXbepRcLtNzOractkTnHqAFG/mi7VwVJO5MDYIv7 lS2g== 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=GV73RXEdrCmxL2ukYz+QnQHvr6ywJPWC3ZrM+fnMINk=; b=tbEFfyrD47JNgrEtk9jPuhFC99rwStrbD+sdFXBUvRLhSaQFSt+RKd/B+CKFwzFDmC AmcnGON/mtD0+xJK//ZYnrcTGo6tSi/XXm6dqrXTJOG4waLhTHYuzFQUHbBIbLxivCfM JeIaHqUj3xnw2V+dVkQ5PWxLajTut9E1OwwEtcP+f/mK6NXHJ0WCfp3Ycf4wuVqfShso wIYhlcO56pnA75kjO5KbTT0b+a79lxgfz6ea0Y2jOLo8V0Z06cm1oN2btyM5QWZTIXu4 JziKSjtUuxaqzWLDZnImWhIPd6CvnB5iWb9byg1HiUoE8WDTnEfuOxS6WFo+JteK23fw VrxQ== 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 o10si15579108edv.54.2021.05.10.19.44.44; Mon, 10 May 2021 19:45:08 -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 S230236AbhEKCo3 (ORCPT + 99 others); Mon, 10 May 2021 22:44:29 -0400 Received: from mga03.intel.com ([134.134.136.65]:7554 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230184AbhEKCoZ (ORCPT ); Mon, 10 May 2021 22:44:25 -0400 IronPort-SDR: aeJUavLJyyotwvVdT29KTKWfRYVWDvL+561eMBbN91xO8vMAKC95ZwLQmLSV8LNQpEWB2naePK qgVjava+jynQ== X-IronPort-AV: E=McAfee;i="6200,9189,9980"; a="199391206" X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="199391206" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 May 2021 19:43:19 -0700 IronPort-SDR: 7a2b7LbHr3hNjpiW68vgkN+qcs/SroJu8xA2EpY2hxOzZ+tzr77nHgOQMQcCFhSsfXbfJe1SGn /LkGDzI27yGw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,290,1613462400"; d="scan'208";a="468591710" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by fmsmga002.fm.intel.com with ESMTP; 10 May 2021 19:43:15 -0700 From: Like Xu To: Peter Zijlstra , Paolo Bonzini Cc: Borislav Petkov , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , weijiang.yang@intel.com, Kan Liang , ak@linux.intel.com, wei.w.wang@intel.com, eranian@google.com, liuxiangdong5@huawei.com, linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, Like Xu , Luwei Kang Subject: [PATCH v6 05/16] KVM: x86/pmu: Introduce the ctrl_mask value for fixed counter Date: Tue, 11 May 2021 10:42:03 +0800 Message-Id: <20210511024214.280733-6-like.xu@linux.intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511024214.280733-1-like.xu@linux.intel.com> References: <20210511024214.280733-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 55efbacfc244..49b421bd3dd8 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -457,6 +457,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.31.1