Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3035227rwb; Mon, 15 Aug 2022 16:35:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR59hnjRb+Jr0XqzRCxoyTehVRNaFKKdsAYnoVS7lWwBMQKsWg/e9x7lJn6/EQ4zlj/oWHw5 X-Received: by 2002:a05:6402:5203:b0:43d:444b:9f99 with SMTP id s3-20020a056402520300b0043d444b9f99mr16855464edd.343.1660606503215; Mon, 15 Aug 2022 16:35:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660606503; cv=none; d=google.com; s=arc-20160816; b=B6zys8YwP+r3LLy/aM/DDviUemFXdBeLZ6JRSdlyYn9Xn+HWsYWo570NdbUWpjLaCX HWaQfzfKgJC+S8P9Y0fLSJzyaw+FlBAqzdUw7xhlYdqF009JOYd2kqI3PIjgiVjYTS26 Bym4eq2vqiFTxPGDTeKHm7RGGssNcUzXpvlcD3C/VavMCE5Dy1ZZBROtIE7tekUeuGa1 3vIjZg8mvYUfGhOEQfcnDpL7YR9yR+jhL6JAUgCYWFBDv0q9M2wFbf2ehep8PaIN73Bh Kg10DBv4TjMJ7GntQsvD67Xgnek41BrdP2q6nVHXaYDPMaxjVB2+UJRJHf9AeKhvXMxl jCrQ== 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=2Uqgz//M5qYMIVfWJSC1uxEf1x+7Ygr90gBQLEl6rvs=; b=b0wdPadixo1wXygJ5dWA4aWCFyTf0yiA6v5rCuyjXMxiN1zhBaCIphIluIsg+UmTiB zUU80HCT6wZdfXYvpq8zyR5K7CaT0998f9r5gE7kL/gQUW8MNoBnJzmEq0DtbYob74kZ pJo5MsHupzjQaJR1eObqKkjF7UPeSzbkjO2FSvWxI6CyY3+OUL+trjEcvFsaaUM/6+JR ujJrNVl5moTtDeGNIWwGuGxqktXAA/m0M8iDLxN31vv7UEX5Bx0rqLCPi7sPAD+1kZSf GgPmKZvyJfqlMArYc1Lq58ztvPb3uWc/BeB3Y1vpG4QToQWZ5bUTD1XBng4p6SKh1eSk QR4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h2nV5w0k; 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 z12-20020a170906714c00b00730947701dbsi7576048ejj.485.2022.08.15.16.34.27; Mon, 15 Aug 2022 16:35:03 -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=h2nV5w0k; 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 S1352956AbiHOXb0 (ORCPT + 99 others); Mon, 15 Aug 2022 19:31:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343905AbiHOX0K (ORCPT ); Mon, 15 Aug 2022 19:26:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77A7A47BBE; Mon, 15 Aug 2022 13:06:18 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 156EB6069F; Mon, 15 Aug 2022 20:06:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F32BC433D6; Mon, 15 Aug 2022 20:06:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660593977; bh=LbYr9atvpCd18aFJFyM1+zLJDnqYHvtoUfsb5FBaeuw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h2nV5w0kTBGYmGhaMu4EQXQ4EdyR4k0QtAsjw1llYtinQv9K7Yhoe0X83EF2IfR/y E7Fc/Q1CwDrBPeS1/V5vPKCwPOwY85rAx6Z5NDlXdzBp0051ANTFzpe/srE+zP/wPt ZOJKLV8vCTOtcQTYJ+tl+82x4hvTfs8BuTGFA5sA= 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.18 1037/1095] KVM: x86/pmu: Introduce the ctrl_mask value for fixed counter Date: Mon, 15 Aug 2022 20:07:16 +0200 Message-Id: <20220815180511.988000689@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 57550a427789..35c7a1fce8ea 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -508,6 +508,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 b82b6709d7a8..040d598622e3 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