On 3/25/20 8:46 AM, Paolo Bonzini wrote: > 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? Nope, no help. That's the wrong location. Need a patch for this: >> 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. -- ~Randy