mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [GIT PULL] x86 fixes for v3.14-rc6
@ 2014-03-07 23:25 H. Peter Anvin
  2014-03-08  3:03 ` Linus Torvalds
  0 siblings, 1 reply; 5+ messages in thread
From: H. Peter Anvin @ 2014-03-07 23:25 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: a.p.zijlstra, acme, bp, dzickus, hpa, hpa, jolsa, linux-kernel,
	matt.fleming, mingo, paulus, peterz, rja, rostedt, seiji.aguchi,
	tglx, vincent.weaver

Hi Linus,

A small collection of minor fixes.  The FPU stuff is still pending, I
fear.  I haven't heard anything from Suresh so I suspect I'm going to
have to dig into the init specifics myself and fix up the patchset.

The following changes since commit 0414855fdc4a40da05221fc6062cccbc0c30f169:

  Linux 3.14-rc5 (2014-03-02 18:56:16 -0800)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86-urgent-for-linus

for you to fetch changes up to 5fa10196bdb5f190f595ebd048490ee52dddea0f:

  x86: Ignore NMIs that come in during early boot (2014-03-07 15:08:14 -0800)

----------------------------------------------------------------
Borislav Petkov (1):
      x86/efi: Quirk out SGI UV

H. Peter Anvin (2):
      Merge tag 'efi-urgent' into x86/urgent
      x86: Ignore NMIs that come in during early boot

Jiri Olsa (1):
      x86, trace: Fix CR2 corruption when tracing page faults

Peter Zijlstra (1):
      x86, trace: Further robustify CR2 handling vs tracing

 arch/x86/include/asm/efi.h  |  1 +
 arch/x86/kernel/head_32.S   |  7 ++++++-
 arch/x86/kernel/head_64.S   |  6 +++++-
 arch/x86/kernel/setup.c     | 10 ++--------
 arch/x86/mm/fault.c         | 47 +++++++++++++++++++++++++++++++--------------
 arch/x86/platform/efi/efi.c | 20 +++++++++++++++++++
 6 files changed, 67 insertions(+), 24 deletions(-)

diff --git a/arch/x86/include/asm/efi.h b/arch/x86/include/asm/efi.h
index 3d6b9f8..acd86c8 100644
--- a/arch/x86/include/asm/efi.h
+++ b/arch/x86/include/asm/efi.h
@@ -134,6 +134,7 @@ extern void efi_setup_page_tables(void);
 extern void __init old_map_region(efi_memory_desc_t *md);
 extern void __init runtime_code_page_mkexec(void);
 extern void __init efi_runtime_mkexec(void);
+extern void __init efi_apply_memmap_quirks(void);
 
 struct efi_setup_data {
 	u64 fw_vendor;
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 81ba276..d2a2159 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -544,6 +544,10 @@ ENDPROC(early_idt_handlers)
 	/* This is global to keep gas from relaxing the jumps */
 ENTRY(early_idt_handler)
 	cld
+
+	cmpl $X86_TRAP_NMI,(%esp)
+	je is_nmi		# Ignore NMI
+
 	cmpl $2,%ss:early_recursion_flag
 	je hlt_loop
 	incl %ss:early_recursion_flag
@@ -594,8 +598,9 @@ ex_entry:
 	pop %edx
 	pop %ecx
 	pop %eax
-	addl $8,%esp		/* drop vector number and error code */
 	decl %ss:early_recursion_flag
+is_nmi:
+	addl $8,%esp		/* drop vector number and error code */
 	iret
 ENDPROC(early_idt_handler)
 
diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index e1aabdb..33f36c7 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -343,6 +343,9 @@ early_idt_handlers:
 ENTRY(early_idt_handler)
 	cld
 
+	cmpl $X86_TRAP_NMI,(%rsp)
+	je is_nmi		# Ignore NMI
+
 	cmpl $2,early_recursion_flag(%rip)
 	jz  1f
 	incl early_recursion_flag(%rip)
@@ -405,8 +408,9 @@ ENTRY(early_idt_handler)
 	popq %rdx
 	popq %rcx
 	popq %rax
-	addq $16,%rsp		# drop vector number and error code
 	decl early_recursion_flag(%rip)
+is_nmi:
+	addq $16,%rsp		# drop vector number and error code
 	INTERRUPT_RETURN
 ENDPROC(early_idt_handler)
 
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 06853e6..ce72964 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -1239,14 +1239,8 @@ void __init setup_arch(char **cmdline_p)
 	register_refined_jiffies(CLOCK_TICK_RATE);
 
 #ifdef CONFIG_EFI
-	/* Once setup is done above, unmap the EFI memory map on
-	 * mismatched firmware/kernel archtectures since there is no
-	 * support for runtime services.
-	 */
-	if (efi_enabled(EFI_BOOT) && !efi_is_native()) {
-		pr_info("efi: Setup done, disabling due to 32/64-bit mismatch\n");
-		efi_unmap_memmap();
-	}
+	if (efi_enabled(EFI_BOOT))
+		efi_apply_memmap_quirks();
 #endif
 }
 
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index 6dea040..a10c8c7 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -1020,13 +1020,17 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
  * This routine handles page faults.  It determines the address,
  * and the problem, and then passes it off to one of the appropriate
  * routines.
+ *
+ * This function must have noinline because both callers
+ * {,trace_}do_page_fault() have notrace on. Having this an actual function
+ * guarantees there's a function trace entry.
  */
-static void __kprobes
-__do_page_fault(struct pt_regs *regs, unsigned long error_code)
+static void __kprobes noinline
+__do_page_fault(struct pt_regs *regs, unsigned long error_code,
+		unsigned long address)
 {
 	struct vm_area_struct *vma;
 	struct task_struct *tsk;
-	unsigned long address;
 	struct mm_struct *mm;
 	int fault;
 	unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
@@ -1034,9 +1038,6 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
 	tsk = current;
 	mm = tsk->mm;
 
-	/* Get the faulting address: */
-	address = read_cr2();
-
 	/*
 	 * Detect and handle instructions that would cause a page fault for
 	 * both a tracked kernel page and a userspace page.
@@ -1248,32 +1249,50 @@ good_area:
 	up_read(&mm->mmap_sem);
 }
 
-dotraplinkage void __kprobes
+dotraplinkage void __kprobes notrace
 do_page_fault(struct pt_regs *regs, unsigned long error_code)
 {
+	unsigned long address = read_cr2(); /* Get the faulting address */
 	enum ctx_state prev_state;
 
+	/*
+	 * We must have this function tagged with __kprobes, notrace and call
+	 * read_cr2() before calling anything else. To avoid calling any kind
+	 * of tracing machinery before we've observed the CR2 value.
+	 *
+	 * exception_{enter,exit}() contain all sorts of tracepoints.
+	 */
+
 	prev_state = exception_enter();
-	__do_page_fault(regs, error_code);
+	__do_page_fault(regs, error_code, address);
 	exception_exit(prev_state);
 }
 
-static void trace_page_fault_entries(struct pt_regs *regs,
+#ifdef CONFIG_TRACING
+static void trace_page_fault_entries(unsigned long address, struct pt_regs *regs,
 				     unsigned long error_code)
 {
 	if (user_mode(regs))
-		trace_page_fault_user(read_cr2(), regs, error_code);
+		trace_page_fault_user(address, regs, error_code);
 	else
-		trace_page_fault_kernel(read_cr2(), regs, error_code);
+		trace_page_fault_kernel(address, regs, error_code);
 }
 
-dotraplinkage void __kprobes
+dotraplinkage void __kprobes notrace
 trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
 {
+	/*
+	 * The exception_enter and tracepoint processing could
+	 * trigger another page faults (user space callchain
+	 * reading) and destroy the original cr2 value, so read
+	 * the faulting address now.
+	 */
+	unsigned long address = read_cr2();
 	enum ctx_state prev_state;
 
 	prev_state = exception_enter();
-	trace_page_fault_entries(regs, error_code);
-	__do_page_fault(regs, error_code);
+	trace_page_fault_entries(address, regs, error_code);
+	__do_page_fault(regs, error_code, address);
 	exception_exit(prev_state);
 }
+#endif /* CONFIG_TRACING */
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 1a201ac..b97acec 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -52,6 +52,7 @@
 #include <asm/tlbflush.h>
 #include <asm/x86_init.h>
 #include <asm/rtc.h>
+#include <asm/uv/uv.h>
 
 #define EFI_DEBUG
 
@@ -1210,3 +1211,22 @@ static int __init parse_efi_cmdline(char *str)
 	return 0;
 }
 early_param("efi", parse_efi_cmdline);
+
+void __init efi_apply_memmap_quirks(void)
+{
+	/*
+	 * Once setup is done earlier, unmap the EFI memory map on mismatched
+	 * firmware/kernel architectures since there is no support for runtime
+	 * services.
+	 */
+	if (!efi_is_native()) {
+		pr_info("efi: Setup done, disabling due to 32/64-bit mismatch\n");
+		efi_unmap_memmap();
+	}
+
+	/*
+	 * UV doesn't support the new EFI pagetable mapping yet.
+	 */
+	if (is_uv_system())
+		set_bit(EFI_OLD_MEMMAP, &x86_efi_facility);
+}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [GIT PULL] x86 fixes for v3.14-rc6
  2014-03-07 23:25 [GIT PULL] x86 fixes for v3.14-rc6 H. Peter Anvin
@ 2014-03-08  3:03 ` Linus Torvalds
  2014-03-08  3:34   ` H. Peter Anvin
  2014-03-08  3:36   ` H. Peter Anvin
  0 siblings, 2 replies; 5+ messages in thread
