From nobody Mon Apr 6 23:07:12 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D0FDECAAD1 for ; Thu, 1 Sep 2022 17:33:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234624AbiIARd1 (ORCPT ); Thu, 1 Sep 2022 13:33:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234123AbiIARdL (ORCPT ); Thu, 1 Sep 2022 13:33:11 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47A0993503 for ; Thu, 1 Sep 2022 10:33:07 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id e187-20020a6369c4000000b0041c8dfb8447so8973232pgc.23 for ; Thu, 01 Sep 2022 10:33:07 -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; bh=up2TM/zYvuiSr9vjf1/TjFbeoqAIIxAqdA2XP4Ysf64=; b=mnzCFMgQovP4pOxeqKDuUiKfKrfoW65FbzBEQyAYN0ttmKM9Hh1tn19fDLY1zlYtWu +n7/5M4T94WtHynUEM5Qxjeinqtsgq7kkWH1LAKgXSBGxeeB4/vbe1jcHe/yBUsPS47r CS8IVxzzXWcq68j/3bpQUF6p/7SH4+Sgj0cIqPEZt25gWPd6VkfhYz+p2Rt1jEahgKP2 VMVS1gWvHEFx4IC8PCk70lmXV016g5e8CrdOg/DNbEb5xuetcpm3Yq6WuPP+NMhYDh/i XiYz9dt3VoPajHrHpKBF/rxWZeUyIF4eymR1mkVJRp56WXnN1UakQer/LEUTyRLDRfZq B4IA== 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; bh=up2TM/zYvuiSr9vjf1/TjFbeoqAIIxAqdA2XP4Ysf64=; b=MWTEC5suc6YgPu4M2ejKa4a/UYzg+O/GfkS/cjD8CweILR1rEJLdhuByIVm7go59wl 1XTofRYIBRcArNTLUwugOdKPv/bQNLD5aYgFJOD0qXUlEsaFO0iJDLZj2tRuSKGiJguP 3Rt3MsVnDW3q57M1SxqLlP1YfMTW3eHc6bir3kvLwNcrzhjjA9Xi5qKxpmyVP5usuSmh 0b+Irvxmh0uEP0LT7Js6I936APFRM4PYgaJRJK2Nj3C0dEu8J9FTE3yOm5Vl7vdAq+7W 5alaIFpDJAJ4xrcM8DLuPHvkm1XJjZVgjQhu7VnXv2sYB1kWsWVaIis+4/FdQLf0aEFi 2T5Q== X-Gm-Message-State: ACgBeo3/JdtihDLjYvSpA+F7mii9bvwLpdCDsFRp27J8xGufaR3AhK3D KWV/JkAMxEMQHYEdHyZt0JOQ/QjbGSs= X-Google-Smtp-Source: AA6agR7YtYGNAqd7HjqTYxeCdsRMjgGly3qkWP2F386oX2uY9RK0QBieMMd91SJA6yGNmzbigLsV1w4m5nk= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:3b52:b0:1fe:2ee2:e341 with SMTP id ot18-20020a17090b3b5200b001fe2ee2e341mr207479pjb.231.1662053586161; Thu, 01 Sep 2022 10:33:06 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 1 Sep 2022 17:32:56 +0000 In-Reply-To: <20220901173258.925729-1-seanjc@google.com> Mime-Version: 1.0 References: <20220901173258.925729-1-seanjc@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220901173258.925729-4-seanjc@google.com> Subject: [PATCH v4 3/5] KVM: VMX: Move vmx_get_perf_capabilities() definition to vmx.c 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move vmx_get_perf_capabilities() to vmx.c as a non-inline function so that it can safely reference x86_perf_get_lbr(), which is available iff CPU_SUP_INTEL=3Dy, i.e. only if kvm_intel is being built. The helper is non-trivial and isn't used in any paths that are performance critical, i.e. doesn't need to be inlined. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/capabilities.h | 24 ++---------------------- arch/x86/kvm/vmx/vmx.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilitie= s.h index c5e5dfef69c7..23dca5ebae16 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -75,6 +75,8 @@ struct vmx_capability { }; extern struct vmx_capability vmx_capability; =20 +u64 vmx_get_perf_capabilities(void); + static inline bool cpu_has_vmx_basic_inout(void) { return (((u64)vmcs_config.basic_cap << 32) & VMX_BASIC_INOUT); @@ -401,28 +403,6 @@ static inline bool vmx_pebs_supported(void) return boot_cpu_has(X86_FEATURE_PEBS) && kvm_pmu_cap.pebs_ept; } =20 -static inline u64 vmx_get_perf_capabilities(void) -{ - u64 perf_cap =3D PMU_CAP_FW_WRITES; - u64 host_perf_cap =3D 0; - - if (!enable_pmu) - return 0; - - if (boot_cpu_has(X86_FEATURE_PDCM)) - rdmsrl(MSR_IA32_PERF_CAPABILITIES, host_perf_cap); - - perf_cap |=3D host_perf_cap & PMU_CAP_LBR_FMT; - - if (vmx_pebs_supported()) { - perf_cap |=3D host_perf_cap & PERF_CAP_PEBS_MASK; - if ((perf_cap & PERF_CAP_PEBS_FORMAT) < 4) - perf_cap &=3D ~PERF_CAP_PEBS_BASELINE; - } - - return perf_cap; -} - static inline u64 vmx_supported_debugctl(void) { u64 debugctl =3D 0; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index c9b49a09e6b5..657fa9908bf9 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1826,6 +1826,28 @@ static inline bool vmx_feature_control_msr_valid(str= uct kvm_vcpu *vcpu, return !(val & ~valid_bits); } =20 +u64 vmx_get_perf_capabilities(void) +{ + u64 perf_cap =3D PMU_CAP_FW_WRITES; + u64 host_perf_cap =3D 0; + + if (!enable_pmu) + return 0; + + if (boot_cpu_has(X86_FEATURE_PDCM)) + rdmsrl(MSR_IA32_PERF_CAPABILITIES, host_perf_cap); + + perf_cap |=3D host_perf_cap & PMU_CAP_LBR_FMT; + + if (vmx_pebs_supported()) { + perf_cap |=3D host_perf_cap & PERF_CAP_PEBS_MASK; + if ((perf_cap & PERF_CAP_PEBS_FORMAT) < 4) + perf_cap &=3D ~PERF_CAP_PEBS_BASELINE; + } + + return perf_cap; +} + static int vmx_get_msr_feature(struct kvm_msr_entry *msr) { switch (msr->index) { --=20 2.37.2.789.g6183377224-goog