Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp3415178rwb; Mon, 5 Sep 2022 11:12:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR7MrYRY82keL3Y1l0UNyccYIJ9CVZAxsSRQTEG4uVRcmjdKxMvMqgJm/i1na5ttg0Ts+o8U X-Received: by 2002:a17:907:2c68:b0:730:9272:8c7f with SMTP id ib8-20020a1709072c6800b0073092728c7fmr37281610ejc.528.1662401574320; Mon, 05 Sep 2022 11:12:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662401574; cv=none; d=google.com; s=arc-20160816; b=WW1lCCnwsswvMdMXq9LppTs9IC/pz5ODudUEVza4D7wOGL5u91GrNwgsYDSTxqjP1c YaBacWFCJqYfJJwbNAwnzcjX//6Ix8miNP5IKL80iF/pEeVz3genw2Zfx3gl1XBhovkL btXfgtxu7rRiNGC4+z1LIC2cjBfyUH9mlow2Yh9Lio/7T9nEnKoZ7wRDBB9DreFTWqtf 4z84G67EYsDm5rW5ByjkK/HyTBfLHJlDXk8101yJdcw1yOnp2oWhHRMJ7hnbSvv1S8S9 v8ytwujzA1lBgC5k/CWI5fBkPVciNMVcZS+iO9pO+0rijcxcuNLaHyrhxt9brrBJh7L/ L8yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=a1Wl5OOBM+OdiCqwjpRNbQVvWBi9SOkRJQ7j+gqJGAI=; b=wnWK3ABOBS/cTqxSXhmEVKR53yeDNi3x9Z9fatUhArCBcW2Vm6fiGPqkLg2HQijBgf nt5LaeE6A2ZvE1CV7cCnmnrzaJQbgfONoSvBHTfSLGrWe4eRMoWLD8xFarfmVH+E2zjJ Wi06ySyrNEd8YX8fYQzD7o3Y0PFUawxKe+puvGB2ETbi0+SSRBapyhsnp20x960pCwIB nxBSp7hrY+7Ujwkl97BE6pB1DZlAoO9tZMa+SWZJR7Dg6ZuoNhMq+2jgKUl5LJMGdFMP oDVOVckbAHuYld0SP7zAgXczAdZ6DRyfcTSrPaloUt76sYHOsrOp/GALIORBGkhdsrn+ gMGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=omXxCPqB; 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 dr2-20020a170907720200b0073d78033578si8719840ejc.622.2022.09.05.11.12.28; Mon, 05 Sep 2022 11:12:54 -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=omXxCPqB; 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 S238017AbiIERhF (ORCPT + 99 others); Mon, 5 Sep 2022 13:37:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231658AbiIERhD (ORCPT ); Mon, 5 Sep 2022 13:37:03 -0400 Received: from mail-oa1-x29.google.com (mail-oa1-x29.google.com [IPv6:2001:4860:4864:20::29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEA4B5EDEC for ; Mon, 5 Sep 2022 10:37:02 -0700 (PDT) Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-11eab59db71so22741840fac.11 for ; Mon, 05 Sep 2022 10:37:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=a1Wl5OOBM+OdiCqwjpRNbQVvWBi9SOkRJQ7j+gqJGAI=; b=omXxCPqBgDlAxdUX5U3YmgblCVqUcKpbsoTO+4DUk94Iq8Ti9QLdiueFbqZ+DgSlp1 V8iuStpxP2j4Ww3tI5mVwdlgs1zcuRT7t7INHg1D0a7/IAnd9sXOCdqgra40rPUE8wD0 cg4U3zqiRno6i+kIK7wfyr0jwxRhlU3xtFU/jTVDRYdedLsMRBHOcbn1RUKJY2Unmeeb 4iCsdLOAZ4xhRkAWzbOtmAMh4Fj2HMXy2Og0EuTF0lq0EjrIGgbFcqz+I3BrU271nVeH fzkUWc7H43GObS8fzc6AQAbWhMpWmlJsPGwVRHukT8vRkg/NL9sNpwmkJRLBvILW1I/Q 3qpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=a1Wl5OOBM+OdiCqwjpRNbQVvWBi9SOkRJQ7j+gqJGAI=; b=Fu8rBk8r5O6eRl0u/EsR5mMYG7UVlC1r0PagGu7ZESM82ozlgsNgqxaPh7INZQZ0/T OWjGgSs4MswLEVVzcTy/hGhPSl13NFpZjXOjABEQJN8595O/870ABQ2WrRua2RtBMdbU V0Yg5ggIa0sgVB8ncrQ2ZdrAqtM2nkmNf2+diESZmBoPmzoqmBjH3L8z8AdiNj08+B6n XDqOpDvb5ks9sQ+vQdgQ8JcAVAqzs9kdE+S7nRUDpcI0/EGILgKEuJkcKmNMmivGD8Ui jdBqxCVG/yLGPjMHvJt5AJifaXOiLy1zkj3euYP6Q8PDY/ceQ0i4nSbA7ogHeSjftX5Z NdbQ== X-Gm-Message-State: ACgBeo0xD0e3wOmNYLqigviAGczYmB30o8suT/p/bblxjMu1zTTGS8JY C2OWrg4WndhOvPDOSdApUOKVhCj/QLnSCjpQWKGcDA== X-Received: by 2002:a05:6808:150f:b0:343:3202:91cf with SMTP id u15-20020a056808150f00b00343320291cfmr8032565oiw.112.1662399422082; Mon, 05 Sep 2022 10:37:02 -0700 (PDT) MIME-Version: 1.0 References: <20220905123946.95223-1-likexu@tencent.com> <20220905123946.95223-5-likexu@tencent.com> In-Reply-To: <20220905123946.95223-5-likexu@tencent.com> From: Jim Mattson Date: Mon, 5 Sep 2022 10:36:51 -0700 Message-ID: Subject: Re: [PATCH 4/4] KVM: x86/cpuid: Add AMD CPUID ExtPerfMonAndDbg leaf 0x80000022 To: Like Xu Cc: Sean Christopherson , Paolo Bonzini , Sandipan Das , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 On Mon, Sep 5, 2022 at 5:45 AM Like Xu wrote: > > From: Sandipan Das > > CPUID leaf 0x80000022 i.e. ExtPerfMonAndDbg advertises some > new performance monitoring features for AMD processors. > > Bit 0 of EAX indicates support for Performance Monitoring > Version 2 (PerfMonV2) features. If found to be set during > PMU initialization, the EBX bits of the same CPUID function > can be used to determine the number of available PMCs for > different PMU types. > > Expose the relevant bits via KVM_GET_SUPPORTED_CPUID so > that guests can make use of the PerfMonV2 features. > > Co-developed-by: Like Xu > Signed-off-by: Like Xu > Signed-off-by: Sandipan Das > --- > arch/x86/include/asm/perf_event.h | 8 ++++++++ > arch/x86/kvm/cpuid.c | 21 ++++++++++++++++++++- > 2 files changed, 28 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h > index f6fc8dd51ef4..c848f504e467 100644 > --- a/arch/x86/include/asm/perf_event.h > +++ b/arch/x86/include/asm/perf_event.h > @@ -214,6 +214,14 @@ union cpuid_0x80000022_ebx { > unsigned int full; > }; > > +union cpuid_0x80000022_eax { > + struct { > + /* Performance Monitoring Version 2 Supported */ > + unsigned int perfmon_v2:1; > + } split; > + unsigned int full; > +}; > + > struct x86_pmu_capability { > int version; > int num_counters_gp; > diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c > index 75dcf7a72605..08a29ab096d2 100644 > --- a/arch/x86/kvm/cpuid.c > +++ b/arch/x86/kvm/cpuid.c > @@ -1094,7 +1094,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) > entry->edx = 0; > break; > case 0x80000000: > - entry->eax = min(entry->eax, 0x80000021); > + entry->eax = min(entry->eax, 0x80000022); > /* > * Serializing LFENCE is reported in a multitude of ways, and > * NullSegClearsBase is not reported in CPUID on Zen2; help > @@ -1203,6 +1203,25 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) > if (!static_cpu_has_bug(X86_BUG_NULL_SEG)) > entry->eax |= BIT(6); > break; > + /* AMD Extended Performance Monitoring and Debug */ > + case 0x80000022: { > + union cpuid_0x80000022_eax eax; > + union cpuid_0x80000022_ebx ebx; > + > + entry->eax = entry->ebx = entry->ecx = entry->edx = 0; > + if (!enable_pmu) > + break; > + > + if (kvm_pmu_cap.version > 1) { > + /* AMD PerfMon is only supported up to V2 in the KVM. */ > + eax.split.perfmon_v2 = 1; > + ebx.split.num_core_pmc = min(kvm_pmu_cap.num_counters_gp, > + KVM_AMD_PMC_MAX_GENERIC); Note that the number of core PMCs has to be at least 6 if guest_cpuid_has(vcpu, X86_FEATURE_PERFCTR_CORE). I suppose this leaf could claim fewer, but the first 6 PMCs must work, per the v1 PMU spec. That is, software that knows about PERFCTR_CORE, but not about PMU v2, can rightfully expect 6 PMCs. > + } > + entry->eax = eax.full; > + entry->ebx = ebx.full; > + break; > + } > /*Add support for Centaur's CPUID instruction*/ > case 0xC0000000: > /*Just support up to 0xC0000004 now*/ > -- > 2.37.3 >