Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3124161rwb; Mon, 15 Aug 2022 18:43:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR6vG8QGknoZhUxaE84AQUl5Dmgd2Kvx2u6aznoTY4UYTMFgyBbMAEWrhNU53DYqaIrZw9EG X-Received: by 2002:a17:907:2714:b0:730:851d:66b1 with SMTP id w20-20020a170907271400b00730851d66b1mr11777933ejk.184.1660614222446; Mon, 15 Aug 2022 18:43:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660614222; cv=none; d=google.com; s=arc-20160816; b=DfKK9VYY8OlNwhFMVtFtniED6oCdCfsODb3s84S2HEj4swBOi1YJGRv5EyjdR+6d7t so/KmcmWo9zmTeNqNuVSuDf/yaX5WZxIanLJLEBduE822a66IvvFE40AWRfKFTNb4ORx 2vbIBLMr6KbdBoNKvzkzOMrG2yWY82xi3cnDCUv6QOGkea6sN8ViMmEbhfXjilXsP6mP CiV8QSFh+pZXslIUOWpnfZ4/oovVnvGF5vXkVWS/GGyfjewDV5oftncPZUbafbm0lGBc UNpqInmBkVAqvbuhosEdiuEExgvlyH9VdAVGY+7JRiJWHo3Kdn+0AE6PO8hsnd0oJuqY o5gw== 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=/zANnpO0M1GEYRusC5Y7DwPlAHmQBgSLHFa+lXyaX0Q=; b=mllXhKTotuJ6HhN8T1hMeHE6xiFyyAFzoGKGA0xv8eK500tofMOeM0c1ZeBEXVsIra RCZ2Zad0ho9E2cDCRXFuf0tqEOKjbH86XdkNf9mKyF/hkhAaZgbmaRf1AeOFjn30ROmn whrCq4taC8/11SR4BqlXATx9ifkhtDC1Kse6UBuq9ZxTJ5eKScUTwrG41D1w5tkWYGvR Fmq+P8+c90vryhYhoFefMZJYPsxGYC2gJheQDZj57xaOsqe67T2QUunAZiGaJj+Tj7y4 gsg8hVdDKsWC5GX+Tr59koUkxRmlJBVJy4DG4vMmczrdcp6T0Uxqtx/RwWOWbUgsZqOS uKag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hUIkpD+S; 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 q15-20020a50cc8f000000b0043ade0b9a7fsi8721455edi.195.2022.08.15.18.43.17; Mon, 15 Aug 2022 18:43:42 -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=hUIkpD+S; 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 S1348730AbiHPBCV (ORCPT + 99 others); Mon, 15 Aug 2022 21:02:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345675AbiHPA4s (ORCPT ); Mon, 15 Aug 2022 20:56:48 -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 D527F19ECBE; Mon, 15 Aug 2022 13:48:32 -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 315FDB811AB; Mon, 15 Aug 2022 20:48:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80710C43140; Mon, 15 Aug 2022 20:48:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596509; bh=PZHUzo28fcY40qGF8VAbfQcWrKlhKbJf0GIFTyrboQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hUIkpD+S2EQbQHUEXlESUxDuaPagXiLH+yEA81/SD/3yfCjN/aCvZtRDrTK7l5DKk vEpa1NyrGkBP6thpURsrLwImymzkbvqoVn2bmjefcI3WZfxnf4rHBYum4lJHUndT6A LMokPCfS/5dMxwJLP8cZ/nBYj6vuPKCcVhDrmpjk= 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.19 1102/1157] KVM: x86/pmu: Introduce the ctrl_mask value for fixed counter Date: Mon, 15 Aug 2022 20:07:38 +0200 Message-Id: <20220815180524.342210037@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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 9217bd6cf0d1..4b41ab003a1c 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -505,6 +505,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 counter_bitmask[2]; diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index 37e9eb32e3d9..7e72022a00aa 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -395,7 +395,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; } @@ -479,6 +479,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; @@ -487,6 +488,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 || !vcpu->kvm->arch.enable_pmu) @@ -522,6 +524,8 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) setup_fixed_pmc_eventsel(pmu); } + 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