Commit 9297e602 authored by Andy Lutomirski's avatar Andy Lutomirski Committed by Borislav Petkov
Browse files

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: default avatarAndy Lutomirski <luto@kernel.org>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/aee4b1cdfc56083eb779ce927b7d3459aad2af76.1604346818.git.luto@kernel.org
parent 4b2d8ca9
Loading
Loading
Loading
Loading
+4 −20
Original line number Diff line number Diff line
@@ -6,36 +6,20 @@

static inline unsigned long get_eflags(void)
{
	unsigned long eflags;

	asm volatile (
#ifdef __x86_64__
		"subq $128, %%rsp\n\t"
		"pushfq\n\t"
		"popq %0\n\t"
		"addq $128, %%rsp"
	return __builtin_ia32_readeflags_u64();
#else
		"pushfl\n\t"
		"popl %0"
	return __builtin_ia32_readeflags_u32();
#endif
		: "=r" (eflags) :: "memory");

	return eflags;
}

static inline void set_eflags(unsigned long eflags)
{
	asm volatile (
#ifdef __x86_64__
		"subq $128, %%rsp\n\t"
		"pushq %0\n\t"
		"popfq\n\t"
		"addq $128, %%rsp"
	__builtin_ia32_writeeflags_u64(eflags);
#else
		"pushl %0\n\t"
		"popfl"
	__builtin_ia32_writeeflags_u32(eflags);
#endif
		:: "r" (eflags) : "flags", "memory");
}

#endif /* __SELFTESTS_X86_HELPERS_H */