Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1482013 > unrolled thread

[PATCH 0/2] x86/64: espfix64 cleanups and testing

Started byAndy Lutomirski <luto@kernel.org>
First post2016-09-13 00:10 +0200
Last post2016-09-13 11:10 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 0/2] x86/64: espfix64 cleanups and testing Andy Lutomirski <luto@kernel.org> - 2016-09-13 00:10 +0200
    [PATCH 1/2] selftests/x86/sigreturn: Use CX, not AX, as the scratch register Andy Lutomirski <luto@kernel.org> - 2016-09-13 00:10 +0200
      [tip:x86/asm] selftests/x86/sigreturn: Use CX, not AX, as the  scratch register tip-bot for Andy Lutomirski <tipbot@zytor.com> - 2016-09-14 00:10 +0200
    Re: [PATCH 0/2] x86/64: espfix64 cleanups and testing Borislav Petkov <bp@alien8.de> - 2016-09-13 11:10 +0200

#1482013 — [PATCH 0/2] x86/64: espfix64 cleanups and testing

FromAndy Lutomirski <luto@kernel.org>
Date2016-09-13 00:10 +0200
Subject[PATCH 0/2] x86/64: espfix64 cleanups and testing
Message-ID<sgHAl-172-3@gated-at.bofh.it>
This tidies up ESPFIX a bit and improves the test case slightly.

Andy Lutomirski (2):
  selftests/x86/sigreturn: Use CX, not AX, as the scratch register
  x86/entry/64: Clean up and document espfix64 stack setup

 arch/x86/entry/entry_64.S               | 64 +++++++++++++++++++++++++++------
 tools/testing/selftests/x86/sigreturn.c | 16 ++++-----
 2 files changed, 61 insertions(+), 19 deletions(-)

-- 
2.7.4

[toc] | [next] | [standalone]


#1482020 — [PATCH 1/2] selftests/x86/sigreturn: Use CX, not AX, as the scratch register

