Kexec Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Baoquan He <bhe@redhat.com>
Cc: mhuang@redhat.com, kexec@lists.infradead.org,
	linux-kernel@vger.kernel.org, tatsu@ab.jp.nec.com,
	lisa.mitchell@hp.com, seiji.aguchi.tr@hitachi.com,
	dyoung@redhat.com, vgoyal@redhat.com, ebiederm@xmission.com
Subject: Re: [Patch v2] align crash_notes allocation to make it be inside one physical page
Date: Mon, 3 Aug 2015 15:04:17 -0700	[thread overview]
Message-ID: <20150803150417.b3536887b1ad86ae04c405b7@linux-foundation.org> (raw)
In-Reply-To: <1438606243-13064-1-git-send-email-bhe@redhat.com>

On Mon,  3 Aug 2015 20:50:43 +0800 Baoquan He <bhe@redhat.com> wrote:

> 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.
> 
> ...
>
> --- 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<<order), PAGE_SIZE);
> +
> +	WARN_ON(size > PAGE_SIZE);
> +
> +	crash_notes = __alloc_percpu(size, align);

A code comment would be helpful - the reason for this code's existence
is otherwise utterly unobvious.

I think it can be done this way:

	align = min(roundup_pow_of_two(sizeof(note_buf_t)), PAGE_SIZE);


I never noticed get_count_order() before.  afaict it does the same as
order_base_2(), except get_count_order() generates better code and has
a ridiculous name.

And I think the WARN_ON can be replaced with a
BUILD_BUG_ON(sizeof>PAGE_SIZE)?  That would avoid adding runtime
overhead.


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  reply	other threads:[~2015-08-03 22:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-03 12:50 [Patch v2] align crash_notes allocation to make it be inside one physical page Baoquan He
2015-08-03 22:04 ` Andrew Morton [this message]
2015-08-03 23:01   ` Baoquan He
2015-08-11  6:33   ` Baoquan He
2015-08-11  8:01     ` Minfei Huang
2015-08-11  8:42       ` Baoquan He

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150803150417.b3536887b1ad86ae04c405b7@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=bhe@redhat.com \
    --cc=dyoung@redhat.com \
    --cc=ebiederm@xmission.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lisa.mitchell@hp.com \
    --cc=mhuang@redhat.com \
    --cc=seiji.aguchi.tr@hitachi.com \
    --cc=tatsu@ab.jp.nec.com \
    --cc=vgoyal@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox