From 06c2a2d8412927eea24c310860202f7633c23f11 Mon Sep 17 00:00:00 2001 From: CentOS Sources Date: Apr 10 2018 05:35:08 +0000 Subject: import kexec-tools-2.0.15-13.el7 --- diff --git a/.gitignore b/.gitignore index 3e4cfae..a6ef97a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ SOURCES/eppic_050615.tar.gz SOURCES/kdump-anaconda-addon-003-23-g80e78fb.tar.gz -SOURCES/kexec-tools-2.0.14.tar.xz -SOURCES/makedumpfile-1.6.1.tar.gz +SOURCES/kexec-tools-2.0.15.tar.xz +SOURCES/makedumpfile-1.6.2.tar.gz diff --git a/.kexec-tools.metadata b/.kexec-tools.metadata index 429335b..cae8820 100644 --- a/.kexec-tools.metadata +++ b/.kexec-tools.metadata @@ -1,4 +1,4 @@ a096c8e0892b559f40b01916aae240652f75b68a SOURCES/eppic_050615.tar.gz dfa17c4a04bc3775ede56c1fd3a8904e938f0fe1 SOURCES/kdump-anaconda-addon-003-23-g80e78fb.tar.gz -cc3d6155ffb2aac5cf943312b41c0f41141dc9c6 SOURCES/kexec-tools-2.0.14.tar.xz -74ec93ff2709542772175ae7761a2852adce8c35 SOURCES/makedumpfile-1.6.1.tar.gz +e723b075f2183066e8ee174edf9d85dff4f863e4 SOURCES/kexec-tools-2.0.15.tar.xz +3f1b8092a71cf174c4685634982f1d5abc30d3e6 SOURCES/makedumpfile-1.6.2.tar.gz diff --git a/SOURCES/dracut-module-setup.sh b/SOURCES/dracut-module-setup.sh index 3dea978..bed9fde 100755 --- a/SOURCES/dracut-module-setup.sh +++ b/SOURCES/dracut-module-setup.sh @@ -7,6 +7,13 @@ if ! [[ -d "${initdir}/tmp" ]]; then mkdir -p "${initdir}/tmp" fi +is_mpath() { + local _dev=$1 + [ -e /sys/dev/block/$_dev/dm/uuid ] || return 1 + [[ $(cat /sys/dev/block/$_dev/dm/uuid) =~ mpath- ]] && return 0 + return 1 +} + check() { [[ $debug ]] && set -x #kdumpctl sets this explicitly @@ -24,10 +31,11 @@ depends() { _dep="$_dep drm" fi - if [ is_generic_fence_kdump -o is_pcs_fence_kdump ]; then + if is_generic_fence_kdump -o is_pcs_fence_kdump; then _dep="$_dep network" fi + for_each_host_dev_and_slaves is_mpath && _dep="$_dep multipath-hostonly" echo $_dep return 0 } @@ -390,20 +398,20 @@ default_dump_target_install_conf() _save_path=$_mntpoint/$_save_path fi - if [ "$_mntpoint" != "/" ]; then - _fstype=$(get_fs_type_from_target $_target) - - if $(is_fs_type_nfs $_fstype); then - kdump_install_net "$_target" - _fstype="nfs" - else - _target=$(kdump_to_udev_name $_target) - fi + _fstype=$(get_fs_type_from_target $_target) + if $(is_fs_type_nfs $_fstype); then + kdump_install_net "$_target" + _fstype="nfs" + else + _target=$(kdump_to_udev_name $_target) + fi - echo "$_fstype $_target" >> ${initdir}/tmp/$$-kdump.conf + echo "$_fstype $_target" >> ${initdir}/tmp/$$-kdump.conf - # strip the duplicated "/" - _save_path=$(echo $_save_path | tr -s /) + # strip the duplicated "/" + _save_path=$(echo $_save_path | tr -s /) + # don't touch the path under root mount + if [ "$_mntpoint" != "/" ]; then _save_path=${_save_path##"$_mntpoint"} fi @@ -539,11 +547,9 @@ kdump_setup_iscsi_device() { dinfo "Found iscsi component $1" - # Check once before getting explicit values, so we can output a decent - # error message. - - if ! /sbin/iscsiadm -m session -r ${path} >/dev/null ; then - derror "Unable to find iscsi record for $path" + # Check once before getting explicit values, so we can bail out early, + # e.g. in case of pure-hardware(all-offload) iscsi. + if ! /sbin/iscsiadm -m session -r ${path} &>/dev/null ; then return 1 fi @@ -731,6 +737,9 @@ install() { dracut_install -o /etc/adjtime /etc/localtime inst "$moddir/monitor_dd_progress" "/kdumpscripts/monitor_dd_progress" chmod +x ${initdir}/kdumpscripts/monitor_dd_progress + inst "/bin/grep" "/bin/grep" + inst "/bin/cat" "/bin/cat" + inst "/bin/rm" "/bin/rm" inst "/bin/dd" "/bin/dd" inst "/bin/tail" "/bin/tail" inst "/bin/date" "/bin/date" @@ -756,4 +765,22 @@ install() { # target. Ideally all this should be pushed into dracut iscsi module # at some point of time. kdump_check_iscsi_targets + + # For the lvm type target under kdump, in /etc/lvm/lvm.conf we can + # safely replace "reserved_memory=XXXX"(default value is 8192) with + # "reserved_memory=1024" to lower memory pressure under kdump. We do + # it unconditionally here, if "/etc/lvm/lvm.conf" doesn't exist, it + # actually does nothing. + sed -i -e \ + 's/\(^[[:space:]]*reserved_memory[[:space:]]*=\)[[:space:]]*[[:digit:]]*/\1 1024/' \ + ${initdir}/etc/lvm/lvm.conf &>/dev/null + + # Kdump turns out to require longer default systemd mount timeout + # than 1st kernel(90s by default), we use default 300s for kdump. + grep -r "^[[:space:]]*DefaultTimeoutStartSec=" ${initdir}/etc/systemd/system.conf* &>/dev/null + if [ $? -ne 0 ]; then + mkdir -p ${initdir}/etc/systemd/system.conf.d + echo "[Manager]" > ${initdir}/etc/systemd/system.conf.d/kdump.conf + echo "DefaultTimeoutStartSec=300s" >> ${initdir}/etc/systemd/system.conf.d/kdump.conf + fi } diff --git a/SOURCES/kdump-lib.sh b/SOURCES/kdump-lib.sh index 2c5ced2..c40b0d6 100755 --- a/SOURCES/kdump-lib.sh +++ b/SOURCES/kdump-lib.sh @@ -6,6 +6,18 @@ DEFAULT_PATH="/var/crash/" FENCE_KDUMP_CONFIG_FILE="/etc/sysconfig/fence_kdump" FENCE_KDUMP_SEND="/usr/libexec/fence_kdump_send" +FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled" + +is_fadump_capable() +{ + # Check if firmware-assisted dump is enabled + # if no, fallback to kdump check + if [ -f $FADUMP_ENABLED_SYS_NODE ]; then + rc=`cat $FADUMP_ENABLED_SYS_NODE` + [ $rc -eq 1 ] && return 0 + fi + return 1 +} perror_exit() { echo $@ >&2 @@ -44,12 +56,6 @@ is_fs_dump_target() egrep -q "^ext[234]|^xfs|^btrfs|^minix" /etc/kdump.conf } -is_user_configured_dump_target() -{ - return $(is_mount_in_dracut_args || is_ssh_dump_target || is_nfs_dump_target || \ - is_raw_dump_target || is_fs_dump_target) -} - strip_comments() { echo $@ | sed -e 's/\(.*\)#.*/\1/' @@ -114,18 +120,21 @@ kdump_get_persistent_dev() { echo $1 } +is_user_configured_dump_target() +{ + return $(is_mount_in_dracut_args || is_ssh_dump_target || is_nfs_dump_target || \ + is_raw_dump_target || is_fs_dump_target) +} + get_user_configured_dump_disk() { local _target - if is_ssh_dump_target || is_nfs_dump_target; then - return - fi - _target=$(egrep "^ext[234]|^xfs|^btrfs|^minix|^raw" /etc/kdump.conf 2>/dev/null |awk '{print $2}') - [ -n "$_target" ] && echo $_target + [ -n "$_target" ] && echo $_target && return - return + _target=$(get_dracut_args_target "$(grep "^dracut_args .*\-\-mount" /etc/kdump.conf)") + [ -b "$_target" ] && echo $_target } get_root_fs_device() @@ -137,6 +146,76 @@ get_root_fs_device() return } +get_save_path() +{ + local _save_path=$(grep "^path" /etc/kdump.conf|awk '{print $2}') + if [ -z "$_save_path" ]; then + _save_path=$DEFAULT_PATH + fi + + echo $_save_path +} + +get_block_dump_target() +{ + local _target _path + + if is_ssh_dump_target || is_nfs_dump_target; then + return + fi + + _target=$(get_user_configured_dump_disk) + [ -n "$_target" ] && echo $(to_dev_name $_target) && return + + # Get block device name from local save path + _path=$(get_save_path) + _target=$(get_target_from_path $_path) + [ -b "$_target" ] && echo $(to_dev_name $_target) +} + +is_dump_to_rootfs() +{ + grep "^default[[:space:]]dump_to_rootfs" /etc/kdump.conf >/dev/null +} + +get_default_action_target() +{ + local _target + + if is_dump_to_rootfs; then + # Get rootfs device name + _target=$(get_root_fs_device) + [ -b "$_target" ] && echo $(to_dev_name $_target) && return + # Then, must be nfs root + echo "nfs" + fi +} + +# Get kdump targets(including root in case of dump_to_rootfs). +get_kdump_targets() +{ + local _target _root + local kdump_targets + + _target=$(get_block_dump_target) + if [ -n "$_target" ]; then + kdump_targets=$_target + elif is_ssh_dump_target; then + kdump_targets="ssh" + else + kdump_targets="nfs" + fi + + # Add the root device if dump_to_rootfs is specified. + _root=$(get_default_action_target) + if [ -n "$_root" -a "$kdump_targets" != "$_root" ]; then + kdump_targets="$kdump_targets $_root" + fi + + echo "$kdump_targets" +} + + # findmnt uses the option "-v, --nofsroot" to exclusive the [/dir] # in the SOURCE column for bind-mounts, then if $_mntpoint equals to # $_mntpoint_nofsroot, the mountpoint is not bind mounted directory. diff --git a/SOURCES/kdump.sysconfig.i386 b/SOURCES/kdump.sysconfig.i386 deleted file mode 100644 index 37d1b96..0000000 --- a/SOURCES/kdump.sysconfig.i386 +++ /dev/null @@ -1,40 +0,0 @@ -# Kernel Version string for the -kdump kernel, such as 2.6.13-1544.FC5kdump -# If no version is specified, then the init script will try to find a -# kdump kernel with the same version number as the running kernel. -KDUMP_KERNELVER="" - -# The kdump commandline is the command line that needs to be passed off to -# the kdump kernel. This will likely match the contents of the grub kernel -# line. For example: -# KDUMP_COMMANDLINE="ro root=LABEL=/" -# Dracut depends on proper root= options, so please make sure that appropriate -# root= options are copied from /proc/cmdline. In general it is best to append -# command line options using "KDUMP_COMMANDLINE_APPEND=". -# If a command line is not specified, the default will be taken from -# /proc/cmdline -KDUMP_COMMANDLINE="" - -# This variable lets us remove arguments from the current kdump commandline -# as taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline -# NOTE: some arguments such as crashkernel will always be removed -KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug" - -# This variable lets us append arguments to the current kdump commandline -# after processed by KDUMP_COMMANDLINE_REMOVE -KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices numa=off udev.children-max=2 panic=10 rootflags=nofail transparent_hugepage=never" - -# Any additional kexec arguments required. In most situations, this should -# be left empty -# -# Example: -# KEXEC_ARGS="--elf32-core-headers" -KEXEC_ARGS="" - -#Where to find the boot image -#KDUMP_BOOTDIR="/boot" - -#What is the image type used for kdump -KDUMP_IMG="vmlinuz" - -#What is the images extension. Relocatable kernels don't have one -KDUMP_IMG_EXT="" diff --git a/SOURCES/kdump.sysconfig.ia64 b/SOURCES/kdump.sysconfig.ia64 deleted file mode 100644 index 83e8ad0..0000000 --- a/SOURCES/kdump.sysconfig.ia64 +++ /dev/null @@ -1,32 +0,0 @@ -# Kernel Version string for the -kdump kernel, such as 2.6.13-1544.FC5kdump -# If no version is specified, then the init script will try to find a -# kdump kernel with the same version number as the running kernel. -KDUMP_KERNELVER="" - -# The kdump commandline is the command line that needs to be passed off to -# the kdump kernel. This will likely match the contents of the grub kernel -# line. For example: -# KDUMP_COMMANDLINE="ro root=LABEL=/" -# If a command line is not specified, the default will be taken from -# /proc/cmdline -KDUMP_COMMANDLINE="" - -# This variable lets us append arguments to the current kdump commandline -# As taken from either KDUMP_COMMANDLINE above, or from /proc/cmdline -KDUMP_COMMANDLINE_APPEND="irqpoll maxcpus=1 reset_devices" - -# Any additional kexec arguments required. In most situations, this should -# be left empty -# -# Example: -# KEXEC_ARGS="--elf32-core-headers" -KEXEC_ARGS="" - -#Where to find the boot image -KDUMP_BOOTDIR="/boot/efi/efi/redhat" - -#What is the image type used for kdump -KDUMP_IMG="vmlinuz" - -#What is the images extension. Relocatable kernels don't have one -KDUMP_IMG_EXT="" diff --git a/SOURCES/kdump.sysconfig.ppc64 b/SOURCES/kdump.sysconfig.ppc64 index 3d4db57..38caf75 100644 --- a/SOURCES/kdump.sysconfig.ppc64 +++ b/SOURCES/kdump.sysconfig.ppc64 @@ -28,7 +28,7 @@ KDUMP_COMMANDLINE_APPEND="irqpoll maxcpus=1 noirqdistrib reset_devices cgroup_di # # Example: # KEXEC_ARGS="--elf32-core-headers" -KEXEC_ARGS="" +KEXEC_ARGS="--dt-no-old-root" #Where to find the boot image #KDUMP_BOOTDIR="/boot" diff --git a/SOURCES/kdump.sysconfig.ppc64le b/SOURCES/kdump.sysconfig.ppc64le index 3d4db57..38caf75 100644 --- a/SOURCES/kdump.sysconfig.ppc64le +++ b/SOURCES/kdump.sysconfig.ppc64le @@ -28,7 +28,7 @@ KDUMP_COMMANDLINE_APPEND="irqpoll maxcpus=1 noirqdistrib reset_devices cgroup_di # # Example: # KEXEC_ARGS="--elf32-core-headers" -KEXEC_ARGS="" +KEXEC_ARGS="--dt-no-old-root" #Where to find the boot image #KDUMP_BOOTDIR="/boot" diff --git a/SOURCES/kdump.sysconfig.x86_64 b/SOURCES/kdump.sysconfig.x86_64 index 77cbd0e..9093209 100644 --- a/SOURCES/kdump.sysconfig.x86_64 +++ b/SOURCES/kdump.sysconfig.x86_64 @@ -21,7 +21,7 @@ KDUMP_COMMANDLINE_REMOVE="hugepages hugepagesz slub_debug notsc kaslr" # This variable lets us append arguments to the current kdump commandline # after processed by KDUMP_COMMANDLINE_REMOVE -KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices cgroup_disable=memory mce=off numa=off udev.children-max=2 panic=10 rootflags=nofail acpi_no_memhotplug transparent_hugepage=never" +KDUMP_COMMANDLINE_APPEND="irqpoll nr_cpus=1 reset_devices cgroup_disable=memory mce=off numa=off udev.children-max=2 panic=10 rootflags=nofail acpi_no_memhotplug transparent_hugepage=never nokaslr" # Any additional kexec arguments required. In most situations, this should # be left empty diff --git a/SOURCES/kdumpctl b/SOURCES/kdumpctl index 98793de..4e09ac8 100755 --- a/SOURCES/kdumpctl +++ b/SOURCES/kdumpctl @@ -14,7 +14,6 @@ DUMP_TARGET="" DEFAULT_INITRD="" DEFAULT_INITRD_BAK="" TARGET_INITRD="" -FADUMP_ENABLED_SYS_NODE="/sys/kernel/fadump_enabled" FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered" #kdump shall be the default dump mode DEFAULT_DUMP_MODE="kdump" @@ -37,6 +36,11 @@ single_instance_lock() exec 9>/var/lock/kdump + if [ $? -ne 0 ]; then + echo "Create file lock failed" + exit 1 + fi + flock -n 9 rc=$? @@ -67,23 +71,24 @@ remove_cmdline_param() for arg in $@; do cmdline=`echo $cmdline | \ - sed -e "s/\b$arg=[^ ]*\b//g" \ - -e "s/\b$arg\b//g" \ + sed -e "s/\b$arg=[^ ]*//g" \ + -e "s/^$arg\b//g" \ + -e "s/[[:space:]]$arg\b//g" \ -e "s/\s\+/ /g"` done echo $cmdline } # -# This function returns the "initial apicid" of the -# boot cpu (cpu 0) if present. +# This function returns the "apicid" of the boot +# cpu (cpu 0) if present. # -get_bootcpu_initial_apicid() +get_bootcpu_apicid() { awk ' \ BEGIN { CPU = "-1"; } \ $1=="processor" && $2==":" { CPU = $NF; } \ - CPU=="0" && /initial apicid/ { print $NF; } \ + CPU=="0" && /^apicid/ { print $NF; } \ ' \ /proc/cpuinfo } @@ -104,28 +109,39 @@ append_cmdline() echo $cmdline } -# This function performs a series of edits on the command line +# This function performs a series of edits on the command line. +# Store the final result in global $KDUMP_COMMANDLINE. prepare_cmdline() { - local cmdline; + local cmdline id + if [ -z "$KDUMP_COMMANDLINE" ]; then - cmdline=`cat /proc/cmdline` + cmdline=$(cat /proc/cmdline) else cmdline=${KDUMP_COMMANDLINE} fi + # These params should always be removed - cmdline=`remove_cmdline_param "$cmdline" crashkernel panic_on_warn` + cmdline=$(remove_cmdline_param "$cmdline" crashkernel panic_on_warn) # These params can be removed configurably - cmdline=`remove_cmdline_param "$cmdline" ${KDUMP_COMMANDLINE_REMOVE}` + cmdline=$(remove_cmdline_param "$cmdline" ${KDUMP_COMMANDLINE_REMOVE}) + + # Always remove "root=X", as we now explicitly generate all kinds + # of dump target mount information including root fs. + # + # We do this before KDUMP_COMMANDLINE_APPEND, if one really cares + # about it(e.g. for debug purpose), then can pass "root=X" using + # KDUMP_COMMANDLINE_APPEND. + cmdline=$(remove_cmdline_param "$cmdline" root) cmdline="${cmdline} ${KDUMP_COMMANDLINE_APPEND}" - local id=`get_bootcpu_initial_apicid` + id=$(get_bootcpu_apicid) if [ ! -z ${id} ] ; then - cmdline=`append_cmdline "${cmdline}" disable_cpu_apicid ${id}` + cmdline=$(append_cmdline "${cmdline}" disable_cpu_apicid ${id}) fi - echo $cmdline + KDUMP_COMMANDLINE=$cmdline } @@ -277,6 +293,13 @@ check_config() return 1 } + # Check if we have any leading spaces (or tabs) before the + # variable name in the kdump conf file + if grep -E -q '^[[:blank:]]+[a-z]' $KDUMP_CONFIG_FILE; then + echo "No whitespaces are allowed before a kdump option name in $KDUMP_CONFIG_FILE" + return 1 + fi + while read config_opt config_val; do case "$config_opt" in \#* | "") @@ -437,10 +460,15 @@ check_dump_fs_modified() fi if ! findmnt $_target >/dev/null; then - echo "Dump target $_target is probably not mounted." - return 2 - fi - _new_mntpoint="/kdumproot/$(get_mntpoint_from_target $_target)" + echo "Dump target $_target is probably not mounted." + return 2 + fi + + if [[ "$_target" = "$(get_root_fs_device)" ]]; then + _new_mntpoint="/sysroot" + else + _new_mntpoint="/kdumproot/$(get_mntpoint_from_target $_target)" + fi _dracut_args=$(lsinitrd $TARGET_INITRD -f usr/lib/dracut/build-parameter.txt) if [[ -z "$_dracut_args" ]];then @@ -687,7 +715,7 @@ load_kdump() fi fi - KDUMP_COMMANDLINE=`prepare_cmdline` + prepare_cmdline # For secureboot enabled machines, use new kexec file based syscall. # Old syscall will always fail as it does not have capability to @@ -817,17 +845,6 @@ handle_mode_switch() fi } -is_fadump_capable() -{ - # Check if firmware-assisted dump is enabled - # if no, fallback to kdump check - if [ -f $FADUMP_ENABLED_SYS_NODE ]; then - rc=`cat $FADUMP_ENABLED_SYS_NODE` - [ $rc -eq 1 ] && return 0 - fi - return 1 -} - check_current_fadump_status() { # Check if firmware-assisted dump has been registered. @@ -892,16 +909,6 @@ save_raw() return 0 } -get_save_path() -{ - local _save_path=$(grep "^path" /etc/kdump.conf|awk '{print $2}') - if [ -z "$_save_path" ]; then - _save_path="/var/crash" - fi - - echo $_save_path -} - is_dump_target_configured() { local _target @@ -937,6 +944,9 @@ path_to_be_relabeled() fi fi + if is_mount_in_dracut_args; then + return; + fi _path=$(get_save_path) # if $_path is masked by other mount, we will not relabel it. _rmnt=$(df $_mnt/$_path 2>/dev/null | tail -1 | awk '{ print $NF }') diff --git a/SOURCES/kexec-tools-2.0.14-Only-print-debug-message-when-failed-to-serach-for-k.patch b/SOURCES/kexec-tools-2.0.14-Only-print-debug-message-when-failed-to-serach-for-k.patch deleted file mode 100644 index 0a312f1..0000000 --- a/SOURCES/kexec-tools-2.0.14-Only-print-debug-message-when-failed-to-serach-for-k.patch +++ /dev/null @@ -1,40 +0,0 @@ -From f85183096d31d865c97565614535d84943b12908 Mon Sep 17 00:00:00 2001 -Message-Id: -From: Baoquan He -Date: Fri, 3 Mar 2017 11:52:15 +0800 -Subject: [PATCH 01/10] Only print debug message when failed to serach for - kernel symbol from /proc/kallsyms - -Kernel symbol page_offset_base could be unavailable when mm KASLR code is -not compiled in kernel. It's inappropriate to print out error message -when failed to search for page_offset_base from /proc/kallsyms. Seems now -there is not a way to find out if mm KASLR is compiled in or not. An -alternative approach is only printing out debug message in get_kernel_sym -if failed to search a expected kernel symbol. - -Do it in this patch, a simple fix. - -Signed-off-by: Baoquan He -Reviewed-by: Pratyush Anand -Acked-by: Dave Young -Signed-off-by: Simon Horman ---- - kexec/arch/i386/crashdump-x86.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c -index 88aeee33572b..c4cf2013a001 100644 ---- a/kexec/arch/i386/crashdump-x86.c -+++ b/kexec/arch/i386/crashdump-x86.c -@@ -127,7 +127,7 @@ static unsigned long long get_kernel_sym(const char *symbol) - } - } - -- fprintf(stderr, "Cannot get kernel %s symbol address\n", symbol); -+ dbgprintf("Cannot get kernel %s symbol address\n", symbol); - return 0; - } - --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-arm64-identify-PHYS_OFFSET-correctly.patch b/SOURCES/kexec-tools-2.0.14-arm64-identify-PHYS_OFFSET-correctly.patch deleted file mode 100644 index 6d63dd8..0000000 --- a/SOURCES/kexec-tools-2.0.14-arm64-identify-PHYS_OFFSET-correctly.patch +++ /dev/null @@ -1,76 +0,0 @@ -From 7a4381e2042e2be308c96bc927145bc39a0594cc Mon Sep 17 00:00:00 2001 -Message-Id: <7a4381e2042e2be308c96bc927145bc39a0594cc.1489676829.git.panand@redhat.com> -In-Reply-To: -References: -From: AKASHI Takahiro -Date: Wed, 15 Mar 2017 18:38:18 +0900 -Subject: [PATCH 04/10] arm64: identify PHYS_OFFSET correctly - -Due to the kernel patch, commit e7cd190385d1 ("arm64: mark reserved -memblock regions explicitly in iomem"), the current code will not be able -to identify the correct value of PHYS_OFFSET if some "reserved" memory -region, which is likely to be UEFI runtime services code/data, exists at -an address below the first "System RAM" regions. - -This patch fixes this issue. - -Signed-off-by: AKASHI Takahiro ---- - kexec/arch/arm64/iomem.h | 7 +++++++ - kexec/arch/arm64/kexec-arm64.c | 12 ++++++++++-- - 2 files changed, 17 insertions(+), 2 deletions(-) - create mode 100644 kexec/arch/arm64/iomem.h - -diff --git a/kexec/arch/arm64/iomem.h b/kexec/arch/arm64/iomem.h -new file mode 100644 -index 000000000000..7fd66eb063e1 ---- /dev/null -+++ b/kexec/arch/arm64/iomem.h -@@ -0,0 +1,7 @@ -+#ifndef IOMEM_H -+#define IOMEM_H -+ -+#define SYSTEM_RAM "System RAM\n" -+#define IOMEM_RESERVED "reserved\n" -+ -+#endif -diff --git a/kexec/arch/arm64/kexec-arm64.c b/kexec/arch/arm64/kexec-arm64.c -index 04fd3968bb52..d02b9dac3d33 100644 ---- a/kexec/arch/arm64/kexec-arm64.c -+++ b/kexec/arch/arm64/kexec-arm64.c -@@ -21,6 +21,7 @@ - #include "crashdump-arm64.h" - #include "dt-ops.h" - #include "fs2dt.h" -+#include "iomem.h" - #include "kexec-syscall.h" - #include "arch/options.h" - -@@ -476,7 +477,14 @@ static int get_memory_ranges_iomem_cb(void *data, int nr, char *str, - return -1; - - r = (struct memory_range *)data + nr; -- r->type = RANGE_RAM; -+ -+ if (!strncmp(str, SYSTEM_RAM, strlen(SYSTEM_RAM))) -+ r->type = RANGE_RAM; -+ else if (!strncmp(str, IOMEM_RESERVED, strlen(IOMEM_RESERVED))) -+ r->type = RANGE_RESERVED; -+ else -+ return 1; -+ - r->start = base; - r->end = base + length - 1; - -@@ -495,7 +503,7 @@ static int get_memory_ranges_iomem_cb(void *data, int nr, char *str, - static int get_memory_ranges_iomem(struct memory_range *array, - unsigned int *count) - { -- *count = kexec_iomem_for_each_line("System RAM\n", -+ *count = kexec_iomem_for_each_line(NULL, - get_memory_ranges_iomem_cb, array); - - if (!*count) { --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-arm64-kdump-Add-support-for-binary-image-files.patch b/SOURCES/kexec-tools-2.0.14-arm64-kdump-Add-support-for-binary-image-files.patch deleted file mode 100644 index bbdf554..0000000 --- a/SOURCES/kexec-tools-2.0.14-arm64-kdump-Add-support-for-binary-image-files.patch +++ /dev/null @@ -1,52 +0,0 @@ -From ba77ebdac0d49ac128f4d31a5fd86e8165ce916a Mon Sep 17 00:00:00 2001 -Message-Id: -In-Reply-To: -References: -From: Pratyush Anand -Date: Wed, 15 Mar 2017 18:38:24 +0900 -Subject: [PATCH 10/10] arm64: kdump: Add support for binary image files - -This patch adds support to use binary image ie arch/arm64/boot/Image with -kdump. - -Signed-off-by: Pratyush Anand -[takahiro.akashi@linaro.org: a bit reworked] -Signed-off-by: AKASHI Takahiro ---- - kexec/arch/arm64/kexec-image-arm64.c | 12 ++++++++++++ - 1 file changed, 12 insertions(+) - -diff --git a/kexec/arch/arm64/kexec-image-arm64.c b/kexec/arch/arm64/kexec-image-arm64.c -index 960ed9667a4d..982e431e6d22 100644 ---- a/kexec/arch/arm64/kexec-image-arm64.c -+++ b/kexec/arch/arm64/kexec-image-arm64.c -@@ -4,7 +4,9 @@ - - #define _GNU_SOURCE - -+#include "crashdump-arm64.h" - #include "kexec-arm64.h" -+#include "kexec-syscall.h" - #include - - int image_arm64_probe(const char *kernel_buf, off_t kernel_size) -@@ -58,6 +60,16 @@ int image_arm64_load(int argc, char **argv, const char *kernel_buf, - dbgprintf("%s: PE format: %s\n", __func__, - (arm64_header_check_pe_sig(header) ? "yes" : "no")); - -+ if (info->kexec_flags & KEXEC_ON_CRASH) { -+ /* create and initialize elf core header segment */ -+ result = load_crashdump_segments(info); -+ if (result) { -+ dbgprintf("%s: Creating eflcorehdr failed.\n", -+ __func__); -+ goto exit; -+ } -+ } -+ - /* load the kernel */ - add_segment_phys_virt(info, kernel_buf, kernel_size, - kernel_segment + arm64_mem.text_offset, --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-arm64-kdump-add-DT-properties-to-crash-dump-kernel-s.patch b/SOURCES/kexec-tools-2.0.14-arm64-kdump-add-DT-properties-to-crash-dump-kernel-s.patch deleted file mode 100644 index 5414e17..0000000 --- a/SOURCES/kexec-tools-2.0.14-arm64-kdump-add-DT-properties-to-crash-dump-kernel-s.patch +++ /dev/null @@ -1,282 +0,0 @@ -From 7c59b94be4abf8b28dd02bae8b79542377a86618 Mon Sep 17 00:00:00 2001 -Message-Id: <7c59b94be4abf8b28dd02bae8b79542377a86618.1489676829.git.panand@redhat.com> -In-Reply-To: -References: -From: AKASHI Takahiro -Date: Wed, 15 Mar 2017 18:38:23 +0900 -Subject: [PATCH 09/10] arm64: kdump: add DT properties to crash dump kernel's - dtb - -We pass the following properties to crash dump kernel: -linux,elfcorehdr: elf core header segment, - same as "elfcorehdr=" kernel parameter on other archs -linux,usable-memory-range: usable memory reserved for crash dump kernel - -Signed-off-by: AKASHI Takahiro ---- - kexec/arch/arm64/kexec-arm64.c | 197 ++++++++++++++++++++++++++++++++++++- - kexec/arch/arm64/kexec-elf-arm64.c | 5 - - 2 files changed, 192 insertions(+), 10 deletions(-) - -diff --git a/kexec/arch/arm64/kexec-arm64.c b/kexec/arch/arm64/kexec-arm64.c -index 5e30107b043f..f3f101d1be48 100644 ---- a/kexec/arch/arm64/kexec-arm64.c -+++ b/kexec/arch/arm64/kexec-arm64.c -@@ -25,6 +25,14 @@ - #include "kexec-syscall.h" - #include "arch/options.h" - -+#define ROOT_NODE_ADDR_CELLS_DEFAULT 1 -+#define ROOT_NODE_SIZE_CELLS_DEFAULT 1 -+ -+#define PROP_ADDR_CELLS "#address-cells" -+#define PROP_SIZE_CELLS "#size-cells" -+#define PROP_ELFCOREHDR "linux,elfcorehdr" -+#define PROP_USABLE_MEM_RANGE "linux,usable-memory-range" -+ - /* Global varables the core kexec routines expect. */ - - unsigned char reuse_initrd; -@@ -128,9 +136,6 @@ int arch_process_options(int argc, char **argv) - case OPT_INITRD: - arm64_opts.initrd = optarg; - break; -- case OPT_PANIC: -- die("load-panic (-p) not supported"); -- break; - default: - break; /* Ignore core and unknown options. */ - } -@@ -281,12 +286,115 @@ on_success: - return 0; - } - -+static int get_cells_size(void *fdt, uint32_t *address_cells, -+ uint32_t *size_cells) -+{ -+ int nodeoffset; -+ const uint32_t *prop = NULL; -+ int prop_len; -+ -+ /* default values */ -+ *address_cells = ROOT_NODE_ADDR_CELLS_DEFAULT; -+ *size_cells = ROOT_NODE_SIZE_CELLS_DEFAULT; -+ -+ /* under root node */ -+ nodeoffset = fdt_path_offset(fdt, "/"); -+ if (nodeoffset < 0) -+ goto on_error; -+ -+ prop = fdt_getprop(fdt, nodeoffset, PROP_ADDR_CELLS, &prop_len); -+ if (prop) { -+ if (prop_len == sizeof(*prop)) -+ *address_cells = fdt32_to_cpu(*prop); -+ else -+ goto on_error; -+ } -+ -+ prop = fdt_getprop(fdt, nodeoffset, PROP_SIZE_CELLS, &prop_len); -+ if (prop) { -+ if (prop_len == sizeof(*prop)) -+ *size_cells = fdt32_to_cpu(*prop); -+ else -+ goto on_error; -+ } -+ -+ dbgprintf("%s: #address-cells:%d #size-cells:%d\n", __func__, -+ *address_cells, *size_cells); -+ return 0; -+ -+on_error: -+ return -EFAILED; -+} -+ -+bool cells_size_fitted(uint32_t address_cells, uint32_t size_cells, -+ struct memory_range *range) -+{ -+ dbgprintf("%s: %llx-%llx\n", __func__, range->start, range->end); -+ -+ /* if *_cells >= 2, cells can hold 64-bit values anyway */ -+ if ((address_cells == 1) && (range->start >= (1ULL << 32))) -+ return false; -+ -+ if ((size_cells == 1) && -+ ((range->end - range->start + 1) >= (1ULL << 32))) -+ return false; -+ -+ return true; -+} -+ -+static void fill_property(void *buf, uint64_t val, uint32_t cells) -+{ -+ uint32_t val32; -+ int i; -+ -+ if (cells == 1) { -+ val32 = cpu_to_fdt32((uint32_t)val); -+ memcpy(buf, &val32, sizeof(uint32_t)); -+ } else { -+ for (i = 0; -+ i < (cells * sizeof(uint32_t) - sizeof(uint64_t)); i++) -+ *(char *)buf++ = 0; -+ -+ val = cpu_to_fdt64(val); -+ memcpy(buf, &val, sizeof(uint64_t)); -+ } -+} -+ -+static int setprop_range(void *fdt, int nodeoffset, -+ const char *name, struct memory_range *range, -+ uint32_t address_cells, uint32_t size_cells) -+{ -+ void *buf, *prop; -+ size_t buf_size; -+ int result; -+ -+ buf_size = (address_cells + size_cells) * sizeof(uint32_t); -+ prop = buf = xmalloc(buf_size); -+ -+ fill_property(prop, range->start, address_cells); -+ prop += address_cells * sizeof(uint32_t); -+ -+ fill_property(prop, range->end - range->start + 1, size_cells); -+ prop += size_cells * sizeof(uint32_t); -+ -+ result = fdt_setprop(fdt, nodeoffset, name, buf, buf_size); -+ -+ free(buf); -+ -+ return result; -+} -+ - /** - * setup_2nd_dtb - Setup the 2nd stage kernel's dtb. - */ - --static int setup_2nd_dtb(struct dtb *dtb, char *command_line) -+static int setup_2nd_dtb(struct dtb *dtb, char *command_line, int on_crash) - { -+ uint32_t address_cells, size_cells; -+ int range_len; -+ int nodeoffset; -+ char *new_buf = NULL; -+ int new_size; - int result; - - result = fdt_check_header(dtb->buf); -@@ -298,8 +406,86 @@ static int setup_2nd_dtb(struct dtb *dtb, char *command_line) - - result = set_bootargs(dtb, command_line); - -+ if (on_crash) { -+ /* determine #address-cells and #size-cells */ -+ result = get_cells_size(dtb->buf, &address_cells, &size_cells); -+ if (result) { -+ fprintf(stderr, -+ "kexec: cannot determine cells-size.\n"); -+ result = -EINVAL; -+ goto on_error; -+ } -+ -+ if (!cells_size_fitted(address_cells, size_cells, -+ &elfcorehdr_mem)) { -+ fprintf(stderr, -+ "kexec: elfcorehdr doesn't fit cells-size.\n"); -+ result = -EINVAL; -+ goto on_error; -+ } -+ -+ if (!cells_size_fitted(address_cells, size_cells, -+ &crash_reserved_mem)) { -+ fprintf(stderr, -+ "kexec: usable memory range doesn't fit cells-size.\n"); -+ result = -EINVAL; -+ goto on_error; -+ } -+ -+ /* duplicate dt blob */ -+ range_len = sizeof(uint32_t) * (address_cells + size_cells); -+ new_size = fdt_totalsize(dtb->buf) -+ + fdt_prop_len(PROP_ELFCOREHDR, range_len) -+ + fdt_prop_len(PROP_USABLE_MEM_RANGE, range_len); -+ -+ new_buf = xmalloc(new_size); -+ result = fdt_open_into(dtb->buf, new_buf, new_size); -+ if (result) { -+ dbgprintf("%s: fdt_open_into failed: %s\n", __func__, -+ fdt_strerror(result)); -+ result = -ENOSPC; -+ goto on_error; -+ } -+ -+ /* add linux,elfcorehdr */ -+ nodeoffset = fdt_path_offset(new_buf, "/chosen"); -+ result = setprop_range(new_buf, nodeoffset, -+ PROP_ELFCOREHDR, &elfcorehdr_mem, -+ address_cells, size_cells); -+ if (result) { -+ dbgprintf("%s: fdt_setprop failed: %s\n", __func__, -+ fdt_strerror(result)); -+ result = -EINVAL; -+ goto on_error; -+ } -+ -+ /* add linux,usable-memory-range */ -+ nodeoffset = fdt_path_offset(new_buf, "/chosen"); -+ result = setprop_range(new_buf, nodeoffset, -+ PROP_USABLE_MEM_RANGE, &crash_reserved_mem, -+ address_cells, size_cells); -+ if (result) { -+ dbgprintf("%s: fdt_setprop failed: %s\n", __func__, -+ fdt_strerror(result)); -+ result = -EINVAL; -+ goto on_error; -+ } -+ -+ fdt_pack(new_buf); -+ dtb->buf = new_buf; -+ dtb->size = fdt_totalsize(new_buf); -+ } -+ - dump_reservemap(dtb); - -+ -+ return result; -+ -+on_error: -+ fprintf(stderr, "kexec: %s failed.\n", __func__); -+ if (new_buf) -+ free(new_buf); -+ - return result; - } - -@@ -367,7 +553,8 @@ int arm64_load_other_segments(struct kexec_info *info, - } - } - -- result = setup_2nd_dtb(&dtb, command_line); -+ result = setup_2nd_dtb(&dtb, command_line, -+ info->kexec_flags & KEXEC_ON_CRASH); - - if (result) - return -EFAILED; -diff --git a/kexec/arch/arm64/kexec-elf-arm64.c b/kexec/arch/arm64/kexec-elf-arm64.c -index 842ce21e2387..b17a31afa24e 100644 ---- a/kexec/arch/arm64/kexec-elf-arm64.c -+++ b/kexec/arch/arm64/kexec-elf-arm64.c -@@ -47,11 +47,6 @@ int elf_arm64_load(int argc, char **argv, const char *kernel_buf, - int result; - int i; - -- if (info->kexec_flags & KEXEC_ON_CRASH) { -- fprintf(stderr, "kexec: kdump not yet supported on arm64\n"); -- return -EFAILED; -- } -- - result = build_elf_exec_info(kernel_buf, kernel_size, &ehdr, 0); - - if (result < 0) { --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-arm64-kdump-add-elf-core-header-segment.patch b/SOURCES/kexec-tools-2.0.14-arm64-kdump-add-elf-core-header-segment.patch deleted file mode 100644 index 6c24d59..0000000 --- a/SOURCES/kexec-tools-2.0.14-arm64-kdump-add-elf-core-header-segment.patch +++ /dev/null @@ -1,191 +0,0 @@ -From dd3886b82ed56c18d9d6d0e7228a2b31eed0ec5a Mon Sep 17 00:00:00 2001 -Message-Id: -In-Reply-To: -References: -From: AKASHI Takahiro -Date: Wed, 15 Mar 2017 18:38:20 +0900 -Subject: [PATCH 06/10] arm64: kdump: add elf core header segment - -Elf core header contains the information necessary for the coredump of -the 1st kernel, including its physcal memory layout as well as cpu register -states at the panic. -The segment is allocated inside the reserved memory of crash dump kernel. - -Signed-off-by: AKASHI Takahiro ---- - kexec/arch/arm64/crashdump-arm64.c | 96 ++++++++++++++++++++++++++++++++++++++ - kexec/arch/arm64/crashdump-arm64.h | 3 ++ - kexec/arch/arm64/iomem.h | 2 + - kexec/arch/arm64/kexec-elf-arm64.c | 10 ++++ - 4 files changed, 111 insertions(+) - -diff --git a/kexec/arch/arm64/crashdump-arm64.c b/kexec/arch/arm64/crashdump-arm64.c -index dcaca434af62..83461312d412 100644 ---- a/kexec/arch/arm64/crashdump-arm64.c -+++ b/kexec/arch/arm64/crashdump-arm64.c -@@ -39,6 +39,39 @@ struct memory_ranges usablemem_rgns = { - .ranges = &crash_reserved_mem, - }; - -+struct memory_range elfcorehdr_mem; -+ -+static struct crash_elf_info elf_info = { -+ .class = ELFCLASS64, -+#if (__BYTE_ORDER == __LITTLE_ENDIAN) -+ .data = ELFDATA2LSB, -+#else -+ .data = ELFDATA2MSB, -+#endif -+ .machine = EM_AARCH64, -+}; -+ -+/* -+ * Note: The returned value is correct only if !CONFIG_RANDOMIZE_BASE. -+ */ -+static uint64_t get_kernel_page_offset(void) -+{ -+ int i; -+ -+ if (elf_info.kern_vaddr_start == UINT64_MAX) -+ return UINT64_MAX; -+ -+ /* Current max virtual memory range is 48-bits. */ -+ for (i = 48; i > 0; i--) -+ if (!(elf_info.kern_vaddr_start & (1UL << i))) -+ break; -+ -+ if (i <= 0) -+ return UINT64_MAX; -+ else -+ return UINT64_MAX << i; -+} -+ - /* - * iomem_range_callback() - callback called for each iomem region - * @data: not used -@@ -62,6 +95,10 @@ static int iomem_range_callback(void *UNUSED(data), int UNUSED(nr), - else if (strncmp(str, SYSTEM_RAM, strlen(SYSTEM_RAM)) == 0) - return mem_regions_add(&crash_memory_rgns, - base, length, RANGE_RAM); -+ else if (strncmp(str, KERNEL_CODE, strlen(KERNEL_CODE)) == 0) -+ elf_info.kern_paddr_start = base; -+ else if (strncmp(str, KERNEL_DATA, strlen(KERNEL_DATA)) == 0) -+ elf_info.kern_size = base + length - elf_info.kern_paddr_start; - - return 0; - } -@@ -115,5 +152,64 @@ static int crash_get_memory_ranges(void) - dbgprint_mem_range("Coredump memory ranges", - crash_memory_rgns.ranges, crash_memory_rgns.size); - -+ /* -+ * For additional kernel code/data segment. -+ * kern_paddr_start/kern_size are determined in iomem_range_callback -+ */ -+ elf_info.kern_vaddr_start = get_kernel_sym("_text"); -+ if (!elf_info.kern_vaddr_start) -+ elf_info.kern_vaddr_start = UINT64_MAX; -+ -+ return 0; -+} -+ -+/* -+ * load_crashdump_segments() - load the elf core header -+ * @info: kexec info structure -+ * -+ * This function creates and loads an additional segment of elf core header -+ : which is used to construct /proc/vmcore on crash dump kernel. -+ * -+ * Return 0 in case of success and -1 in case of error. -+ */ -+ -+int load_crashdump_segments(struct kexec_info *info) -+{ -+ unsigned long elfcorehdr; -+ unsigned long bufsz; -+ void *buf; -+ int err; -+ -+ /* -+ * First fetch all the memory (RAM) ranges that we are going to -+ * pass to the crash dump kernel during panic. -+ */ -+ -+ err = crash_get_memory_ranges(); -+ -+ if (err) -+ return err; -+ -+ elf_info.page_offset = get_kernel_page_offset(); -+ dbgprintf("%s: page_offset: %016llx\n", __func__, -+ elf_info.page_offset); -+ -+ err = crash_create_elf64_headers(info, &elf_info, -+ crash_memory_rgns.ranges, crash_memory_rgns.size, -+ &buf, &bufsz, ELF_CORE_HEADER_ALIGN); -+ -+ if (err) -+ return err; -+ -+ elfcorehdr = add_buffer_phys_virt(info, buf, bufsz, bufsz, 0, -+ crash_reserved_mem.start, crash_reserved_mem.end, -+ -1, 0); -+ -+ elfcorehdr_mem.start = elfcorehdr; -+ elfcorehdr_mem.end = elfcorehdr + bufsz - 1; -+ -+ dbgprintf("%s: elfcorehdr 0x%llx-0x%llx\n", __func__, -+ elfcorehdr_mem.start, elfcorehdr_mem.end); -+ - return 0; - } -diff --git a/kexec/arch/arm64/crashdump-arm64.h b/kexec/arch/arm64/crashdump-arm64.h -index 07a0ed0bc344..da75a2d0c5f1 100644 ---- a/kexec/arch/arm64/crashdump-arm64.h -+++ b/kexec/arch/arm64/crashdump-arm64.h -@@ -18,5 +18,8 @@ - - extern struct memory_ranges usablemem_rgns; - extern struct memory_range crash_reserved_mem; -+extern struct memory_range elfcorehdr_mem; -+ -+extern int load_crashdump_segments(struct kexec_info *info); - - #endif /* CRASHDUMP_ARM64_H */ -diff --git a/kexec/arch/arm64/iomem.h b/kexec/arch/arm64/iomem.h -index 20cda87dbd02..d4864bb44922 100644 ---- a/kexec/arch/arm64/iomem.h -+++ b/kexec/arch/arm64/iomem.h -@@ -2,6 +2,8 @@ - #define IOMEM_H - - #define SYSTEM_RAM "System RAM\n" -+#define KERNEL_CODE "Kernel code\n" -+#define KERNEL_DATA "Kernel data\n" - #define CRASH_KERNEL "Crash kernel\n" - #define IOMEM_RESERVED "reserved\n" - -diff --git a/kexec/arch/arm64/kexec-elf-arm64.c b/kexec/arch/arm64/kexec-elf-arm64.c -index daf8bf0df9c4..c70a37ae7732 100644 ---- a/kexec/arch/arm64/kexec-elf-arm64.c -+++ b/kexec/arch/arm64/kexec-elf-arm64.c -@@ -119,6 +119,16 @@ int elf_arm64_load(int argc, char **argv, const char *kernel_buf, - dbgprintf("%s: PE format: %s\n", __func__, - (arm64_header_check_pe_sig(header) ? "yes" : "no")); - -+ if (info->kexec_flags & KEXEC_ON_CRASH) { -+ /* create and initialize elf core header segment */ -+ result = load_crashdump_segments(info); -+ if (result) { -+ dbgprintf("%s: Creating eflcorehdr failed.\n", -+ __func__); -+ goto exit; -+ } -+ } -+ - /* load the kernel */ - result = elf_exec_load(&ehdr, info); - --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-arm64-kdump-identify-memory-regions.patch b/SOURCES/kexec-tools-2.0.14-arm64-kdump-identify-memory-regions.patch deleted file mode 100644 index b914e43..0000000 --- a/SOURCES/kexec-tools-2.0.14-arm64-kdump-identify-memory-regions.patch +++ /dev/null @@ -1,202 +0,0 @@ -From 2fa1ef9e45b3ce6f7977a2518e58e177934f377c Mon Sep 17 00:00:00 2001 -Message-Id: <2fa1ef9e45b3ce6f7977a2518e58e177934f377c.1489676829.git.panand@redhat.com> -In-Reply-To: -References: -From: AKASHI Takahiro -Date: Wed, 15 Mar 2017 18:38:19 +0900 -Subject: [PATCH 05/10] arm64: kdump: identify memory regions - -The following regions need to be identified for later use: - a) memory regions which belong to the 1st kernel - b) usable memory reserved for crash dump kernel - -We go through /proc/iomem to find out a) and b) which are marked -as "System RAM" and "Crash kernel", respectively. - -Signed-off-by: AKASHI Takahiro ---- - kexec/arch/arm64/Makefile | 2 + - kexec/arch/arm64/crashdump-arm64.c | 100 ++++++++++++++++++++++++++++++++++++- - kexec/arch/arm64/crashdump-arm64.h | 14 +++++- - kexec/arch/arm64/iomem.h | 1 + - 4 files changed, 114 insertions(+), 3 deletions(-) - -diff --git a/kexec/arch/arm64/Makefile b/kexec/arch/arm64/Makefile -index 74b677f7784e..2d4ae0eed9e0 100644 ---- a/kexec/arch/arm64/Makefile -+++ b/kexec/arch/arm64/Makefile -@@ -6,6 +6,8 @@ arm64_FS2DT_INCLUDE += \ - - arm64_DT_OPS += kexec/dt-ops.c - -+arm64_MEM_REGIONS = kexec/mem_regions.c -+ - arm64_CPPFLAGS += -I $(srcdir)/kexec/ - - arm64_KEXEC_SRCS += \ -diff --git a/kexec/arch/arm64/crashdump-arm64.c b/kexec/arch/arm64/crashdump-arm64.c -index d2272c8124d0..dcaca434af62 100644 ---- a/kexec/arch/arm64/crashdump-arm64.c -+++ b/kexec/arch/arm64/crashdump-arm64.c -@@ -1,5 +1,13 @@ - /* - * ARM64 crashdump. -+ * partly derived from arm implementation -+ * -+ * Copyright (c) 2014-2016 Linaro Limited -+ * Author: AKASHI Takahiro -+ * -+ * This program is free software; you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License version 2 as -+ * published by the Free Software Foundation. - */ - - #define _GNU_SOURCE -@@ -10,12 +18,102 @@ - #include "kexec.h" - #include "crashdump.h" - #include "crashdump-arm64.h" -+#include "iomem.h" - #include "kexec-arm64.h" - #include "kexec-elf.h" -+#include "mem_regions.h" - --struct memory_ranges usablemem_rgns = {}; -+/* memory ranges on crashed kernel */ -+static struct memory_range crash_memory_ranges[CRASH_MAX_MEMORY_RANGES]; -+static struct memory_ranges crash_memory_rgns = { -+ .size = 0, -+ .max_size = CRASH_MAX_MEMORY_RANGES, -+ .ranges = crash_memory_ranges, -+}; -+ -+/* memory range reserved for crashkernel */ -+struct memory_range crash_reserved_mem; -+struct memory_ranges usablemem_rgns = { -+ .size = 0, -+ .max_size = 1, -+ .ranges = &crash_reserved_mem, -+}; -+ -+/* -+ * iomem_range_callback() - callback called for each iomem region -+ * @data: not used -+ * @nr: not used -+ * @str: name of the memory region -+ * @base: start address of the memory region -+ * @length: size of the memory region -+ * -+ * This function is called once for each memory region found in /proc/iomem. -+ * It locates system RAM and crashkernel reserved memory and places these to -+ * variables, respectively, crash_memory_ranges and crash_reserved_mem. -+ */ -+ -+static int iomem_range_callback(void *UNUSED(data), int UNUSED(nr), -+ char *str, unsigned long long base, -+ unsigned long long length) -+{ -+ if (strncmp(str, CRASH_KERNEL, strlen(CRASH_KERNEL)) == 0) -+ return mem_regions_add(&usablemem_rgns, -+ base, length, RANGE_RAM); -+ else if (strncmp(str, SYSTEM_RAM, strlen(SYSTEM_RAM)) == 0) -+ return mem_regions_add(&crash_memory_rgns, -+ base, length, RANGE_RAM); -+ -+ return 0; -+} - - int is_crashkernel_mem_reserved(void) - { -+ if (!crash_reserved_mem.end) -+ kexec_iomem_for_each_line(NULL, iomem_range_callback, NULL); -+ -+ return crash_reserved_mem.start != crash_reserved_mem.end; -+} -+ -+/* -+ * crash_get_memory_ranges() - read system physical memory -+ * -+ * Function reads through system physical memory and stores found memory -+ * regions in crash_memory_ranges. -+ * Regions are sorted in ascending order. -+ * -+ * Returns 0 in case of success and -1 otherwise (errno is set). -+ */ -+static int crash_get_memory_ranges(void) -+{ -+ /* -+ * First read all memory regions that can be considered as -+ * system memory including the crash area. -+ */ -+ if (!usablemem_rgns.size) -+ kexec_iomem_for_each_line(NULL, iomem_range_callback, NULL); -+ -+ /* allow only a single region for crash dump kernel */ -+ if (usablemem_rgns.size != 1) { -+ errno = EINVAL; -+ return -1; -+ } -+ -+ dbgprint_mem_range("Reserved memory range", &crash_reserved_mem, 1); -+ -+ if (mem_regions_exclude(&crash_memory_rgns, &crash_reserved_mem)) { -+ fprintf(stderr, -+ "Error: Number of crash memory ranges excedeed the max limit\n"); -+ errno = ENOMEM; -+ return -1; -+ } -+ -+ /* -+ * Make sure that the memory regions are sorted. -+ */ -+ mem_regions_sort(&crash_memory_rgns); -+ -+ dbgprint_mem_range("Coredump memory ranges", -+ crash_memory_rgns.ranges, crash_memory_rgns.size); -+ - return 0; - } -diff --git a/kexec/arch/arm64/crashdump-arm64.h b/kexec/arch/arm64/crashdump-arm64.h -index f33c7a25b454..07a0ed0bc344 100644 ---- a/kexec/arch/arm64/crashdump-arm64.h -+++ b/kexec/arch/arm64/crashdump-arm64.h -@@ -1,12 +1,22 @@ - /* - * ARM64 crashdump. -+ * -+ * Copyright (c) 2014-2016 Linaro Limited -+ * Author: AKASHI Takahiro -+ * -+ * This program is free software; you can redistribute it and/or modify -+ * it under the terms of the GNU General Public License version 2 as -+ * published by the Free Software Foundation. - */ - --#if !defined(CRASHDUMP_ARM64_H) -+#ifndef CRASHDUMP_ARM64_H - #define CRASHDUMP_ARM64_H - - #include "kexec.h" - -+#define CRASH_MAX_MEMORY_RANGES 32 -+ - extern struct memory_ranges usablemem_rgns; -+extern struct memory_range crash_reserved_mem; - --#endif -+#endif /* CRASHDUMP_ARM64_H */ -diff --git a/kexec/arch/arm64/iomem.h b/kexec/arch/arm64/iomem.h -index 7fd66eb063e1..20cda87dbd02 100644 ---- a/kexec/arch/arm64/iomem.h -+++ b/kexec/arch/arm64/iomem.h -@@ -2,6 +2,7 @@ - #define IOMEM_H - - #define SYSTEM_RAM "System RAM\n" -+#define CRASH_KERNEL "Crash kernel\n" - #define IOMEM_RESERVED "reserved\n" - - #endif --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-arm64-kdump-set-up-kernel-image-segment.patch b/SOURCES/kexec-tools-2.0.14-arm64-kdump-set-up-kernel-image-segment.patch deleted file mode 100644 index 47c71fd..0000000 --- a/SOURCES/kexec-tools-2.0.14-arm64-kdump-set-up-kernel-image-segment.patch +++ /dev/null @@ -1,140 +0,0 @@ -From af338a51df9012f1b1dca87ddd27a5c66db5b80b Mon Sep 17 00:00:00 2001 -Message-Id: -In-Reply-To: -References: -From: AKASHI Takahiro -Date: Wed, 15 Mar 2017 18:38:21 +0900 -Subject: [PATCH 07/10] arm64: kdump: set up kernel image segment - -On arm64, we can use the same kernel image as 1st kernel, but -we have to modify the entry point as well as segments' addresses -in the kernel's elf header in order to load them into correct places. - -Minor conflicts was resolved in kexec/arch/arm64/crashdump-arm64.c because -get_crash_kernel_load_range() is not yet backported. - -Signed-off-by: AKASHI Takahiro ---- - kexec/arch/arm64/crashdump-arm64.c | 23 +++++++++++++++++++++++ - kexec/arch/arm64/crashdump-arm64.h | 1 + - kexec/arch/arm64/kexec-arm64.c | 25 ++++++++++++++++++++----- - kexec/arch/arm64/kexec-elf-arm64.c | 10 +++++++++- - 4 files changed, 53 insertions(+), 6 deletions(-) - -diff --git a/kexec/arch/arm64/crashdump-arm64.c b/kexec/arch/arm64/crashdump-arm64.c -index 83461312d412..9517329e1086 100644 ---- a/kexec/arch/arm64/crashdump-arm64.c -+++ b/kexec/arch/arm64/crashdump-arm64.c -@@ -213,3 +213,26 @@ int load_crashdump_segments(struct kexec_info *info) - - return 0; - } -+ -+/* -+ * e_entry and p_paddr are actually in virtual address space. -+ * Those values will be translated to physcal addresses by -+ * using virt_to_phys(). -+ * So let's get ready for later use so the memory base (phys_offset) -+ * will be correctly replaced with crash_reserved_mem.start. -+ */ -+void modify_ehdr_for_crashdump(struct mem_ehdr *ehdr) -+{ -+ struct mem_phdr *phdr; -+ int i; -+ -+ ehdr->e_entry += - arm64_mem.phys_offset + crash_reserved_mem.start; -+ -+ for (i = 0; i < ehdr->e_phnum; i++) { -+ phdr = &ehdr->e_phdr[i]; -+ if (phdr->p_type != PT_LOAD) -+ continue; -+ phdr->p_paddr += -+ (-arm64_mem.phys_offset + crash_reserved_mem.start); -+ } -+} -diff --git a/kexec/arch/arm64/crashdump-arm64.h b/kexec/arch/arm64/crashdump-arm64.h -index da75a2d0c5f1..382f57154f2a 100644 ---- a/kexec/arch/arm64/crashdump-arm64.h -+++ b/kexec/arch/arm64/crashdump-arm64.h -@@ -21,5 +21,6 @@ extern struct memory_range crash_reserved_mem; - extern struct memory_range elfcorehdr_mem; - - extern int load_crashdump_segments(struct kexec_info *info); -+extern void modify_ehdr_for_crashdump(struct mem_ehdr *ehdr); - - #endif /* CRASHDUMP_ARM64_H */ -diff --git a/kexec/arch/arm64/kexec-arm64.c b/kexec/arch/arm64/kexec-arm64.c -index d02b9dac3d33..5a1da2ec1a34 100644 ---- a/kexec/arch/arm64/kexec-arm64.c -+++ b/kexec/arch/arm64/kexec-arm64.c -@@ -307,12 +307,27 @@ unsigned long arm64_locate_kernel_segment(struct kexec_info *info) - { - unsigned long hole; - -- hole = locate_hole(info, -- arm64_mem.text_offset + arm64_mem.image_size, -- MiB(2), 0, ULONG_MAX, 1); -+ if (info->kexec_flags & KEXEC_ON_CRASH) { -+ unsigned long hole_end; -+ -+ hole = (crash_reserved_mem.start < mem_min ? -+ mem_min : crash_reserved_mem.start); -+ hole = _ALIGN_UP(hole, MiB(2)); -+ hole_end = hole + arm64_mem.text_offset + arm64_mem.image_size; -+ -+ if ((hole_end > mem_max) || -+ (hole_end > crash_reserved_mem.end)) { -+ dbgprintf("%s: Crash kernel out of range\n", __func__); -+ hole = ULONG_MAX; -+ } -+ } else { -+ hole = locate_hole(info, -+ arm64_mem.text_offset + arm64_mem.image_size, -+ MiB(2), 0, ULONG_MAX, 1); - -- if (hole == ULONG_MAX) -- dbgprintf("%s: locate_hole failed\n", __func__); -+ if (hole == ULONG_MAX) -+ dbgprintf("%s: locate_hole failed\n", __func__); -+ } - - return hole; - } -diff --git a/kexec/arch/arm64/kexec-elf-arm64.c b/kexec/arch/arm64/kexec-elf-arm64.c -index c70a37ae7732..842ce21e2387 100644 ---- a/kexec/arch/arm64/kexec-elf-arm64.c -+++ b/kexec/arch/arm64/kexec-elf-arm64.c -@@ -9,6 +9,7 @@ - #include - #include - -+#include "crashdump-arm64.h" - #include "kexec-arm64.h" - #include "kexec-elf.h" - #include "kexec-syscall.h" -@@ -105,7 +106,8 @@ int elf_arm64_load(int argc, char **argv, const char *kernel_buf, - } - - arm64_mem.vp_offset = _ALIGN_DOWN(ehdr.e_entry, MiB(2)); -- arm64_mem.vp_offset -= kernel_segment - get_phys_offset(); -+ if (!(info->kexec_flags & KEXEC_ON_CRASH)) -+ arm64_mem.vp_offset -= kernel_segment - get_phys_offset(); - - dbgprintf("%s: kernel_segment: %016lx\n", __func__, kernel_segment); - dbgprintf("%s: text_offset: %016lx\n", __func__, -@@ -127,6 +129,12 @@ int elf_arm64_load(int argc, char **argv, const char *kernel_buf, - __func__); - goto exit; - } -+ -+ /* -+ * offset addresses in order to fit vmlinux -+ * (elf_exec) into crash kernel's memory -+ */ -+ modify_ehdr_for_crashdump(&ehdr); - } - - /* load the kernel */ --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-arm64-kdump-set-up-other-segments.patch b/SOURCES/kexec-tools-2.0.14-arm64-kdump-set-up-other-segments.patch deleted file mode 100644 index 7261936..0000000 --- a/SOURCES/kexec-tools-2.0.14-arm64-kdump-set-up-other-segments.patch +++ /dev/null @@ -1,35 +0,0 @@ -From 6b1b954c9b2faf4969fa9f285d4162bd41b78498 Mon Sep 17 00:00:00 2001 -Message-Id: <6b1b954c9b2faf4969fa9f285d4162bd41b78498.1489676829.git.panand@redhat.com> -In-Reply-To: -References: -From: AKASHI Takahiro -Date: Wed, 15 Mar 2017 18:38:22 +0900 -Subject: [PATCH 08/10] arm64: kdump: set up other segments - -We make sure that all the other segments, initrd and device-tree blob, -also be loaded into the reserved memory of crash dump kernel. - -Signed-off-by: AKASHI Takahiro ---- - kexec/arch/arm64/kexec-arm64.c | 5 ++++- - 1 file changed, 4 insertions(+), 1 deletion(-) - -diff --git a/kexec/arch/arm64/kexec-arm64.c b/kexec/arch/arm64/kexec-arm64.c -index 5a1da2ec1a34..5e30107b043f 100644 ---- a/kexec/arch/arm64/kexec-arm64.c -+++ b/kexec/arch/arm64/kexec-arm64.c -@@ -375,7 +375,10 @@ int arm64_load_other_segments(struct kexec_info *info, - /* Put the other segments after the image. */ - - hole_min = image_base + arm64_mem.image_size; -- hole_max = ULONG_MAX; -+ if (info->kexec_flags & KEXEC_ON_CRASH) -+ hole_max = crash_reserved_mem.end; -+ else -+ hole_max = ULONG_MAX; - - if (arm64_opts.initrd) { - initrd_buf = slurp_file(arm64_opts.initrd, &initrd_size); --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-build_mem_phdrs-check-if-p_paddr-is-invalid.patch b/SOURCES/kexec-tools-2.0.14-build_mem_phdrs-check-if-p_paddr-is-invalid.patch deleted file mode 100644 index f479086..0000000 --- a/SOURCES/kexec-tools-2.0.14-build_mem_phdrs-check-if-p_paddr-is-invalid.patch +++ /dev/null @@ -1,43 +0,0 @@ -From 5520739f1e6e31c7731d34d384bbaf4904282931 Mon Sep 17 00:00:00 2001 -Message-Id: <5520739f1e6e31c7731d34d384bbaf4904282931.1489470510.git.panand@redhat.com> -From: Pratyush Anand -Date: Wed, 1 Mar 2017 11:19:42 +0530 -Subject: [PATCH] build_mem_phdrs(): check if p_paddr is invalid - -Currently, all the p_paddr of PT_LOAD headers are assigned to 0, which -is not correct and could be misleading, since 0 is a valid physical -address. - -Upstream kernel commit "464920104bf7 /proc/kcore: update physical -address for kcore ram and text" fixed it and now invalid PT_LOAD is -assigned as -1. - -kexec/arch/i386/crashdump-x86.c:get_kernel_vaddr_and_size() uses kcore -interface and so calls build_mem_phdrs() for kcore PT_LOAD headers. - -This patch fixes build_mem_phdrs() to check if p_paddr is invalid. - -Signed-off-by: Pratyush Anand -Acked-by: Dave Young -Signed-off-by: Simon Horman ---- - kexec/kexec-elf.c | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) - -diff --git a/kexec/kexec-elf.c b/kexec/kexec-elf.c -index 1d6320a2f0e6..be60bbd48486 100644 ---- a/kexec/kexec-elf.c -+++ b/kexec/kexec-elf.c -@@ -432,7 +432,8 @@ static int build_mem_phdrs(const char *buf, off_t len, struct mem_ehdr *ehdr, - } - return -1; - } -- if ((phdr->p_paddr + phdr->p_memsz) < phdr->p_paddr) { -+ if (phdr->p_paddr != (unsigned long long)-1 && -+ (phdr->p_paddr + phdr->p_memsz) < phdr->p_paddr) { - /* The memory address wraps */ - if (probe_debug) { - fprintf(stderr, "ELF address wrap around\n"); --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-kexec-Increase-the-upper-limit-for-RAM-segments.patch b/SOURCES/kexec-tools-2.0.14-kexec-Increase-the-upper-limit-for-RAM-segments.patch deleted file mode 100644 index 7f95e1e..0000000 --- a/SOURCES/kexec-tools-2.0.14-kexec-Increase-the-upper-limit-for-RAM-segments.patch +++ /dev/null @@ -1,32 +0,0 @@ -From 24aa2d93cac316657a2c20f28b8687bbf7e22991 Mon Sep 17 00:00:00 2001 -Message-Id: <24aa2d93cac316657a2c20f28b8687bbf7e22991.1492785094.git.panand@redhat.com> -From: Sameer Goel -Date: Wed, 18 Jan 2017 16:15:12 -0700 -Subject: [PATCH] kexec: Increase the upper limit for RAM segments - -On a newer UEFI based Qualcomm target the number of system ram regions -retrieved from /proc/iomem are ~40. So increasing the current hardcoded -values to 64 from 16. - -Signed-off-by: Sameer Goel -Signed-off-by: Simon Horman ---- - kexec/arch/arm64/kexec-arm64.h | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/kexec/arch/arm64/kexec-arm64.h b/kexec/arch/arm64/kexec-arm64.h -index bac62f8b19e0..bd4c20e76d15 100644 ---- a/kexec/arch/arm64/kexec-arm64.h -+++ b/kexec/arch/arm64/kexec-arm64.h -@@ -11,7 +11,7 @@ - #include "image-header.h" - #include "kexec.h" - --#define KEXEC_SEGMENT_MAX 16 -+#define KEXEC_SEGMENT_MAX 64 - - #define BOOT_BLOCK_VERSION 17 - #define BOOT_BLOCK_LAST_COMP_VERSION 16 --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-kexec-exntend-the-semantics-of-kexec_iomem_for_each_.patch b/SOURCES/kexec-tools-2.0.14-kexec-exntend-the-semantics-of-kexec_iomem_for_each_.patch deleted file mode 100644 index 4842ea2..0000000 --- a/SOURCES/kexec-tools-2.0.14-kexec-exntend-the-semantics-of-kexec_iomem_for_each_.patch +++ /dev/null @@ -1,79 +0,0 @@ -From e7bb07ee7b499f71990e9e83596bdb2ddabdd4cd Mon Sep 17 00:00:00 2001 -Message-Id: -In-Reply-To: -References: -From: AKASHI Takahiro -Date: Wed, 15 Mar 2017 18:38:16 +0900 -Subject: [PATCH 02/10] kexec: exntend the semantics of - kexec_iomem_for_each_line - -The current kexec_iomem_for_each_line() counts up all the lines for which -a callback function returns zero(0) or positive, and otherwise it stops -further scanning. -This behavior is incovenient in some cases. For instance, on arm64, we want -to count up "System RAM" entries, but need to skip "reserved" entries. - -So this patch extends the semantics so that we will continue to scan -succeeding entries but not count lines for which a callback function -returns positive. - -The current users of kexec_iomem_for_each_line(), arm, sh and x86, will not -be affected by this change because -* arm - The callback function only returns -1 or 0, and the return value of - kexec_iomem_for_each_line() will never be used. -* sh, x86 - The callback function may return (-1 for sh,) 0 or 1, but always returns - 1 once we have reached the maximum number of entries allowed. - Even so the current kexec_iomem_for_each_line() counts them up. - This change actually fixes this bug. - -Signed-off-by: AKASHI Takahiro ---- - kexec/kexec-iomem.c | 15 ++++++++++----- - 1 file changed, 10 insertions(+), 5 deletions(-) - -diff --git a/kexec/kexec-iomem.c b/kexec/kexec-iomem.c -index 485a2e810080..0a0277a422d8 100644 ---- a/kexec/kexec-iomem.c -+++ b/kexec/kexec-iomem.c -@@ -18,6 +18,9 @@ - * Iterate over each line in the file returned by proc_iomem(). If match is - * NULL or if the line matches with our match-pattern then call the - * callback if non-NULL. -+ * If match is NULL, callback should return a negative if error. -+ * Otherwise the interation goes on, incrementing nr but only if callback -+ * returns 0 (matched). - * - * Return the number of lines matched. - */ -@@ -37,7 +40,7 @@ int kexec_iomem_for_each_line(char *match, - char *str; - int consumed; - int count; -- int nr = 0; -+ int nr = 0, ret; - - fp = fopen(iomem, "r"); - if (!fp) -@@ -50,11 +53,13 @@ int kexec_iomem_for_each_line(char *match, - str = line + consumed; - size = end - start + 1; - if (!match || memcmp(str, match, strlen(match)) == 0) { -- if (callback -- && callback(data, nr, str, start, size) < 0) { -- break; -+ if (callback) { -+ ret = callback(data, nr, str, start, size); -+ if (ret < 0) -+ break; -+ else if (ret == 0) -+ nr++; - } -- nr++; - } - } - --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-kexec-generalize-and-rename-get_kernel_stext_sym.patch b/SOURCES/kexec-tools-2.0.14-kexec-generalize-and-rename-get_kernel_stext_sym.patch deleted file mode 100644 index 070ed5d..0000000 --- a/SOURCES/kexec-tools-2.0.14-kexec-generalize-and-rename-get_kernel_stext_sym.patch +++ /dev/null @@ -1,187 +0,0 @@ -From d8e8090a66891eb114f31ed0d4c006a161efc109 Mon Sep 17 00:00:00 2001 -Message-Id: -In-Reply-To: -References: -From: Pratyush Anand -Date: Wed, 15 Mar 2017 18:38:17 +0900 -Subject: [PATCH 03/10] kexec: generalize and rename get_kernel_stext_sym() - -get_kernel_stext_sym() has been defined for both arm and i386. Other -architecture might need some other kernel symbol address. Therefore rewrite -this function as generic function to get any kernel symbol address. - -More over, kallsyms is not arch specific representation, therefore have -common function for all arches. - -Signed-off-by: Pratyush Anand -[created symbols.c] -Signed-off-by: AKASHI Takahiro ---- - kexec/Makefile | 1 + - kexec/arch/arm/crashdump-arm.c | 40 +--------------------------------------- - kexec/arch/i386/crashdump-x86.c | 29 ----------------------------- - kexec/kexec.h | 2 ++ - kexec/symbols.c | 34 ++++++++++++++++++++++++++++++++++ - 5 files changed, 38 insertions(+), 68 deletions(-) - create mode 100644 kexec/symbols.c - -diff --git a/kexec/Makefile b/kexec/Makefile -index 39f365f543d7..2b4fb3d162ec 100644 ---- a/kexec/Makefile -+++ b/kexec/Makefile -@@ -26,6 +26,7 @@ KEXEC_SRCS_base += kexec/kernel_version.c - KEXEC_SRCS_base += kexec/lzma.c - KEXEC_SRCS_base += kexec/zlib.c - KEXEC_SRCS_base += kexec/kexec-xen.c -+KEXEC_SRCS_base += kexec/symbols.c - - KEXEC_GENERATED_SRCS += $(PURGATORY_HEX_C) - -diff --git a/kexec/arch/arm/crashdump-arm.c b/kexec/arch/arm/crashdump-arm.c -index 4a89b5ea9645..245c21af5e32 100644 ---- a/kexec/arch/arm/crashdump-arm.c -+++ b/kexec/arch/arm/crashdump-arm.c -@@ -73,48 +73,10 @@ static struct crash_elf_info elf_info = { - - extern unsigned long long user_page_offset; - --/* Retrieve kernel _stext symbol virtual address from /proc/kallsyms */ --static unsigned long long get_kernel_stext_sym(void) --{ -- const char *kallsyms = "/proc/kallsyms"; -- const char *stext = "_stext"; -- char sym[128]; -- char line[128]; -- FILE *fp; -- unsigned long long vaddr = 0; -- char type; -- -- fp = fopen(kallsyms, "r"); -- if (!fp) { -- fprintf(stderr, "Cannot open %s\n", kallsyms); -- return 0; -- } -- -- while(fgets(line, sizeof(line), fp) != NULL) { -- unsigned long long addr; -- -- if (sscanf(line, "%Lx %c %s", &addr, &type, sym) != 3) -- continue; -- -- if (strcmp(sym, stext) == 0) { -- dbgprintf("kernel symbol %s vaddr = %#llx\n", stext, addr); -- vaddr = addr; -- break; -- } -- } -- -- fclose(fp); -- -- if (vaddr == 0) -- fprintf(stderr, "Cannot get kernel %s symbol address\n", stext); -- -- return vaddr; --} -- - static int get_kernel_page_offset(struct kexec_info *info, - struct crash_elf_info *elf_info) - { -- unsigned long long stext_sym_addr = get_kernel_stext_sym(); -+ unsigned long long stext_sym_addr = get_kernel_sym("_stext"); - if (stext_sym_addr == 0) { - if (user_page_offset != (-1ULL)) { - elf_info->page_offset = user_page_offset; -diff --git a/kexec/arch/i386/crashdump-x86.c b/kexec/arch/i386/crashdump-x86.c -index c4cf2013a001..a324c6c9074f 100644 ---- a/kexec/arch/i386/crashdump-x86.c -+++ b/kexec/arch/i386/crashdump-x86.c -@@ -102,35 +102,6 @@ static int get_kernel_paddr(struct kexec_info *UNUSED(info), - return -1; - } - --/* Retrieve kernel symbol virtual address from /proc/kallsyms */ --static unsigned long long get_kernel_sym(const char *symbol) --{ -- const char *kallsyms = "/proc/kallsyms"; -- char sym[128]; -- char line[128]; -- FILE *fp; -- unsigned long long vaddr; -- char type; -- -- fp = fopen(kallsyms, "r"); -- if (!fp) { -- fprintf(stderr, "Cannot open %s\n", kallsyms); -- return 0; -- } -- -- while(fgets(line, sizeof(line), fp) != NULL) { -- if (sscanf(line, "%Lx %c %s", &vaddr, &type, sym) != 3) -- continue; -- if (strcmp(sym, symbol) == 0) { -- dbgprintf("kernel symbol %s vaddr = %16llx\n", symbol, vaddr); -- return vaddr; -- } -- } -- -- dbgprintf("Cannot get kernel %s symbol address\n", symbol); -- return 0; --} -- - /* Retrieve info regarding virtual address kernel has been compiled for and - * size of the kernel from /proc/kcore. Current /proc/kcore parsing from - * from kexec-tools fails because of malformed elf notes. A kernel patch has -diff --git a/kexec/kexec.h b/kexec/kexec.h -index 9194f1c87c91..b4fafad9487b 100644 ---- a/kexec/kexec.h -+++ b/kexec/kexec.h -@@ -312,4 +312,6 @@ int xen_kexec_load(struct kexec_info *info); - int xen_kexec_unload(uint64_t kexec_flags); - void xen_kexec_exec(void); - -+extern unsigned long long get_kernel_sym(const char *text); -+ - #endif /* KEXEC_H */ -diff --git a/kexec/symbols.c b/kexec/symbols.c -new file mode 100644 -index 000000000000..5e42de98de32 ---- /dev/null -+++ b/kexec/symbols.c -@@ -0,0 +1,34 @@ -+#include -+#include -+#include "kexec.h" -+ -+/* Retrieve kernel symbol virtual address from /proc/kallsyms */ -+unsigned long long get_kernel_sym(const char *symbol) -+{ -+ const char *kallsyms = "/proc/kallsyms"; -+ char sym[128]; -+ char line[128]; -+ FILE *fp; -+ unsigned long long vaddr; -+ char type; -+ -+ fp = fopen(kallsyms, "r"); -+ if (!fp) { -+ fprintf(stderr, "Cannot open %s\n", kallsyms); -+ return 0; -+ } -+ -+ while (fgets(line, sizeof(line), fp) != NULL) { -+ if (sscanf(line, "%Lx %c %s", &vaddr, &type, sym) != 3) -+ continue; -+ if (strcmp(sym, symbol) == 0) { -+ dbgprintf("kernel symbol %s vaddr = %16llx\n", -+ symbol, vaddr); -+ return vaddr; -+ } -+ } -+ -+ dbgprintf("Cannot get kernel %s symbol address\n", symbol); -+ -+ return 0; -+} --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-kexec-powerpc-fix-command-line-overflow-error.patch b/SOURCES/kexec-tools-2.0.14-kexec-powerpc-fix-command-line-overflow-error.patch deleted file mode 100644 index 2831148..0000000 --- a/SOURCES/kexec-tools-2.0.14-kexec-powerpc-fix-command-line-overflow-error.patch +++ /dev/null @@ -1,94 +0,0 @@ -From 21eb397a5fc9227cd95d23e8c74a49cf6a293e57 Mon Sep 17 00:00:00 2001 - -From: Hari Bathini - -Subject: [PATCH] kexec-tools: powerpc: fix command line overflow error - -Since kernel commit a5980d064fe2 ("powerpc: Bump COMMAND_LINE_SIZE -to 2048"), powerpc bumped command line size to 2048 but the size -used here is still the default value of 512. Bump it to 2048 to -fix command line overflow errors observed when command line length -is above 512 bytes. Also, get rid of the multiple definitions of -COMMAND_LINE_SIZE macro in ppc architecture. - -Signed-off-by: Hari Bathini -Signed-off-by: Simon Horman ---- - kexec/arch/ppc/crashdump-powerpc.h | 2 -- - kexec/arch/ppc/fs2dt.c | 1 - - kexec/arch/ppc/kexec-ppc.h | 3 ++- - kexec/arch/ppc/ops.h | 1 - - kexec/arch/ppc64/crashdump-ppc64.h | 2 +- - 5 files changed, 3 insertions(+), 6 deletions(-) - -diff --git a/kexec/arch/ppc/crashdump-powerpc.h b/kexec/arch/ppc/crashdump-powerpc.h -index 9b9b01e..97b5095 100644 ---- a/kexec/arch/ppc/crashdump-powerpc.h -+++ b/kexec/arch/ppc/crashdump-powerpc.h -@@ -20,8 +20,6 @@ extern struct arch_options_t arch_options; - #define KERNELBASE PAGE_OFFSET - #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) - --#define COMMAND_LINE_SIZE 512 /* from kernel */ -- - #ifdef CONFIG_BOOKE - /* We don't need backup region in Book E */ - #define BACKUP_SRC_START 0x0000 -diff --git a/kexec/arch/ppc/fs2dt.c b/kexec/arch/ppc/fs2dt.c -index 6e77379..fed499b 100644 ---- a/kexec/arch/ppc/fs2dt.c -+++ b/kexec/arch/ppc/fs2dt.c -@@ -37,7 +37,6 @@ - #define TREEWORDS 65536 /* max 32 bit words for properties */ - #define MEMRESERVE 256 /* max number of reserved memory blks */ - #define MAX_MEMORY_RANGES 1024 --#define COMMAND_LINE_SIZE 512 /* from kernel */ - - static char pathname[MAXPATH]; - static char propnames[NAMESPACE] = { 0 }; -diff --git a/kexec/arch/ppc/kexec-ppc.h b/kexec/arch/ppc/kexec-ppc.h -index 904cf48..6dc36c6 100644 ---- a/kexec/arch/ppc/kexec-ppc.h -+++ b/kexec/arch/ppc/kexec-ppc.h -@@ -6,6 +6,8 @@ - #define CORE_TYPE_ELF32 1 - #define CORE_TYPE_ELF64 2 - -+#define COMMAND_LINE_SIZE 2048 /* from kernel */ -+ - extern unsigned char setup_simple_start[]; - extern uint32_t setup_simple_size; - -@@ -75,7 +77,6 @@ extern unsigned long dt_address_cells, dt_size_cells; - extern int init_memory_region_info(void); - extern int read_memory_region_limits(int fd, unsigned long long *start, - unsigned long long *end); --#define COMMAND_LINE_SIZE 512 /* from kernel */ - /*fs2dt*/ - void reserve(unsigned long long where, unsigned long long length); - -diff --git a/kexec/arch/ppc/ops.h b/kexec/arch/ppc/ops.h -index 7334a05..5e7a070 100644 ---- a/kexec/arch/ppc/ops.h -+++ b/kexec/arch/ppc/ops.h -@@ -12,7 +12,6 @@ - #define _PPC_BOOT_OPS_H_ - #include "types.h" - --#define COMMAND_LINE_SIZE 512 - #define MAX_PATH_LEN 256 - #define MAX_PROP_LEN 256 /* What should this be? */ - -diff --git a/kexec/arch/ppc64/crashdump-ppc64.h b/kexec/arch/ppc64/crashdump-ppc64.h -index d654c6b..42ccc31 100644 ---- a/kexec/arch/ppc64/crashdump-ppc64.h -+++ b/kexec/arch/ppc64/crashdump-ppc64.h -@@ -16,7 +16,7 @@ void add_usable_mem_rgns(unsigned long long base, unsigned long long size); - #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) - #define MAXMEM (-KERNELBASE-VMALLOCBASE) - --#define COMMAND_LINE_SIZE 512 /* from kernel */ -+#define COMMAND_LINE_SIZE 2048 /* from kernel */ - /* Backup Region, First 64K of System RAM. */ - #define BACKUP_SRC_START 0x0000 - #define BACKUP_SRC_END 0xffff diff --git a/SOURCES/kexec-tools-2.0.14-makedumpfile-elf_info-kcore-check-for-invalid-physic.patch b/SOURCES/kexec-tools-2.0.14-makedumpfile-elf_info-kcore-check-for-invalid-physic.patch deleted file mode 100644 index 1edff59..0000000 --- a/SOURCES/kexec-tools-2.0.14-makedumpfile-elf_info-kcore-check-for-invalid-physic.patch +++ /dev/null @@ -1,47 +0,0 @@ -From f4ab6897a716d3f3959f6cb8cab27744eaecb5a6 Mon Sep 17 00:00:00 2001 -Message-Id: -In-Reply-To: <4b0bed3523a5f6c2c428d9dab3d27d4572207d52.1489471500.git.panand@redhat.com> -References: <4b0bed3523a5f6c2c428d9dab3d27d4572207d52.1489471500.git.panand@redhat.com> -From: Pratyush Anand -Date: Thu, 2 Mar 2017 17:37:16 +0900 -Subject: [PATCH 4/7] [PATCH v3 4/7] elf_info: kcore: check for invalid - physical address - -kcore passes correct phys_start for direct mapped region and an invalid -value (-1) for all other regions after the kernel commit -464920104bf7(/proc/kcore: update physical address for kcore ram and -text). arch specific function is_phys_addr() accepts only virt_start. -Therefore, check for valid phys_start in get_kcore_dump_loads(). - -Signed-off-by: Pratyush Anand ---- - elf_info.c | 6 ++++-- - 1 file changed, 4 insertions(+), 2 deletions(-) - -diff --git a/makedumpfile-1.6.1/elf_info.c b/makedumpfile-1.6.1/elf_info.c -index 65ff333cf33a..c5743b3cab28 100644 ---- a/makedumpfile-1.6.1/elf_info.c -+++ b/makedumpfile-1.6.1/elf_info.c -@@ -881,7 +881,8 @@ int get_kcore_dump_loads(void) - - for (i = 0; i < num_pt_loads; ++i) { - struct pt_load_segment *p = &pt_loads[i]; -- if (!is_phys_addr(p->virt_start)) -+ if (p->phys_start == NOT_PADDR -+ || !is_phys_addr(p->virt_start)) - continue; - loads++; - } -@@ -901,7 +902,8 @@ int get_kcore_dump_loads(void) - - for (i = 0, j = 0; i < num_pt_loads; ++i) { - struct pt_load_segment *p = &pt_loads[i]; -- if (!is_phys_addr(p->virt_start)) -+ if (p->phys_start == NOT_PADDR -+ || !is_phys_addr(p->virt_start)) - continue; - if (j >= loads) - return FALSE; --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-makedumpfile-initial-call-cache_init-a-bit-early.patch b/SOURCES/kexec-tools-2.0.14-makedumpfile-initial-call-cache_init-a-bit-early.patch deleted file mode 100644 index 8523767..0000000 --- a/SOURCES/kexec-tools-2.0.14-makedumpfile-initial-call-cache_init-a-bit-early.patch +++ /dev/null @@ -1,47 +0,0 @@ -From 8e2834bac4f62da3894da297f083068431be6d80 Mon Sep 17 00:00:00 2001 -Message-Id: <8e2834bac4f62da3894da297f083068431be6d80.1489471500.git.panand@redhat.com> -In-Reply-To: <4b0bed3523a5f6c2c428d9dab3d27d4572207d52.1489471500.git.panand@redhat.com> -References: <4b0bed3523a5f6c2c428d9dab3d27d4572207d52.1489471500.git.panand@redhat.com> -From: Pratyush Anand -Date: Thu, 2 Mar 2017 17:37:11 +0900 -Subject: [PATCH 2/7] [PATCH v3 2/7] initial(): call cache_init() a bit early - -Call cache_init() before get_kcore_dump_loads(), because latter uses -cache_search(). - -Call path is like this : -get_kcore_dump_loads() -> process_dump_load() -> vaddr_to_paddr() -> -vtop4_x86_64() -> readmem() -> cache_search() - -Signed-off-by: Pratyush Anand ---- - makedumpfile.c | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/makedumpfile-1.6.1/makedumpfile.c b/makedumpfile-1.6.1/makedumpfile.c -index 6942047199de..3b8e9810468d 100644 ---- a/makedumpfile-1.6.1/makedumpfile.c -+++ b/makedumpfile-1.6.1/makedumpfile.c -@@ -3878,6 +3878,9 @@ initial(void) - if (!get_value_for_old_linux()) - return FALSE; - -+ if (!is_xen_memory() && !cache_init()) -+ return FALSE; -+ - if (info->flag_mem_usage && !get_kcore_dump_loads()) - return FALSE; - -@@ -4000,9 +4003,6 @@ out: - } - } - -- if (!is_xen_memory() && !cache_init()) -- return FALSE; -- - if (debug_info && !get_machdep_info()) - return FALSE; - --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-makedumpfile-makedumpfile-Correct-the-calculation-of.patch b/SOURCES/kexec-tools-2.0.14-makedumpfile-makedumpfile-Correct-the-calculation-of.patch deleted file mode 100644 index 16388c8..0000000 --- a/SOURCES/kexec-tools-2.0.14-makedumpfile-makedumpfile-Correct-the-calculation-of.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 4c53423b995463067fbbd394e724b4d1d6ea3d62 Mon Sep 17 00:00:00 2001 -Message-Id: <4c53423b995463067fbbd394e724b4d1d6ea3d62.1489471500.git.panand@redhat.com> -In-Reply-To: <4b0bed3523a5f6c2c428d9dab3d27d4572207d52.1489471500.git.panand@redhat.com> -References: <4b0bed3523a5f6c2c428d9dab3d27d4572207d52.1489471500.git.panand@redhat.com> -From: Baoquan He -Date: Thu, 2 Mar 2017 17:37:19 +0900 -Subject: [PATCH 5/7] [PATCH v3 5/7] makedumpfile: Correct the calculation of - kvaddr in set_kcore_vmcoreinfo - -In set_kcore_vmcoreinfo, we calculate the virtual address of vmcoreinfo -by OR operation as below: - - kvaddr = (ulong)vmcoreinfo_addr | PAGE_OFFSET; - -When mm sections kaslr is not enabled, this is correct since the -starting address of direct mapping section is 0xffff880000000000 which -is 1T aligned. Usually system with memory below 1T won't cause problem. - -However with mm section kaslr enabled, the starting address of direct -mapping is 1G aligned. The above code makes kvaddr unsure. - -So change it to adding operation: - kvaddr = (ulong)vmcoreinfo_addr + PAGE_OFFSET; - -Signed-off-by: Baoquan He ---- - elf_info.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/makedumpfile-1.6.1/elf_info.c b/makedumpfile-1.6.1/elf_info.c -index c5743b3cab28..100272f83c48 100644 ---- a/makedumpfile-1.6.1/elf_info.c -+++ b/makedumpfile-1.6.1/elf_info.c -@@ -372,7 +372,7 @@ int set_kcore_vmcoreinfo(uint64_t vmcoreinfo_addr, uint64_t vmcoreinfo_len) - off_t offset_desc; - - offset = UNINITIALIZED; -- kvaddr = (ulong)vmcoreinfo_addr | PAGE_OFFSET; -+ kvaddr = (ulong)vmcoreinfo_addr + PAGE_OFFSET; - - for (i = 0; i < num_pt_loads; ++i) { - struct pt_load_segment *p = &pt_loads[i]; --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-makedumpfile-makedumpfile-Discard-process_dump_load.patch b/SOURCES/kexec-tools-2.0.14-makedumpfile-makedumpfile-Discard-process_dump_load.patch deleted file mode 100644 index 30b0e0e..0000000 --- a/SOURCES/kexec-tools-2.0.14-makedumpfile-makedumpfile-Discard-process_dump_load.patch +++ /dev/null @@ -1,57 +0,0 @@ -From f3ff8c6232de43fa2cc60f5ca0f233cf8eb8d2ad Mon Sep 17 00:00:00 2001 -Message-Id: -In-Reply-To: <4b0bed3523a5f6c2c428d9dab3d27d4572207d52.1489471500.git.panand@redhat.com> -References: <4b0bed3523a5f6c2c428d9dab3d27d4572207d52.1489471500.git.panand@redhat.com> -From: Baoquan He -Date: Thu, 2 Mar 2017 17:37:23 +0900 -Subject: [PATCH 6/7] [PATCH v3 6/7] makedumpfile: Discard process_dump_load - -Kernel commit 464920104bf7 (/proc/kcore: update physical address for -kcore ram and text) provides physical address of direct mapping kcore -program segments. So no need to calculate it specifically now. And the -old code is not correct since it calls vaddr_to_paddr() which has not -been ready at that time. - -Signed-off-by: Baoquan He ---- - elf_info.c | 17 ----------------- - 1 file changed, 17 deletions(-) - -diff --git a/makedumpfile-1.6.1/elf_info.c b/makedumpfile-1.6.1/elf_info.c -index 100272f83c48..8e2437622141 100644 ---- a/makedumpfile-1.6.1/elf_info.c -+++ b/makedumpfile-1.6.1/elf_info.c -@@ -857,22 +857,6 @@ static int exclude_segment(struct pt_load_segment **pt_loads, - return 0; - } - --static int --process_dump_load(struct pt_load_segment *pls) --{ -- unsigned long long paddr; -- -- paddr = vaddr_to_paddr(pls->virt_start); -- pls->phys_start = paddr; -- pls->phys_end = paddr + (pls->virt_end - pls->virt_start); -- DEBUG_MSG("process_dump_load\n"); -- DEBUG_MSG(" phys_start : %llx\n", pls->phys_start); -- DEBUG_MSG(" phys_end : %llx\n", pls->phys_end); -- DEBUG_MSG(" virt_start : %llx\n", pls->virt_start); -- DEBUG_MSG(" virt_end : %llx\n", pls->virt_end); -- -- return TRUE; --} - - int get_kcore_dump_loads(void) - { -@@ -917,7 +901,6 @@ int get_kcore_dump_loads(void) - } - - pls[j] = *p; -- process_dump_load(&pls[j]); - j++; - } - --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-makedumpfile-makedumpfile-add-runtime-kaslr-offset-if-it-exists.patch b/SOURCES/kexec-tools-2.0.14-makedumpfile-makedumpfile-add-runtime-kaslr-offset-if-it-exists.patch deleted file mode 100644 index 2d90a65..0000000 --- a/SOURCES/kexec-tools-2.0.14-makedumpfile-makedumpfile-add-runtime-kaslr-offset-if-it-exists.patch +++ /dev/null @@ -1,303 +0,0 @@ -From 302c16ede3723264ca0abb5eef9c9f553ffcfbd7 Mon Sep 17 00:00:00 2001 -Message-Id: <302c16ede3723264ca0abb5eef9c9f553ffcfbd7.1496033260.git.panand@redhat.com> -From: Pratyush Anand -Date: Wed, 26 Apr 2017 14:36:29 +0530 -Subject: [PATCH 1/3] makedumpfile: add runtime kaslr offset if it exists - -If we have to erase a symbol from vmcore whose address is not present in -vmcoreinfo, then we need to pass vmlinux as well to get the symbol -address. -When kaslr is enabled, virtual address of all the kernel symbols are -randomized with an offset. vmlinux always has a static address, but all -the arch specific calculation are based on run time kernel address. So -we need to find a way to translate symbol address from vmlinux to kernel -run time address. - -without this patch: - # cat > scrub.conf << EOF - [vmlinux] - erase jiffies - erase init_task.utime - for tsk in init_task.tasks.next within task_struct:tasks - erase tsk.utime - endfor - EOF - - # makedumpfile --split -d 5 -x vmlinux --config scrub.conf vmcore dumpfile_{1,2,3} - - readpage_kdump_compressed: pfn(f97ea) is excluded from vmcore. - readmem: type_addr: 1, addr:f97eaff8, size:8 - vtop4_x86_64: Can't get pml4 (page_dir:f97eaff8). - readmem: Can't convert a virtual address(ffffffff819f1284) to physical address. - readmem: type_addr: 0, addr:ffffffff819f1284, size:390 - check_release: Can't get the address of system_utsname. - -After this patch check_release() is ok, and also we are able to erase -symbol from vmcore. - -Signed-off-by: Pratyush Anand ---- - arch/x86_64.c | 36 ++++++++++++++++++++++++++++++++++++ - erase_info.c | 1 + - makedumpfile.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ - makedumpfile.h | 16 ++++++++++++++++ - 4 files changed, 99 insertions(+) - -diff --git a/makedumpfile-1.6.1/arch/x86_64.c b/makedumpfile-1.6.1/arch/x86_64.c -index e978a36f8878..fd2e8ac154d6 100644 ---- a/makedumpfile-1.6.1/arch/x86_64.c -+++ b/makedumpfile-1.6.1/arch/x86_64.c -@@ -33,6 +33,42 @@ get_xen_p2m_mfn(void) - return NOT_FOUND_LONG_VALUE; - } - -+unsigned long -+get_kaslr_offset_x86_64(unsigned long vaddr) -+{ -+ unsigned int i; -+ char buf[BUFSIZE_FGETS], *endp; -+ -+ if (!info->kaslr_offset && info->file_vmcoreinfo) { -+ if (fseek(info->file_vmcoreinfo, 0, SEEK_SET) < 0) { -+ ERRMSG("Can't seek the vmcoreinfo file(%s). %s\n", -+ info->name_vmcoreinfo, strerror(errno)); -+ return FALSE; -+ } -+ -+ while (fgets(buf, BUFSIZE_FGETS, info->file_vmcoreinfo)) { -+ i = strlen(buf); -+ if (!i) -+ break; -+ if (buf[i - 1] == '\n') -+ buf[i - 1] = '\0'; -+ if (strncmp(buf, STR_KERNELOFFSET, -+ strlen(STR_KERNELOFFSET)) == 0) -+ info->kaslr_offset = -+ strtoul(buf+strlen(STR_KERNELOFFSET),&endp,16); -+ } -+ } -+ if (vaddr >= __START_KERNEL_map && -+ vaddr < __START_KERNEL_map + info->kaslr_offset) -+ return info->kaslr_offset; -+ else -+ /* -+ * TODO: we need to check if it is vmalloc/vmmemmap/module -+ * address, we will have different offset -+ */ -+ return 0; -+} -+ - static int - get_page_offset_x86_64(void) - { -diff --git a/makedumpfile-1.6.1/erase_info.c b/makedumpfile-1.6.1/erase_info.c -index f2ba9149e93e..60abfa1a1adf 100644 ---- a/makedumpfile-1.6.1/erase_info.c -+++ b/makedumpfile-1.6.1/erase_info.c -@@ -1088,6 +1088,7 @@ resolve_config_entry(struct config_entry *ce, unsigned long long base_vaddr, - ce->line, ce->name); - return FALSE; - } -+ ce->sym_addr += get_kaslr_offset(ce->sym_addr); - ce->type_name = get_symbol_type_name(ce->name, - DWARF_INFO_GET_SYMBOL_TYPE, - &ce->size, &ce->type_flag); -diff --git a/makedumpfile-1.6.1/makedumpfile.c b/makedumpfile-1.6.1/makedumpfile.c -index 301772a8820c..9babf1a07154 100644 ---- a/makedumpfile-1.6.1/makedumpfile.c -+++ b/makedumpfile-1.6.1/makedumpfile.c -@@ -3782,6 +3782,46 @@ free_for_parallel() - } - - int -+find_kaslr_offsets() -+{ -+ off_t offset; -+ unsigned long size; -+ int ret = FALSE; -+ -+ get_vmcoreinfo(&offset, &size); -+ -+ if (!(info->name_vmcoreinfo = strdup(FILENAME_VMCOREINFO))) { -+ MSG("Can't duplicate strings(%s).\n", FILENAME_VMCOREINFO); -+ return FALSE; -+ } -+ if (!copy_vmcoreinfo(offset, size)) -+ goto out; -+ -+ if (!open_vmcoreinfo("r")) -+ goto out; -+ -+ unlink(info->name_vmcoreinfo); -+ -+ /* -+ * This arch specific function should update info->kaslr_offset. If -+ * kaslr is not enabled then offset will be set to 0. arch specific -+ * function might need to read from vmcoreinfo, therefore we have -+ * called this function between open_vmcoreinfo() and -+ * close_vmcoreinfo() -+ */ -+ get_kaslr_offset(SYMBOL(_stext)); -+ -+ close_vmcoreinfo(); -+ -+ ret = TRUE; -+out: -+ free(info->name_vmcoreinfo); -+ info->name_vmcoreinfo = NULL; -+ -+ return ret; -+} -+ -+int - initial(void) - { - off_t offset; -@@ -3833,6 +3873,9 @@ initial(void) - set_dwarf_debuginfo("vmlinux", NULL, - info->name_vmlinux, info->fd_vmlinux); - -+ if (has_vmcoreinfo() && !find_kaslr_offsets()) -+ return FALSE; -+ - if (!get_symbol_info()) - return FALSE; - -@@ -8635,6 +8678,7 @@ close_vmcoreinfo(void) - if(fclose(info->file_vmcoreinfo) < 0) - ERRMSG("Can't close the vmcoreinfo file(%s). %s\n", - info->name_vmcoreinfo, strerror(errno)); -+ info->file_vmcoreinfo = NULL; - } - - void -@@ -11026,11 +11070,13 @@ main(int argc, char *argv[]) - strerror(errno)); - goto out; - } -+ info->file_vmcoreinfo = NULL; - info->fd_vmlinux = -1; - info->fd_xen_syms = -1; - info->fd_memory = -1; - info->fd_dumpfile = -1; - info->fd_bitmap = -1; -+ info->kaslr_offset = 0; - initialize_tables(); - - /* -diff --git a/makedumpfile-1.6.1/makedumpfile.h b/makedumpfile-1.6.1/makedumpfile.h -index e32e567018f6..9f16becadd55 100644 ---- a/makedumpfile-1.6.1/makedumpfile.h -+++ b/makedumpfile-1.6.1/makedumpfile.h -@@ -253,10 +253,14 @@ static inline int string_exists(char *s) { return (s ? TRUE : FALSE); } - #define SYMBOL_INIT(symbol, str_symbol) \ - do { \ - SYMBOL(symbol) = get_symbol_addr(str_symbol); \ -+ if (SYMBOL(symbol) != NOT_FOUND_SYMBOL) \ -+ SYMBOL(symbol) += info->kaslr_offset; \ - } while (0) - #define SYMBOL_INIT_NEXT(symbol, str_symbol) \ - do { \ - SYMBOL(symbol) = get_next_symbol_addr(str_symbol); \ -+ if (SYMBOL(symbol) != NOT_FOUND_SYMBOL) \ -+ SYMBOL(symbol) += info->kaslr_offset; \ - } while (0) - #define WRITE_SYMBOL(str_symbol, symbol) \ - do { \ -@@ -495,6 +499,7 @@ do { \ - #define STR_CONFIG_X86_PAE "CONFIG_X86_PAE=y" - #define STR_CONFIG_PGTABLE_4 "CONFIG_PGTABLE_4=y" - #define STR_CONFIG_PGTABLE_3 "CONFIG_PGTABLE_3=y" -+#define STR_KERNELOFFSET "KERNELOFFSET=" - - /* - * common value -@@ -838,6 +843,7 @@ int get_xen_info_arm64(void); - #define get_phys_base() get_phys_base_arm64() - #define get_machdep_info() get_machdep_info_arm64() - #define get_versiondep_info() get_versiondep_info_arm64() -+#define get_kaslr_offset(X) FALSE - #define get_xen_basic_info_arch(X) get_xen_basic_info_arm64(X) - #define get_xen_info_arch(X) get_xen_info_arm64(X) - #define is_phys_addr(X) stub_true_ul(X) -@@ -851,6 +857,7 @@ unsigned long long vaddr_to_paddr_arm(unsigned long vaddr); - #define get_phys_base() get_phys_base_arm() - #define get_machdep_info() get_machdep_info_arm() - #define get_versiondep_info() stub_true() -+#define get_kaslr_offset(X) FALSE - #define vaddr_to_paddr(X) vaddr_to_paddr_arm(X) - #define is_phys_addr(X) stub_true_ul(X) - #endif /* arm */ -@@ -863,11 +870,13 @@ unsigned long long vaddr_to_paddr_x86(unsigned long vaddr); - #define get_phys_base() stub_true() - #define get_machdep_info() get_machdep_info_x86() - #define get_versiondep_info() get_versiondep_info_x86() -+#define get_kaslr_offset(X) FALSE - #define vaddr_to_paddr(X) vaddr_to_paddr_x86(X) - #define is_phys_addr(X) stub_true_ul(X) - #endif /* x86 */ - - #ifdef __x86_64__ -+unsigned long get_kaslr_offset_x86_64(unsigned long vaddr); - int get_phys_base_x86_64(void); - int get_machdep_info_x86_64(void); - int get_versiondep_info_x86_64(void); -@@ -876,6 +885,7 @@ unsigned long long vtop4_x86_64(unsigned long vaddr); - #define get_phys_base() get_phys_base_x86_64() - #define get_machdep_info() get_machdep_info_x86_64() - #define get_versiondep_info() get_versiondep_info_x86_64() -+#define get_kaslr_offset(X) get_kaslr_offset_x86_64(X) - #define vaddr_to_paddr(X) vtop4_x86_64(X) - #define is_phys_addr(X) stub_true_ul(X) - #endif /* x86_64 */ -@@ -888,6 +898,7 @@ unsigned long long vaddr_to_paddr_ppc64(unsigned long vaddr); - #define get_phys_base() stub_true() - #define get_machdep_info() get_machdep_info_ppc64() - #define get_versiondep_info() get_versiondep_info_ppc64() -+#define get_kaslr_offset(X) FALSE - #define vaddr_to_paddr(X) vaddr_to_paddr_ppc64(X) - #define is_phys_addr(X) stub_true_ul(X) - #endif /* powerpc64 */ -@@ -899,6 +910,7 @@ unsigned long long vaddr_to_paddr_ppc(unsigned long vaddr); - #define get_phys_base() stub_true() - #define get_machdep_info() get_machdep_info_ppc() - #define get_versiondep_info() stub_true() -+#define get_kaslr_offset(X) FALSE - #define vaddr_to_paddr(X) vaddr_to_paddr_ppc(X) - #define is_phys_addr(X) stub_true_ul(X) - #endif /* powerpc32 */ -@@ -911,6 +923,7 @@ int is_iomem_phys_addr_s390x(unsigned long addr); - #define get_phys_base() stub_true() - #define get_machdep_info() get_machdep_info_s390x() - #define get_versiondep_info() stub_true() -+#define get_kaslr_offset(X) FALSE - #define vaddr_to_paddr(X) vaddr_to_paddr_s390x(X) - #define is_phys_addr(X) is_iomem_phys_addr_s390x(X) - #endif /* s390x */ -@@ -923,6 +936,7 @@ unsigned long long vaddr_to_paddr_ia64(unsigned long vaddr); - #define get_machdep_info() get_machdep_info_ia64() - #define get_phys_base() get_phys_base_ia64() - #define get_versiondep_info() stub_true() -+#define get_kaslr_offset(X) FALSE - #define vaddr_to_paddr(X) vaddr_to_paddr_ia64(X) - #define VADDR_REGION(X) (((unsigned long)(X)) >> REGION_SHIFT) - #define is_phys_addr(X) stub_true_ul(X) -@@ -1152,6 +1166,7 @@ struct DumpInfo { - int vmemmap_psize; - int vmemmap_cnt; - struct ppc64_vmemmap *vmemmap_list; -+ unsigned long kaslr_offset; - - /* - * page table info for ppc64 -@@ -1803,6 +1818,7 @@ struct memory_range { - struct memory_range crash_reserved_mem[CRASH_RESERVED_MEM_NR]; - int crash_reserved_mem_nr; - -+unsigned long read_vmcoreinfo_symbol(char *str_symbol); - int readmem(int type_addr, unsigned long long addr, void *bufptr, size_t size); - int get_str_osrelease_from_vmlinux(void); - int read_vmcoreinfo_xen(void); --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-makedumpfile-sadump-set-info-page_size-before-cache_init.patch b/SOURCES/kexec-tools-2.0.14-makedumpfile-sadump-set-info-page_size-before-cache_init.patch deleted file mode 100644 index 04d47fb..0000000 --- a/SOURCES/kexec-tools-2.0.14-makedumpfile-sadump-set-info-page_size-before-cache_init.patch +++ /dev/null @@ -1,83 +0,0 @@ -From 90cc28fc9ab0a0076bcd9120b4f791401655280d Mon Sep 17 00:00:00 2001 -Message-Id: <90cc28fc9ab0a0076bcd9120b4f791401655280d.1496033260.git.panand@redhat.com> -In-Reply-To: <302c16ede3723264ca0abb5eef9c9f553ffcfbd7.1496033260.git.panand@redhat.com> -References: <302c16ede3723264ca0abb5eef9c9f553ffcfbd7.1496033260.git.panand@redhat.com> -From: "Hatayama, Daisuke" -Date: Tue, 23 May 2017 02:52:51 +0000 -Subject: [PATCH 3/3] sadump: set info->page_size before cache_init() - -Currently, makedumpfile results in Segmentation fault on sadump dump -files as follows: - - # LANG=C makedumpfile -f --message-level=31 -ld31 -x vmlinux ./sadump_vmcore sadump_vmcore-ld31 - sadump: read dump device as single partition - sadump: single partition configuration - page_size : 4096 - sadump: timezone information is missing - Segmentation fault - -By bisect, I found that this issue is caused by the following commit -that moves invocation of cache_init() in initial() a bit early: - - # git bisect bad - 8e2834bac4f62da3894da297f083068431be6d80 is the first bad commit - commit 8e2834bac4f62da3894da297f083068431be6d80 - Author: Pratyush Anand - Date: Thu Mar 2 17:37:11 2017 +0900 - - [PATCH v3 2/7] initial(): call cache_init() a bit early - - Call cache_init() before get_kcore_dump_loads(), because latter uses - cache_search(). - - Call path is like this : - get_kcore_dump_loads() -> process_dump_load() -> vaddr_to_paddr() -> - vtop4_x86_64() -> readmem() -> cache_search() - - Signed-off-by: Pratyush Anand - - :100644 100644 6942047199deb09dd1fff2121e264584dbb05587 3b8e9810468de26b0d8b73d456f0bd4f3d3aa2fe M makedumpfile.c - -In this timing, on sadump vmcores, info->page_size has not been -initialized yet so has 0. So, malloc() in cache_init() returns a chunk -of 0 size. A bit later, info->page_size is initialized with 4096. -Later processing on cache.c behaves assuming the chunk size is 8 * -4096. This destroys objects allocated after the chunk, resulting in -the above Segmentation fault. - -To fix this issue, this commit moves setting info->page_size before -cache_init(). - -Signed-off-by: HATAYAMA Daisuke -Cc: Pratyush Anand ---- - makedumpfile.c | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/makedumpfile-1.6.1/makedumpfile.c b/makedumpfile-1.6.1/makedumpfile.c -index 9babf1a07154..2e4286c83b8f 100644 ---- a/makedumpfile-1.6.1/makedumpfile.c -+++ b/makedumpfile-1.6.1/makedumpfile.c -@@ -3921,6 +3921,9 @@ initial(void) - if (!get_value_for_old_linux()) - return FALSE; - -+ if (info->flag_sadump && !set_page_size(sadump_page_size())) -+ return FALSE; -+ - if (!is_xen_memory() && !cache_init()) - return FALSE; - -@@ -3949,9 +3952,6 @@ initial(void) - return FALSE; - } - -- if (!set_page_size(sadump_page_size())) -- return FALSE; -- - if (!sadump_initialize_bitmap_memory()) - return FALSE; - --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-makedumpfile-show_mem_usage-calculate-page-offset-af.patch b/SOURCES/kexec-tools-2.0.14-makedumpfile-show_mem_usage-calculate-page-offset-af.patch deleted file mode 100644 index 5f30a2a..0000000 --- a/SOURCES/kexec-tools-2.0.14-makedumpfile-show_mem_usage-calculate-page-offset-af.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 4b0bed3523a5f6c2c428d9dab3d27d4572207d52 Mon Sep 17 00:00:00 2001 -Message-Id: <4b0bed3523a5f6c2c428d9dab3d27d4572207d52.1489471500.git.panand@redhat.com> -From: Pratyush Anand -Date: Thu, 2 Mar 2017 17:37:08 +0900 -Subject: [PATCH 1/7] [PATCH v3 1/7] show_mem_usage(): calculate page offset - after elf load - -x86_64 calculated page offset from PT_LOAD headers. Therefore call -get_page_offset() after get_elf_loads() - -Signed-off-by: Pratyush Anand ---- - makedumpfile.c | 6 +++--- - 1 file changed, 3 insertions(+), 3 deletions(-) - -diff --git a/makedumpfile-1.6.1/makedumpfile.c b/makedumpfile-1.6.1/makedumpfile.c -index e69b6df9a9ee..6942047199de 100644 ---- a/makedumpfile-1.6.1/makedumpfile.c -+++ b/makedumpfile-1.6.1/makedumpfile.c -@@ -10944,15 +10944,15 @@ int show_mem_usage(void) - - info->dump_level = MAX_DUMP_LEVEL; - -- if (!get_page_offset()) -- return FALSE; -- - if (!open_files_for_creating_dumpfile()) - return FALSE; - - if (!get_elf_loads(info->fd_memory, info->name_memory)) - return FALSE; - -+ if (!get_page_offset()) -+ return FALSE; -+ - if (!get_sys_kernel_vmcoreinfo(&vmcoreinfo_addr, &vmcoreinfo_len)) - return FALSE; - --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-makedumpfile-x86_64-calculate-page_offset-in-case-of-re-filtering.patch b/SOURCES/kexec-tools-2.0.14-makedumpfile-x86_64-calculate-page_offset-in-case-of-re-filtering.patch deleted file mode 100644 index aaf1730..0000000 --- a/SOURCES/kexec-tools-2.0.14-makedumpfile-x86_64-calculate-page_offset-in-case-of-re-filtering.patch +++ /dev/null @@ -1,85 +0,0 @@ -From 586c58752e0e48e8ed48ba951e5b1448831bbf11 Mon Sep 17 00:00:00 2001 -Message-Id: <586c58752e0e48e8ed48ba951e5b1448831bbf11.1496033260.git.panand@redhat.com> -In-Reply-To: <302c16ede3723264ca0abb5eef9c9f553ffcfbd7.1496033260.git.panand@redhat.com> -References: <302c16ede3723264ca0abb5eef9c9f553ffcfbd7.1496033260.git.panand@redhat.com> -From: Pratyush Anand -Date: Wed, 26 Apr 2017 11:04:07 +0530 -Subject: [PATCH 2/3] x86_64: calculate page_offset in case of - re-filtering/sadump/virsh dump - -we do not call get_elf_info() in case of refiltering and sadump. -Therefore, we will not have any pt_load in that case, and so we get: - -get_page_offset_x86_64: Can't get any pt_load to calculate page offset. - -However, we will have vmcoreinfo and vmlinux information in case of -re-filtering. So, we are able to find kaslr offset and we can get -page_offset_base address. Thus we can read the page offset as well. - -If kaslr is not enabled and also we do not have valid PT_LOAD to -calculate page offset then use old method to find fixed page -offset. - -In case of virsh dump virtual addresses in PT_LOAD are 0. Ignore such -addresses for the page_offset calculation. - -Suggested-by: HATAYAMA Daisuke -Signed-off-by: Pratyush Anand ---- - arch/x86_64.c | 36 +++++++++++++++++++++++++++++------- - 1 file changed, 29 insertions(+), 7 deletions(-) - -diff --git a/makedumpfile-1.6.1/arch/x86_64.c b/makedumpfile-1.6.1/arch/x86_64.c -index fd2e8ac154d6..18384a8dd684 100644 ---- a/makedumpfile-1.6.1/arch/x86_64.c -+++ b/makedumpfile-1.6.1/arch/x86_64.c -@@ -75,17 +75,39 @@ get_page_offset_x86_64(void) - int i; - unsigned long long phys_start; - unsigned long long virt_start; -+ unsigned long page_offset_base; -+ -+ if (info->kaslr_offset) { -+ page_offset_base = get_symbol_addr("page_offset_base"); -+ page_offset_base += info->kaslr_offset; -+ if (!readmem(VADDR, page_offset_base, &info->page_offset, -+ sizeof(info->page_offset))) { -+ ERRMSG("Can't read page_offset_base.\n"); -+ return FALSE; -+ } -+ return TRUE; -+ } - -- for (i = 0; get_pt_load(i, &phys_start, NULL, &virt_start, NULL); i++) { -- if (virt_start < __START_KERNEL_map -- && phys_start != NOT_PADDR) { -- info->page_offset = virt_start - phys_start; -- return TRUE; -+ if (get_num_pt_loads()) { -+ for (i = 0; -+ get_pt_load(i, &phys_start, NULL, &virt_start, NULL); -+ i++) { -+ if (virt_start != NOT_KV_ADDR -+ && virt_start < __START_KERNEL_map -+ && phys_start != NOT_PADDR) { -+ info->page_offset = virt_start - phys_start; -+ return TRUE; -+ } - } - } - -- ERRMSG("Can't get any pt_load to calculate page offset.\n"); -- return FALSE; -+ if (info->kernel_version < KERNEL_VERSION(2, 6, 27)) { -+ info->page_offset = __PAGE_OFFSET_ORIG; -+ } else { -+ info->page_offset = __PAGE_OFFSET_2_6_27; -+ } -+ -+ return TRUE; - } - - int --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-makedumpfile-x86_64-check-physical-address-in-PT_LOA.patch b/SOURCES/kexec-tools-2.0.14-makedumpfile-x86_64-check-physical-address-in-PT_LOA.patch deleted file mode 100644 index 02deed8..0000000 --- a/SOURCES/kexec-tools-2.0.14-makedumpfile-x86_64-check-physical-address-in-PT_LOA.patch +++ /dev/null @@ -1,47 +0,0 @@ -From f1363023b909df886eca5efcb64b78be9b8e6086 Mon Sep 17 00:00:00 2001 -Message-Id: -In-Reply-To: <4b0bed3523a5f6c2c428d9dab3d27d4572207d52.1489471500.git.panand@redhat.com> -References: <4b0bed3523a5f6c2c428d9dab3d27d4572207d52.1489471500.git.panand@redhat.com> -From: Pratyush Anand -Date: Thu, 2 Mar 2017 17:37:13 +0900 -Subject: [PATCH 3/7] [PATCH v3 3/7] x86_64: check physical address in PT_LOAD - for none direct mapped regions - -A kcore PT_LOAD can have a section from vmalloc region. However, -physical address in that header would be invalid (-1) after kernel -commit 464920104bf7 (/proc/kcore: update physical address for kcore ram -and text). Therefore, check for valid physical address while calculating -page_offset or phys_offset. - -Signed-off-by: Pratyush Anand ---- - arch/x86_64.c | 6 ++++-- - 1 file changed, 4 insertions(+), 2 deletions(-) - -diff --git a/makedumpfile-1.6.1/arch/x86_64.c b/makedumpfile-1.6.1/arch/x86_64.c -index 893cd516fc8b..e978a36f8878 100644 ---- a/makedumpfile-1.6.1/arch/x86_64.c -+++ b/makedumpfile-1.6.1/arch/x86_64.c -@@ -41,7 +41,8 @@ get_page_offset_x86_64(void) - unsigned long long virt_start; - - for (i = 0; get_pt_load(i, &phys_start, NULL, &virt_start, NULL); i++) { -- if (virt_start < __START_KERNEL_map) { -+ if (virt_start < __START_KERNEL_map -+ && phys_start != NOT_PADDR) { - info->page_offset = virt_start - phys_start; - return TRUE; - } -@@ -76,7 +77,8 @@ get_phys_base_x86_64(void) - } - - for (i = 0; get_pt_load(i, &phys_start, NULL, &virt_start, NULL); i++) { -- if (virt_start >= __START_KERNEL_map) { -+ if (virt_start >= __START_KERNEL_map -+ && phys_start != NOT_PADDR) { - - info->phys_base = phys_start - - (virt_start & ~(__START_KERNEL_map)); --- -2.9.3 - diff --git a/SOURCES/kexec-tools-2.0.14-ppc64-Reduce-number-of-ELF-LOAD-segments.patch b/SOURCES/kexec-tools-2.0.14-ppc64-Reduce-number-of-ELF-LOAD-segments.patch deleted file mode 100644 index c0ee06a..0000000 --- a/SOURCES/kexec-tools-2.0.14-ppc64-Reduce-number-of-ELF-LOAD-segments.patch +++ /dev/null @@ -1,67 +0,0 @@ -From f63d8530b9b6a2d7e79b946e326e5a2197eb8f87 Mon Sep 17 00:00:00 2001 -From: Petr Tesarik -Date: Thu, 19 Jan 2017 18:37:09 +0100 -Subject: [PATCH] ppc64: Reduce number of ELF LOAD segments - -The number of program header table entries (e_phnum) is an Elf64_Half, -which is a 16-bit entity, i.e. the limit is 65534 entries (one entry is -reserved for NOTE). This is a hard limit, defined by the ELF standard. -It is possible that more LMBs (Logical Memory Blocks) are needed to -represent all RAM on some machines, and this field overflows, causing -an incomplete /proc/vmcore file. - -This has actually happened on a machine with 31TB of RAM and an LMB size -of 256MB. - -However, since there is usually no memory hole between adjacent LMBs, the -map can be "compressed", combining multiple adjacent into a single LOAD -segment. - -Signed-off-by: Petr Tesarik -Signed-off-by: Simon Horman -Signed-off-by: Pingfan Liu ---- - kexec/arch/ppc64/crashdump-ppc64.c | 12 +++++++++++- - 1 file changed, 11 insertions(+), 1 deletion(-) - -diff --git a/kexec/arch/ppc64/crashdump-ppc64.c b/kexec/arch/ppc64/crashdump-ppc64.c -index b3c8928..f62b159 100644 ---- a/kexec/arch/ppc64/crashdump-ppc64.c -+++ b/kexec/arch/ppc64/crashdump-ppc64.c -@@ -123,6 +123,7 @@ static void exclude_crash_region(uint64_t start, uint64_t end) - static int get_dyn_reconf_crash_memory_ranges(void) - { - uint64_t start, end; -+ uint64_t startrange, endrange; - char fname[128], buf[32]; - FILE *file; - unsigned int i; -@@ -137,6 +138,7 @@ static int get_dyn_reconf_crash_memory_ranges(void) - } - - fseek(file, 4, SEEK_SET); -+ startrange = endrange = 0; - for (i = 0; i < num_of_lmbs; i++) { - if ((n = fread(buf, 1, 24, file)) < 0) { - perror(fname); -@@ -162,8 +164,16 @@ static int get_dyn_reconf_crash_memory_ranges(void) - if ((flags & 0x80) || !(flags & 0x8)) - continue; - -- exclude_crash_region(start, end); -+ if (start != endrange) { -+ if (startrange != endrange) -+ exclude_crash_region(startrange, endrange); -+ startrange = start; -+ } -+ endrange = end; - } -+ if (startrange != endrange) -+ exclude_crash_region(startrange, endrange); -+ - fclose(file); - return 0; - } --- -2.7.4 - diff --git a/SOURCES/kexec-tools-2.0.14-x86-Support-large-number-of-memory-ranges.patch b/SOURCES/kexec-tools-2.0.14-x86-Support-large-number-of-memory-ranges.patch deleted file mode 100644 index 69c69ef..0000000 --- a/SOURCES/kexec-tools-2.0.14-x86-Support-large-number-of-memory-ranges.patch +++ /dev/null @@ -1,52 +0,0 @@ -From 4a6d67d9e938a7accf128aff23f8ad4bda67f729 Mon Sep 17 00:00:00 2001 -From: Xunlei Pang -Date: Thu, 23 Mar 2017 19:16:59 +0800 -Subject: [PATCH] x86: Support large number of memory ranges - -We got a problem on one SGI 64TB machine, the current kexec-tools -failed to work due to the insufficient ranges(MAX_MEMORY_RANGES) -allowed which is defined as 1024(less than the ranges on the machine). -The kcore header is insufficient due to the same reason as well. - -To solve this, this patch simply doubles "MAX_MEMORY_RANGES" and -"KCORE_ELF_HEADERS_SIZE". - -Signed-off-by: Xunlei Pang -Tested-by: Frank Ramsay -Signed-off-by: Simon Horman ---- - kexec/arch/i386/kexec-x86.h | 2 +- - kexec/crashdump.h | 4 ++-- - 2 files changed, 3 insertions(+), 3 deletions(-) - -diff --git a/kexec/arch/i386/kexec-x86.h b/kexec/arch/i386/kexec-x86.h -index 33df352..51855f8 100644 ---- a/kexec/arch/i386/kexec-x86.h -+++ b/kexec/arch/i386/kexec-x86.h -@@ -1,7 +1,7 @@ - #ifndef KEXEC_X86_H - #define KEXEC_X86_H - --#define MAX_MEMORY_RANGES 1024 -+#define MAX_MEMORY_RANGES 2048 - - enum coretype { - CORE_TYPE_UNDEF = 0, -diff --git a/kexec/crashdump.h b/kexec/crashdump.h -index 86e1ef2..18bd691 100644 ---- a/kexec/crashdump.h -+++ b/kexec/crashdump.h -@@ -7,8 +7,8 @@ extern int get_xen_vmcoreinfo(uint64_t *addr, uint64_t *len); - - /* Need to find a better way to determine per cpu notes section size. */ - #define MAX_NOTE_BYTES 1024 --/* Expecting ELF headers to fit in 32K. Increase it if you need more. */ --#define KCORE_ELF_HEADERS_SIZE 32768 -+/* Expecting ELF headers to fit in 64K. Increase it if you need more. */ -+#define KCORE_ELF_HEADERS_SIZE 65536 - /* The address of the ELF header is passed to the secondary kernel - * using the kernel command line option memmap=nnn. - * The smallest unit the kernel accepts is in kilobytes, --- -1.8.3.1 - diff --git a/SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-SECTION_MAP_MASK-for-kernel-v.13.patch b/SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-SECTION_MAP_MASK-for-kernel-v.13.patch new file mode 100644 index 0000000..a8390d4 --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-SECTION_MAP_MASK-for-kernel-v.13.patch @@ -0,0 +1,55 @@ +From a02f5f078ce635dd1633dab70869306b0a62e2e2 Mon Sep 17 00:00:00 2001 +From: Pratyush Anand +Date: Thu, 17 Aug 2017 12:47:13 +0900 +Subject: [PATCH v2] Fix SECTION_MAP_MASK for kernel >= v.13 + +* Required for kernel 4.13 + +commit 2d070eab2e82 "mm: consider zone which is not fully populated to +have holes" added a new flag SECTION_IS_ONLINE and therefore +SECTION_MAP_MASK has been changed. We are not able to find correct +mem_map in makedumpfile for kernel version v4.13-rc1 and onward because +of the above kernel change. + +This patch fixes the MASK value keeping the code backward compatible + +Signed-off-by: Pratyush Anand +--- + makedumpfile.c | 5 ++++- + makedumpfile.h | 4 +++- + 2 files changed, 7 insertions(+), 2 deletions(-) + +diff --git a/makedumpfile-1.6.2/makedumpfile.c b/makedumpfile-1.6.2/makedumpfile.c +index 8af0c9d..5096319 100644 +--- a/makedumpfile-1.6.2/makedumpfile.c ++++ b/makedumpfile-1.6.2/makedumpfile.c +@@ -3304,7 +3304,10 @@ section_mem_map_addr(unsigned long addr) + return NOT_KV_ADDR; + } + map = ULONG(mem_section + OFFSET(mem_section.section_mem_map)); +- map &= SECTION_MAP_MASK; ++ if (info->kernel_version < KERNEL_VERSION(4, 13, 0)) ++ map &= SECTION_MAP_MASK_4_12; ++ else ++ map &= SECTION_MAP_MASK; + free(mem_section); + + return map; +diff --git a/makedumpfile-1.6.2/makedumpfile.h b/makedumpfile-1.6.2/makedumpfile.h +index b0cdd02..6f188e4 100644 +--- a/makedumpfile-1.6.2/makedumpfile.h ++++ b/makedumpfile-1.6.2/makedumpfile.h +@@ -183,7 +183,9 @@ isAnon(unsigned long mapping) + #define SECTIONS_PER_ROOT() (info->sections_per_root) + #define SECTION_ROOT_MASK() (SECTIONS_PER_ROOT() - 1) + #define SECTION_NR_TO_ROOT(sec) ((sec) / SECTIONS_PER_ROOT()) +-#define SECTION_MAP_LAST_BIT (1UL<<2) ++#define SECTION_IS_ONLINE (1UL<<2) ++#define SECTION_MAP_LAST_BIT (1UL<<3) ++#define SECTION_MAP_MASK_4_12 (~(SECTION_IS_ONLINE-1)) + #define SECTION_MAP_MASK (~(SECTION_MAP_LAST_BIT-1)) + #define NR_SECTION_ROOTS() divideup(num_section, SECTIONS_PER_ROOT()) + #define SECTION_NR_TO_PFN(sec) ((sec) << PFN_SECTION_SHIFT()) +-- +2.7.4 + diff --git a/SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-kernel_version-variable-being-uninitia.patch b/SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-kernel_version-variable-being-uninitia.patch new file mode 100644 index 0000000..2e3ff1c --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-kernel_version-variable-being-uninitia.patch @@ -0,0 +1,124 @@ +From 08e08d1330f5d4dd0989bfb1558d85c82254654e Mon Sep 17 00:00:00 2001 +From: Bhupesh Sharma +Date: Fri, 17 Nov 2017 06:30:41 +0900 +Subject: [PATCH 2/2] [PATCH 2/2] Fix 'kernel_version' variable being + uninitialized & introduce minor reorganization + +On executing `makedumpfile --mem-usage /proc/kcore`, it +fails currently with the following error message on newer Linux kernels +like 4.13.0 or 4.14.0: + +mem-usage not supported for this kernel. +You can try with -f if your kernel's kcore has valid p_paddr +makedumpfile Failed. + +This happens because 'info->kernel_version' is uninitialized in function +main(). So when we perform the following check, it fails even though the +kernel version is greater than 4.11.0: + +if (info->kernel_version < KERNEL_VERSION(4, 11, 0) && + !info->flag_force) { + +Fix this by reorganizing the code to: +- Add an API to populate the kernel version. +- Call this API rather than replicating the open code across other APIs + across 'makedumpfile.c' + +After this patch, '--mem-usage' can be used properly with makedumpfile. +Here are the logs I observe on a Fedora 26 ppc64le system: + +The kernel version is not supported. +The makedumpfile operation may be incomplete. + +TYPE PAGES EXCLUDABLE DESCRIPTION +---------------------------------------------------------------------- +ZERO 99 yes Pages filled with zero +NON_PRI_CACHE 7817 yes Cache pages without private flag +PRI_CACHE 63603 yes Cache pages with private flag +USER 4105 yes User process pages +FREE 165446 yes Free pages +KERN_DATA 6738 no Dumpable kernel data + +page size: 65536 +Total pages on system: 247808 +Total size on system: 16240345088 Byte + +Signed-off-by: Bhupesh Sharma +--- + makedumpfile.c | 31 ++++++++++++++++++++----------- + 1 file changed, 20 insertions(+), 11 deletions(-) + +diff --git a/makedumpfile-1.6.2/makedumpfile.c b/makedumpfile-1.6.2/makedumpfile.c +index 7ce0c6d648aa..4bde542b4f0c 100644 +--- a/makedumpfile-1.6.2/makedumpfile.c ++++ b/makedumpfile-1.6.2/makedumpfile.c +@@ -1089,6 +1089,21 @@ fallback_to_current_page_size(void) + return TRUE; + } + ++static int populate_kernel_version(void) ++{ ++ struct utsname utsname; ++ ++ if (uname(&utsname)) { ++ ERRMSG("Cannot get name and information about current kernel : %s\n", ++ strerror(errno)); ++ return FALSE; ++ } ++ ++ info->kernel_version = get_kernel_version(utsname.release); ++ ++ return TRUE; ++} ++ + int + check_release(void) + { +@@ -1120,11 +1135,8 @@ check_release(void) + } + } + +- info->kernel_version = get_kernel_version(info->system_utsname.release); +- if (info->kernel_version == FALSE) { +- ERRMSG("Can't get the kernel version.\n"); ++ if (!populate_kernel_version()) + return FALSE; +- } + + return TRUE; + } +@@ -10973,20 +10985,14 @@ int is_crashkernel_mem_reserved(void) + + static int get_page_offset(void) + { +- struct utsname utsname; +- if (uname(&utsname)) { +- ERRMSG("Cannot get name and information about current kernel : %s", +- strerror(errno)); ++ if (!populate_kernel_version()) + return FALSE; +- } + +- info->kernel_version = get_kernel_version(utsname.release); + get_versiondep_info(); + + return TRUE; + } + +- + /* Returns the physical address of start of crash notes buffer for a kernel. */ + static int get_sys_kernel_vmcoreinfo(uint64_t *addr, uint64_t *len) + { +@@ -11363,6 +11369,9 @@ main(int argc, char *argv[]) + MSG("Try `makedumpfile --help' for more information.\n"); + goto out; + } ++ if (!populate_kernel_version()) ++ goto out; ++ + if (info->kernel_version < KERNEL_VERSION(4, 11, 0) && + !info->flag_force) { + MSG("mem-usage not supported for this kernel.\n"); +-- +2.7.4 + diff --git a/SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-off-by-one-errors-in-exclude_segment.patch b/SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-off-by-one-errors-in-exclude_segment.patch new file mode 100644 index 0000000..f1bf20b --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-off-by-one-errors-in-exclude_segment.patch @@ -0,0 +1,75 @@ +From 590f35e773dcd51a750b9a181863660a25b66f01 Mon Sep 17 00:00:00 2001 +From: Petr Tesarik +Date: Fri, 19 Jan 2018 20:46:19 +0900 +Subject: [PATCH 1/2] [PATCH 1/2] Fix off-by-one errors in exclude_segment() + +The crashed reserved memory end offset is the last address within +range, whereas the end offset in the pt_loads[] denotes the first +address past the range. This has caused a number of off-by-one +errors in exclude_segment(). + +First, let's unify the meaning of "end" to be the first out-of-range +address, i.e. start + size. Thanks to that, no +1 or -1 adjustments +are needed in exclude_segment(). + +Second, since the value read from /proc/iomem is the last address +within range, add one when passing it as an argument to +exclude_segment(). This is now the only adjustment by one. + +Signed-off-by: Petr Tesarik +Tested-by: Bhupesh Sharma +--- + elf_info.c | 18 +++++++++--------- + 1 file changed, 9 insertions(+), 9 deletions(-) + +diff --git a/makedumpfile-1.6.2/elf_info.c b/makedumpfile-1.6.2/elf_info.c +index 69b1719b020f..1eaddd968826 100644 +--- a/makedumpfile-1.6.2/elf_info.c ++++ b/makedumpfile-1.6.2/elf_info.c +@@ -820,26 +820,26 @@ static int exclude_segment(struct pt_load_segment **pt_loads, + if (kvstart < vend && kvend > vstart) { + if (kvstart != vstart && kvend != vend) { + /* Split load segment */ +- temp_seg.phys_start = end + 1; ++ temp_seg.phys_start = end; + temp_seg.phys_end = (*pt_loads)[i].phys_end; +- temp_seg.virt_start = kvend + 1; ++ temp_seg.virt_start = kvend; + temp_seg.virt_end = vend; + temp_seg.file_offset = (*pt_loads)[i].file_offset + + temp_seg.virt_start - (*pt_loads)[i].virt_start; + temp_seg.file_size = temp_seg.phys_end + - temp_seg.phys_start; + +- (*pt_loads)[i].virt_end = kvstart - 1; +- (*pt_loads)[i].phys_end = start - 1; ++ (*pt_loads)[i].virt_end = kvstart; ++ (*pt_loads)[i].phys_end = start; + (*pt_loads)[i].file_size -= temp_seg.file_size; + + tidx = i+1; + } else if (kvstart != vstart) { +- (*pt_loads)[i].phys_end = start - 1; +- (*pt_loads)[i].virt_end = kvstart - 1; ++ (*pt_loads)[i].phys_end = start; ++ (*pt_loads)[i].virt_end = kvstart; + } else { +- (*pt_loads)[i].phys_start = end + 1; +- (*pt_loads)[i].virt_start = kvend + 1; ++ (*pt_loads)[i].phys_start = end; ++ (*pt_loads)[i].virt_start = kvend; + } + (*pt_loads)[i].file_size -= (end -start); + } +@@ -917,7 +917,7 @@ int get_kcore_dump_loads(void) + + for (i = 0; i < crash_reserved_mem_nr; i++) { + exclude_segment(&pt_loads, &num_pt_loads, +- crash_reserved_mem[i].start, crash_reserved_mem[i].end); ++ crash_reserved_mem[i].start, crash_reserved_mem[i].end + 1); + } + + max_file_offset = 0; +-- +2.7.4 + diff --git a/SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-physical-to-virtual-conversion-in-excl.patch b/SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-physical-to-virtual-conversion-in-excl.patch new file mode 100644 index 0000000..a355f69 --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-makedumpfile-Fix-physical-to-virtual-conversion-in-excl.patch @@ -0,0 +1,35 @@ +From 6c1bf2a029be0615089f55d815fdb78f6e06e06a Mon Sep 17 00:00:00 2001 +From: Petr Tesarik +Date: Fri, 19 Jan 2018 20:46:17 +0900 +Subject: [PATCH 2/2] [PATCH 2/2] Fix physical-to-virtual conversion in + exclude_segment() + +With kaslr enabled, PAGE_OFFSET may no longer be aligned to allow +calculation using bitwise OR. My fix follows the same idea as +Baoquan's commit 4c53423b995463067fbbd394e724b4d1d6ea3d62 for +set_kcore_vmcoreinfo, i.e. use arithmetic addition instead. + +Signed-off-by: Petr Tesarik +Tested-by: Bhupesh Sharma +--- + elf_info.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/makedumpfile-1.6.2/elf_info.c b/makedumpfile-1.6.2/elf_info.c +index 1eaddd968826..711601a170c7 100644 +--- a/makedumpfile-1.6.2/elf_info.c ++++ b/makedumpfile-1.6.2/elf_info.c +@@ -810,8 +810,8 @@ static int exclude_segment(struct pt_load_segment **pt_loads, + int i, j, tidx = -1; + unsigned long long vstart, vend, kvstart, kvend; + struct pt_load_segment temp_seg = {0}; +- kvstart = (ulong)start | PAGE_OFFSET; +- kvend = (ulong)end | PAGE_OFFSET; ++ kvstart = (ulong)start + PAGE_OFFSET; ++ kvend = (ulong)end + PAGE_OFFSET; + unsigned long size; + + for (i = 0; i < (*num_pt_loads); i++) { +-- +2.7.4 + diff --git a/SOURCES/kexec-tools-2.0.15-makedumpfile-Introduce-vtop4_x86_64_pagetable.patch b/SOURCES/kexec-tools-2.0.15-makedumpfile-Introduce-vtop4_x86_64_pagetable.patch new file mode 100644 index 0000000..f799afd --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-makedumpfile-Introduce-vtop4_x86_64_pagetable.patch @@ -0,0 +1,93 @@ +From 8c89727155f4994b4e75a659e28e5eff16ff6cbc Mon Sep 17 00:00:00 2001 +From: Takao Indoh +Date: Thu, 26 Oct 2017 20:32:54 +0900 +Subject: [PATCH 2/4] [PATCH v3 2/4] Introduce vtop4_x86_64_pagetable + +This patch introduces new function vtop4_x86_64_pagetable +to translate virtual address to physical address. Unlike vtop4_x86_64, +vtop4_x86_64_pagetable need a pointer of top of pagetable like CR3. + +Current vtop4_x86_64 implementation uses symbol value of +init_level4_pgt, therefore vtop4_x86_64 does not work for sadump +dumpfile of kaslr enabled kernel because it does not have vmcoreinfo to +correct address of init_level4_pgt. vtop4_x86_64_pagetable requires +pagetable address instead of init_level4_pgt and sadump dumpfile can +pass CR3 value which is included in dump header. + +Signed-off-by: Takao Indoh +Signed-off-by: HATAYAMA Daisuke +--- + arch/x86_64.c | 30 +++++++++++++++++++++++------- + makedumpfile.h | 1 + + 2 files changed, 24 insertions(+), 7 deletions(-) + +diff --git a/arch/x86_64.c b/arch/x86_64.c +index 08dd6b208bce..33621f1f259c 100644 +--- a/makedumpfile-1.6.2/arch/x86_64.c ++++ b/makedumpfile-1.6.2/arch/x86_64.c +@@ -255,20 +255,15 @@ get_versiondep_info_x86_64(void) + * Translate a virtual address to a physical address by using 4 levels paging. + */ + unsigned long long +-vtop4_x86_64(unsigned long vaddr) ++__vtop4_x86_64(unsigned long vaddr, unsigned long pagetable) + { + unsigned long page_dir, pml4, pgd_paddr, pgd_pte, pmd_paddr, pmd_pte; + unsigned long pte_paddr, pte; + +- if (SYMBOL(init_level4_pgt) == NOT_FOUND_SYMBOL) { +- ERRMSG("Can't get the symbol of init_level4_pgt.\n"); +- return NOT_PADDR; +- } +- + /* + * Get PGD. + */ +- page_dir = SYMBOL(init_level4_pgt) - __START_KERNEL_map + info->phys_base; ++ page_dir = pagetable; + if (is_xen_memory()) { + page_dir = ptom_xen(page_dir); + if (page_dir == NOT_PADDR) +@@ -346,6 +341,27 @@ vtop4_x86_64(unsigned long vaddr) + return (pte & ENTRY_MASK) + PAGEOFFSET(vaddr); + } + ++unsigned long long ++vtop4_x86_64(unsigned long vaddr) ++{ ++ unsigned long pagetable; ++ ++ if (SYMBOL(init_level4_pgt) == NOT_FOUND_SYMBOL) { ++ ERRMSG("Can't get the symbol of init_level4_pgt.\n"); ++ return NOT_PADDR; ++ } ++ ++ pagetable = SYMBOL(init_level4_pgt) - __START_KERNEL_map + info->phys_base; ++ ++ return __vtop4_x86_64(vaddr, pagetable); ++} ++ ++unsigned long long ++vtop4_x86_64_pagetable(unsigned long vaddr, unsigned long pagetable) ++{ ++ return __vtop4_x86_64(vaddr, pagetable); ++} ++ + /* + * for Xen extraction + */ +diff --git a/makedumpfile.h b/makedumpfile.h +index 704a6bc2f8f4..f48dc0b82d4a 100644 +--- a/makedumpfile-1.6.2/makedumpfile.h ++++ b/makedumpfile-1.6.2/makedumpfile.h +@@ -978,6 +978,7 @@ int get_phys_base_x86_64(void); + int get_machdep_info_x86_64(void); + int get_versiondep_info_x86_64(void); + unsigned long long vtop4_x86_64(unsigned long vaddr); ++unsigned long long vtop4_x86_64_pagetable(unsigned long vaddr, unsigned long pagetable); + #define find_vmemmap() find_vmemmap_x86_64() + #define get_phys_base() get_phys_base_x86_64() + #define get_machdep_info() get_machdep_info_x86_64() +-- +2.5.5 + diff --git a/SOURCES/kexec-tools-2.0.15-makedumpfile-PATCH-Support-newer-kernels.patch b/SOURCES/kexec-tools-2.0.15-makedumpfile-PATCH-Support-newer-kernels.patch new file mode 100644 index 0000000..b3edbcc --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-makedumpfile-PATCH-Support-newer-kernels.patch @@ -0,0 +1,48 @@ +From 555943348e649d2c187189f7690a98555a4b3251 Mon Sep 17 00:00:00 2001 +From: Atsushi Kumagai +Date: Wed, 10 Jan 2018 11:56:31 +0900 +Subject: [PATCH] [PATCH] Support newer kernels. + +A new makedumpfile supports newer kernels: + + - 4.12, 4.13, 4.14 (x86 FLATMEM) + - 4.12, 4.13, 4.14 (x86 SPARSEMEM) + - 4.12, 4.13, 4.14 (x86_64 SPARSEMEM) + +Signed-off-by: Atsushi Kumagai +Signed-off-by: Pingfan Liu +--- + README | 3 +++ + makedumpfile.h | 2 +- + 2 files changed, 4 insertions(+), 1 deletion(-) + +diff --git a/makedumpfile-1.6.2/README b/makedumpfile-1.6.2/README +index 8de4dc6..c3eeefe 100644 +--- a/makedumpfile-1.6.2/README ++++ b/makedumpfile-1.6.2/README +@@ -119,6 +119,9 @@ + 4.9 | OK | ** | | | | ** | | -- | OK | OK | | | + 4.10 | OK | ** | | | | ** | | -- | OK | OK | | | + 4.11 | OK | ** | | | | ** | | -- | OK | OK | | | ++ 4.12 | OK | ** | | | | ** | | -- | OK | OK | | | ++ 4.13 | OK | ** | | | | ** | | -- | OK | OK | | | ++ 4.14 | OK | ** | | | | ** | | -- | OK | OK | | | + + OK : Support. + -- : Not support. +diff --git a/makedumpfile-1.6.2/makedumpfile.h b/makedumpfile-1.6.2/makedumpfile.h +index c1f779a..50aaffa 100644 +--- a/makedumpfile-1.6.2/makedumpfile.h ++++ b/makedumpfile-1.6.2/makedumpfile.h +@@ -478,7 +478,7 @@ do { \ + #define KVER_MIN_SHIFT 16 + #define KERNEL_VERSION(x,y,z) (((x) << KVER_MAJ_SHIFT) | ((y) << KVER_MIN_SHIFT) | (z)) + #define OLDEST_VERSION KERNEL_VERSION(2, 6, 15)/* linux-2.6.15 */ +-#define LATEST_VERSION KERNEL_VERSION(4, 11, 7)/* linux-4.11.7 */ ++#define LATEST_VERSION KERNEL_VERSION(4, 14, 8)/* linux-4.14.8 */ + + /* + * vmcoreinfo in /proc/vmcore +-- +2.7.4 + diff --git a/SOURCES/kexec-tools-2.0.15-makedumpfile-Support-symbol-__cpu_online_mask.patch b/SOURCES/kexec-tools-2.0.15-makedumpfile-Support-symbol-__cpu_online_mask.patch new file mode 100644 index 0000000..1974ffa --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-makedumpfile-Support-symbol-__cpu_online_mask.patch @@ -0,0 +1,68 @@ +From d6d5b443c82471818d43cb87c9280a0252e763e7 Mon Sep 17 00:00:00 2001 +From: Takao Indoh +Date: Thu, 26 Oct 2017 20:32:48 +0900 +Subject: [PATCH 1/4] [PATCH v3 1/4] Support symbol __cpu_online_mask + +In the upstream kernel, by commit 5aec01b83 cpu_online_mask was replaced +with macros and new variables __cpu_online_mask was added instead of it. +Sadump uses cpu_online_mask to check the cpu was online or not, +therefore it also need __cpu_online_mask symbol for this in the latest +kernel. + +Signed-off-by: Takao Indoh +Signed-off-by: HATAYAMA Daisuke +--- + makedumpfile.c | 9 +++++++-- + makedumpfile.h | 1 + + sadump_info.c | 3 ++- + 3 files changed, 10 insertions(+), 3 deletions(-) + +diff --git a/makedumpfile.c b/makedumpfile.c +index 567ac5dc1f9e..5f2ca7d0fbc8 100644 +--- a/makedumpfile-1.6.2/makedumpfile.c ++++ b/makedumpfile-1.6.2/makedumpfile.c +@@ -1519,8 +1519,13 @@ get_symbol_info(void) + SYMBOL_INIT(__per_cpu_load, "__per_cpu_load"); + SYMBOL_INIT(__per_cpu_offset, "__per_cpu_offset"); + SYMBOL_INIT(cpu_online_mask, "cpu_online_mask"); +- if (SYMBOL(cpu_online_mask) == NOT_FOUND_SYMBOL) +- SYMBOL_INIT(cpu_online_mask, "cpu_online_map"); ++ SYMBOL_INIT(__cpu_online_mask, "__cpu_online_mask"); ++ if (SYMBOL(cpu_online_mask) == NOT_FOUND_SYMBOL) { ++ if (SYMBOL(__cpu_online_mask) == NOT_FOUND_SYMBOL) ++ SYMBOL_INIT(cpu_online_mask, "cpu_online_map"); ++ else ++ SYMBOL_INIT(cpu_online_mask, "__cpu_online_mask"); ++ } + SYMBOL_INIT(kexec_crash_image, "kexec_crash_image"); + SYMBOL_INIT(node_remap_start_vaddr, "node_remap_start_vaddr"); + SYMBOL_INIT(node_remap_end_vaddr, "node_remap_end_vaddr"); +diff --git a/makedumpfile.h b/makedumpfile.h +index f4ba02d11f09..704a6bc2f8f4 100644 +--- a/makedumpfile-1.6.2/makedumpfile.h ++++ b/makedumpfile-1.6.2/makedumpfile.h +@@ -1596,6 +1596,7 @@ struct symbol_table { + unsigned long long __per_cpu_offset; + unsigned long long __per_cpu_load; + unsigned long long cpu_online_mask; ++ unsigned long long __cpu_online_mask; + unsigned long long kexec_crash_image; + + /* +diff --git a/sadump_info.c b/sadump_info.c +index 257f1be5e686..7dd22e704234 100644 +--- a/makedumpfile-1.6.2/sadump_info.c ++++ b/makedumpfile-1.6.2/sadump_info.c +@@ -953,7 +953,8 @@ cpu_online_mask_init(void) + return FALSE; + } + +- if (SIZE(cpumask) == NOT_FOUND_STRUCTURE) ++ if ((SIZE(cpumask) == NOT_FOUND_STRUCTURE) || ++ (SYMBOL(__cpu_online_mask) != NOT_FOUND_SYMBOL)) + cpu_online_mask_addr = SYMBOL(cpu_online_mask); + + else { +-- +2.5.5 + diff --git a/SOURCES/kexec-tools-2.0.15-makedumpfile-book3s-ppc64-Lower-the-max-real-address-to-53-bits.patch b/SOURCES/kexec-tools-2.0.15-makedumpfile-book3s-ppc64-Lower-the-max-real-address-to-53-bits.patch new file mode 100644 index 0000000..3d08d0a --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-makedumpfile-book3s-ppc64-Lower-the-max-real-address-to-53-bits.patch @@ -0,0 +1,71 @@ +From dc28bfc3213960b549bcc70f0d5379a6222d2c60 Mon Sep 17 00:00:00 2001 +From: Bhupesh Sharma +Date: Wed, 13 Sep 2017 05:04:00 +0900 +Subject: [PATCH] [PATCH v2] book3s/ppc64: Lower the max real address to 53 + bits for kernels >= v4.11 + +* Required for kernel 4.11 + +Kernel commit 2f18d533757da3899f4bedab0b2c051b080079dc lowered the +max real address on ppc64 to 53 bits. + +Make similar changes in makedumpfile (on basis of the underlying kernel +version), without which the makedumpfile will fail to create a dumpfile +and instead throw a SEGV fault as shown below on kernels >= v4.11: + + # makedumpfile --split -d 31 -x vmlinux vmcore dumpfile_{1,2,3} 2>&1 + + The kernel version is not supported. + The makedumpfile operation may be incomplete. + [ 1196.252094] makedumpfile[2367]: unhandled signal 11 at + 00000100f7011ca8 nip 000000001001eecc lr 000000001001f3c0 code 30001 + Segmentation fault + +Signed-off-by: Bhupesh Sharma +--- + arch/ppc64.c | 8 +++++++- + makedumpfile.h | 5 +++++ + 2 files changed, 12 insertions(+), 1 deletion(-) + +diff --git a/makedumpfile-1.6.2/arch/ppc64.c b/makedumpfile-1.6.2/arch/ppc64.c +index bacac778f73c..2f5a0daa16b2 100644 +--- a/makedumpfile-1.6.2/arch/ppc64.c ++++ b/makedumpfile-1.6.2/arch/ppc64.c +@@ -307,11 +307,17 @@ ppc64_vmalloc_init(void) + } + + info->pte_rpn_mask = PTE_RPN_MASK_DEFAULT; +- if (info->kernel_version >= KERNEL_VERSION(4, 6, 0)) { ++ if ((info->kernel_version >= KERNEL_VERSION(4, 6, 0)) && ++ (info->kernel_version < KERNEL_VERSION(4, 11, 0))) { + info->pte_rpn_mask = PTE_RPN_MASK_L4_4_6; + info->pte_rpn_shift = PTE_RPN_SHIFT_L4_4_6; + } + ++ if (info->kernel_version >= KERNEL_VERSION(4, 11, 0)) { ++ info->pte_rpn_mask = PTE_RPN_MASK_L4_4_11; ++ info->pte_rpn_shift = PTE_RPN_SHIFT_L4_4_11; ++ } ++ + /* + * Compute ptrs per each level + */ +diff --git a/makedumpfile-1.6.2/makedumpfile.h b/makedumpfile-1.6.2/makedumpfile.h +index 7d81bbcf2234..f4ba02d11f09 100644 +--- a/makedumpfile-1.6.2/makedumpfile.h ++++ b/makedumpfile-1.6.2/makedumpfile.h +@@ -692,6 +692,11 @@ unsigned long get_kvbase_arm64(void); + #define PUD_MASKED_BITS_4_7 0xc0000000000000ffUL + #define PMD_MASKED_BITS_4_7 0xc0000000000000ffUL + ++#define PTE_RPN_SIZE_L4_4_11 53 ++#define PTE_RPN_MASK_L4_4_11 \ ++ (((1UL << PTE_RPN_SIZE_L4_4_11) - 1) & ~((1UL << info->page_shift) - 1)) ++#define PTE_RPN_SHIFT_L4_4_11 info->page_shift ++ + /* + * Supported MMU types + */ +-- +2.7.4 + diff --git a/SOURCES/kexec-tools-2.0.15-makedumpfile-ppc64-get-the-info-of-mem-reserved-for-.patch b/SOURCES/kexec-tools-2.0.15-makedumpfile-ppc64-get-the-info-of-mem-reserved-for-.patch new file mode 100644 index 0000000..598376f --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-makedumpfile-ppc64-get-the-info-of-mem-reserved-for-.patch @@ -0,0 +1,169 @@ +From 0300f611541ad8ec654898eebf03c8345f0263ca Mon Sep 17 00:00:00 2001 +From: Pingfan Liu +Date: Mon, 21 Aug 2017 12:24:14 +0900 +Subject: [PATCH 2/2] [PATCH v2 2/2] ppc64: get the info of mem reserved for + crashkernel + +In kernel, ppc64 does not export the mem layout by ioresource. So we +need to get the mem info for crashkernel from device tree. + +Signed-off-by: Pingfan Liu +--- + arch/ppc64.c | 36 ++++++++++++++++++++++++++++++++++++ + makedumpfile.c | 3 +++ + makedumpfile.h | 11 +++++++++++ + 3 files changed, 50 insertions(+) + +diff --git a/makedumpfile-1.6.2/arch/ppc64.c b/makedumpfile-1.6.2/arch/ppc64.c +index 3fd6002..bacac77 100644 +--- a/makedumpfile-1.6.2/arch/ppc64.c ++++ b/makedumpfile-1.6.2/arch/ppc64.c +@@ -617,4 +617,40 @@ vaddr_to_paddr_ppc64(unsigned long vaddr) + return ppc64_vtop_level4(vaddr); + } + ++int arch_crashkernel_mem_size_ppc64() ++{ ++ const char f_crashsize[] = "/proc/device-tree/chosen/linux,crashkernel-size"; ++ const char f_crashbase[] = "/proc/device-tree/chosen/linux,crashkernel-base"; ++ unsigned long crashk_sz_be, crashk_sz; ++ unsigned long crashk_base_be, crashk_base; ++ uint swap; ++ FILE *fp, *fpb; ++ ++ fp = fopen(f_crashsize, "r"); ++ if (!fp) { ++ ERRMSG("Cannot open %s\n", f_crashsize); ++ return FALSE; ++ } ++ fpb = fopen(f_crashbase, "r"); ++ if (!fp) { ++ ERRMSG("Cannot open %s\n", f_crashbase); ++ fclose(fp); ++ return FALSE; ++ } ++ ++ fread(&crashk_sz_be, sizeof(crashk_sz_be), 1, fp); ++ fread(&crashk_base_be, sizeof(crashk_base_be), 1, fpb); ++ fclose(fp); ++ fclose(fpb); ++ /* dev tree is always big endian */ ++ swap = !is_bigendian(); ++ crashk_sz = swap64(crashk_sz_be, swap); ++ crashk_base = swap64(crashk_base_be, swap); ++ crash_reserved_mem_nr = 1; ++ crash_reserved_mem[0].start = crashk_base; ++ crash_reserved_mem[0].end = crashk_base + crashk_sz - 1; ++ ++ return TRUE; ++} ++ + #endif /* powerpc64 */ +diff --git a/makedumpfile-1.6.2/makedumpfile.c b/makedumpfile-1.6.2/makedumpfile.c +index 5096319..567ac5d 100644 +--- a/makedumpfile-1.6.2/makedumpfile.c ++++ b/makedumpfile-1.6.2/makedumpfile.c +@@ -10945,6 +10945,9 @@ int is_crashkernel_mem_reserved(void) + { + int ret; + ++ if (arch_crashkernel_mem_size()) ++ return TRUE; ++ + ret = iomem_for_each_line("Crash kernel\n", + crashkernel_mem_callback, NULL); + crash_reserved_mem_nr = ret; +diff --git a/makedumpfile-1.6.2/makedumpfile.h b/makedumpfile-1.6.2/makedumpfile.h +index 6f188e4..7d81bbc 100644 +--- a/makedumpfile-1.6.2/makedumpfile.h ++++ b/makedumpfile-1.6.2/makedumpfile.h +@@ -936,6 +936,7 @@ int get_xen_info_arm64(void); + #define get_xen_basic_info_arch(X) get_xen_basic_info_arm64(X) + #define get_xen_info_arch(X) get_xen_info_arm64(X) + #define is_phys_addr(X) stub_true_ul(X) ++#define arch_crashkernel_mem_size() stub_false() + #endif /* aarch64 */ + + #ifdef __arm__ +@@ -949,6 +950,7 @@ unsigned long long vaddr_to_paddr_arm(unsigned long vaddr); + #define get_kaslr_offset(X) stub_false() + #define vaddr_to_paddr(X) vaddr_to_paddr_arm(X) + #define is_phys_addr(X) stub_true_ul(X) ++#define arch_crashkernel_mem_size() stub_false() + #endif /* arm */ + + #ifdef __x86__ +@@ -962,6 +964,7 @@ unsigned long long vaddr_to_paddr_x86(unsigned long vaddr); + #define get_kaslr_offset(X) stub_false() + #define vaddr_to_paddr(X) vaddr_to_paddr_x86(X) + #define is_phys_addr(X) stub_true_ul(X) ++#define arch_crashkernel_mem_size() stub_false() + #endif /* x86 */ + + #ifdef __x86_64__ +@@ -977,12 +980,14 @@ unsigned long long vtop4_x86_64(unsigned long vaddr); + #define get_kaslr_offset(X) get_kaslr_offset_x86_64(X) + #define vaddr_to_paddr(X) vtop4_x86_64(X) + #define is_phys_addr(X) stub_true_ul(X) ++#define arch_crashkernel_mem_size() stub_false() + #endif /* x86_64 */ + + #ifdef __powerpc64__ /* powerpc64 */ + int get_machdep_info_ppc64(void); + int get_versiondep_info_ppc64(void); + unsigned long long vaddr_to_paddr_ppc64(unsigned long vaddr); ++int arch_crashkernel_mem_size_ppc64(void); + #define find_vmemmap() stub_false() + #define get_phys_base() stub_true() + #define get_machdep_info() get_machdep_info_ppc64() +@@ -990,6 +995,7 @@ unsigned long long vaddr_to_paddr_ppc64(unsigned long vaddr); + #define get_kaslr_offset(X) stub_false() + #define vaddr_to_paddr(X) vaddr_to_paddr_ppc64(X) + #define is_phys_addr(X) stub_true_ul(X) ++#define arch_crashkernel_mem_size() arch_crashkernel_mem_size_ppc64() + #endif /* powerpc64 */ + + #ifdef __powerpc32__ /* powerpc32 */ +@@ -1002,6 +1008,7 @@ unsigned long long vaddr_to_paddr_ppc(unsigned long vaddr); + #define get_kaslr_offset(X) stub_false() + #define vaddr_to_paddr(X) vaddr_to_paddr_ppc(X) + #define is_phys_addr(X) stub_true_ul(X) ++#define arch_crashkernel_mem_size() stub_false() + #endif /* powerpc32 */ + + #ifdef __s390x__ /* s390x */ +@@ -1015,6 +1022,7 @@ int is_iomem_phys_addr_s390x(unsigned long addr); + #define get_kaslr_offset(X) stub_false() + #define vaddr_to_paddr(X) vaddr_to_paddr_s390x(X) + #define is_phys_addr(X) is_iomem_phys_addr_s390x(X) ++#define arch_crashkernel_mem_size() stub_false() + #endif /* s390x */ + + #ifdef __ia64__ /* ia64 */ +@@ -1029,6 +1037,7 @@ unsigned long long vaddr_to_paddr_ia64(unsigned long vaddr); + #define vaddr_to_paddr(X) vaddr_to_paddr_ia64(X) + #define VADDR_REGION(X) (((unsigned long)(X)) >> REGION_SHIFT) + #define is_phys_addr(X) stub_true_ul(X) ++#define arch_crashkernel_mem_size() stub_false() + #endif /* ia64 */ + + #ifdef __sparc64__ /* sparc64 */ +@@ -1041,6 +1050,7 @@ unsigned long long vaddr_to_paddr_sparc64(unsigned long vaddr); + #define get_versiondep_info() get_versiondep_info_sparc64() + #define vaddr_to_paddr(X) vaddr_to_paddr_sparc64(X) + #define is_phys_addr(X) stub_true_ul(X) ++#define arch_crashkernel_mem_size() stub_false() + #endif /* sparc64 */ + + typedef unsigned long long mdf_pfn_t; +@@ -1942,6 +1952,7 @@ int iomem_for_each_line(char *match, int (*callback)(void *data, int nr, + unsigned long base, + unsigned long length), + void *data); ++int is_bigendian(void); + + + /* +-- +2.7.4 + diff --git a/SOURCES/kexec-tools-2.0.15-makedumpfile-ppc64-set-page_offset-in-get_versiondep.patch b/SOURCES/kexec-tools-2.0.15-makedumpfile-ppc64-set-page_offset-in-get_versiondep.patch new file mode 100644 index 0000000..e7fb949 --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-makedumpfile-ppc64-set-page_offset-in-get_versiondep.patch @@ -0,0 +1,30 @@ +From d0f59cdf7f30e4c2e533004c32c1f1979ae86371 Mon Sep 17 00:00:00 2001 +From: Pingfan Liu +Date: Mon, 21 Aug 2017 12:24:13 +0900 +Subject: [PATCH 1/2] [PATCH v2 1/2] ppc64: set page_offset in + get_versiondep_info_ppc64() + +Envalue info->page_offset in get_versiondep_info_ppc64() is a little +misleading. But since show_mem_usage->get_page_offset->get_versiondep_info +needs to get this info, so initialize it in get_versiondep_info_ppc64(). + +Signed-off-by: Pingfan Liu +--- + arch/ppc64.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/makedumpfile-1.6.2/arch/ppc64.c b/makedumpfile-1.6.2/arch/ppc64.c +index 6aeab7e..3fd6002 100644 +--- a/makedumpfile-1.6.2/arch/ppc64.c ++++ b/makedumpfile-1.6.2/arch/ppc64.c +@@ -576,6 +576,7 @@ get_versiondep_info_ppc64() + ERRMSG("Can't initialize for vmalloc translation\n"); + return FALSE; + } ++ info->page_offset = __PAGE_OFFSET; + + return TRUE; + } +-- +2.7.4 + diff --git a/SOURCES/kexec-tools-2.0.15-makedumpfile-sadump-Fix-a-KASLR-problem-of-sadump-wh.patch b/SOURCES/kexec-tools-2.0.15-makedumpfile-sadump-Fix-a-KASLR-problem-of-sadump-wh.patch new file mode 100644 index 0000000..c41e38d --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-makedumpfile-sadump-Fix-a-KASLR-problem-of-sadump-wh.patch @@ -0,0 +1,359 @@ +From 09288f2058c8066a2729588ec668eed3e1140028 Mon Sep 17 00:00:00 2001 +From: Takao Indoh +Date: Thu, 26 Oct 2017 20:33:01 +0900 +Subject: [PATCH 4/4] [PATCH v3 4/4] sadump: Fix a KASLR problem of sadump + while kdump is working + +In the calc_kaslr_offset(), kaslr_offset and phys_base are calculated +using IDTR and CR3, but this solution does not work in the following +cases. + +1) If the dump is captured on early stage of kernel boot, IDTR points + early IDT table(early_idts) instead of normal IDT(idt_table). +2) If the dump is captured whle kdump is working, IDTR points IDT table + of 2nd kernel, not 1st kernel. + +This patch fixes the case 2). Current implementation does not support +the case 1), need enhancement in the future. This patch gets kernel boot +parameter from "saved_command_line" and check if "elfcorehdr=" is +included in the parameter. If it's included, we are in the 2nd kernel. +Retrieve vmcoreinfo from address of "elfcorehdr=" and get kaslr_offset +and phys_base from vmcoreinfo. + +Signed-off-by: Takao Indoh +--- + makedumpfile.c | 1 + + makedumpfile.h | 1 + + sadump_info.c | 271 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 3 files changed, 273 insertions(+) + +diff --git a/makedumpfile.c b/makedumpfile.c +index 41438a344574..6d5fc8b95415 100644 +--- a/makedumpfile-1.6.2/makedumpfile.c ++++ b/makedumpfile-1.6.2/makedumpfile.c +@@ -1556,6 +1556,7 @@ get_symbol_info(void) + + SYMBOL_INIT(divide_error, "divide_error"); + SYMBOL_INIT(idt_table, "idt_table"); ++ SYMBOL_INIT(saved_command_line, "saved_command_line"); + + return TRUE; + } +diff --git a/makedumpfile.h b/makedumpfile.h +index 5f814e7bc3c1..db753792bca6 100644 +--- a/makedumpfile-1.6.2/makedumpfile.h ++++ b/makedumpfile-1.6.2/makedumpfile.h +@@ -1602,6 +1602,7 @@ struct symbol_table { + unsigned long long kexec_crash_image; + unsigned long long divide_error; + unsigned long long idt_table; ++ unsigned long long saved_command_line; + + /* + * symbols on ppc64 arch +diff --git a/sadump_info.c b/sadump_info.c +index 29ccef881370..148d4baaa538 100644 +--- a/makedumpfile-1.6.2/sadump_info.c ++++ b/makedumpfile-1.6.2/sadump_info.c +@@ -1059,6 +1059,241 @@ get_vec0_addr(ulong idtr) + } + + /* ++ * Parse a string of [size[KMG]@]offset[KMG] ++ * Import from Linux kernel(lib/cmdline.c) ++ */ ++static ulong memparse(char *ptr, char **retptr) ++{ ++ char *endptr; ++ ++ unsigned long long ret = strtoull(ptr, &endptr, 0); ++ ++ switch (*endptr) { ++ case 'E': ++ case 'e': ++ ret <<= 10; ++ case 'P': ++ case 'p': ++ ret <<= 10; ++ case 'T': ++ case 't': ++ ret <<= 10; ++ case 'G': ++ case 'g': ++ ret <<= 10; ++ case 'M': ++ case 'm': ++ ret <<= 10; ++ case 'K': ++ case 'k': ++ ret <<= 10; ++ endptr++; ++ default: ++ break; ++ } ++ ++ if (retptr) ++ *retptr = endptr; ++ ++ return ret; ++} ++ ++/* ++ * Find "elfcorehdr=" in the boot parameter of kernel and return the address ++ * of elfcorehdr. ++ */ ++static ulong ++get_elfcorehdr(ulong cr3) ++{ ++ char cmdline[BUFSIZE], *ptr; ++ ulong cmdline_vaddr; ++ ulong cmdline_paddr; ++ ulong buf_vaddr, buf_paddr; ++ char *end; ++ ulong elfcorehdr_addr = 0, elfcorehdr_size = 0; ++ ++ if (SYMBOL(saved_command_line) == NOT_FOUND_SYMBOL) { ++ ERRMSG("Can't get the symbol of saved_command_line.\n"); ++ return 0; ++ } ++ cmdline_vaddr = SYMBOL(saved_command_line); ++ if ((cmdline_paddr = vtop4_x86_64_pagetable(cmdline_vaddr, cr3)) == NOT_PADDR) ++ return 0; ++ ++ DEBUG_MSG("sadump: cmdline vaddr: %lx\n", cmdline_vaddr); ++ DEBUG_MSG("sadump: cmdline paddr: %lx\n", cmdline_paddr); ++ ++ if (!readmem(PADDR, cmdline_paddr, &buf_vaddr, sizeof(ulong))) ++ return 0; ++ ++ if ((buf_paddr = vtop4_x86_64_pagetable(buf_vaddr, cr3)) == NOT_PADDR) ++ return 0; ++ ++ DEBUG_MSG("sadump: cmdline buf vaddr: %lx\n", buf_vaddr); ++ DEBUG_MSG("sadump: cmdline buf paddr: %lx\n", buf_paddr); ++ ++ memset(cmdline, 0, BUFSIZE); ++ if (!readmem(PADDR, buf_paddr, cmdline, BUFSIZE)) ++ return 0; ++ ++ ptr = strstr(cmdline, "elfcorehdr="); ++ if (!ptr) ++ return 0; ++ ++ DEBUG_MSG("sadump: 2nd kernel detected.\n"); ++ ++ ptr += strlen("elfcorehdr="); ++ elfcorehdr_addr = memparse(ptr, &end); ++ if (*end == '@') { ++ elfcorehdr_size = elfcorehdr_addr; ++ elfcorehdr_addr = memparse(end + 1, &end); ++ } ++ ++ DEBUG_MSG("sadump: elfcorehdr_addr: %lx\n", elfcorehdr_addr); ++ DEBUG_MSG("sadump: elfcorehdr_size: %lx\n", elfcorehdr_size); ++ ++ return elfcorehdr_addr; ++} ++ ++/* ++ * Get vmcoreinfo from elfcorehdr. ++ * Some codes are imported from Linux kernel(fs/proc/vmcore.c) ++ */ ++static int ++get_vmcoreinfo_in_kdump_kernel(ulong elfcorehdr, ulong *addr, int *len) ++{ ++ unsigned char e_ident[EI_NIDENT]; ++ Elf64_Ehdr ehdr; ++ Elf64_Phdr phdr; ++ Elf64_Nhdr nhdr; ++ ulong ptr; ++ ulong nhdr_offset = 0; ++ int i; ++ ++ if (!readmem(PADDR, elfcorehdr, e_ident, EI_NIDENT)) ++ return FALSE; ++ ++ if (e_ident[EI_CLASS] != ELFCLASS64) { ++ ERRMSG("Only ELFCLASS64 is supportd\n"); ++ return FALSE; ++ } ++ ++ if (!readmem(PADDR, elfcorehdr, &ehdr, sizeof(ehdr))) ++ return FALSE; ++ ++ /* Sanity Check */ ++ if (memcmp(ehdr.e_ident, ELFMAG, SELFMAG) != 0 || ++ (ehdr.e_type != ET_CORE) || ++ ehdr.e_ident[EI_CLASS] != ELFCLASS64 || ++ ehdr.e_ident[EI_VERSION] != EV_CURRENT || ++ ehdr.e_version != EV_CURRENT || ++ ehdr.e_ehsize != sizeof(Elf64_Ehdr) || ++ ehdr.e_phentsize != sizeof(Elf64_Phdr) || ++ ehdr.e_phnum == 0) { ++ ERRMSG("Invalid elf header\n"); ++ return FALSE; ++ } ++ ++ ptr = elfcorehdr + ehdr.e_phoff; ++ for (i = 0; i < ehdr.e_phnum; i++) { ++ ulong offset; ++ char name[16]; ++ ++ if (!readmem(PADDR, ptr, &phdr, sizeof(phdr))) ++ return FALSE; ++ ++ ptr += sizeof(phdr); ++ if (phdr.p_type != PT_NOTE) ++ continue; ++ ++ offset = phdr.p_offset; ++ if (!readmem(PADDR, offset, &nhdr, sizeof(nhdr))) ++ return FALSE; ++ ++ offset += divideup(sizeof(Elf64_Nhdr), sizeof(Elf64_Word))* ++ sizeof(Elf64_Word); ++ memset(name, 0, sizeof(name)); ++ if (!readmem(PADDR, offset, name, sizeof(name))) ++ return FALSE; ++ ++ if(!strcmp(name, "VMCOREINFO")) { ++ nhdr_offset = offset; ++ break; ++ } ++ } ++ ++ if (!nhdr_offset) ++ return FALSE; ++ ++ *addr = nhdr_offset + ++ divideup(nhdr.n_namesz, sizeof(Elf64_Word))* ++ sizeof(Elf64_Word); ++ *len = nhdr.n_descsz; ++ ++ DEBUG_MSG("sadump: vmcoreinfo addr: %lx\n", *addr); ++ DEBUG_MSG("sadump: vmcoreinfo len: %d\n", *len); ++ ++ return TRUE; ++} ++ ++/* ++ * Check if current kaslr_offset/phys_base is for 1st kernel or 2nd kernel. ++ * If we are in 2nd kernel, get kaslr_offset/phys_base from vmcoreinfo. ++ * ++ * 1. Get command line and try to retrieve "elfcorehdr=" boot parameter ++ * 2. If "elfcorehdr=" is not found in command line, we are in 1st kernel. ++ * There is nothing to do. ++ * 3. If "elfcorehdr=" is found, we are in 2nd kernel. Find vmcoreinfo ++ * using "elfcorehdr=" and retrieve kaslr_offset/phys_base from vmcoreinfo. ++ */ ++int ++get_kaslr_offset_from_vmcoreinfo(ulong cr3, ulong *kaslr_offset, ++ ulong *phys_base) ++{ ++ ulong elfcorehdr_addr = 0; ++ ulong vmcoreinfo_addr; ++ int vmcoreinfo_len; ++ char *buf, *pos; ++ int ret = FALSE; ++ ++ elfcorehdr_addr = get_elfcorehdr(cr3); ++ if (!elfcorehdr_addr) ++ return FALSE; ++ ++ if (!get_vmcoreinfo_in_kdump_kernel(elfcorehdr_addr, &vmcoreinfo_addr, ++ &vmcoreinfo_len)) ++ return FALSE; ++ ++ if (!vmcoreinfo_len) ++ return FALSE; ++ ++ DEBUG_MSG("sadump: Find vmcoreinfo in kdump memory\n"); ++ ++ if (!(buf = malloc(vmcoreinfo_len))) { ++ ERRMSG("Can't allocate vmcoreinfo buffer.\n"); ++ return FALSE; ++ } ++ ++ if (!readmem(PADDR, vmcoreinfo_addr, buf, vmcoreinfo_len)) ++ goto finish; ++ ++ pos = strstr(buf, STR_NUMBER("phys_base")); ++ if (!pos) ++ goto finish; ++ *phys_base = strtoull(pos + strlen(STR_NUMBER("phys_base")), NULL, 0); ++ ++ pos = strstr(buf, STR_KERNELOFFSET); ++ if (!pos) ++ goto finish; ++ *kaslr_offset = strtoull(pos + strlen(STR_KERNELOFFSET), NULL, 16); ++ ret = TRUE; ++ ++finish: ++ free(buf); ++ return ret; ++} ++ ++/* + * Calculate kaslr_offset and phys_base + * + * kaslr_offset: +@@ -1106,6 +1341,26 @@ get_vec0_addr(ulong idtr) + * + * Note that the address (A) cannot be used instead of (E) because (A) is + * not direct map address, it's a fixed map address. ++ * ++ * This solution works in most every case, but does not work in the ++ * following case. ++ * ++ * 1) If the dump is captured on early stage of kernel boot, IDTR points ++ * early IDT table(early_idts) instead of normal IDT(idt_table). ++ * 2) If the dump is captured whle kdump is working, IDTR points ++ * IDT table of 2nd kernel, not 1st kernel. ++ * ++ * Current implementation does not support the case 1), need ++ * enhancement in the future. For the case 2), get kaslr_offset and ++ * phys_base as follows. ++ * ++ * 1) Get kaslr_offset and phys_base using the above solution. ++ * 2) Get kernel boot parameter from "saved_command_line" ++ * 3) If "elfcorehdr=" is not included in boot parameter, we are in the ++ * first kernel, nothing to do any more. ++ * 4) If "elfcorehdr=" is included in boot parameter, we are in the 2nd ++ * kernel. Retrieve vmcoreinfo from address of "elfcorehdr=" and ++ * get kaslr_offset and phys_base from vmcoreinfo. + */ + int + calc_kaslr_offset(void) +@@ -1116,6 +1371,7 @@ calc_kaslr_offset(void) + int apicid; + unsigned long divide_error_vmcore, divide_error_vmlinux; + unsigned long kaslr_offset, phys_base; ++ unsigned long kaslr_offset_kdump, phys_base_kdump; + + memset(&zero, 0, sizeof(zero)); + for (apicid = 0; apicid < sh->nr_cpus; ++apicid) { +@@ -1161,6 +1417,21 @@ calc_kaslr_offset(void) + if (!get_symbol_info()) + return FALSE; + ++ /* ++ * Check if current kaslr_offset/phys_base is for 1st kernel or 2nd ++ * kernel. If we are in 2nd kernel, get kaslr_offset/phys_base ++ * from vmcoreinfo ++ */ ++ if (get_kaslr_offset_from_vmcoreinfo(cr3, &kaslr_offset_kdump, ++ &phys_base_kdump)) { ++ info->kaslr_offset = kaslr_offset_kdump; ++ info->phys_base = phys_base_kdump; ++ ++ /* Reload symbol */ ++ if (!get_symbol_info()) ++ return FALSE; ++ } ++ + DEBUG_MSG("sadump: kaslr_offset=%lx\n", info->kaslr_offset); + DEBUG_MSG("sadump: phys_base=%lx\n", info->phys_base); + +-- +2.5.5 + diff --git a/SOURCES/kexec-tools-2.0.15-makedumpfile-sadump-Fix-a-KASLR-problem-of-sadump.patch b/SOURCES/kexec-tools-2.0.15-makedumpfile-sadump-Fix-a-KASLR-problem-of-sadump.patch new file mode 100644 index 0000000..49248d7 --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-makedumpfile-sadump-Fix-a-KASLR-problem-of-sadump.patch @@ -0,0 +1,262 @@ +From e1ac694b94ebfa7204c5b1fac1a87d204b48f5b4 Mon Sep 17 00:00:00 2001 +From: Takao Indoh +Date: Thu, 26 Oct 2017 20:32:54 +0900 +Subject: [PATCH 3/4] [PATCH v3 3/4] sadump: Fix a KASLR problem of sadump + +This patch fix a problem that makedumpfile cannot handle a dumpfile +which is captured by sadump in KASLR enabled kernel. + +When KASLR feature is enabled, a kernel is placed on the memory randomly +and therefore makedumpfile cannot handle a dumpfile captured by sadump +because addresses of kernel symbols in System.map or vmlinux are +different from actual addresses. + +To solve this problem, we need to calculate kaslr offset(the difference +between original symbol address and actual address) and phys_base, and +adjust symbol table of makedumpfile. In the case of dumpfile of kdump, +these information is included in the header, but dumpfile of sadump does +not have such a information. + +This patch calculate kaslr offset and phys_base to solve this problem. +Please see the comment in the calc_kaslr_offset() for the detail idea. +The basic idea is getting register (IDTR and CR3) from dump header, and +calculate kaslr_offset/phys_base using them. + +Signed-off-by: Takao Indoh +--- + makedumpfile.c | 10 ++++ + makedumpfile.h | 5 +- + sadump_info.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- + 3 files changed, 155 insertions(+), 3 deletions(-) + +diff --git a/makedumpfile.c b/makedumpfile.c +index 5f2ca7d0fbc8..41438a344574 100644 +--- a/makedumpfile-1.6.2/makedumpfile.c ++++ b/makedumpfile-1.6.2/makedumpfile.c +@@ -1554,6 +1554,9 @@ get_symbol_info(void) + SYMBOL_INIT(demote_segment_4k, "demote_segment_4k"); + SYMBOL_INIT(cur_cpu_spec, "cur_cpu_spec"); + ++ SYMBOL_INIT(divide_error, "divide_error"); ++ SYMBOL_INIT(idt_table, "idt_table"); ++ + return TRUE; + } + +@@ -2249,6 +2252,13 @@ write_vmcoreinfo_data(void) + WRITE_NUMBER_UNSIGNED("kimage_voffset", kimage_voffset); + #endif + ++ if (info->phys_base) ++ fprintf(info->file_vmcoreinfo, "%s%lu\n", STR_NUMBER("phys_base"), ++ info->phys_base); ++ if (info->kaslr_offset) ++ fprintf(info->file_vmcoreinfo, "%s%lx\n", STR_KERNELOFFSET, ++ info->kaslr_offset); ++ + /* + * write the source file of 1st kernel + */ +diff --git a/makedumpfile.h b/makedumpfile.h +index f48dc0b82d4a..5f814e7bc3c1 100644 +--- a/makedumpfile-1.6.2/makedumpfile.h ++++ b/makedumpfile-1.6.2/makedumpfile.h +@@ -45,6 +45,7 @@ + #include "sadump_mod.h" + #include + #include ++#include + + #define VMEMMAPSTART 0xffffea0000000000UL + #define BITS_PER_WORD 64 +@@ -1599,6 +1600,8 @@ struct symbol_table { + unsigned long long cpu_online_mask; + unsigned long long __cpu_online_mask; + unsigned long long kexec_crash_image; ++ unsigned long long divide_error; ++ unsigned long long idt_table; + + /* + * symbols on ppc64 arch +@@ -1960,7 +1963,7 @@ int iomem_for_each_line(char *match, int (*callback)(void *data, int nr, + unsigned long length), + void *data); + int is_bigendian(void); +- ++int get_symbol_info(void); + + /* + * for Xen extraction +diff --git a/sadump_info.c b/sadump_info.c +index 7dd22e704234..29ccef881370 100644 +--- a/makedumpfile-1.6.2/sadump_info.c ++++ b/makedumpfile-1.6.2/sadump_info.c +@@ -1035,6 +1035,138 @@ sadump_get_max_mapnr(void) + + #ifdef __x86_64__ + ++/* ++ * Get address of vector0 interrupt handler (Devide Error) form Interrupt ++ * Descriptor Table. ++ */ ++static unsigned long ++get_vec0_addr(ulong idtr) ++{ ++ struct gate_struct64 { ++ uint16_t offset_low; ++ uint16_t segment; ++ uint32_t ist : 3, zero0 : 5, type : 5, dpl : 2, p : 1; ++ uint16_t offset_middle; ++ uint32_t offset_high; ++ uint32_t zero1; ++ } __attribute__((packed)) gate; ++ ++ readmem(PADDR, idtr, &gate, sizeof(gate)); ++ ++ return ((ulong)gate.offset_high << 32) ++ + ((ulong)gate.offset_middle << 16) ++ + gate.offset_low; ++} ++ ++/* ++ * Calculate kaslr_offset and phys_base ++ * ++ * kaslr_offset: ++ * The difference between original address in vmlinux and actual address ++ * placed randomly by kaslr feature. To be more accurate, ++ * kaslr_offset = actual address - original address ++ * ++ * phys_base: ++ * Physical address where the kerenel is placed. In other words, it's a ++ * physical address of __START_KERNEL_map. This is also decided randomly by ++ * kaslr. ++ * ++ * kaslr offset and phys_base are calculated as follows: ++ * ++ * kaslr_offset: ++ * 1) Get IDTR and CR3 value from the dump header. ++ * 2) Get a virtual address of IDT from IDTR value ++ * --- (A) ++ * 3) Translate (A) to physical address using CR3, which points a top of ++ * page table. ++ * --- (B) ++ * 4) Get an address of vector0 (Devide Error) interrupt handler from ++ * IDT, which are pointed by (B). ++ * --- (C) ++ * 5) Get an address of symbol "divide_error" form vmlinux ++ * --- (D) ++ * ++ * Now we have two addresses: ++ * (C)-> Actual address of "divide_error" ++ * (D)-> Original address of "divide_error" in the vmlinux ++ * ++ * kaslr_offset can be calculated by the difference between these two ++ * value. ++ * ++ * phys_base; ++ * 1) Get IDT virtual address from vmlinux ++ * --- (E) ++ * ++ * So phys_base can be calculated using relationship of directly mapped ++ * address. ++ * ++ * phys_base = ++ * Physical address(B) - ++ * (Virtual address(E) + kaslr_offset - __START_KERNEL_map) ++ * ++ * Note that the address (A) cannot be used instead of (E) because (A) is ++ * not direct map address, it's a fixed map address. ++ */ ++int ++calc_kaslr_offset(void) ++{ ++ struct sadump_header *sh = si->sh_memory; ++ uint64_t idtr = 0, cr3 = 0, idtr_paddr; ++ struct sadump_smram_cpu_state smram, zero; ++ int apicid; ++ unsigned long divide_error_vmcore, divide_error_vmlinux; ++ unsigned long kaslr_offset, phys_base; ++ ++ memset(&zero, 0, sizeof(zero)); ++ for (apicid = 0; apicid < sh->nr_cpus; ++apicid) { ++ if (!get_smram_cpu_state(apicid, &smram)) { ++ ERRMSG("get_smram_cpu_state error\n"); ++ return FALSE; ++ } ++ ++ if (memcmp(&smram, &zero, sizeof(smram)) != 0) ++ break; ++ } ++ if (apicid >= sh->nr_cpus) { ++ ERRMSG("Can't get smram state\n"); ++ return FALSE; ++ } ++ ++ idtr = ((uint64_t)smram.IdtUpper)<<32 | (uint64_t)smram.IdtLower; ++ cr3 = smram.Cr3; ++ ++ /* Convert virtual address of IDT table to physical address */ ++ if ((idtr_paddr = vtop4_x86_64_pagetable(idtr, cr3)) == NOT_PADDR) ++ return FALSE; ++ ++ /* Now we can calculate kaslr_offset and phys_base */ ++ divide_error_vmlinux = SYMBOL(divide_error); ++ divide_error_vmcore = get_vec0_addr(idtr_paddr); ++ kaslr_offset = divide_error_vmcore - divide_error_vmlinux; ++ phys_base = idtr_paddr - ++ (SYMBOL(idt_table) + kaslr_offset - __START_KERNEL_map); ++ ++ info->kaslr_offset = kaslr_offset; ++ info->phys_base = phys_base; ++ ++ DEBUG_MSG("sadump: idtr=%" PRIx64 "\n", idtr); ++ DEBUG_MSG("sadump: cr3=%" PRIx64 "\n", cr3); ++ DEBUG_MSG("sadump: idtr(phys)=%" PRIx64 "\n", idtr_paddr); ++ DEBUG_MSG("sadump: devide_error(vmlinux)=%lx\n", ++ divide_error_vmlinux); ++ DEBUG_MSG("sadump: devide_error(vmcore)=%lx\n", ++ divide_error_vmcore); ++ ++ /* Reload symbol */ ++ if (!get_symbol_info()) ++ return FALSE; ++ ++ DEBUG_MSG("sadump: kaslr_offset=%lx\n", info->kaslr_offset); ++ DEBUG_MSG("sadump: phys_base=%lx\n", info->phys_base); ++ ++ return TRUE; ++} ++ + int + sadump_virt_phys_base(void) + { +@@ -1065,6 +1197,9 @@ sadump_virt_phys_base(void) + } + + failed: ++ if (calc_kaslr_offset()) ++ return TRUE; ++ + info->phys_base = 0; + + DEBUG_MSG("sadump: failed to calculate phys_base; default to 0\n"); +@@ -1518,10 +1653,14 @@ cpu_to_apicid(int cpu, int *apicid) + if (!readmem(VADDR, SYMBOL(x86_bios_cpu_apicid_early_ptr), + &early_ptr, sizeof(early_ptr))) + return FALSE; +- ++ /* ++ * Note: SYMBOL(name) value is adjusted by info->kaslr_offset, ++ * but per_cpu symbol does not need to be adjusted becasue it ++ * is not affected by kaslr. ++ */ + apicid_addr = early_ptr + ? SYMBOL(x86_bios_cpu_apicid_early_map)+cpu*sizeof(uint16_t) +- : per_cpu_ptr(SYMBOL(x86_bios_cpu_apicid), cpu); ++ : per_cpu_ptr(SYMBOL(x86_bios_cpu_apicid) - info->kaslr_offset, cpu); + + if (!readmem(VADDR, apicid_addr, &apicid_u16, sizeof(uint16_t))) + return FALSE; +-- +2.5.5 + diff --git a/SOURCES/kexec-tools-2.0.15-makedumpfile-sadump-Fix-a-problem-of-PTI-enabled-kernel.patch b/SOURCES/kexec-tools-2.0.15-makedumpfile-sadump-Fix-a-problem-of-PTI-enabled-kernel.patch new file mode 100644 index 0000000..346ccee --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-makedumpfile-sadump-Fix-a-problem-of-PTI-enabled-kernel.patch @@ -0,0 +1,87 @@ +From: Takao Indoh +To: ats-kumagai@wm.jp.nec.com, d.hatayama@jp.fujitsu.com +Subject: [makedumpfile PATCH] sadump: Fix a problem of PTI enabled kernel +Date: Fri, 26 Jan 2018 09:22:26 +0900 +Cc: kexec@lists.infradead.org +MIME-Version: 1.0 +Content-Transfer-Encoding: 8bit +Content-Type: text/plain; charset=utf-8 + +This patch fixes a problme that a dumpfile of sadump cannot be handled by +makedumpfile when Page Table Isolation(PTI) is enabled. + +When PTI is enabled, bit 12 of CR3 register is used to split user space and +kernel space. Also bit 11:0 is used for Process Context IDentifiers(PCID). To +open a dump file of sadump, a value of CR3 is used to calculate KASLR offset and +phys_base, therefore this patch fixes to mask CR3 register value collectly for +PTI enabled kernel. + +Signed-off-by: Takao Indoh +--- + makedumpfile.c | 2 ++ + makedumpfile.h | 2 ++ + sadump_info.c | 9 ++++++++- + 3 files changed, 12 insertions(+), 1 deletion(-) + +diff --git a/makedumpfile-1.6.2/makedumpfile.c b/makedumpfile-1.6.2/makedumpfile.c +index 64b404a..247a056 100644 +--- a/makedumpfile-1.6.2/makedumpfile.c ++++ b/makedumpfile-1.6.2/makedumpfile.c +@@ -1557,6 +1557,8 @@ get_symbol_info(void) + SYMBOL_INIT(divide_error, "divide_error"); + SYMBOL_INIT(idt_table, "idt_table"); + SYMBOL_INIT(saved_command_line, "saved_command_line"); ++ SYMBOL_INIT(pti_init, "pti_init"); ++ SYMBOL_INIT(kaiser_init, "kaiser_init"); + + return TRUE; + } +diff --git a/makedumpfile-1.6.2/makedumpfile.h b/makedumpfile-1.6.2/makedumpfile.h +index 57cf4d9..8ee4d29 100644 +--- a/makedumpfile-1.6.2/makedumpfile.h ++++ b/makedumpfile-1.6.2/makedumpfile.h +@@ -1608,6 +1608,8 @@ struct symbol_table { + unsigned long long divide_error; + unsigned long long idt_table; + unsigned long long saved_command_line; ++ unsigned long long pti_init; ++ unsigned long long kaiser_init; + + /* + * symbols on ppc64 arch +diff --git a/makedumpfile-1.6.2/sadump_info.c b/makedumpfile-1.6.2/sadump_info.c +index 148d4ba..dd50d48 100644 +--- a/makedumpfile-1.6.2/sadump_info.c ++++ b/makedumpfile-1.6.2/sadump_info.c +@@ -1362,6 +1362,9 @@ finish: + * kernel. Retrieve vmcoreinfo from address of "elfcorehdr=" and + * get kaslr_offset and phys_base from vmcoreinfo. + */ ++#define PTI_USER_PGTABLE_BIT (info->page_shift) ++#define PTI_USER_PGTABLE_MASK (1 << PTI_USER_PGTABLE_BIT) ++#define CR3_PCID_MASK 0xFFFull + int + calc_kaslr_offset(void) + { +@@ -1389,7 +1392,11 @@ calc_kaslr_offset(void) + } + + idtr = ((uint64_t)smram.IdtUpper)<<32 | (uint64_t)smram.IdtLower; +- cr3 = smram.Cr3; ++ if ((SYMBOL(pti_init) != NOT_FOUND_SYMBOL) || ++ (SYMBOL(kaiser_init) != NOT_FOUND_SYMBOL)) ++ cr3 = smram.Cr3 & ~(CR3_PCID_MASK|PTI_USER_PGTABLE_MASK); ++ else ++ cr3 = smram.Cr3 & ~CR3_PCID_MASK; + + /* Convert virtual address of IDT table to physical address */ + if ((idtr_paddr = vtop4_x86_64_pagetable(idtr, cr3)) == NOT_PADDR) +-- +1.8.3.1 + + + +_______________________________________________ +kexec mailing list +kexec@lists.infradead.org +http://lists.infradead.org/mailman/listinfo/kexec diff --git a/SOURCES/kexec-tools-2.0.15-makedumpfile-x86_64-Take-care-of-init_level4_pgt-rename-.patch b/SOURCES/kexec-tools-2.0.15-makedumpfile-x86_64-Take-care-of-init_level4_pgt-rename-.patch new file mode 100644 index 0000000..344293f --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-makedumpfile-x86_64-Take-care-of-init_level4_pgt-rename-.patch @@ -0,0 +1,48 @@ +From 64bd5db6f90ec5bb6622273fa5ee4cb80b172ade Mon Sep 17 00:00:00 2001 +From: Pratyush Anand +Date: Fri, 4 Aug 2017 10:12:17 +0900 +Subject: [PATCH] [PATCH v2] x86_64: Take care of init_level4_pgt rename in + kernel + +* Required for kernel 4.13 + +Following commit renamed init_level4_pgt to init_top_pgt in kernel. + +commit 65ade2f872b474fa8a04c2d397783350326634e6 +Author: Kirill A. Shutemov +Date: Tue Jun 6 14:31:27 2017 +0300 + + x86/boot/64: Rename init_level4_pgt and early_level4_pgt + +This patch takes care of above kernel modification in makedumpfile. + +Signed-off-by: Pratyush Anand +--- + makedumpfile.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/makedumpfile-1.6.2/makedumpfile.c b/makedumpfile-1.6.2/makedumpfile.c +index f85003a..30230a1 100644 +--- a/makedumpfile-1.6.2/makedumpfile.c ++++ b/makedumpfile-1.6.2/makedumpfile.c +@@ -1486,6 +1486,8 @@ get_symbol_info(void) + SYMBOL_INIT(_stext, "_stext"); + SYMBOL_INIT(swapper_pg_dir, "swapper_pg_dir"); + SYMBOL_INIT(init_level4_pgt, "init_level4_pgt"); ++ if (SYMBOL(init_level4_pgt) == NOT_FOUND_SYMBOL) ++ SYMBOL_INIT(init_level4_pgt, "init_top_pgt"); + SYMBOL_INIT(vmlist, "vmlist"); + SYMBOL_INIT(vmap_area_list, "vmap_area_list"); + SYMBOL_INIT(node_online_map, "node_online_map"); +@@ -2500,6 +2502,8 @@ read_vmcoreinfo(void) + READ_SYMBOL("_stext", _stext); + READ_SYMBOL("swapper_pg_dir", swapper_pg_dir); + READ_SYMBOL("init_level4_pgt", init_level4_pgt); ++ if (SYMBOL(init_level4_pgt) == NOT_FOUND_SYMBOL) ++ READ_SYMBOL("init_top_pgt", init_level4_pgt); + READ_SYMBOL("vmlist", vmlist); + READ_SYMBOL("vmap_area_list", vmap_area_list); + READ_SYMBOL("node_online_map", node_online_map); +-- +2.7.4 + diff --git a/SOURCES/kexec-tools-2.0.15-ppc64-avoid-adding-coherent-memory-regio.patch b/SOURCES/kexec-tools-2.0.15-ppc64-avoid-adding-coherent-memory-regio.patch new file mode 100644 index 0000000..e2c5784 --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-ppc64-avoid-adding-coherent-memory-regio.patch @@ -0,0 +1,131 @@ +From hbathini at linux.vnet.ibm.com Thu Aug 17 05:31:51 2017 +From: hbathini at linux.vnet.ibm.com (Hari Bathini) +Date: Thu, 17 Aug 2017 18:01:51 +0530 +Subject: [PATCH] kexec-tools: ppc64: avoid adding coherent memory regions to + crash memory ranges +Message-ID: <150297311110.25328.11468130779639120510.stgit@hbathini.in.ibm.com> +Content-Length: 3407 +Lines: 121 + +Accelerator devices like GPU and FPGA cards contain onboard memory. This +onboard memory is represented as a memory only NUMA node, integrating it +with core memory subsystem. Since, the link through which these devices +are integrated to core memory goes down after a system crash and they are +meant for user workloads, avoid adding coherent device memory regions to +crash memory ranges. Without this change, makedumpfile tool tries to save +unaccessible coherent device memory regions, crashing the system. + +Signed-off-by: Hari Bathini +--- + kexec/arch/ppc64/crashdump-ppc64.c | 64 +++++++++++++++++++++++++++++++++++- + kexec/arch/ppc64/kexec-ppc64.h | 1 + + 2 files changed, 63 insertions(+), 2 deletions(-) + +diff --git a/kexec/arch/ppc64/crashdump-ppc64.c b/kexec/arch/ppc64/crashdump-ppc64.c +index 13995bf..7ea3983 100644 +--- a/kexec/arch/ppc64/crashdump-ppc64.c ++++ b/kexec/arch/ppc64/crashdump-ppc64.c +@@ -181,6 +181,53 @@ static int get_dyn_reconf_crash_memory_ranges(void) + return 0; + } + ++/* ++ * For a given memory node, check if it is mapped to system RAM or ++ * to onboard memory on accelerator device like GPU card or such. ++ */ ++static int is_coherent_device_mem(const char *fname) ++{ ++ char fpath[PATH_LEN]; ++ char buf[32]; ++ DIR *dmem; ++ FILE *file; ++ struct dirent *mentry; ++ int cnt, ret = 0; ++ ++ strcpy(fpath, fname); ++ if ((dmem = opendir(fpath)) == NULL) { ++ perror(fpath); ++ return -1; ++ } ++ ++ while ((mentry = readdir(dmem)) != NULL) { ++ if (strcmp(mentry->d_name, "compatible")) ++ continue; ++ ++ strcat(fpath, "/compatible"); ++ if ((file = fopen(fpath, "r")) == NULL) { ++ perror(fpath); ++ ret = -1; ++ break; ++ } ++ if ((cnt = fread(buf, 1, 32, file)) < 0) { ++ perror(fpath); ++ fclose(file); ++ ret = -1; ++ break; ++ } ++ if (!strncmp(buf, "ibm,coherent-device-memory", 26)) { ++ ret = 1; ++ break; ++ } ++ fclose(file); ++ } ++ ++ closedir(dmem); ++ return ret; ++} ++ ++ + /* Reads the appropriate file and retrieves the SYSTEM RAM regions for whom to + * create Elf headers. Keeping it separate from get_memory_ranges() as + * requirements are different in the case of normal kexec and crashdumps. +@@ -196,12 +243,12 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges) + { + + char device_tree[256] = "/proc/device-tree/"; +- char fname[256]; ++ char fname[PATH_LEN]; + char buf[MAXBYTES]; + DIR *dir, *dmem; + FILE *file; + struct dirent *dentry, *mentry; +- int n, crash_rng_len = 0; ++ int n, ret, crash_rng_len = 0; + unsigned long long start, end; + int page_size; + +@@ -240,6 +287,19 @@ static int get_crash_memory_ranges(struct memory_range **range, int *ranges) + continue; + strcpy(fname, device_tree); + strcat(fname, dentry->d_name); ++ ++ ret = is_coherent_device_mem(fname); ++ if (ret == -1) { ++ closedir(dir); ++ goto err; ++ } else if (ret == 1) { ++ /* ++ * Avoid adding this memory region as it is not ++ * mapped to system RAM. ++ */ ++ continue; ++ } ++ + if ((dmem = opendir(fname)) == NULL) { + perror(fname); + closedir(dir); +diff --git a/kexec/arch/ppc64/kexec-ppc64.h b/kexec/arch/ppc64/kexec-ppc64.h +index 633ae77..434b4bf 100644 +--- a/kexec/arch/ppc64/kexec-ppc64.h ++++ b/kexec/arch/ppc64/kexec-ppc64.h +@@ -1,6 +1,7 @@ + #ifndef KEXEC_PPC64_H + #define KEXEC_PPC64_H + ++#define PATH_LEN 256 + #define MAXBYTES 128 + #define MAX_LINE 160 + #define CORE_TYPE_ELF32 1 + + + diff --git a/SOURCES/kexec-tools-2.0.15-ppc64-fix-command-line-overflow-error.patch b/SOURCES/kexec-tools-2.0.15-ppc64-fix-command-line-overflow-error.patch new file mode 100644 index 0000000..cef2101 --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-ppc64-fix-command-line-overflow-error.patch @@ -0,0 +1,141 @@ +From 21eb397a5fc9227cd95d23e8c74a49cf6a293e57 Mon Sep 17 00:00:00 2001 +From: Hari Bathini +Date: Wed, 9 Aug 2017 23:47:42 +0530 +Subject: [PATCH] kexec-tools: powerpc: fix command line overflow error + +Since kernel commit a5980d064fe2 ("powerpc: Bump COMMAND_LINE_SIZE +to 2048"), powerpc bumped command line size to 2048 but the size +used here is still the default value of 512. Bump it to 2048 to +fix command line overflow errors observed when command line length +is above 512 bytes. Also, get rid of the multiple definitions of +COMMAND_LINE_SIZE macro in ppc architecture. + +Signed-off-by: Hari Bathini +Signed-off-by: Simon Horman +Signed-off-by: Pingfan Liu +--- + kexec/arch/ppc/crashdump-powerpc.c | 6 +++++- + kexec/arch/ppc/crashdump-powerpc.h | 2 -- + kexec/arch/ppc/fs2dt.c | 1 - + kexec/arch/ppc/kexec-ppc.h | 3 ++- + kexec/arch/ppc/ops.h | 1 - + kexec/arch/ppc64/crashdump-ppc64.c | 6 ++++-- + kexec/arch/ppc64/crashdump-ppc64.h | 2 +- + 7 files changed, 12 insertions(+), 9 deletions(-) + +diff --git a/kexec/arch/ppc/crashdump-powerpc.c b/kexec/arch/ppc/crashdump-powerpc.c +index dde6de7..4ad026f 100644 +--- a/kexec/arch/ppc/crashdump-powerpc.c ++++ b/kexec/arch/ppc/crashdump-powerpc.c +@@ -252,8 +252,12 @@ static void ulltoa(unsigned long long i, char *str) + /* Append str to cmdline */ + static void add_cmdline(char *cmdline, char *str) + { ++ int cmdline_size; + int cmdlen = strlen(cmdline) + strlen(str); +- if (cmdlen > (COMMAND_LINE_SIZE - 1)) ++ ++ cmdline_size = (kernel_version() < KERNEL_VERSION(3, 10, 0) ? ++ 512 : COMMAND_LINE_SIZE); ++ if (cmdlen > (cmdline_size - 1)) + die("Command line overflow\n"); + strcat(cmdline, str); + } +diff --git a/kexec/arch/ppc/crashdump-powerpc.h b/kexec/arch/ppc/crashdump-powerpc.h +index 9b9b01e..97b5095 100644 +--- a/kexec/arch/ppc/crashdump-powerpc.h ++++ b/kexec/arch/ppc/crashdump-powerpc.h +@@ -20,8 +20,6 @@ extern struct arch_options_t arch_options; + #define KERNELBASE PAGE_OFFSET + #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) + +-#define COMMAND_LINE_SIZE 512 /* from kernel */ +- + #ifdef CONFIG_BOOKE + /* We don't need backup region in Book E */ + #define BACKUP_SRC_START 0x0000 +diff --git a/kexec/arch/ppc/fs2dt.c b/kexec/arch/ppc/fs2dt.c +index 6e77379..fed499b 100644 +--- a/kexec/arch/ppc/fs2dt.c ++++ b/kexec/arch/ppc/fs2dt.c +@@ -37,7 +37,6 @@ + #define TREEWORDS 65536 /* max 32 bit words for properties */ + #define MEMRESERVE 256 /* max number of reserved memory blks */ + #define MAX_MEMORY_RANGES 1024 +-#define COMMAND_LINE_SIZE 512 /* from kernel */ + + static char pathname[MAXPATH]; + static char propnames[NAMESPACE] = { 0 }; +diff --git a/kexec/arch/ppc/kexec-ppc.h b/kexec/arch/ppc/kexec-ppc.h +index f8fd678..04e728e 100644 +--- a/kexec/arch/ppc/kexec-ppc.h ++++ b/kexec/arch/ppc/kexec-ppc.h +@@ -6,6 +6,8 @@ + #define CORE_TYPE_ELF32 1 + #define CORE_TYPE_ELF64 2 + ++#define COMMAND_LINE_SIZE 2048 /* from kernel */ ++ + extern unsigned char setup_simple_start[]; + extern uint32_t setup_simple_size; + +@@ -76,7 +78,6 @@ extern int init_memory_region_info(void); + extern int read_memory_region_limits(int fd, unsigned long long *start, + unsigned long long *end); + extern int get_devtree_value(const char *fname, unsigned long long *pvalue); +-#define COMMAND_LINE_SIZE 512 /* from kernel */ + /*fs2dt*/ + void reserve(unsigned long long where, unsigned long long length); + +diff --git a/kexec/arch/ppc/ops.h b/kexec/arch/ppc/ops.h +index 7334a05..5e7a070 100644 +--- a/kexec/arch/ppc/ops.h ++++ b/kexec/arch/ppc/ops.h +@@ -12,7 +12,6 @@ + #define _PPC_BOOT_OPS_H_ + #include "types.h" + +-#define COMMAND_LINE_SIZE 512 + #define MAX_PATH_LEN 256 + #define MAX_PROP_LEN 256 /* What should this be? */ + +diff --git a/kexec/arch/ppc64/crashdump-ppc64.c b/kexec/arch/ppc64/crashdump-ppc64.c +index 5a71d51..13995bf 100644 +--- a/kexec/arch/ppc64/crashdump-ppc64.c ++++ b/kexec/arch/ppc64/crashdump-ppc64.c +@@ -381,7 +381,7 @@ static void ultoa(uint64_t i, char *str) + static int add_cmdline_param(char *cmdline, uint64_t addr, char *cmdstr, + char *byte) + { +- int cmdlen, len, align = 1024; ++ int cmdline_size, cmdlen, len, align = 1024; + char str[COMMAND_LINE_SIZE], *ptr; + + /* Passing in =xxxK / =xxxM format. Saves space required in cmdline.*/ +@@ -402,7 +402,9 @@ static int add_cmdline_param(char *cmdline, uint64_t addr, char *cmdstr, + strcat(str, byte); + len = strlen(str); + cmdlen = strlen(cmdline) + len; +- if (cmdlen > (COMMAND_LINE_SIZE - 1)) ++ cmdline_size = (kernel_version() < KERNEL_VERSION(3, 10, 0) ? ++ 512 : COMMAND_LINE_SIZE); ++ if (cmdlen > (cmdline_size - 1)) + die("Command line overflow\n"); + strcat(cmdline, str); + dbgprintf("Command line after adding elfcorehdr: %s\n", cmdline); +diff --git a/kexec/arch/ppc64/crashdump-ppc64.h b/kexec/arch/ppc64/crashdump-ppc64.h +index d654c6b..42ccc31 100644 +--- a/kexec/arch/ppc64/crashdump-ppc64.h ++++ b/kexec/arch/ppc64/crashdump-ppc64.h +@@ -16,7 +16,7 @@ void add_usable_mem_rgns(unsigned long long base, unsigned long long size); + #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) + #define MAXMEM (-KERNELBASE-VMALLOCBASE) + +-#define COMMAND_LINE_SIZE 512 /* from kernel */ ++#define COMMAND_LINE_SIZE 2048 /* from kernel */ + /* Backup Region, First 64K of System RAM. */ + #define BACKUP_SRC_START 0x0000 + #define BACKUP_SRC_END 0xffff +-- +2.7.4 + diff --git a/SOURCES/kexec-tools-2.0.15-ppc64-fix-how-RMA-top-is-deduced.patch b/SOURCES/kexec-tools-2.0.15-ppc64-fix-how-RMA-top-is-deduced.patch new file mode 100644 index 0000000..ed43f28 --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-ppc64-fix-how-RMA-top-is-deduced.patch @@ -0,0 +1,123 @@ +From: Hari Bathini +Date: Wed, 26 Jul 2017 22:49:41 +0530 +Subject: [PATCH] kexec-tools: ppc64: fix how RMA top is deduced + +Hang was observed, in purgatory, on a machine configured with +single LPAR. This was because one of the segments was loaded +outside the actual Real Memory Area (RMA) due to wrongly +deduced RMA top value. + +Currently, top of real memory area, which is crucial for loading +kexec/kdump kernel, is obtained by iterating through mem nodes +and setting its value based on the base and size values of the +last mem node in the iteration. That can't always be correct as +the order of iteration may not be same and RMA base & size are +always based on the first memory property. Fix this by setting +RMA top value based on the base and size values of the memory +node that has the smallest base value (first memory property) +among all the memory nodes. + +Also, correct the misnomers rmo_base and rmo_top to rma_base +and rma_top respectively. + +While how RMA top is deduced was broken for sometime, the issue +may not have been seen so far, for couple of possible reasons: + + 1. Only one mem node was available. + 2. First memory property has been the last node in + iteration when multiple mem nodes were present. + +Fixes: 02f4088ffded ("kexec fix ppc64 device-tree mem node") +Reported-by: Ankit Kumar +Cc: Michael Ellerman +Cc: Geoff Levand +Signed-off-by: Hari Bathini +Signed-off-by: Simon Horman +Signed-off-by: Pingfan Liu +--- + kexec/arch/ppc64/kexec-ppc64.c | 35 +++++++++++++++++++---------------- + 1 file changed, 19 insertions(+), 16 deletions(-) + +diff --git a/kexec/arch/ppc64/kexec-ppc64.c b/kexec/arch/ppc64/kexec-ppc64.c +index 6e8c175..a7d708b 100644 +--- a/kexec/arch/ppc64/kexec-ppc64.c ++++ b/kexec/arch/ppc64/kexec-ppc64.c +@@ -38,7 +38,7 @@ + static struct memory_range *exclude_range = NULL; + static struct memory_range *memory_range = NULL; + static struct memory_range *base_memory_range = NULL; +-static uint64_t rmo_top; ++static uint64_t rma_top; + uint64_t memory_max = 0; + uint64_t memory_limit; + static int nr_memory_ranges, nr_exclude_ranges; +@@ -385,7 +385,7 @@ int get_devtree_value(const char *fname, unsigned long long *value) + */ + static int get_devtree_details(unsigned long kexec_flags) + { +- uint64_t rmo_base; ++ uint64_t rma_base = -1, base; + uint64_t tce_base; + unsigned int tce_size; + uint64_t htab_base, htab_size; +@@ -696,10 +696,13 @@ static int get_devtree_details(unsigned long kexec_flags) + perror(fname); + goto error_openfile; + } +- rmo_base = be64_to_cpu(((uint64_t *)buf)[0]); +- rmo_top = rmo_base + be64_to_cpu(((uint64_t *)buf)[1]); +- if (rmo_top > 0x30000000UL) +- rmo_top = 0x30000000UL; ++ base = be64_to_cpu(((uint64_t *)buf)[0]); ++ if (base < rma_base) { ++ rma_base = base; ++ rma_top = base + be64_to_cpu(((uint64_t *)buf)[1]); ++ if (rma_top > 0x30000000UL) ++ rma_top = 0x30000000UL; ++ } + + fclose(file); + closedir(cdir); +@@ -811,14 +814,14 @@ int setup_memory_ranges(unsigned long kexec_flags) + j++; + if (j >= max_memory_ranges) + realloc_memory_ranges(); +- /* Limit the end to rmo_top */ +- if (memory_range[j-1].start >= rmo_top) { ++ /* Limit the end to rma_top */ ++ if (memory_range[j-1].start >= rma_top) { + j--; + break; + } +- if ((memory_range[j-1].start < rmo_top) && +- (memory_range[j-1].end >= rmo_top)) { +- memory_range[j-1].end = rmo_top; ++ if ((memory_range[j-1].start < rma_top) && ++ (memory_range[j-1].end >= rma_top)) { ++ memory_range[j-1].end = rma_top; + break; + } + continue; +@@ -833,14 +836,14 @@ int setup_memory_ranges(unsigned long kexec_flags) + j++; + if (j >= max_memory_ranges) + realloc_memory_ranges(); +- /* Limit range to rmo_top */ +- if (memory_range[j-1].start >= rmo_top) { ++ /* Limit range to rma_top */ ++ if (memory_range[j-1].start >= rma_top) { + j--; + break; + } +- if ((memory_range[j-1].start < rmo_top) && +- (memory_range[j-1].end >= rmo_top)) { +- memory_range[j-1].end = rmo_top; ++ if ((memory_range[j-1].start < rma_top) && ++ (memory_range[j-1].end >= rma_top)) { ++ memory_range[j-1].end = rma_top; + break; + } + } +-- +2.7.4 + diff --git a/SOURCES/kexec-tools-2.0.15-ppc64-fix-leak-while-checking-for-cohere.patch b/SOURCES/kexec-tools-2.0.15-ppc64-fix-leak-while-checking-for-cohere.patch new file mode 100644 index 0000000..1f0387e --- /dev/null +++ b/SOURCES/kexec-tools-2.0.15-ppc64-fix-leak-while-checking-for-cohere.patch @@ -0,0 +1,28 @@ +From 69431282f075ab723c4886f20aa248976920aaae Mon Sep 17 00:00:00 2001 +From: Hari Bathini +Date: Tue, 29 Aug 2017 23:08:02 +0530 +Subject: [PATCH] kexec-tools: ppc64: fix leak while checking for coherent + device memory + +Signed-off-by: Hari Bathini +Signed-off-by: Simon Horman +Signed-off-by: Pingfan Liu +--- + kexec/arch/ppc64/crashdump-ppc64.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/kexec/arch/ppc64/crashdump-ppc64.c b/kexec/arch/ppc64/crashdump-ppc64.c +index 7ea3983..bc9f948 100644 +--- a/kexec/arch/ppc64/crashdump-ppc64.c ++++ b/kexec/arch/ppc64/crashdump-ppc64.c +@@ -217,6 +217,7 @@ static int is_coherent_device_mem(const char *fname) + break; + } + if (!strncmp(buf, "ibm,coherent-device-memory", 26)) { ++ fclose(file); + ret = 1; + break; + } +-- +2.7.4 + diff --git a/SOURCES/mkdumprd b/SOURCES/mkdumprd index f1150bc..719633d 100644 --- a/SOURCES/mkdumprd +++ b/SOURCES/mkdumprd @@ -81,12 +81,6 @@ add_dracut_sshkey() { # Generic substring function. If $2 is in $1, return 0. strstr() { [[ $1 =~ $2 ]]; } -target_is_root() { - local _t - _t=$(findmnt -k -n -r -o TARGET $1|sort|head -1) - [ "$_t" = "/" ] -} - # caller should ensure $1 is valid and mounted in 1st kernel to_mount() { local _dev=$1 _source _target _fstype _options _mntopts _pdev @@ -108,22 +102,10 @@ to_mount() { [ -z "$_options" ] && _options=$(findmnt -k -f -n -r -o OPTIONS $_dev) # with 'noauto' in fstab nfs and non-root disk mount will fail in 2nd # kernel, filter it out here. - _options=$(echo $_options | sed 's/noauto//') - _options=${_options/#ro/rw} #mount fs target as rw in 2nd kernel - # "x-initrd.mount" mount failure will trigger isolate emergency service - # W/o this, systemd won't isolate, thus we won't get to emergency. - # This is not applicable to remote fs mount, because if we use - # "x-initrd.mount", remote mount will become required by - # "initrd-root-fs.target", instead of "remote-fs.target". That's how it is - # handled within systemd internal. We need remote mount to be required - # "remote-fs.target", because we need to bring up network before any remote - # mount and "remote-fs.target" can be a checkpoint of that. - # If remote mount fails, dracut-initqueue will still start and once - # dracut-initqueue finishes, kdump service will start. Because remote mount - # failed, kdump service will fail and it will lead to kdump error handler. - if ! is_nfs_dump_target; then - _options="$_options,x-initrd.mount" - fi + _options=$(echo $_options | sed 's/\bnoauto\b//') + #mount fs target as rw in 2nd kernel + _options=$(echo $_options | sed 's/\bro\b/rw/') + _mntopts="$_target $_fstype $_options" #for non-nfs _dev converting to use udev persistent name if [ -b "$_source" ]; then @@ -248,13 +230,13 @@ verify_core_collector() { } add_mount() { - if ! target_is_root "$1"; then - local _mnt=$(to_mount "$1") - if [ $? -ne 0 ]; then - exit 1 - fi - add_dracut_mount "$_mnt" + local _mnt=$(to_mount "$1") + + if [ $? -ne 0 ]; then + exit 1 fi + + add_dracut_mount "$_mnt" } # get_maj_min @@ -314,25 +296,11 @@ check_block_and_slaves() { return 1 } -get_block_dump_target() -{ - local _target - - - _target=$(get_user_configured_dump_disk) - [ -n "$_target" ] && echo $(to_dev_name $_target) && return - - #get rootfs device name - _target=$(get_root_fs_device) - [ -b "$_target" ] && echo $(to_dev_name $_target) -} - #handle the case user does not specify the dump target explicitly handle_default_dump_target() { local _target local _mntpoint - local _fstype is_user_configured_dump_target && return @@ -351,25 +319,9 @@ handle_default_dump_target() SAVE_PATH=$_mntpoint/$SAVE_PATH fi - if [ "$_mntpoint" != "/" ]; then - SAVE_PATH=${SAVE_PATH##"$_mntpoint"} - _fstype=$(get_fs_type_from_target $_target) - - add_mount "$_target" - check_size fs $_target - fi -} - -get_default_action_target() -{ - local _target - local _action=$(grep "^default" /etc/kdump.conf 2>/dev/null | awk '{print $2}') - if [ -n "$_action" ] && [ "$_action" = "dump_to_rootfs" ]; then - #get rootfs device name - _target=$(findmnt -k -f -n -o SOURCE /) - [ -b "$_target" ] && echo $(to_dev_name $_target) - fi - return + SAVE_PATH=${SAVE_PATH##"$_mntpoint"} + add_mount "$_target" + check_size fs $_target } get_override_resettable() @@ -391,20 +343,11 @@ for_each_block_target() { local dev majmin - #check dump target - dev=$(get_block_dump_target) - - if [ -n "$dev" ]; then + for dev in $(get_kdump_targets); do + [ -b "$dev" ] || continue majmin=$(get_maj_min $dev) check_block_and_slaves $1 $majmin && return 1 - fi - - #check rootfs when default action dump_to_rootfs is set - dev=$(get_default_action_target) - if [ -n "$dev" ]; then - majmin=$(get_maj_min $dev) - check_block_and_slaves $1 $majmin && return 2 - fi + done return 0 } @@ -423,7 +366,7 @@ is_unresettable() resettable="$(cat $path)" [ $resettable -eq 0 -a "$OVERRIDE_RESETTABLE" -eq 0 ] && { local device=$(udevadm info --query=all --path=/sys/dev/block/$1 | awk -F= '/DEVNAME/{print $2}') - echo "Device $device is unresettable" + echo "Error: Can not save vmcore because device $device is unresettable" return 0 } fi @@ -444,14 +387,6 @@ check_resettable() [ $_ret -eq 0 ] && return - if [ $_ret -eq 1 ]; then - _target=$(get_block_dump_target) - perror "Can not save vmcore to target device $_target . This device can not be initialized in kdump kernel as it is not resettable" - elif [ $_ret -eq 2 ]; then - _target=$(get_default_action_target) - perror "Rootfs device $_target is not resettable, can not be used as the default target, please specify a default action" - fi - return 1 } @@ -572,6 +507,14 @@ then add_dracut_arg "--add-drivers" "$extra_modules" fi +if ! is_fadump_capable; then + # The 2nd rootfs mount stays behind the normal dump target mount, + # so it doesn't affect the logic of check_dump_fs_modified(). + is_dump_to_rootfs && add_mount "$(to_dev_name $(get_root_fs_device))" + + add_dracut_arg "--no-hostonly-default-device" +fi + dracut "${dracut_args[@]}" "$@" _rc=$? sync diff --git a/SPECS/kexec-tools.spec b/SPECS/kexec-tools.spec index 141f0b0..51cc126 100644 --- a/SPECS/kexec-tools.spec +++ b/SPECS/kexec-tools.spec @@ -1,6 +1,6 @@ Name: kexec-tools -Version: 2.0.14 -Release: 17.2%{?dist} +Version: 2.0.15 +Release: 13%{?dist} License: GPLv2 Group: Applications/System Summary: The kexec/kdump userspace component. @@ -8,12 +8,10 @@ Source0: http://kernel.org/pub/linux/utils/kernel/kexec/%{name}-%{version}.tar.x Source1: kdumpctl Source2: kdump.sysconfig Source3: kdump.sysconfig.x86_64 -Source4: kdump.sysconfig.i386 Source5: kdump.sysconfig.ppc64 -Source6: kdump.sysconfig.ia64 Source7: mkdumprd Source8: kdump.conf -Source9: http://downloads.sourceforge.net/project/makedumpfile/makedumpfile/1.6.1/makedumpfile-1.6.1.tar.gz +Source9: http://downloads.sourceforge.net/project/makedumpfile/makedumpfile/1.6.2/makedumpfile-1.6.2.tar.gz Source10: kexec-kdump-howto.txt Source11: fadump-howto.txt Source12: mkdumprd.8 @@ -49,8 +47,8 @@ Requires(post): systemd-units Requires(preun): systemd-units Requires(postun): systemd-units Requires(pre): coreutils sed zlib -Requires: dracut >= 033-449 -Requires: dracut-network >= 033-449 +Requires: dracut >= 033-522 +Requires: dracut-network >= 033-522 Requires: ethtool BuildRequires: zlib-devel zlib zlib-static elfutils-devel-static glib2-devel bzip2-devel ncurses-devel bison flex lzo-devel snappy-devel BuildRequires: pkgconfig intltool gettext @@ -68,18 +66,20 @@ Obsoletes: diskdumputils netdump # # Patches 101 through 200 are meant for x86_64 kexec-tools enablement +Patch101: kexec-tools-2.0.15-makedumpfile-x86_64-Take-care-of-init_level4_pgt-rename-.patch # -Patch101: kexec-tools-2.0.14-x86-Support-large-number-of-memory-ranges.patch - # # Patches 201 through 300 are meant for ia64 kexec-tools enablement # - # # Patches 301 through 400 are meant for ppc64 kexec-tools enablement # -Patch301: kexec-tools-2.0.14-ppc64-Reduce-number-of-ELF-LOAD-segments.patch -Patch302: kexec-tools-2.0.14-kexec-powerpc-fix-command-line-overflow-error.patch +Patch301: kexec-tools-2.0.15-ppc64-fix-how-RMA-top-is-deduced.patch +Patch302: kexec-tools-2.0.15-ppc64-fix-command-line-overflow-error.patch +Patch303: kexec-tools-2.0.15-ppc64-avoid-adding-coherent-memory-regio.patch +Patch304: kexec-tools-2.0.15-ppc64-fix-leak-while-checking-for-cohere.patch +Patch305: kexec-tools-2.0.15-makedumpfile-ppc64-get-the-info-of-mem-reserved-for-.patch +Patch306: kexec-tools-2.0.15-makedumpfile-ppc64-set-page_offset-in-get_versiondep.patch # # Patches 401 through 500 are meant for s390 kexec-tools enablement @@ -91,32 +91,22 @@ Patch302: kexec-tools-2.0.14-kexec-powerpc-fix-command-line-overflow-error.patch # # Patches 601 through 700 are meant for arm64 kexec-tools enablement # -Patch601: kexec-tools-2.0.14-Only-print-debug-message-when-failed-to-serach-for-k.patch -Patch602: kexec-tools-2.0.14-kexec-exntend-the-semantics-of-kexec_iomem_for_each_.patch -Patch603: kexec-tools-2.0.14-kexec-generalize-and-rename-get_kernel_stext_sym.patch -Patch604: kexec-tools-2.0.14-arm64-identify-PHYS_OFFSET-correctly.patch -Patch605: kexec-tools-2.0.14-arm64-kdump-identify-memory-regions.patch -Patch606: kexec-tools-2.0.14-arm64-kdump-add-elf-core-header-segment.patch -Patch607: kexec-tools-2.0.14-arm64-kdump-set-up-kernel-image-segment.patch -Patch608: kexec-tools-2.0.14-arm64-kdump-set-up-other-segments.patch -Patch609: kexec-tools-2.0.14-arm64-kdump-add-DT-properties-to-crash-dump-kernel-s.patch -Patch610: kexec-tools-2.0.14-arm64-kdump-Add-support-for-binary-image-files.patch -Patch611: kexec-tools-2.0.14-kexec-Increase-the-upper-limit-for-RAM-segments.patch - # # Patches 701 onward are generic patches # Patch701: kexec-tools-2.0.3-disable-kexec-test.patch -Patch702: kexec-tools-2.0.14-build_mem_phdrs-check-if-p_paddr-is-invalid.patch -Patch703: kexec-tools-2.0.14-makedumpfile-show_mem_usage-calculate-page-offset-af.patch -Patch704: kexec-tools-2.0.14-makedumpfile-initial-call-cache_init-a-bit-early.patch -Patch705: kexec-tools-2.0.14-makedumpfile-x86_64-check-physical-address-in-PT_LOA.patch -Patch706: kexec-tools-2.0.14-makedumpfile-elf_info-kcore-check-for-invalid-physic.patch -Patch707: kexec-tools-2.0.14-makedumpfile-makedumpfile-Correct-the-calculation-of.patch -Patch708: kexec-tools-2.0.14-makedumpfile-makedumpfile-Discard-process_dump_load.patch -Patch709: kexec-tools-2.0.14-makedumpfile-makedumpfile-add-runtime-kaslr-offset-if-it-exists.patch -Patch710: kexec-tools-2.0.14-makedumpfile-sadump-set-info-page_size-before-cache_init.patch -Patch711: kexec-tools-2.0.14-makedumpfile-x86_64-calculate-page_offset-in-case-of-re-filtering.patch +Patch702: kexec-tools-2.0.15-makedumpfile-Fix-SECTION_MAP_MASK-for-kernel-v.13.patch +Patch703: kexec-tools-2.0.15-makedumpfile-Support-symbol-__cpu_online_mask.patch +Patch704: kexec-tools-2.0.15-makedumpfile-Introduce-vtop4_x86_64_pagetable.patch +Patch705: kexec-tools-2.0.15-makedumpfile-sadump-Fix-a-KASLR-problem-of-sadump.patch +Patch706: kexec-tools-2.0.15-makedumpfile-sadump-Fix-a-KASLR-problem-of-sadump-wh.patch +Patch707: kexec-tools-2.0.15-makedumpfile-book3s-ppc64-Lower-the-max-real-address-to-53-bits.patch +Patch708: kexec-tools-2.0.15-makedumpfile-Fix-kernel_version-variable-being-uninitia.patch +Patch709: kexec-tools-2.0.15-makedumpfile-Fix-off-by-one-errors-in-exclude_segment.patch +Patch710: kexec-tools-2.0.15-makedumpfile-Fix-physical-to-virtual-conversion-in-excl.patch +Patch711: kexec-tools-2.0.15-makedumpfile-sadump-Fix-a-problem-of-PTI-enabled-kernel.patch +Patch712: kexec-tools-2.0.15-makedumpfile-PATCH-Support-newer-kernels.patch + # # Patch 701 through 800 are meant for kdump anaconda addon @@ -159,17 +149,10 @@ tar -z -x -v -f %{SOURCE25} %patch101 -p1 %patch301 -p1 %patch302 -p1 -%patch601 -p1 -%patch602 -p1 -%patch603 -p1 -%patch604 -p1 -%patch605 -p1 -%patch606 -p1 -%patch607 -p1 -%patch608 -p1 -%patch609 -p1 -%patch610 -p1 -%patch611 -p1 +%patch303 -p1 +%patch304 -p1 +%patch305 -p1 +%patch306 -p1 %patch701 -p1 %patch702 -p1 %patch703 -p1 @@ -181,6 +164,7 @@ tar -z -x -v -f %{SOURCE25} %patch709 -p1 %patch710 -p1 %patch711 -p1 +%patch712 -p1 %ifarch ppc @@ -218,8 +202,8 @@ cp %{SOURCE22} . make %ifarch %{ix86} x86_64 ia64 ppc64 s390x ppc64le aarch64 make -C eppic/libeppic -make -C makedumpfile-1.6.1 LINKTYPE=dynamic USELZO=on USESNAPPY=on -make -C makedumpfile-1.6.1 LDFLAGS="-I../eppic/libeppic -L../eppic/libeppic" eppic_makedumpfile.so +make -C makedumpfile-1.6.2 LINKTYPE=dynamic USELZO=on USESNAPPY=on +make -C makedumpfile-1.6.2 LDFLAGS="-I../eppic/libeppic -L../eppic/libeppic" eppic_makedumpfile.so %endif make -C kdump-anaconda-addon/po @@ -260,13 +244,13 @@ install -m 644 %{SOURCE16} $RPM_BUILD_ROOT%{_unitdir}/kdump.service install -m 755 -D %{SOURCE23} $RPM_BUILD_ROOT%{_prefix}/lib/systemd/system-generators/kdump-dep-generator.sh %ifarch %{ix86} x86_64 ia64 ppc64 s390x ppc64le aarch64 -install -m 755 makedumpfile-1.6.1/makedumpfile $RPM_BUILD_ROOT/sbin/makedumpfile -install -m 644 makedumpfile-1.6.1/makedumpfile.8.gz $RPM_BUILD_ROOT/%{_mandir}/man8/makedumpfile.8.gz -install -m 644 makedumpfile-1.6.1/makedumpfile.conf.5.gz $RPM_BUILD_ROOT/%{_mandir}/man5/makedumpfile.conf.5.gz -install -m 644 makedumpfile-1.6.1/makedumpfile.conf $RPM_BUILD_ROOT/%{_sysconfdir}/makedumpfile.conf.sample -install -m 755 makedumpfile-1.6.1/eppic_makedumpfile.so $RPM_BUILD_ROOT/%{_libdir}/eppic_makedumpfile.so +install -m 755 makedumpfile-1.6.2/makedumpfile $RPM_BUILD_ROOT/sbin/makedumpfile +install -m 644 makedumpfile-1.6.2/makedumpfile.8.gz $RPM_BUILD_ROOT/%{_mandir}/man8/makedumpfile.8.gz +install -m 644 makedumpfile-1.6.2/makedumpfile.conf.5.gz $RPM_BUILD_ROOT/%{_mandir}/man5/makedumpfile.conf.5.gz +install -m 644 makedumpfile-1.6.2/makedumpfile.conf $RPM_BUILD_ROOT/%{_sysconfdir}/makedumpfile.conf.sample +install -m 755 makedumpfile-1.6.2/eppic_makedumpfile.so $RPM_BUILD_ROOT/%{_libdir}/eppic_makedumpfile.so mkdir -p $RPM_BUILD_ROOT/usr/share/makedumpfile/eppic_scripts/ -install -m 644 makedumpfile-1.6.1/eppic_scripts/* $RPM_BUILD_ROOT/usr/share/makedumpfile/eppic_scripts/ +install -m 644 makedumpfile-1.6.2/eppic_scripts/* $RPM_BUILD_ROOT/usr/share/makedumpfile/eppic_scripts/ %endif make -C kdump-anaconda-addon install DESTDIR=$RPM_BUILD_ROOT %find_lang kdump-anaconda-addon @@ -406,11 +390,78 @@ done %doc %changelog -* Tue Sep 26 2017 Baoquan He 2.0.14-17.2 -- tools: powerpc: fix command line overflow error +* Thu Feb 8 2018 Pingfan Liu 2.0.15-13 + +* Thu Feb 1 2018 Pingfan Liu 2.0.15-12 +- makedumpfile/sadump: Fix a problem of PTI enabled kernel +- makedumpfile: Fix physical-to-virtual conversion in 'exclude_segment()' + +* Tue Dec 12 2017 Pingfan Liu 2.0.15-11 +- dracut-module-setup.sh: temporary install /bin/grep to work around dracut's bug +- kdump.sysconfig/x86_64: Add nokaslr to kdump kernel cmdline +- kdumpctl: skip selinux-relabel for dracut_args --mount dump target + +* Mon Dec 11 2017 Pingfan Liu 2.0.15-10 +- kexec-tools.spec: require dracut >= 033-522 to make 99kdump module installed correctly +- kdump.sysconfig.ppc64(le): remove "root=" param from ppc64(le) 2nd kernel's command line +- Revert "kdumpctl: sanity check of nr_cpus for x86_64 in case running out of vectors" + +* Wed Nov 29 2017 Pingfan Liu 2.0.15-9 +- makedumpfile: Fix 'kernel_version' variable being uninitialized & introduce minor reorganization +- makedumpfile: Fix segmentation fault when using --split on a vmcore +- dracut-module-setup.sh: check whether to include multipath-hostonly or not + +* Tue Nov 14 2017 Pingfan Liu 2.0.15-8 +- kdumpctl: Error out in case there are white spaces before an option name + +* Mon Nov 13 2017 Pingfan Liu 2.0.15-7 +- mkdumprd: apply dracut "--hostonly-cmdline" and "--no-hostonly-default-device" +- Change dump_to_rootfs to use "--mount" instead of "root=X" +- kdumpctl: move is_fadump_capable() to kdump-lib.sh +- module-setup: fix 99kdumpbase network dependency +- mkdumprd: change for_each_block_target() to use get_kdump_targets() +- kdump-lib.sh: introduce get_kdump_targets() +- kdump-lib.sh: fix improper get_block_dump_target() +- kdumpctl: remove "root=X" for kdump boot +- kdumpctl: fix a bug in remove_cmdline_param() + +* Fri Nov 10 2017 Pingfan Liu 2.0.15-6 +- Fix KASLR problem on sadump + +* Wed Nov 8 2017 Pingfan Liu 2.0.15-5 +- Revert "Update kdump anaconda addon" +- Revert "Update kdump anaconda addon: fix the md5sum in source file" + +* Fri Nov 3 2017 Pingfan Liu 2.0.15-4 +- Update kdump anaconda addon: fix the md5sum in source file +- Update kdump anaconda addon -* Fri Sep 15 2017 Pingfan Liu - 2.0.14-17.1 -- fadump: rebuild default initrd with dump capture capability +* Fri Nov 3 2017 Pingfan Liu 2.0.15-3 +- makedumpfile: x86_64: Take care of init_level4_pgt rename in kernel +- makedumpfile: ppc64: get the info of mem reserved for crashkernel +- makedumpfile: Fix SECTION_MAP_MASK for kernel >= v.13 + +* Wed Oct 25 2017 Pingfan Liu 2.0.15-2 +- mkdumprd: fix patterns to modify mount options +- kexec-tools/ppc64: avoid adding coherent memory regions to crash memory ranges +- kexec-tools/ppc64: fix command line overflow error +- kexec-tools/ppc64: fix how RMA top is deduced + +* Wed Sep 27 2017 Baoquan He - 2.0.15-1 +- kexec-tools: Rebase from 2.0.14 to 2.0.15 + +* Thu Sep 14 2017 Pingfan Liu - 2.0.14-19 +makedumpfile: rebase makedumpfile from 1.6.1 to 1.6.2 + +* Fri Aug 25 2017 Pingfan Liu - 2.0.14-18 +mkdumprd: remove useless "x-initrd.mount" +kdumpctl: use "apicid" other than "initial apicid" +kdumpctl: sanity check of nr_cpus for x86_64 in case running out of vectors +kdumpctl: change prepare_cmdline() to operate KDUMP_COMMANDLINE directly +mkdumprd: use 300s as the default systemd unit timeout for kdump mount +mkdumprd: reduce lvm2 memory under kdump +module-setup: suppress the early iscsi error messages +kdumpctl: fix infinite loop caused by running under bash * Tue Jun 27 2017 Pingfan Liu - 2.0.14-17 - revert udev rule changes