From: Linus Torvalds @ 2014-03-08  3:03 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Peter Zijlstra, Arnaldo Carvalho de Melo, Borislav Petkov,
	Don Zickus, Peter Anvin, Jiri Olsa, Linux Kernel Mailing List,
	Matt Fleming, Ingo Molnar, Paul Mackerras, Peter Zijlstra,
	Russ Anderson, Steven Rostedt, seiji.aguchi, Thomas Gleixner,
	Vince Weaver

Oww, oww, oww.

DAMMIT.

On Fri, Mar 7, 2014 at 3:25 PM, H. Peter Anvin <hpa@linux.intel.com> wrote:
>
> A small collection of minor fixes.  The FPU stuff is still pending, I
> fear.  I haven't heard anything from Suresh so I suspect I'm going to
> have to dig into the init specifics myself and fix up the patchset.

I pulled this and then pushed out without test-compiling, because I'm
not used to the x86 trees causing problems. Usually they've gone
through a lot of build tests etc.

But dammit, it's broken:

  arch/x86/kernel/head_64.o: In function `early_idt_handler':
  (.init.text+0x124): undefined reference to `X86_TRAP_NMI'

because X86_TRAP_NMI is an enum, not a #define.

This can not have worked in your tree either, because that thing has
never been anything *but* an enum. So I'm pissed off. This patch was
clearly never tested anywhere. Why was it sent to me?

