Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp210272rwb; Wed, 5 Oct 2022 17:32:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Dbhs3nRRDP1+AVuA4AAh9mOMe5Bqgy0rfGcOZtPT6cVwJvf3Qf3qdtgQri0J2knzjhlzi X-Received: by 2002:a05:6402:4003:b0:459:b859:ed09 with SMTP id d3-20020a056402400300b00459b859ed09mr2121825eda.135.1665016365418; Wed, 05 Oct 2022 17:32:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665016365; cv=none; d=google.com; s=arc-20160816; b=zdC8AmDscBMYzeMbi110zS03cz59+rZRyFlh3D86p400tcgeHj2VXOpCEnN/cPz04L 0pSaN5+44fTNV6Q6mUPb/8tpJW5MM57znqwCl0h7HI/cS4S9f31zShcUIuXPeOCzZqPK vUz/eWmlH+yqQrQwbFG8lUExHc8zXiojd/xGPPCAL19HI79PAzedZ4Q22VxRTitsg8Jj kTLGiCP3qjKRxLT1rwT8lE1bxD5d/ENQtQNmsYykhaHhrVaV+qB/2SlkgldKZO60Aawy /aHkGOyIMtKnMMzf4TYdVY7nFSEMW/mj5LeO2ahKGOCHSfteQxrygxfERPCiU3ga6nJn s7vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=ZuL2WMiGYze3NRMdfPj3MoHFJUJYGCMiGE6H5e3qchw=; b=MXNBUL5+CVivKrTu1+NihbqNdctKYHM8eWyLUF0uSkTm4i6JzYH2EkwPdSrpLmyx0X 0fq58QDmAqsIwTKF6is2q8iG6GBferzNq3XipatFYPKHLUdxJICisQxp0Z9+VIyeRiM1 L9O3GOSuhTU/R1Lst6yvRcD4w0DRUCGpsoos+k+U0ip7Md8hUnrSjineIQn49jfUqfmK Cqtm6jQdNXj5pkDZPkETExaUG8pQZTZvQWtVv1h4Ay85oFOAsfssGHlEZIZozsidNBK/ EhT1r4sgtpfo+hn2U5RuCXIMaCvZfTA2VcUhmFcYM6MR9/ciqDugZpFyUxtpfWKO5522 OJbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mWjjFMys; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w14-20020a1709062f8e00b007386f4ab2a2si14071467eji.638.2022.10.05.17.32.17; Wed, 05 Oct 2022 17:32:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mWjjFMys; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229733AbiJFADa (ORCPT + 99 others); Wed, 5 Oct 2022 20:03:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbiJFADW (ORCPT ); Wed, 5 Oct 2022 20:03:22 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACD3732BB9 for ; Wed, 5 Oct 2022 17:03:21 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id 203-20020a6300d4000000b0043fc5adabc8so146580pga.9 for ; Wed, 05 Oct 2022 17:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=ZuL2WMiGYze3NRMdfPj3MoHFJUJYGCMiGE6H5e3qchw=; b=mWjjFMysPgnbZbFgdefAEx2kRBsVhavP43kyucIJt8jdHM/sTIeM8/nrm27y0nTdpB 3KDpayu47Wl4wb7uRxPiI/OAtjMEWyffz852gWqdUiLHcxh2AXto+H/RgzVO4IrGT2BB PeQmdoOnJ8aUJB3yLZPh50+fJ/HuPUqFZ5KX/+Rfen6BaSt0tvzit14GTnDeiDixYb8F VoFb6shWMcdqhPS0xIAn/zPp+hwC+WrcYpT6YYhP2sOc63LLXlvfVVv4NackFLRO128z TBX2F7JtCKwCMC9bq2SMY56QED0Lo4G+whthTouWif9FedYgR85/xWrzizJkZRkjmYn4 tA4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZuL2WMiGYze3NRMdfPj3MoHFJUJYGCMiGE6H5e3qchw=; b=i8dkIzXZwzBDUqmijwC0SQauqRidSyxz7YZU/6Dqv0rI99B8Zsl57XsSwI9sN9Z2tw X78B3Szg/zuIo3qqK0r0oOFpNMiwQuodGi0hIACs21C6zKFpHIfAH5PLkl+QFMgkzmrT VpX44UIQ9GWl5G6EEGBJ4+xTRqkvwCiFrGLRc3nQZHTJG23Pu7rEL1klLUqjqI8P8ffi JnT9mA3dN67Ts3VTaiTjfds0kIh8zjCT53NdFmmpMwtyg++Wvwvs70k91le9qDdIpQew rxINYfSXxYPI8Pn6TzbyMxcHYFzKPDXdlgCXVz6HwXDGaBzv/4mCy+7wB7zJHf7pgdHZ oXrQ== X-Gm-Message-State: ACrzQf36MfuX1PEj3JbT0m1IjJZv6I/dNVs3qg/F8vENep/WlZCunMTL vgbCgpOoxcdpyItB50BiqWNUCxdvYg8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:2409:b0:54e:a3ad:d32d with SMTP id z9-20020a056a00240900b0054ea3add32dmr1929000pfh.70.1665014601268; Wed, 05 Oct 2022 17:03:21 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 6 Oct 2022 00:03:08 +0000 In-Reply-To: <20221006000314.73240-1-seanjc@google.com> Mime-Version: 1.0 References: <20221006000314.73240-1-seanjc@google.com> X-Mailer: git-send-email 2.38.0.rc1.362.ged0d419d3c-goog Message-ID: <20221006000314.73240-3-seanjc@google.com> Subject: [PATCH v5 2/8] KVM: VMX: Advertise PMU LBRs if and only if perf supports LBRs From: Sean Christopherson To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Sean Christopherson , Paolo Bonzini Cc: Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Like Xu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Advertise LBR support to userspace via MSR_IA32_PERF_CAPABILITIES if and only if perf fully supports LBRs. Perf may disable LBRs (by zeroing the number of LBRs) even on platforms the allegedly support LBRs, e.g. if probing any LBR MSRs during setup fails. Fixes: be635e34c284 ("KVM: vmx/pmu: Expose LBR_FMT in the MSR_IA32_PERF_CAPABILITIES") Reported-by: Like Xu Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/capabilities.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilities.h index 87c4e46daf37..a6689bf06542 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -400,6 +400,7 @@ static inline bool vmx_pebs_supported(void) static inline u64 vmx_get_perf_capabilities(void) { u64 perf_cap = PMU_CAP_FW_WRITES; + struct x86_pmu_lbr lbr; u64 host_perf_cap = 0; if (!enable_pmu) @@ -408,7 +409,9 @@ static inline u64 vmx_get_perf_capabilities(void) if (boot_cpu_has(X86_FEATURE_PDCM)) rdmsrl(MSR_IA32_PERF_CAPABILITIES, host_perf_cap); - perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT; + x86_perf_get_lbr(&lbr); + if (lbr.nr) + perf_cap |= host_perf_cap & PMU_CAP_LBR_FMT; if (vmx_pebs_supported()) { perf_cap |= host_perf_cap & PERF_CAP_PEBS_MASK; -- 2.38.0.rc1.362.ged0d419d3c-goog