linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Vince Weaver <vincent.weaver@maine.edu>
Cc: "H. Peter Anvin" <hpa@zytor.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Linux Kernel <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@redhat.com>
Subject: Re: perf_fuzzer compiled for x32 causes reboot
Date: Thu, 27 Feb 2014 21:57:26 -0500	[thread overview]
Message-ID: <20140227215726.7018c861@gandalf.local.home> (raw)
In-Reply-To: <alpine.DEB.2.10.1402272032140.6271@vincent-weaver-1.um.maine.edu>

On Thu, 27 Feb 2014 20:34:34 -0500 (EST)
Vince Weaver <vincent.weaver@maine.edu> wrote:


> > I would actually suggest we do the equivalent on i386 as well.
> > 
> > Vince, could you try this patch as an experiment?
> 
> OK with your patch applied it does not segfault.
> 

Vince, Great! Can you remove Peter's patch, and try this one. It
removes the crud to save the cr2 from entry_64.S and makes both i386
and x86_64 do the same thing in regards to cr2 handling.

-- Steve

diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index 1e96c36..937cb8d 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -1854,29 +1854,11 @@ end_repeat_nmi:
 	call save_paranoid
 	DEFAULT_FRAME 0
 
-	/*
-	 * Save off the CR2 register. If we take a page fault in the NMI then
-	 * it could corrupt the CR2 value. If the NMI preempts a page fault
-	 * handler before it was able to read the CR2 register, and then the
-	 * NMI itself takes a page fault, the page fault that was preempted
-	 * will read the information from the NMI page fault and not the
-	 * origin fault. Save it off and restore it if it changes.
-	 * Use the r12 callee-saved register.
-	 */
-	movq %cr2, %r12
-
 	/* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
 	movq %rsp,%rdi
 	movq $-1,%rsi
 	call do_nmi
 
-	/* Did the NMI take a page fault? Restore cr2 if it did */
-	movq %cr2, %rcx
-	cmpq %rcx, %r12
-	je 1f
-	movq %r12, %cr2
-1:
-	
 	testl %ebx,%ebx				/* swapgs needed? */
 	jnz nmi_restore
 nmi_swapgs:
diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
index 6fcb49c..f1a6294 100644
--- a/arch/x86/kernel/nmi.c
+++ b/arch/x86/kernel/nmi.c
@@ -443,7 +443,6 @@ enum nmi_states {
 	NMI_LATCHED,
 };
 static DEFINE_PER_CPU(enum nmi_states, nmi_state);
-static DEFINE_PER_CPU(unsigned long, nmi_cr2);
 
 #define nmi_nesting_preprocess(regs)					\
 	do {								\
@@ -452,14 +451,11 @@ static DEFINE_PER_CPU(unsigned long, nmi_cr2);
 			return;						\
 		}							\
 		this_cpu_write(nmi_state, NMI_EXECUTING);		\
-		this_cpu_write(nmi_cr2, read_cr2());			\
 	} while (0);							\
 	nmi_restart:
 
 #define nmi_nesting_postprocess()					\
 	do {								\
-		if (unlikely(this_cpu_read(nmi_cr2) != read_cr2()))	\
-			write_cr2(this_cpu_read(nmi_cr2));		\
 		if (this_cpu_dec_return(nmi_state))			\
 			goto nmi_restart;				\
 	} while (0)
@@ -512,8 +508,21 @@ static inline void nmi_nesting_postprocess(void)
 dotraplinkage notrace __kprobes void
 do_nmi(struct pt_regs *regs, long error_code)
 {
+	unsigned long cr2;
+	
 	nmi_nesting_preprocess(regs);
 
+	/*
+	 * Save off the CR2 register. If we take a page fault in the NMI then
+	 * it could corrupt the CR2 value. If the NMI preempts a page fault
+	 * handler before it was able to read the CR2 register, and then the
+	 * NMI itself takes a page fault, the page fault that was preempted
+	 * will read the information from the NMI page fault and not the
+	 * origin fault. Save it off and restore it if it changes.
+	 * Use the r12 callee-saved register.
+	 */
+	cr2 = read_cr2();
+
 	nmi_enter();
 
 	inc_irq_stat(__nmi_count);
@@ -523,6 +532,10 @@ do_nmi(struct pt_regs *regs, long error_code)
 
 	nmi_exit();
 
+	/* Reads are cheaper than writes */
+	if (unlikely(cr2 != read_cr2()))
+		write_cr2(cr2);
+
 	/* On i386, may loop back to preprocess */
 	nmi_nesting_postprocess();
 }

  parent reply	other threads:[~2014-02-28  2:57 UTC|newest]

