Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1859361rwb; Fri, 19 Aug 2022 10:34:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR5gKlEpgqK8yG2TsF/Qmmm8V9FJegh9CIl7r2DvyTH3k7H06YKAxh9/uZXwwrAVH2CAjWN6 X-Received: by 2002:a63:5f8e:0:b0:429:c286:4ef7 with SMTP id t136-20020a635f8e000000b00429c2864ef7mr6961991pgb.166.1660930446270; Fri, 19 Aug 2022 10:34:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930446; cv=none; d=google.com; s=arc-20160816; b=BS010y6zkK1QOvlImbwveZ3eW7GYPooyabicpJ82sKPNBnJG6+JDHLnt8UkI6gocKp GbHGH2qJgoA9WTVspr541s4j5zP3PJNeyddXB30mvywtFhb/2yP2cobrNmxvFdbjY/qL 6xyNdF82+9FdYZpNmjukuB97zRj1oYHQlXwjtG2nFiK/rG+HM0Pmb0aWEZpvs6a2dvXD nHiHd3I/1QsEEx4hFxL7OtYhjHocuD6TNdoZgoKtJIuvppIIkZ48R1t7bURPu2sjZ9rf 8oegou4kFVThfC30m+uxDEBczWibB7mB5XUR2BmQR0gwsoj0+W7/xhoJ9VT3N9oDF120 hRfg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LYk37WvsSqWv/hIxtJiKEAYD9lKdBfOLMtGBz9BFEQE=; b=lU55ZvoOo29z9nsi/kxfoYTdfKgm9BHfRuQztqeJRr15GYmUAooaYCXHFmEP1PA9tq PnbBxv0Q6IVshcLfOrFnZD8hYtkLuWkS2fO0IS8WMKgiaIybD84CyxBnobXIA8bB94xn ptotloobVXw4WBsn4yWJX6nyiP1uVcsQYTlm2wUnpEsVE9St59CEoJHxL4Hh5+It447D ZC3mGM2HK6n9NptjTUbZcj6E6B/dq/zfSscft/DfuJfucX+U4Pt8diHPZQVDSeh6QB3y 0tpBbkHlOdWPPQR42honzo5M2DFQqXB0Cb2l72JOdt2g+3tMt9ZenQOXJVh4VqZniNrC aEFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qjtahmOj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h132-20020a636c8a000000b00412607fea43si451982pgc.617.2022.08.19.10.33.55; Fri, 19 Aug 2022 10:34:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qjtahmOj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354164AbiHSQwH (ORCPT + 99 others); Fri, 19 Aug 2022 12:52:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354307AbiHSQub (ORCPT ); Fri, 19 Aug 2022 12:50:31 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3640461730; Fri, 19 Aug 2022 09:13:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C0560B82826; Fri, 19 Aug 2022 16:13:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1972C433C1; Fri, 19 Aug 2022 16:13:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660925581; bh=DTKZ6bdI5jrQB4QII9bce3SIgjNBeTrpBNeMprKIUck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qjtahmOjHnBZDT2taFwNhh56zjAb0srMjfHSLiUWkEN+xfY/cheJQ5Y5PSQ0syXGg qHSFD66nqYyOKvnyQR5IiNo3Ok8E52tr3rHfhViH2uBD/V7Tb03VoXvDVYoVovUSSX Q97Mzx6g//i0PCCFbapKt0CGNilqtTfGfXXUffoI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Luwei Kang , Like Xu , "Peter Zijlstra (Intel)" , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.10 507/545] KVM: x86/pmu: Introduce the ctrl_mask value for fixed counter Date: Fri, 19 Aug 2022 17:44:37 +0200 Message-Id: <20220819153852.170395868@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Like Xu [ Upstream commit 2c985527dd8d283e786ad7a67e532ef7f6f00fac ] 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 Acked-by: Peter Zijlstra (Intel) Message-Id: <20220411101946.20262-6-likexu@tencent.com> Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- 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 613334d626b2..38c63a78aba6 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -432,6 +432,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 663b6eb5de66..ea5a7056fdfd 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -259,7 +259,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; } @@ -326,6 +326,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; @@ -334,6 +335,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) pmu->version = 0; pmu->reserved_bits = 0xffffffff00200000ull; pmu->raw_event_mask = X86_RAW_EVENT_MASK; + pmu->fixed_ctr_ctrl_mask = ~0ull; entry = kvm_find_cpuid_entry(vcpu, 0xa, 0); if (!entry) @@ -367,6 +369,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.35.1