Commit cc57165874e938ef684d71ba7d36e7088b551489

Authored by Vivek Goyal
Committed by Linus Torvalds
1 parent 8240941157

[PATCH] kdump: dynamic per cpu allocation of memory for saving cpu registers

- In case of system crash, current state of cpu registers is saved in memory
  in elf note format.  So far memory for storing elf notes was being allocated
  statically for NR_CPUS.

- This patch introduces dynamic allocation of memory for storing elf notes.
  It uses alloc_percpu() interface.  This should lead to better memory usage.

- Introduced based on Andi Kleen's and Eric W. Biederman's suggestions.

- This patch also moves memory allocation for elf notes from architecture
  dependent portion to architecture independent portion.  Now crash_notes is
  architecture independent.  The whole idea is that size of memory to be
  allocated per cpu (MAX_NOTE_BYTES) can be architecture dependent and
  allocation of this memory can be architecture independent.

Signed-off-by: Vivek Goyal <vgoyal@in.ibm.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 10 changed files with 21 additions and 24 deletions Side-by-side Diff

arch/i386/kernel/crash.c
... ... @@ -25,7 +25,6 @@
25 25 #include <mach_ipi.h>
26 26  
27 27  
28   -note_buf_t crash_notes[NR_CPUS];
29 28 /* This keeps a track of which one is crashing cpu. */
30 29 static int crashing_cpu;
31 30  
... ... @@ -72,7 +71,9 @@
72 71 * squirrelled away. ELF notes happen to provide
73 72 * all of that that no need to invent something new.
74 73 */
75   - buf = &crash_notes[cpu][0];
  74 + buf = (u32*)per_cpu_ptr(crash_notes, cpu);
  75 + if (!buf)
  76 + return;
76 77 memset(&prstatus, 0, sizeof(prstatus));
77 78 prstatus.pr_pid = current->pid;
78 79 elf_core_copy_regs(&prstatus.pr_reg, regs);
arch/ppc/kernel/machine_kexec.c
... ... @@ -28,12 +28,6 @@
28 28 const extern unsigned char relocate_new_kernel[];
29 29 const extern unsigned int relocate_new_kernel_size;
30 30  
31   -/*
32   - * Provide a dummy crash_notes definition while crash dump arrives to ppc.
33   - * This prevents breakage of crash_notes attribute in kernel/ksysfs.c.
34   - */
35   -note_buf_t crash_notes[NR_CPUS];
36   -
37 31 void machine_shutdown(void)
38 32 {
39 33 if (ppc_md.machine_shutdown)
arch/s390/kernel/crash.c
... ... @@ -10,8 +10,6 @@
10 10 #include <linux/threads.h>
11 11 #include <linux/kexec.h>
12 12  
13   -note_buf_t crash_notes[NR_CPUS];
14   -
15 13 void machine_crash_shutdown(struct pt_regs *regs)
16 14 {
17 15 }
arch/x86_64/kernel/crash.c
... ... @@ -19,8 +19,6 @@
19 19 #include <asm/nmi.h>
20 20 #include <asm/hw_irq.h>
21 21  
22   -note_buf_t crash_notes[NR_CPUS];
23   -
24 22 void machine_crash_shutdown(struct pt_regs *regs)
25 23 {
26 24 /* This function is only called after the system
include/asm-i386/kexec.h
... ... @@ -26,9 +26,6 @@
26 26 #define KEXEC_ARCH KEXEC_ARCH_386
27 27  
28 28 #define MAX_NOTE_BYTES 1024
29   -typedef u32 note_buf_t[MAX_NOTE_BYTES/4];
30   -
31   -extern note_buf_t crash_notes[];
32 29  
33 30 #endif /* _I386_KEXEC_H */
include/asm-powerpc/kexec.h
... ... @@ -38,9 +38,6 @@
38 38 #ifdef CONFIG_KEXEC
39 39  
40 40 #define MAX_NOTE_BYTES 1024
41   -typedef u32 note_buf_t[MAX_NOTE_BYTES / sizeof(u32)];
42   -
43   -extern note_buf_t crash_notes[];
44 41  
45 42 #ifdef __powerpc64__
46 43 extern void kexec_smp_wait(void); /* get and clear naca physid, wait for
include/asm-s390/kexec.h
... ... @@ -35,9 +35,6 @@
35 35 #define KEXEC_ARCH KEXEC_ARCH_S390
36 36  
37 37 #define MAX_NOTE_BYTES 1024
38   -typedef u32 note_buf_t[MAX_NOTE_BYTES/4];
39   -
40   -extern note_buf_t crash_notes[];
41 38  
42 39 #endif /*_S390_KEXEC_H */
include/asm-x86_64/kexec.h
... ... @@ -26,9 +26,6 @@
26 26 #define KEXEC_ARCH KEXEC_ARCH_X86_64
27 27  
28 28 #define MAX_NOTE_BYTES 1024
29   -typedef u32 note_buf_t[MAX_NOTE_BYTES/4];
30   -
31   -extern note_buf_t crash_notes[];
32 29  
33 30 #endif /* _X86_64_KEXEC_H */
include/linux/kexec.h
... ... @@ -125,6 +125,8 @@
125 125 /* Location of a reserved region to hold the crash kernel.
126 126 */
127 127 extern struct resource crashk_res;
  128 +typedef u32 note_buf_t[MAX_NOTE_BYTES/4];
  129 +extern note_buf_t *crash_notes;
128 130  
129 131 #else /* !CONFIG_KEXEC */
130 132 struct pt_regs;
... ... @@ -26,6 +26,9 @@
26 26 #include <asm/system.h>
27 27 #include <asm/semaphore.h>
28 28  
  29 +/* Per cpu memory for storing cpu states in case of system crash. */
  30 +note_buf_t* crash_notes;
  31 +
29 32 /* Location of the reserved area for the crash kernel */
30 33 struct resource crashk_res = {
31 34 .name = "Crash kernel",
... ... @@ -1060,4 +1063,17 @@
1060 1063 xchg(&kexec_lock, 0);
1061 1064 }
1062 1065 }
  1066 +
  1067 +static int __init crash_notes_memory_init(void)
  1068 +{
  1069 + /* Allocate memory for saving cpu registers. */
  1070 + crash_notes = alloc_percpu(note_buf_t);
  1071 + if (!crash_notes) {
  1072 + printk("Kexec: Memory allocation for saving cpu register"
  1073 + " states failed\n");
  1074 + return -ENOMEM;
  1075 + }
  1076 + return 0;
  1077 +}
  1078 +module_init(crash_notes_memory_init)