All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: kexec@lists.infradead.org, kvm@vger.kernel.org
Cc: Eduardo Habkost <ehabkost@redhat.com>
Subject: [PATCH 1/2] kdump: crash-time CPU halt notifier interface
Date: Mon, 20 Oct 2008 13:01:33 -0200	[thread overview]
Message-ID: <1224514894-30171-2-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1224514894-30171-1-git-send-email-ehabkost@redhat.com>

This patch adds an interface for notification of CPUs being
halted on a crash. The notifier will be called once on each CPU by
machine_crash_shutdown().

The notifiers will be used by KVM to disable virtualization before
halting the CPUs, otherwise the booting of the kdump kernel may hang
(it does, on my machine, when kvm-intel module is loaded).

We can't just use the same notifiers used at reboot time (that are used
by non-crash-dump kexec), because at crash time some CPUs may have IRQs
disabled, so we can't use IPIs. The crash shutdown code use NMIs to tell
the other CPUs to be halted, and the new notifier call is hooked into
the CPU halting code that is on the crash shutdown NMI handler.

I am not sure if a non x86-specific interface is more recommended. Some
arches don't have code to halt the CPUs on machine_crash_shutdown(),
so the interface wouldn't make sense on those arches.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 arch/x86/kernel/crash.c  |    5 ++++
 arch/x86/kernel/reboot.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++
 include/asm-x86/reboot.h |    4 +++
 3 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index 2685538..3303e3c 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -16,6 +16,7 @@
 #include <linux/delay.h>
 #include <linux/elf.h>
 #include <linux/elfcore.h>
+#include <linux/module.h>
 
 #include <asm/processor.h>
 #include <asm/hardirq.h>
@@ -65,6 +66,8 @@ static int crash_nmi_callback(struct notifier_block *self,
 	}
 #endif
 	crash_save_cpu(regs, cpu);
+
+	emergency_halt_notify(cpu);
 	disable_local_APIC();
 	atomic_dec(&waiting_for_crash_ipi);
 	/* Assume hlt works */
@@ -134,6 +137,8 @@ void native_machine_crash_shutdown(struct pt_regs *regs)
 	/* Make a note of crashing cpu. Will be used in NMI callback.*/
 	crashing_cpu = safe_smp_processor_id();
 	nmi_shootdown_cpus();
+	emergency_halt_notify(crashing_cpu);
+
 	lapic_shutdown();
 #if defined(CONFIG_X86_IO_APIC)
 	disable_IO_APIC();
diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index f4c93f1..976d0bf 100644
--- a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -518,3 +518,57 @@ void machine_crash_shutdown(struct pt_regs *regs)
 	machine_ops.crash_shutdown(regs);
 }
 #endif
+
+
+static RAW_NOTIFIER_HEAD(emergency_halt_chain);
+static DEFINE_SPINLOCK(emergency_halt_chain_lock);
+
+/**
+ *	register_emergency_halt_notifier - Register crash-time CPU halt notifier
+ *	@nb: Info about notifier function to be called
+ *
+ *	Registers a function to be called when CPUs are being halted at
+ *	machine_crash_shutdown().
+ *
+ *	The function is called once on each online CPU, possibly
+ *	from a NMI handler. Do the very least to allow the CPU
+ *	to be halted, as the kernel has just crashed.
+ */
+int register_emergency_halt_notifier(struct notifier_block *nb)
+{
+	int r;
+	spin_lock(&emergency_halt_chain_lock);
+	r = raw_notifier_chain_register(&emergency_halt_chain, nb);
+	spin_unlock(&emergency_halt_chain_lock);
+	return r;
+}
+EXPORT_SYMBOL(register_emergency_halt_notifier);
+
+/**
+ *	unregister_emergency_halt_notifier - Unregister a emergency_halt notifier
+ *	@nb: Notifier info previously registered
+ *
+ *	Unregister a CPU crash-time emergency halt notifier previously
+ *	registered.
+ *
+ *	Returns zero on success, or %-ENOENT on failure.
+ */
+int unregister_emergency_halt_notifier(struct notifier_block *nb)
+{
+	return raw_notifier_chain_unregister(&emergency_halt_chain, nb);
+}
+EXPORT_SYMBOL(unregister_emergency_halt_notifier);
+
+/* Notify that the CPU will be halted on crash
+ *
+ * Runs the notifiers registered by register_emergency_halt_notifier().
+ * Must be called on the CPU that is being halted.
+ */
+void emergency_halt_notify(unsigned int cpu)
+{
+	void *hcpu = (void *)(long)cpu;
+
+	/* Don't use any locking. We are crashing.
+	 */
+	raw_notifier_call_chain(&emergency_halt_chain, 0, hcpu);
+}
diff --git a/include/asm-x86/reboot.h b/include/asm-x86/reboot.h
index 1c2f0ce..49c9d7f 100644
--- a/include/asm-x86/reboot.h
+++ b/include/asm-x86/reboot.h
@@ -18,4 +18,8 @@ void native_machine_crash_shutdown(struct pt_regs *regs);
 void native_machine_shutdown(void);
 void machine_real_restart(const unsigned char *code, int length);
 
