Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp525889pxb; Wed, 27 Jan 2021 13:55:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWEXPf6VjInnMQubqY/ZerHFIbWrB7kVrvEVroKQAt/60qMW/vh0G5Qy+HpbpNVLC0TpLR X-Received: by 2002:a17:906:6d44:: with SMTP id a4mr8787429ejt.453.1611784555141; Wed, 27 Jan 2021 13:55:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611784555; cv=none; d=google.com; s=arc-20160816; b=ZjiiqmW+J4vInczVDoYhXwRnnmRiKldgQMCh7YgdZM4Ea9HuCQlxZkV1u+IBUl9Oiz XaMLx8w4Cpz2X6MHsJaINsymuK9FMbYNRguCmsolhu8goDCziiiRrEMYTadTlguqjmUi wl5YN3TPpVxrCUuEHqKKfQOJ1F8HK09nz/N2x7r5kTGXfUp7woL34u4DocfdtILa0eZY isCbLW9xoRNYQTkM9dXDj6lcz1yRxz4FSSM8K/OECw8ewG9+zpHHFSmn2E9vNkf9jjDc ZQEGHxAoWtaVGzrvKfgObWisyy/CeDEazvHkhSOqyW6mDESB9Pxbfm2zuLXTqrw7sy14 9oOg== 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=DaFVJvN6AJIm4eMhIGuGzzmhxpfr2bv/IyhgNnC+fcs=; b=N3lAYgVHhyt/AnncOjd8dQ+5dnwVNFMqKSoigmAvAbreFRjed1JAtg1OqvVTPhvsaL sS/tEVwS4XGWjfuVsFQ9rkNs8FRokRzOVB63Se+0jMtma3G17sEEUp/di4CrlojdaFCt VnJmewCPDLTM8Scj4WWx63inJUf9PmwkarZfrVC3DuYE7X/nvJ3bBpTpxHpW+FBWD3hE gMFhhl8l2ZpmBcm46I5SjobQkbqQn3AtEgv231jt9freEco1mezRdTr6ebQoDfQQK1SZ OcxNfktKSYFHeSd5jyBrFkzJH9HeVmWlpC/rzSvk52L8FizMagcl8OsYLzUDhxY2YmOV Isng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gRGHFVQY; 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 d3si1630367edy.581.2021.01.27.13.55.30; Wed, 27 Jan 2021 13:55:55 -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=gRGHFVQY; 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 S235283AbhA0J5m (ORCPT + 99 others); Wed, 27 Jan 2021 04:57:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24350 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235514AbhA0JvQ (ORCPT ); Wed, 27 Jan 2021 04:51:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611740988; 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=DaFVJvN6AJIm4eMhIGuGzzmhxpfr2bv/IyhgNnC+fcs=; b=gRGHFVQY3lmcjbXocK2gZfhlCKx+iaHfhENUM3y1Ntt+sOOGNc9bmFSLhSW3uMZLgbt6KA NOKCBB6BC2PfwCpms2tiLypW97Pnew1RLe933+WaEoNJJnhgCFrfr2UHKc+JfPiIt5TRzL tSf889QCCo8DZrjb6Bvp1t6cbTvPTnI= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-510-1S7lBYw7PzmH7tmERtatuQ-1; Wed, 27 Jan 2021 04:49:46 -0500 X-MC-Unique: 1S7lBYw7PzmH7tmERtatuQ-1 Received: by mail-ej1-f72.google.com with SMTP id jg11so438568ejc.23 for ; Wed, 27 Jan 2021 01:49:46 -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=DaFVJvN6AJIm4eMhIGuGzzmhxpfr2bv/IyhgNnC+fcs=; b=aYq7FrqY9zMou6uz3257KlpH+WOnnjW6asmrpjIHWxG2HSZSyC90zZnRNWe0kjtMcq 49++oS0MfuXXT20Orhq0ET4E2vY9Am02KF4DaUXwqC/AzIkwpx5SSfVSGyaONnJaVHw7 LXG585R9zUGD6Fp9iQ/YogjKff/xfC7oC1m5vuJDwXj1JZFSsqyhO3bZ4paPFVilF7g8 qulNdVK5vQfn5KsT/yhV4bmjKbiojdkAbJsQ/JVXJAj3x26rIXTWCPnXFazY0eRIMQMj LR4ROqah2ZaYkmtZezOvm/i9snqffATnqfOBZHvigrMrlh2M6fkOZBaXtSxOEaE4+1tw C/1A== X-Gm-Message-State: AOAM532rAIUok6HsU1lVIlcYjBhOBAbpM1hrlX3rF4W3vIknfkNkr4Mw 3HXqpiun+PG00hQNIfA75jlC7rgzq3HZWkVWAlzsQgmG4Y5cVlHiKD1teeUp8jvuybYhj9YabcI IZh8wYI2SsNjwxYUQ0OsKGFm8 X-Received: by 2002:a17:906:5495:: with SMTP id r21mr6266576ejo.59.1611740985603; Wed, 27 Jan 2021 01:49:45 -0800 (PST) X-Received: by 2002:a17:906:5495:: with SMTP id r21mr6266562ejo.59.1611740985394; Wed, 27 Jan 2021 01:49:45 -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 v25sm574656ejw.21.2021.01.27.01.49.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Jan 2021 01:49:44 -0800 (PST) Subject: Re: [RESEND v13 09/10] KVM: vmx/pmu: Expose LBR_FMT in the MSR_IA32_PERF_CAPABILITIES To: "Xu, Like" 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, Joerg Roedel , Jim Mattson , Wanpeng Li , Like Xu , Sean Christopherson , Vitaly Kuznetsov References: <20210108013704.134985-1-like.xu@linux.intel.com> <20210108013704.134985-10-like.xu@linux.intel.com> <2ff8ca5a-32ec-ca5d-50c3-d1690e933f6d@redhat.com> From: Paolo Bonzini Message-ID: Date: Wed, 27 Jan 2021 10:49:42 +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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 27/01/21 06:45, Xu, Like wrote: > On 2021/1/26 17:30, Paolo Bonzini wrote: >> 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 >> > Thanks, I'll do this part early in the next version. > > I would have thought that we need to > make the interface exposing as the last enabling step. That's the right thing to do for vmx_get_perf_capabilities(). However, checking the values of MSR_IA32_PERF_CAPABILITIES can be done early. Paolo