Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp2900366pxb; Sun, 8 Nov 2020 18:19:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJwk0WzGDXHJSCqT7wGCKLgRhaTEZpkPYSm4PIPhOTrQT+CcXmZapAn2TNjHY0ROl9QGPrKP X-Received: by 2002:a17:906:398b:: with SMTP id h11mr13325287eje.277.1604888354356; Sun, 08 Nov 2020 18:19:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604888354; cv=none; d=google.com; s=arc-20160816; b=EJ2JWouflxznCe24WTEPsVUgxxdVaugYEPRsmfYegi5qAQbYfnTiFhxB+snuIgz1xa 0+szSVDjTzgdyQS4WY2Vh91GSk8CgDux+vbC1LEoaFL9yl52uuAG9g8piCy42tjzA03J 26hBATbSIT8TGt6NmyePRcuJ/WbNFjRQXN4lmO6atxTZ6antGhbapRCkiMVMpVhBsn53 2n9vwYLP7jJN5nuDc6ZJYwViCIw9uebo7rJq1BtpJIO1h3cvXVKHPh/MVABTxSRyIVhS nj9TfsLWQz58W7EGAv5tkhmnQLNzxyGDG2pj95osr3DWejmY6rX2yq0/IxCpDQMPLGGR eM/Q== 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=zM5G3eN/Vlu55rcFOX5dQD5Vw/vtrR3PyLFBSTjr31s=; b=gMZJf6hdak7ErFrO6UFTV1LOKm3K3/sQfjtu/H3McHa5+4q1IJhkogtJptHySiZ5ZB 3f65IPdVHJKajl4MMMpVFrWPS3KNuNrbcWkB5vi57zOhEiBqvcIWPBVzrMz+SFVUeIO8 71v7UaThCjGzyhBFA/TCpyIXFZPwjVf3NlhkZ5N5y78AWGay0YiqYxcuMVjkKJ5cZeU4 P0tL8gTYEVG4zrIYBh7nUsCx66woJAeOWSpkaX8RzlpBzLEdirnJTIKWtUxpsVqOTqOw 4AtKozL60h13udCRBBtCLOoZzTEWu4AbGqLzWMAyeZOhW3K8HzhbG6qjYxAtVT28x3J8 SHuA== 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 m18si5878610ejb.604.2020.11.08.18.18.52; Sun, 08 Nov 2020 18:19:14 -0800 (PST) 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 S1729193AbgKICRA (ORCPT + 99 others); Sun, 8 Nov 2020 21:17:00 -0500 Received: from mga01.intel.com ([192.55.52.88]:64875 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729216AbgKICQ6 (ORCPT ); Sun, 8 Nov 2020 21:16:58 -0500 IronPort-SDR: HFf0aMtJcPoxubD9PKZo8mbkcEYPLxVemA3tF4b4TAUGhzxHNCwWddSDI2OAeHanK2BiK1OS1M 8sj24xZZaiIw== X-IronPort-AV: E=McAfee;i="6000,8403,9799"; a="187684572" X-IronPort-AV: E=Sophos;i="5.77,462,1596524400"; d="scan'208";a="187684572" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2020 18:16:57 -0800 IronPort-SDR: 5Eb2OerQ21gcJj5BjwrEi9DNvEcqI2KIv+AR85ywLRg1GpBXK001m5bzJ0wls0Rn2o8Yy/PUx1 x9RkHs9nBmqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,462,1596524400"; d="scan'208";a="540646125" Received: from e5-2699-v4-likexu.sh.intel.com ([10.239.48.39]) by orsmga005.jf.intel.com with ESMTP; 08 Nov 2020 18:16:53 -0800 From: Like Xu To: Peter Zijlstra , Paolo Bonzini , kvm@vger.kernel.org Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Kan Liang , luwei.kang@intel.com, Thomas Gleixner , wei.w.wang@intel.com, Tony Luck , Stephane Eranian , Mark Gross , Srinivas Pandruvada , linux-kernel@vger.kernel.org Subject: [PATCH v2 02/17] KVM: vmx/pmu: Use IA32_PERF_CAPABILITIES to adjust features visibility Date: Mon, 9 Nov 2020 10:12:39 +0800 Message-Id: <20201109021254.79755-3-like.xu@linux.intel.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201109021254.79755-1-like.xu@linux.intel.com> References: <20201109021254.79755-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 validly via vmx_set_msr(), 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 01c7d84ecf3e..7c18c85328da 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) @@ -342,8 +341,6 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu) vcpu->arch.ia32_misc_enable_msr |= MSR_IA32_MISC_ENABLE_EMON; 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); @@ -403,6 +400,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 281c405c7ea3..83a16ae04b4e 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2197,6 +2197,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 c89e423f6f5e..e1280bb18152 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