lkml.org 
[lkml]   [2022]   [Feb]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 3/3] selftests/x86/corrupt_xstate_header: Use existing __cpuid_count() macro
Date
gcc as well as clang makes the __cpuid_count() macro available
via cpuid.h to conveniently call the CPUID instruction.

Below is a copy of the macro as found in cpuid.h:

#define __cpuid_count(level, count, a, b, c, d) \
__asm__ ("cpuid\n\t" \
: "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
: "0" (level), "2" (count))

The corrupt_xstate_header test contains a local function
used as wrapper to the CPUID instruction. One difference between
the corrupt_xstate_header implementation and the macro from cpuid.h
is that the corrupt_xstate_header implementation provides the
"volatile" qualifier to the asm() call. The "volatile" qualifier
is necessary when CPUID has side effects and thus any
optimizations should be avoided. CPUID is used in the
corrupt_xstate_header test to query the system for its
XSAVE/XRSTOR support, a query without side effect, the
"volatile" qualifier is thus not required and the macro from
cpuid.h can be used instead.

Remove the duplicated wrapper to CPUID and use __cpuid_count()
from cpuid.h instead.

Cc: Andy Lutomirski <luto@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
---
.../selftests/x86/corrupt_xstate_header.c | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/tools/testing/selftests/x86/corrupt_xstate_header.c b/tools/testing/selftests/x86/corrupt_xstate_header.c
index ab8599c10ce5..7a877612bc98 100644
--- a/tools/testing/selftests/x86/corrupt_xstate_header.c
+++ b/tools/testing/selftests/x86/corrupt_xstate_header.c
@@ -7,6 +7,7 @@

#define _GNU_SOURCE

+#include <cpuid.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -17,25 +18,11 @@
#include <stdint.h>
#include <sys/wait.h>

-static inline void __cpuid(unsigned int *eax, unsigned int *ebx,
- unsigned int *ecx, unsigned int *edx)
-{
- asm volatile(
- "cpuid;"
- : "=a" (*eax),
- "=b" (*ebx),
- "=c" (*ecx),
- "=d" (*edx)
- : "0" (*eax), "2" (*ecx));
-}
-
static inline int xsave_enabled(void)
{
unsigned int eax, ebx, ecx, edx;

- eax = 0x1;
- ecx = 0x0;
- __cpuid(&eax, &ebx, &ecx, &edx);
+ __cpuid_count(0x1, 0x0, eax, ebx, ecx, edx);

/* Is CR4.OSXSAVE enabled ? */
return ecx & (1U << 27);
--
2.25.1
\
 
 \ /
  Last update: 2022-02-04 20:19    [W:0.084 / U:0.780 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site