kdumpctl: Pass disable_cpu_apicid to kexec of capture kernel

== Version 2 ==

Addresses Vivek's review comments:

1. Don't force numeric in awk script snipet.

2. Command line processing is moved from load_kernel to new function
   "prepare_cmdline."   This new function is responsible for
   setting up the command line passed to KEXEC.

3. New function "append_cmdline" is added to append {argument,value}
   pair to command line if argument is not already present.

== Version 1 ==

A recent patch (https://lkml.org/lkml/2014/1/15/42) enables multiple
processors in the crash kernel.

To do this safely the crash kernel needs to know which CPU was the 1st
kernel BSP (bootstrap processor) so that the crash kernel will NOT send
the BSP an INIT.  If the crash kernel sends an INIT to the 1st kernel
BSP, some systems may reset or hang.

The EFI spec doesn't require that any particular processor is chosen
as the BSP and the CPU (and its apic id) can change from one boot to
the next.  Hence automating the selection of CPU to disable if the
system would panic is desired.

This patch updates the kdumpctl script to get the "initial apicid"
of CPU 0 in the first kernel and will pass this as the
"disable_cpu_apicid=" arguement to kexec if it wasn't explicitly
set in /etc/sysconfig/kdump KDUMP_COMMANDLINE_APPEND.

CPU 0 is chosen as it is the processor thats execute the OS
initialization
code and hence was the BSP as per x86 SDM (Vol 3a Section 8.4.)

See associated Red Hat Bugzilla(s) for additional background material:

        https://bugzilla.redhat.com/show_bug.cgi?id=1059031
        https://bugzilla.redhat.com/show_bug.cgi?id=980621

Signed-off-by: Jerry Hoemann <jerry.hoemann@hp.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
This commit is contained in:
Jerry Hoemann 2014-02-20 18:09:30 -07:00 committed by WANG Chao
parent 906dc0bca0
commit 428a5e99ee

View File

@ -41,6 +41,59 @@ function remove_cmdline_param()
echo $cmdline
}
#
# This function returns the "initial apicid" of the
# boot cpu (cpu 0) if present.
#
function get_bootcpu_initial_apicid()
{
awk ' \
BEGIN { CPU = "-1"; } \
$1=="processor" && $2==":" { CPU = $NF; } \
CPU=="0" && /initial apicid/ { print $NF; } \
' \
/proc/cpuinfo
}
#
# This function appends argument "$2=$3" to string ($1) if not already present.
#
function append_cmdline()
{
local cmdline=$1
local newstr=${cmdline/$2/""}
# unchanged str implies argument wasn't there
if [ "$cmdline" == "$newstr" ]; then
cmdline="${cmdline} ${2}=${3}"
fi
echo $cmdline
}
# This function performs a series of edits on the command line
function prepare_cmdline()
{
local cmdline;
if [ -z "$KDUMP_COMMANDLINE" ]; then
cmdline=`cat /proc/cmdline`
else
cmdline=${KDUMP_COMMANDLINE}
fi
cmdline=`remove_cmdline_param "$cmdline" crashkernel hugepages hugepagesz`
cmdline="${cmdline} ${KDUMP_COMMANDLINE_APPEND}"
local id=`get_bootcpu_initial_apicid`
if [ ! -z ${id} ] ; then
cmdline=`append_cmdline "${cmdline}" disable_cpu_apicid ${id}`
fi
echo $cmdline
}
function save_core()
{
coredir="/var/crash/`date +"%Y-%m-%d-%H:%M"`"
@ -270,13 +323,7 @@ function load_kdump()
fi
fi
if [ -z "$KDUMP_COMMANDLINE" ]
then
KDUMP_COMMANDLINE=`cat /proc/cmdline`
fi
KDUMP_COMMANDLINE=`remove_cmdline_param "$KDUMP_COMMANDLINE" crashkernel hugepages hugepagesz`
KDUMP_COMMANDLINE="${KDUMP_COMMANDLINE} ${KDUMP_COMMANDLINE_APPEND}"
KDUMP_COMMANDLINE=`prepare_cmdline`
$KEXEC $KEXEC_ARGS $standard_kexec_args \
--command-line="$KDUMP_COMMANDLINE" \