mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Andy Lutomirski <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: jpoimboe@redhat.com, jslaby@suse.cz,
	torvalds@linux-foundation.org, bp@alien8.de,
	linux-kernel@vger.kernel.org, tglx@linutronix.de,
	mingo@kernel.org, hpa@zytor.com, luto@kernel.org,
	peterz@infradead.org, brgerst@gmail.com, efault@gmx.de,
	dvlasenk@redhat.com
Subject: [tip:x86/asm] x86/entry/64: Initialize the top of the IRQ stack before switching stacks
Date: Tue, 18 Jul 2017 03:41:21 -0700	[thread overview]
Message-ID: <tip-2995590964da93e1fd9a91550f9c9d9fab28f160@git.kernel.org> (raw)
In-Reply-To: <aae7e79e49914808440ad5310ace138ced2179ca.1499786555.git.jpoimboe@redhat.com>

Commit-ID:  2995590964da93e1fd9a91550f9c9d9fab28f160
Gitweb:     http://git.kernel.org/tip/2995590964da93e1fd9a91550f9c9d9fab28f160
Author:     Andy Lutomirski <luto@kernel.org>
AuthorDate: Tue, 11 Jul 2017 10:33:39 -0500
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 18 Jul 2017 10:56:23 +0200

x86/entry/64: Initialize the top of the IRQ stack before switching stacks

The OOPS unwinder wants the word at the top of the IRQ stack to
point back to the previous stack at all times when the IRQ stack
is in use.  There's currently a one-instruction window in ENTER_IRQ_STACK
during which this isn't the case.  Fix it by writing the old RSP to the
top of the IRQ stack before jumping.

This currently writes the pointer to the stack twice, which is a bit
ugly.  We could get rid of this by replacing irq_stack_ptr with
irq_stack_ptr_minus_eight (better name welcome).  OTOH, there may be
all kinds of odd microarchitectural considerations in play that
affect performance by a few cycles here.

Reported-by: Mike Galbraith <efault@gmx.de>
Reported-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
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: Jiri Slaby <jslaby@suse.cz>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: live-patching@vger.kernel.org
Link: http://lkml.kernel.org/r/aae7e79e49914808440ad5310ace138ced2179ca.1499786555.git.jpoimboe@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/entry/entry_64.S | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index 0d4483a..b56f7f2 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -469,6 +469,7 @@ END(irq_entries_start)
 	DEBUG_ENTRY_ASSERT_IRQS_OFF
 	movq	%rsp, \old_rsp
 	incl	PER_CPU_VAR(irq_count)
+	jnz	.Lirq_stack_push_old_rsp_\@
 
 	/*
 	 * Right now, if we just incremented irq_count to zero, we've
@@ -478,9 +479,30 @@ END(irq_entries_start)
 	 * it must be *extremely* careful to limit its stack usage.  This
 	 * could include kprobes and a hypothetical future IST-less #DB
 	 * handler.
+	 *
+	 * The OOPS unwinder relies on the word at the top of the IRQ
+	 * stack linking back to the previous RSP for the entire time we're
+	 * on the IRQ stack.  For this to work reliably, we need to write
+	 * it before we actually move ourselves to the IRQ stack.
+	 */
+
+	movq	\old_rsp, PER_CPU_VAR(irq_stack_union + IRQ_STACK_SIZE - 8)
+	movq	PER_CPU_VAR(irq_stack_ptr), %rsp
+
+#ifdef CONFIG_DEBUG_ENTRY
+	/*
+	 * If the first movq above becomes wrong due to IRQ stack layout
+	 * changes, the only way we'll notice is if we try to unwind right
+	 * here.  Assert that we set up the stack right to catch this type
+	 * of bug quickly.
 	 */
+	cmpq	-8(%rsp), \old_rsp
+	je	.Lirq_stack_okay\@
+	ud2
+	.Lirq_stack_okay\@:
+#endif
 