+int register_emergency_halt_notifier(struct notifier_block *nb);
+int unregister_emergency_halt_notifier(struct notifier_block *nb);
+void emergency_halt_notify(unsigned int cpu);
+
 #endif /* ASM_X86__REBOOT_H */
-- 
1.5.5.GIT


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

WARNING: multiple messages have this Message-ID (diff)
From: Eduardo Habkost <ehabkost-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: kexec-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Eduardo Habkost <ehabkost-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Subject: [PATCH 1/2] kdump: crash-time CPU halt notifier interface
Date: Mon, 20 Oct 2008 13:01:33 -0200	[thread overview]
Message-ID: <1224514894-30171-2-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1224514894-30171-1-git-send-email-ehabkost-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

This patch adds an interface for notification of CPUs being
halted on a crash. The notifier will be called once on each CPU by
machine_crash_shutdown().

The notifiers will be used by KVM to disable virtualization before
halting the CPUs, otherwise the booting of the kdump kernel may hang
(it does, on my machine, when kvm-intel module is loaded).

We can't just use the same notifiers used at reboot time (that are used
by non-crash-dump kexec), because at crash time some CPUs may have IRQs
disabled, so we can't use IPIs. The crash shutdown code use NMIs to tell
the other CPUs to be halted, and the new notifier call is hooked into
the CPU halting code that is on the crash shutdown NMI handler.

I am not sure if a non x86-specific interface is more recommended. Some
arches don't have code to halt the CPUs on machine_crash_shutdown(),
so the interface wouldn't make sense on those arches.

Signed-off-by: Eduardo Habkost <ehabkost-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 arch/x86/kernel/crash.c  |    5 ++++
 arch/x86/kernel/reboot.c |   54 ++++++++++++++++++++++++++++++++++++++++++++++
 include/asm-x86/reboot.h |    4 +++
 3 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
index 2685538..3303e3c 100644
--- a/arch/x86/kernel/crash.c
+++ b/arch/x86/kernel/crash.c
@@ -16,6 +16,7 @@
 #include <linux/delay.h>
 #include <linux/elf.h>
 #include <linux/elfcore.h>
+#include <linux/module.h>
 
 #include <asm/processor.h>
 #include <asm/hardirq.h>
@@ -65,6 +66,8 @@ static int crash_nmi_callback(struct notifier_block *self,
 	}
 #endif
 	crash_save_cpu(regs, cpu);
+
+	emergency_halt_notify(cpu);
 	disable_local_APIC();
 	atomic_dec(&waiting_for_crash_ipi);
 	/* Assume hlt works */
@@ -134,6 +137,8 @@ void native_machine_crash_shutdown(struct pt_regs *regs)
 	/* Make a note of crashing cpu. Will be used in NMI callback.*/
 	crashing_cpu = safe_smp_processor_id();
 	nmi_shootdown_cpus();
+	emergency_halt_notify(crashing_cpu);
+
 	lapic_shutdown();
 #if defined(CONFIG_X86_IO_APIC)
 	disable_IO_APIC();
diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index f4c93f1..976d0bf 100644
--- a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -518,3 +518,57 @@ void machine_crash_shutdown(struct pt_regs *regs)
 	machine_ops.crash_shutdown(regs);
 }
 #endif
+
+
+static RAW_NOTIFIER_HEAD(emergency_halt_chain);
+static DEFINE_SPINLOCK(emergency_halt_chain_lock);
+
+/**
+ *	register_emergency_halt_notifier - Register crash-time CPU halt notifier
+ *	@nb: Info about notifier function to be called
+ *
+ *	Registers a function to be called when CPUs are being halted at
+ *	machine_crash_shutdown().
+ *
+ *	The function is called once on each online CPU, possibly
+ *	from a NMI handler. Do the very least to allow the CPU
+ *	to be halted, as the kernel has just crashed.
+ */
+int register_emergency_halt_notifier(struct notifier_block *nb)
+{
+	int r;
+	spin_lock(&emergency_halt_chain_lock);
+	r = raw_notifier_chain_register(&emergency_halt_chain, nb);
+	spin_unlock(&emergency_halt_chain_lock);
+	return r;
+}
+EXPORT_SYMBOL(register_emergency_halt_notifier);
+
+/**
+ *	unregister_emergency_halt_notifier - Unregister a emergency_halt notifier
+ *	@nb: Notifier info previously registered
+ *
+ *	Unregister a CPU crash-time emergency halt notifier previously
+ *	registered.
+ *
+ *	Returns zero on success, or %-ENOENT on failure.
+ */
+int unregister_emergency_halt_notifier(struct notifier_block *nb)
+{
+	return raw_notifier_chain_unregister(&emergency_halt_chain, nb);
+}
+EXPORT_SYMBOL(unregister_emergency_halt_notifier);
+
+/* Notify that the CPU will be halted on crash
+ *
+ * Runs the notifiers registered by register_emergency_halt_notifier().
+ * Must be called on the CPU that is being halted.
+ */
+void emergency_halt_notify(unsigned int cpu)
+{
+	void *hcpu = (void *)(long)cpu;
+
+	/* Don't use any locking. We are crashing.
+	 */
+	raw_notifier_call_chain(&emergency_halt_chain, 0, hcpu);
+}
diff --git a/include/asm-x86/reboot.h b/include/asm-x86/reboot.h
index 1c2f0ce..49c9d7f 100644
--- a/include/asm-x86/reboot.h
+++ b/include/asm-x86/reboot.h
@@ -18,4 +18,8 @@ void native_machine_crash_shutdown(struct pt_regs *regs);
 void native_machine_shutdown(void);
 void machine_real_restart(const unsigned char *code, int length);
 
+int register_emergency_halt_notifier(struct notifier_block *nb);
+int unregister_emergency_halt_notifier(struct notifier_block *nb);
+void emergency_halt_notify(unsigned int cpu);
+
 #endif /* ASM_X86__REBOOT_H */
