Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp144334pxb; Wed, 3 Feb 2021 01:45:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6jqnmnlI1h7Jy8P+xO8pSdi+EfqXLisrasSLNsCRStHPrnWao4NbAKZ4uRdJkR4JKf9wu X-Received: by 2002:a05:6402:d05:: with SMTP id eb5mr2018952edb.143.1612345519617; Wed, 03 Feb 2021 01:45:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612345519; cv=none; d=google.com; s=arc-20160816; b=vxvy702FfH9TypYaZnia9groGxR/Tn5B07/qpkkivlMkhVZ0XqW8TYhfjIhPBUsdht 5GQUCf46bAqYTmK8HRm+NnHpzYWWFK/ZWRp+nXkYoZJn+iImOQiEVywiQuAwo+sc5wWr yoCFVcNPTTtU+ZE8XX0idsCv0FvjzoQAfXsqnG4rx3jX94woPLb/KmLba3uxmHHfRK+D r1z6lIyHM9KIeAW0xSeIRLM6M2r+mZObDpNh1gx5otlhqKnNA9omsHKbZ6gPGL01CBfO lNIwbY5jSmBeEJKHeV9C4WRK7tsY4oIS11keqyGkU2wOTsag0u+B/sQjaR4sjAvPLexJ pzxw== 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=biSKBCz8mruHfx6T0zzWWZ0kE/fGP6S93LISl+LC4YQ=; b=NlPEm4NabboYz+4yghcrRr6MKX/4eaNwhbqShMaRqd1ueKEu7ajqsDJLLezhkTkxP+ cDSSGCWez7DuK81+U+U4lB9W1Y5ryZAc9/bkffItUbs0Fz40sDoc3HJwW7jziyWgbIgq 1ysMcgyZX5ZEjik7hTX6m4/FmTv7F1Gh8j111dGZH5DxYa7zJl3GpyikrE11IIx/T6v/ 5XvHLPZq1V1/Z2Mmrm6Sg4u3Fs/fu08Kn9JHWPbg2oR/j/pva0wWDTO4uXvPSvSYNccp nk7W5wpOSRGDU5b0aw+1+OQ/u03+zc6qBngVlz1r7jTtPsyTeKK/x9yYfVShy3cq21SQ /FWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=EIsN3IFb; 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 s8si982531ejd.111.2021.02.03.01.44.55; Wed, 03 Feb 2021 01:45: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=EIsN3IFb; 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 S233125AbhBCJoH (ORCPT + 99 others); Wed, 3 Feb 2021 04:44:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:23804 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbhBCJny (ORCPT ); Wed, 3 Feb 2021 04:43:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612345348; 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=biSKBCz8mruHfx6T0zzWWZ0kE/fGP6S93LISl+LC4YQ=; b=EIsN3IFbu/MGknE88neWPUOJRFKVuAawtuvg3O4gKL3q292xed5+l/0B8PlqR/6Q4cDmV5 4nDIOn1oSQa1zw+b20simLiL9s2zj0oYib/WGZR1C92b+YGl3aOptGxp+IGZEGNK0JWmXL ujgleHvxGSaeMgR87IWepgkwiBnlu1U= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-318-b2CkWUVrNO6r-7kahe4TAA-1; Wed, 03 Feb 2021 04:42:26 -0500 X-MC-Unique: b2CkWUVrNO6r-7kahe4TAA-1 Received: by mail-ed1-f69.google.com with SMTP id ck25so11050698edb.16 for ; Wed, 03 Feb 2021 01:42:26 -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=biSKBCz8mruHfx6T0zzWWZ0kE/fGP6S93LISl+LC4YQ=; b=BSaKKy1EBvvG2faoQyl0M5+q9AhgxksDjKCQQ734F4jt7Fvoz/rpSVHBH1iKBmQ+F2 IT81M2onHxDCWiyG/LyeZIFAN875Ih8fchTcepWq/A+edjApZF3bGY5kTeOigiWHj+AN qBWGF5MtZtDGC10rLUwrsWsCKJWNE1PuksIJJ732CBUbFitizoL4XIKHwGViAGuDwu4z kPxjk2h6ncafH6o6eX8b6QR3TXjUXFwNANW9bWe84gGI08T3bqwY3lPj0E04esuA0FUp cHuo64eETAY3HmR765oyQ4H+15NUQlUsq/Mo6tCU0UUqNKeWRVX78RVPBgamlPuUAPdG 7jWw== X-Gm-Message-State: AOAM533BakL+5H9kqOLGNg4UelChVFj3+uuwSukPRm6QGZeXsXypDSc9 DlAUW2wS6am1uE9OXczAslPGR7s9sNfaEEbpyKBOSSrs1eYZch2ONfYo1bh/m+XgycqyV1BD8qg E8Dz5qnD2zccn63oM0B64ciLnkfvWz2fJx3zdpfwBaOCfhCBBMXYbQ+0MTaWGx+wk2pZ9/LRdNl pL X-Received: by 2002:aa7:d352:: with SMTP id m18mr2081512edr.190.1612345345068; Wed, 03 Feb 2021 01:42:25 -0800 (PST) X-Received: by 2002:aa7:d352:: with SMTP id m18mr2081484edr.190.1612345344780; Wed, 03 Feb 2021 01:42:24 -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 t3sm585734eds.89.2021.02.03.01.42.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Feb 2021 01:42:23 -0800 (PST) Subject: Re: [PATCH] KVM: vmx/pmu: Add VMCS fields check before exposing LBR_FMT To: Like Xu Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org References: <20210203065027.314622-1-like.xu@linux.intel.com> From: Paolo Bonzini Message-ID: Date: Wed, 3 Feb 2021 10:42:22 +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: <20210203065027.314622-1-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 03/02/21 07:50, Like Xu wrote: > Before KVM exposes guest LBR_FMT perf capabilities, it needs to check > whether VMCS has GUEST_IA32_DEBUGCTL guest status field and vmx switch > support on IA32_DEBUGCTL MSR (including VM_EXIT_SAVE_DEBUG_CONTROLS > and VM_ENTRY_LOAD_DEBUG_CONTROLS). It helps nested LBR enablement. > > Signed-off-by: Like Xu > --- > arch/x86/kvm/vmx/capabilities.h | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h > index d1d77985e889..ac3af06953a8 100644 > --- a/arch/x86/kvm/vmx/capabilities.h > +++ b/arch/x86/kvm/vmx/capabilities.h > @@ -378,6 +378,12 @@ static inline bool vmx_pt_mode_is_host_guest(void) > return pt_mode == PT_MODE_HOST_GUEST; > } > > +static inline bool cpu_has_vmx_lbr(void) > +{ > + return (vmcs_config.vmexit_ctrl & VM_EXIT_SAVE_DEBUG_CONTROLS) && > + (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_DEBUG_CONTROLS); > +} > + > static inline u64 vmx_get_perf_capabilities(void) > { > u64 perf_cap = 0; > @@ -385,7 +391,8 @@ static inline u64 vmx_get_perf_capabilities(void) > if (boot_cpu_has(X86_FEATURE_PDCM)) > rdmsrl(MSR_IA32_PERF_CAPABILITIES, perf_cap); > > - perf_cap &= PMU_CAP_LBR_FMT; > + if (cpu_has_vmx_lbr()) > + perf_cap &= PMU_CAP_LBR_FMT; This is incorrect in the case where cpu_has_vmx_lbr() is false. You would need something like u64 perf_cap = 0; u64 host_perf_cap = 0; if (boot_cpu_has(X86_FEATURE_PDCM)) rdmsrl(MSR_IA32_PERF_CAPABILITIES, host_perf_cap); if (cpu_has_vmx_lbr()) perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT; However, KVM won't run without VM_ENTRY_LOAD_DEBUG_CONTROLS and VM_EXIT_SAVE_DEBUG_CONTROLS (see setup_vmcs_config), so this change is not needed either. Paolo