Grr. Consider yourself cursed at. Saatana.

              Linus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [GIT PULL] x86 fixes for v3.14-rc6
  2014-03-08  3:03 ` Linus Torvalds
@ 2014-03-08  3:34   ` H. Peter Anvin
  2014-03-08  3:36   ` H. Peter Anvin
  1 sibling, 0 replies; 5+ messages in thread
From: H. Peter Anvin @ 2014-03-08  3:34 UTC (permalink / raw)
  To: Linus Torvalds, H. Peter Anvin
  Cc: Peter Zijlstra, Arnaldo Carvalho de Melo, Borislav Petkov,
	Don Zickus, Jiri Olsa, Linux Kernel Mailing List, Matt Fleming,
	Ingo Molnar, Paul Mackerras, Peter Zijlstra, Russ Anderson,
	Steven Rostedt, seiji.aguchi, Thomas Gleixner, Vince Weaver

Bloody hell.  Friday afternoon malfunction (thought I checked the output and apparently missed.)

On March 7, 2014 7:03:09 PM PST, Linus Torvalds <torvalds@linux-foundation.org> wrote:
>Oww, oww, oww.
>
>DAMMIT.
>
>On Fri, Mar 7, 2014 at 3:25 PM, H. Peter Anvin <hpa@linux.intel.com>
>wrote:
>>
>> A small collection of minor fixes.  The FPU stuff is still pending, I
>> fear.  I haven't heard anything from Suresh so I suspect I'm going to
>> have to dig into the init specifics myself and fix up the patchset.
>
>I pulled this and then pushed out without test-compiling, because I'm
>not used to the x86 trees causing problems. Usually they've gone
>through a lot of build tests etc.
>
>But dammit, it's broken:
>
>  arch/x86/kernel/head_64.o: In function `early_idt_handler':
>  (.init.text+0x124): undefined reference to `X86_TRAP_NMI'
>
>because X86_TRAP_NMI is an enum, not a #define.
>
>This can not have worked in your tree either, because that thing has
>never been anything *but* an enum. So I'm pissed off. This patch was
>clearly never tested anywhere. Why was it sent to me?
>
>Grr. Consider yourself cursed at. Saatana.
>
>              Linus

-- 
Sent from my mobile phone.  Please pardon brevity and lack of formatting.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [GIT PULL] x86 fixes for v3.14-rc6
  2014-03-08  3:03 ` Linus Torvalds
  2014-03-08  3:34   ` H. Peter Anvin
@ 2014-03-08  3:36   ` H. Peter Anvin
  1 sibling, 0 replies; 5+ messages in thread
