Skip to content

Commit b5bfcc1

Browse files
Pnina Federakpm00
authored andcommitted
kernel/crash: handle multi-page vmcoreinfo in crash kernel copy
kimage_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. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Pnina Feder <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Cc: Baoquan He <[email protected]> Cc: Dave Young <[email protected]> Cc: Vivek Goyal <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 76103d1 commit b5bfcc1

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

kernel/crash_core.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,15 @@ note_buf_t __percpu *crash_notes;
4444

4545
int kimage_crash_copy_vmcoreinfo(struct kimage *image)
4646
{
47-
struct page *vmcoreinfo_page;
47+
struct page *vmcoreinfo_base;
48+
struct page *vmcoreinfo_pages[DIV_ROUND_UP(VMCOREINFO_BYTES, PAGE_SIZE)];
49+
unsigned int order, nr_pages;
50+
int i;
4851
void *safecopy;
4952

53+
nr_pages = DIV_ROUND_UP(VMCOREINFO_BYTES, PAGE_SIZE);
54+
order = get_order(VMCOREINFO_BYTES);
55+
5056
if (!IS_ENABLED(CONFIG_CRASH_DUMP))
5157
return 0;
5258
if (image->type != KEXEC_TYPE_CRASH)
@@ -61,12 +67,15 @@ int kimage_crash_copy_vmcoreinfo(struct kimage *image)
6167
* happens to generate vmcoreinfo note, hereby we rely on
6268
* vmap for this purpose.
6369
*/
64-
vmcoreinfo_page = kimage_alloc_control_pages(image, 0);
65-
if (!vmcoreinfo_page) {
70+
vmcoreinfo_base = kimage_alloc_control_pages(image, order);
71+
if (!vmcoreinfo_base) {
6672
pr_warn("Could not allocate vmcoreinfo buffer\n");
6773
return -ENOMEM;
6874
}
69-
safecopy = vmap(&vmcoreinfo_page, 1, VM_MAP, PAGE_KERNEL);
75+
for (i = 0; i < nr_pages; i++)
76+
vmcoreinfo_pages[i] = vmcoreinfo_base + i;
77+
78+
safecopy = vmap(vmcoreinfo_pages, nr_pages, VM_MAP, PAGE_KERNEL);
7079
if (!safecopy) {
7180
pr_warn("Could not vmap vmcoreinfo buffer\n");
7281
return -ENOMEM;

0 commit comments

Comments
 (0)