Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3735249pxb; Tue, 26 Jan 2021 03:29:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3E5w/boO2SJJk7eWv3M4w4LlPoQq32bDpjqZJsH9e2vGWCcKMmfiAGv4x8xDHu/+DFqfM X-Received: by 2002:a17:906:11d3:: with SMTP id o19mr3351069eja.256.1611660559389; Tue, 26 Jan 2021 03:29:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611660559; cv=none; d=google.com; s=arc-20160816; b=kNsrPjuZsD9acbr854Te/hLn26NAFo8HkqDDddsKdhx24QIooSK1B/AgQZDtKj9kWc qfmlYDYmMrCjd87Rtpt0utEwbD4azLPDQaHB2Z1cvJ9+2zVe86t1/g4QpsMwy43Hb366 d2ocsWLkoYFQJVvtkaa8Emw7dVTQOLW72/sKh/g0LiD+TI/SN8/N0XP5u5glu3/VV23h O1uOvYmYIIMIuEASjPVpKk7cvRv2W2fKyrU/CWmH052DmR/UOrx0WkmnFSDsm9hezr/i r7jU0r37LU8CZV2s6t/qRomQNeXQBXQ9ScaYmev9RxlKEW/Qar1B91VK/VbiSLPOk2jh NI6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=h+ZpZHpOkIPnIutZEYCghjpUFXEecoOLDsLy71i5vGQ=; b=QY9+U7IM9BjZRQJeThlg5ImsAoCuj4O88LXMGLzd3knZRwwsN2uMsBXrY9krFWJtJG Ff/UBvld11aSrIKhyZCejz2fJDlt0wc9Kv6Na5q07C3vdnYGrFQVB2Fp5GhYQ2PdTfBu fJZ10mZshJmYy+DjJBOVHblQOdoSaZs7uTvv/hf3/gQ/oZ6p4qh2M9hPCXFuGhax/vP0 c9Z5jzXprAI9OaMIPDIarSKZy6Syluu/ed6UxQBBU8/P8n2aHXfnzahbUCndtvlDr+j2 pyvWuOaPg7JSi3/KBMSHIEVlQwmypQE/JtFbvptGzPZiVGszQUKWTNHXMwrC0oC264kV yXlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hR4pW+LW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l26si7146220ejc.315.2021.01.26.03.28.53; Tue, 26 Jan 2021 03:29:19 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hR4pW+LW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392262AbhAZL1L (ORCPT + 99 others); Tue, 26 Jan 2021 06:27:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48710 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391162AbhAZJbf (ORCPT ); Tue, 26 Jan 2021 04:31:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611653408; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h+ZpZHpOkIPnIutZEYCghjpUFXEecoOLDsLy71i5vGQ=; b=hR4pW+LWomkdON9SViap7LahQOgEMGyng20K4Fs+wXkh3aC9iqhRImreKN73gpfVvdA/30 880423Pt/NL6e6lNtsDo+ZqMEY3KP8Qnoen8fo5fd9MU1k3U0El2dlJTeh9+WJG4zNtGfd 14aKiZGy5r8Itdgvmf2EyNXwkJmL1qY= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-206-y6F1hYppPgiDu2r3UvxGzg-1; Tue, 26 Jan 2021 04:30:07 -0500 X-MC-Unique: y6F1hYppPgiDu2r3UvxGzg-1 Received: by mail-wr1-f70.google.com with SMTP id u3so10815185wri.19 for ; Tue, 26 Jan 2021 01:30:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=h+ZpZHpOkIPnIutZEYCghjpUFXEecoOLDsLy71i5vGQ=; b=KcHspg6P0HZF1OQAB6sjwraf95P6kwA9GhKuTEPVTtSbvugspclnP0urRnSJYMx6BK uRnH3RcIZDef6AabjJpwX1wYYyd5e2UqsLKy5X4NzSkeMnNlMDxO5PLJHKuixpaOgOkO pq/rKO0oPYbIW+d8oJbjZty8HdO6eFfugY3l6nOHIqBrOlX+KZCdwWsAky03dxpUNjhw eLCRKu+xnRdOt7b9kv9t9HZFdb34OK/Umg/y3Ln7pjR2Pb1+/h2KlZPxwHLzM4jIqgEg Yg+GXEVACjWJ14OMH3RQuBgSRjQQ/jdyt0lEmg0KcR0leP1iJ9yv6u9P41F3yx7n2GCh 3Zuw== X-Gm-Message-State: AOAM531lbWQ8AZnoSQzCEAhKrkgtDeD99ndvuadKoP3GEKTNFjeTfdUA 9QNqbRq536b272LIvPbw0bxnvg2BI046knPnxaLXmpxjjV5ThG/mmSzQU88EU2B+ApQ/luWtbCk uUSHZ5KIAYA3DFepveR9lUMyCTNfhPlpB4GkOtlvS7/uOYSp/YyahMtf/4QItw6uPxTS3H+yhwS nA X-Received: by 2002:a05:6000:1142:: with SMTP id d2mr5142103wrx.307.1611653405294; Tue, 26 Jan 2021 01:30:05 -0800 (PST) X-Received: by 2002:a05:6000:1142:: with SMTP id d2mr5142070wrx.307.1611653405005; Tue, 26 Jan 2021 01:30:05 -0800 (PST) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id k131sm2540210wmb.37.2021.01.26.01.30.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 Jan 2021 01:30:04 -0800 (PST) Subject: Re: [RESEND v13 09/10] KVM: vmx/pmu: Expose LBR_FMT in the MSR_IA32_PERF_CAPABILITIES To: Like Xu , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , ak@linux.intel.com, wei.w.wang@intel.com, kan.liang@intel.com, x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210108013704.134985-1-like.xu@linux.intel.com> <20210108013704.134985-10-like.xu@linux.intel.com> From: Paolo Bonzini Message-ID: <2ff8ca5a-32ec-ca5d-50c3-d1690e933f6d@redhat.com> Date: Tue, 26 Jan 2021 10:30:03 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210108013704.134985-10-like.xu@linux.intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/01/21 02:37, Like Xu wrote: > Userspace could enable guest LBR feature when the exactly supported > LBR format value is initialized to the MSR_IA32_PERF_CAPABILITIES > and the LBR is also compatible with vPMU version and host cpu model. > > Signed-off-by: Like Xu > Reviewed-by: Andi Kleen > --- > arch/x86/kvm/vmx/capabilities.h | 9 ++++++++- > arch/x86/kvm/vmx/vmx.c | 7 +++++++ > 2 files changed, 15 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h > index 57b940c613ab..a9a7c4d1b634 100644 > --- a/arch/x86/kvm/vmx/capabilities.h > +++ b/arch/x86/kvm/vmx/capabilities.h > @@ -378,7 +378,14 @@ static inline u64 vmx_get_perf_capabilities(void) > * Since counters are virtualized, KVM would support full > * width counting unconditionally, even if the host lacks it. > */ > - return PMU_CAP_FW_WRITES; > + u64 perf_cap = PMU_CAP_FW_WRITES; > + > + if (boot_cpu_has(X86_FEATURE_PDCM)) > + rdmsrl(MSR_IA32_PERF_CAPABILITIES, perf_cap); > + > + perf_cap |= perf_cap & PMU_CAP_LBR_FMT; > + > + return perf_cap; > } > > static inline u64 vmx_supported_debugctl(void) > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index ad3b079f6700..9cb5b1e4fc27 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -2229,6 +2229,13 @@ static int vmx_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > case MSR_IA32_PERF_CAPABILITIES: > if (data && !vcpu_to_pmu(vcpu)->version) > return 1; > + if (data & PMU_CAP_LBR_FMT) { > + if ((data & PMU_CAP_LBR_FMT) != > + (vmx_get_perf_capabilities() & PMU_CAP_LBR_FMT)) > + return 1; > + if (!intel_pmu_lbr_is_compatible(vcpu)) > + return 1; > + } > ret = kvm_set_msr_common(vcpu, msr_info); > break; > > Please move this hunk to patch 4. Paolo