From: H. Peter Anvin @ 2014-03-08  3:36 UTC (permalink / raw)
  To: Linus Torvalds, H. Peter Anvin
  Cc: Peter Zijlstra, Arnaldo Carvalho de Melo, Borislav Petkov,
	Don Zickus, Jiri Olsa, Linux Kernel Mailing List, Matt Fleming,
	Ingo Molnar, Paul Mackerras, Peter Zijlstra, Russ Anderson,
	Steven Rostedt, seiji.aguchi, Thomas Gleixner, Vince Weaver

And yes, of course the change from hardcoded 2 to X86_TRAP_NMI was an afterthought.

On March 7, 2014 7:03:09 PM PST, Linus Torvalds <torvalds@linux-foundation.org> wrote:
>Oww, oww, oww.
>
>DAMMIT.
>
>On Fri, Mar 7, 2014 at 3:25 PM, H. Peter Anvin <hpa@linux.intel.com>
>wrote:
>>
>> A small collection of minor fixes.  The FPU stuff is still pending, I
>> fear.  I haven't heard anything from Suresh so I suspect I'm going to
>> have to dig into the init specifics myself and fix up the patchset.
>
>I pulled this and then pushed out without test-compiling, because I'm
>not used to the x86 trees causing problems. Usually they've gone
>through a lot of build tests etc.
>
>But dammit, it's broken:
>
>  arch/x86/kernel/head_64.o: In function `early_idt_handler':
>  (.init.text+0x124): undefined reference to `X86_TRAP_NMI'
>
>because X86_TRAP_NMI is an enum, not a #define.
>
>This can not have worked in your tree either, because that thing has
>never been anything *but* an enum. So I'm pissed off. This patch was
>clearly never tested anywhere. Why was it sent to me?
>
>Grr. Consider yourself cursed at. Saatana.
>
>              Linus

-- 
Sent from my mobile phone.  Please pardon brevity and lack of formatting.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [GIT PULL] x86 fixes for v3.14-rc6
@ 2014-03-08  5:24 George Spelvin
  0 siblings, 0 replies; 5+ messages in thread
From: George Spelvin @ 2014-03-08  5:24 UTC (permalink / raw)
  To: hpa; +Cc: linux, linux-kernel, sbsiddha

> The FPU stuff is still pending, I fear.  I haven't heard anything from
> Suresh so I suspect I'm going to have to dig into the init specifics
> myself and fix up the patchset.

As I mentioned a couple of weeks ago in the "[PATCH] Make
math_state_restore() save and restore the interrupt flag" thread,
I've been running with just Suresh's second patch for the last month,
and it's cured all my symptoms.

Although, just as a minor style point, I might reduce the
number of levels if indentation by rewriting it as:

 void __kernel_fpu_end(void)
 {
-	if (use_eager_fpu())
-		math_state_restore();
-	else
+	if (!use_eager_fpu()) {
 		stts();
+	} else if (likely(tsk_used_math(current)))
+		math_state_restore();
+	}
+	/*
+	 * When using eager fpu, tsk_used_math() is almost always true,
+	 * and we restore the user math state eagerly. In some special
+	 * cases during thread exit, signal handling etc, tsk_used_math()
+	 * is false. Those few places will take proper actions, so we
+	 * don't need to restore the math here.
+	 */
 }
 EXPORT_SYMBOL(__kernel_fpu_end);

Truthfully, the idea I like best is Linus's proposal to postpone all
such adjustments to the processor state until the return to user space,
so multiple kernel_fpu_begin()/_end() pairs become much cheaper:
http://marc.info/?l=linux-kernel&m=139128398717816

Hoerver, that deep into Here Be Dragons code is somewhere I fear to tread,
so I'm hoping someone braver than I is inspired.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-03-08  5:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-07 23:25 [GIT PULL] x86 fixes for v3.14-rc6 H. Peter Anvin
2014-03-08  3:03 ` Linus Torvalds
2014-03-08  3:34   ` H. Peter Anvin
2014-03-08  3:36   ` H. Peter Anvin
2014-03-08  5:24 George Spelvin

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®