Merge branch 'acpica'
[firefly-linux-kernel-4.4.55.git] / kernel / kexec_core.c
index 9aa25c034b2ef4b30c769171db9525b7a0e1d5cc..201b45327804d230edc9017eef6c07805ae3f8d3 100644 (file)
@@ -439,11 +439,10 @@ static struct page *kimage_alloc_crash_control_pages(struct kimage *image,
                /* If I don't overlap any segments I have found my hole! */
                if (i == image->nr_segments) {
                        pages = pfn_to_page(hole_start >> PAGE_SHIFT);
+                       image->control_page = hole_end;
                        break;
                }
        }
-       if (pages)
-               image->control_page = hole_end;
 
        return pages;
 }
@@ -1005,7 +1004,28 @@ void crash_save_cpu(struct pt_regs *regs, int cpu)
 static int __init crash_notes_memory_init(void)
 {
        /* Allocate memory for saving cpu registers. */
-       crash_notes = alloc_percpu(note_buf_t);
+       size_t size, align;
+
+       /*
+        * crash_notes could be allocated across 2 vmalloc pages when percpu
+        * is vmalloc based . vmalloc doesn't guarantee 2 continuous vmalloc
+        * pages are also on 2 continuous physical pages. In this case the
+        * 2nd part of crash_notes in 2nd page could be lost since only the
+        * starting address and size of crash_notes are exported through sysfs.
+        * Here round up the size of crash_notes to the nearest power of two
+        * and pass it to __alloc_percpu as align value. This can make sure
+        * crash_notes is allocated inside one physical page.
+        */
+       size = sizeof(note_buf_t);
+       align = min(roundup_pow_of_two(sizeof(note_buf_t)), PAGE_SIZE);
+
+       /*
+        * Break compile if size is bigger than PAGE_SIZE since crash_notes
+        * definitely will be in 2 pages with that.
+        */
+       BUILD_BUG_ON(size > PAGE_SIZE);
+
+       crash_notes = __alloc_percpu(size, align);
        if (!crash_notes) {
                pr_warn("Kexec: Memory allocation for saving cpu register states failed\n");
                return -ENOMEM;
@@ -1397,6 +1417,9 @@ static int __init crash_save_vmcoreinfo_init(void)
 #endif
        VMCOREINFO_NUMBER(PG_head_mask);
        VMCOREINFO_NUMBER(PAGE_BUDDY_MAPCOUNT_VALUE);
+#ifdef CONFIG_X86
+       VMCOREINFO_NUMBER(KERNEL_IMAGE_SIZE);
+#endif
 #ifdef CONFIG_HUGETLBFS
        VMCOREINFO_SYMBOL(free_huge_page);
 #endif