Changes since V1: - V1: https://lore.kernel.org/lkml/cover.1644000145.git.reinette.chatre@intel.com/ - Change solution to not use __cpuid_count() from compiler's cpuid.h but instead use a local define of __cpuid_count() provided in kselftest.h to ensure tests continue working in all supported environments. (Shuah) - Rewrite cover letter and changelogs to reflect new solution.
A few tests that require running CPUID do so with a private implementation of a wrapper for CPUID. This duplication of the CPUID wrapper should be avoided.
Both gcc and clang/LLVM provide wrappers for CPUID but the wrappers are not available in the minimal required version of gcc, v3.2, that the selftests need to be used in. __cpuid_count() was added to gcc in v4.4, which is ok for kernels after v4.19 when the gcc minimal required version was changed to v4.6.
Add a local define of __cpuid_count() to kselftest.h to ensure that selftests can still work in environments with older stable kernels (v4.9 and v4.14 that have the minimal required version of gcc of v3.2). Update tests with private CPUID wrappers to use the new macro.
Cc: Dave Hansen dave.hansen@linux.intel.com Cc: Sandipan Das sandipan@linux.ibm.com Cc: Florian Weimer fweimer@redhat.com Cc: "Desnes A. Nunes do Rosario" desnesn@linux.vnet.ibm.com Cc: Ingo Molnar mingo@kernel.org Cc: Thiago Jung Bauermann bauerman@linux.ibm.com Cc: Michael Ellerman mpe@ellerman.id.au Cc: Michal Suchanek msuchanek@suse.de Cc: linux-mm@kvack.org Cc: Chang S. Bae chang.seok.bae@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 Cc: Andy Lutomirski luto@kernel.org
Reinette Chatre (4): selftests: Provide local define of __cpuid_count() selftests/vm/pkeys: Use provided __cpuid_count() macro selftests/x86/amx: Use provided __cpuid_count() macro selftests/x86/corrupt_xstate_header: Use provided __cpuid_count() macro
tools/testing/selftests/kselftest.h | 15 ++++++++++++ tools/testing/selftests/vm/pkey-x86.h | 21 ++-------------- tools/testing/selftests/x86/amx.c | 24 ++++++------------- .../selftests/x86/corrupt_xstate_header.c | 16 ++----------- 4 files changed, 26 insertions(+), 50 deletions(-)
base-commit: 09688c0166e76ce2fb85e86b9d99be8b0084cdf9
Some selftests depend on information provided by the CPUID instruction. To support this dependency the selftests implement private wrappers for CPUID.
Duplication of the CPUID wrappers should be avoided.
Both gcc and clang/LLVM provide __cpuid_count() macros but neither the macro nor its header file are available in all the compiler versions that need to be supported by the selftests. __cpuid_count() as provided by gcc is available starting with gcc v4.4, so it is not available if the latest tests need to be run in all the environments required to support kernels v4.9 and v4.14 that have the minimal required gcc v3.2.
Provide a centrally defined macro for __cpuid_count() to help eliminate the duplicate CPUID wrappers while continuing to compile in older environments.
Suggested-by: Shuah Khan skhan@linuxfoundation.org Signed-off-by: Reinette Chatre reinette.chatre@intel.com --- Note to maintainers: - Macro is identical to the one provided by gcc, but not liked by checkpatch.pl with message "Macros with complex values should be enclosed in parentheses". Similar style is used in kernel, for example in arch/x86/kernel/fpu/xstate.h.
tools/testing/selftests/kselftest.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index f1180987492c..898d7b2fac6c 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -52,6 +52,21 @@ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #endif
+/* + * gcc cpuid.h provides __cpuid_count() since v4.4. + * Clang/LLVM cpuid.h provides __cpuid_count() since v3.4.0. + * + * Provide local define for tests needing __cpuid_count() because + * selftests need to work in older environments that do not yet + * have __cpuid_count(). + */ +#ifndef __cpuid_count +#define __cpuid_count(level, count, a, b, c, d) \ + __asm__ __volatile__ ("cpuid\n\t" \ + : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ + : "0" (level), "2" (count)) +#endif + /* define kselftest exit codes */ #define KSFT_PASS 0 #define KSFT_FAIL 1
On 2022-03-15 at 09:44:25 -0700, Reinette Chatre wrote:
Some selftests depend on information provided by the CPUID instruction. To support this dependency the selftests implement private wrappers for CPUID.
Duplication of the CPUID wrappers should be avoided.
Both gcc and clang/LLVM provide __cpuid_count() macros but neither the macro nor its header file are available in all the compiler versions that need to be supported by the selftests. __cpuid_count() as provided by gcc is available starting with gcc v4.4, so it is not available if the latest tests need to be run in all the environments required to support kernels v4.9 and v4.14 that have the minimal required gcc v3.2.
Provide a centrally defined macro for __cpuid_count() to help eliminate the duplicate CPUID wrappers while continuing to compile in older environments.
Suggested-by: Shuah Khan skhan@linuxfoundation.org Signed-off-by: Reinette Chatre reinette.chatre@intel.com
Note to maintainers:
- Macro is identical to the one provided by gcc, but not liked by checkpatch.pl with message "Macros with complex values should be enclosed in parentheses". Similar style is used in kernel, for example in arch/x86/kernel/fpu/xstate.h.
tools/testing/selftests/kselftest.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index f1180987492c..898d7b2fac6c 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -52,6 +52,21 @@
- have __cpuid_count().
- */
+#ifndef __cpuid_count +#define __cpuid_count(level, count, a, b, c, d) \
- __asm__ __volatile__ ("cpuid\n\t" \
: "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
: "0" (level), "2" (count))
+#endif
Linux C check tool "scripts/checkpatch.pl" shows an error: " ERROR: Macros with complex values should be enclosed in parentheses ... +#define __cpuid_count(level, count, a, b, c, d) \ + __asm__ __volatile__ ("cpuid\n\t" \ + : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ + : "0" (level), "2" (count)) " Googling: https://www.google.com/search?q=Macros+with+complex+values+should+be+enclose... -> https://stackoverflow.com/questions/8142280/why-do-we-need-parentheses-aroun...
Could we fix it as follow, shall we? " #ifndef __cpuid_count #define __cpuid_count(level, count, a, b, c, d) ({ \ __asm__ __volatile__ ("cpuid\n\t" \ : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ : "0" (level), "2" (count)) \ }) #endif " Thanks! --Pengfei
Hi Pengfei,
On 4/16/2022 12:52 AM, Pengfei Xu wrote:
On 2022-03-15 at 09:44:25 -0700, Reinette Chatre wrote:
Some selftests depend on information provided by the CPUID instruction. To support this dependency the selftests implement private wrappers for CPUID.
Duplication of the CPUID wrappers should be avoided.
Both gcc and clang/LLVM provide __cpuid_count() macros but neither the macro nor its header file are available in all the compiler versions that need to be supported by the selftests. __cpuid_count() as provided by gcc is available starting with gcc v4.4, so it is not available if the latest tests need to be run in all the environments required to support kernels v4.9 and v4.14 that have the minimal required gcc v3.2.
Provide a centrally defined macro for __cpuid_count() to help eliminate the duplicate CPUID wrappers while continuing to compile in older environments.
Suggested-by: Shuah Khan skhan@linuxfoundation.org Signed-off-by: Reinette Chatre reinette.chatre@intel.com
Note to maintainers:
- Macro is identical to the one provided by gcc, but not liked by checkpatch.pl with message "Macros with complex values should be enclosed in parentheses". Similar style is used in kernel, for example in arch/x86/kernel/fpu/xstate.h.
tools/testing/selftests/kselftest.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index f1180987492c..898d7b2fac6c 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -52,6 +52,21 @@
- have __cpuid_count().
- */
+#ifndef __cpuid_count +#define __cpuid_count(level, count, a, b, c, d) \
- __asm__ __volatile__ ("cpuid\n\t" \
: "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
: "0" (level), "2" (count))
+#endif
Linux C check tool "scripts/checkpatch.pl" shows an error: " ERROR: Macros with complex values should be enclosed in parentheses
I encountered this also and that is why this patch contains the "Note to maintainers" above. It is not clear to me whether you considered the note since your response does not acknowledge it.
... +#define __cpuid_count(level, count, a, b, c, d) \
__asm__ __volatile__ ("cpuid\n\t" \
: "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
: "0" (level), "2" (count))
" Googling: https://www.google.com/search?q=Macros+with+complex+values+should+be+enclose... -> https://stackoverflow.com/questions/8142280/why-do-we-need-parentheses-aroun...
More information available in https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html#Statement-Exprs but from what I understand it does not apply to this macro. Even so, I do not know what checkpatch.pl uses to determine that this is a "Macro with complex values".
Could we fix it as follow, shall we? " #ifndef __cpuid_count #define __cpuid_count(level, count, a, b, c, d) ({ \ __asm__ __volatile__ ("cpuid\n\t" \ : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ : "0" (level), "2" (count)) \ }) #endif "
Sure, I can do so.
Reinette
On 2022-04-18 at 09:04:33 -0700, Reinette Chatre wrote:
Hi Pengfei,
On 4/16/2022 12:52 AM, Pengfei Xu wrote:
On 2022-03-15 at 09:44:25 -0700, Reinette Chatre wrote:
Some selftests depend on information provided by the CPUID instruction. To support this dependency the selftests implement private wrappers for CPUID.
Duplication of the CPUID wrappers should be avoided.
Both gcc and clang/LLVM provide __cpuid_count() macros but neither the macro nor its header file are available in all the compiler versions that need to be supported by the selftests. __cpuid_count() as provided by gcc is available starting with gcc v4.4, so it is not available if the latest tests need to be run in all the environments required to support kernels v4.9 and v4.14 that have the minimal required gcc v3.2.
Provide a centrally defined macro for __cpuid_count() to help eliminate the duplicate CPUID wrappers while continuing to compile in older environments.
Suggested-by: Shuah Khan skhan@linuxfoundation.org Signed-off-by: Reinette Chatre reinette.chatre@intel.com
Note to maintainers:
- Macro is identical to the one provided by gcc, but not liked by checkpatch.pl with message "Macros with complex values should be enclosed in parentheses". Similar style is used in kernel, for example in arch/x86/kernel/fpu/xstate.h.
tools/testing/selftests/kselftest.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index f1180987492c..898d7b2fac6c 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -52,6 +52,21 @@
- have __cpuid_count().
- */
+#ifndef __cpuid_count +#define __cpuid_count(level, count, a, b, c, d) \
- __asm__ __volatile__ ("cpuid\n\t" \
: "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
: "0" (level), "2" (count))
+#endif
Linux C check tool "scripts/checkpatch.pl" shows an error: " ERROR: Macros with complex values should be enclosed in parentheses
I encountered this also and that is why this patch contains the "Note to maintainers" above. It is not clear to me whether you considered the note since your response does not acknowledge it.
Sorry, I just made a suggestion to fix this problem mentioned by the script. I didn't notice and reply for the note.
... +#define __cpuid_count(level, count, a, b, c, d) \
__asm__ __volatile__ ("cpuid\n\t" \
: "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
: "0" (level), "2" (count))
" Googling: https://www.google.com/search?q=Macros+with+complex+values+should+be+enclose... -> https://stackoverflow.com/questions/8142280/why-do-we-need-parentheses-aroun...
More information available in https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html#Statement-Exprs but from what I understand it does not apply to this macro. Even so, I do not know what checkpatch.pl uses to determine that this is a "Macro with complex values".
Checked checkpatch.pl and it seems to suggest using ({ }) for any asm macro definition.
Could we fix it as follow, shall we? " #ifndef __cpuid_count #define __cpuid_count(level, count, a, b, c, d) ({ \ __asm__ __volatile__ ("cpuid\n\t" \ : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ : "0" (level), "2" (count)) \ }) #endif "
Sure, I can do so.
I just made a suggestion to fix the problem reported by the checkpatch.pl. But I didn't think deeply enough before: I'm not sure is there any real improvment or help after the fix.
Thanks! --Pengfei
Reinette
Hi Pengfei,
On 4/18/2022 9:31 PM, Pengfei Xu wrote:
On 2022-04-18 at 09:04:33 -0700, Reinette Chatre wrote:
Hi Pengfei,
On 4/16/2022 12:52 AM, Pengfei Xu wrote:
On 2022-03-15 at 09:44:25 -0700, Reinette Chatre wrote:
Some selftests depend on information provided by the CPUID instruction. To support this dependency the selftests implement private wrappers for CPUID.
Duplication of the CPUID wrappers should be avoided.
Both gcc and clang/LLVM provide __cpuid_count() macros but neither the macro nor its header file are available in all the compiler versions that need to be supported by the selftests. __cpuid_count() as provided by gcc is available starting with gcc v4.4, so it is not available if the latest tests need to be run in all the environments required to support kernels v4.9 and v4.14 that have the minimal required gcc v3.2.
Provide a centrally defined macro for __cpuid_count() to help eliminate the duplicate CPUID wrappers while continuing to compile in older environments.
Suggested-by: Shuah Khan skhan@linuxfoundation.org Signed-off-by: Reinette Chatre reinette.chatre@intel.com
Note to maintainers:
- Macro is identical to the one provided by gcc, but not liked by checkpatch.pl with message "Macros with complex values should be enclosed in parentheses". Similar style is used in kernel, for example in arch/x86/kernel/fpu/xstate.h.
tools/testing/selftests/kselftest.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index f1180987492c..898d7b2fac6c 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -52,6 +52,21 @@
- have __cpuid_count().
- */
+#ifndef __cpuid_count +#define __cpuid_count(level, count, a, b, c, d) \
- __asm__ __volatile__ ("cpuid\n\t" \
: "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
: "0" (level), "2" (count))
+#endif
Linux C check tool "scripts/checkpatch.pl" shows an error: " ERROR: Macros with complex values should be enclosed in parentheses
I encountered this also and that is why this patch contains the "Note to maintainers" above. It is not clear to me whether you considered the note since your response does not acknowledge it.
Sorry, I just made a suggestion to fix this problem mentioned by the script. I didn't notice and reply for the note.
... +#define __cpuid_count(level, count, a, b, c, d) \
__asm__ __volatile__ ("cpuid\n\t" \
: "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
: "0" (level), "2" (count))
" Googling: https://www.google.com/search?q=Macros+with+complex+values+should+be+enclose... -> https://stackoverflow.com/questions/8142280/why-do-we-need-parentheses-aroun...
More information available in https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html#Statement-Exprs but from what I understand it does not apply to this macro. Even so, I do not know what checkpatch.pl uses to determine that this is a "Macro with complex values".
Checked checkpatch.pl and it seems to suggest using ({ }) for any asm macro definition.
Could we fix it as follow, shall we? " #ifndef __cpuid_count #define __cpuid_count(level, count, a, b, c, d) ({ \ __asm__ __volatile__ ("cpuid\n\t" \ : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ : "0" (level), "2" (count)) \ }) #endif "
Sure, I can do so.
I just made a suggestion to fix the problem reported by the checkpatch.pl. But I didn't think deeply enough before: I'm not sure is there any real improvment or help after the fix.
In this case I would prefer to not implicitly follow the checkpatch.pl without understanding what the concern is.
The goal of this change is to make the __cpuid_count() macro available within kselftest and it does so by duplicating gcc's __cpuid_count() macro.
The macro style is not unique and you would, for example, encounter the same checkpatch.pl complaint if you run: ./scripts/checkpatch.pl -f arch/x86/kernel/fpu/xstate.h
Reinette
On 2022-04-19 at 15:34:11 -0700, Reinette Chatre wrote:
Hi Pengfei,
On 4/18/2022 9:31 PM, Pengfei Xu wrote:
On 2022-04-18 at 09:04:33 -0700, Reinette Chatre wrote:
Hi Pengfei,
On 4/16/2022 12:52 AM, Pengfei Xu wrote:
On 2022-03-15 at 09:44:25 -0700, Reinette Chatre wrote:
Some selftests depend on information provided by the CPUID instruction. To support this dependency the selftests implement private wrappers for CPUID.
Duplication of the CPUID wrappers should be avoided.
Both gcc and clang/LLVM provide __cpuid_count() macros but neither the macro nor its header file are available in all the compiler versions that need to be supported by the selftests. __cpuid_count() as provided by gcc is available starting with gcc v4.4, so it is not available if the latest tests need to be run in all the environments required to support kernels v4.9 and v4.14 that have the minimal required gcc v3.2.
Provide a centrally defined macro for __cpuid_count() to help eliminate the duplicate CPUID wrappers while continuing to compile in older environments.
Suggested-by: Shuah Khan skhan@linuxfoundation.org Signed-off-by: Reinette Chatre reinette.chatre@intel.com
Note to maintainers:
- Macro is identical to the one provided by gcc, but not liked by checkpatch.pl with message "Macros with complex values should be enclosed in parentheses". Similar style is used in kernel, for example in arch/x86/kernel/fpu/xstate.h.
tools/testing/selftests/kselftest.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index f1180987492c..898d7b2fac6c 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -52,6 +52,21 @@
- have __cpuid_count().
- */
+#ifndef __cpuid_count +#define __cpuid_count(level, count, a, b, c, d) \
- __asm__ __volatile__ ("cpuid\n\t" \
: "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
: "0" (level), "2" (count))
+#endif
Linux C check tool "scripts/checkpatch.pl" shows an error: " ERROR: Macros with complex values should be enclosed in parentheses
I encountered this also and that is why this patch contains the "Note to maintainers" above. It is not clear to me whether you considered the note since your response does not acknowledge it.
Sorry, I just made a suggestion to fix this problem mentioned by the script. I didn't notice and reply for the note.
... +#define __cpuid_count(level, count, a, b, c, d) \
__asm__ __volatile__ ("cpuid\n\t" \
: "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
: "0" (level), "2" (count))
" Googling: https://www.google.com/search?q=Macros+with+complex+values+should+be+enclose... -> https://stackoverflow.com/questions/8142280/why-do-we-need-parentheses-aroun...
More information available in https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html#Statement-Exprs but from what I understand it does not apply to this macro. Even so, I do not know what checkpatch.pl uses to determine that this is a "Macro with complex values".
Checked checkpatch.pl and it seems to suggest using ({ }) for any asm macro definition.
Could we fix it as follow, shall we? " #ifndef __cpuid_count #define __cpuid_count(level, count, a, b, c, d) ({ \ __asm__ __volatile__ ("cpuid\n\t" \ : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ : "0" (level), "2" (count)) \ }) #endif "
Sure, I can do so.
I just made a suggestion to fix the problem reported by the checkpatch.pl. But I didn't think deeply enough before: I'm not sure is there any real improvment or help after the fix.
In this case I would prefer to not implicitly follow the checkpatch.pl without understanding what the concern is.
The goal of this change is to make the __cpuid_count() macro available within kselftest and it does so by duplicating gcc's __cpuid_count() macro.
The macro style is not unique and you would, for example, encounter the same checkpatch.pl complaint if you run: ./scripts/checkpatch.pl -f arch/x86/kernel/fpu/xstate.h
Ok, no question from my side.
Thanks! --Pengfei
Reinette
kselftest.h makes the __cpuid_count() macro available to conveniently call the CPUID instruction.
Remove the local CPUID wrapper and use __cpuid_count() from already included 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 compiled with gcc v3.2, the minimal required version for stable kernels.
Cc: Dave Hansen dave.hansen@linux.intel.com Cc: Sandipan Das sandipan@linux.ibm.com Cc: Florian Weimer fweimer@redhat.com Cc: "Desnes A. Nunes do Rosario" desnesn@linux.vnet.ibm.com Cc: Ingo Molnar mingo@kernel.org Cc: Thiago Jung Bauermann bauerman@linux.ibm.com Cc: Michael Ellerman mpe@ellerman.id.au Cc: Michal Suchanek msuchanek@suse.de Cc: linux-mm@kvack.org Signed-off-by: Reinette Chatre reinette.chatre@intel.com --- Changes since V1: - Update changelog - Remove Ram Pai from cc list (email address no longer valid) - No longer include cpuid.h but obtain __cpuid_count() from kselftest.h.
tools/testing/selftests/vm/pkey-x86.h | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-)
diff --git a/tools/testing/selftests/vm/pkey-x86.h b/tools/testing/selftests/vm/pkey-x86.h index e4a4ce2b826d..b078ce9c6d2a 100644 --- a/tools/testing/selftests/vm/pkey-x86.h +++ b/tools/testing/selftests/vm/pkey-x86.h @@ -80,19 +80,6 @@ static inline void __write_pkey_reg(u64 pkey_reg) assert(pkey_reg == __read_pkey_reg()); }
-static inline void __cpuid(unsigned int *eax, unsigned int *ebx, - unsigned int *ecx, unsigned int *edx) -{ - /* ecx is often an input as well as an output. */ - asm volatile( - "cpuid;" - : "=a" (*eax), - "=b" (*ebx), - "=c" (*ecx), - "=d" (*edx) - : "0" (*eax), "2" (*ecx)); -} - /* Intel-defined CPU features, CPUID level 0x00000007:0 (ecx) */ #define X86_FEATURE_PKU (1<<3) /* Protection Keys for Userspace */ #define X86_FEATURE_OSPKE (1<<4) /* OS Protection Keys Enable */ @@ -104,9 +91,7 @@ static inline int cpu_has_pkeys(void) unsigned int ecx; unsigned int edx;
- eax = 0x7; - ecx = 0x0; - __cpuid(&eax, &ebx, &ecx, &edx); + __cpuid_count(0x7, 0x0, eax, ebx, ecx, edx);
if (!(ecx & X86_FEATURE_PKU)) { dprintf2("cpu does not have PKU\n"); @@ -142,9 +127,7 @@ int pkey_reg_xstate_offset(void) /* assume that XSTATE_PKEY is set in XCR0 */ leaf = XSTATE_PKEY_BIT; { - eax = XSTATE_CPUID; - ecx = leaf; - __cpuid(&eax, &ebx, &ecx, &edx); + __cpuid_count(XSTATE_CPUID, leaf, eax, ebx, ecx, edx);
if (leaf == XSTATE_PKEY_BIT) { xstate_offset = ebx;
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 --- Changes since V1: - Update changelog - No longer include cpuid.h but obtain __cpuid_count() from kselftest.h.
tools/testing/selftests/x86/amx.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-)
diff --git a/tools/testing/selftests/x86/amx.c b/tools/testing/selftests/x86/amx.c index 3615ef4a48bb..d463ea30d90f 100644 --- a/tools/testing/selftests/x86/amx.c +++ b/tools/testing/selftests/x86/amx.c @@ -17,6 +17,8 @@ #include <sys/syscall.h> #include <sys/wait.h>
+#include "../kselftest.h" /* For __cpuid_count() */ + #ifndef __x86_64__ # error This test is 64-bit only #endif @@ -45,13 +47,6 @@ static inline uint64_t xgetbv(uint32_t index) return eax + ((uint64_t)edx << 32); }
-static inline void cpuid(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) -{ - asm volatile("cpuid;" - : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) - : "0" (*eax), "2" (*ecx)); -} - static inline void xsave(struct xsave_buffer *xbuf, uint64_t rfbm) { uint32_t rfbm_lo = rfbm; @@ -115,9 +110,7 @@ static inline void check_cpuid_xsave(void) * support for the XSAVE feature set, including * XGETBV. */ - eax = 1; - ecx = 0; - cpuid(&eax, &ebx, &ecx, &edx); + __cpuid_count(1, 0, eax, ebx, ecx, edx); if (!(ecx & CPUID_LEAF1_ECX_XSAVE_MASK)) fatal_error("cpuid: no CPU xsave support"); if (!(ecx & CPUID_LEAF1_ECX_OSXSAVE_MASK)) @@ -140,9 +133,8 @@ static void check_cpuid_xtiledata(void) { uint32_t eax, ebx, ecx, edx;
- eax = CPUID_LEAF_XSTATE; - ecx = CPUID_SUBLEAF_XSTATE_USER; - cpuid(&eax, &ebx, &ecx, &edx); + __cpuid_count(CPUID_LEAF_XSTATE, CPUID_SUBLEAF_XSTATE_USER, + eax, ebx, ecx, edx);
/* * EBX enumerates the size (in bytes) required by the XSAVE @@ -153,10 +145,8 @@ static void check_cpuid_xtiledata(void) */ xbuf_size = ebx;
- eax = CPUID_LEAF_XSTATE; - ecx = XFEATURE_XTILEDATA; - - cpuid(&eax, &ebx, &ecx, &edx); + __cpuid_count(CPUID_LEAF_XSTATE, XFEATURE_XTILEDATA, + eax, ebx, ecx, edx); /* * eax: XTILEDATA state component size * ebx: XTILEDATA state component offset in user buffer
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: 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 --- Changes since V1: - Update changelog - No longer include cpuid.h but obtain __cpuid_count() from kselftest.h.
.../selftests/x86/corrupt_xstate_header.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/tools/testing/selftests/x86/corrupt_xstate_header.c b/tools/testing/selftests/x86/corrupt_xstate_header.c index ab8599c10ce5..cf9ce8fbb656 100644 --- a/tools/testing/selftests/x86/corrupt_xstate_header.c +++ b/tools/testing/selftests/x86/corrupt_xstate_header.c @@ -17,25 +17,13 @@ #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)); -} +#include "../kselftest.h" /* For __cpuid_count() */
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);
linux-kselftest-mirror@lists.linaro.org