Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13817937pxu; Mon, 4 Jan 2021 05:26:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyErbnct8IlXrL/ug1B0OMJ+VWMYd1pB8z80ppAEJqWZSgjFYcj+iEiI2VkJD+WHcU2EnAE X-Received: by 2002:a17:907:9705:: with SMTP id jg5mr67582161ejc.448.1609766774097; Mon, 04 Jan 2021 05:26:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609766774; cv=none; d=google.com; s=arc-20160816; b=KPExWR4gnaQlqTWNn8bNgskUTltFjeHmifLDddTwKLyJJmQ4MNs3QoQcFHpAgLYXT0 bbupAjFHW9CgFE/KkfCssa+QN9T4cPKTTyhLaYIMh7VbE8LJhWCSmtyI3nAICBOLke3K NdmsamJOEXl5rzxKlOTo2nR3vNhuGuDPIgkxMSxUCsVWyg1k73vosGUv8Kjf4OgXO46U YQ6h4sGPLDGpsM3+YDgdY/mCP2Esz8JTDFr+RTMr24rK+Qp2dw56PS6ADsgyxrxEiEml JClUa/4A+BoRkcIGpDr1knEsFq9rbAKWql9WNXz1pKVn670b3xmoOJEdLxtFHLTXfv+H tM8w== 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=bnVaknPFLTwERuHSBEEfrY8dCk4gDm3lEERmMOdMsAQ=; b=UplDfgVaA0N3SvpLYHUu8LPdjjqL1Lax6tPY/Z0TRcKQNrRjJotOnystViqreJ8IrL /JIxtBVJLz28YpZ7U0STSK3wJCEA4vP3Py5qRnNnXlUTyp/IntwY8RofnGJth3sQbVv7 r8+xyRfGUisOgsf6bZwbReu/yKWBNZSLx0hmbvl41h1niqwO5AoVIhRA1DmzYl+qdtWP lL8G+FDQcEeOlTttdiIs8OhsKFjMw7CeoepYAelwng18n6kA12zB3WxCkeURigq7lm/p J4dQot/Jtg2BnB08cgrLctYx83xonchkb+dAjyUGi53+GJIqXeaOTmOV8+zBPyizgIJY DddA== 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 m7si34600611edq.123.2021.01.04.05.25.51; Mon, 04 Jan 2021 05:26: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 S1727146AbhADNXw (ORCPT + 99 others); Mon, 4 Jan 2021 08:23:52 -0500 Received: from mga07.intel.com ([134.134.136.100]:23250 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726670AbhADNXv (ORCPT ); Mon, 4 Jan 2021 08:23:51 -0500 IronPort-SDR: vh6eDlTf1FajgIEvsjVEkcuVZKpVw7zItICBIVxPVQlhNGiskx0bsoXMp35qHPhOXFsKyhB6RO URqablbLZpRQ== X-IronPort-AV: E=McAfee;i="6000,8403,9853"; a="241034286" X-IronPort-AV: E=Sophos;i="5.78,474,1599548400"; d="scan'208";a="241034286" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jan 2021 05:22:05 -0800 IronPort-SDR: 8V3wvu92/v3Ugp0BmNmnvuYtRtHlhMone7GdyMUmehzi5qoTiw+RF3xedx164O6OnmqXXgWbn+ xjcgL08CqDOA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,474,1599548400"; d="scan'208";a="461944526" Received: from clx-ap-likexu.sh.intel.com ([10.239.48.108]) by fmsmga001.fm.intel.com with ESMTP; 04 Jan 2021 05:22:02 -0800 From: Like Xu To: Peter Zijlstra , Paolo Bonzini , eranian@google.com, kvm@vger.kernel.org Cc: Ingo Molnar , Sean Christopherson , Thomas Gleixner , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Andi Kleen , Kan Liang , wei.w.wang@intel.com, luwei.kang@intel.com, linux-kernel@vger.kernel.org Subject: [PATCH v3 02/17] KVM: x86/pmu: Use IA32_PERF_CAPABILITIES to adjust features visibility Date: Mon, 4 Jan 2021 21:15:27 +0800 Message-Id: <20210104131542.495413-3-like.xu@linux.intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210104131542.495413-1-like.xu@linux.intel.com> References: <20210104131542.495413-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 75c9c6a0a3a4..09bc41c53cd8 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2196,6 +2196,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 87f97ffa9966..a38ca932eec5 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3037,7 +3037,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.29.2