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

selftests/x86: Use __builtin_ia32_read/writeeflags

The asm to read and write EFLAGS from userspace is horrible. The
compiler builtins are now available on all supported compilers, so
use them instead.

(The compiler builtins are also unnecessarily ugly, but that's a
more manageable level of ugliness.)

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/aee4b1cdfc56083eb779ce927b7d3459aad2af76.1604346818.git.luto@kernel.org

authored by

Andy Lutomirski and committed by
Borislav Petkov
9297e602 4b2d8ca9

+4 -20
+4 -20
tools/testing/selftests/x86/helpers.h
··· 6 6 7 7 static inline unsigned long get_eflags(void) 8 8 { 9 - unsigned long eflags; 10 - 11 - asm volatile ( 12 9 #ifdef __x86_64__ 13 - "subq $128, %%rsp\n\t" 14 - "pushfq\n\t" 15 - "popq %0\n\t" 16 - "addq $128, %%rsp" 10 + return __builtin_ia32_readeflags_u64(); 17 11 #else 18 - "pushfl\n\t" 19 - "popl %0" 12 + return __builtin_ia32_readeflags_u32(); 20 13 #endif 21 - : "=r" (eflags) :: "memory"); 22 - 23 - return eflags; 24 14 } 25 15 26 16 static inline void set_eflags(unsigned long eflags) 27 17 { 28 - asm volatile ( 29 18 #ifdef __x86_64__ 30 - "subq $128, %%rsp\n\t" 31 - "pushq %0\n\t" 32 - "popfq\n\t" 33 - "addq $128, %%rsp" 19 + __builtin_ia32_writeeflags_u64(eflags); 34 20 #else 35 - "pushl %0\n\t" 36 - "popfl" 21 + __builtin_ia32_writeeflags_u32(eflags); 37 22 #endif 38 - :: "r" (eflags) : "flags", "memory"); 39 23 } 40 24 41 25 #endif /* __SELFTESTS_X86_HELPERS_H */