Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp415295ybg; Sun, 26 Jul 2020 08:35:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjZ4l4Hnm+TQBYuLLEJI3Na3JxIOIWF5yfNT+XkMB8Ya47vBo57pejYUISPdB/FOFRuHeR X-Received: by 2002:a05:6402:1ade:: with SMTP id ba30mr16861218edb.231.1595777739104; Sun, 26 Jul 2020 08:35:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595777739; cv=none; d=google.com; s=arc-20160816; b=BUSpS2V5fD+qW8+khrYATI87r7+3ITFG/l9luB0/0l8iZUbEBz+5Xpcy7ohyXZ1MdN HpcTWfW30n//uPcxIVKBq9flEztHQykl38SiXG1CJYxZ/fEXFXnKkju8RA8soC+MrEsi H4g9m47YfZeliqTSaQSMlWsO7xG6tNzMFwJf8HvobqSvL9iNmS5wHBVDPZ1fblrUXmrY 4rDVYCFWigEw6Cm9JUyJgCTrO9YPN8xZE6yGq38d/WY+K2BEmqX+ecPrHAyzRhNbgWHf 1inZ2poDDd5J0P/UILxk3tUwJEqTF8oYPv8oV99FVOcxGgfndFJDkCIOf65q/b+noXyw YDwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=/R5QDHGP6pGcHSmkINkD7gF8xYWdMr+YPlgdN1myqdE=; b=IUG2bnqyPDZnYReYgOiF6XNlNe4Fys2QLTuKEJ+Xy4fGQAQSJ19JnKYQoqiDZLX9PV Re6GTCV4fHpeORGbapnpWqAh3THiNRo8GEvBqCg3F0mzkpiRFFSZPSQ7Q9IFqePfUPQn gjSiQoWwcamarHE6GU9R1+UG8ihN5hDZUrpD/phq5AxmGdT5WwgseNXsK3g5aQCsiH5b rInwKRDm9GiP0ft9IBQn7TNwXeTgkIQJ5wQ44btpncm4PDUg/BjSztkkGl/eGtDLIPd4 /2ut7ZcCrNOTUJE2BseeejOWglU1XL6DPk0hj3BHTfSr3LVXehr1EspnCAX1vpRhwJ7o DdQA== 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 u11si4106048edy.592.2020.07.26.08.35.17; Sun, 26 Jul 2020 08:35:39 -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 S1727055AbgGZPez (ORCPT + 99 others); Sun, 26 Jul 2020 11:34:55 -0400 Received: from mga03.intel.com ([134.134.136.65]:17603 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727037AbgGZPev (ORCPT ); Sun, 26 Jul 2020 11:34:51 -0400 IronPort-SDR: I4cUuhujIbUKnMZWeB0M3pfW4njTkT1TxWuy/8YVQjhshloH059qu9KlyxnLFYoEsqFFgDTRKc /yzOVUWPEUYA== X-IronPort-AV: E=McAfee;i="6000,8403,9694"; a="150890969" X-IronPort-AV: E=Sophos;i="5.75,399,1589266800"; d="scan'208";a="150890969" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jul 2020 08:34:51 -0700 IronPort-SDR: a9sLuA9zaKwf3PEAf9BVRYBYNSJCeYGKwJk3i5ecxeQv0ZRWZXOWSsPGhGurHksYyy4AU/53Tx 7vXkDXbl0JGg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,399,1589266800"; d="scan'208";a="303177550" Received: from sqa-gate.sh.intel.com (HELO clx-ap-likexu.tsp.org) ([10.239.48.212]) by orsmga002.jf.intel.com with ESMTP; 26 Jul 2020 08:34:49 -0700 From: Like Xu To: Paolo Bonzini , Vitaly Kuznetsov , Jim Mattson , kvm@vger.kernel.org Cc: Sean Christopherson , Wanpeng Li , Joerg Roedel , linux-kernel@vger.kernel.org, Like Xu Subject: [PATCH v13 03/10] KVM: vmx/pmu: Initialize vcpu perf_capabilities once in intel_pmu_init() Date: Sun, 26 Jul 2020 23:32:22 +0800 Message-Id: <20200726153229.27149-5-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200726153229.27149-1-like.xu@linux.intel.com> References: <20200726153229.27149-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The guest hypervisor may configure MSR_IA32_PERF_CAPABILITIES to unmask some vmx-supported bits in vcpu->arch.perf_capabilities, and the requested value could affect the exposure of features in the intel_pmu_refresh(). Refactoring its initialization path clears the way for the above usage. Signed-off-by: Like Xu --- arch/x86/kvm/vmx/pmu_intel.c | 6 +++--- arch/x86/kvm/x86.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index a886a47daebd..f8083ecf8c7b 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -327,7 +327,6 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) pmu->counter_bitmask[KVM_PMC_FIXED] = 0; pmu->version = 0; pmu->reserved_bits = 0xffffffff00200000ull; - vcpu->arch.perf_capabilities = 0; entry = kvm_find_cpuid_entry(vcpu, 0xa, 0); if (!entry) @@ -340,8 +339,6 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) return; perf_get_x86_pmu_capability(&x86_pmu); - if (guest_cpuid_has(vcpu, X86_FEATURE_PDCM)) - vcpu->arch.perf_capabilities = vmx_get_perf_capabilities(); pmu->nr_arch_gp_counters = min_t(int, eax.split.num_counters, x86_pmu.num_counters_gp); @@ -401,6 +398,9 @@ static void intel_pmu_init(struct kvm_vcpu *vcpu) pmu->fixed_counters[i].idx = i + INTEL_PMC_IDX_FIXED; pmu->fixed_counters[i].current_config = 0; } + + vcpu->arch.perf_capabilities = guest_cpuid_has(vcpu, X86_FEATURE_PDCM) ? + vmx_get_perf_capabilities() : 0; } static void intel_pmu_reset(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c79953b49c77..8a58d0355a99 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2871,7 +2871,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) return 1; vcpu->arch.perf_capabilities = data; - + kvm_pmu_refresh(vcpu); return 0; } case MSR_EFER: -- 2.21.3