Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/boot: Do not test if AC and ID eflags are changeable on x86_64

The test for the changeabitily of AC and ID EFLAGS is used to
distinguish between i386 and i486 processors (AC) and to test
for CPUID instruction support (ID).

Skip these tests on x86_64 processors as they always supports CPUID.

Also change the return type of has_eflag() to bool.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Link: https://lore.kernel.org/r/20250307091022.181136-1-ubizjak@gmail.com

authored by

Uros Bizjak and committed by
Ingo Molnar
558fc8e1 9c94c14c

+14 -18
+9 -17
arch/x86/boot/cpuflags.c
··· 29 29 return fsw == 0 && (fcw & 0x103f) == 0x003f; 30 30 } 31 31 32 + #ifdef CONFIG_X86_32 32 33 /* 33 34 * For building the 16-bit code we want to explicitly specify 32-bit 34 35 * push/pop operations, rather than just saying 'pushf' or 'popf' and 35 - * letting the compiler choose. But this is also included from the 36 - * compressed/ directory where it may be 64-bit code, and thus needs 37 - * to be 'pushfq' or 'popfq' in that case. 36 + * letting the compiler choose. 38 37 */ 39 - #ifdef __x86_64__ 40 - #define PUSHF "pushfq" 41 - #define POPF "popfq" 42 - #else 43 - #define PUSHF "pushfl" 44 - #define POPF "popfl" 45 - #endif 46 - 47 - int has_eflag(unsigned long mask) 38 + bool has_eflag(unsigned long mask) 48 39 { 49 40 unsigned long f0, f1; 50 41 51 - asm volatile(PUSHF " \n\t" 52 - PUSHF " \n\t" 42 + asm volatile("pushfl \n\t" 43 + "pushfl \n\t" 53 44 "pop %0 \n\t" 54 45 "mov %0,%1 \n\t" 55 46 "xor %2,%1 \n\t" 56 47 "push %1 \n\t" 57 - POPF " \n\t" 58 - PUSHF " \n\t" 48 + "popfl \n\t" 49 + "pushfl \n\t" 59 50 "pop %1 \n\t" 60 - POPF 51 + "popfl" 61 52 : "=&r" (f0), "=&r" (f1) 62 53 : "ri" (mask)); 63 54 64 55 return !!((f0^f1) & mask); 65 56 } 57 + #endif 66 58 67 59 void cpuid_count(u32 id, u32 count, u32 *a, u32 *b, u32 *c, u32 *d) 68 60 {
+5 -1
arch/x86/boot/cpuflags.h
··· 15 15 extern struct cpu_features cpu; 16 16 extern u32 cpu_vendor[3]; 17 17 18 - int has_eflag(unsigned long mask); 18 + #ifdef CONFIG_X86_32 19 + bool has_eflag(unsigned long mask); 20 + #else 21 + static inline bool has_eflag(unsigned long mask) { return true; } 22 + #endif 19 23 void get_cpuflags(void); 20 24 void cpuid_count(u32 id, u32 count, u32 *a, u32 *b, u32 *c, u32 *d); 21 25 bool has_cpuflag(int flag);