diff mbox

Fix MPX tests on systems with MPX disabled

Message ID 20160625181450.19462-1-andi@firstfloor.org
State New
Headers show

Commit Message

Andi Kleen June 25, 2016, 6:14 p.m. UTC
From: Andi Kleen <ak@linux.intel.com>

I have a Skylake system with MPX in the CPU, but MPX is disabled
in the kernel configuration.

This makes all the MPX tests fail because they assume if MPX
is in CPUID it works

Check the output of XGETBV too to detect non MPX kernels.

gcc/testsuite/:

2016-06-25  Andi Kleen  <ak@linux.intel.com>

	* gcc.target/i386/mpx/mpx-check.h: Check XGETBV output
	if kernel supports MPX.
---
 gcc/testsuite/gcc.target/i386/mpx/mpx-check.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Andi Kleen July 4, 2016, 7:58 p.m. UTC | #1
Andi Kleen <andi@firstfloor.org> writes:

PING!

> From: Andi Kleen <ak@linux.intel.com>
>
> I have a Skylake system with MPX in the CPU, but MPX is disabled
> in the kernel configuration.
>
> This makes all the MPX tests fail because they assume if MPX
> is in CPUID it works
>
> Check the output of XGETBV too to detect non MPX kernels.
>
> gcc/testsuite/:
>
> 2016-06-25  Andi Kleen  <ak@linux.intel.com>
>
> 	* gcc.target/i386/mpx/mpx-check.h: Check XGETBV output
> 	if kernel supports MPX.
> ---
>  gcc/testsuite/gcc.target/i386/mpx/mpx-check.h | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h b/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h
> index 3afa460..73aa01f 100644
> --- a/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h
> +++ b/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h
> @@ -16,6 +16,16 @@ mpx_test (int, const char **);
>  
>  #define DEBUG
>  
> +#define XSTATE_BNDREGS (1 << 3)
> +
> +/* This should be an intrinsic, but isn't.  */
> +static int xgetbv (unsigned x)
> +{
> +   unsigned eax, edx;
> +   asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (x)); 
> +   return eax;
> +}
> +
>  int
>  main (int argc, const char **argv)
>  {
> @@ -27,7 +37,7 @@ main (int argc, const char **argv)
>    __cpuid_count (7, 0, eax, ebx, ecx, edx);
>  
>    /* Run MPX test only if host has MPX support.  */
> -  if (ebx & bit_MPX)
> +  if ((ebx & bit_MPX) && (xgetbv (0) & XSTATE_BNDREGS))
>      mpx_test (argc, argv);
>    else
>      {
Ilya Enkovich July 5, 2016, 10:01 a.m. UTC | #2
2016-07-04 22:58 GMT+03:00 Andi Kleen <andi@firstfloor.org>:
> Andi Kleen <andi@firstfloor.org> writes:
>
> PING!
>
>> From: Andi Kleen <ak@linux.intel.com>
>>
>> I have a Skylake system with MPX in the CPU, but MPX is disabled
>> in the kernel configuration.
>>
>> This makes all the MPX tests fail because they assume if MPX
>> is in CPUID it works
>>
>> Check the output of XGETBV too to detect non MPX kernels.

The patch is OK for trunk and GCC 6 branch

Thanks,
Ilya

>>
>> gcc/testsuite/:
>>
>> 2016-06-25  Andi Kleen  <ak@linux.intel.com>
>>
>>       * gcc.target/i386/mpx/mpx-check.h: Check XGETBV output
>>       if kernel supports MPX.
>> ---
>>  gcc/testsuite/gcc.target/i386/mpx/mpx-check.h | 12 +++++++++++-
>>  1 file changed, 11 insertions(+), 1 deletion(-)
>>
>> diff --git a/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h b/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h
>> index 3afa460..73aa01f 100644
>> --- a/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h
>> +++ b/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h
>> @@ -16,6 +16,16 @@ mpx_test (int, const char **);
>>
>>  #define DEBUG
>>
>> +#define XSTATE_BNDREGS (1 << 3)
>> +
>> +/* This should be an intrinsic, but isn't.  */
>> +static int xgetbv (unsigned x)
>> +{
>> +   unsigned eax, edx;
>> +   asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (x));
>> +   return eax;
>> +}
>> +
>>  int
>>  main (int argc, const char **argv)
>>  {
>> @@ -27,7 +37,7 @@ main (int argc, const char **argv)
>>    __cpuid_count (7, 0, eax, ebx, ecx, edx);
>>
>>    /* Run MPX test only if host has MPX support.  */
>> -  if (ebx & bit_MPX)
>> +  if ((ebx & bit_MPX) && (xgetbv (0) & XSTATE_BNDREGS))
>>      mpx_test (argc, argv);
>>    else
>>      {
>
> --
> ak@linux.intel.com -- Speaking for myself only
diff mbox

Patch

diff --git a/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h b/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h
index 3afa460..73aa01f 100644
--- a/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h
+++ b/gcc/testsuite/gcc.target/i386/mpx/mpx-check.h
@@ -16,6 +16,16 @@  mpx_test (int, const char **);
 
 #define DEBUG
 
+#define XSTATE_BNDREGS (1 << 3)
+
+/* This should be an intrinsic, but isn't.  */
+static int xgetbv (unsigned x)
+{
+   unsigned eax, edx;
+   asm ("xgetbv" : "=a" (eax), "=d" (edx) : "c" (x)); 
+   return eax;
+}
+
 int
 main (int argc, const char **argv)
 {
@@ -27,7 +37,7 @@  main (int argc, const char **argv)
   __cpuid_count (7, 0, eax, ebx, ecx, edx);
 
   /* Run MPX test only if host has MPX support.  */
-  if (ebx & bit_MPX)
+  if ((ebx & bit_MPX) && (xgetbv (0) & XSTATE_BNDREGS))
     mpx_test (argc, argv);
   else
     {