Re: [PATCH v2 3/3] selftests/x86, x86/ldt: Add a selftest for modify_ldt

2015-07-21 Thread Andy Lutomirski
On Tue, Jul 21, 2015 at 4:36 PM, Willy Tarreau  wrote:
> Hi Andy,
>
> On Tue, Jul 21, 2015 at 12:59:31PM -0700, Andy Lutomirski wrote:
>> This tests general modify_ldt behavior (only writes, so far) as
>> well as synchronous updates via IPI.  It fails on old kernels.
>>
>> I called this ldt_gdt because I'll add set_thread_area tests to
>> it at some point.
>
> Quick feedback : at two places you have this :
>
>> + } else if (errno == ENOSYS) {
>> + printf("[OK]\tmodify_ldt is returned -ENOSYS\n");
>
> => s/is //
>
> Please add stdlib.h to avoid this warning I'm getting on 32-bit :
>
> ldt_gdt.c:286:4: warning: incompatible implicit declaration of built-in 
> function 'exit' [enabled by default]
>
> And I had to remove xmmintrinsic as suggested by Boris as well.
>
>
> FWIW here's what I'm getting here on 4.1.2 without CONFIG_X86_16BIT
> (where nmi_espfix failed), the output is the same for a 32- and a 64-bit
> process :
>
> [OK]LDT entry 0 has AR 0x0040FA00 and limit 0x000A
> [OK]LDT entry 0 has AR 0x00C0FA00 and limit 0xAFFF
> [OK]LDT entry 1 is invalid
> [OK]LDT entry 2 has AR 0x00C0FA00 and limit 0xAFFF
> [OK]LDT entry 1 is invalid
> [OK]LDT entry 2 has AR 0x00C0FA00 and limit 0xAFFF
> [OK]LDT entry 2 has AR 0x00D0FA00 and limit 0xAFFF
> [OK]LDT entry 2 has AR 0x00D07A00 and limit 0xAFFF
> [OK]modify_ldt rejected 16 bit segment
> [OK]LDT entry 2 has AR 0x00D07200 and limit 0xAFFF
> [OK]LDT entry 2 has AR 0x00D07000 and limit 0xAFFF
> [OK]LDT entry 2 has AR 0x00D07400 and limit 0xAFFF
> [OK]LDT entry 2 has AR 0x00507600 and limit 0x000A
> [OK]LDT entry 2 has AR 0x00507E00 and limit 0x000A
> [OK]LDT entry 2 has AR 0x00507C00 and limit 0x000A
> [OK]LDT entry 2 has AR 0x00507A00 and limit 0x000A
> [OK]LDT entry 2 has AR 0x00507800 and limit 0x000A
> [OK]LDT entry 2 has AR 0x00507800 and limit 0x000A
> [RUN]   Test fork
> [OK]LDT entry 2 has AR 0x00507800 and limit 0x000A
> [OK]LDT entry 1 is invalid
> [OK]Child succeeded
> [OK]modify_ldt failure 22
> [OK]modify_ldt rejected 16 bit segment
> [OK]modify_ldt rejected 16 bit segment
> [OK]modify_ldt rejected 16 bit segment
> [OK]modify_ldt rejected 16 bit segment
> [OK]modify_ldt rejected 16 bit segment
> [OK]modify_ldt rejected 16 bit segment
> [OK]LDT entry 0 is invalid
> [OK]LDT entry 0 has AR 0x0040F200 and limit 0x
> [OK]LDT entry 0 is invalid
> [RUN]   Cross-CPU LDT invalidation
> [FAIL]  5 of 5 iterations failed

That's intentional.  Old modify_ldt can leave other threads with stale
cached descriptors, which is what you're seeing.

--Andy

>
> Thanks,
> Willy
>



-- 
Andy Lutomirski
AMA Capital Management, LLC
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 3/3] selftests/x86, x86/ldt: Add a selftest for modify_ldt

2015-07-21 Thread Willy Tarreau
Hi Andy,

On Tue, Jul 21, 2015 at 12:59:31PM -0700, Andy Lutomirski wrote:
> This tests general modify_ldt behavior (only writes, so far) as
> well as synchronous updates via IPI.  It fails on old kernels.
> 
> I called this ldt_gdt because I'll add set_thread_area tests to
> it at some point.

Quick feedback : at two places you have this :

