mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: hpa@zytor.com, linux-kernel@vger.kernel.org, mingo@elte.hu,
	tglx@linutronix.de
Subject: [PATCH] [1/28] x86: Fix panic with interrupts off (needed for MCE)
Date: Tue,  7 Apr 2009 17:07:40 +0200 (CEST)	[thread overview]
Message-ID: <20090407150740.D95E51D046D@basil.firstfloor.org> (raw)
In-Reply-To: <20090407507.636692542@firstfloor.org>


Impact: bug fix, fixes an old regression

For some time each panic() called with interrupts disabled triggered the 
!irqs_disabled() WARN_ON in smp_call_function(), producing ugly
backtraces and confusing users.

This is a common situation with machine checks for example which tend
to call panic with interrupts disabled, but will also hit 
in other situations e.g. panic during early boot. In fact 
it means that panic cannot be called in many circumstances, which
would be bad.

This all started with the new fancy queued smp_call_function,
which is then used by the shutdown path to shut down the other CPUs.

On closer examination it turned out that the fancy RCU
smp_call_function() does lots of things not suitable in a panic
situation anyways, like allocating memory and relying on complex system
state.

I originally tried to patch this over by checking for panic
there, but it was quite complicated and the original patch
was also not very popular. This also didn't fix some
of the underlying complexity problems.

The new code in post 2.6.29 tries to patch around this by
checking for oops_in_progress, but that is not enough to make
this fully safe and I don't think that's a real solution
because panic has to be reliable.

So instead use an own vector to reboot. This makes the reboot code
extremly straight forward, which is definitely a big plus
in a panic situation where it is important to avoid relying
on too much kernel state. The new simple code is also
safe to be called from interupts off region because it is
very very simple.

There can be situations where it is important that panic
is reliable. For example on a fatal machine check the panic
is needed to get the system up again and running as quickly
as possible. So it's important that panic is reliable and
all function it calls simple.

This is why I came up with this simple vector scheme.
It's very hard to beat in simplicity.  Vectors are not
particularly precious anymore since all big systems
are using per CPU vectors.

Another possibility would have been to use an NMI similar
to kdump, but there is still the problem that NMIs don't
work reliably on some systems due to BIOS issues. NMIs
would have been able to stop CPUs running with interrupts
off too. In the sake of universal reliability I opted for 
using a non NMI vector for now.

I put the reboot vector into the highest priority bucket
of the APIC vectors and moved the 64bit UV_BAU message
down instead into the next lower priority.

Signed-off-by: Andi Kleen <ak@linux.intel.com>

---
 arch/x86/include/asm/entry_arch.h  |    1 +
 arch/x86/include/asm/hw_irq.h      |    1 +
 arch/x86/include/asm/irq_vectors.h |    8 ++++++--
 arch/x86/kernel/entry_64.S         |    2 ++
 arch/x86/kernel/irqinit_32.c       |    3 +++
 arch/x86/kernel/irqinit_64.c       |    3 +++
 arch/x86/kernel/smp.c              |   28 +++++++++++++++++++++++++++-
 7 files changed, 43 insertions(+), 3 deletions(-)

Index: linux/arch/x86/kernel/irqinit_32.c
===================================================================
--- linux.orig/arch/x86/kernel/irqinit_32.c	2009-04-07 16:09:58.000000000 +0200
+++ linux/arch/x86/kernel/irqinit_32.c	2009-04-07 16:09:58.000000000 +0200
@@ -167,6 +167,9 @@
 	/* Low priority IPI to cleanup after moving an irq */
 	set_intr_gate(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt);
 	set_bit(IRQ_MOVE_CLEANUP_VECTOR, used_vectors);
+
+	/* IPI used for rebooting/stopping */
+	alloc_intr_gate(REBOOT_VECTOR, reboot_interrupt);
 #endif
 
 #ifdef CONFIG_X86_LOCAL_APIC
Index: linux/arch/x86/kernel/entry_64.S
===================================================================
--- linux.orig/arch/x86/kernel/entry_64.S	2009-04-07 16:09:58.000000000 +0200
+++ linux/arch/x86/kernel/entry_64.S	2009-04-07 16:43:12.000000000 +0200
@@ -976,6 +976,8 @@
 #ifdef CONFIG_SMP
 apicinterrupt IRQ_MOVE_CLEANUP_VECTOR \
 	irq_move_cleanup_interrupt smp_irq_move_cleanup_interrupt
+apicinterrupt REBOOT_VECTOR \
+	reboot_interrupt smp_reboot_interrupt
 #endif
 
 #ifdef CONFIG_X86_UV
Index: linux/arch/x86/kernel/irqinit_64.c
===================================================================
--- linux.orig/arch/x86/kernel/irqinit_64.c	2009-04-07 16:09:58.000000000 +0200
+++ linux/arch/x86/kernel/irqinit_64.c	2009-04-07 16:43:12.000000000 +0200
@@ -133,6 +133,9 @@
 	/* Low priority IPI to cleanup after moving an irq */
 	set_intr_gate(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt);
 	set_bit(IRQ_MOVE_CLEANUP_VECTOR, used_vectors);