-	cmovzq	PER_CPU_VAR(irq_stack_ptr), %rsp
+.Lirq_stack_push_old_rsp_\@:
 	pushq	\old_rsp
 .endm
 

  reply	other threads:[~2017-07-18 10:47 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-11 15:33 [PATCH v3 00/10] x86: ORC unwinder (previously undwarf) Josh Poimboeuf
2017-07-11 15:33 ` [PATCH v3 01/10] x86/entry/64: Refactor IRQ stacks and make them NMI-safe Josh Poimboeuf
2017-07-18 10:40   ` [tip:x86/asm] " tip-bot for Andy Lutomirski
2017-07-11 15:33 ` [PATCH v3 02/10] x86/entry/64: Initialize the top of the IRQ stack before switching stacks Josh Poimboeuf
2017-07-18 10:41   ` tip-bot for Andy Lutomirski [this message]
2017-07-11 15:33 ` [PATCH v3 03/10] x86/dumpstack: fix occasionally missing registers Josh Poimboeuf
2017-07-18 10:41   ` [tip:x86/asm] x86/dumpstack: Fix " tip-bot for Josh Poimboeuf
2017-07-11 15:33 ` [PATCH v3 04/10] x86/dumpstack: fix interrupt and exception stack boundary checks Josh Poimboeuf
2017-07-18 10:42   ` [tip:x86/asm] x86/dumpstack: Fix " tip-bot for Josh Poimboeuf
2017-07-11 15:33 ` [PATCH v3 05/10] objtool: add ORC unwind table generation Josh Poimboeuf
2017-07-18 10:42   ` [tip:x86/asm] objtool: Add " tip-bot for Josh Poimboeuf
2017-07-11 15:33 ` [PATCH v3 06/10] objtool, x86: add facility for asm code to provide unwind hints Josh Poimboeuf
2017-07-18 10:43   ` [tip:x86/asm] objtool, x86: Add " tip-bot for Josh Poimboeuf
2017-07-11 15:33 ` [PATCH v3 07/10] x86/entry/64: add unwind hint annotations Josh Poimboeuf
2017-07-18 10:43   ` [tip:x86/asm] x86/entry/64: Add " tip-bot for Josh Poimboeuf
2017-07-11 15:33 ` [PATCH v3 08/10] x86/asm: add unwind hint annotations to sync_core() Josh Poimboeuf
2017-07-18 10:43   ` [tip:x86/asm] x86/asm: Add " tip-bot for Josh Poimboeuf
2017-07-11 15:33 ` [PATCH v3 09/10] x86/unwind: add ORC unwinder Josh Poimboeuf
2017-07-14 17:22   ` [PATCH v3.1 " Josh Poimboeuf
2017-07-20  7:12     ` Jiri Slaby
2017-07-20 21:16       ` Josh Poimboeuf
2017-07-11 15:33 ` [PATCH v3 10/10] x86/kconfig: make it easier to switch to the new " Josh Poimboeuf
2017-07-12  8:27 ` [PATCH v3 00/10] x86: ORC unwinder (previously undwarf) Ingo Molnar
2017-07-12 14:42   ` Josh Poimboeuf
2017-07-12 19:27     ` Ingo Molnar
2017-07-14 17:17       ` Josh Poimboeuf
2017-07-25  9:09         ` Ingo Molnar
2017-07-25 17:58           ` Josh Poimboeuf
2017-07-25 18:46             ` Kees Cook
2017-07-12 21:49 ` Andres Freund
2017-07-12 22:32   ` Josh Poimboeuf
2017-07-12 22:36     ` Andres Freund
2017-07-12 22:40       ` Josh Poimboeuf
2017-07-12 22:54         ` Andres Freund
2017-07-13  7:12     ` Peter Zijlstra
2017-07-13  8:50       ` Peter Zijlstra
2017-07-13  8:51         ` Peter Zijlstra
2017-07-13  9:19           ` Ingo Molnar
2017-07-13 12:17             ` Josh Poimboeuf
2017-07-13 12:21               ` Josh Poimboeuf
2017-07-13 12:35                 ` Josh Poimboeuf
2017-07-14  8:33                   ` Ingo Molnar
2017-07-14  8:29               ` Ingo Molnar
2017-07-25 11:55             ` [RFC] perf: Delayed userspace unwind (Was: [PATCH v3 00/10] x86: ORC unwinder) Peter Zijlstra
2017-07-28 14:13               ` Jiri Olsa
2017-07-28 14:21                 ` Peter Zijlstra
2017-07-29  3:35               ` Andy Lutomirski
2017-07-29  9:28                 ` Peter Zijlstra
2017-07-12 22:30 ` [PATCH v3 00/10] x86: ORC unwinder (previously undwarf) Andi Kleen
2017-07-12 22:47   ` Josh Poimboeuf
2017-07-13  4:29     ` Andi Kleen
2017-07-13 13:15       ` Josh Poimboeuf
2017-07-13  9:29     ` Ingo Molnar
2017-07-12 23:22   ` Andy Lutomirski
2017-07-13  3:03   ` Mike Galbraith
2017-07-13  4:15     ` Andi Kleen
2017-07-13  4:28       ` Mike Galbraith
2017-07-13  4:40         ` Andi Kleen
2017-07-13  5:22           ` Mike Galbraith
2017-07-13 12:02           ` Jiri Kosina

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=tip-2995590964da93e1fd9a91550f9c9d9fab28f160@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dvlasenk@redhat.com \
    --cc=efault@gmx.de \
    --cc=hpa@zytor.com \
    --cc=jpoimboe@redhat.com \
    --cc=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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

Powered by JetHome