> + } else if (errno == ENOSYS) {
> + printf("[OK]\tmodify_ldt is returned -ENOSYS\n");

=> s/is //

Please add stdlib.h to avoid this warning I'm getting on 32-bit :

ldt_gdt.c:286:4: warning: incompatible implicit declaration of built-in 
function 'exit' [enabled by default]

And I had to remove xmmintrinsic as suggested by Boris as well.


FWIW here's what I'm getting here on 4.1.2 without CONFIG_X86_16BIT
(where nmi_espfix failed), the output is the same for a 32- and a 64-bit
process :

[OK]LDT entry 0 has AR 0x0040FA00 and limit 0x000A
[OK]LDT entry 0 has AR 0x00C0FA00 and limit 0xAFFF
[OK]LDT entry 1 is invalid
[OK]LDT entry 2 has AR 0x00C0FA00 and limit 0xAFFF
[OK]LDT entry 1 is invalid
[OK]LDT entry 2 has AR 0x00C0FA00 and limit 0xAFFF
[OK]LDT entry 2 has AR 0x00D0FA00 and limit 0xAFFF
[OK]LDT entry 2 has AR 0x00D07A00 and limit 0xAFFF
[OK]modify_ldt rejected 16 bit segment
[OK]LDT entry 2 has AR 0x00D07200 and limit 0xAFFF
[OK]LDT entry 2 has AR 0x00D07000 and limit 0xAFFF
[OK]LDT entry 2 has AR 0x00D07400 and limit 0xAFFF
[OK]LDT entry 2 has AR 0x00507600 and limit 0x000A
[OK]LDT entry 2 has AR 0x00507E00 and limit 0x000A
[OK]LDT entry 2 has AR 0x00507C00 and limit 0x000A
[OK]LDT entry 2 has AR 0x00507A00 and limit 0x000A
[OK]LDT entry 2 has AR 0x00507800 and limit 0x000A
[OK]LDT entry 2 has AR 0x00507800 and limit 0x000A
[RUN]   Test fork
[OK]LDT entry 2 has AR 0x00507800 and limit 0x000A
[OK]LDT entry 1 is invalid
[OK]Child succeeded
[OK]modify_ldt failure 22
[OK]modify_ldt rejected 16 bit segment
[OK]modify_ldt rejected 16 bit segment
[OK]modify_ldt rejected 16 bit segment
[OK]modify_ldt rejected 16 bit segment
[OK]modify_ldt rejected 16 bit segment
[OK]modify_ldt rejected 16 bit segment
[OK]LDT entry 0 is invalid
[OK]LDT entry 0 has AR 0x0040F200 and limit 0x
[OK]LDT entry 0 is invalid
[RUN]   Cross-CPU LDT invalidation
[FAIL]  5 of 5 iterations failed

Thanks,
Willy

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 3/3] selftests/x86, x86/ldt: Add a selftest for modify_ldt

2015-07-21 Thread Andy Lutomirski
On Tue, Jul 21, 2015 at 3:02 PM, Boris Ostrovsky
 wrote:
> On 07/21/2015 03:59 PM, Andy Lutomirski wrote:
>>
>> diff --git a/tools/testing/selftests/x86/ldt_gdt.c
>> b/tools/testing/selftests/x86/ldt_gdt.c
>> new file mode 100644
>> index ..6f6699f0351a
>> --- /dev/null
>> +++ b/tools/testing/selftests/x86/ldt_gdt.c
>> @@ -0,0 +1,492 @@
>> +/*
>> + * ldt_gdt.c - Test cases for LDT and GDT access
>> + * Copyright (c) 2015 Andrew Lutomirski
>> + */
>> +
>> +#define _GNU_SOURCE
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>
>
> Is xmmintrin.h necessary? It breaks 32-bit build with

no, and I'll remove it.

--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 3/3] selftests/x86, x86/ldt: Add a selftest for modify_ldt

2015-07-21 Thread Boris Ostrovsky

On 07/21/2015 03:59 PM, Andy Lutomirski wrote:

diff --git a/tools/testing/selftests/x86/ldt_gdt.c 
b/tools/testing/selftests/x86/ldt_gdt.c
new file mode 100644
index ..6f6699f0351a
--- /dev/null
+++ b/tools/testing/selftests/x86/ldt_gdt.c
@@ -0,0 +1,492 @@
+/*
+ * ldt_gdt.c - Test cases for LDT and GDT access
+ * Copyright (c) 2015 Andrew Lutomirski
+ */
+
+#define _GNU_SOURCE
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 


Is xmmintrin.h necessary? It breaks 32-bit build with

/usr/lib/gcc/x86_64-redhat-linux/4.7.2/include/xmmintrin.h:32:3: error: 
#error "SSE instruction set not enabled"


unless I add -msse2.

(This also needs stdlib.h for exit() declaration)

-boris


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 3/3] selftests/x86, x86/ldt: Add a selftest for modify_ldt

2015-07-21 Thread Boris Ostrovsky

