Skip to contentSkip to conversation

sh: add kexec jump support V2

PATCH In review Magnus Damm 3 participants 4 messages Mar 18, 2009 – Mar 26, 2009 SuperH

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sh: add kexec jump support V2

From: Magnus Damm <[email protected]>

Add kexec jump support to the SuperH architecture V2.

Similar to the x86 implementation, with the following exceptions:

- Instead of separating the assembly code flow into two parts for regular kexec and kexec jump we use a single code path. In the assembly snippet regular kexec is just kexec jump that never comes back.

- Instead of using a swap page when moving data between pages the page copy assembly routine has been modified to exchange the data between the pages using registers.

- We walk the page list twice in machine_kexec() to do and undo physical to virtual address conversion.

---

Changes since V1:
- rebased on top of new vbr and no segment patch
- restore vbr
- make sure exceptions are unblocked
- added code to convert page list back to physical addresses

Patches for kexec-tools have been merged earlier today.

 arch/sh/Kconfig                  |    7 +
 arch/sh/kernel/machine_kexec.c   |   32 +++++-
 arch/sh/kernel/relocate_kernel.S |  195 ++++++++++++++++++++++++++++++++------
 3 files changed, 202 insertions(+), 32 deletions(-)
arch/sh/Kconfig +7 -0
@@ -558,6 +558,13 @@ config CRASH_DUMP
 
 	  For more details see Documentation/kdump/kdump.txt
 
+config KEXEC_JUMP
+	bool "kexec jump (EXPERIMENTAL)"
+	depends on SUPERH32 && KEXEC && HIBERNATION && EXPERIMENTAL
+	help
+	  Jump between original kernel and kexeced kernel and invoke
+	  code via KEXEC
+
 config SECCOMP
 	bool "Enable seccomp to safely compute untrusted bytecode"
 	depends on PROC_FS
arch/sh/kernel/machine_kexec.c +27 -5
@@ -14,20 +14,21 @@
 #include <linux/delay.h>
 #include <linux/reboot.h>
 #include <linux/numa.h>
+#include <linux/suspend.h>
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
 #include <asm/mmu_context.h>
 #include <asm/io.h>
 #include <asm/cacheflush.h>
 
-typedef NORET_TYPE void (*relocate_new_kernel_t)(
-				unsigned long indirection_page,
-				unsigned long reboot_code_buffer,
-				unsigned long start_address) ATTRIB_NORET;
+typedef void (*relocate_new_kernel_t)(unsigned long indirection_page,
+				      unsigned long reboot_code_buffer,
+				      unsigned long start_address);
 
 extern const unsigned char relocate_new_kernel[];
 extern const unsigned int relocate_new_kernel_size;
 extern void *gdb_vbr_vector;
+extern void *vbr_base;
 
 void machine_shutdown(void)
 {
@@ -72,7 +73,6 @@ static void kexec_info(struct kimage *im
  */
 void machine_kexec(struct kimage *image)
 {
-
 	unsigned long page_list;
 	unsigned long reboot_code_buffer;
 	relocate_new_kernel_t rnk;
@@ -92,6 +92,11 @@ void machine_kexec(struct kimage *image)
 			*ptr = (unsigned long) phys_to_virt(*ptr);
 	}
 
+#ifdef CONFIG_KEXEC_JUMP
+	if (image->preserve_context)
+		save_processor_state();
+#endif
+
 	/* Interrupts aren't acceptable while we reboot */
 	local_irq_disable();
 
@@ -117,6 +122,23 @@ void machine_kexec(struct kimage *image)
 	/* now call it */
 	rnk = (relocate_new_kernel_t) reboot_code_buffer;
 	(*rnk)(page_list, reboot_code_buffer, image->start);
+
+#ifdef CONFIG_KEXEC_JUMP
+	asm volatile("ldc %0, vbr" : : "r" (&vbr_base) : "memory");
+	local_irq_disable();
+	clear_bl_bit();
+	if (image->preserve_context)
+		restore_processor_state();
+
+	/* Convert page list back to physical addresses, what a mess. */
+	for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE);
+	     ptr = (*ptr & IND_INDIRECTION) ?
+	       phys_to_virt(*ptr & PAGE_MASK) : ptr + 1) {
+		if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION ||
+		    *ptr & IND_DESTINATION)
+			*ptr = virt_to_phys(*ptr);
+	}
+#endif
 }
 
 void arch_crash_save_vmcoreinfo(void)
arch/sh/kernel/relocate_kernel.S +168 -27

240 lines not on this page · raw message

#1 lore raw

Hi,all.

I'm sorry that I could not check this patch.

This patch became compilation error in SH2/SH2A, because there are not a spc register and a ssr register in SH2.[0]
I don't have environment of SH2 and I don't know whether I work by these measures.
Do you have somebody, environment?

[0]: http://kisskb.ellerman.id.au/kisskb/buildresult/271654/

Best regards,
Nobuhiro

Quoted 20 lines · Magnus Damm

From: Magnus Damm <[email protected]>

Add kexec jump support to the SuperH architecture V2.

Similar to the x86 implementation, with the following exceptions:

- Instead of separating the assembly code flow into two parts for regular kexec and kexec jump we use a single code path. In the assembly snippet regular kexec is just kexec jump that never comes back.

- Instead of using a swap page when moving data between pages the page copy assembly routine has been modified to exchange the data between the pages using registers.

- We walk the page list twice in machine_kexec() to do and undo physical to virtual address conversion.

#2 lore raw
In reply to Magnus Damm
Quoted 4 lines · Nobuhiro Iwamatsu

Hi,all.

I'm sorry that I could not check this patch.

Quoted 8 lines

This patch became compilation error in SH2/SH2A, because there are not a spc register and a ssr register in SH2.[0]
I don't have environment of SH2 and I don't know whether I work by these measures.
Do you have somebody, environment?

[0]: http://kisskb.ellerman.id.au/kisskb/buildresult/271654/

Kexec is not likely to work on nommu anyways, given that all of the tools today assume ELF. I suspect we should just make it depend on MMU and be done with it for now.

#3 lore raw
In reply to Magnus Damm
Quoted 11 lines · Paul Mundt
Quoted 10 lines · Nobuhiro Iwamatsu

Hi,all.

I'm sorry that I could not check this patch.

This patch became compilation error in SH2/SH2A, because there are not a spc register and a ssr register in SH2.[0]
I don't have environment of SH2 and I don't know whether I work by these measures.
Do you have somebody, environment?

Quoted 6 lines
Quoted 2 lines

[0]: http://kisskb.ellerman.id.au/kisskb/buildresult/271654/

Kexec is not likely to work on nommu anyways, given that all of the tools today assume ELF. I suspect we should just make it depend on MMU and be done with it for now.

OK, I understood.
I will send patch for this topic.

Best regards,
Nobuhiro