-- 
1.5.5.GIT

  reply	other threads:[~2008-10-20 15:01 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-20 15:01 [PATCH 0/2] kvm: disable virtualization on kdump Eduardo Habkost
2008-10-20 15:01 ` Eduardo Habkost
2008-10-20 15:01 ` Eduardo Habkost [this message]
2008-10-20 15:01   ` [PATCH 1/2] kdump: crash-time CPU halt notifier interface Eduardo Habkost
2008-10-20 15:01 ` [PATCH 2/2] kvm: disable virtualization when halting CPUs on crash Eduardo Habkost
2008-10-20 15:01   ` Eduardo Habkost
2008-10-22 23:28 ` [PATCH 0/2] kvm: disable virtualization on kdump Simon Horman
2008-10-22 23:28   ` Simon Horman
2008-10-23 19:41   ` Eduardo Habkost
2008-10-23 19:41     ` Eduardo Habkost
2008-10-23 22:29     ` Simon Horman
2008-10-23 22:29       ` Simon Horman
2008-10-24  1:00       ` Eric W. Biederman
2008-10-24  1:00         ` Eric W. Biederman
2008-10-26 12:49         ` Avi Kivity
2008-10-26 12:49           ` Avi Kivity
2008-10-26 14:46           ` Eric W. Biederman
2008-10-26 14:46             ` Eric W. Biederman
2008-10-26 15:07             ` Avi Kivity
2008-10-26 15:07               ` Avi Kivity
2008-10-26 21:39               ` Eduardo Habkost
2008-10-26 21:39                 ` Eduardo Habkost
2008-10-27  2:08                 ` Eric W. Biederman
2008-10-27  2:08                   ` Eric W. Biederman
2008-10-27  9:13                   ` Avi Kivity
2008-10-27  9:13                     ` Avi Kivity
2008-10-27 12:28                     ` Eduardo Habkost
2008-10-27 12:28                       ` Eduardo Habkost
2008-10-27 14:02                       ` Avi Kivity
2008-10-27 14:02                         ` Avi Kivity
2008-10-27 17:32                         ` Eric W. Biederman
2008-10-27 17:32                           ` Eric W. Biederman
2008-10-28 19:45                           ` Eduardo Habkost
2008-10-28 19:45                             ` Eduardo Habkost
2008-10-28 20:13                             ` Eric W. Biederman
2008-10-28 20:13                               ` Eric W. Biederman
2008-10-29  9:41                               ` Avi Kivity
2008-10-29  9:41                                 ` Avi Kivity
2008-10-29 14:54                                 ` Eric W. Biederman
2008-10-29 14:54                                   ` Eric W. Biederman
2008-10-29 17:03                                   ` Avi Kivity
2008-10-29 17:03                                     ` Avi Kivity
2008-10-30  1:33                                     ` Eric W. Biederman
2008-10-30  1:33                                       ` Eric W. Biederman
2008-10-30  7:35                                       ` Chris Lalancette
2008-10-30  7:35                                         ` Chris Lalancette
2008-10-30  7:43                                         ` Avi Kivity
2008-10-30  7:43                                           ` Avi Kivity
2008-10-30  7:52                                       ` Avi Kivity
2008-10-30  7:52                                         ` Avi Kivity
2008-10-29  9:31                             ` Avi Kivity
2008-10-29  9:31                               ` Avi Kivity
2008-10-27 15:05                     ` Eric W. Biederman
2008-10-27 15:05                       ` Eric W. Biederman
2008-10-27 15:50                       ` Eduardo Habkost
2008-10-27 15:50                         ` Eduardo Habkost
2008-10-27  8:54                 ` Avi Kivity
2008-10-27  8:54                   ` Avi Kivity
2008-10-27 13:09                   ` Vivek Goyal
2008-10-27 13:09                     ` Vivek Goyal
2008-10-27 14:04                     ` Avi Kivity
2008-10-27 14:04                       ` Avi Kivity
2008-10-29 20:10                     ` Eduardo Habkost
2008-10-29 20:10                       ` Eduardo Habkost
2008-10-29 20:29                       ` Avi Kivity
2008-10-29 20:29                         ` Avi Kivity
2008-10-29 21:05                       ` Vivek Goyal
2008-10-29 21:05                         ` Vivek Goyal
2008-10-30  0:58                         ` Eric W. Biederman
2008-10-30  0:58                           ` Eric W. Biederman
2008-10-26 21:47               ` Eric W. Biederman
2008-10-26 21:47                 ` Eric W. Biederman
2008-10-27  8:59                 ` Avi Kivity
2008-10-27  8:59                   ` Avi Kivity
2008-10-27 15:02                   ` Eric W. Biederman
2008-10-27 15:02                     ` Eric W. Biederman
2008-10-27 15:38                     ` Eduardo Habkost
2008-10-27 15:38                       ` Eduardo Habkost
2008-10-26 12:46     ` Avi Kivity
2008-10-26 12:46       ` Avi Kivity

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=1224514894-30171-2-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=kexec@lists.infradead.org \
    --cc=kvm@vger.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 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.