On 07/21/2015 03:59 PM, Andy Lutomirski wrote:

diff --git a/tools/testing/selftests/x86/ldt_gdt.c 
b/tools/testing/selftests/x86/ldt_gdt.c
new file mode 100644
index ..6f6699f0351a
--- /dev/null
+++ b/tools/testing/selftests/x86/ldt_gdt.c
@@ -0,0 +1,492 @@
+/*
+ * ldt_gdt.c - Test cases for LDT and GDT access
+ * Copyright (c) 2015 Andrew Lutomirski
+ */
+
+#define _GNU_SOURCE
+#include err.h
+#include stdio.h
+#include stdint.h
+#include signal.h
+#include setjmp.h
+#include string.h
+#include errno.h
+#include xmmintrin.h


Is xmmintrin.h necessary? It breaks 32-bit build with

/usr/lib/gcc/x86_64-redhat-linux/4.7.2/include/xmmintrin.h:32:3: error: 
#error SSE instruction set not enabled


unless I add -msse2.

(This also needs stdlib.h for exit() declaration)

-boris


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 3/3] selftests/x86, x86/ldt: Add a selftest for modify_ldt

2015-07-21 Thread Andy Lutomirski
On Tue, Jul 21, 2015 at 3:02 PM, Boris Ostrovsky
boris.ostrov...@oracle.com wrote:
 On 07/21/2015 03:59 PM, Andy Lutomirski wrote:

 diff --git a/tools/testing/selftests/x86/ldt_gdt.c
 b/tools/testing/selftests/x86/ldt_gdt.c
 new file mode 100644
 index ..6f6699f0351a
 --- /dev/null
 +++ b/tools/testing/selftests/x86/ldt_gdt.c
 @@ -0,0 +1,492 @@
 +/*
 + * ldt_gdt.c - Test cases for LDT and GDT access
 + * Copyright (c) 2015 Andrew Lutomirski
 + */
 +
 +#define _GNU_SOURCE
 +#include err.h
 +#include stdio.h
 +#include stdint.h
 +#include signal.h
 +#include setjmp.h
 +#include string.h
 +#include errno.h
 +#include xmmintrin.h


 Is xmmintrin.h necessary? It breaks 32-bit build with

no, and I'll remove it.

--Andy
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 3/3] selftests/x86, x86/ldt: Add a selftest for modify_ldt

2015-07-21 Thread Willy Tarreau
Hi Andy,

On Tue, Jul 21, 2015 at 12:59:31PM -0700, Andy Lutomirski wrote:
 This tests general modify_ldt behavior (only writes, so far) as
 well as synchronous updates via IPI.  It fails on old kernels.
 
 I called this ldt_gdt because I'll add set_thread_area tests to
 it at some point.

Quick feedback : at two places you have this :

 + } else if (errno == ENOSYS) {
 + printf([OK]\tmodify_ldt is returned -ENOSYS\n);

= s/is //

Please add stdlib.h to avoid this warning I'm getting on 32-bit :

ldt_gdt.c:286:4: warning: incompatible implicit declaration of built-in 
function 'exit' [enabled by default]

And I had to remove xmmintrinsic as suggested by Boris as well.


FWIW here's what I'm getting here on 4.1.2 without CONFIG_X86_16BIT
(where nmi_espfix failed), the output is the same for a 32- and a 64-bit
process :

[OK]LDT entry 0 has AR 0x0040FA00 and limit 0x000A
[OK]LDT entry 0 has AR 0x00C0FA00 and limit 0xAFFF
[OK]LDT entry 1 is invalid
[OK]LDT entry 2 has AR 0x00C0FA00 and limit 0xAFFF
[OK]LDT entry 1 is invalid
[OK]LDT entry 2 has AR 0x00C0FA00 and limit 0xAFFF
[OK]LDT entry 2 has AR 0x00D0FA00 and limit 0xAFFF
[OK]LDT entry 2 has AR 0x00D07A00 and limit 0xAFFF
[OK]modify_ldt rejected 16 bit segment
[OK]LDT entry 2 has AR 0x00D07200 and limit 0xAFFF
[OK]LDT entry 2 has AR 0x00D07000 and limit 0xAFFF
[OK]LDT entry 2 has AR 0x00D07400 and limit 0xAFFF
[OK]LDT entry 2 has AR 0x00507600 and limit 0x000A
[OK]LDT entry 2 has AR 0x00507E00 and limit 0x000A
[OK]LDT entry 2 has AR 0x00507C00 and limit 0x000A
[OK]LDT entry 2 has AR 0x00507A00 and limit 0x000A
[OK]LDT entry 2 has AR 0x00507800 and limit 0x000A
[OK]LDT entry 2 has AR 0x00507800 and limit 0x000A
[RUN]   Test fork
[OK]LDT entry 2 has AR 0x00507800 and limit 0x000A
[OK]LDT entry 1 is invalid
[OK]Child succeeded
[OK]modify_ldt failure 22
[OK]modify_ldt rejected 16 bit segment
[OK]modify_ldt rejected 16 bit segment
[OK]modify_ldt rejected 16 bit segment
[OK]modify_ldt rejected 16 bit segment
[OK]modify_ldt rejected 16 bit segment
[OK]modify_ldt rejected 16 bit segment
[OK]LDT entry 0 is invalid
[OK]LDT entry 0 has AR 0x0040F200 and limit 0x
[OK]LDT entry 0 is invalid
[RUN]   Cross-CPU LDT invalidation
[FAIL]  5 of 5 iterations failed

Thanks,
Willy

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 3/3] selftests/x86, x86/ldt: Add a selftest for modify_ldt

