summaryrefslogtreecommitdiff
path: root/kexec/kexec.c
AgeCommit message (Collapse)Author
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>
2010-02-02Cast when making signed/unsigned comparison in locate_hole()Simon Horman
Signed-off-by: Simon Horman <horms@verge.net.au>
2010-02-02don't leak in concat_cmdlineSimon Horman
Cc: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2010-02-02Fix --reuse-cmdline so it is usable.Eric W. Biederman
A colleague of mine implemented kdump and it used --reuse-cmdline with some rather interesting and unexpected results. Update the getopt specification so that --reuse-cmdline does not attempt to take an argument that it will not use. Update the processing of --append so that --reuse-cmdline followed by --append actually appends the parameters specified by --reuse-cmdline. Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com>
2009-11-30add support for loading lzma compressed kernelsFlorian Fainelli
This patch allows one to load a lzma compressed kernel using kexec -l. As I wanted the lzma code to be very similar to the existing zlib slurp_decompress I took lzread and associated routines from the cpio lzma support. Tested on my x86 laptop using the following commands: lzma e bzImage bzImage.lzma kexec -l bzImage.lzma Having lzma support is particularly useful on some embedded systems on which we have the kernel already lzma compressed and available on a mtd partition. Signed-off-by: Florian Fainelli <florian@openwrt.org> Signed-off-by: Simon Horman <horms@verge.net.au>
2009-11-27kexec.c: workaround getline and fscanf to make it *libc agnostic. Tested ↵Andrea Adami
against klibc and dietlibc. Based on a patch by Andrea Adami and Yuri Bushmelev I have: * Cleaned up indentation * Rearranged the logic in get_command_line() * Increased the buffer for reading the command line from 1024 to 2048 bytes as this is now possible on x86 Only compile tested against glibc. Cc: Andrea Adami <andrea.adami@gmail.com> Cc: Yuri Bushmelev <jay4mail@gmail.com> Cc: Bernhard Walle <bernhard@bwalle.de> Signed-off-by: Simon Horman <horms@verge.net.au>
2009-03-18kexec jump: use add_segment_phys_virt()Magnus Damm
Since /proc/iomem contains physical addresses, use add_segment_phys_virt(xxx, 0) instead of add_segment() in add_backup_segments(). This fix is needed for kexec jump on SuperH where add_segment() only takes virtual addresses. Signed-off-by: Magnus Damm <damm@igel.co.jp> Signed-off-by: Simon Horman <horms@verge.net.au>
2009-01-16entry wants to be void *Milton Miller
The kexec info struct defines entry to be a void *, so pass around the user supplied value as one. This fixes the following warning: gcc -g -O2 -fno-strict-aliasing -Wall -Wstrict-prototypes -I./include -I./util_lib/include -Iinclude/ -I./kexec/arch/ppc64/include -c -MD -o kexec/kexec.o kexec/kexec.c kexec/kexec.c: In function ‘my_load’: kexec/kexec.c:773: warning: assignment makes pointer from integer without a cast Signed-off-by: Milton Miller <miltonm@bga.com> Tested-by: M. Mohan Kumar <mohan@in.ibm.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2008-11-17Fix spell error in help outputBernhard Walle
This patch just fixes a spell error. Found by Dave Plater. Signed-off-by: Bernhard Walle <bwalle@suse.de> Signed-off-by: Simon Horman <horms@verge.net.au>
2008-10-31kexec jump support for kexec-toolsHuang Ying
To support memory backup/restore an option named --load-preserve-context is added to kexec. When it is specified toggether with --mem-max, most segments for crash dump support are loaded, and the memory range between mem_min to mem_max which has no segments loaded are loaded as backup segments. To support jump back from kexeced, options named --load-jump-back-helper and --entry are added to load a helper image with specified entry to jump back. Signed-off-by: Huang Ying <ying.huang@intel.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2008-06-13Fix wrong remove_parameter() callsBernhard Walle
When --reuse-cmdline is specified, kexec automatically removes some command line parameter that are *known* to break the kexec'd target. That patch corrects that behaviour: 1. BOOT_IMAGE should be removed always when --reuse-cmdline is specified since it's likely that the kernel is not the same as the running kernel. As only lilo-like bootloaders (i.e. not GRUB) adds that parameter, there's no need to add a BOOT_IMAGE here. 2. crashkernel should be only removed when 'kexec -p' is called. For the normal kexec, the crashkernel parameter can be passed as in the running kernel. The mistake has been introduced by commit 3c5bb06948881b3e31c783c19edef74275794280 by myself. Signed-off-by: Bernhard Walle <bwalle@suse.de> Signed-off-by: Simon Horman <horms@verge.net.au>
2008-05-28Specify the arch on kexec_unload.Bernhard Walle
This fixes the problem in kexec-tools that the patch http://article.gmane.org/gmane.linux.kernel/685027 tries to fix in kernel. The fix in userspace is correct. Signed-off-by: Bernhard Walle <bwalle@suse.de> Signed-off-by: Simon Horman <horms@verge.net.au>
2008-05-21Factor uname-based native architecture detection into a common function.Jamey Sharp
This code was copy-pasted into every architecture and was basically identical. Besides producing a nice net reduction in code, this factors a portability challenge into a single function that can be easily replaced at build-time. Signed-off-by: Jamey Sharp <jamey@thetovacompany.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2008-05-21Open slurped files in binary mode, on systems where that matters.Jamey Sharp
Signed-off-by: Jamey Sharp <jamey@thetovacompany.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2008-05-21Prototype ifdown() in kexec.h, not nested in main().Jamey Sharp
Signed-off-by: Jamey Sharp <jamey@thetovacompany.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2008-05-21Add --reuse-cmdlineBernhard Walle
This patch adds an option "--reuse-cmdline" for people that are lazy in typing --append="$(cat /proc/cmdline)". The advantage of "--reuse-cmdline" is also that it strips off BOOT_IMAGE (since it may not be correct any more) from lilo and other boot loaders, and, more important, the crashkernel option in case a panic kernel is loaded. If you like the option I can also add it for really all architectures. Tested only with x86-bzImage both the kexec and kdump case. Signed-off-by: Bernhard Walle <bwalle@suse.de> Signed-off-by: Simon Horman <horms@verge.net.au>
2008-04-24Die on early EOF in slurp_file, instead of infinite-looping.Jamey Sharp
Signed-off-by: Jamey Sharp <jamey@thetovacompany.com> Signed-off-by: Simon Horman <horms@verge.net.au>