Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp266455pxv; Wed, 21 Jul 2021 22:44:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxV74xvBgrNwae22A0hrzbBftAcyVkmVLHvabi9PAZbqQiHCN4xkN2foxsqi9Sj9PwoNJvA X-Received: by 2002:a05:6602:2801:: with SMTP id d1mr22352036ioe.73.1626932656756; Wed, 21 Jul 2021 22:44:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626932656; cv=none; d=google.com; s=arc-20160816; b=rwpiYNa7bqBUAtgRHMY8MF/QHN+em+PBIpVk6Rohm87/yqyEYwtRuuVaBx2uaJuEZ3 HRiO1sGXI9pqSwc1fCvDMWe8rksvlJVKGLxCpWZ5YEqhyuC8Cv9t2GhxEQkjTFw7UHvo Z1TT9Af+QmIj35saEODDnDAvQD1Ks71SUHiPQWlq13XV/mCAJLkVVuiUGX4WvxKR537Q bsLCM3Gf2Ye4BWNSiwMrTr4T8rAgmGvbBRXRd+aNGKCwjAIHXhNDVmyAjl9yGzYlyWdy LVO1l4zfieLVK/DKv6kpGj2TwvsET7JqDnV+e4vC13ppkifljxm6nZS8opKS0xU/3P6T vLrA== 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; bh=Ll/KcmMFWcE4U2UvUhFYB34zlCHWY0aIsS9mhD9UVs4=; b=sIN8VfzXHf5QYDchcYxg2poNngq/nRL/sRW+Y/rKLgp485RFvbjfrT/Y+DCqmxqgye 930X6HXf/+nuvLb/wA1ucAXocN22FF6soYCeLk5Wm6Pay+AZo3pSEvo0WzU+nttjwlJ/ +cLQXz1ODwzHCX8jE5kB8sGcp5SqJXg4ze4pn1jfc//j8xDDD7EbDIiaKnz81YCyEvJy PZammiZkSr16k3gzICUweQ9PToIQsy73PuoszZqGNCDRcOhtBvTnin+z9l/B1fAl5Y47 zMuFf3lbEM5YU6DYLmpWgS5o583afw3NdsB1ZRlb/cQeCn92XWWo2a54W34VrUbi6cJt b6Yg== 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 i3si25933004ila.8.2021.07.21.22.44.05; Wed, 21 Jul 2021 22:44:16 -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 S230476AbhGVFCQ (ORCPT + 99 others); Thu, 22 Jul 2021 01:02:16 -0400 Received: from mga06.intel.com ([134.134.136.31]:24019 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230438AbhGVFCO (ORCPT ); Thu, 22 Jul 2021 01:02:14 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10052"; a="272686930" X-IronPort-AV: E=Sophos;i="5.84,260,1620716400"; d="scan'208";a="272686930" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2021 22:42:50 -0700 X-IronPort-AV: E=Sophos;i="5.84,260,1620716400"; d="scan'208";a="512372380" Received: from vmm_a4_icx.sh.intel.com (HELO localhost.localdomain) ([10.239.53.245]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2021 22:42:45 -0700 From: Zhu Lingshan To: peterz@infradead.org, pbonzini@redhat.com Cc: bp@alien8.de, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, kan.liang@linux.intel.com, 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.linux@gmail.com, boris.ostrvsky@oracle.com, Like Xu , Luwei Kang , Zhu Lingshan Subject: [PATCH V9 06/18] KVM: x86/pmu: Introduce the ctrl_mask value for fixed counter Date: Thu, 22 Jul 2021 13:41:47 +0800 Message-Id: <20210722054159.4459-7-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210722054159.4459-1-lingshan.zhu@intel.com> References: <20210722054159.4459-1-lingshan.zhu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Like Xu 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 a generic code refactoring. Co-developed-by: Luwei Kang Signed-off-by: Luwei Kang Signed-off-by: Like Xu Signed-off-by: Zhu Lingshan --- 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 128e2dd9c944..172fabbcc11a 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -489,6 +489,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.27.0