linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Allow crash dumps with crash_kexec_post_notifiers
@ 2016-07-13 12:19 Petr Tesarik
  2016-07-13 12:19 ` [PATCH 1/2] Add a kexec_crash_loaded() function Petr Tesarik
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Petr Tesarik @ 2016-07-13 12:19 UTC (permalink / raw)
  To: Juergen Gross, Josh Triplett, Ingo Molnar, Thomas Gleixner,
	Eric Biederman, H. Peter Anvin, Boris Ostrovsky,
	Paul E. McKenney, Dave Young, Andrew Morton, David Vrabel
  Cc: moderated list:XEN HYPERVISOR INTERFACE,
	maintainer:X86 ARCHITECTURE 32-BIT AND 64-BIT, open list:KEXEC,
	open list

Hello all,

this patch series makes it possible to save a kernel crash dump when the
kernel command line includes "crash_kexec_post_notifiers". There might
be other approaches, but mine has the advantage that no new sysctl is
required, and the behaviour is the same whether panic notifiers are run
or not: If you load a crash kernel with kexec, it will be used, otherwise
the hypervisor facility is used (using a hypercall).

Feedback welcome!

Petr T

---

Petr Tesarik (2):
      Add a kexec_crash_loaded() function
      Allow kdump with crash_kexec_post_notifiers


 arch/x86/xen/enlighten.c |    3 ++-
 include/linux/kexec.h    |    2 ++
 kernel/kexec_core.c      |    5 +++++
 kernel/ksysfs.c          |    2 +-
 4 files changed, 10 insertions(+), 2 deletions(-)

--
Signature

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

* [PATCH 1/2] Add a kexec_crash_loaded() function
  2016-07-13 12:19 [PATCH 0/2] Allow crash dumps with crash_kexec_post_notifiers Petr Tesarik
@ 2016-07-13 12:19 ` Petr Tesarik
  2016-07-13 12:52   ` Josh Triplett
  2016-07-13 12:20 ` [PATCH 2/2] Allow kdump with crash_kexec_post_notifiers Petr Tesarik
  2016-07-13 12:27 ` [PATCH 0/2] Allow crash dumps " Petr Tesarik
  2 siblings, 1 reply; 8+ messages in thread
From: Petr Tesarik @ 2016-07-13 12:19 UTC (permalink / raw)
  To: Juergen Gross, Josh Triplett, Ingo Molnar, Thomas Gleixner,
	Eric Biederman, H. Peter Anvin, Boris Ostrovsky,
	Paul E. McKenney, Dave Young, Andrew Morton, David Vrabel
  Cc: moderated list:XEN HYPERVISOR INTERFACE,
	maintainer:X86 ARCHITECTURE 32-BIT AND 64-BIT, open list:KEXEC,
	open list

Provide a wrapper function to be used by kernel code to check whether
a crash kernel is loaded. It returns the same value that can be seen
in /sys/kernel/kexec_crash_loaded by userspace programs.

I'm exporting the function, because it will be used by Xen, and it is
possible to compile Xen modules separately to enable the use of PV
drivers with unmodified bare-metal kernels.

Signed-off-by: Petr Tesarik <ptesarik@suse.com>
---
 include/linux/kexec.h |    2 ++
 kernel/kexec_core.c   |    6 ++++++
 kernel/ksysfs.c       |    2 +-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index e8acb2b..d461d02 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -228,6 +228,7 @@ extern void *kexec_purgatory_get_symbol_addr(struct kimage *image,
 extern void __crash_kexec(struct pt_regs *);
 extern void crash_kexec(struct pt_regs *);
 int kexec_should_crash(struct task_struct *);
+int kexec_crash_loaded(void);
 void crash_save_cpu(struct pt_regs *regs, int cpu);
 void crash_save_vmcoreinfo(void);
 void arch_crash_save_vmcoreinfo(void);
@@ -324,6 +325,7 @@ struct task_struct;
 static inline void __crash_kexec(struct pt_regs *regs) { }
 static inline void crash_kexec(struct pt_regs *regs) { }
 static inline int kexec_should_crash(struct task_struct *p) { return 0; }
+static inline int kexec_crash_loaded(void) { return 0; }
 #define kexec_in_progress false
 #endif /* CONFIG_KEXEC_CORE */
 
diff --git a/kernel/kexec_core.c b/kernel/kexec_core.c
index 56b3ed0..a303dce 100644
--- a/kernel/kexec_core.c
+++ b/kernel/kexec_core.c
@@ -95,6 +95,12 @@ int kexec_should_crash(struct task_struct *p)
 	return 0;
 }
 
+int kexec_crash_loaded(void)
+{
+	return !!kexec_crash_image;
+}
+EXPORT_SYMBOL_GPL(kexec_crash_loaded);
+
 /*
  * When kexec transitions to the new kernel there is a one-to-one
  * mapping between physical and virtual addresses.  On processors
diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index 152da4a..bf9fc9d 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -101,7 +101,7 @@ KERNEL_ATTR_RO(kexec_loaded);
 static ssize_t kexec_crash_loaded_show(struct kobject *kobj,
 				       struct kobj_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%d\n", !!kexec_crash_image);
+	return sprintf(buf, "%d\n", kexec_crash_loaded());
 }
 KERNEL_ATTR_RO(kexec_crash_loaded);
 

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

* [PATCH 2/2] Allow kdump with crash_kexec_post_notifiers
  2016-07-13 12:19 [PATCH 0/2] Allow crash dumps with crash_kexec_post_notifiers Petr Tesarik
  2016-07-13 12:19 ` [PATCH 1/2] Add a kexec_crash_loaded() function Petr Tesarik
@ 2016-07-13 12:20 ` Petr Tesarik
  2016-07-13 12:53   ` [Xen-devel] " David Vrabel
  2016-07-13 12:27 ` [PATCH 0/2] Allow crash dumps " Petr Tesarik
  2 siblings, 1 reply; 8+ messages in thread
From: Petr Tesarik @ 2016-07-13 12:20 UTC (permalink / raw)
  To: Juergen Gross, Josh Triplett, Ingo Molnar, Thomas Gleixner,
	Eric Biederman, H. Peter Anvin, Boris Ostrovsky,
	Paul E. McKenney, Dave Young, Andrew Morton, David Vrabel
  Cc: moderated list:XEN HYPERVISOR INTERFACE,
	maintainer:X86 ARCHITECTURE 32-BIT AND 64-BIT, open list:KEXEC,
	open list

If a crash kernel is loaded, do not crash the running domain. This is
needed if the kernel is loaded with crash_kexec_post_notifiers, because
panic notifiers are run before __crash_kexec() in that case, and this
Xen hook prevents its being called later.

Signed-off-by: Petr Tesarik <ptesarik@suse.com>
---
 arch/x86/xen/enlighten.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
index 760789a..6e3e7c6 100644
--- a/arch/x86/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
@@ -1325,7 +1325,8 @@ static void xen_crash_shutdown(struct pt_regs *regs)
 static int
 xen_panic_event(struct notifier_block *this, unsigned long event, void *ptr)
 {
-	xen_reboot(SHUTDOWN_crash);
+	if (!kexec_crash_loaded())
+		xen_reboot(SHUTDOWN_crash);
 	return NOTIFY_DONE;
 }
 

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

* Re: [PATCH 0/2] Allow crash dumps with crash_kexec_post_notifiers
  2016-07-13 12:19 [PATCH 0/2] Allow crash dumps with crash_kexec_post_notifiers Petr Tesarik
  2016-07-13 12:19 ` [PATCH 1/2] Add a kexec_crash_loaded() function Petr Tesarik
  2016-07-13 12:20 ` [PATCH 2/2] Allow kdump with crash_kexec_post_notifiers Petr Tesarik
@ 2016-07-13 12:27 ` Petr Tesarik
  2 siblings, 0 replies; 8+ messages in thread
From: Petr Tesarik @ 2016-07-13 12:27 UTC (permalink / raw)
  To: Juergen Gross, Josh Triplett, Ingo Molnar, Thomas Gleixner,
	Eric Biederman, H. Peter Anvin, Boris Ostrovsky,
	Paul E. McKenney, Dave Young, Andrew Morton, David Vrabel
  Cc: moderated list:XEN HYPERVISOR INTERFACE,
	maintainer:X86 ARCHITECTURE 32-BIT AND 64-BIT, open list:KEXEC,
	open list

On Wed, 13 Jul 2016 14:19:50 +0200
Petr Tesarik <ptesarik@suse.com> wrote:

> Hello all,
> 
> this patch series makes it possible to save a kernel crash dump when the
> kernel command line includes "crash_kexec_post_notifiers".

Oh ... I forgot to add: This only applies to running Linux under Xen.
If you run on bare metal, you can always save the dump already, as you
certainly know.

Petr T

> There might
> be other approaches, but mine has the advantage that no new sysctl is
> required, and the behaviour is the same whether panic notifiers are run
> or not: If you load a crash kernel with kexec, it will be used, otherwise
> the hypervisor facility is used (using a hypercall).
> 
> Feedback welcome!
> 
> Petr T
> 
> ---
> 
> Petr Tesarik (2):
>       Add a kexec_crash_loaded() function
>       Allow kdump with crash_kexec_post_notifiers
> 
> 
>  arch/x86/xen/enlighten.c |    3 ++-
>  include/linux/kexec.h    |    2 ++
>  kernel/kexec_core.c      |    5 +++++
>  kernel/ksysfs.c          |    2 +-
>  4 files changed, 10 insertions(+), 2 deletions(-)
> 
> --
> Signature
> 
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec

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

* Re: [PATCH 1/2] Add a kexec_crash_loaded() function
  2016-07-13 12:19 ` [PATCH 1/2] Add a kexec_crash_loaded() function Petr Tesarik
@ 2016-07-13 12:52   ` Josh Triplett
  2016-07-13 13:03     ` Petr Tesarik
  0 siblings, 1 reply; 8+ messages in thread
From: Josh Triplett @ 2016-07-13 12:52 UTC (permalink / raw)
  To: Petr Tesarik
  Cc: Juergen Gross, Ingo Molnar, Thomas Gleixner, Eric Biederman,
	H. Peter Anvin, Boris Ostrovsky, Paul E. McKenney, Dave Young,
	Andrew Morton, David Vrabel,
	moderated list:XEN HYPERVISOR INTERFACE,
	maintainer:X86 ARCHITECTURE 32-BIT AND 64-BIT, open list:KEXEC,
	open list

On Wed, Jul 13, 2016 at 02:19:55PM +0200, Petr Tesarik wrote:
> --- a/kernel/kexec_core.c
> +++ b/kernel/kexec_core.c
> @@ -95,6 +95,12 @@ int kexec_should_crash(struct task_struct *p)
>  	return 0;
>  }
>  
> +int kexec_crash_loaded(void)
> +{
> +	return !!kexec_crash_image;
> +}

Nit: this function should return bool rather than int, since it
effectively returns true/false.

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

* Re: [Xen-devel] [PATCH 2/2] Allow kdump with crash_kexec_post_notifiers
  2016-07-13 12:20 ` [PATCH 2/2] Allow kdump with crash_kexec_post_notifiers Petr Tesarik
@ 2016-07-13 12:53   ` David Vrabel
  2016-08-01 11:55     ` Jan Beulich
  0 siblings, 1 reply; 8+ messages in thread
From: David Vrabel @ 2016-07-13 12:53 UTC (permalink / raw)
  To: Petr Tesarik, Juergen Gross, Josh Triplett, Ingo Molnar,
	Thomas Gleixner, Eric Biederman, H. Peter Anvin, Boris Ostrovsky,
	Paul E. McKenney, Dave Young, Andrew Morton, David Vrabel
  Cc: moderated list:XEN HYPERVISOR INTERFACE,
	maintainer:X86 ARCHITECTURE 32-BIT AND 64-BIT, open list:KEXEC,
	open list

On 13/07/16 13:20, Petr Tesarik wrote:
> If a crash kernel is loaded, do not crash the running domain. This is
> needed if the kernel is loaded with crash_kexec_post_notifiers, because
> panic notifiers are run before __crash_kexec() in that case, and this
> Xen hook prevents its being called later.

Prioritising the in-kernel kexec image over the hypervisor one seems
sensible behaviour to me.