+
+	/* IPI for rebooting/panicing */
+	alloc_intr_gate(REBOOT_VECTOR, reboot_interrupt);
 #endif
 }
 
Index: linux/arch/x86/kernel/smp.c
===================================================================
--- linux.orig/arch/x86/kernel/smp.c	2009-04-07 16:09:58.000000000 +0200
+++ linux/arch/x86/kernel/smp.c	2009-04-07 16:43:16.000000000 +0200
@@ -150,14 +150,40 @@
  * this function calls the 'stop' function on all other CPUs in the system.
  */
 
+asmlinkage void smp_reboot_interrupt(void)
+{
+	ack_APIC_irq();
+	irq_enter();
+	stop_this_cpu(NULL);
+	irq_exit();
+}
+
 static void native_smp_send_stop(void)
 {
 	unsigned long flags;
+	unsigned long wait;
 
 	if (reboot_force)
 		return;
 
-	smp_call_function(stop_this_cpu, NULL, 0);
+	/*
+	 * Use an own vector here because smp_call_function
+	 * does lots of things not suitable in a panic situation.
+	 * On most systems we could also use an NMI here,
+	 * but there are a few systems around where NMI
+	 * is problematic so stay with an non NMI for now
+	 * (this implies we cannot stop CPUs spinning with irq off
+	 * currently)
+	 */
+	if (num_online_cpus() > 1) {
+		apic->send_IPI_allbutself(REBOOT_VECTOR);
+
+		/* Don't wait longer than a second */
+		wait = USEC_PER_SEC;
+		while (num_online_cpus() > 1 && wait--)
+			udelay(1);
+	}
+
 	local_irq_save(flags);
 	disable_local_APIC();
 	local_irq_restore(flags);
Index: linux/arch/x86/include/asm/entry_arch.h
===================================================================
--- linux.orig/arch/x86/include/asm/entry_arch.h	2009-04-07 16:09:58.000000000 +0200
+++ linux/arch/x86/include/asm/entry_arch.h	2009-04-07 16:09:58.000000000 +0200
@@ -14,6 +14,7 @@
 BUILD_INTERRUPT(call_function_interrupt,CALL_FUNCTION_VECTOR)
 BUILD_INTERRUPT(call_function_single_interrupt,CALL_FUNCTION_SINGLE_VECTOR)
 BUILD_INTERRUPT(irq_move_cleanup_interrupt,IRQ_MOVE_CLEANUP_VECTOR)
+BUILD_INTERRUPT(reboot_interrupt,REBOOT_VECTOR)
 
 BUILD_INTERRUPT3(invalidate_interrupt0,INVALIDATE_TLB_VECTOR_START+0,
 		 smp_invalidate_interrupt)
Index: linux/arch/x86/include/asm/irq_vectors.h
===================================================================
--- linux.orig/arch/x86/include/asm/irq_vectors.h	2009-04-07 16:09:58.000000000 +0200
+++ linux/arch/x86/include/asm/irq_vectors.h	2009-04-07 16:43:12.000000000 +0200
@@ -88,12 +88,14 @@
 #define THERMAL_APIC_VECTOR		0xfa
 
 #ifdef CONFIG_X86_32
-/* 0xf8 - 0xf9 : free */
+/* 0xf9 : free */
 #else
 # define THRESHOLD_APIC_VECTOR		0xf9
-# define UV_BAU_MESSAGE			0xf8
 #endif
 
+#define REBOOT_VECTOR			0xf8
+
+
 /* f0-f7 used for spreading out TLB flushes: */
 #define INVALIDATE_TLB_VECTOR_END	0xf7
 #define INVALIDATE_TLB_VECTOR_START	0xf0
@@ -116,6 +118,8 @@
  */
 #define GENERIC_INTERRUPT_VECTOR	0xed
 
+#define UV_BAU_MESSAGE			0xec
+
 /*
  * First APIC vector available to drivers: (vectors 0x30-0xee) we
  * start at 0x31(0x41) to spread out vectors evenly between priority
Index: linux/arch/x86/include/asm/hw_irq.h
===================================================================
--- linux.orig/arch/x86/include/asm/hw_irq.h	2009-04-07 16:09:58.000000000 +0200
+++ linux/arch/x86/include/asm/hw_irq.h	2009-04-07 16:43:12.000000000 +0200
@@ -44,6 +44,7 @@
 extern void invalidate_interrupt7(void);
 
 extern void irq_move_cleanup_interrupt(void);
+extern void reboot_interrupt(void);
 extern void threshold_interrupt(void);
 
 extern void call_function_interrupt(void);

  reply	other threads:[~2009-04-07 15:09 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-07 15:07 [PATCH] [0/28] x86: MCE: Feature series for 2.6.31 Andi Kleen
2009-04-07 15:07 ` Andi Kleen [this message]
2009-04-20  0:26   ` [PATCH] [1/28] x86: Fix panic with interrupts off (needed for MCE) Hidetoshi Seto
2009-04-20  5:36     ` Andi Kleen
2009-04-07 15:07 ` [PATCH] [2/28] x86: MCE: Synchronize core after machine check handling Andi Kleen
2009-04-07 15:07 ` [PATCH] [3/28] x86: MCE: Remove assumption that RIP MSR is exact Andi Kleen
2009-04-07 15:07 ` [PATCH] [4/28] x86: MCE: Use symbolic macros to access MCG_CAP register Andi Kleen
2009-04-07 15:07 ` [PATCH] [5/28] x86: MCE: Use extended sysattrs for the check_interval attribute Andi Kleen
2009-04-07 15:07 ` [PATCH] [6/28] x86: MCE: Add machine check exception count in /proc/interrupts Andi Kleen
2009-04-08  5:00   ` Hidetoshi Seto
2009-04-08  9:56     ` Andi Kleen
2009-04-07 15:07 ` [PATCH] [7/28] x86: MCE: Log corrected errors when panicing Andi Kleen
2009-04-07 15:07 ` [PATCH] [8/28] x86: MCE: Remove unused mce_events variable Andi Kleen
2009-04-07 15:07 ` [PATCH] [9/28] x86: MCE: Remove machine check handler idle notify on 64bit Andi Kleen
2009-04-07 15:07 ` [PATCH] [10/28] x86: MCE: Remove oops_begin() use in 64bit machine check Andi Kleen
2009-04-07 15:07 ` [PATCH] [11/28] x86: MCE: Remove mce_init unused argument Andi Kleen
2009-04-07 15:07 ` [PATCH] [12/28] x86: MCE: Rename and align out2 label Andi Kleen
2009-04-07 15:07 ` [PATCH] [13/28] x86: MCE: Implement bootstrapping for machine check wakeups Andi Kleen
2009-04-07 15:07 ` [PATCH] [14/28] x86: MCE: Add MSR read wrappers for easier error injection Andi Kleen
2009-04-17 11:23   ` Hidetoshi Seto
2009-04-17 13:00     ` Andi Kleen
2009-04-17 23:55       ` H. Peter Anvin
2009-04-07 15:07 ` [PATCH] [15/28] x86: MCE: Remove TSC print heuristic Andi Kleen
2009-04-07 15:07 ` [PATCH] [16/28] x86: MCE: Drop BKL in mce_open Andi Kleen
2009-04-07 15:07 ` [PATCH] [17/28] x86: MCE: Add table driven machine check grading Andi Kleen
2009-04-07 15:08 ` [PATCH] [18/28] x86: MCE: Check early in exception handler if panic is needed Andi Kleen
2009-04-07 15:08 ` [PATCH] [19/28] x86: MCE: Implement panic synchronization Andi Kleen
2009-04-07 15:08 ` [PATCH] [20/28] x86: MCE: Switch x86 machine check handler to Monarch election Andi Kleen
2009-04-17 11:24   ` Hidetoshi Seto
2009-04-17 13:09     ` Andi Kleen
2009-04-17 13:53       ` [PATCH] [20/28] x86: MCE: Switch x86 machine check handler to Monarch election. II Andi Kleen
2009-04-07 15:08 ` [PATCH] [21/28] x86: MCE: Store record length into memory struct mce anchor Andi Kleen
2009-04-07 15:08 ` [PATCH] [22/28] x86: MCE: Default to panic timeout for machine checks Andi Kleen
2009-04-17 11:24   ` Hidetoshi Seto
2009-04-17 13:12     ` Andi Kleen
2009-04-07 15:08 ` [PATCH] [23/28] x86: MCE: Improve documentation Andi Kleen
2009-04-08  5:12   ` Hidetoshi Seto
2009-04-07 15:08 ` [PATCH] [24/28] x86: MCE: Support more than 256 CPUs in struct mce Andi Kleen
2009-04-07 15:08 ` [PATCH] [25/28] x86: MCE: Extend struct mce user interface with more information Andi Kleen
2009-04-07 15:08 ` [PATCH] [26/28] Export add_timer_on for modules Andi Kleen
2009-04-07 15:08 ` [PATCH] [27/28] MCE: Add basic error injection infrastructure Andi Kleen
2009-04-07 15:08 ` [PATCH] [28/28] x86: MCE: Implement new status bits Andi Kleen
2009-04-17 11:24   ` Hidetoshi Seto
2009-04-17 13:17     ` Andi Kleen
2009-04-17 11:24 ` [PATCH] [0/28] x86: MCE: Feature series for 2.6.31 Hidetoshi Seto
2009-04-17 13:28   ` Andi Kleen

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=20090407150740.D95E51D046D@basil.firstfloor.org \
    --to=andi@firstfloor.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    /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

Powered by JetHome