Skip to contentSkip to conversation

Kexec jump: Kexec jump

PATCH In review Huang, Ying 3 participants 8 messages Jul 11, 2007 – Jul 13, 2007

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 Kexec jump: Kexec jump

This patch provide the kexec based implementation of hibernation image operation. Now, only jumping between original kernel and kexeced kernel is supported, real image write/read/check will be provided in next patches.

 arch/i386/kernel/Makefile        |    1 
 arch/i386/kernel/kexec_jump.S    |   73 ++++++++++++++++++++++++++
 arch/i386/kernel/machine_kexec.c |   58 +++++++++++++++++++++
 include/asm-i386/kexec.h         |    4 +
 include/linux/kexec.h            |    8 ++
 kernel/kexec.c                   |   25 +++++++++
 kernel/ksysfs.c                  |   12 ++++
 kernel/power/Kconfig             |    8 ++
 kernel/power/Makefile            |    1 
 kernel/power/kexec.c             |  106 +++++++++++++++++++++++++++++++++++++++
 10 files changed, 296 insertions(+)
arch/i386/kernel/Makefile +1 -0
Index: linux-2.6/arch/i386/kernel/Makefile
===================================================================
@@ -27,6 +27,7 @@
 obj-$(CONFIG_X86_REBOOTFIXUPS)	+= reboot_fixups.o
 obj-$(CONFIG_KEXEC)		+= machine_kexec.o relocate_kernel.o crash.o
 obj-$(CONFIG_CRASH_DUMP)	+= crash_dump.o
+obj-$(CONFIG_KEXEC_HIBERNATION)	+= kexec_jump.o
 obj-$(CONFIG_X86_NUMAQ)		+= numaq.o
 obj-$(CONFIG_X86_SUMMIT_NUMA)	+= summit.o
 obj-$(CONFIG_KPROBES)		+= kprobes.o
arch/i386/kernel/machine_kexec.c +58 -0

67 lines not on this page · raw message

include/asm-i386/kexec.h +4 -0
Index: linux-2.6/include/asm-i386/kexec.h
===================================================================
@@ -94,6 +94,10 @@
 		unsigned long start_address,
 		unsigned int has_pae) ATTRIB_NORET;
 
+#ifdef CONFIG_KEXEC_HIBERNATION
+extern asmlinkage int kexec_real_jump(int save_only, void *buf);
+#endif
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* _I386_KEXEC_H */
include/linux/kexec.h +8 -0
Index: linux-2.6/include/linux/kexec.h
===================================================================
@@ -161,4 +161,12 @@
 static inline void crash_kexec(struct pt_regs *regs) { }
 static inline int kexec_should_crash(struct task_struct *p) { return 0; }
 #endif /* CONFIG_KEXEC */
+
+#ifdef CONFIG_KEXEC_HIBERNATION
+#define KEXEC_JUMP_TYPE_EXEC 0
+#define KEXEC_JUMP_TYPE_JUMP 1
+extern int kexec_jump(int jump_type);
+extern unsigned long kexec_get_jump_buf_pfn(int alloc);
+extern void kexec_restore_backup(void);
+#endif
 #endif /* LINUX_KEXEC_H */
kernel/kexec.c +25 -0
Index: linux-2.6/kernel/kexec.c
===================================================================
@@ -1135,3 +1135,28 @@
 	return 0;
 }
 module_init(crash_notes_memory_init)
+
+#ifdef CONFIG_KEXEC_HIBERNATION
+static unsigned long kexec_jump_buf_pfn;
+
+static int __init parse_kexec_jump_buf_pfn(char *arg)
+{
+	if (!arg)
+		return -EINVAL;
+
+	kexec_jump_buf_pfn = memparse(arg, &arg);
+	return 0;
+}
+early_param("kexec_jump_buf_pfn", parse_kexec_jump_buf_pfn);
+
+unsigned long kexec_get_jump_buf_pfn(int alloc)
+{
+	struct page *jump_buf_page;
+
+	if (!kexec_jump_buf_pfn && alloc) {
+		jump_buf_page = alloc_page(GFP_KERNEL);
+		kexec_jump_buf_pfn = page_to_pfn(jump_buf_page);
+	}
+	return kexec_jump_buf_pfn;
+}
+#endif /* CONFIG_KEXEC_HIBERNATION */
kernel/ksysfs.c +12 -0
Index: linux-2.6/kernel/ksysfs.c
===================================================================
@@ -60,6 +60,15 @@
 	return sprintf(page, "%d\n", !!kexec_crash_image);
 }
 KERNEL_ATTR_RO(kexec_crash_loaded);
