vmcoreinfo: support VMCOREINFO_BYTES larger than PAGE_SIZE
Subsystems (3)
cover vmcoreinfo: support VMCOREINFO_BYTES larger than PAGE_SIZE
VMCOREINFO_BYTES is defined as a configurable size, but multiple code paths implicitly assume it always fits into a single page.
This series removes that assumption by allocating and mapping vmcoreinfo based on its actual size.
Patch 1 updates vmcoreinfo allocation to use get_order(VMCOREINFO_BYTES). Patch 2 updates crash kernel handling to correctly allocate and map multiple pages when copying vmcoreinfo.
This makes vmcoreinfo size consistent across the kernel and avoids future breakage if VMCOREINFO_BYTES grows.
Tested on riscv64.
(No functional change when VMCOREINFO_BYTES == PAGE_SIZE.)
Pnina Feder (2):
kernel: vmcoreinfo: allocate vmcoreinfo_data based on VMCOREINFO_BYTES kernel/crash: handle multi-page vmcoreinfo in crash kernel copy
kernel/crash_core.c | 17 +++++++++++++---- kernel/vmcore_info.c | 6 ++++-- 2 files changed, 17 insertions(+), 6 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 kernel: vmcoreinfo: allocate vmcoreinfo_data based on VMCOREINFO_BYTES
VMCOREINFO_BYTES defines the size of vmcoreinfo data, but the current implementation assumes a single page allocation.
Allocate vmcoreinfo_data using get_order(VMCOREINFO_BYTES) so that vmcoreinfo can safely grow beyond PAGE_SIZE.
This avoids hidden assumptions and keeps vmcoreinfo size consistent across the kernel.
--- kernel/vmcore_info.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/vmcore_info.c +4 -2
@@ -137,7 +137,9 @@ EXPORT_SYMBOL_GPL(hwerr_log_error_type);static int __init crash_save_vmcoreinfo_init (void ) { - vmcoreinfo_data = (unsigned char *)get_zeroed_page (GFP_KERNEL ); +int order; + order =get_order (VMCOREINFO_BYTES ); + vmcoreinfo_data = (unsigned char *)__get_free_pages (GFP_KERNEL | __GFP_ZERO, order);if (!vmcoreinfo_data) {pr_warn ("Memory allocation for vmcoreinfo_data failed\n" );return -ENOMEM ;
@@ -146,7 +148,7 @@ static int __init crash_save_vmcoreinfo_init(void) vmcoreinfo_note =alloc_pages_exact (VMCOREINFO_NOTE_SIZE ,GFP_KERNEL | __GFP_ZERO);if (!vmcoreinfo_note) { -free_page ((unsigned long )vmcoreinfo_data); +free_pages ((unsigned long )vmcoreinfo_data, order); vmcoreinfo_data =NULL ;pr_warn ("Memory allocation for vmcoreinfo_note failed\n" );return -ENOMEM ;
Signature · 1 line
2.43.0
PATCH 2/2 kernel/crash: handle multi-page vmcoreinfo in crash kernel copy
In reply to Pnina Federkimage_crash_copy_vmcoreinfo() currently assumes vmcoreinfo fits in a single page. This breaks if VMCOREINFO_BYTES exceeds PAGE_SIZE.
Allocate the required order of control pages and vmap all pages needed to safely copy vmcoreinfo into the crash kernel image.
--- kernel/crash_core.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
kernel/crash_core.c +13 -4
@@ -44,9 +44,15 @@ note_buf_t __percpu *crash_notes;int kimage_crash_copy_vmcoreinfo (struct kimage *image) { -struct page *vmcoreinfo_page; +struct page *vmcoreinfo_base; +struct page *vmcoreinfo_pages[DIV_ROUND_UP (VMCOREINFO_BYTES ,PAGE_SIZE )]; +unsigned int order, nr_pages; +int i;void *safecopy; + nr_pages =DIV_ROUND_UP (VMCOREINFO_BYTES ,PAGE_SIZE ); + order =get_order (VMCOREINFO_BYTES ); +if (!IS_ENABLED (CONFIG_CRASH_DUMP ))return 0 ;if (image->type !=KEXEC_TYPE_CRASH )
@@ -61,12 +67,15 @@ int kimage_crash_copy_vmcoreinfo(struct kimage *image)* happens to generate vmcoreinfo note, hereby we rely on * vmap for this purpose. */ - vmcoreinfo_page =kimage_alloc_control_pages (image,0 ); -if (!vmcoreinfo_page) { + vmcoreinfo_base =kimage_alloc_control_pages (image, order); +if (!vmcoreinfo_base) {pr_warn ("Could not allocate vmcoreinfo buffer\n" );return -ENOMEM ; } - safecopy =vmap (&vmcoreinfo_page,1 ,VM_MAP ,PAGE_KERNEL ); +for (i =0 ; i < nr_pages; i++) + vmcoreinfo_pages[i] = vmcoreinfo_base + i; + + safecopy =vmap (vmcoreinfo_pages, nr_pages,VM_MAP ,PAGE_KERNEL );if (!safecopy) {pr_warn ("Could not vmap vmcoreinfo buffer\n" );return -ENOMEM ;
Signature · 1 line
2.43.0