crash: keep crashkernel CMA pages reserved if activation fails
Subsystems (5)
PATCH 1/1 crash: keep crashkernel CMA pages reserved if activation fails
reserve_crashkernel_cma() adds each crashkernel CMA area to crashk_cma_ranges[] as soon as it is declared. If the area later fails activation, e.g. because movablecore= put the ZONE_MOVABLE boundary inside it, cma_activate_area() releases the pages to the buddy allocator as ordinary memory. The range is still handed to the crash kernel and excluded from the vmcore, so kernel data that lands there is overwritten by the crash kernel and missing from the dump.
Mark the areas with cma_reserve_pages_on_error(), so that a failed activation leaves the pages reserved: lost to the first kernel, but safe for the crash kernel to use.
--- kernel/crash_reserve.c | 1 + 1 file changed, 1 insertion(+)
kernel/crash_reserve.c +1 -0
@@ -498,6 +498,7 @@ void __init reserve_crashkernel_cma(unsigned long long cma_size)continue ; } +cma_reserve_pages_on_error (res); crashk_cma_ranges[crashk_cma_cnt].start =cma_get_base (res); crashk_cma_ranges[crashk_cma_cnt].end = crashk_cma_ranges[crashk_cma_cnt].start +
Signature · 1 line
2.53.0-Meta
Quoted 23 lines · Usama Arif
reserve_crashkernel_cma()adds each crashkernel CMA area to crashk_cma_ranges[] as soon as it is declared. If the area later fails activation, e.g. because movablecore= put theZONE_MOVABLEboundary inside it,cma_activate_area()releases the pages to the buddy allocator as ordinary memory. The range is still handed to the crash kernel and excluded from the vmcore, so kernel data that lands there is overwritten by the crash kernel and missing from the dump.Mark the areas with
cma_reserve_pages_on_error(), so that a failed activation leaves the pages reserved: lost to the first kernel, but safe for the crash kernel to use.Fixes ab475510e042 ("kdump: implement reserve_crashkernel_cma")Signed-off-by Usama Arif <[email protected]>---
kernel/crash_reserve.c| 1 +1 file changed, 1 insertion(+)kernel/crash_reserve.c +0
-0
kernel/crash_reserve.c void __init reserve_crashkernel_cma(unsigned long long cma_size) · line 501
Quoted 4 lines
kernel/crash_reserve.c +1
-0@@ -498,6 +498,7 @@ void __init reserve_crashkernel_cma(unsigned long long cma_size)continue ; } +cma_reserve_pages_on_error (res);
You do know that this will activate under every bitmap_zalloc() failure, right? Is that accounted for?
kernel/crash_reserve.c void __init reserve_crashkernel_cma(unsigned long long cma_size) · line 504
Quoted 4 lines
kernel/crash_reserve.c +0
-0crashk_cma_ranges[crashk_cma_cnt].start =cma_get_base (res); crashk_cma_ranges[crashk_cma_cnt].end = crashk_cma_ranges[crashk_cma_cnt].start +
--- Thanks!
Re: [PATCH] crash: keep crashkernel C MA pages reserved if activation fails
Quoted 27 lines · On Wed, 04 Nov 2026 19:16:42 +0000 Bradley Morgan <[email protected]> wrote:
Quoted 26 lines · Usama Arif
reserve_crashkernel_cma()adds each crashkernel CMA area to crashk_cma_ranges[] as soon as it is declared. If the area later fails activation, e.g. because movablecore= put theZONE_MOVABLEboundary inside it,cma_activate_area()releases the pages to the buddy allocator as ordinary memory. The range is still handed to the crash kernel and excluded from the vmcore, so kernel data that lands there is overwritten by the crash kernel and missing from the dump.Mark the areas with
cma_reserve_pages_on_error(), so that a failed activation leaves the pages reserved: lost to the first kernel, but safe for the crash kernel to use.Fixes ab475510e042 ("kdump: implement reserve_crashkernel_cma")Signed-off-by Usama Arif <[email protected]>---
kernel/crash_reserve.c| 1 +1 file changed, 1 insertion(+)kernel/crash_reserve.c +0
-0@@ -498,6 +498,7 @@ void __init reserve_crashkernel_cma(unsigned long long cma_size)continue ; }
Quoted 4 lines
kernel/crash_reserve.c void __init reserve_crashkernel_cma(unsigned long long cma_size) · line 501
Quoted 1 line
kernel/crash_reserve.c +1
-0+cma_reserve_pages_on_error (res);You do know that this will activate under every
bitmap_zalloc()failure, right? Is that accounted for?
Yes, that's intended. By the time cma_activate_area() runs, the range is already in crashk_cma_ranges[], so the crash kernel will use it no matter why activation failed. Keeping the pages reserved is the only way to make sure the first kernel has nothing there that gets overwritten or goes missing from the vmcore; the area then behaves like a regular crashkernel= reservation of the same size.
fadump made the same choice; it is what cma_reserve_pages_on_error() was added for in commit 27d121d0ec6d ("mm/cma: provide option to opt out from exposing pages on activation failure").
The bitmap is one bit per page (32 KiB per GiB with 4K pages) and is allocated at core_initcall, so a failure there is very unlikely.
The alternative is to give the memory back and to drop the range from crashk_cma_ranges[] when activation fails, leaving the crash kernel with less memory than requested. I do think that is acceptable as well. But we do need either whats done in this patch or give the memory back. Happy to send the alternative as v2 is everyone thinks that the better way forward.
Quoted 8 lines
kernel/crash_reserve.c void __init reserve_crashkernel_cma(unsigned long long cma_size) · line 504
Quoted 5 lines
kernel/crash_reserve.c +0
-0crashk_cma_ranges[crashk_cma_cnt].start =cma_get_base (res); crashk_cma_ranges[crashk_cma_cnt].end = crashk_cma_ranges[crashk_cma_cnt].start +--- Thanks!
Re: [PATCH] crash: keep crashkernel C MA pages reserved if activation fails
Quoted 54 lines · Usama Arif
Quoted 1 line · On Wed, 04 Nov 2026 19:16:42 +0000 Bradley Morgan <[email protected]> wrote:
On 4 November 2026 14:56:00 GMT, Usama Arif <[email protected]>
Quoted 4 lines · wrote:
Quoted 4 lines
reserve_crashkernel_cma()adds each crashkernel CMA area to crashk_cma_ranges[] as soon as it is declared. If the area later fails activation, e.g. because movablecore= put theZONE_MOVABLEboundary inside it,cma_activate_area()releases the pages to the buddyallocator
Quoted 2 lines
Quoted 2 lines
as ordinary memory. The range is still handed to the crash kernel and excluded from the vmcore, so kernel data that lands there is
overwritten
Quoted 4 lines
Quoted 4 lines
by the crash kernel and missing from the dump.
Mark the areas with
cma_reserve_pages_on_error(), so that a failed activation leaves the pages reserved: lost to the first kernel, butsafe
Quoted 8 lines
Quoted 8 lines
for the crash kernel to use.
Fixes ab475510e042 ("kdump: implement reserve_crashkernel_cma")Signed-off-by Usama Arif <[email protected]>---
kernel/crash_reserve.c| 1 +1 file changed, 1 insertion(+)Quoted 5 lines
kernel/crash_reserve.c void __init reserve_crashkernel_cma(unsigned long
Quoted 5 lines
kernel/crash_reserve.c +0
-0@@ -498,6 +498,7 @@ void __init reserve_crashkernel_cma(unsigned longlong
cma_size)Quoted 7 lines
kernel/crash_reserve.c void __init reserve_crashkernel_cma(unsigned long long cma_size) · line 501
Quoted 4 lines
kernel/crash_reserve.c +1
-0continue ; } +cma_reserve_pages_on_error (res);You do know that this will activate under every
bitmap_zalloc()failure, right? Is that accounted for?Yes, that's intended. By the time
cma_activate_area()runs, the range is already in crashk_cma_ranges[], so the crash kernel will use it no matter why activation failed. Keeping the pages reserved is the only way to make sure the first kernel has nothing there that gets overwritten or goes missing from the vmcore; the area then behaves like a regular crashkernel= reservation of the same size.fadump made the same choice; it is what
cma_reserve_pages_on_error()was added for in commit27d121d0ec6d("mm/cma: provide option to opt out from exposing pages on activation failure").The bitmap is one bit per page (32 KiB per GiB with 4K pages) and is allocated at
core_initcall, so a failure there is very unlikely.
Quoted 6 lines
The alternative is to give the memory back and to drop the range from crashk_cma_ranges[] when activation fails, leaving the crash kernel with less memory than requested. I do think that is acceptable as well. But we do need either whats done in this patch or give the memory back. Happy to send the alternative as v2 is everyone thinks that the better way forward.
Hmm. No approach at the moment is the "perfect" approach so far.
Quoted 9 lines
Quoted 9 lines
kernel/crash_reserve.c void __init reserve_crashkernel_cma(unsigned long long cma_size) · line 504
Quoted 6 lines
kernel/crash_reserve.c +0
-0crashk_cma_ranges[crashk_cma_cnt].start =cma_get_base (res); crashk_cma_ranges[crashk_cma_cnt].end = crashk_cma_ranges[crashk_cma_cnt].start +--- Thanks!
--- Thanks!
Quoted 8 lines · Usama Arif
reserve_crashkernel_cma()adds each crashkernel CMA area to crashk_cma_ranges[] as soon as it is declared. If the area later fails activation, e.g. because movablecore= put theZONE_MOVABLEboundary inside it,cma_activate_area()releases the pages to the buddy allocator as ordinary memory. The range is still handed to the crash kernel and excluded from the vmcore, so kernel data that lands there is overwritten by the crash kernel and missing from the dump.
Quoted 7 lines
Mark the areas with
cma_reserve_pages_on_error(), so that a failed activation leaves the pages reserved: lost to the first kernel, but safe for the crash kernel to use.Fixes ab475510e042 ("kdump: implement reserve_crashkernel_cma")Signed-off-by Usama Arif <[email protected]>---
s390 hits this without movablecore= (adding the s390 maintainers and linux-s390) since ZONE_DMA ends at 2G here.
CMA tries to reserve areas above 4G first, but falls back to lower memory when it doesn't fit, so a cma area can end up across the 2G boundary. I ran into this while adding crashkernel=,cma support for s390, which I will post soon, and came up with the same fix.
About dropping the range instead, as you offered for v2: I'd keep this version. With the range dropped, the kdump kernel gets less memory than configured, and that only shows at crash time. With this patch, the the first kernel 'loses' the memory as with a regular crashkernel= reservation of the same size.
There is a second problem in the same loop: all areas are named "crashkernel", which breaks the CMA sysfs and debugfs entries when there are several. I've sent a separate fix for that:
https://lore.kernel.org/r/[email protected]
Quoted 25 lines · On Fri, 6 Nov 2026 12:21:12 +0100 Mikhail Zaslonko <[email protected]>…
Quoted 8 lines · Usama Arif
reserve_crashkernel_cma()adds each crashkernel CMA area to crashk_cma_ranges[] as soon as it is declared. If the area later fails activation, e.g. because movablecore= put theZONE_MOVABLEboundary inside it,cma_activate_area()releases the pages to the buddy allocator as ordinary memory. The range is still handed to the crash kernel and excluded from the vmcore, so kernel data that lands there is overwritten by the crash kernel and missing from the dump.Quoted 7 lines
Mark the areas with
cma_reserve_pages_on_error(), so that a failed activation leaves the pages reserved: lost to the first kernel, but safe for the crash kernel to use.Fixes ab475510e042 ("kdump: implement reserve_crashkernel_cma")Signed-off-by Usama Arif <[email protected]>---
s390 hits this without movablecore= (adding the s390 maintainers and linux-s390) since
ZONE_DMAends at 2G here.
CMA tries to reserve areas above 4G first, but falls back to lower memory when it doesn't fit, so a cma area can end up across the 2G boundary. I ran into this while adding crashkernel=,cma support for s390, which I will post soon, and came up with the same fix.
Quoted 5 lines
About dropping the range instead, as you offered for v2: I'd keep this version. With the range dropped, the kdump kernel gets less memory than configured, and that only shows at crash time. With this patch, the the first kernel 'loses' the memory as with a regular crashkernel= reservation of the same size.
Yes, I do agree with this. Losing memory in first kernel is preferrable and it will then force someone to fix whatever is broken rather than finding out when their kernel crashes.
Quoted 7 lines
There is a second problem in the same loop: all areas are named "crashkernel", which breaks the CMA sysfs and debugfs entries when there are several. I've sent a separate fix for that:
Thanks! I reviewed this now.
Quoted 3 lines
Reviewed-by Mikhail Zaslonko <[email protected]>Tested-by Mikhail Zaslonko <[email protected]>
Thanks for testing and reviewing!
Usama
Bradley Morgan
Reviewed-byQuoted 49 lines · Usama Arif
Quoted 7 lines · On Fri, 6 Nov 2026 12:21:12 +0100 Mikhail Zaslonko <[email protected]>…
Quoted 4 lines · Usama Arif
reserve_crashkernel_cma()adds each crashkernel CMA area to crashk_cma_ranges[] as soon as it is declared. If the area later fails activation, e.g. because movablecore= put theZONE_MOVABLEboundary inside it,cma_activate_area()releases the pages to the buddyallocator
Quoted 2 lines
Quoted 2 lines
as ordinary memory. The range is still handed to the crash kernel and excluded from the vmcore, so kernel data that lands there is
overwritten
Quoted 4 lines
Quoted 4 lines
by the crash kernel and missing from the dump.
Mark the areas with
cma_reserve_pages_on_error(), so that a failed activation leaves the pages reserved: lost to the first kernel, butsafe
Quoted 9 lines
Quoted 5 lines
for the crash kernel to use.
Fixes ab475510e042 ("kdump: implement reserve_crashkernel_cma")Signed-off-by Usama Arif <[email protected]>---
s390 hits this without movablecore= (adding the s390 maintainers and linux-s390) since
ZONE_DMAends at 2G here.
CMA tries to reserve areas above 4G first, but falls back to lower memory when it doesn't fit, so a cma area can end up across the 2Gboundary.
Quoted 7 lines
I ran into this while adding crashkernel=,cma support for s390, which I will post soon, and came up with the same fix.
About dropping the range instead, as you offered for v2: I'd keep this version. With the range dropped, the kdump kernel gets less memory than configured, and that only shows at crash time. With this patch, the the first kernel 'loses' the memory as with a regular crashkernel=
reservation
Quoted 1 line
of the same size.
Yes, I do agree with this. Losing memory in first kernel is preferrable and it will then force someone to fix whatever is broken rather than finding out when their kernel crashes.
Quoted 6 lines
There is a second problem in the same loop: all areas are named "crashkernel", which breaks the CMA sysfs and debugfs entries when there are several. I've sent a separate fix for that:
Quoted 7 lines
https://lore.kernel.org/r/[email protected]
Quoted 1 line
Thanks! I reviewed this now.
Quoted 2 lines
Reviewed-by Mikhail Zaslonko <[email protected]>Tested-by Mikhail Zaslonko <[email protected]>
Well, now that that predicament arises, I see that this patch is a "hidden gem" sort of thing
(Thanks for telling me about how you accounted for that bitmap_zalloc() failure)
Quoted 5 lines
Quoted 1 line
Thanks for testing and reviewing!
Usama
--- Thanks!
Quoted 8 lines · Usama Arif
reserve_crashkernel_cma()adds each crashkernel CMA area to crashk_cma_ranges[] as soon as it is declared. If the area later fails activation, e.g. because movablecore= put theZONE_MOVABLEboundary inside it,cma_activate_area()releases the pages to the buddy allocator as ordinary memory. The range is still handed to the crash kernel and excluded from the vmcore, so kernel data that lands there is overwritten by the crash kernel and missing from the dump.
Quoted 6 lines
Mark the areas with
cma_reserve_pages_on_error(), so that a failed activation leaves the pages reserved: lost to the first kernel, but safe for the crash kernel to use.Fixes ab475510e042 ("kdump: implement reserve_crashkernel_cma")Signed-off-by Usama Arif <[email protected]>
From: Mike Rapoport (Microsoft) <[email protected]>
Quoted 9 lines · Usama Arif
reserve_crashkernel_cma()adds each crashkernel CMA area to crashk_cma_ranges[] as soon as it is declared. If the area later fails activation, e.g. because movablecore= put theZONE_MOVABLEboundary inside it,cma_activate_area()releases the pages to the buddy allocator as ordinary memory. The range is still handed to the crash kernel and excluded from the vmcore, so kernel data that lands there is overwritten by the crash kernel and missing from the dump.[...]
Applied to kexec-next branch of liveupdate/linux.git tree, thanks!
[1/1] crash: keep crashkernel CMA pages reserved if activation fails
commit: e2b6a999e1df5bda2100262397260664655cd47c
tree: https://git.kernel.org/pub/scm/linux/kernel/git/liveupdate/linux
branch: kexec-next
--
Sincerely yours,
Mike.