Skip to contentSkip to conversation

kexec for 2.5.46

PATCH Eric W. Biederman 2 participants 4 messages Nov 6, 2002 – Nov 11, 2002 kexec

lore
Share & tools
lore
#0 lore raw

Linus please apply,

sys_kexec is a system call that allows you to boot another kernel directly from Linux and it enables all kinds of interesting things.

It is currently marked as experimental because not all the kinks in using it have been working out. The core code itself is solid and stable.

This code was first submitted before the feature freeze deadline, and there was another patch to 2.5.45 that conflicted because it also added a system call so for lack of any feedback I will assume that was why this patch was dropped.

There has been some question if this code could be made modular, or if there is a better interface than a syscall for it. Currently I have not seen a proposal with as few downsides as a syscall, nor have I seen clear direction another interface is preferred. I guess a kexecfs might be cleaner, though I would be surprised if the binary code size was smaller...

The code intimately knows how the kernel is running the cpu and it uses that information to reliably transition the cpu to another state, when jumping to the new kernel, at the very least how paging is currently done needs to be modified. Half of the functions sys_kexec calls are not exported from the kernel, so the code cannot be built as module, nor do I think it is a reasonable to desire to do so.

Until I get some kind of clear signal I will continue to retransmit assuming my email messages were just dropped.

Eric

 MAINTAINERS                        |    7 
 arch/i386/Kconfig                  |   17 +
 arch/i386/kernel/Makefile          |    1 
 arch/i386/kernel/entry.S           |    1 
 arch/i386/kernel/machine_kexec.c   |  142 +++++++++
 arch/i386/kernel/relocate_kernel.S |   99 ++++++
 include/asm-i386/kexec.h           |   25 +
 include/asm-i386/unistd.h          |    1 
 include/linux/kexec.h              |   48 +++
 kernel/Makefile                    |    1 
 kernel/kexec.c                     |  577 +++++++++++++++++++++++++++++++++++++
 kernel/sys.c                       |   61 +++
 12 files changed, 980 insertions
MAINTAINERS +7 -0
diff -uNr linux-2.5.46/MAINTAINERS linux-2.5.46.x86kexec/MAINTAINERS
@@ -941,6 +941,13 @@
 W:	http://www.cse.unsw.edu.au/~neilb/patches/linux-devel/
 S:	Maintained
 
+KEXEC
+P:	Eric Biederman
+M:	[email protected]
+M:	[email protected]
+L:	[email protected]
+S:	Maintained
+
 LANMEDIA WAN CARD DRIVER
 P:	Andrew Stanley-Jones
 M:	[email protected]
arch/i386/Kconfig +17 -0
diff -uNr linux-2.5.46/arch/i386/Kconfig linux-2.5.46.x86kexec/arch/i386/Kconfig
@@ -785,6 +785,23 @@
 	depends on (SMP || PREEMPT) && X86_CMPXCHG
 	default y
 
+config KEXEC
+	bool "kexec system call (EXPERIMENTAL)"
+	depends on EXPERIMENTAL
+	help
+	  kexec is a system call that implements the ability to  shutdown your
+	  current kernel, and to start another kernel.  It is like a reboot
+	  but it is indepedent of the system firmware.   And like a reboot the
+	  you can start any kernel with it not just Linux.  
+	
+	  The name comes from the similiarity to the exec system call. 
+	
+	  It is on an going process to be certain the hardware in a machine
+	  is properly shutdown, so do not be surprised if this code does not
+	  initially work for you.  It may help to enable device hotplugging
+	  support.  As of this writing the exact hardware interface is
+	  strongly in flux, so no good recommendation can be made.
+
 endmenu
 
 
arch/i386/kernel/Makefile +1 -0
diff -uNr linux-2.5.46/arch/i386/kernel/Makefile linux-2.5.46.x86kexec/arch/i386/kernel/Makefile
@@ -25,6 +25,7 @@
 obj-$(CONFIG_X86_MPPARSE)	+= mpparse.o
 obj-$(CONFIG_X86_LOCAL_APIC)	+= apic.o nmi.o
 obj-$(CONFIG_X86_IO_APIC)	+= io_apic.o
+obj-$(CONFIG_KEXEC)		+= machine_kexec.o relocate_kernel.o
 obj-$(CONFIG_SOFTWARE_SUSPEND)	+= suspend.o
 obj-$(CONFIG_X86_NUMAQ)		+= numaq.o
 obj-$(CONFIG_PROFILING)		+= profile.o
arch/i386/kernel/entry.S +1 -0
diff -uNr linux-2.5.46/arch/i386/kernel/entry.S linux-2.5.46.x86kexec/arch/i386/kernel/entry.S
@@ -741,6 +741,7 @@
 	.long sys_epoll_ctl	/* 255 */
 	.long sys_epoll_wait
  	.long sys_remap_file_pages
+	.long sys_kexec
 
 
 	.rept NR_syscalls-(.-sys_call_table)/4
arch/i386/kernel/machine_kexec.c +142 -0

142 lines not on this page · raw message

arch/i386/kernel/relocate_kernel.S +99 -0

99 lines not on this page · raw message

include/asm-i386/kexec.h +25 -0
diff -uNr linux-2.5.46/include/asm-i386/kexec.h linux-2.5.46.x86kexec/include/asm-i386/kexec.h
@@ -0,0 +1,25 @@
+#ifndef _I386_KEXEC_H
+#define _I386_KEXEC_H
+
+#include <asm/fixmap.h>
+
+/*
+ * KEXEC_SOURCE_MEMORY_LIMIT maximum page get_free_page can return.
+ * I.e. Maximum page that is mapped directly into kernel memory,
+ * and kmap is not required.
+ *
+ * Someone correct me if FIXADDR_START - PAGEOFFSET is not the correct
+ * calculation for the amount of memory directly mappable into the
+ * kernel memory space.
+ */
+
+/* Maximum physical address we can use pages from */
+#define KEXEC_SOURCE_MEMORY_LIMIT (FIXADDR_START - PAGE_OFFSET) 
+/* Maximum address we can reach in physical address mode */
+#define KEXEC_DESTINATION_MEMORY_LIMIT (-1UL)
+
+#define KEXEC_REBOOT_CODE_SIZE	4096
+#define KEXEC_REBOOT_CODE_ALIGN 0
+
+
+#endif /* _I386_KEXEC_H */
include/asm-i386/unistd.h +1 -0
diff -uNr linux-2.5.46/include/asm-i386/unistd.h linux-2.5.46.x86kexec/include/asm-i386/unistd.h
@@ -262,6 +262,7 @@
 #define __NR_sys_epoll_ctl	255
 #define __NR_sys_epoll_wait	256
 #define __NR_remap_file_pages	257
+#define __NR_sys_kexec		258
 
 
 /* user-visible error numbers are in the range -1 - -124: see <asm-i386/errno.h> */
include/linux/kexec.h +48 -0

48 lines not on this page · raw message

kernel/Makefile +1 -0
diff -uNr linux-2.5.46/kernel/Makefile linux-2.5.46.x86kexec/kernel/Makefile
@@ -21,6 +21,7 @@
 obj-$(CONFIG_CPU_FREQ) += cpufreq.o
 obj-$(CONFIG_BSD_PROCESS_ACCT) += acct.o
 obj-$(CONFIG_SOFTWARE_SUSPEND) += suspend.o
+obj-$(CONFIG_KEXEC) += kexec.o
 
 ifneq ($(CONFIG_IA64),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/kexec.c +577 -0

577 lines not on this page · raw message

kernel/sys.c +61 -0

73 lines not on this page · raw message

#1 lore raw
Quoted 1 line · Eric W. Biederman

Linus please apply,

FYI: patch applied cleanly for me.

After fudging kexec-tools-1.4 to correct for the new syscall number:

    # ./kexec-1.4+ -debug ./kexec_test-1.4
    Synchronizing SCSI caches: 
    Shutting down devices
    Starting new kernel
    kexec_test 1.4 starting...
    eax: 0E1FB007 ebx: 00001078 ecx: 00000000 edx: 00000000
    esi: 00000000 edi: 00000000 esp: 00000000 ebp: 00000000
    idt: 00000000 C0000000
    gdt: 00000000 C0000000
    Switching descriptors.
    Descriptors changed.
    In real mode.
    <hang>

It does not make it to the "Interrupts enabled." print, so it is probably going wacko at the "sti."

As before, the system:
% lspci -tv

-+-[01]---03.0  Adaptec AIC-7892P U160/m
 \-[00]-+-00.0  ServerWorks CNB20LE Host Bridge
        +-00.1  ServerWorks CNB20LE Host Bridge
        +-01.0  S3 Inc. Savage 4
        +-09.0  Intel Corp. 82557/8/9 [Ethernet Pro 100]
        +-0f.0  ServerWorks OSB4 South Bridge
        +-0f.1  ServerWorks OSB4 IDE Controller
        \-0f.2  ServerWorks OSB4/CSB5 OHCI USB Controller

% cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 8
model name : Pentium III (Coppermine)
stepping : 10
cpu MHz : 799.717
cache size : 256 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov
pat pse36 mmx fxsr sse
bogomips : 1576.96

#2 lore raw
Quoted 11 lines · Andy Pfiffer
Quoted 1 line · Eric W. Biederman

Linus please apply,

FYI: patch applied cleanly for me.

After fudging kexec-tools-1.4 to correct for the new syscall number:

    <hang>

It does not make it to the "Interrupts enabled." print, so it is probably going wacko at the "sti."

Thanks for the report. Linus has asked for some changes, but has ok'd. the basic idea the thread topic on linux-kernel was:
"Re: [lkcd-devel] Re: What's left over."
I am going to focus on getting those changes made, and then I concentrate on why things fail in strange ways for various people.

The primary change is that the mcore people need a 2 stage kexec. 1 load the kernel. 2 later actually start it. This allows the second kernel to be started when the first kernel panics. Allowing for nice crash dumps and perhaps some other interesting debugging techniques.

Talk to you later...

Eric

#3 lore raw
In reply to Andy Pfiffer
Quoted 7 lines · Andy Pfiffer
Quoted 1 line · Eric W. Biederman

Linus please apply,

FYI: patch applied cleanly for me.

After fudging kexec-tools-1.4 to correct for the new syscall number:

O.k. After looking more this sounds like all of the systems of being uniprocessor but still having apic support enabled. And since I don't have the apic shutdown code in there it doesn't work.

Eric