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

selftests/x86/amx: Use provided __cpuid_count() macro

kselftest.h makes the __cpuid_count() macro available
to conveniently call the CPUID instruction.

Remove the local CPUID wrapper and use __cpuid_count()
from kselftest.h instead.

__cpuid_count() from kselftest.h is used instead of the
macro provided by the compiler since gcc v4.4 (via cpuid.h)
because the selftest needs to be supported with gcc v3.2,
the minimal required version for stable kernels.

Cc: Chang S. Bae <chang.seok.bae@intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Reinette Chatre and committed by
Shuah Khan
2ba8a7ab 0dba8dae

+7 -17
+7 -17
tools/testing/selftests/x86/amx.c
··· 17 17 #include <sys/syscall.h> 18 18 #include <sys/wait.h> 19 19 20 + #include "../kselftest.h" /* For __cpuid_count() */ 21 + 20 22 #ifndef __x86_64__ 21 23 # error This test is 64-bit only 22 24 #endif ··· 45 43 : "=a" (eax), "=d" (edx) 46 44 : "c" (index)); 47 45 return eax + ((uint64_t)edx << 32); 48 - } 49 - 50 - static inline void cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) 51 - { 52 - asm volatile("cpuid;" 53 - : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) 54 - : "0" (*eax), "2" (*ecx)); 55 46 } 56 47 57 48 static inline void xsave(struct xsave_buffer *xbuf, uint64_t rfbm) ··· 110 115 * support for the XSAVE feature set, including 111 116 * XGETBV. 112 117 */ 113 - eax = 1; 114 - ecx = 0; 115 - cpuid(&eax, &ebx, &ecx, &edx); 118 + __cpuid_count(1, 0, eax, ebx, ecx, edx); 116 119 if (!(ecx & CPUID_LEAF1_ECX_XSAVE_MASK)) 117 120 fatal_error("cpuid: no CPU xsave support"); 118 121 if (!(ecx & CPUID_LEAF1_ECX_OSXSAVE_MASK)) ··· 133 140 { 134 141 uint32_t eax, ebx, ecx, edx; 135 142 136 - eax = CPUID_LEAF_XSTATE; 137 - ecx = CPUID_SUBLEAF_XSTATE_USER; 138 - cpuid(&eax, &ebx, &ecx, &edx); 143 + __cpuid_count(CPUID_LEAF_XSTATE, CPUID_SUBLEAF_XSTATE_USER, 144 + eax, ebx, ecx, edx); 139 145 140 146 /* 141 147 * EBX enumerates the size (in bytes) required by the XSAVE ··· 145 153 */ 146 154 xbuf_size = ebx; 147 155 148 - eax = CPUID_LEAF_XSTATE; 149 - ecx = XFEATURE_XTILEDATA; 150 - 151 - cpuid(&eax, &ebx, &ecx, &edx); 156 + __cpuid_count(CPUID_LEAF_XSTATE, XFEATURE_XTILEDATA, 157 + eax, ebx, ecx, edx); 152 158 /* 153 159 * eax: XTILEDATA state component size 154 160 * ebx: XTILEDATA state component offset in user buffer