+
+#ifdef CONFIG_KEXEC_HIBERNATION
+static ssize_t kexec_jump_buf_pfn_show(struct kset *kset, char *page)
+{
+	return sprintf(page, "0x%lx\n", kexec_get_jump_buf_pfn(1));
+}
+
+KERNEL_ATTR_RO(kexec_jump_buf_pfn);
+#endif
 #endif /* CONFIG_KEXEC */
 
 decl_subsys(kernel, NULL, NULL);
@@ -73,6 +82,9 @@
 #ifdef CONFIG_KEXEC
 	&kexec_loaded_attr.attr,
 	&kexec_crash_loaded_attr.attr,
+#ifdef CONFIG_KEXEC_HIBERNATION
+	&kexec_jump_buf_pfn_attr.attr,
+#endif
 #endif
 	NULL
 };
kernel/power/Kconfig +8 -0
Index: linux-2.6/kernel/power/Kconfig
===================================================================
@@ -115,6 +115,14 @@
 
 	  For more information take a look at <file:Documentation/power/swsusp.txt>.
 
+config KEXEC_HIBERNATION
+	bool "Kexec based software suspend (hibernation) (EXPERIMENTAL)"
+	depends on EXPERIMENTAL
+	depends on SOFTWARE_SUSPEND && X86_32 && KEXEC
+	---help---
+	  Writing the hibernation image through booting another kernel with
+	  kexec.
+
 config PM_STD_PARTITION
 	string "Default resume partition"
 	depends on SOFTWARE_SUSPEND
kernel/power/Makefile +1 -0
Index: linux-2.6/kernel/power/Makefile
===================================================================
@@ -6,5 +6,6 @@
 obj-y				:= main.o process.o console.o
 obj-$(CONFIG_PM_LEGACY)		+= pm.o
 obj-$(CONFIG_SOFTWARE_SUSPEND)	+= swsusp.o disk.o snapshot.o swap.o user.o
+obj-$(CONFIG_KEXEC_HIBERNATION)	+= kexec.o
 
 obj-$(CONFIG_MAGIC_SYSRQ)	+= poweroff.o
arch/i386/kernel/kexec_jump.S new file +73 -0

73 lines not on this page · raw message

kernel/power/kexec.c new file +106 -0

106 lines not on this page · raw message

#1 lore raw

Hi!

Quoted 4 lines

This patch provide the kexec based implementation of hibernation image operation. Now, only jumping between original kernel and kexeced kernel is supported, real image write/read/check will be provided in next patches.

I'd prefer this not to use hibernation hooks... existing dumping infrastructure should be good enough to write resume image, no?

BTW... is this able to do kdump, then return back to the old kernel? That seems to be similar functionality to hibernation, and I was told it would be very welcome.

Quoted 30 lines
kernel/power/kexec.c new file +30 -0
+static int kexec_suspend(void)
+{
+	int error;
+
+	local_irq_disable();
+	/* At this point, device_suspend() has been called, but *not*
+	 * device_power_down(). We *must* device_power_down() now.
+	 * Otherwise, drivers for some devices (e.g. interrupt controllers)
+	 * become desynchronized with the actual state of the hardware
+	 * at resume time, and evil weirdness ensues.
+	 */
+	error = device_power_down(PMSG_FREEZE);
+	if (error) {
+		printk(KERN_ERR "Some devices failed to power down, aborting suspend\n");
+		goto Enable_irqs;
+	}
+
+	save_processor_state();
+	error = kexec_jump(KEXEC_JUMP_TYPE_EXEC);
+	restore_processor_state();
+
+	/* NOTE:  device_power_up() is just a resume() for devices
+	 * that suspended with irqs off ... no overall powerup.
+	 */
+	device_power_up();
+ Enable_irqs:
+	in_suspend = 0;
+	local_irq_enable();
+	return error;
+}

...

