Skip to content

Commit

Permalink
kexec: add a kexec_crash_loaded() function
Browse files Browse the repository at this point in the history
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.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Petr Tesarik <[email protected]>
Cc: Juergen Gross <[email protected]>
Cc: Josh Triplett <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Eric Biederman <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: Dave Young <[email protected]>
Cc: David Vrabel <[email protected]>
Cc: Vivek Goyal <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
ptesarik authored and torvalds committed Aug 2, 2016
1 parent b26e27d commit 21db79e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/linux/kexec.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,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);
Expand Down Expand Up @@ -364,6 +365,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 */

Expand Down
6 changes: 6 additions & 0 deletions kernel/kexec_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion kernel/ksysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 21db79e

Please sign in to comment.