Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp974832pxx; Thu, 29 Oct 2020 20:58:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydfuQpELpnANZfmTzx7sShCYoQ4QKPMk5r9j1cQCtmLP3MmNA9Z5tmo6ajIIsRDPn1sYRc X-Received: by 2002:a17:906:b009:: with SMTP id v9mr587618ejy.155.1604030310543; Thu, 29 Oct 2020 20:58:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1604030310; cv=none; d=google.com; s=arc-20160816; b=uk4qlHBBI/j9LAv3/mFCv6ECPcQ8Mz/Tvebi+uwOiUsuTvy23emMXj940xXveIds80 SbFU0xUERLbd8MT1R5XkGJIzmj+zhv6w9EXbGnFQTMB5m7HnDqVF7cfZJvgbDI5fScNg q7dtFzAPSd1TXLHZLUsqPIfHikeaV+oh6Tm03dqHF5iYxe0ir3FdmyYJikICanRiLTa3 /5erPAAuT1ShVf32nYIePT2MNCVUnryHuWFhSKFhfNlyPEprmR65qGGsucIjWjlq8ynl aaG6IUZjsAyNuevFm5f7YIct2GwA42p+wKWVvFgWfGEr7GdwSdfMkGESumKzHKc7RsfR 4szw== 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 :ironport-sdr:ironport-sdr; bh=MazNjDflH36nS44+0REuimsVUeZnYn/BYgdGMU39sQ4=; b=jXeauSSsLZHV25lTk2Iim0lp9RlIVH9FFdGemDeILRItyZUj4gIR66aB7mttbyvo4Q znZyHqkl8/iET3KDc2JIdKUnq5Gjvea80TsnQnZYQ4T0dcDhbU6IslcHAiyhspY2fvj4 K5VaF8s+opat0maCWiVBySyzsor/GwpI9QKSAK1MRVUXFbdtGZQqZZy1kxj63sWDv/xe 9LbOE4Q0IYKmyn4qZDeSUxvNeOlvbUuEOBMRrgUg/nAtXPmAj4UlsNoXGSxPZ7mledmk TF+f5iVDluuZoYshTqGmTM+U9ExYm8U4UDE9mG3ymQi9DyDGGQSO0x1vbmv+dBkETrXY 7zyQ== 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 sa7si439404ejb.453.2020.10.29.20.58.08; Thu, 29 Oct 2020 20:58:30 -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 S1726441AbgJ3D4q (ORCPT + 99 others); Thu, 29 Oct 2020 23:56:46 -0400 Received: from mga09.intel.com ([134.134.136.24]:4238 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726419AbgJ3D4p (ORCPT ); Thu, 29 Oct 2020 23:56:45 -0400 IronPort-SDR: tGkqFydCKQsjlLAnn2PPu681ixKz41fBfgdKnN2IU6qeLtwYbkbxzdveNyMTb6LY4NTAjANPUE E3X0iRIkX1Pw== X-IronPort-AV: E=McAfee;i="6000,8403,9789"; a="168685738" X-IronPort-AV: E=Sophos;i="5.77,432,1596524400"; d="scan'208";a="168685738" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2020 20:56:45 -0700 IronPort-SDR: vtGzMqs1vS2Qry1rOPHzUnPkXcNauGT2ieUC2kEMKyoQj9Tulz6NMbavJuOakMwYXRwVidCS/O MmE78hpmiviw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,432,1596524400"; d="scan'208";a="525770423" Received: from sqa-gate.sh.intel.com (HELO clx-ap-likexu.tsp.org) ([10.239.48.212]) by fmsmga006.fm.intel.com with ESMTP; 29 Oct 2020 20:56:42 -0700 From: Like Xu To: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H . Peter Anvin" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND v13 03/10] KVM: x86/pmu: Use IA32_PERF_CAPABILITIES to adjust features visibility Date: Fri, 30 Oct 2020 11:52:13 +0800 Message-Id: <20201030035220.102403-4-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201030035220.102403-1-like.xu@linux.intel.com> References: <20201030035220.102403-1-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Intel platforms, KVM agent could configure MSR_IA32_PERF_CAPABILITIES (such as unmask some vmx-supported bits in vcpu->arch.perf_capabilities) to adjust the visibility of guest PMU features for vPMU-enabled guests. Once MSR_IA32_PERF_CAPABILITIES is changed via vmx_set_msr() validly, the adjustment in intel_pmu_refresh() will be triggered. To ensure the sustainability of the new value, the default initialization path is moved to intel_pmu_init(). Signed-off-by: Like Xu --- arch/x86/kvm/vmx/pmu_intel.c | 6 +++--- arch/x86/kvm/vmx/vmx.c | 5 +++++ arch/x86/kvm/x86.c | 2 +- 3 files changed, 9 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/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 4085c90c8fc2..b9fde795dd96 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2210,6 +2210,11 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) if ((data >> 32) != 0) return 1; goto find_uret_msr; + case MSR_IA32_PERF_CAPABILITIES: + if (data && !vcpu_to_pmu(vcpu)->version) + return 1; + ret = kvm_set_msr_common(vcpu, msr_info); + break; default: find_uret_msr: diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 021791991e05..410d5209a76f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3029,7 +3029,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