linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/x86: Use __builtin_ia32_read/writeeflags
@ 2020-11-02 19:54 Andy Lutomirski
  2021-01-12 11:35 ` [tip: x86/misc] " tip-bot2 for Andy Lutomirski
  0 siblings, 1 reply; 2+ messages in thread
From: Andy Lutomirski @ 2020-11-02 19:54 UTC (permalink / raw)
  To: x86; +Cc: LKML, Andy Lutomirski

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>
---
 tools/testing/selftests/x86/helpers.h | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/tools/testing/selftests/x86/helpers.h b/tools/testing/selftests/x86/helpers.h
index f5ff2a2615df..4ef42c4559a9 100644
--- a/tools/testing/selftests/x86/helpers.h
+++ b/tools/testing/selftests/x86/helpers.h
@@ -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 */
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [tip: x86/misc] selftests/x86: Use __builtin_ia32_read/writeeflags
  2020-11-02 19:54 [PATCH] selftests/x86: Use __builtin_ia32_read/writeeflags Andy Lutomirski
@ 2021-01-12 11:35 ` tip-bot2 for Andy Lutomirski
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Andy Lutomirski @ 2021-01-12 11:35 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Andy Lutomirski, Borislav Petkov, x86, linux-kernel

The following commit has been merged into the x86/misc branch of tip:

Commit-ID:     9297e602adf8d5587d83941c48e4dbae46c8df5f
Gitweb:        https://git.kernel.org/tip/9297e602adf8d5587d83941c48e4dbae46c8df5f
Author:        Andy Lutomirski <luto@kernel.org>
AuthorDate:    Mon, 02 Nov 2020 11:54:02 -08:00
Committer:     Borislav Petkov <bp@suse.de>
CommitterDate: Tue, 12 Jan 2021 12:31:28 +01:00

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
---
 tools/testing/selftests/x86/helpers.h | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/tools/testing/selftests/x86/helpers.h b/tools/testing/selftests/x86/helpers.h
index f5ff2a2..4ef42c4 100644
--- a/tools/testing/selftests/x86/helpers.h
+++ b/tools/testing/selftests/x86/helpers.h
@@ -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 */

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-12 11:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-02 19:54 [PATCH] selftests/x86: Use __builtin_ia32_read/writeeflags Andy Lutomirski
2021-01-12 11:35 ` [tip: x86/misc] " tip-bot2 for Andy Lutomirski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).