From mboxrd@z Thu Jan 1 00:00:00 1970 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 97B09ECAAA1 for ; Thu, 27 Oct 2022 22:37:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235675AbiJ0WhZ (ORCPT ); Thu, 27 Oct 2022 18:37:25 -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-Google-Smtp-Source: AMsMyM4wwjIk9ZHI8pZcsG+FNxhwRL3lw9zG/dOQPHWt/yYgnuXqjLQdE90uEuRPQRWQJ/2y0fXSyA== 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> 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;