From: Nadav Amit <namit@vmware.com>
To: Ingo Molnar <mingo@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
Willy Tarreau <w@1wt.eu>, Nadav Amit <nadav.amit@gmail.com>,
<x86@kernel.org>, <linux-kernel@vger.kernel.org>,
Nadav Amit <namit@vmware.com>
Subject: [PATCH RFC v2 6/6] selftest: x86: test using CS64 on compatibility-mode
Date: Thu, 15 Feb 2018 08:36:02 -0800 [thread overview]
Message-ID: <20180215163602.61162-7-namit@vmware.com> (raw)
In-Reply-To: <20180215163602.61162-1-namit@vmware.com>
As we mask the 64-bit code segment in compatibility-mode, and since
applications, most notably CRIU, might still use it, add a test to
ensure it does not break.
Signed-off-by: Nadav Amit <namit@vmware.com>
---
tools/testing/selftests/x86/ldt_gdt.c | 41 +++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/tools/testing/selftests/x86/ldt_gdt.c b/tools/testing/selftests/x86/ldt_gdt.c
index 1aef72df20a1..40b442e5c514 100644
--- a/tools/testing/selftests/x86/ldt_gdt.c
+++ b/tools/testing/selftests/x86/ldt_gdt.c
@@ -50,6 +50,11 @@
# define INT80_CLOBBERS "r8", "r9", "r10", "r11"
#else
# define INT80_CLOBBERS
+
+/* copied from asm/segment.h */
+#define GDT_ENTRY_DEFAULT_USER_CS 14
+#define GDT_ENTRY_DEFAULT_USER_DS 15
+
#endif
static int nerrs;
@@ -907,6 +912,40 @@ static void test_gdt_invalidation(void)
#endif
}
+struct far_jmp_addr {
+ unsigned long addr;
+ unsigned short seg;
+} __packed;
+
+static void switch_to_cs64(void)
+{
+#ifdef __i386__
+ struct far_jmp_addr far_jmp_compat, far_jmp_64;
+ unsigned short ds;
+
+ /* Poor's man detection of compatibility mode; */
+ asm volatile ("mov %%ds, %0" : [ds]"=r"(ds));
+ if (ds >> 3 != 5)
+ return;
+
+ far_jmp_64.seg = (6 << 3) | 3; /* __USER_CS */
+ far_jmp_compat.seg = (4 << 3) | 3; /* __USER32_CS */
+
+ asm volatile ("movl $.cs64_target, (%[target64])\n\t"
+ "movl $.cs32_target, (%[target32])\n\t"
+ "ljmp *%[jmp_addr_64]\n\t"
+ ".cs64_target:\n\t"
+ "ljmp *%[jmp_addr_32]\n\t"
+ ".cs32_target:\n\t" : :
+ [jmp_addr_64]"m"(far_jmp_64),
+ [jmp_addr_32]"m"(far_jmp_compat),
+ [target64]"r"(&far_jmp_64.addr),
+ [target32]"r"(&far_jmp_compat.addr) : "memory");
+
+ printf("[OK]\tSwitching to CS64 and back\n");
+#endif
+}
+
int main(int argc, char **argv)
{
if (argc == 1 && !strcmp(argv[0], "ldt_gdt_test_exec"))
@@ -923,5 +962,7 @@ int main(int argc, char **argv)
test_gdt_invalidation();
+ switch_to_cs64();
+
return nerrs ? 1 : 0;
}
--
2.14.1
next prev parent reply other threads:[~2018-02-15 16:36 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-15 16:35 [PATCH RFC v2 0/6] x86: Disabling PTI in compatibility mode Nadav Amit
2018-02-15 16:35 ` [PATCH RFC v2 1/6] x86: Skip PTI when disable indication is set Nadav Amit
2018-02-15 18:10 ` Dave Hansen
2018-02-15 19:51 ` Andy Lutomirski
2018-02-15 20:51 ` Nadav Amit
2018-02-15 23:35 ` Andy Lutomirski
2018-02-15 16:35 ` [PATCH RFC v2 2/6] x86: Save pti_disable for each mm_context Nadav Amit
2018-02-15 16:35 ` [PATCH RFC v2 3/6] x86: Switching page-table isolation Nadav Amit
2018-02-15 16:36 ` [PATCH RFC v2 4/6] x86: Disable PTI on compatibility mode Nadav Amit
2018-02-15 20:02 ` Andy Lutomirski
2018-02-15 20:58 ` Nadav Amit
2018-02-15 23:29 ` Andy Lutomirski
2018-02-16 0:08 ` Linus Torvalds
2018-02-16 0:22 ` Nadav Amit
2018-02-16 0:42 ` Linus Torvalds
2018-02-16 3:03 ` Andy Lutomirski
2018-02-16 4:55 ` Nadav Amit
2018-02-16 0:35 ` Andrew Cooper
2018-02-16 15:20 ` Andy Lutomirski
2018-02-16 7:11 ` Cyrill Gorcunov
2018-02-16 22:07 ` Dmitry Safonov
2018-02-16 22:11 ` Nadav Amit
2018-02-16 16:25 ` Dmitry Safonov
2018-02-15 16:36 ` [PATCH RFC v2 5/6] x86: Use global pages when PTI is disabled Nadav Amit
2018-02-15 16:54 ` Dave Hansen
2018-02-15 17:36 ` Nadav Amit
2018-02-15 17:47 ` Nadav Amit
2018-02-15 18:08 ` Dave Hansen
2018-02-15 19:53 ` Andy Lutomirski
2018-02-15 20:32 ` Dave Hansen
2018-02-15 20:45 ` Nadav Amit
2018-02-15 16:36 ` Nadav Amit [this message]
2018-02-16 0:21 ` [PATCH RFC v2 0/6] x86: Disabling PTI in compatibility mode Dave Hansen
2018-02-16 0:25 ` Nadav Amit
2018-02-16 0:42 ` Dave Hansen
2018-02-16 0:48 ` Nadav Amit
2018-02-16 0:45 ` Andrew Cooper
2018-02-16 0:51 ` Nadav Amit
2018-02-16 1:04 ` Andrew Cooper
2018-02-16 3:05 ` Andy Lutomirski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180215163602.61162-7-namit@vmware.com \
--to=namit@vmware.com \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=nadav.amit@gmail.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=w@1wt.eu \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox