]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - kernel/kexec.c
add-vmcore: cleanup the coding style according to Andrew's comments
[linux-2.6.git] / kernel / kexec.c
index 2a59c8a01ae0010da5ef5b80b39fad2ec1da14ae..b979b010b6d8b98b5b2ab699cb304c8ae17f3989 100644 (file)
 #include <linux/highmem.h>
 #include <linux/syscalls.h>
 #include <linux/reboot.h>
-#include <linux/syscalls.h>
 #include <linux/ioport.h>
 #include <linux/hardirq.h>
 #include <linux/elf.h>
 #include <linux/elfcore.h>
+#include <linux/utsrelease.h>
+#include <linux/utsname.h>
+#include <linux/numa.h>
 
 #include <asm/page.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 #include <asm/system.h>
 #include <asm/semaphore.h>
+#include <asm/sections.h>
 
 /* Per cpu memory for storing cpu states in case of system crash. */
 note_buf_t* crash_notes;
 
+/* vmcoreinfo stuff */
+unsigned char vmcoreinfo_data[VMCOREINFO_BYTES];
+u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
+size_t vmcoreinfo_size;
+size_t vmcoreinfo_max_size = sizeof(vmcoreinfo_data);
+
 /* Location of the reserved area for the crash kernel */
 struct resource crashk_res = {
        .name  = "Crash kernel",
@@ -1061,6 +1070,7 @@ void crash_kexec(struct pt_regs *regs)
                if (kexec_crash_image) {
                        struct pt_regs fixed_regs;
                        crash_setup_regs(&fixed_regs, regs);
+                       crash_save_vmcoreinfo();
                        machine_crash_shutdown(&fixed_regs);
                        machine_kexec(kexec_crash_image);
                }
@@ -1118,8 +1128,8 @@ void crash_save_cpu(struct pt_regs *regs, int cpu)
        memset(&prstatus, 0, sizeof(prstatus));
        prstatus.pr_pid = current->pid;
        elf_core_copy_regs(&prstatus.pr_reg, regs);
-       buf = append_elf_note(buf, "CORE", NT_PRSTATUS, &prstatus,
-                               sizeof(prstatus));
+       buf = append_elf_note(buf, KEXEC_CORE_NOTE_NAME, NT_PRSTATUS,
+                             &prstatus, sizeof(prstatus));
        final_note(buf);
 }
 
@@ -1135,3 +1145,102 @@ static int __init crash_notes_memory_init(void)
        return 0;
 }
 module_init(crash_notes_memory_init)
+
+void crash_save_vmcoreinfo(void)
+{
+       u32 *buf;
+
+       if (!vmcoreinfo_size)
+               return;
+
+       vmcoreinfo_append_str("CRASHTIME=%ld", get_seconds());
+
+       buf = (u32 *)vmcoreinfo_note;
+
+       buf = append_elf_note(buf, VMCOREINFO_NOTE_NAME, 0, vmcoreinfo_data,
+                             vmcoreinfo_size);
+
+       final_note(buf);
+}
+
+void vmcoreinfo_append_str(const char *fmt, ...)
+{
+       va_list args;
+       char buf[0x50];
+       int r;
+
+       va_start(args, fmt);
+       r = vsnprintf(buf, sizeof(buf), fmt, args);
+       va_end(args);
+
+       if (r + vmcoreinfo_size > vmcoreinfo_max_size)
+               r = vmcoreinfo_max_size - vmcoreinfo_size;
+
+       memcpy(&vmcoreinfo_data[vmcoreinfo_size], buf, r);
+
+       vmcoreinfo_size += r;
+}
+
+/*
+ * provide an empty default implementation here -- architecture
+ * code may override this
+ */
+void __attribute__ ((weak)) arch_crash_save_vmcoreinfo(void)
+{}
+
+unsigned long __attribute__ ((weak)) paddr_vmcoreinfo_note(void)
+{
+       return __pa((unsigned long)(char *)&vmcoreinfo_note);
+}
+
+static int __init crash_save_vmcoreinfo_init(void)
+{
+       vmcoreinfo_append_str("OSRELEASE=%s\n", init_uts_ns.name.release);
+       vmcoreinfo_append_str("PAGESIZE=%ld\n", PAGE_SIZE);
+
+       SYMBOL(init_uts_ns);
+       SYMBOL(node_online_map);
+       SYMBOL(swapper_pg_dir);
+       SYMBOL(_stext);
+
+#ifndef CONFIG_NEED_MULTIPLE_NODES
+       SYMBOL(mem_map);
+       SYMBOL(contig_page_data);
+#endif
+#ifdef CONFIG_SPARSEMEM
+       SYMBOL(mem_section);
+       LENGTH(mem_section, NR_SECTION_ROOTS);
+       SIZE(mem_section);
+       OFFSET(mem_section, section_mem_map);
+#endif
+       SIZE(page);
+       SIZE(pglist_data);
+       SIZE(zone);
+       SIZE(free_area);
+       SIZE(list_head);
+       OFFSET(page, flags);
+       OFFSET(page, _count);
+       OFFSET(page, mapping);
+       OFFSET(page, lru);
+       OFFSET(pglist_data, node_zones);
+       OFFSET(pglist_data, nr_zones);
+#ifdef CONFIG_FLAT_NODE_MEM_MAP
+       OFFSET(pglist_data, node_mem_map);
+#endif
+       OFFSET(pglist_data, node_start_pfn);
+       OFFSET(pglist_data, node_spanned_pages);
+       OFFSET(pglist_data, node_id);
+       OFFSET(zone, free_area);
+       OFFSET(zone, vm_stat);
+       OFFSET(zone, spanned_pages);
+       OFFSET(free_area, free_list);
+       OFFSET(list_head, next);
+       OFFSET(list_head, prev);
+       LENGTH(zone.free_area, MAX_ORDER);
+
+       arch_crash_save_vmcoreinfo();
+
+       return 0;
+}
+
+module_init(crash_save_vmcoreinfo_init)