Thread overview: 115+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-21 20:25 perf_fuzzer causes reboot Vince Weaver
2014-02-21 22:13 ` perf_fuzzer compiled for x32 " Vince Weaver
2014-02-21 22:34   ` Vince Weaver
2014-02-22  4:50     ` Vince Weaver
2014-02-22  5:03       ` H. Peter Anvin
2014-02-22  6:26       ` H. Peter Anvin
2014-02-23  5:18         ` Vince Weaver
2014-02-23  5:24           ` H. Peter Anvin
2014-02-23  6:07           ` H. Peter Anvin
2014-02-23 14:05             ` Vince Weaver
2014-02-24  3:02               ` Vince Weaver
2014-02-24  5:22                 ` H. Peter Anvin
2014-02-24 15:35                   ` Vince Weaver
2014-02-24 16:34                     ` Vince Weaver
2014-02-24 16:47                       ` H. Peter Anvin
2014-02-24 17:10                         ` Vince Weaver
2014-02-24 17:25                           ` Peter Zijlstra
2014-02-24 17:32                             ` Vince Weaver
2014-02-24 17:40                               ` H. Peter Anvin
2014-02-24 18:00                                 ` Vince Weaver
2014-02-24 18:07                                   ` Vince Weaver
2014-02-24 18:34                                     ` H. Peter Anvin
2014-02-24 19:13                                       ` Steven Rostedt
2014-02-24 19:15                                         ` H. Peter Anvin
2014-02-24 19:30                                         ` Peter Zijlstra
2014-02-24 19:32                                           ` Steven Rostedt
2014-02-25  3:49                                           ` H. Peter Anvin
2014-02-25 14:07                                             ` Vince Weaver
2014-02-25 14:34                                               ` H. Peter Anvin
2014-02-25 14:43                                                 ` Steven Rostedt
2014-02-25 15:33                                                   ` Vince Weaver
2014-02-26 15:06                                                     ` Vince Weaver
2014-02-27 22:06                                                       ` Vince Weaver
2014-02-27 22:31                                                         ` Steven Rostedt
2014-02-27 22:52                                                           ` H. Peter Anvin
2014-02-27 23:30                                                             ` Steven Rostedt
2014-02-27 23:46                                                               ` H. Peter Anvin
2014-02-28  1:00                                                                 ` Vince Weaver
2014-02-28 20:34                                                                   ` Paul E. McKenney
2014-02-28 20:47                                                                     ` Steven Rostedt
2014-02-28 20:54                                                                       ` Peter Zijlstra
2014-02-28 21:17                                                                         ` Paul E. McKenney
2014-02-28 21:27                                                                           ` Peter Zijlstra
2014-02-28 21:51                                                                             ` Paul E. McKenney
2014-02-28 21:55                                                                               ` Peter Zijlstra
2014-02-28 22:05                                                                                 ` Steven Rostedt
2014-02-28 22:23                                                                                   ` Paul E. McKenney
2014-02-28  1:34                                                             ` Vince Weaver
2014-02-28  2:17                                                               ` H. Peter Anvin
2014-02-28  2:57                                                               ` Steven Rostedt [this message]
2014-02-28 11:11                                                                 ` Peter Zijlstra
2014-02-28 13:37                                                                   ` Steven Rostedt
2014-02-28 14:15                                                                 ` Vince Weaver
2014-02-28 14:23                                                                   ` Steven Rostedt
2014-02-28 15:07                                                                     ` Vince Weaver
2014-02-28 15:13                                                                       ` H. Peter Anvin
2014-02-28 15:40                                                                         ` Peter Zijlstra
2014-02-28 16:15                                                                           ` H. Peter Anvin
2014-02-28 16:29                                                                             ` Steven Rostedt
2014-02-28 19:33                                                                               ` [PATCH] x86: Rename copy_from_user_nmi() to copy_from_user_trace() Steven Rostedt
2014-02-28 20:46                                                                                 ` Peter Zijlstra
2014-02-28 20:51                                                                                   ` Steven Rostedt
2014-02-28 20:58                                                                                     ` Peter Zijlstra
2014-02-28 21:01                                                                                   ` Steven Rostedt
2014-02-28 21:17                                                                                     ` Peter Zijlstra
2014-02-28 20:56                                                                               ` perf_fuzzer compiled for x32 causes reboot Peter Zijlstra
2014-02-28 21:06                                                                                 ` Steven Rostedt
2014-03-01  9:16                                                                                   ` Ingo Molnar
2014-03-01  9:50                                                                                     ` Borislav Petkov
2014-03-01 16:50                                                                                       ` H. Peter Anvin
2014-03-04 23:05                                                                                         ` Borislav Petkov
2014-03-03  9:16                                                                                     ` Peter Zijlstra
2014-02-28 20:55                                                                             ` Peter Zijlstra
2014-02-28 15:20                                                                       ` Steven Rostedt
2014-02-28 15:30                                                                         ` Steven Rostedt
2014-02-28 20:38                                                                       ` H. Peter Anvin
2014-02-28 20:46                                                                         ` Steven Rostedt
2014-02-28 21:18                                                                         ` Vince Weaver
2014-02-28 21:30                                                                           ` Steven Rostedt
2014-02-28 23:34                                                                             ` Vince Weaver
2014-03-01  0:43                                                                               ` H. Peter Anvin
2014-03-01  3:36                                                                               ` Steven Rostedt
2014-03-01 16:24                                                                                 ` Andi Kleen
2014-03-02 15:34                                                                                   ` Vince Weaver
2014-03-02 16:02                                                                                 ` Vince Weaver
2014-02-28  9:39                                                           ` Peter Zijlstra
2014-02-24 17:40                               ` Peter Zijlstra
2014-02-24 17:41                               ` Vince Weaver
2014-02-24 17:42                                 ` H. Peter Anvin
2014-02-24 17:52                             ` H. Peter Anvin
2014-02-28 15:33 [PATCH] x86 trace: Fix page fault tracing bug Jiri Olsa
2014-02-28 15:47 ` Peter Zijlstra
2014-02-28 16:05   ` [PATCHv2] " Jiri Olsa
2014-02-28 16:11     ` H. Peter Anvin
2014-02-28 16:23       ` Steven Rostedt
2014-02-28 16:15     ` Steven Rostedt
2014-03-05  0:03     ` [tip:x86/urgent] x86, trace: Fix CR2 corruption when tracing page faults tip-bot for Jiri Olsa
2014-03-05 11:14       ` Peter Zijlstra
2014-03-05 12:20         ` Steven Rostedt
2014-03-05 12:25           ` Peter Zijlstra
2014-03-05 12:33             ` Steven Rostedt
2014-03-05 12:54               ` Peter Zijlstra
2014-03-05 13:02                 ` Peter Zijlstra
2014-03-05 13:07                   ` Peter Zijlstra
2014-03-05 12:36             ` Peter Zijlstra
2014-03-05 13:00               ` Steven Rostedt
2014-03-05 13:08                 ` Peter Zijlstra
2014-03-05 21:37                   ` H. Peter Anvin
2014-03-06  8:40                     ` Peter Zijlstra
2014-03-06 11:02                       ` Steven Rostedt
2014-03-06 14:53                         ` [PATCH] x86: Further robustify CR2 handling vs tracing Peter Zijlstra
2014-03-07 23:07                           ` [tip:x86/urgent] x86, trace: " tip-bot for Peter Zijlstra
2014-02-28 15:47 ` [PATCH] x86 trace: Fix page fault tracing bug Jiri Olsa
2014-02-28 16:00   ` Steven Rostedt
2014-02-28 16:01 ` Steven Rostedt

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=20140227215726.7018c861@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=vincent.weaver@maine.edu \
    /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;
as well as URLs for NNTP newsgroup(s).