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 0DCF2C636D4 for ; Fri, 10 Feb 2023 01:32:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231197AbjBJBc0 (ORCPT ); Thu, 9 Feb 2023 20:32:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230470AbjBJBcY (ORCPT ); Thu, 9 Feb 2023 20:32:24 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 275FD29E2B for ; Thu, 9 Feb 2023 17:32:23 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id v23so4962438plo.1 for ; Thu, 09 Feb 2023 17:32:23 -0800 (PST) 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=bYnD9chKHCWtyrpf49b2NsC5WdY8A7zHhx6W+ZzkgKw=; b=WP6iSEQiMxh6VldKHayGB98be8LoQ/yb8XWZbSqG9VeD9akqVGKxJArMKzpw8s/jx7 /Ju7rPJsFAxO+u5IjbDf7UkjNFv1rTt0O9uu2YelgQEtpS+h14QR/rBe5da9KJAKQ6Nw Q5+jgSrGNGAj9JOLSDIjv6WKfO1xfFyvJDsbaiLfRgelDk4dxvkTAiW3DUsxW69HP6Vv OpZlaQPxA4rGNsUMwe74eXwx+VumBbAPB+EXR1vgXRjZoF8k235egypDx4UxNrqQNuDm eyTm9rtZiq8ZHkfh5cyLAGOguo3v+PlQ4UaOE7bvGBLwqoZxBxCrHa2YMyiEQjFBjanD c/NA== 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=bYnD9chKHCWtyrpf49b2NsC5WdY8A7zHhx6W+ZzkgKw=; b=RMR6jH+duoEmEg4HF3zSpFgTCaRbTQbAISSzwgDUm1XnayfVwGIJiEOWrVgEFm6Z16 SlLvBt4tNVBBsVnCVSsWChoGBkLQS68zxpde+fZiMnlUJYYjC6UKQIFH+x2A9JiQYy1S 690azhnkjzXcXgkzEvEssujUfKSJcGCT5mdOG4WRzFmjPPljd2BCrtvZTvoxKMKD0oBX 4dlAYR3Sq5MRi5RwL7w+pru3reLHiGtOpNVjOujkUw6onTvpgIn/hG1vKBypnEJJvfhE Y9ZgysKwCWATpkokU+fOx9yNT2RvIF7HKyxJx/h5vcjbrmZKl8Ag9bVu3IXSUwG0mpL/ jZ7g== X-Gm-Message-State: AO0yUKUE4cjrPEau8WZbYm+QE1Ld8Ac73Cx+/obmsT2DXsSvRCF/5/vz Iz8jtIu8+doGEgrA3dn3mdyoLg== X-Google-Smtp-Source: AK7set+j2ckj55z67zfyaU2KvLlcVNTuY86fxaemeG8af8QPBKtxZ84UbhJG4xnOx+mED0d+Y8pKcg== X-Received: by 2002:a17:902:b115:b0:198:d5cc:44a8 with SMTP id q21-20020a170902b11500b00198d5cc44a8mr44674plr.19.1675992742406; Thu, 09 Feb 2023 17:32:22 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id q26-20020a63bc1a000000b004cd2eebc551sm1856822pge.62.2023.02.09.17.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 17:32:21 -0800 (PST) Date: Fri, 10 Feb 2023 01:32:17 +0000 From: Sean Christopherson To: Like Xu Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 5/8] KVM: x86/cpuid: Add X86_FEATURE_AMD_PMU_V2 as a KVM-only leaf entry Message-ID: References: <20221111102645.82001-1-likexu@tencent.com> <20221111102645.82001-6-likexu@tencent.com> <4a7fb3b6-f9eb-6cde-7120-7d256d9d288e@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4a7fb3b6-f9eb-6cde-7120-7d256d9d288e@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 06, 2023, Like Xu wrote: > On 25/1/2023 3:47 am, Sean Christopherson wrote: > > On Fri, Nov 11, 2022, Like Xu wrote: > > > From: Like Xu > > > > > > Alias X86_FEATURE_AMD_PMU_V2 for feature AMD_PMU_V2 in KVM-only leafs that > > > aren't scattered by cpufeatures.h so that it can be used in KVM, e.g. to > > > query guest CPUID. As a bonus, no translation is needed for these features > > > in __feature_translate(). > > > > > > Suggested-by: Sean Christopherson > > > Signed-off-by: Like Xu > > > --- > > > arch/x86/kvm/reverse_cpuid.h | 10 ++++++++++ > > > 1 file changed, 10 insertions(+) > > > > > > diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h > > > index a19d473d0184..7cfedb3e47c0 100644 > > > --- a/arch/x86/kvm/reverse_cpuid.h > > > +++ b/arch/x86/kvm/reverse_cpuid.h > > > @@ -13,6 +13,7 @@ > > > */ > > > enum kvm_only_cpuid_leafs { > > > CPUID_12_EAX = NCAPINTS, > > > + CPUID_8000_0022_EAX, > > > NR_KVM_CPU_CAPS, > > > NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS, > > > @@ -23,7 +24,15 @@ enum kvm_only_cpuid_leafs { > > > /* Intel-defined SGX sub-features, CPUID level 0x12 (EAX). */ > > > #define KVM_X86_FEATURE_SGX1 KVM_X86_FEATURE(CPUID_12_EAX, 0) > > > #define KVM_X86_FEATURE_SGX2 KVM_X86_FEATURE(CPUID_12_EAX, 1) > > > +#define KVM_X86_FEATURE_AMD_PMU_V2 KVM_X86_FEATURE(CPUID_8000_0022_EAX, 0) > > > +/* > > > + * Alias X86_FEATURE_* to the KVM variant for features in KVM-only leafs that > > > + * aren't scattered by cpufeatures.h so that X86_FEATURE_* can be used in KVM, > > > + * e.g. to query guest CPUID. As a bonus, no translation is needed for these > > > + * features in __feature_translate(). > > > + */ > > > +#define X86_FEATURE_AMD_PMU_V2 KVM_X86_FEATURE_AMD_PMU_V2 > > > > I gave you bad input earlier, for purely KVM-defined flags there's no need for an > > intermediate KVM_X86_FEATURE_AMD_PMU_V2, this could simply be: > > > > #define X86_FEATURE_AMD_PMU_V2 KVM_X86_FEATURE(CPUID_8000_0022_EAX, 0) > > > > That's a moot point though because, after much searching because I had a very hard > > time believing the kernel wouldn't want to know about this flag, I found commit > > > > d6d0c7f681fd ("x86/cpufeatures: Add PerfMonV2 feature bit") > > > > from nearly a year ago. I.e. to avoid confusiong, this needs to be a scattered > > flag, not a purely KVM flag. > > > > --- > > arch/x86/kvm/reverse_cpuid.h | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h > > index 4945456fd646..333e28b0a13c 100644 > > --- a/arch/x86/kvm/reverse_cpuid.h > > +++ b/arch/x86/kvm/reverse_cpuid.h > > @@ -15,6 +15,7 @@ enum kvm_only_cpuid_leafs { > > CPUID_12_EAX = NCAPINTS, > > CPUID_7_1_EDX, > > CPUID_8000_0007_EDX, > > + CPUID_8000_0022_EAX, > > NR_KVM_CPU_CAPS, > > NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS, > > @@ -47,6 +48,9 @@ enum kvm_only_cpuid_leafs { > > /* CPUID level 0x80000007 (EDX). */ > > #define KVM_X86_FEATURE_CONSTANT_TSC KVM_X86_FEATURE(CPUID_8000_0007_EDX, 8) > > +/* CPUID level 0x80000022 (EAX) */ > > +#define KVM_X86_FEATURE_PERFMON_V2 KVM_X86_FEATURE(CPUID_8000_0022_EAX, 0) > > I'm very confused and is this the usage you want to see: > > kvm_cpu_cap_set(KVM_X86_FEATURE_PERFMON_V2) > kvm_cpu_cap_has(KVM_X86_FEATURE_PERFMON_V2) > guest_cpuid_has(vcpu, X86_FEATURE_PERFMON_V2) > > ? No, all of those should just use X86_FEATURE_PERFMON_V2, i.e. the existing flag from cpufeatures.h. > then what about X86_FEATURE_PERFMON_V2 ? Not sure I follow. As above, it's scattered, thus KVM needs to redirect it to the hardware-defined bit position, which is the role of __feature_translate() and KVM_X86_FEATURE_PERFMON_V2.