From: Salman Qazi <sqazi@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@linux.intel.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] x86: Don't clobber top of pt_regs in nested NMI
Date: Tue, 18 Sep 2012 18:29:35 -0700 [thread overview]
Message-ID: <20120919012935.23551.12099.stgit@dungbeetle.mtv.corp.google.com> (raw)
The nested NMI modifies the place (instruction, flags and stack)
that the first NMI will iret to. However, the copy of registers
modified is exactly the one that is the part of pt_regs in
the first NMI. This can change the behaviour of the first NMI.
In particular, Google's arch_trigger_all_cpu_backtrace handler
also prints regions of memory surrounding addresses appearing in
registers. This results in handled exceptions, after which nested NMIs
start coming in. These nested NMIs change the value of registers
in pt_regs. This can cause the original NMI handler to produce
incorrect output.
We solve this problem by introducing an extra copy of the iret
registers that are exclusively a part of pt_regs and are not modified
elsewhere. The downside is that the do_nmi function can no longer
change the control flow, as any values it writes to these five
registers will be discarded.
Signed-off-by: Salman Qazi <sqazi@google.com>
---
arch/x86/kernel/entry_64.S | 20 +++++++++++++++++++-
1 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 69babd8..40ddb6d 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -1724,6 +1724,18 @@ repeat_nmi:
end_repeat_nmi:
/*
+ * We went a running NMI handling routine to have a consistent
+ * picture of register state. This should hold true even if
+ * there is a nested NMI. Therefore, we let the nested NMI
+ * play with the previous copy of these registers and leave this
+ * new copy unmodified for do_nmi()
+ */
+ .rept 5
+ pushq_cfi 4*8(%rsp)
+ .endr
+ CFI_DEF_CFA_OFFSET SS+8-RIP
+
+ /*
* Everything below this point can be preempted by a nested
* NMI if the first NMI took an exception and reset our iret stack
* so that we repeat another NMI.
@@ -1771,7 +1783,13 @@ nmi_swapgs:
nmi_restore:
RESTORE_ALL 8
/* Clear the NMI executing stack variable */
- movq $0, 10*8(%rsp)
+ movq $0, 15*8(%rsp)
+
+ /* Pop the extra copy of iret context that was saved above
+ * just for do_nmi()
+ */
+ addq $5*8, %rsp
+
jmp irq_return
CFI_ENDPROC
END(nmi)
next reply other threads:[~2012-09-19 1:29 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-19 1:29 Salman Qazi [this message]
2012-09-24 13:27 ` Steven Rostedt
2012-09-24 16:55 ` Salman Qazi
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=20120919012935.23551.12099.stgit@dungbeetle.mtv.corp.google.com \
--to=sqazi@google.com \
--cc=hpa@linux.intel.com \
--cc=linux-kernel@vger.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
all inboxes | Powered by JetHome®