Skip to content

Commit 4ae362b

Browse files
Vivek GoyalLinus Torvalds
authored andcommitted
[PATCH] kdump: read previous kernel's memory
- Moving the crash_dump.c file to arch dependent part as kmap_atomic_pfn is specific to i386 and highmem may not exist in other archs. - Use ioremap for x86_64 to map the previous kernel memory. - In copy_oldmem_page(), we now directly copy to the user/kernel buffer and avoid the unneccesary copy to a kmalloc'd page. Signed-off-by: Rachita Kothiyal <rachita@in.ibm.com> Signed-off-by: Vivek Goyal <vgoyal@in.ibm.com> Cc: Andi Kleen <ak@muc.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent ec9ce0d commit 4ae362b

6 files changed

Lines changed: 88 additions & 27 deletions

File tree

‎arch/i386/kernel/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ obj-$(CONFIG_X86_LOCAL_APIC) += apic.o nmi.o
2525
obj-$(CONFIG_X86_IO_APIC) += io_apic.o
2626
obj-$(CONFIG_X86_REBOOTFIXUPS) += reboot_fixups.o
2727
obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o crash.o
28+
obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
2829
obj-$(CONFIG_X86_NUMAQ) += numaq.o
2930
obj-$(CONFIG_X86_SUMMIT_NUMA) += summit.o
3031
obj-$(CONFIG_KPROBES) += kprobes.o

‎arch/i386/kernel/crash_dump.c‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* kernel/crash_dump.c - Memory preserving reboot related code.
3+
*
4+
* Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
5+
* Copyright (C) IBM Corporation, 2004. All rights reserved
6+
*/
7+
8+
#include <linux/errno.h>
9+
#include <linux/highmem.h>
10+
#include <linux/crash_dump.h>
11+
12+
#include <asm/uaccess.h>
13+
14+
static void *kdump_buf_page;
15+
16+
/**
17+
* copy_oldmem_page - copy one page from "oldmem"
18+
* @pfn: page frame number to be copied
19+
* @buf: target memory address for the copy; this can be in kernel address
20+
* space or user address space (see @userbuf)
21+
* @csize: number of bytes to copy
22+
* @offset: offset in bytes into the page (based on pfn) to begin the copy
23+
* @userbuf: if set, @buf is in user address space, use copy_to_user(),
24+
* otherwise @buf is in kernel address space, use memcpy().
25+
*
26+
* Copy a page from "oldmem". For this page, there is no pte mapped
27+
* in the current kernel. We stitch up a pte, similar to kmap_atomic.
28+
*
29+
* Calling copy_to_user() in atomic context is not desirable. Hence first
30+
* copying the data to a pre-allocated kernel page and then copying to user
31+
* space in non-atomic context.
32+
*/
33+
ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
34+
size_t csize, unsigned long offset, int userbuf)
35+
{
36+
void *vaddr;
37+
38+
if (!csize)
39+
return 0;
40+
41+
vaddr = kmap_atomic_pfn(pfn, KM_PTE0);
42+
43+
if (!userbuf) {
44+
memcpy(buf, (vaddr + offset), csize);
45+
kunmap_atomic(vaddr, KM_PTE0);
46+
} else {
47+
if (!kdump_buf_page) {
48+
printk(KERN_WARNING "Kdump: Kdump buffer page not"
49+
" allocated\n");
50+
return -EFAULT;
51+
}
52+
copy_page(kdump_buf_page, vaddr);
53+
kunmap_atomic(vaddr, KM_PTE0);
54+
if (copy_to_user(buf, (kdump_buf_page + offset), csize))
55+
return -EFAULT;
56+
}
57+
58+
return csize;
59+
}
60+
61+
static int __init kdump_buf_page_init(void)
62+
{
63+
int ret = 0;
64+
65+
kdump_buf_page = kmalloc(PAGE_SIZE, GFP_KERNEL);
66+
if (!kdump_buf_page) {
67+
printk(KERN_WARNING "Kdump: Failed to allocate kdump buffer"
68+
" page\n");
69+
ret = -ENOMEM;
70+
}
71+
72+
return ret;
73+
}
74+
arch_initcall(kdump_buf_page_init);

‎arch/x86_64/kernel/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ obj-$(CONFIG_X86_LOCAL_APIC) += apic.o nmi.o
2222
obj-$(CONFIG_X86_IO_APIC) += io_apic.o mpparse.o \
2323
genapic.o genapic_cluster.o genapic_flat.o
2424
obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o crash.o
25+
obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
2526
obj-$(CONFIG_PM) += suspend.o
2627
obj-$(CONFIG_SOFTWARE_SUSPEND) += suspend_asm.o
2728
obj-$(CONFIG_CPU_FREQ) += cpufreq/
Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,12 @@
55
* Copyright (C) IBM Corporation, 2004. All rights reserved
66
*/
77

8-
#include <linux/smp_lock.h>
98
#include <linux/errno.h>
10-
#include <linux/proc_fs.h>
11-
#include <linux/bootmem.h>
12-
#include <linux/highmem.h>
139
#include <linux/crash_dump.h>
1410

15-
#include <asm/io.h>
1611
#include <asm/uaccess.h>
17-
#include <asm/kexec.h>
18-
19-
/* Stores the physical address of elf header of crash image. */
20-
unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX;
12+
#include <asm/io.h>
2113

22-
#ifndef HAVE_ARCH_COPY_OLDMEM_PAGE
2314
/**
2415
* copy_oldmem_page - copy one page from "oldmem"
2516
* @pfn: page frame number to be copied
@@ -34,31 +25,23 @@ unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX;
3425
* in the current kernel. We stitch up a pte, similar to kmap_atomic.
3526
*/
3627
ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
37-
size_t csize, unsigned long offset, int userbuf)
28+
size_t csize, unsigned long offset, int userbuf)
3829
{
39-
void *page, *vaddr;
30+
void *vaddr;
4031

4132
if (!csize)
4233
return 0;
4334

44-
page = kmalloc(PAGE_SIZE, GFP_KERNEL);
45-
if (!page)
46-
return -ENOMEM;
47-
48-
vaddr = kmap_atomic_pfn(pfn, KM_PTE0);
49-
copy_page(page, vaddr);
50-
kunmap_atomic(vaddr, KM_PTE0);
35+
vaddr = ioremap(pfn << PAGE_SHIFT, PAGE_SIZE);
5136

5237
if (userbuf) {
53-
if (copy_to_user(buf, (page + offset), csize)) {
54-
kfree(page);
38+
if (copy_to_user(buf, (vaddr + offset), csize)) {
39+
iounmap(vaddr);
5540
return -EFAULT;
5641
}
57-
} else {
58-
memcpy(buf, (page + offset), csize);
59-
}
42+
} else
43+
memcpy(buf, (vaddr + offset), csize);
6044

61-
kfree(page);
45+
iounmap(vaddr);
6246
return csize;
6347
}
64-
#endif

‎fs/proc/vmcore.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ static size_t elfcorebuf_sz;
3535
/* Total size of vmcore file. */
3636
static u64 vmcore_size;
3737

38+
/* Stores the physical address of elf header of crash image. */
39+
unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX;
40+
3841
struct proc_dir_entry *proc_vmcore = NULL;
3942

4043
/* Reads a page from the oldmem device from given offset. */

‎kernel/Makefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ obj-$(CONFIG_KPROBES) += kprobes.o
3030
obj-$(CONFIG_SYSFS) += ksysfs.o
3131
obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o
3232
obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
33-
obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
3433
obj-$(CONFIG_SECCOMP) += seccomp.o
3534
obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
3635

0 commit comments

Comments
 (0)