2015-07-21 Thread Andy Lutomirski
On Tue, Jul 21, 2015 at 4:36 PM, Willy Tarreau w...@1wt.eu wrote:
 Hi Andy,

 On Tue, Jul 21, 2015 at 12:59:31PM -0700, Andy Lutomirski wrote:
 This tests general modify_ldt behavior (only writes, so far) as
 well as synchronous updates via IPI.  It fails on old kernels.

 I called this ldt_gdt because I'll add set_thread_area tests to
 it at some point.

 Quick feedback : at two places you have this :

 + } else if (errno == ENOSYS) {
 + printf([OK]\tmodify_ldt is returned -ENOSYS\n);

 = s/is //

 Please add stdlib.h to avoid this warning I'm getting on 32-bit :

 ldt_gdt.c:286:4: warning: incompatible implicit declaration of built-in 
 function 'exit' [enabled by default]

 And I had to remove xmmintrinsic as suggested by Boris as well.


 FWIW here's what I'm getting here on 4.1.2 without CONFIG_X86_16BIT
 (where nmi_espfix failed), the output is the same for a 32- and a 64-bit
 process :

 [OK]LDT entry 0 has AR 0x0040FA00 and limit 0x000A
 [OK]LDT entry 0 has AR 0x00C0FA00 and limit 0xAFFF
 [OK]LDT entry 1 is invalid
 [OK]LDT entry 2 has AR 0x00C0FA00 and limit 0xAFFF
 [OK]LDT entry 1 is invalid
 [OK]LDT entry 2 has AR 0x00C0FA00 and limit 0xAFFF
 [OK]LDT entry 2 has AR 0x00D0FA00 and limit 0xAFFF
 [OK]LDT entry 2 has AR 0x00D07A00 and limit 0xAFFF
 [OK]modify_ldt rejected 16 bit segment
 [OK]LDT entry 2 has AR 0x00D07200 and limit 0xAFFF
 [OK]LDT entry 2 has AR 0x00D07000 and limit 0xAFFF
 [OK]LDT entry 2 has AR 0x00D07400 and limit 0xAFFF
 [OK]LDT entry 2 has AR 0x00507600 and limit 0x000A
 [OK]LDT entry 2 has AR 0x00507E00 and limit 0x000A
 [OK]LDT entry 2 has AR 0x00507C00 and limit 0x000A
 [OK]LDT entry 2 has AR 0x00507A00 and limit 0x000A
 [OK]LDT entry 2 has AR 0x00507800 and limit 0x000A
 [OK]LDT entry 2 has AR 0x00507800 and limit 0x000A
 [RUN]   Test fork
 [OK]LDT entry 2 has AR 0x00507800 and limit 0x000A
 [OK]LDT entry 1 is invalid
 [OK]Child succeeded
 [OK]modify_ldt failure 22
 [OK]modify_ldt rejected 16 bit segment
 [OK]modify_ldt rejected 16 bit segment
 [OK]modify_ldt rejected 16 bit segment
 [OK]modify_ldt rejected 16 bit segment
 [OK]modify_ldt rejected 16 bit segment
 [OK]modify_ldt rejected 16 bit segment
 [OK]LDT entry 0 is invalid
 [OK]LDT entry 0 has AR 0x0040F200 and limit 0x
 [OK]LDT entry 0 is invalid
 [RUN]   Cross-CPU LDT invalidation
 [FAIL]  5 of 5 iterations failed

That's intentional.  Old modify_ldt can leave other threads with stale
cached descriptors, which is what you're seeing.

--Andy


 Thanks,
 Willy




-- 
Andy Lutomirski
AMA Capital Management, LLC
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/