Skip to content

Commit 558fc8e

Browse files
ubizjakIngo Molnar
authored andcommitted
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
1 parent 9c94c14 commit 558fc8e

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

arch/x86/boot/cpuflags.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,32 @@ static int has_fpu(void)
2929
return fsw == 0 && (fcw & 0x103f) == 0x003f;
3030
}
3131

32+
#ifdef CONFIG_X86_32
3233
/*
3334
* For building the 16-bit code we want to explicitly specify 32-bit
3435
* 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.
3837
*/
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)
4839
{
4940
unsigned long f0, f1;
5041

51-
asm volatile(PUSHF " \n\t"
52-
PUSHF " \n\t"
42+
asm volatile("pushfl \n\t"
43+
"pushfl \n\t"
5344
"pop %0 \n\t"
5445
"mov %0,%1 \n\t"
5546
"xor %2,%1 \n\t"
5647
"push %1 \n\t"
57-
POPF " \n\t"
58-
PUSHF " \n\t"
48+
"popfl \n\t"
49+
"pushfl \n\t"
5950
"pop %1 \n\t"
60-
POPF
51+
"popfl"
6152
: "=&r" (f0), "=&r" (f1)
6253
: "ri" (mask));
6354

6455
return !!((f0^f1) & mask);
6556
}
57+
#endif
6658

6759
void cpuid_count(u32 id, u32 count, u32 *a, u32 *b, u32 *c, u32 *d)
6860
{

arch/x86/boot/cpuflags.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ struct cpu_features {
1515
extern struct cpu_features cpu;
1616
extern u32 cpu_vendor[3];
1717

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
1923
void get_cpuflags(void);
2024
void cpuid_count(u32 id, u32 count, u32 *a, u32 *b, u32 *c, u32 *d);
2125
bool has_cpuflag(int flag);

0 commit comments

Comments
 (0)