kexec: move vmcoreinfo out of the kernel's .bss section
authorXunlei Pang <xlpang@redhat.com>
Wed, 12 Jul 2017 21:33:14 +0000 (14:33 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 12 Jul 2017 23:25:59 +0000 (16:25 -0700)
As Eric said,
 "what we need to do is move the variable vmcoreinfo_note out of the
  kernel's .bss section. And modify the code to regenerate and keep this
  information in something like the control page.

  Definitely something like this needs a page all to itself, and ideally
  far away from any other kernel data structures. I clearly was not
  watching closely the data someone decided to keep this silly thing in
  the kernel's .bss section."

This patch allocates extra pages for these vmcoreinfo_XXX variables, one
advantage is that it enhances some safety of vmcoreinfo, because
vmcoreinfo now is kept far away from other kernel data structures.

Link: http://lkml.kernel.org/r/1493281021-20737-1-git-send-email-xlpang@redhat.com
Signed-off-by: Xunlei Pang <xlpang@redhat.com>
Tested-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Suggested-by: Eric Biederman <ebiederm@xmission.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Dave Young <dyoung@redhat.com>
Cc: Hari Bathini <hbathini@linux.vnet.ibm.com>
Cc: Mahesh Salgaonkar <mahesh@linux.vnet.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/ia64/kernel/machine_kexec.c
arch/s390/kernel/machine_kexec.c
arch/s390/kernel/setup.c
arch/x86/kernel/crash.c
arch/x86/xen/mmu_pv.c
include/linux/crash_core.h
kernel/crash_core.c
kernel/ksysfs.c

index 599507bcec91fc577147cf97d894fe7f6dd11677..c14815dca747dead3c608a4bf1a5122165aaf2b7 100644 (file)
@@ -163,8 +163,3 @@ void arch_crash_save_vmcoreinfo(void)
 #endif
 }
 
-phys_addr_t paddr_vmcoreinfo_note(void)
-{
-       return ia64_tpa((unsigned long)(char *)&vmcoreinfo_note);
-}
-
index 49a6bd45957b53aaee9a4ad387725c06ca299cac..3d0b14afa23258efa6047baa0954e1731fb166bb 100644 (file)
@@ -246,6 +246,7 @@ void arch_crash_save_vmcoreinfo(void)
        VMCOREINFO_SYMBOL(lowcore_ptr);
        VMCOREINFO_SYMBOL(high_memory);
        VMCOREINFO_LENGTH(lowcore_ptr, NR_CPUS);
+       mem_assign_absolute(S390_lowcore.vmcore_info, paddr_vmcoreinfo_note());
 }
 
 void machine_shutdown(void)
index 3ae756c0db3de276936283a5c3577fa264ba2aa9..3d1d808ea8a97bb31be7dee6a7c06e16b3f56ad6 100644 (file)
@@ -496,11 +496,6 @@ static void __init setup_memory_end(void)
        pr_notice("The maximum memory size is %luMB\n", memory_end >> 20);
 }
 
-static void __init setup_vmcoreinfo(void)
-{
-       mem_assign_absolute(S390_lowcore.vmcore_info, paddr_vmcoreinfo_note());
-}
-
 #ifdef CONFIG_CRASH_DUMP
 
 /*
@@ -939,7 +934,6 @@ void __init setup_arch(char **cmdline_p)
 #endif
 
        setup_resources();
-       setup_vmcoreinfo();
        setup_lowcore();
        smp_fill_possible_mask();
        cpu_detect_mhz_feature();
index 22217ece26c8807a2747d8396a171c7a6b952842..44404e2307bbebaa9c1edd17db0cd4a07099462a 100644 (file)
@@ -457,7 +457,7 @@ static int prepare_elf64_headers(struct crash_elf_data *ced,
        bufp += sizeof(Elf64_Phdr);
        phdr->p_type = PT_NOTE;
        phdr->p_offset = phdr->p_paddr = paddr_vmcoreinfo_note();
-       phdr->p_filesz = phdr->p_memsz = sizeof(vmcoreinfo_note);
+       phdr->p_filesz = phdr->p_memsz = VMCOREINFO_NOTE_SIZE;
        (ehdr->e_phnum)++;
 
 #ifdef CONFIG_X86_64
index 1d7a7213a3109fb3f21bba9a7a6789496b19b346..cab28cf2cffbb78d09325c46413f65381ec6c5e3 100644 (file)
@@ -2693,8 +2693,8 @@ EXPORT_SYMBOL_GPL(xen_destroy_contiguous_region);
 phys_addr_t paddr_vmcoreinfo_note(void)
 {
        if (xen_pv_domain())
-               return virt_to_machine(&vmcoreinfo_note).maddr;
+               return virt_to_machine(vmcoreinfo_note).maddr;
        else
-               return __pa_symbol(&vmcoreinfo_note);
+               return __pa(vmcoreinfo_note);
 }
 #endif /* CONFIG_KEXEC_CORE */