FromAndy Lutomirski <luto@kernel.org>
Date2016-09-13 00:10 +0200
Subject[PATCH 1/2] selftests/x86/sigreturn: Use CX, not AX, as the scratch register
Message-ID<sgHAl-172-21@gated-at.bofh.it>
In reply to#1482013
RAX is handled specially in ESPFIX64.  Use CX as our scratch
register so that, if something goes wrong with RAX handling, we'll
notice.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 tools/testing/selftests/x86/sigreturn.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/x86/sigreturn.c b/tools/testing/selftests/x86/sigreturn.c
index 8a577e7070c6..246145b84a12 100644
--- a/tools/testing/selftests/x86/sigreturn.c
+++ b/tools/testing/selftests/x86/sigreturn.c
@@ -106,7 +106,7 @@ asm (".pushsection .text\n\t"
      ".type int3, @function\n\t"
      ".align 4096\n\t"
      "int3:\n\t"
-     "mov %ss,%eax\n\t"
+     "mov %ss,%ecx\n\t"
      "int3\n\t"
      ".size int3, . - int3\n\t"
      ".align 4096, 0xcc\n\t"
@@ -306,7 +306,7 @@ static volatile sig_atomic_t sig_corrupt_final_ss;
 #ifdef __x86_64__
 # define REG_IP REG_RIP
 # define REG_SP REG_RSP
-# define REG_AX REG_RAX
+# define REG_CX REG_RCX
 
 struct selectors {
 	unsigned short cs, gs, fs, ss;
@@ -326,7 +326,7 @@ static unsigned short *csptr(ucontext_t *ctx)
 #else
 # define REG_IP REG_EIP
 # define REG_SP REG_ESP
-# define REG_AX REG_EAX
+# define REG_CX REG_ECX
 
 static greg_t *ssptr(ucontext_t *ctx)
 {
@@ -457,10 +457,10 @@ static void sigusr1(int sig, siginfo_t *info, void *ctx_void)
 	ctx->uc_mcontext.gregs[REG_IP] =
 		sig_cs == code16_sel ? 0 : (unsigned long)&int3;
 	ctx->uc_mcontext.gregs[REG_SP] = (unsigned long)0x8badf00d5aadc0deULL;
-	ctx->uc_mcontext.gregs[REG_AX] = 0;
+	ctx->uc_mcontext.gregs[REG_CX] = 0;
 
 	memcpy(&requested_regs, &ctx->uc_mcontext.gregs, sizeof(gregset_t));
-	requested_regs[REG_AX] = *ssptr(ctx);	/* The asm code does this. */
+	requested_regs[REG_CX] = *ssptr(ctx);	/* The asm code does this. */
 
 	return;
 }
@@ -482,7 +482,7 @@ static void sigtrap(int sig, siginfo_t *info, void *ctx_void)
 	unsigned short ss;
 	asm ("mov %%ss,%0" : "=r" (ss));
 
-	greg_t asm_ss = ctx->uc_mcontext.gregs[REG_AX];
+	greg_t asm_ss = ctx->uc_mcontext.gregs[REG_CX];
 	if (asm_ss != sig_ss && sig == SIGTRAP) {
 		/* Sanity check failure. */
 		printf("[FAIL]\tSIGTRAP: ss = %hx, frame ss = %hx, ax = %llx\n",
@@ -654,8 +654,8 @@ static int test_valid_sigreturn(int cs_bits, bool use_16bit_ss, int force_ss)
 #endif
 
 		/* Sanity check on the kernel */
-		if (i == REG_AX && requested_regs[i] != resulting_regs[i]) {
-			printf("[FAIL]\tAX (saved SP) mismatch: requested 0x%llx; got 0x%llx\n",
+		if (i == REG_CX && requested_regs[i] != resulting_regs[i]) {
+			printf("[FAIL]\tCX (saved SP) mismatch: requested 0x%llx; got 0x%llx\n",
 			       (unsigned long long)requested_regs[i],
 			       (unsigned long long)resulting_regs[i]);
 			nerrs++;
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1482803 — [tip:x86/asm] selftests/x86/sigreturn: Use CX, not AX, as the scratch register

Fromtip-bot for Andy Lutomirski <tipbot@zytor.com>
Date2016-09-14 00:10 +0200
Subject[tip:x86/asm] selftests/x86/sigreturn: Use CX, not AX, as the scratch register
Message-ID<sh43T-7UT-7@gated-at.bofh.it>
In reply to#1482020
Commit-ID:  1ef0199a1a698d82ecd39d11d1daa3f4ab006c75
Gitweb:     http://git.kernel.org/tip/1ef0199a1a698d82ecd39d11d1daa3f4ab006c75
Author:     Andy Lutomirski <luto@kernel.org>
AuthorDate: Mon, 12 Sep 2016 15:05:50 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 13 Sep 2016 20:34:15 +0200

selftests/x86/sigreturn: Use CX, not AX, as the scratch register

RAX is handled specially in ESPFIX64.  Use CX as our scratch
register so that, if something goes wrong with RAX handling, we'll
notice.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
Reviewed-by: Borislav Petkov <bp@suse.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/9ceeb24ea56925586c330dc46306f757ddea9fb5.1473717910.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 tools/testing/selftests/x86/sigreturn.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/x86/sigreturn.c b/tools/testing/selftests/x86/sigreturn.c
index 8a577e7..246145b 100644
--- a/tools/testing/selftests/x86/sigreturn.c
+++ b/tools/testing/selftests/x86/sigreturn.c
@@ -106,7 +106,7 @@ asm (".pushsection .text\n\t"
      ".type int3, @function\n\t"
      ".align 4096\n\t"
      "int3:\n\t"
-     "mov %ss,%eax\n\t"
+     "mov %ss,%ecx\n\t"
      "int3\n\t"
      ".size int3, . - int3\n\t"
      ".align 4096, 0xcc\n\t"
@@ -306,7 +306,7 @@ static volatile sig_atomic_t sig_corrupt_final_ss;
 #ifdef __x86_64__
 # define REG_IP REG_RIP
 # define REG_SP REG_RSP
-# define REG_AX REG_RAX
+# define REG_CX REG_RCX
 
 struct selectors {
 	unsigned short cs, gs, fs, ss;
@@ -326,7 +326,7 @@ static unsigned short *csptr(ucontext_t *ctx)
 #else
 # define REG_IP REG_EIP
 # define REG_SP REG_ESP
-# define REG_AX REG_EAX
+# define REG_CX REG_ECX
 
 static greg_t *ssptr(ucontext_t *ctx)
 {
@@ -457,10 +457,10 @@ static void sigusr1(int sig, siginfo_t *info, void *ctx_void)
 	ctx->uc_mcontext.gregs[REG_IP] =
 		sig_cs == code16_sel ? 0 : (unsigned long)&int3;
 	ctx->uc_mcontext.gregs[REG_SP] = (unsigned long)0x8badf00d5aadc0deULL;
-	ctx->uc_mcontext.gregs[REG_AX] = 0;
+	ctx->uc_mcontext.gregs[REG_CX] = 0;
 
 	memcpy(&requested_regs, &ctx->uc_mcontext.gregs, sizeof(gregset_t));
-	requested_regs[REG_AX] = *ssptr(ctx);	/* The asm code does this. */
+	requested_regs[REG_CX] = *ssptr(ctx);	/* The asm code does this. */
 
 	return;
 }
@@ -482,7 +482,7 @@ static void sigtrap(int sig, siginfo_t *info, void *ctx_void)
 	unsigned short ss;
 	asm ("mov %%ss,%0" : "=r" (ss));
 
-	greg_t asm_ss = ctx->uc_mcontext.gregs[REG_AX];
+	greg_t asm_ss = ctx->uc_mcontext.gregs[REG_CX];
 	if (asm_ss != sig_ss && sig == SIGTRAP) {
 		/* Sanity check failure. */
 		printf("[FAIL]\tSIGTRAP: ss = %hx, frame ss = %hx, ax = %llx\n",
@@ -654,8 +654,8 @@ static int test_valid_sigreturn(int cs_bits, bool use_16bit_ss, int force_ss)
 #endif
 
 		/* Sanity check on the kernel */
-		if (i == REG_AX && requested_regs[i] != resulting_regs[i]) {
-			printf("[FAIL]\tAX (saved SP) mismatch: requested 0x%llx; got 0x%llx\n",
+		if (i == REG_CX && requested_regs[i] != resulting_regs[i]) {
+			printf("[FAIL]\tCX (saved SP) mismatch: requested 0x%llx; got 0x%llx\n",
 			       (unsigned long long)requested_regs[i],
 			       (unsigned long long)resulting_regs[i]);
 			nerrs++;

[toc] | [prev] | [next] | [standalone]


#1482285

FromBorislav Petkov <bp@alien8.de>
Date2016-09-13 11:10 +0200
Message-ID<sgRT3-8gk-7@gated-at.bofh.it>
In reply to#1482013
On Mon, Sep 12, 2016 at 03:05:49PM -0700, Andy Lutomirski wrote:
> This tidies up ESPFIX a bit and improves the test case slightly.
> 
> Andy Lutomirski (2):
>   selftests/x86/sigreturn: Use CX, not AX, as the scratch register
>   x86/entry/64: Clean up and document espfix64 stack setup
> 
>  arch/x86/entry/entry_64.S               | 64 +++++++++++++++++++++++++++------
>  tools/testing/selftests/x86/sigreturn.c | 16 ++++-----
>  2 files changed, 61 insertions(+), 19 deletions(-)

Both: Reviewed-by: Borislav Petkov <bp@suse.de>

Thanks.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web