Reviewed-by: David Vrabel <david.vrabel@citrix.com>

David

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

* Re: [PATCH 1/2] Add a kexec_crash_loaded() function
  2016-07-13 12:52   ` Josh Triplett
@ 2016-07-13 13:03     ` Petr Tesarik
  0 siblings, 0 replies; 8+ messages in thread
From: Petr Tesarik @ 2016-07-13 13:03 UTC (permalink / raw)
  To: Josh Triplett
  Cc: Juergen Gross, Ingo Molnar, Thomas Gleixner, Eric Biederman,
	H. Peter Anvin, Boris Ostrovsky, Paul E. McKenney, Dave Young,
	Andrew Morton, David Vrabel,
	moderated list:XEN HYPERVISOR INTERFACE,
	maintainer:X86 ARCHITECTURE 32-BIT AND 64-BIT, open list:KEXEC,
	open list

On Wed, 13 Jul 2016 05:52:33 -0700
Josh Triplett <josh@joshtriplett.org> wrote:

> On Wed, Jul 13, 2016 at 02:19:55PM +0200, Petr Tesarik wrote:
> > --- a/kernel/kexec_core.c
> > +++ b/kernel/kexec_core.c
> > @@ -95,6 +95,12 @@ int kexec_should_crash(struct task_struct *p)
> >  	return 0;
> >  }
> >  
> > +int kexec_crash_loaded(void)
> > +{
> > +	return !!kexec_crash_image;
> > +}
> 
> Nit: this function should return bool rather than int, since it
> effectively returns true/false.

I thought about this for a moment. Since the return value should also
be used for the corresponding sysctl, which is an integer, I wasn't
sure if bool is the correct type, especially since other boolean
functions in kexec.h also return int... But that could be legacy.

I've got no problem changing the type to 'bool' if that's what it takes.

Petr T

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

* Re: [Xen-devel] [PATCH 2/2] Allow kdump with crash_kexec_post_notifiers
  2016-07-13 12:53   ` [Xen-devel] " David Vrabel
@ 2016-08-01 11:55     ` Jan Beulich
  0 siblings, 0 replies; 8+ messages in thread
From: Jan Beulich @ 2016-08-01 11:55 UTC (permalink / raw)
  To: David Vrabel, Petr Tesarik
  Cc: JoshTriplett, maintainer:X86 ARCHITECTURE 32-BIT AND64-BIT,
	ThomasGleixner, Andrew Morton, Paul E. McKenney, open list:KEXEC,
	moderated list:XEN HYPERVISOR INTERFACE, Boris Ostrovsky,
	Dave Young, Ingo Molnar, Juergen Gross, open list,
	Eric Biederman, H.Peter Anvin

>>> On 13.07.16 at 14:53, <david.vrabel@citrix.com> wrote:
> On 13/07/16 13:20, Petr Tesarik wrote:
>> If a crash kernel is loaded, do not crash the running domain. This is
>> needed if the kernel is loaded with crash_kexec_post_notifiers, because
>> panic notifiers are run before __crash_kexec() in that case, and this
>> Xen hook prevents its being called later.
> 
> Prioritising the in-kernel kexec image over the hypervisor one seems
> sensible behaviour to me.

For HVM guests certainly; does loading of an in-kernel crash kernel
properly fail for PV guests (and namely PV Dom0), or does such a
setup work nowadays?

Jan

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

end of thread, other threads:[~2016-08-01 11:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-13 12:19 [PATCH 0/2] Allow crash dumps with crash_kexec_post_notifiers Petr Tesarik
2016-07-13 12:19 ` [PATCH 1/2] Add a kexec_crash_loaded() function Petr Tesarik
2016-07-13 12:52   ` Josh Triplett
2016-07-13 13:03     ` Petr Tesarik
2016-07-13 12:20 ` [PATCH 2/2] Allow kdump with crash_kexec_post_notifiers Petr Tesarik
2016-07-13 12:53   ` [Xen-devel] " David Vrabel
2016-08-01 11:55     ` Jan Beulich
2016-07-13 12:27 ` [PATCH 0/2] Allow crash dumps " Petr Tesarik

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).