From 63345d21a7bab5908211a3c8aa5d1c408db86a17 Mon Sep 17 00:00:00 2001 From: "Guilherme G. Piccoli" Date: Sat, 23 Dec 2023 12:03:00 -0500 Subject: [PATCH] kdumpst-load/config: Add option to use crashkernel as pstore/ram memory Currently kdumpst only allows a proper RAM buffer to be used as ramoops memory area - this is the proper way of doing that, but there are cases in which it's not trivial to have these buffers available: (a) In case it's not there by default (due to kernel alignment / device-tree) for example, there is no easy parameter to reserve such area right now (using mem= is the way to go, but a bit complex to gather the exact size). (b) The kernel parameter crashkernel= does something like this: reserve a piece of memory not to be used by the kernel. It's meant for kdump, but can be (ab)used for other purposes. So, we hereby add a way for kdumpst to make use of crash reserved area if the users wish so; the risks are exposed in the config file text. Also, since we're changing this code, take the opportunity to improve the sanitization of addresses from /proc/iomem and fix a corner case of empty RANGE in the iomem parsing routine. Signed-off-by: Guilherme G. Piccoli --- 00-default.conf | 6 ++++++ kdumpst-load.sh.in | 14 +++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/00-default.conf b/00-default.conf index f7cca48..e810495 100644 --- a/00-default.conf +++ b/00-default.conf @@ -16,9 +16,15 @@ # relies in having an available RAM buffer on /proc/iomem with at least # PSTORE_MEM_AMOUNT (decimal, in MB) in size. Also, kernel must be able to # allocate a contiguous memory amount of PSTORE_RECORD_SZ (decimal, MB). +# If there is no such RAM buffer, there is a possibility to make use of +# the crash kernel area for that. There are risks: such memory area could +# have its address mapped differently across kernel updates; also if both +# pstore and the kdump kernel are loaded, that memory region will be for +# sure corrupted by the kexec panic load - so, kind of a last resource. USE_PSTORE_RAM=1 PSTORE_MEM_AMOUNT=4194304 PSTORE_RECORD_SZ=1048576 +PSTORE_RAM_USE_CRASH_MEM=0 # # # Mount-related options diff --git a/kdumpst-load.sh.in b/kdumpst-load.sh.in index cec33c6..c28b925 100644 --- a/kdumpst-load.sh.in +++ b/kdumpst-load.sh.in @@ -77,10 +77,14 @@ clear_all_initrds() { # Next routine parses /proc/iomem to obtain the biggest RAM buffer # available. Saves the results in 2 global variables: MEM_{SIZE,START}. parse_ram_buffers() { - BUFFERS="$(grep "RAM buffer" /proc/iomem)" + BUFFERS="$(grep "$1" /proc/iomem)" while read -r line do - RANGE=$(echo "$line" | cut -f1 -d\ ) + RANGE=$(echo "$line" | sed 's/^[[:space:]]*//g' | cut -f1 -d:) + + if [ "${RANGE}" == '' ]; then + continue + fi MEM_END=$(echo "$RANGE" | cut -f2 -d-) MSTART=$(echo "$RANGE" | cut -f1 -d-) @@ -155,7 +159,11 @@ if [ "${USE_PSTORE_RAM}" -eq 1 ]; then RECORD_SIZE="${PSTORE_RECORD_SZ}" MEM_SIZE=0 - parse_ram_buffers + parse_ram_buffers "RAM buffer" + + if [ "${MEM_SIZE}" -eq 0 ] && [ "${PSTORE_RAM_USE_CRASH_MEM}" -eq 1 ]; then + parse_ram_buffers "Crash kernel" + fi if [ "${MEM_SIZE}" -gt 0 ]; then if modprobe ramoops mem_address=0x"${MEM_START}" mem_size="${MEM_REQUIRED}" record_size="${RECORD_SIZE}"; then