crash-add-kunit-tests-for-crash_exclude_mem_range.patch removed from -mm tree
The quilt patch titled
Subject: crash: add KUnit tests for crash_exclude_mem_range
has been removed from the -mm tree. Its filename was
crash-add-kunit-tests-for-crash_exclude_mem_range.patch
This patch was dropped because it was merged into the mm-nonmm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Coiby Xu <[email protected]>
Subject: crash: add KUnit tests for crash_exclude_mem_range
Date: Thu, 4 Sep 2025 17:38:53 +0800
crash_exclude_mem_range seems to be a simple function but there have been multiple attempts to fix it,
- commit a2e9a95d2190 ("kexec: Improve & fix crash_exclude_mem_range() to handle overlapping ranges")
- commit 6dff31597264 ("crash_core: fix and simplify the logic of crash_exclude_mem_range()")
So add a set of unit tests to verify the correctness of current implementation. Shall we change the function in the future, the unit tests can also help prevent any regression. For example, we may make the function smarter by allocating extra crash_mem range on demand thus there is no need for the caller to foresee any memory range split or address -ENOMEM failure.
The testing strategy is to verify the correctness of base case. The base case is there is one to-be-excluded range A and one existing range B. Then we can exhaust all possibilities of the position of A regarding B. For example, here are two combinations,
Case: A is completely inside B (causes split)
Original: [----B----]
Exclude: {--A--}
Result: [B1] .. [B2]
Case: A overlaps B's left part
Original: [----B----]
Exclude: {---A---}
Result: [..B..]In theory we can prove the correctness by induction,
- Base case: crash_exclude_mem_range is correct in the case where n=1 (n is the number of existing ranges).
- Inductive step: If crash_exclude_mem_range is correct for n=k existing ranges, then the it's also correct for n=k+1 ranges.
But for the sake of simplicity, simply use unit tests to cover the base case together with two regression tests.
Note most of the exclude_single_range_test() code is generated by Google Gemini with some small tweaks. The function specification, function body and the exhausting test strategy are presented as prompts.
---
kernel/Kconfig.kexec | 11 + kernel/Makefile | 1 kernel/crash_core.c | 15 + kernel/crash_core_test.c | 343 +++++++++++++++++++++++++++++++++++++ 4 files changed, 370 insertions(+)
kernel/crash_core.c renamed from kernel/crash_core.c~crash-add-kunit-tests-for-crash_exclude_mem_range +15 -0
@@ -265,6 +265,20 @@ int crash_prepare_elf64_headers(struct creturn 0 ; } +/** +* crash_exclude_mem_range - exclude a mem range for existing ranges +* @mem: mem->range contains an array of ranges sorted in ascending order +* @mstart: the start of to-be-excluded range +* @mend: the start of to-be-excluded range +* +* If you are unsure if a range split will happen, to avoid function call +* failure because of -ENOMEM, always make sure +* mem->max_nr_ranges == mem->nr_ranges + 1 +* before calling the function each time. +* +* returns 0 if a memory range is excluded successfully +* return -ENOMEM if mem->ranges doesn't have space to hold split ranges +*/ int crash_exclude_mem_range (struct crash_mem *mem,unsigned long long mstart,unsigned long long mend) {
@@ -324,6 +338,7 @@ int crash_exclude_mem_range(struct crashreturn 0 ; } +EXPORT_SYMBOL_GPL (crash_exclude_mem_range);ssize_t crash_get_memory_size (void ) {
kernel/crash_core_test.c new file +343 -0
343 lines not on this page · raw message
kernel/Kconfig.kexec renamed from kernel/Kconfig.kexec~crash-add-kunit-tests-for-crash_exclude_mem_range +11 -0
@@ -148,6 +148,17 @@ config CRASH_DM_CRYPT_CONFIGS CRASH_DM_CRYPT cannot directly select CONFIGFS_FS, because that is required to be built-in. +config CRASH_DUMP_KUNIT_TEST + tristate "Unit Tests for kernel crash dumps" if !KUNIT_ALL_TESTS + depends on CRASH_DUMP && KUNIT + default KUNIT_ALL_TESTS + help + This option builds KUnit unit tests for kernel crash dumps. The unit + tests will be used to verify the correctness of covered functions and + also prevent any regression. + + If unsure, say N. + config CRASH_HOTPLUG bool "Update the crash elfcorehdr on system configuration changes" default y
kernel/Makefile renamed from kernel/Makefile~crash-add-kunit-tests-for-crash_exclude_mem_range +1 -0
@@ -78,6 +78,7 @@ obj-$(CONFIG_CRASH_RESERVE) += crash_res obj-$(CONFIG_KEXEC_CORE) += kexec_core.o obj-$(CONFIG_CRASH_DUMP) += crash_core.o obj-$(CONFIG_CRASH_DM_CRYPT) += crash_dump_dm_crypt.o +obj-$(CONFIG_CRASH_DUMP_KUNIT_TEST) += crash_core_test.o obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_KEXEC_FILE) += kexec_file.o obj-$(CONFIG_KEXEC_ELF) += kexec_elf.o
_
Patches currently in -mm which might be from [email protected] are