index 4090a42578a8f4b047930508d5655b603c31bdd5..87506a02e9140888ce2382469a326a14eb42106c 100644 (file)
@@ -19,7 +19,7 @@
                                     CRASH_CORE_NOTE_NAME_BYTES +       \
                                     CRASH_CORE_NOTE_DESC_BYTES)
 
-#define VMCOREINFO_BYTES          (4096)
+#define VMCOREINFO_BYTES          PAGE_SIZE
 #define VMCOREINFO_NOTE_NAME      "VMCOREINFO"
 #define VMCOREINFO_NOTE_NAME_BYTES ALIGN(sizeof(VMCOREINFO_NOTE_NAME), 4)
 #define VMCOREINFO_NOTE_SIZE      ((CRASH_CORE_NOTE_HEAD_BYTES * 2) +  \
@@ -56,7 +56,7 @@ phys_addr_t paddr_vmcoreinfo_note(void);
 #define VMCOREINFO_CONFIG(name) \
        vmcoreinfo_append_str("CONFIG_%s=y\n", #name)
 
-extern u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
+extern u32 *vmcoreinfo_note;
 extern size_t vmcoreinfo_size;
 extern size_t vmcoreinfo_max_size;
 
index fcbd568f1e95069e6f42a46cad5f5c739f273def..2837d6164db8139ed48d35fb9784e6df59c1e1b9 100644 (file)
 #include <asm/sections.h>
 
 /* vmcoreinfo stuff */
-static unsigned char vmcoreinfo_data[VMCOREINFO_BYTES];
-u32 vmcoreinfo_note[VMCOREINFO_NOTE_SIZE/4];
+static unsigned char *vmcoreinfo_data;
 size_t vmcoreinfo_size;
-size_t vmcoreinfo_max_size = sizeof(vmcoreinfo_data);
+size_t vmcoreinfo_max_size = VMCOREINFO_BYTES;
+u32 *vmcoreinfo_note;
 
 /*
  * parsing the "crashkernel" commandline
@@ -326,6 +326,9 @@ static void update_vmcoreinfo_note(void)
 
 void crash_save_vmcoreinfo(void)
 {
+       if (!vmcoreinfo_note)
+               return;
+
        vmcoreinfo_append_str("CRASHTIME=%ld\n", get_seconds());
        update_vmcoreinfo_note();
 }
@@ -356,11 +359,26 @@ void __weak arch_crash_save_vmcoreinfo(void)
 
 phys_addr_t __weak paddr_vmcoreinfo_note(void)
 {
-       return __pa_symbol((unsigned long)(char *)&vmcoreinfo_note);
+       return __pa(vmcoreinfo_note);
 }
 
 static int __init crash_save_vmcoreinfo_init(void)
 {
+       vmcoreinfo_data = (unsigned char *)get_zeroed_page(GFP_KERNEL);
+       if (!vmcoreinfo_data) {
+               pr_warn("Memory allocation for vmcoreinfo_data failed\n");
+               return -ENOMEM;
+       }
+
+       vmcoreinfo_note = alloc_pages_exact(VMCOREINFO_NOTE_SIZE,
+                                               GFP_KERNEL | __GFP_ZERO);
+       if (!vmcoreinfo_note) {
+               free_page((unsigned long)vmcoreinfo_data);
+               vmcoreinfo_data = NULL;
+               pr_warn("Memory allocation for vmcoreinfo_note failed\n");
+               return -ENOMEM;
+       }
+
        VMCOREINFO_OSRELEASE(init_uts_ns.name.release);
        VMCOREINFO_PAGESIZE(PAGE_SIZE);
 
index df1a9aa602a083a9a97a5b0c8128a684f507f92d..46ba853656f63b7ba1a1e11171b8cdc935666c8d 100644 (file)
@@ -134,7 +134,7 @@ static ssize_t vmcoreinfo_show(struct kobject *kobj,
 {
        phys_addr_t vmcore_base = paddr_vmcoreinfo_note();
        return sprintf(buf, "%pa %x\n", &vmcore_base,
-                      (unsigned int)sizeof(vmcoreinfo_note));
+                       (unsigned int)VMCOREINFO_NOTE_SIZE);
 }
 KERNEL_ATTR_RO(vmcoreinfo);