public inbox for linux-next@vger.kernel.org 
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat•com>
To: Randy Dunlap <rdunlap@infradead•org>,
	Stephen Rothwell <sfr@canb•auug.org.au>,
	Linux Next Mailing List <linux-next@vger•kernel.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger•kernel.org>,
	KVM <kvm@vger•kernel.org>,
	Sean Christopherson <sean.j.christopherson@intel•com>,
	Vitaly Kuznetsov <vkuznets@redhat•com>,
	Wanpeng Li <wanpengli@tencent•com>,
	Jim Mattson <jmattson@google•com>, Joerg Roedel <joro@8bytes•org>
Subject: Re: linux-next: Tree for Mar 25 (arch/x86/kvm/)
Date: Wed, 25 Mar 2020 16:46:58 +0100	[thread overview]
Message-ID: <d9af8094-96c3-3b7f-835c-4e48d157e582@redhat.com> (raw)
In-Reply-To: <e9286016-66ae-9505-ea52-834527cdae27@infradead.org>

On 25/03/20 16:30, Randy Dunlap wrote:
> 24 (only showing one of them here) BUILD_BUG() errors in arch/x86/kvm/cpuid.h
> function __cpuid_entry_get_reg(), for the default: case.
> 
> 
>   CC      arch/x86/kvm/cpuid.o
> In file included from ../include/linux/export.h:43:0,
>                  from ../include/linux/linkage.h:7,
>                  from ../include/linux/preempt.h:10,
>                  from ../include/linux/hardirq.h:5,
>                  from ../include/linux/kvm_host.h:7,
>                  from ../arch/x86/kvm/cpuid.c:12:
> In function ‘__cpuid_entry_get_reg’,
>     inlined from ‘kvm_cpu_cap_mask’ at ../arch/x86/kvm/cpuid.c:272:25,
>     inlined from ‘kvm_set_cpu_caps’ at ../arch/x86/kvm/cpuid.c:292:2:
> ../include/linux/compiler.h:394:38: error: call to ‘__compiletime_assert_114’ declared with attribute error: BUILD_BUG failed
>   _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
>                                       ^
> ../include/linux/compiler.h:375:4: note: in definition of macro ‘__compiletime_assert’
>     prefix ## suffix();    \
>     ^~~~~~
> ../include/linux/compiler.h:394:2: note: in expansion of macro ‘_compiletime_assert’
>   _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
>   ^~~~~~~~~~~~~~~~~~~
> ../include/linux/build_bug.h:39:37: note: in expansion of macro ‘compiletime_assert’
>  #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
>                                      ^~~~~~~~~~~~~~~~~~
> ../include/linux/build_bug.h:59:21: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
>  #define BUILD_BUG() BUILD_BUG_ON_MSG(1, "BUILD_BUG failed")
>                      ^~~~~~~~~~~~~~~~
> ../arch/x86/kvm/cpuid.h:114:3: note: in expansion of macro ‘BUILD_BUG’
>    BUILD_BUG();
>    ^~~~~~~~~
> 

Looks like the compiler is not smart enough to figure out the constant 
expressions in BUILD_BUG.  I think we need to do something like this:

diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
index 23b4cd1ad986..8f711b0cdec0 100644
--- a/arch/x86/kvm/cpuid.h
+++ b/arch/x86/kvm/cpuid.h
@@ -40,6 +40,7 @@ struct cpuid_reg {
 	int reg;
 };
 
+/* Update reverse_cpuid_check as well when adding an entry.  */
 static const struct cpuid_reg reverse_cpuid[] = {
 	[CPUID_1_EDX]         = {         1, 0, CPUID_EDX},
 	[CPUID_8000_0001_EDX] = {0x80000001, 0, CPUID_EDX},
@@ -68,12 +69,21 @@ static const struct cpuid_reg reverse_cpuid[] = {
  */
 static __always_inline void reverse_cpuid_check(unsigned int x86_leaf)
 {
-	BUILD_BUG_ON(x86_leaf == CPUID_LNX_1);
-	BUILD_BUG_ON(x86_leaf == CPUID_LNX_2);
-	BUILD_BUG_ON(x86_leaf == CPUID_LNX_3);
-	BUILD_BUG_ON(x86_leaf == CPUID_LNX_4);
-	BUILD_BUG_ON(x86_leaf >= ARRAY_SIZE(reverse_cpuid));
-	BUILD_BUG_ON(reverse_cpuid[x86_leaf].function == 0);
+	BUILD_BUG_ON(x86_leaf != CPUID_1_EDX &&
+	             x86_leaf != CPUID_8000_0001_EDX &&
+	             x86_leaf != CPUID_8086_0001_EDX &&
+	             x86_leaf != CPUID_1_ECX &&
+	             x86_leaf != CPUID_C000_0001_EDX &&
+	             x86_leaf != CPUID_8000_0001_ECX &&
+	             x86_leaf != CPUID_7_0_EBX &&
+	             x86_leaf != CPUID_D_1_EAX &&
+	             x86_leaf != CPUID_8000_0008_EBX &&
+	             x86_leaf != CPUID_6_EAX &&
+	             x86_leaf != CPUID_8000_000A_EDX &&
+	             x86_leaf != CPUID_7_ECX &&
+	             x86_leaf != CPUID_8000_0007_EBX &&
+	             x86_leaf != CPUID_7_EDX &&
+	             x86_leaf != CPUID_7_1_EAX);
 }
 
 /*

Randy, can you test it with your compiler?

Thanks,

Paolo


  parent reply	other threads:[~2020-03-25 15:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-25  8:53 linux-next: Tree for Mar 25 Stephen Rothwell
2020-03-25 15:30 ` linux-next: Tree for Mar 25 (arch/x86/kvm/) Randy Dunlap
2020-03-25 15:32   ` Sean Christopherson
2020-03-25 15:46   ` Paolo Bonzini [this message]
2020-03-25 15:57     ` Randy Dunlap
2020-03-25 16:08       ` Paolo Bonzini
2020-03-25 16:14         ` Sean Christopherson
2020-03-25 16:26           ` Paolo Bonzini
2020-03-25 16:46             ` Sean Christopherson
2020-03-25 18:47               ` Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d9af8094-96c3-3b7f-835c-4e48d157e582@redhat.com \
    --to=pbonzini@redhat$(echo .)com \
    --cc=jmattson@google$(echo .)com \
    --cc=joro@8bytes$(echo .)org \
    --cc=kvm@vger$(echo .)kernel.org \
    --cc=linux-kernel@vger$(echo .)kernel.org \
    --cc=linux-next@vger$(echo .)kernel.org \
    --cc=rdunlap@infradead$(echo .)org \
    --cc=sean.j.christopherson@intel$(echo .)com \
    --cc=sfr@canb$(echo .)auug.org.au \
    --cc=vkuznets@redhat$(echo .)com \
    --cc=wanpengli@tencent$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox