summaryrefslogtreecommitdiff
path: root/kexec/fs2dt.c
AgeCommit message (Collapse)Author
2021-09-13Refer FDT tokens with symbolic namesSourabh Jain
Replace hardcoded FDT structure block tokens with proper names to improve code readability. Signed-off-by: Sourabh Jain <sourabhjain@linux.ibm.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2020-09-29kexec: Fix snprintf related compilation warningsBhupesh Sharma
This patch fixes the following snprintf related compilation warning seen currently with gcc versions 7 and 8 when kexec is compiled with -Wformat-truncation option: kexec/fs2dt.c:673:34: warning: ‘stdout-path’ directive output may be truncated writing 11 bytes into a region of size between 1 and 1024 [-Wformat-truncation=] snprintf(filename, MAXPATH, "%sstdout-path", pathname); ^~~~~~~~~~~ kexec/fs2dt.c:673:3: note: ‘snprintf’ output between 12 and 1035 bytes into a destination of size 1024 snprintf(filename, MAXPATH, "%sstdout-path", pathname); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kexec/fs2dt.c:676:35: warning: ‘linux,stdout-path’ directive output may be truncated writing 17 bytes into a region of size between 1 and 1024 [-Wformat-truncation=] snprintf(filename, MAXPATH, "%slinux,stdout-path", pathname); ^~~~~~~~~~~~~~~~~ kexec/fs2dt.c:676:4: note: ‘snprintf’ output between 18 and 1041 bytes into a destination of size 1024 snprintf(filename, MAXPATH, "%slinux,stdout-path", pathname); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kexec/firmware_memmap.c:132:35: warning: ‘%s’ directive output may be truncated writing 5 bytes into a region of size between 0 and 4095 [-Wformat-truncation=] snprintf(filename, PATH_MAX, "%s/%s", entry, "start"); ^~ ~~~~~~~ kexec/firmware_memmap.c:132:2: note: ‘snprintf’ output between 7 and 4102 bytes into a destination of size 4096 snprintf(filename, PATH_MAX, "%s/%s", entry, "start"); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kexec/firmware_memmap.c:142:35: warning: ‘%s’ directive output may be truncated writing 3 bytes into a region of size between 0 and 4095 [-Wformat-truncation=] snprintf(filename, PATH_MAX, "%s/%s", entry, "end"); ^~ ~~~~~ kexec/firmware_memmap.c:142:2: note: ‘snprintf’ output between 5 and 4100 bytes into a destination of size 4096 snprintf(filename, PATH_MAX, "%s/%s", entry, "end"); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ kexec/firmware_memmap.c:152:35: warning: ‘%s’ directive output may be truncated writing 4 bytes into a region of size between 0 and 4095 [-Wformat-truncation=] snprintf(filename, PATH_MAX, "%s/%s", entry, "type"); ^~ ~~~~~~ kexec/firmware_memmap.c:152:2: note: ‘snprintf’ output between 6 and 4101 bytes into a destination of size 4096 snprintf(filename, PATH_MAX, "%s/%s", entry, "type"); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Since the simplest method to address the gcc warnings and possible truncation would be to check the return value provided from snprintf (well there are other methods like using 'asnprintf' or using 'open_memstream' function to create the FILE object, but these are more intrusive), so this patch does the same. Cc: Simon Horman <horms@verge.net.au> Cc: Eric Biederman <ebiederm@xmission.com> Cc: kexec@lists.infradead.org Signed-off-by: Bhupesh Sharma <bhsharma@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2018-02-22kexec/ppc64: add support to parse ibm, dynamic-memory-v2 propertyHari Bathini
Add support to parse the new 'ibm,dynamic-memory-v2' property in the 'ibm,dynamic-reconfiguration-memory' node. This replaces the old 'ibm,dynamic-memory' property and is enabled in the kernel with a patch series that starts with commit 0c38ed6f6f0b ("powerpc/pseries: Enable support of ibm,dynamic-memory-v2"). All LMBs that share the same flags and are adjacent are grouped together in the newer version of the property making it compact to represent larger memory configurations. Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com> Mahesh Jagannath Salgaonkar <mahesh@linux.vnet.ibm.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2018-02-22kexec: add a helper function to add rangesHari Bathini
Add a helper function for adding ranges to avoid duplicating code. Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com> Reviewed-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2016-10-07kexec/fs2dt: Check for NULL pointer in dt_copy_old_root_param()Madhavan Srinivasan
In dt_copy_old_root_param(), FILE * returned from fopen is not checked for NULL pointer before passinig to fclose(). This could trigger a segfault. Patch to fix the same. Signed-off-by: Madhavan Srinivasan <maddy@linux.vnet.ibm.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2016-03-02kexec/fs2dt.c: wrong dt node fixDave Young
2nd kernel hangs early because of a regression caused by below commit: commit 68262155d8c661586b809bc5301a7dff1c378137 Author: Andrew Jones <drjones@redhat.com> Date: Fri Nov 20 12:31:53 2015 -0500 kexec/fs2dt: cleanup pathname putnode() will add the trailing '/', avoid having two. Also pathstart is unused, get rid of it. Signed-off-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au> The actual purpose of the commit is to avoid double slash in pathname. But unfortunately in function putnode() we have below magics to get the node name: basename = strrchr(pathname,'/') + 1; ... strcpy((void *)dt, *basename ? basename : ""); ... strcat(pathname, "/"); We treat none zero basename as a node name, then concat a slash to open the directory for later property handling. pathname originally was "/proc/device-tree/" so for the first run of putnode it will cause double slashes. With the commit above mentioned there are no double slashes but we will copy "device-tree" to dt. Thus kexec kernel is not happy.. Instead let's fix it by only concating slash when the basenanme is not empty and restore the initial value of pathname as "/proc/device-tree/" Note: I only reproduce the issue with loading older kernel like 3.10 in RHEL. I do not see the problem in new kernels in Fedora. Signed-off-by: Dave Young <dyoung@redhat.com> Reviewed-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-11-24kexec/fs2dt: check for /chosen/stdout-path firstAndrew Jones
Check /chosen/stdout-path first, as linux,stdout-path is deprecated. I don't know how the ppc64:my_debug thing works, but on arm the warning "Unable to find /proc/device-tree//chosen/linux,stdout-path, printing from purgatory is diabled" is output when loading a kexec kernel. This patch at least suppresses that when /chosen/stdout-path exists, and maybe it even enables printing from purgatory? Signed-off-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-11-24kexec/fs2dt: cleanup pathnameAndrew Jones
putnode() will add the trailing '/', avoid having two. Also pathstart is unused, get rid of it. Signed-off-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-11-24kexec/fs2dt: s/diabled/disabled/Andrew Jones
Signed-off-by: Andrew Jones <drjones@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-10-30fs2dt.c: move copy old root param as a new functiondyoung@redhat.com
Split the copy old root param code to a new function dt_copy_old_root_param Also add a global variable dt_no_old_root, do not copy root param when dt_no_old_root == 1. It will be used in later patches. Signed-off-by: Dave Young <dyoung@redhat.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-02-18kexec: Fix compiler format warningGeoff Levand
The sizeof operator returns a size_t type. Change the printf format of sizeof values from %d to %zu. Fixes compiler warnings like these: kexec/fs2dt.c: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=] Signed-off-by: Geoff Levand <geoff@infradead.org> Signed-off-by: Simon Horman <horms@verge.net.au>
2015-02-18kexec: Fix compiler ambiguous else warningGeoff Levand
Add braces to if statments in fs2dt.c. Fixes warnings like these when compiling with gcc 4.9.1: kexec/fs2dt.c: warning: suggest explicit braces to avoid ambiguous ‘else’ [-Wparentheses] Signed-off-by: Geoff Levand <geoff@infradead.org> Signed-off-by: Simon Horman <horms@verge.net.au>
2014-12-02kexec/fs2dt: Use slurp_file_len to avoid partial read of filesAnton Blanchard
The OPAL firmware is going to embed its symbol map in the device tree. The size is large enough to be more than a page, and it takes multiple reads to get the whole file. This is because sysfs uses the seq_file helpers which do a page at a time. Unfortunately fs2dt has no handling for short reads and we die with: unrecoverable error: short read from"/proc/device-tree//ibm,opal/firmware/symbol-map" This patch uses the slurp_file_len helper which does the right thing. It moves the explicit open of the file further down for add_usable_mem_property and add_dyn_reconf_usable_mem_property. We should convert both of these to use the buffer provided by slurp_file_len at some stage. Signed-off-by: Anton Blanchard <anton@samba.org> Signed-off-by: Simon Horman <horms@verge.net.au>
2014-11-13kexec/fs2dt: Fix sorting of device treeAnton Blanchard
Commit b02d735bf252 ('ppc64 kdump device_tree sort') added code to sort device tree properties, but it had a few issues. A compare routine needs to return -1 and 1. The special case for sorting properties with unit addresses only returned 1 and ignored the opposite case, which screwed up the sorting. We were missing a few more things: - Need to check both basenames are the same length - Need to check both basenames match I noticed this when looking at the NUMA topology after a kexec, and it had shifted. Signed-off-by: Anton Blanchard <anton@samba.org> Signed-off-by: Simon Horman <horms@verge.net.au>
2014-05-15kexec/ppc64: Fix up ELF header and dt for PowerNV platform.Mahesh Salgaonkar
On PowerNV platform, OPAL region is overlapped with crashkernel, need to create ELF Program header for the overlapped memory. The changes are similar to the way RTAS region was handled. Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2014-04-14kexec/fs2dt : Fix endianess issue with initrd base and sizeLaurent Dufour
The initrd values exposed in the device tree of the kexeced kernel must be encoded in Big Endian format. Without this patch, kexeced LE kernel are expected to panic when dealing with the initrd image. Signed-off-by: Laurent Dufour <ldufour@linux.vnet.ibm.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2014-02-04Avoid buffer overflow on strncat usageDirk Mueller
strncat() does not want the total size but the maximum length (without trailing NUL) that can still be added. Switch over to snprintf which is both more readable and avoids this issue. Signed-off-by: Dirk Mueller <dmueller@suse.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2014-01-31kexec/ppc64 fix device tree endianess issues for memory attributesLaurent Dufour
All the attributes exposed in the device tree are in Big Endian format. This patch add the byte swap operation for some entries which were not yet processed, including those fixed by the following kernel's patch : https://lists.ozlabs.org/pipermail/linuxppc-dev/2014-January/114720.html To work on PPC64 Little Endian mode, kexec now requires that the kernel's patch mentioned above is applied on the kexecing kernel. Tested on ppc64 LPAR (kexec/dump) and ppc64le in a Qemu/KVM guest (kexec) Changes from v1 : * add processing of the following entries : - ibm,dynamic-reconfiguration-memory - chosen/linux,kernel-end - chosen/linux,crashkernel-base & size - chosen/linux,memory-limit - chosen/linux,htab-base & size - linux,tce-base & size - memory@/reg Signed-off-by: Laurent Dufour <ldufour@linux.vnet.ibm.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-12-06kexec: Fix add_usable_memory to use buf of type uint64_t.Mahesh Salgaonkar
A switchover from /kexec/arch/ppc64/fs2dt.c to common code under /kexec/fs2dt.c broke the kdump on ppc64. The function add_usable_memory() assumes that 'memory@*' node exports two 32bit values and fails to populate mem ranges correctly. On ppc64, 'memory@*' exports two 64bit values as below: # hexdump /proc/device-tree/memory\@0/reg 0000000 0000 0000 0000 0000 0000 0000 0800 0000 0000010 # This patch fixes add_usable_memory() to use buf[2] of type uint64_t. Signed-off-by: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-10-17kexec/fs2dt: fix endianess conversionLaurent Dufour
While reviewing fs2dt.c in the common kexec directory, in order to use it to support little endian ppc64 architecture, I found some endianess conversion's issues. In dt_reserve, dt_base is a pointer and thus should not be converted. In checkprop, values read from the device tree are big endian encoded and should be converted if CPU is running in little endian mode. In add_dyn_reconf_usable_mem_property__, fix extraneous endianess conversion of rlen which should be natively used to increase the dt pointer. Signed-off-by: Laurent Dufour <ldufour@linux.vnet.ibm.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-10-04kexec: Handle read errors in fs2dt setupGeoff Levand
The putnode() routine in fs2dt.c was not checking for errors returned from calls to read(). Add checks for these errors and abort the setup of printing from purgatory if the checks fail. Signed-off-by: Geoff Levand <geoff@infradead.org> Signed-off-by: Simon Horman <horms@verge.net.au>
2013-10-04kexec: Fix return value build warningsGeoff Levand
Add a local variable 'result' to the putnode() routine of ds2dt and use it to hold return values of calls to read(). Fixes build warnings like these: kexec/fs2dt.c: warning: ignoring return value of ‘read’ Signed-off-by: Geoff Levand <geoff@infradead.org> for Huawei, Linaro 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>
2012-11-27fs2dt: check for initrd_size != 0 when adding initrd entriesDaniel Mack
This prevents the creation of chosen/linux,initrd-{start,stop} entries with zero length. Signed-off-by: Daniel Mack <zonque@gmail.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2012-11-27fs2dt: fix basename string comparesDaniel Mack
basename is initialized as basename = strrchr(pathname,'/') + 1; and does hence not contain the leading slash character. Signed-off-by: Daniel Mack <zonque@gmail.com> Signed-off-by: Simon Horman <horms@verge.net.au>
2012-09-12fs2dt: Add a generic copy of fs2dtSimon Horman
The motivation for this is to remove duplicated code by sharing the fs2dt between different architectures. The code added by this patch is very close to the code currently used by ppc64, and thus migrating that architecture should not be difficult. The 32bit powerpc code is a little different and thus more care is needed when migrating that architecture to this code. Unfortunately I do not have any powerpc equipment available to test this code. Signed-off-by: Simon Horman <horms@verge.net.au>