Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1442060rwi; Thu, 27 Oct 2022 16:09:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5SakCK9Y0ovpz81WNy07mC2rHeoxYwX1BONHI9uxmhG3jCLcXQbVTKgtXc4tSfsdksjO2V X-Received: by 2002:a17:902:b907:b0:178:2898:8084 with SMTP id bf7-20020a170902b90700b0017828988084mr50929463plb.140.1666912138872; Thu, 27 Oct 2022 16:08:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666912138; cv=none; d=google.com; s=arc-20160816; b=dV0/ksS/ZXcgV/DDdzqM46olvyWe9s0RI4wU3m2VaHoYcZmMiShQdf2W3ypL0EXsao cknEeOvJx49wfLoHM0Hlya9zRt3uUh+pdredPZB6cZMKItkiR4MEseX0uDMTn8baRm6c dbyH68+rwca0/M2jh19rXYOvt8jvoovCp80jW5OV4wgdXn9TXIJ+vTh4Qed62oxxeZvV wPHkFcV7RzrM5W48FzcnW1L3MYIluhO0DNQKqAt0YieURYnAKlyUUisMu19FJWC9DFsH pguml2Ut1IMkGlr3mKEqDONipossw8ZLFllNPpM1dR4XPGoh9PZosYmgNnxMOwPw3W1M DCWQ== 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=Ub/SIEZt986yb8arJ2cndGzVm5KRvAidZjWfFvReRi4=; b=EL07JrZ9XPAT2QEc/FdSSQHt5LvMkuKWLK3mjoWyLtXgtAuoxofgdIZ4LGpvM/dVuv NOo4caPSTF6PBk2HMNQ1kMacMqXAt5gDeZLlF1Sz/ZyBuFca4wTZT8Cikx0lGh79+0fc JrtTLtbzyw8xCsKDZo6jxa8ohxSX7TIQUCWvygnMYI4D0ULencCacobcUKqsJX60q4f8 mEC5Is5KWq84i8XqM3Y6vXbgpA6xvQyykrCkoQ+RXZn8cRSLkLl3AOpgabsTJqJhEUVz SI/w7ek6MY4vtqQT1vTcAPQvb5WVNz5C43JGHPkMOrb2ytZ5watq7B9NHDQEg17baXgA R1cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=qW7iZPT+; 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 l71-20020a63914a000000b0046abab88fd9si3083362pge.677.2022.10.27.16.08.47; Thu, 27 Oct 2022 16:08:58 -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=qW7iZPT+; 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 S235668AbiJ0WhY (ORCPT + 99 others); Thu, 27 Oct 2022 18:37:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235633AbiJ0WhW (ORCPT ); Thu, 27 Oct 2022 18:37:22 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92567B3B11 for ; Thu, 27 Oct 2022 15:37:21 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id 128so3104556pga.1 for ; Thu, 27 Oct 2022 15:37:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Ub/SIEZt986yb8arJ2cndGzVm5KRvAidZjWfFvReRi4=; b=qW7iZPT+Z4eBenEGCE1n1yppuncJnEUGbqoM5b7Mv5wfV9dZqhWk5SH7kyv3kRLunq KwG5ebE5Xx0WmDPEvqMFd2cDGXN4nubSXy870tvU/6zMuD82iTcW1e+fce8XaEB3XqEP 9ORDg/daa9hERdOMgIfXYZf8IRS7OcXuHjC51tk5dBAZe25OOe4Ilw442gkODtYBZN+D j9Dhd/eouOjHhQWptHHVcfBgaQ9ZHQzeYRjTgKjl0DgLHgSFYWUt1wAtdE/j5viDURNP 9LMmIGqLTjJLAsftx1GlMNfddLLMmyDtI1b/DZHgN+HTRfXNOQzfSvtKHMSJI0bio4yn Wz6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Ub/SIEZt986yb8arJ2cndGzVm5KRvAidZjWfFvReRi4=; b=vCaHf2dWpp6Q7UvyLZBd+kYP097q2Y+MscHLQlVNt0iOPUd0R9K38V9un8fBZe3a4o jVLud7wqFdiZB9HZH6KBuSRf+RtPcHg4NMQ4WcFa5w9JSmpHenDvjQdWKq+FOquR1H8B KqYa+NzL2lJ1Hk0VRXLD5a3oawgh0PzJw/jSVHcbTOteNarLGPn76XW4L6bvUWZS0t2S xSL+jEA1TdG4J0XTPXaFH8QvoWgpBNyZvYkngGkHIWFWNYtGSkB2r1KXILiUA1PALQG8 EoPY+dc3KmAV2BxbNmx9nmnPG/gQvbgWoJBBIfI80FJcE8LE/gU8p3lYxpValRzu3jC3 6bxw== X-Gm-Message-State: ACrzQf3PYQDMfJIx1nCDm2RvzBXse7dnK647olRBiVqNi2up5VSCpnuk +qPxb/XLIMkPHliXnqQsLf6C8Q== X-Received: by 2002:aa7:800a:0:b0:565:af23:f5a4 with SMTP id j10-20020aa7800a000000b00565af23f5a4mr51517690pfi.42.1666910241002; Thu, 27 Oct 2022 15:37:21 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id o18-20020a170902d4d200b00176c0e055f8sm1717367plg.64.2022.10.27.15.37.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 15:37:20 -0700 (PDT) Date: Thu, 27 Oct 2022 22:37:17 +0000 From: Sean Christopherson To: Like Xu , g@google.com Cc: Paolo Bonzini , Jim Mattson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sandipan Das Subject: Re: [PATCH v2 3/3] KVM: x86/cpuid: Add AMD CPUID ExtPerfMonAndDbg leaf 0x80000022 Message-ID: References: <20220919093453.71737-1-likexu@tencent.com> <20220919093453.71737-4-likexu@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220919093453.71737-4-likexu@tencent.com> 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, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 19, 2022, Like Xu wrote: > From: Sandipan Das > > From: Sandipan Das Duplicate "From:"s. > CPUID leaf 0x80000022 i.e. ExtPerfMonAndDbg advertises some > new performance monitoring features for AMD processors. Wrap changelogs closer to ~75 chars. > 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 | 32 ++++++++++++++++++++++++++++++- > 2 files changed, 39 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; > +}; I'm not a fan of perf's unions, but I at least understand the value added for CPUID entries that are a bunch of multi-bit values. However, this leaf appears to be a pure features leaf. In which case a union just makes life painful. Please add a CPUID_8000_0022_EAX kvm_only_cpuid_leafs entry (details in link[*] below) so that KVM can write sane code like guest_cpuid_has(X86_FEATURE_AMD_PMU_V2) and cpuid_entry_override() instead of manually filling in information. where appropriate. [*] https://lore.kernel.org/all/Y1AQX3RfM+awULlE@google.com > 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..34ba845c91b7 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,36 @@ 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) Shouldn't case 0xa: { /* Architectural Performance Monitoring */ also check enable_pmu instead of X86_FEATURE_ARCH_PERFMON? > + break; > + > + if (kvm_pmu_cap.version > 1) { > + /* AMD PerfMon is only supported up to V2 in the KVM. */ > + eax.split.perfmon_v2 = 1; With a proper CPUID_8000_0022_EAX, this becomes: entry->ecx = entry->edx = 0; if (!enable_pmu || !kvm_cpu_cap_has(X86_FEATURE_AMD_PMU_V2)) { entry->eax = entry->ebx; break; } cpuid_entry_override(entry, CPUID_8000_0022_EAX); ... entry->ebx = ebx.full;