Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1134000pxb; Thu, 4 Mar 2021 04:19:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyfcxKw6vVgAxGar3KIaiMdcaEw9k4/hIPu/AZhYBHFegyoy+0Qyth3xLkOEyMg3AX+gXIp X-Received: by 2002:a17:906:1746:: with SMTP id d6mr4051565eje.36.1614860395801; Thu, 04 Mar 2021 04:19:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614860395; cv=none; d=google.com; s=arc-20160816; b=sRme+3XXArikBsvbq4Kf7MurpmT6Z6huImX8yYGE3xV9dSl22xYcasBw55rbcSZiY2 jRibl87K9LrIt+OgxbsoCfgveACkrIT96xEWNz9iQTmUSIeE/lyShN8rh/JtVbrnIoro F3KPS2pyZKf0NtHd2kdzqmWZ817+bPVCbiAYaSXL+aG5WFIrOUaxB0epZB6WLObXXWBO nKcAJlna+2XjvGu4IGjQVPC83yq3ZDpTLP27qhidi96f1EH7/Z7yaNsKu8Giwb4ou2/0 VTpKHkSbXzEOGeoMfNacUn9xDE1iSaMvpW+oYq/auB6yR8yqb9H9ts/b00J5+PbJzu5R 5X0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=L/B2jvf8QSlBNCpUJ5UwPXNQmrmiUh/OC9Akzgb/wwc=; b=blceguowMTJhuzT8SxAEedX57VNAFoxngToTyS/uDgs/qEx/3fDxnk7kk0Jo3SHX3m KqKOlp0aIhbHTxI/JctCVJ4QdI+ovpafxH8pibFflBMmMbyIY935uNgrDbJZh9ssmfp5 K1K/q7jDfjro4hkL0VI4wV9ncJ/ALRgtHbW44xDEezrqM6RYLMMBrlO6iqt0B7bw/g7n Zz8DOiyBHGBes2XMNzTM9vEGeRHaeeyPesr/Jez4xSn5Hj6A0+B0lhup+W3qOzUhNHfV treX8EdCS3PAyB66kUGwOEBO/Z7tN059rluekEM8CETwUq6ZdgCFaT80fGL1oZmjN2HR 90jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=OiA0h0nr; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z5si17028616edp.552.2021.03.04.04.19.33; Thu, 04 Mar 2021 04:19: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=@google.com header.s=20161025 header.b=OiA0h0nr; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573232AbhCCSq6 (ORCPT + 99 others); Wed, 3 Mar 2021 13:46:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1575632AbhCCRfU (ORCPT ); Wed, 3 Mar 2021 12:35:20 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CFCEC06175F for ; Wed, 3 Mar 2021 09:34:38 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id q204so15693848pfq.10 for ; Wed, 03 Mar 2021 09:34:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=L/B2jvf8QSlBNCpUJ5UwPXNQmrmiUh/OC9Akzgb/wwc=; b=OiA0h0nrfLULZ/6jMpZb4g4oooUevKrxoPa6XlifCg9w18hRef/Dyg8gqmJIPb9oEu RwCU4vyzTu0cMPlYwZ85Ahwo6pJ4nYDm8ITWOipC7Dov8oaDT9/k1XcYMdVxgDQsU/MU 1ugS/SQgLyojmLNJojqu72z3tiBgox8FHadme2NYINvGGe8mM/bjFjQbFVJqW9SwPJh3 kNS0BYP+D2PYpQv82wMH2lvrjCVONbJKeC3urqTIpDPm0+8VCMuGqtBCfXe5X8bVVd4n z4b3jzdKKn3goS/VhSnWo6/Cwh5F7XctW+8GX3jYYhJIq62czD6DZZFht9izQND9KXQ3 020A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=L/B2jvf8QSlBNCpUJ5UwPXNQmrmiUh/OC9Akzgb/wwc=; b=tToOzCaeuRiLp4Bv57QVymscLftH4K9Q95dZnktUr2pQGhdk0WcZYq0e7rDyoZp55c InIuCbMDZT8M2QAjKeZElgzUgePr1e4nFCwI5IMD6HH90et6JWnA7T/98PYyrVd+CJDE rLTv1mJqs1OpKJBpZlW5yZRijC2H1hKBSkQtZxuJoCk06slWcKt/RoAMyfczRnUIbj8c RCsXPQT73POsURjjcCU5KzYQc3OjoonjAYt4w2w5v0d9AuOwmDwUrVAyGhz1d4hLWkHu BcgSUYgDztykPVv4xkRR6eD2EM2iz2+zfCAafTpDWY4uU/LoUXvuDnhP2qyzLVkDPhZs Pc7g== X-Gm-Message-State: AOAM531ONtu9LNGKjev3FNUe5OB6HOEWLs7NUY/NQcLkEpsgX25JjAqB 6SwbLOMAE8vRfW+mL7cuiqinLw== X-Received: by 2002:aa7:8292:0:b029:1ed:d6e5:1333 with SMTP id s18-20020aa782920000b02901edd6e51333mr3975963pfm.55.1614792877604; Wed, 03 Mar 2021 09:34:37 -0800 (PST) Received: from google.com ([2620:15c:f:10:805d:6324:3372:6183]) by smtp.gmail.com with ESMTPSA id x6sm23878717pfd.12.2021.03.03.09.34.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Mar 2021 09:34:37 -0800 (PST) Date: Wed, 3 Mar 2021 09:34:30 -0800 From: Sean Christopherson To: Like Xu Cc: Peter Zijlstra , Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Kan Liang , Dave Hansen , wei.w.wang@intel.com, Borislav Petkov , kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 8/9] KVM: x86: Expose Architectural LBR CPUID leaf Message-ID: References: <20210303135756.1546253-1-like.xu@linux.intel.com> <20210303135756.1546253-9-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210303135756.1546253-9-like.xu@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 03, 2021, Like Xu wrote: > If CPUID.(EAX=07H, ECX=0):EDX[19] is set to 1, then KVM supports Arch > LBRs and CPUID leaf 01CH indicates details of the Arch LBRs capabilities. > Currently, KVM only supports the current host LBR depth for guests, > which is also the maximum supported depth on the host. > > Signed-off-by: Like Xu > --- > arch/x86/kvm/cpuid.c | 25 ++++++++++++++++++++++++- > arch/x86/kvm/vmx/vmx.c | 2 ++ > 2 files changed, 26 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c > index b4247f821277..4473324fe7be 100644 > --- a/arch/x86/kvm/cpuid.c > +++ b/arch/x86/kvm/cpuid.c > @@ -450,7 +450,7 @@ void kvm_set_cpu_caps(void) > F(AVX512_4VNNIW) | F(AVX512_4FMAPS) | F(SPEC_CTRL) | > F(SPEC_CTRL_SSBD) | F(ARCH_CAPABILITIES) | F(INTEL_STIBP) | > F(MD_CLEAR) | F(AVX512_VP2INTERSECT) | F(FSRM) | > - F(SERIALIZE) | F(TSXLDTRK) | F(AVX512_FP16) > + F(SERIALIZE) | F(TSXLDTRK) | F(AVX512_FP16) | F(ARCH_LBR) > ); > > /* TSC_ADJUST and ARCH_CAPABILITIES are emulated in software. */ ... > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 2f307689a14b..034708a3df20 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -7258,6 +7258,8 @@ static __init void vmx_set_cpu_caps(void) > kvm_cpu_cap_clear(X86_FEATURE_INVPCID); > if (vmx_pt_mode_is_host_guest()) > kvm_cpu_cap_check_and_set(X86_FEATURE_INTEL_PT); > + if (cpu_has_vmx_arch_lbr()) > + kvm_cpu_cap_check_and_set(X86_FEATURE_ARCH_LBR); Using kvm_cpu_cap_check_and_set(), which queries boot_cpu_has(), is only necessary if a feature is not exposed by default in kvm_set_cpu_caps(). That's why INTEL_PT uses it. ARCH_LBR on the other hand is set in the "enable by default" mask. That being said, it's probably a bad idea to advertise ARCH_LBR by default. In the unlikely case that AMD adds support for ARCH_LBR, enable-by-default means guest will be able to use ARCH_LBR on old KVMs that presumably would lack support for ARCH_LBR on SVM. TL;DR: omit F(ARCH_LBR) or replace it with "0 /* ARCH_LBR */". > if (vmx_umip_emulated()) > kvm_cpu_cap_set(X86_FEATURE_UMIP); > -- > 2.29.2 >