[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <6bc87ebe3a62ad2ee31a5e5952897c48a8ef2d77.1644000145.git.reinette.chatre@intel.com>
Date: Fri, 4 Feb 2022 11:17:11 -0800
From: Reinette Chatre <reinette.chatre@...el.com>
To: shuah@...nel.org, linux-kselftest@...r.kernel.org
Cc: linux-kernel@...r.kernel.org,
Reinette Chatre <reinette.chatre@...el.com>,
Andy Lutomirski <luto@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...e.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"H. Peter Anvin" <hpa@...or.com>, x86@...nel.org
Subject: [PATCH 3/3] selftests/x86/corrupt_xstate_header: Use existing __cpuid_count() macro
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@...nel.org>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Ingo Molnar <mingo@...hat.com>
Cc: Borislav Petkov <bp@...e.de>
Cc: Dave Hansen <dave.hansen@...ux.intel.com>
Cc: "H. Peter Anvin" <hpa@...or.com>
Cc: x86@...nel.org
Signed-off-by: Reinette Chatre <reinette.chatre@...el.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
Powered by blists - more mailing lists