Skip to content

Commit edba60d

Browse files
hansendcnumbqq
authored andcommitted
x86/cpufeature: Make sure DISABLED/REQUIRED macros are updated
commit 1e61f78 upstream x86 has two macros which allow us to evaluate some CPUID-based features at compile time: REQUIRED_MASK_BIT_SET() DISABLED_MASK_BIT_SET() They're both defined by having the compiler check the bit argument against some constant masks of features. But, when adding new CPUID leaves, we need to check new words for these macros. So make sure that those macros and the REQUIRED_MASK* and DISABLED_MASK* get updated when necessary. This looks kinda silly to have an open-coded value ("18" in this case) open-coded in 5 places in the code. But, we really do need 5 places updated when NCAPINTS gets bumped, so now we just force the issue. Signed-off-by: Dave Hansen <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Brian Gerst <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]> Signed-off-by: Srivatsa S. Bhat <[email protected]> Reviewed-by: Matt Helsley (VMware) <[email protected]> Reviewed-by: Alexey Makhalov <[email protected]> Reviewed-by: Bo Gan <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 8508a83 commit edba60d

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

arch/x86/include/asm/cpufeature.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
6767
(((bit)>>5)==14 && (1UL<<((bit)&31) & REQUIRED_MASK14)) || \
6868
(((bit)>>5)==15 && (1UL<<((bit)&31) & REQUIRED_MASK15)) || \
6969
(((bit)>>5)==16 && (1UL<<((bit)&31) & REQUIRED_MASK16)) || \
70-
(((bit)>>5)==17 && (1UL<<((bit)&31) & REQUIRED_MASK17)))
70+
(((bit)>>5)==17 && (1UL<<((bit)&31) & REQUIRED_MASK17)) || \
71+
REQUIRED_MASK_CHECK || \
72+
BUILD_BUG_ON_ZERO(NCAPINTS != 18))
7173

7274
#define DISABLED_MASK_BIT_SET(bit) \
7375
( (((bit)>>5)==0 && (1UL<<((bit)&31) & DISABLED_MASK0 )) || \
@@ -87,7 +89,9 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
8789
(((bit)>>5)==14 && (1UL<<((bit)&31) & DISABLED_MASK14)) || \
8890
(((bit)>>5)==15 && (1UL<<((bit)&31) & DISABLED_MASK15)) || \
8991
(((bit)>>5)==16 && (1UL<<((bit)&31) & DISABLED_MASK16)) || \
90-
(((bit)>>5)==17 && (1UL<<((bit)&31) & DISABLED_MASK17)))
92+
(((bit)>>5)==17 && (1UL<<((bit)&31) & DISABLED_MASK17)) || \
93+
DISABLED_MASK_CHECK || \
94+
BUILD_BUG_ON_ZERO(NCAPINTS != 18))
9195

9296
#define cpu_has(c, bit) \
9397
(__builtin_constant_p(bit) && REQUIRED_MASK_BIT_SET(bit) ? 1 : \

arch/x86/include/asm/disabled-features.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@
5959
#define DISABLED_MASK15 0
6060
#define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE)
6161
#define DISABLED_MASK17 0
62+
#define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18)
6263

6364
#endif /* _ASM_X86_DISABLED_FEATURES_H */

arch/x86/include/asm/required-features.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,6 @@
100100
#define REQUIRED_MASK15 0
101101
#define REQUIRED_MASK16 0
102102
#define REQUIRED_MASK17 0
103+
#define REQUIRED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 18)
103104

104105
#endif /* _ASM_X86_REQUIRED_FEATURES_H */

0 commit comments

Comments
 (0)