All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@kernel.org>
To: x86@kernel.org
Cc: Borislav Petkov <bp@alien8.de>,
	linux-kernel@vger.kernel.org,
	Rusty Russell <rusty@rustcorp.com.au>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Rik van Riel <riel@redhat.com>, kvm list <kvm@vger.kernel.org>,
	Andy Lutomirski <luto@kernel.org>
Subject: [PATCH 6/8] x86/fpu: #NM without FPU emulation is an error
Date: Mon, 31 Oct 2016 15:18:47 -0700	[thread overview]
Message-ID: <f1ee6bf73ed1025fccaab321ba43d0594245f927.1477951965.git.luto@kernel.org> (raw)
In-Reply-To: <cover.1477951965.git.luto@kernel.org>
In-Reply-To: <cover.1477951965.git.luto@kernel.org>

don't use CR0.TS.  Make it an error rather than making nonsensical
changes to the FPU state.

(The cond_local_irq_enable() appears to have been pointless, too.)

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 arch/x86/kernel/traps.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index bd4e3d4d3625..bf0c6d049080 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -853,6 +853,8 @@ do_spurious_interrupt_bug(struct pt_regs *regs, long error_code)
 dotraplinkage void
 do_device_not_available(struct pt_regs *regs, long error_code)
 {
+	unsigned long cr0;
+
 	RCU_LOCKDEP_WARN(!rcu_is_watching(), "entry code didn't wake RCU");
 
 #ifdef CONFIG_MATH_EMULATION
@@ -866,10 +868,20 @@ do_device_not_available(struct pt_regs *regs, long error_code)
 		return;
 	}
 #endif
-	fpu__restore(&current->thread.fpu); /* interrupts still off */
-#ifdef CONFIG_X86_32
-	cond_local_irq_enable(regs);
-#endif
+
+	/* This should not happen. */
+	cr0 = read_cr0();
+	if (WARN(cr0 & X86_CR0_TS, "CR0.TS was set")) {
+		/* Try to fix it up and carry on. */
+		write_cr0(cr0 & ~X86_CR0_TS);
+	} else {
+		/*
+		 * Something terrible happened, and we're better off trying
+		 * to kill the task than getting stuck in a never-ending
+		 * loop of #NM faults.
+		 */
+		die("unexpected #NM exception", regs, error_code);
+	}
 }
 NOKPROBE_SYMBOL(do_device_not_available);
 
-- 
2.7.4

  parent reply	other threads:[~2016-10-31 22:19 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-31 22:18 [PATCH 0/8] x86/fpu: Remove CR0.TS support Andy Lutomirski
2016-10-31 22:18 ` [PATCH 1/8] fpu/init: Get rid of two redundant clts() calls Andy Lutomirski
2016-11-01  7:13   ` [tip:x86/fpu] x86/fpu: " tip-bot for Andy Lutomirski
2016-10-31 22:18 ` [PATCH 2/8] fpu/bugs: Stop saving and restoring CR0.TS in fpu__init_check_bugs() Andy Lutomirski
2016-11-01  7:14   ` [tip:x86/fpu] x86/fpu: " tip-bot for Andy Lutomirski
2016-10-31 22:18 ` [PATCH 3/8] x86/fpu: Remove irq_ts_save() and irq_ts_restore() Andy Lutomirski
2016-11-01  7:14   ` [tip:x86/fpu] " tip-bot for Andy Lutomirski
2016-10-31 22:18 ` [PATCH 4/8] x86/kvm: Remove host CR0.TS manipulation Andy Lutomirski
2016-11-01  7:15   ` [tip:x86/fpu] x86/fpu, kvm: " tip-bot for Andy Lutomirski
2016-10-31 22:18 ` [PATCH 5/8] lguest: Remove CR0.TS support Andy Lutomirski
2016-11-01  7:15   ` [tip:x86/fpu] x86/fpu, " tip-bot for Andy Lutomirski
2016-10-31 22:18 ` Andy Lutomirski [this message]
2016-11-01  7:16   ` [tip:x86/fpu] x86/fpu: Handle #NM without FPU emulation as an error tip-bot for Andy Lutomirski
2016-10-31 22:18 ` [PATCH 7/8] x86/fpu: Remove stts() Andy Lutomirski
2016-11-01  7:16   ` [tip:x86/fpu] " tip-bot for Andy Lutomirski
2016-10-31 22:18 ` [PATCH 8/8] x86/fpu: Remove clts() Andy Lutomirski
2016-11-01  7:17   ` [tip:x86/fpu] " tip-bot for Andy Lutomirski
2016-10-31 22:41 ` [PATCH 0/8] x86/fpu: Remove CR0.TS support Paul Bolle
2016-10-31 23:04   ` Borislav Petkov
2016-10-31 23:10     ` Paul Bolle
2016-10-31 23:48       ` Borislav Petkov
2016-11-01  7:51         ` Paul Bolle
2016-11-01  8:50           ` Borislav Petkov

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=f1ee6bf73ed1025fccaab321ba43d0594245f927.1477951965.git.luto@kernel.org \
    --to=luto@kernel.org \
    --cc=bp@alien8.de \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=riel@redhat.com \
    --cc=rusty@rustcorp.com.au \
    --cc=x86@kernel.org \
    --subject='Re: [PATCH 6/8] x86/fpu: #NM without FPU emulation is an error' \
    /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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.