Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1118434pxv; Fri, 16 Jul 2021 01:56:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9oAZT8gpvPKoQKL4InWyWaJv/j1eRAhLjFogPTN7yGnJXJOC4MjuurRonN5eZRMbCLez4 X-Received: by 2002:a02:942e:: with SMTP id a43mr8168603jai.74.1626425813216; Fri, 16 Jul 2021 01:56:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626425813; cv=none; d=google.com; s=arc-20160816; b=aG3w1XhcAmqfuQSlCmP0Eao0NSj6lWrBOmcLuqMh+Y4iyKxzAsaKlJMXuNEm46RMoW mAVCs546RjIXvosugMMEIDJw+rbvG+UXFyuNSELsNCsbpXELye0cxTgyM81z4X+7funn +SAUgOKBKOIewPzNBFSWZWIfyuyQMQ7P5ePaDaZLm7GAz9Cgp3QGZdNeqWRO3nK8BHH5 eA7WTcx/JWCAXVhmlFqthRh3qE59aSo7GW9oKn8UyjHCX9huUcIJ2DliQFVUWOLoTtSY BTosUAyx6u0LI1T4FKiEBRuxv7TxHcZYg4ouxFVKERRwuKjLnybfcR2kHtbkFeJcU1OL fs4w== 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=yBrew0bc1QsY2IUNMAH1BaZqtdzSRY0CGQ0Lf22KSV+LIFHFxUC1QP8kPe/TIapk6T Vlhks23kncDAx3DGbDh45lpxCq/GSgTmqBw4HltGpFUKz/vESXeMMFFbhxMOlM/cgZWp e+Kf7sDK7k8VN4S+ZGkNvPymSUXeqxx+JM6DZSAg/gISE05Wmw5c+HdjiMdh25NLYFUx hL/OJk+oyS2sQiadWjNbULH4VsdfZZz5LUKKPDT6/8xcJnepSGTqfyXwaYzdbY15o2oB d1Fi80WBaxRSXxel/MvzewFYIRgCllkouIXw0vonwCahhlfVXnnXvwdmKhcIvfNsb8Pq GuiA== 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 d16si9031706ilf.112.2021.07.16.01.56.41; Fri, 16 Jul 2021 01:56:53 -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 S239104AbhGPI50 (ORCPT + 99 others); Fri, 16 Jul 2021 04:57:26 -0400 Received: from mga07.intel.com ([134.134.136.100]:47963 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238380AbhGPI5S (ORCPT ); Fri, 16 Jul 2021 04:57:18 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10046"; a="274526347" X-IronPort-AV: E=Sophos;i="5.84,244,1620716400"; d="scan'208";a="274526347" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jul 2021 01:54:24 -0700 X-IronPort-AV: E=Sophos;i="5.84,244,1620716400"; d="scan'208";a="495983937" Received: from vmm_a4_icx.sh.intel.com (HELO localhost.localdomain) ([10.239.53.245]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jul 2021 01:54:20 -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 V8 06/18] KVM: x86/pmu: Introduce the ctrl_mask value for fixed counter Date: Fri, 16 Jul 2021 16:53:13 +0800 Message-Id: <20210716085325.10300-7-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210716085325.10300-1-lingshan.zhu@intel.com> References: <20210716085325.10300-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