1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/highmem.h>
3 #include <linux/bootmem.h>
4 #include <linux/crash_dump.h>
5 #include <linux/uaccess.h>
6 #include <linux/slab.h>
8 static void *kdump_buf_page
;
11 * copy_oldmem_page - copy one page from "oldmem"
12 * @pfn: page frame number to be copied
13 * @buf: target memory address for the copy; this can be in kernel address
14 * space or user address space (see @userbuf)
15 * @csize: number of bytes to copy
16 * @offset: offset in bytes into the page (based on pfn) to begin the copy
17 * @userbuf: if set, @buf is in user address space, use copy_to_user(),
18 * otherwise @buf is in kernel address space, use memcpy().
20 * Copy a page from "oldmem". For this page, there is no pte mapped
21 * in the current kernel.
23 * Calling copy_to_user() in atomic context is not desirable. Hence first
24 * copying the data to a pre-allocated kernel page and then copying to user
25 * space in non-atomic context.
27 ssize_t
copy_oldmem_page(unsigned long pfn
, char *buf
,
28 size_t csize
, unsigned long offset
, int userbuf
)
35 vaddr
= kmap_atomic_pfn(pfn
);
38 memcpy(buf
, (vaddr
+ offset
), csize
);
41 if (!kdump_buf_page
) {
42 pr_warn("Kdump: Kdump buffer page not allocated\n");
46 copy_page(kdump_buf_page
, vaddr
);
48 if (copy_to_user(buf
, (kdump_buf_page
+ offset
), csize
))
55 static int __init
kdump_buf_page_init(void)
59 kdump_buf_page
= kmalloc(PAGE_SIZE
, GFP_KERNEL
);
60 if (!kdump_buf_page
) {
61 pr_warn("Kdump: Failed to allocate kdump buffer page\n");
67 arch_initcall(kdump_buf_page_init
);