[PATCH 1/2] kexec: Print crash kernel reserved size from sysfs
"Rui Qi" <[email protected]>
| Newsgroups | org.infradead.lists.kexec,org.infradead.lists.linux-riscv |
|---|---|
| Message-ID | <[email protected]> |
The --print-ckr-size option was added as a user-visible way for kdump scripts to obtain the crash kernel reserved size. Its original contract is to print the same value and unit as the kernel kexec_crash_size sysfs attribute when Linux exports that attribute. The current implementation derives the value from get_crash_kernel_load_range(), but that helper describes where crash kernel segments may be loaded. That is not the same as the total crash kernel reservation. The two meanings differ on systems with split crash kernel reservations. A low reservation may be available to the crash kernel after boot while the crash image itself must still be loaded into the main/high reservation. Linux reports the total reserved crash kernel size through /sys/kernel/kexec_crash_size, including split reservations. Prefer /sys/kernel/kexec_crash_size when available so --print-ckr-size follows its original sysfs-aligned semantics. Keep the existing load-range calculation as a fallback for older kernels. Signed-off-by: Rui Qi <[email protected]> --- kexec/kexec.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/kexec/kexec.c b/kexec/kexec.c index 58cab57a3ee3..99ec3ff3c373 100644 --- a/kexec/kexec.c +++ b/kexec/kexec.c @@ -60,6 +60,7 @@ #define KEXEC_LOADED_PATH "/sys/kernel/kexec_loaded" #define KEXEC_CRASH_LOADED_PATH "/sys/kernel/kexec_crash_loaded" +#define KEXEC_CRASH_SIZE_PATH "/sys/kernel/kexec_crash_size" unsigned long long mem_min = 0; unsigned long long mem_max = ULONG_MAX; @@ -1495,14 +1496,30 @@ static inline unsigned long get_hotplug_kexec_flag(void) static void print_crashkernel_region_size(void) { uint64_t start = 0, end = 0; + uint64_t size = 0; + FILE *fp; - if (is_crashkernel_mem_reserved() && - get_crash_kernel_load_range(&start, &end)) { - fprintf(stderr, "get_crash_kernel_load_range() failed.\n"); - return; + fp = fopen(KEXEC_CRASH_SIZE_PATH, "r"); + if (fp) { + if (fscanf(fp, "%" SCNu64, &size) == 1) { + fclose(fp); + printf("%" PRIu64 "\n", size); + return; + } + fclose(fp); + } + + if (is_crashkernel_mem_reserved()) { + if (get_crash_kernel_load_range(&start, &end)) { + fprintf(stderr, "get_crash_kernel_load_range() failed.\n"); + return; + } + + if (start != end) + size = end - start + 1; } - printf("%" PRIu64 "\n", (start != end) ? (end - start + 1) : 0UL); + printf("%" PRIu64 "\n", size); } int main(int argc, char *argv[]) -- 2.52.0