Quoted 11 lines
kernel/power/kexec.c new file +11 -0
+static int kexec_resume(void)
+{
+	int error = 0;
+
+	local_irq_disable();
+	/* NOTE:  device_power_down() is just a suspend() with irqs off;
+	 * it has no special "power things down" semantics
+	 */
+	if (device_power_down(PMSG_PRETHAW))
+		printk(KERN_ERR "Some devices failed to power down, very bad\n");
+	/* We'll ignore saved state, but this gets preempt count (etc) right */

kernel/power/kexec.c line 87

Quoted 10 lines
kernel/power/kexec.c new file +10 -0
+	save_processor_state();
+	kexec_restore_backup();
+	error = kexec_jump(KEXEC_JUMP_TYPE_JUMP);
+	swsusp_free();
+	restore_processor_state();
+	touch_softlockup_watchdog();
+	device_power_up();
+	local_irq_enable();
+	return error;
+}

This seems like mostly generic stuff for going between two kernels, no? I'd prefer it not be hooked into hibernation infrastructure.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#2 lore raw
Quoted 11 lines · Pavel Machek
Quoted 4 lines

This patch provide the kexec based implementation of hibernation image operation. Now, only jumping between original kernel and kexeced kernel is supported, real image write/read/check will be provided in next patches.

I'd prefer this not to use hibernation hooks... existing dumping infrastructure should be good enough to write resume image, no?

BTW... is this able to do kdump, then return back to the old kernel? That seems to be similar functionality to hibernation, and I was told it would be very welcome.

Yes. Just because there are so much similarity between them, many people think they can be merged.

Quoted 47 lines
Quoted 30 lines
kernel/power/kexec.c new file +30 -0
+static int kexec_suspend(void)
+{
+	int error;
+
+	local_irq_disable();
+	/* At this point, device_suspend() has been called, but *not*
+	 * device_power_down(). We *must* device_power_down() now.
+	 * Otherwise, drivers for some devices (e.g. interrupt controllers)
+	 * become desynchronized with the actual state of the hardware
+	 * at resume time, and evil weirdness ensues.
+	 */
+	error = device_power_down(PMSG_FREEZE);
+	if (error) {
+		printk(KERN_ERR "Some devices failed to power down, aborting suspend\n");
+		goto Enable_irqs;
+	}
+
+	save_processor_state();
+	error = kexec_jump(KEXEC_JUMP_TYPE_EXEC);
+	restore_processor_state();
+
+	/* NOTE:  device_power_up() is just a resume() for devices
+	 * that suspended with irqs off ... no overall powerup.
+	 */
+	device_power_up();
+ Enable_irqs:
+	in_suspend = 0;
+	local_irq_enable();
+	return error;
+}

...

Quoted 16 lines
kernel/power/kexec.c new file +16 -0
+static int kexec_resume(void)
+{
+	int error = 0;
+
+	local_irq_disable();
+	/* NOTE:  device_power_down() is just a suspend() with irqs off;
+	 * it has no special "power things down" semantics
+	 */
+	if (device_power_down(PMSG_PRETHAW))
+		printk(KERN_ERR "Some devices failed to power down, very bad\n");
+	/* We'll ignore saved state, but this gets preempt count (etc) right */
+	save_processor_state();
+	kexec_restore_backup();
+	error = kexec_jump(KEXEC_JUMP_TYPE_JUMP);
+	swsusp_free();
+	restore_processor_state();
Quoted 8 lines

kernel/power/kexec.c line 87

Quoted 5 lines
kernel/power/kexec.c new file +5 -0
+	touch_softlockup_watchdog();
+	device_power_up();
+	local_irq_enable();
+	return error;
+}

This seems like mostly generic stuff for going between two kernels, no? I'd prefer it not be hooked into hibernation infrastructure.

Yes. In fact, with device_suspend(...), disable_nonboot_cpus() and enable_nonboot_cpus(), device_resume(...) around the above two functions, the jumping between normal kernel and kexeced kernel can work too. Maybe it is more approriate not to hook the kexec into current hibernation. It seems that there are no much code shared between them except device/CPU state quiescent/save/restore.

Best Regards,
Huang Ying

#3 lore raw
In reply to Pavel Machek
Quoted 11 lines · Pavel Machek
Quoted 4 lines

This patch provide the kexec based implementation of hibernation image operation. Now, only jumping between original kernel and kexeced kernel is supported, real image write/read/check will be provided in next patches.

I'd prefer this not to use hibernation hooks... existing dumping infrastructure should be good enough to write resume image, no?

BTW... is this able to do kdump, then return back to the old kernel? That seems to be similar functionality to hibernation, and I was told it would be very welcome.

Yes. Just because there are so much similarity between them, many people think they can be merged.

Quoted 47 lines
Quoted 30 lines
kernel/power/kexec.c new file +30 -0
+static int kexec_suspend(void)
+{
+	int error;
+
+	local_irq_disable();
+	/* At this point, device_suspend() has been called, but *not*
+	 * device_power_down(). We *must* device_power_down() now.
+	 * Otherwise, drivers for some devices (e.g. interrupt controllers)
+	 * become desynchronized with the actual state of the hardware
+	 * at resume time, and evil weirdness ensues.
+	 */
+	error = device_power_down(PMSG_FREEZE);
+	if (error) {
+		printk(KERN_ERR "Some devices failed to power down, aborting suspend\n");
+		goto Enable_irqs;
+	}
+
+	save_processor_state();
+	error = kexec_jump(KEXEC_JUMP_TYPE_EXEC);
+	restore_processor_state();
+
+	/* NOTE:  device_power_up() is just a resume() for devices
+	 * that suspended with irqs off ... no overall powerup.
+	 */
+	device_power_up();
+ Enable_irqs:
+	in_suspend = 0;
+	local_irq_enable();
+	return error;
+}

...

Quoted 16 lines
kernel/power/kexec.c new file +16 -0
+static int kexec_resume(void)
+{
+	int error = 0;
+
+	local_irq_disable();
+	/* NOTE:  device_power_down() is just a suspend() with irqs off;
+	 * it has no special "power things down" semantics
+	 */
+	if (device_power_down(PMSG_PRETHAW))
+		printk(KERN_ERR "Some devices failed to power down, very bad\n");
+	/* We'll ignore saved state, but this gets preempt count (etc) right */
+	save_processor_state();
+	kexec_restore_backup();
+	error = kexec_jump(KEXEC_JUMP_TYPE_JUMP);
+	swsusp_free();
+	restore_processor_state();
Quoted 8 lines

kernel/power/kexec.c line 87

Quoted 5 lines
kernel/power/kexec.c new file +5 -0
+	touch_softlockup_watchdog();
+	device_power_up();
+	local_irq_enable();
+	return error;
+}

This seems like mostly generic stuff for going between two kernels, no? I'd prefer it not be hooked into hibernation infrastructure.

Yes. In fact, with device_suspend(...), disable_nonboot_cpus() and enable_nonboot_cpus(), device_resume(...) around the above two functions, the jumping between normal kernel and kexeced kernel can work too. Maybe it is more approriate not to hook the kexec into current hibernation. It seems that there are no much code shared between them except device/CPU state quiescent/save/restore.

Best Regards,
Huang Ying

#4 lore raw
In reply to Huang, Ying
Quoted 4 lines · Ying

This patch provide the kexec based implementation of hibernation image operation. Now, only jumping between original kernel and kexeced kernel is supported, real image write/read/check will be provided in next patches.

I know a little about kexec.

Could you please tell me what I should know/read to understand this patch?

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#5 lore raw
Quoted 4 lines · Rafael J. Wysocki

I know a little about kexec.

Could you please tell me what I should know/read to understand this patch?

It is sufficient to read the kernel/kexec.c, arch/i386/kernel/machine_kexec.c and arch/i386/kernel/relocate_kernel.S.

Best Regards,
Huang Ying

#6 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

I know a little about kexec.

Could you please tell me what I should know/read to understand this patch?

It is sufficient to read the kernel/kexec.c, arch/i386/kernel/machine_kexec.c and arch/i386/kernel/relocate_kernel.S.

Best Regards,
Huang Ying

#7 lore raw
In reply to Huang, Ying
Quoted 4 lines · Ying

This patch provide the kexec based implementation of hibernation image operation. Now, only jumping between original kernel and kexeced kernel is supported, real image write/read/check will be provided in next patches.

I know a little about kexec.

Could you please tell me what I should know/read to understand this patch?

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth