From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mx1.redhat.com ([209.132.183.28]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZMFCz-00043c-FL for kexec@lists.infradead.org; Mon, 03 Aug 2015 12:51:14 +0000 From: Baoquan He Subject: [Patch v2] align crash_notes allocation to make it be inside one physical page Date: Mon, 3 Aug 2015 20:50:43 +0800 Message-Id: <1438606243-13064-1-git-send-email-bhe@redhat.com> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kexec" Errors-To: kexec-bounces+dwmw2=infradead.org@lists.infradead.org To: akpm@linux-foundation.org, ebiederm@xmission.com, vgoyal@redhat.com, dyoung@redhat.com, mhuang@redhat.com, lisa.mitchell@hp.com, tatsu@ab.jp.nec.com, seiji.aguchi.tr@hitachi.com Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Baoquan He People reported that crash_notes in /proc/vmcore were corrupted and this cause crash kdump failure. With code debugging and log we got the root cause. This is because percpu variable crash_notes are allocated in 2 vmalloc pages. Currently percpu is based on vmalloc by default. Vmalloc can't guarantee 2 continuous vmalloc pages are also on 2 continuous physical pages. So when 1st kernel exports the starting address and size of crash_notes through sysfs like below: /sys/devices/system/cpu/cpux/crash_notes /sys/devices/system/cpu/cpux/crash_notes_size kdump kernel use them to get the content of crash_notes. However the 2nd part may not be in the next neighbouring physical page as we expected if crash_notes are allocated accross 2 vmalloc pages. That's why nhdr_ptr->n_namesz or nhdr_ptr->n_descsz could be very huge in update_note_header_size_elf64() and cause note header merging failure or some warnings. In this patch change to call __alloc_percpu() to passed in the align value by rounding crash_notes_size up to the nearest power of two. This make sure the crash_notes is allocated inside one physical page since sizeof(note_buf_t) in all ARCHS is smaller than PAGE_SIZE. Meanwhile add a WARN_ON in case it grows to be bigger than PAGE_SIZE in the future. v1->v2: Minfei mentioned percpu can't take align value bigger then PAGE_SIZE. So limit align to be PAGE_SIZE at most. Signed-off-by: Baoquan He --- kernel/kexec.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/kexec.c b/kernel/kexec.c index a785c10..9f4b070 100644 --- a/kernel/kexec.c +++ b/kernel/kexec.c @@ -1620,7 +1620,16 @@ 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; + int order; + + size = sizeof(note_buf_t); + order = get_count_order(size); + align = min_t(size_t, (1< 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; -- 2.1.0 _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec