summaryrefslogtreecommitdiff
path: root/kexec/kexec.c
AgeCommit message (Collapse)Author
2016-06-08kexec: fix warnings caused by selecting 64-bit file IO on 32-bit platformsRussell King
Fix warnings caused by selecting 64-bit file IO on 32-bit platforms. kexec/kexec.c:710:2: warning: format '%lx' expects argument of type 'long unsigned int', but argument 4 has type 'off_t' [-Wformat] kexec/zlib.c:63:4: warning: format '%ld' expects argument of type 'long int', but argument 4 has type 'off_t' [-Wformat] kexec/kexec-uImage.c:85:3: warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'off_t' [-Wformat] Acked-by: Baoquan He <bhe@redhat.com> Signed-off-by: Russell King <rmk@arm.linux.org.uk> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-12-01Revert "crashdump/x86: Add option to get crash kernel region size"Simon Horman
This reverts commit 8a1aa35a1077b42bc2a2afb05d24b637e1edf2a1.
2015-11-30crashdump/x86: Add option to get crash kernel region sizeDaniel Kiper
Crash kernel region size is available via sysfs on Linux running on bare metal. However, this does not work when Linux runs as Xen dom0. In this case Xen crash kernel region size should be established using __HYPERVISOR_kexec_op hypercall (Linux kernel kexec functionality does not make a lot of sense in Xen dom0). Sadly hypercalls are not easily accessible using shell scripts or something like that. Potentially we can check "xl dmesg" output for crashkernel option but this is not nice. So, let's add this functionality, for Linux running on bare metal and as Xen dom0, to kexec-tools. This way kdump scripts may establish crash kernel region size in one way regardless of platform. All burden of platform detection lies on kexec-tools. Figure (and unit) displayed by this new kexec-tools functionality is the same as one taken from /sys/kernel/kexec_crash_size. This functionality is available on x86 platform only. If idea is acceptable then I can prepare patches for other platforms (if it is possible and make sense) and repost them as fully flagged patch series. Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-11-27kexec: fix mmap return code handlingMichael Holzheu
When mmap fails, MAP_FAILED (that is, (void *) -1) is returned. Currently we assume that NULL is returned. Fix this and add the MAP_FAILED check. Fixes: 95741713e790 ("kexec/s390x: use mmap instead of read for slurp_file") Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-11-11kexec: determine size of block deviceAndreas Fenkart
starting 'kexec -l /dev/mmcblk0p1' fails since the size of a block device can not be determined with stat Signed-off-by: Andreas Fenkart <andreas.fenkart@dev.digitalstrom.org> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-11-09kexec/s390x: use mmap instead of read for slurp_file()Michael Holzheu
The slurp_fd() function allocates memory and uses the read() system call. This results in double memory consumption for image and initrd: 1) Memory allocated in user space by the kexec tool 2) Memory allocated in kernel by the kexec() system call The following illustrates the use case that we have on s390x: 1) Boot a 4 GB Linux system 2) Copy kernel and 1,5 GB ramdisk from external source into tmpfs (ram) 3) Use kexec to boot kernel with ramdisk Therefore for kexec runtime we need: 1,5 GB (tmpfs) + 1,5 GB (kexec malloc) + 1,5 GB (kernel memory) = 4,5 GB This patch introduces slurp_file_mmap() which for "normal" files uses mmap() instead of malloc()/read(). This reduces the runtime memory consumption of the kexec tool as follows: 1,5 GB (tmpfs) + 1,5 GB (kernel memory) = 3 GB Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com> Reviewed-by: Dave Young <dyoung@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-10-26Revert "kexec: use mmap instead of read for slurp_file()"Dave Young
This reverts commit 7ab842d8a004f6cd75a9d7b3528e4a70819ce4ef. using mmap by default in slurp_file cause segment fault while later reallocing dtb_buf during my arm kexec test. Signed-off-by: Dave Young <dyoung@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-09-07kexec: use mmap instead of read for slurp_file()Michael Holzheu
The slurp_fd() function allocates memory and uses the read() system call. This results in double memory consumption for image and initrd: 1) Memory allocated in user space by the kexec tool 2) Memory allocated in kernel by the kexec() system call Therefore use mmap() for non-character devices to reduce the runtime memory consumption of the kexec tool. The following use case illustrates the usefulness of this patch a bit more: 1) Boot a 4 GB Linux system 2) Read kernel and 1,5 GB ramdisk from external source into local tmpfs (ram) 3) kexec the kernel and ramdisk Without this patch for the kexec runtime we need: 1,5 GB (tmpfs) + 1,5 GB (kexec malloc) + 1,5 GB (kernel memory) = 4,5 GB Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-09-02Drop release date from kexec-tools version outputDave Young
kexec --version reports like below: kexec-tools 2.0.7 released 05 February 2015 The date string is generated when one run bootstrap script, thus it is more like a build date instead of release date. Even for distribution like Fedora it will make more sense if it can report something like "kexec-tools 2.0.7-1 released 05 February 2015" In case building from git tree, the date cause more confusion. So let's remove it from version string unless there is better idea to resolve the issue. Signed-off-by: Dave Young <dyoung@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-04-15kexec: remove ordering constraints from -x (--no-ifdown) and -y (--no-sync)Tejun Heo
Currently, the two options must be the last ones to be honored; otherwise, they can get silently ignored and both the manpage and help text point it out. This is error-prone and trivial to fix. There isn't much point in pointing something out in documentation when the peculiarity can be removed with four lines of extra code. Update option handling so that the two arguments are honored regardless of their positions. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-04-15kexec: implement -y (--no-sync) optionTejun Heo
During kernel develoment, kexec can be used to get out of sticky situations without going through possibly lenghty reboot; however, there are situations where the filesystem and/or storage stack are known to be misbehaving and performing sync before kexecing is dangerous or just never finishes. This patch implement -y (--no-sync) option which makes kexec skip syncing in the similar way as -x (--no-ifdown). Signed-off-by: Tejun Heo <tj@kernel.org> Suggested-by: Chris Mason <clm@fb.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-01-05Revert "kexec, remove panic_on_warn kernel parameter from kdump situations"Simon Horman
This reverts commit 930f0c3734c223433e74037601cbfd1bc9df7bad.
2015-01-01kexec, remove panic_on_warn kernel parameter from kdump situationsPrarit Bhargava
panic_on_warn kernel parameter will cause the kernel to panic when a WARN() is hit in the kernel. This is not a good situation for the kdump kernel because then it would be possible for the kdump kernel to panic in a non-fatal WARN(). This patch removes panic_on_warn as a kernel parameter for the kdump kernel. Signed-off-by: Prarit Bhargava <prarit@redhat.com> Cc: Dave Young <dyoung@redhat.com> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: WANG Chao <chaowang@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2014-12-02kexec: remove some re zero-assignmentHuKeping
since we have already cleared kexec_info with memset, there is no need to do that again to the struct members. Signed-off-by: Hu Keping <hukeping@huawei.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2014-09-04Return error code in case of invalid command line optionVivek Goyal
Currently kexec returns success even if an invalid command line option is encountered. Kexec currently prints usage message and then returns 0. That's not right. It is an error and error code 1 should be returned. Due to this wrapper script thinks that kdump succeeded but that's not the case. Signed-off-by: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2014-08-27kexec: Provide an option to use new kexec system callVivek Goyal
Hi, This is v2 of the patch. Since v1, I moved syscall implemented check littler earlier in the function as per the feedback. Now a new kexec syscall (kexec_file_load()) has been merged in upstream kernel. This system call takes file descriptors of kernel and initramfs as input (as opposed to list of segments to be loaded). This new system call allows for signature verification of the kernel being loaded. One use of signature verification of kernel is secureboot systems where we want to allow kexec into a kernel only if it is validly signed by a key system trusts. This patch provides and option --kexec-file-syscall (-s), to force use of new system call for kexec. Default is to continue to use old syscall. Currently only bzImage64 on x86_64 can be loaded using this system call. As kernel adds support for more arches and for more image types, kexec-tools can be modified accordingly. Signed-off-by: Vivek Goyal <vgoyal@redhat.com> Acked-by: Baoquan He <bhe@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2014-03-20cleanup: add dbgprint_mem_range functionWANG Chao
dbgprint_mem_range is used for printing the given memory range under debugging mode. Signed-off-by: WANG Chao <chaowang@redhat.com> Tested-by: Linn Crosetto <linn@hp.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2014-03-06Fix an off-by-one in locate_hole()Matthew Fleming
Fix an off-by-one in locate_hole() that can cause it to return a range that was previously allocated. In upgrading to kexec-tools 2.0.5 I first got the error "Overlapping memory segments at 0xbeff000" Adding some debugging I found locate_hole was returning incorrect values. The below is from the debug I added: XXXMDF: look for hole size 100000, cur range [52b3000, bffffff] size 6d4cfff XXXMDF: look for hole memsz=100000, found beff000 Hmm, if we wanted 0x100000 bytes ending at 0xbffffff, that should be 0xbf00000, not 0xbef000. Continuing to the second invocation: XXXMDF: look for hole size 1000, cur range [52b3000, befefff] size 6c4bfff XXXMDF: look for hole size 1000, cur range [bfff000, bffffff] size fff XXXMDF: look for hole memsz=1000, found bffe000 Now we die with overlapping ranges, since the 0x100000 bytes at 0xbeff000 overlaps 0x1000 bytes at 0xbffe000. Signed-off-by: Matthew Fleming <mdf356@gmail.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2014-02-06kernel image probe function return value checking fixDave Young
Currently kexec will use the kernel image type when probe function return value >=0. It looks odd, but previously it works. Since commit bf06cf2095 it does not work anymore. During my testing for arm zImage, in 2nd kernel the atags pointer and the machine_id are not valid, I did a lot of debugging in kernel, finally I found this is caused by a kexec tools bug instead. Because uImage will be probed before zImage, also the uImage probe return 1 instead of -1 since bf06cf2095, thus kexec will mistakenly think it is uImage. Fix this issue by regarding it's valid only when probe return 0. Signed-off-by: Dave Young <dyoung@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-12-13kexec: Extract slurp_fd()Geert Uytterhoeven
Factor out the common part of slurp_file() and slurp_file_len() into a new helper function slurp_fd(). Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Dave Young <dyoung@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-12-13kexec: Let slurp_file_len() return the number of bytes readGeert Uytterhoeven
Add an optional output parameter to slurp_file_len() so it can return the actual number of bytes read. Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org> Acked-by: Dave Young <dyoung@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-11-19kexec/xen: directly load images images into XenDavid Vrabel
Xen 4.4 has an improvided kexec hypercall ABI that allows images to be loaded and executed without any kernel involvement. Use the API provided by libxc to load images when running in a Xen guest. Support for loading images via the kexec_load syscall in non-upstream ("classic") Xen kernels is no longer supported. Signed-off-by: David Vrabel <david.vrabel@citrix.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-10-03kexec: Fix off-by-one errors in locate_hole()Geert Uytterhoeven
When calling locate_hole() with "hole_size" equal to the size of an available memory block, it fails to use that memory block. "end" and "hole_max" point to the last byte within the range, hence - "size = end - start" is one less than "hole_size", - "hole_base + hole_size" is one more than "hole_max". Subtract one from "hole_size" when doing the comparison (adding 1 to "size" could overflow in case of one big range covering the whole address space). But explicitly check if "hole_size" is zero first, to handle this case without causing underflows. Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-09-19kexec/kexec.c: Prefix hex numbers by 0xGeert Uytterhoeven
It's confusing that some pointers are printed as hex numbers prefixed with 0x, while some other values are printed as hex numbers without prefixes. Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-06-10add description for entry option in help and man pageBaoquan He
"--entry" option is used to specify jump back entry address, but lack description in help message and man page. Now add it. Signed-off-by: Baoquan He <bhe@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-05-15kexec: check if memory is reserved only when loading kdump kernel.WANG Chao
When memory for crashkernel isn't reserved, it's confusing that kexec spits error message for unloading kdump kernel as if we were loading it: # kexec -p -u Memory for crashkernel is not reserved Please reserve memory by passing "crashkernel=X@Y" parameter to the kernel Then try loading kdump kernel # echo $? 1 It's more appropriate to test if memory is reserved only when loading kdump kernel. With this patch: # kexec -p -u # echo $? 0 It's also the same behavior with the case of trying to unload kernel from unloaded state. Signed-off-by: WANG Chao <chaowang@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-05-14kexec: Replace printf() with die() to error out to stderrWANG Chao
Error messages are mixed stderr with stdout when we use die() along with printf(). So use die() to keep error out consistent. Signed-off-by: WANG Chao <chaowang@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-04-30kexec: cleanup: make add_backup_segments staticZhang Yanfei
The function add_backup_segments is only called by my_load and they are in the same file. So unnecessary to export it. Make it static. Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-03-27kexec: fix a minor mistake in an error messageZhang Yanfei
when specified a wrong --entry option, it outputs the error message: "Bad option value in --load-jump-back-helper=%s\n" which is obviously wrong, it should be: "Bad option value in --entry=%s\n" Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-03-27kexec: fix possible memory leak in check_reuse_initrdZhang Yanfei
If the if test is ok, then it will call die() to exit the process, so freeing line will not be reached, causing memory leak. Fix this. Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-03-15kexec: use _ALIGN* to make the logic clearZhang Yanfei
By replacing all the explicit align opertion with marco _ALIGN*, the code logic could more clear. Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-03-14kexec: check size before trying the mallocZhang Yanfei
If size is zero, it is unnecessary to do the malloc operation. So checking size first is better than doing malloc first. Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-03-05kexec: use dbgprintf instead of #if 0 for debug printingZhang Yanfei
Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com> [ horms@verge.net.au: Applied manually due to conflict ] Signed-off-by: Simon Horman <horms@verge.net.au>
2013-01-30kexec: add additional check when getting memory infoZhang Yanfei
This check makes sure that we indeed get the memory information. Signed-off-by: Zhang Yanfei <zhangyanfei@cn.fujitsu.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2012-12-23die: Use const for fmtSimon Horman
Signed-off-by: Simon Horman <horms@verge.net.au>
2012-12-14fix comment typo in locate_holeOlaf Hering
Signed-off-by: Olaf Hering <olaf@aepfle.de> Signed-off-by: Simon Horman <horms@verge.net.au>
2012-07-13kexec: simply pass LINUX_REBOOT_CMD_KEXEC to rebootmaximilian attems
While trying to port kexec cleanly to klibc, came across this syscall usage for reboot(2). Calling reboot directly simplifies the code. Signed-off-by: maximilian attems <max@stro.at> Signed-off-by: Simon Horman <horms@verge.net.au>
2012-06-27Fix format strings of die()Aleksey Makarov
One of them caused crash when user specifies a file that does not exist. Signed-off-by: Aleksey Makarov <aleksey.makarov@gmail.com> Removed trailing whitespace. Signed-off-by: Simon Horman <horms@verge.net.au>
2012-03-29Add a descriptive error message for kexec load failureKhalid Aziz
kexec-tools package for debian includes a patch that adds a more descriptive error message when someone tries to laod a crash kernel and didn't remember to boot up with crashkernel= parameter. This patch would be of general interest. This patch was originally written by Alastair McKinstry. Please apply. Signed-off-by: Khalid Aziz <khalid.aziz@hp.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2012-03-15Add generic debug optionCong Wang
Currently the debugging code is under #ifdef DEBUG, which means when we want to debug, we have to re-compile the source code with -DDEBUG. This is not convenient, we want to have a generic --debug option so that we can enable debugging code without re-compiling. This patch moves the arch-specific --debug to generic place and moves code under #ifdef DEBUG to --debug on x86. BTW, the size of kexec binary increases very little after this patch. Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2012-02-01kexec: make some functions staticCong Wang
The following functions/variables can become static. Signed-off-by: WANG Cong <xiyou.wangcong@gmail.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2011-11-09remove unnecessary check code for hole_alignDave Young
hole_align == 0 check is not neccesary, because it will be set to pagesize if it's zero. Just remove it here. Signed-off-by: Dave Young <dyoung@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2011-03-30Remove assigned but otherwise unused variablesSimon Horman
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2010-09-08kexec: Kill arch_initEric W. Biederman
The function only had one user, the error checking was wrong, and the functions it performed are best done elsewhere so remove the tempation of a problemenatic hook. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
2010-05-19kexec-tools: Fix option/argument parsingMatt Evans
The argument parsing is currently a bit broken as main()'s getopt_long() knows nothing about either the architecture-specific options or, even more specifically, the architecture-and-loader-specific options. This patch introduces new #defines for all architectures, KEXEC_ALL_OPTIONS and KEXEC_ALL_OPT_STR. These contain all possible options for a given build, and the getopt_long() passes in main() and arch_process_options() will now recognise arch- and loader-specific options; these will not be re-ordered in argv[], there is no confusion over which argv[] entry is the kernel filename, and using '--opt=foo' and '--opt foo' both work. All architectures have command line options (and #define OPT_BLAHs) consolidated into their include/arch/option.h files. x86_64 builds parts of i386/ as well, so now both share a single option.h file (with a symlink). Signed-off-by: Matt Evans <matt@ozlabs.org> Signed-off-by: Simon Horman <horms@verge.net.au>
2010-04-01Merge branch 'ppc32' of git://git.breakpoint.cc/bigeasy/kexec-toolsSimon Horman
2010-03-11kexec: Figure out our native architecture before loadEric W. Biederman
This moves the computing of our native archtecture earlier so that load can use it, as arch/i386/crashdump-x86.c has been trying to. Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2010-03-11Refix concat_cmdlineEric W. Biederman
When removing the potential leak the logic was flipped which mean we never reached the case for handling when both parameters were set. Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2010-03-07slurpfile: use lseek() on character nodes instead of fstat() for file sizeSebastian Andrzej Siewior
fstat() is used to determine the filesize before read() and it requires a filesystem. That means that it can not be used on character nodes. This makes it impossible to obtains the kernel from a char node like mtd or more likely ubi. We can't use this in every case because files in /proc don't support lseek(). This is required by the powerpc part to read some device-tree entries. Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
2010-02-18x86_64: use correct PAGE_OFFSETSimon Horman
This fixes a bug when using gdb with vmcore as explained by Dave Anderson: The kexec/arch/x86_64/crashdump-x86_64.h file contains a stale PAGE_OFFSET value. In 2.6.27 it was changed from 0xffff810000000000UL to 0xffff880000000000UL. This is only a problem when using gdb with the vmlinux/vmcore pair, because gdb relies upon the PT_LOAD segment's p_vaddr values in the ELF header to be correct. Cc: Dave Anderson <anderson@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>