From: Andy Lutomirski <luto@kernel.org>
To: x86@kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
KVM list <kvm@vger.kernel.org>,
Arjan van de Ven <arjan@linux.intel.com>,
xen-devel <Xen-devel@lists.xen.org>,
linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Ingo Molnar <mingo@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Andy Lutomirski <luto@kernel.org>
Subject: [PATCH 1/2] x86/msr: Carry on after a non-"safe" MSR access fails without !panic_on_oops
Date: Thu, 17 Sep 2015 14:11:01 -0700 [thread overview]
Message-ID: <203bb8a52efae1781281fb70ccd45c3e164fbce2.1442523997.git.luto@kernel.org> (raw)
In-Reply-To: <cover.1442523997.git.luto@kernel.org>
In-Reply-To: <cover.1442523997.git.luto@kernel.org>
This demotes an OOPS and likely panic due to a failed non-"safe" MSR
access to a WARN_ON_ONCE and a return of poisoned values (in the
RDMSR case). We still write a pr_info entry unconditionally for
debugging.
To be clear, this type of failure should *not* happen. This patch
exists to minimize the chance of nasty undebuggable failures due on
systems that used to work due to a now-fixed CONFIG_PARAVIRT=y bug.
Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
arch/x86/kernel/traps.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 346eec73f7db..b7731765017a 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -437,6 +437,54 @@ exit_trap:
do_trap(X86_TRAP_BR, SIGSEGV, "bounds", regs, error_code, NULL);
}
+static bool paper_over_kernel_gpf(struct pt_regs *regs)
+{
+ /*
+ * Try to decode the opcode that failed. So far, we only care
+ * about boring two-byte unprefixed opcodes, so we don't need
+ * the full instruction decoder machinery.
+ */
+ u16 opcode;
+
+ if (probe_kernel_read(&opcode, (const void *)regs->ip, sizeof(opcode)))
+ return false;
+
+ if (opcode == 0x320f) {
+ /* RDMSR */
+ pr_info("bad kernel RDMSR from non-existent MSR 0x%x",
+ (unsigned int)regs->cx);
+ if (!panic_on_oops) {
+ WARN_ON_ONCE(true);
+
+ /* Patch it up with deterministic poison. */
+ regs->ax = 0x5aadc0de;
+ regs->dx = 0x8badf00d;
+ regs->ip += 2;
+ return true;
+ } else {
+ /* Don't fix it up. */
+ return false;
+ }
+ } else if (opcode == 0x300f) {
+ /* WRMSR */
+ pr_info("bad kernel WRMSR writing 0x%08x%08x to MSR 0x%x",
+ (unsigned int)regs->dx, (unsigned int)regs->ax,
+ (unsigned int)regs->cx);
+ if (!panic_on_oops) {
+ WARN_ON_ONCE(true);
+
+ /* Pretend it worked and carry on. */
+ regs->ip += 2;
+ return true;
+ } else {
+ /* Don't fix it up. */
+ return false;
+ }
+ }
+
+ return false;
+}
+
dotraplinkage void
do_general_protection(struct pt_regs *regs, long error_code)
{
@@ -456,6 +504,9 @@ do_general_protection(struct pt_regs *regs, long error_code)
if (fixup_exception(regs))
return;
+ if (paper_over_kernel_gpf(regs))
+ return;
+
tsk->thread.error_code = error_code;
tsk->thread.trap_nr = X86_TRAP_GP;
if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
--
2.4.3
next prev parent reply other threads:[~2015-09-17 21:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-17 21:11 [PATCH 0/2] x86/msr: MSR access failure changes Andy Lutomirski
2015-09-17 21:11 ` Andy Lutomirski [this message]
2015-09-18 7:14 ` [PATCH 1/2] x86/msr: Carry on after a non-"safe" MSR access fails without !panic_on_oops Ingo Molnar
2015-09-17 21:11 ` [PATCH 2/2] x86/msr: Set the return value to zero when native_rdmsr_safe fails 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=203bb8a52efae1781281fb70ccd45c3e164fbce2.1442523997.git.luto@kernel.org \
--to=luto@kernel.org \
--cc=Xen-devel@lists.xen.org \
--cc=akpm@linux-foundation.org \
--cc=arjan@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--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
all inboxes | Powered by JetHome®