linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pingfan Liu <kernelfans@gmail.com>
To: Baoquan He <bhe@redhat.com>
Cc: x86@kernel.org, Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Will Deacon <will.deacon@arm.com>,
	Nicolas Pitre <nico@linaro.org>,
	Chao Fan <fanc.fnst@cn.fujitsu.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCHv3] x86/boot/KASLR: skip the specified crashkernel region
Date: Thu, 4 Apr 2019 17:40:26 +0800	[thread overview]
Message-ID: <CAFgQCTs0YTFOePmv6R+j41BTsixE0HdED8kHHVY6+GaZzq4TMg@mail.gmail.com> (raw)
In-Reply-To: <20190403031049.GP7627@MiWiFi-R3L-srv>

On Wed, Apr 3, 2019 at 11:10 AM Baoquan He <bhe@redhat.com> wrote:
>
> On 04/03/19 at 10:58am, Pingfan Liu wrote:
> > On Tue, Apr 2, 2019 at 4:08 PM Baoquan He <bhe@redhat.com> wrote:
> > >
> > > > +/* handle crashkernel=x@y or =range1:size1[,range2:size2,...]@offset options */
> > > > +static void mem_avoid_specified_crashkernel_region(char *option)
> > > > +{
> > > > +     unsigned long long crash_size, crash_base = 0;
> > > > +     char    *first_colon, *first_space, *cur = option;
> > > > +
> > >
> > > Another thing which need be noticed is that you may only need to handle
> > > when '@' is found. Otherwise just let it go. Right?
> > >
> > According to kernel's behavior, only the last "crashkernel=" option
> > takes effect. Hence if no '@', then clearing mem_avoid
>
> Here I mean that you can search '@' at the beginning if crashkernel is
> found. Maybe no need to clear mem_avoid since it's global data, has been
> initialized to 0 during loading. It's in BSS, right?
>
Consider the following cmdline crashkernel=256M@1G crashkernel=512M.
These two options are handled independently by handle_mem_options(),
and the later one should overwrite the previous one. This is the
behavior of current kernel's code, referring to
get_last_crashkernel().
> You don't have to search first colon or first space, then parse size of
> crashkernel, and finally find out that it's only crashkernel=512M-2G:64M,2G-:128M
> style, no '@' specified. What do you think?
>
Yes, that will be better. But I plan to reuse parse_crashkernel_mem/simple().

Thanks,
Pingfan
> >
> > > > +     first_colon = strchr(option, ':');
> > > > +     first_space = strchr(option, ' ');
> > > > +     /* if contain ":" */
> > > > +     if (first_colon && (!first_space || first_colon < first_space)) {
> > > > +             int i;
> > > > +             u64 total_sz = 0;
> > > > +             struct boot_e820_entry *entry;
> > > > +
> > > > +             for (i = 0; i < boot_params->e820_entries; i++) {
> > > > +                     entry = &boot_params->e820_table[i];
> > > > +                     /* Skip non-RAM entries. */
> > > > +                     if (entry->type != E820_TYPE_RAM)
> > > > +                             continue;
> > > > +                     total_sz += entry->size;
> > > > +             }
> > > > +             handle_crashkernel_mem(option, total_sz, &crash_size,
> > > > +                     &crash_base);
> > > > +     } else {
> > > > +             crash_size = memparse(option, &cur);
> > > > +             if (option == cur)
> > > > +                     return;
> > > > +             while (*cur && *cur != ' ' && *cur != '@')
> > > > +                     cur++;
> > > > +             if (*cur == '@') {
> > > > +                     option = cur + 1;
> > > > +                     crash_base = memparse(option, &cur);
> > > > +             }
> > > > +     }
> > > > +     if (crash_base) {
> > > > +             mem_avoid[MEM_AVOID_CRASHKERNEL].start = crash_base;
> > > > +             mem_avoid[MEM_AVOID_CRASHKERNEL].size = crash_size;
> > > > +     } else {
> > > > +             /*
> > > > +              * Clearing mem_avoid if no offset is given. This is consistent
> > > > +              * with kernel, which uses the last crashkernel= option.
> > > > +              */
> > > > +             mem_avoid[MEM_AVOID_CRASHKERNEL].start = 0;
> > > > +             mem_avoid[MEM_AVOID_CRASHKERNEL].size = 0;
> > > > +     }
> > > > +}

      reply	other threads:[~2019-04-04  9:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-02  4:10 [PATCHv3] x86/boot/KASLR: skip the specified crashkernel region Pingfan Liu
2019-04-02  6:19 ` Chao Fan
2019-04-02  6:52   ` Baoquan He
2019-04-02  6:58   ` Pingfan Liu
2019-04-02  7:59     ` Chao Fan
2019-04-02  6:46 ` Baoquan He
2019-04-03  2:59   ` Pingfan Liu
2019-04-02  8:08 ` Baoquan He
2019-04-03  2:58   ` Pingfan Liu
2019-04-03  3:10     ` Baoquan He
2019-04-04  9:40       ` Pingfan Liu [this message]

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=CAFgQCTs0YTFOePmv6R+j41BTsixE0HdED8kHHVY6+GaZzq4TMg@mail.gmail.com \
    --to=kernelfans@gmail.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=bhe@redhat.com \
    --cc=bp@alien8.de \
    --cc=fanc.fnst@cn.fujitsu.com \
    --cc=hpa@zytor.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nico@linaro.org \
    --cc=tglx@linutronix.de \
    --cc=will.deacon@arm.com \
    --cc=x86@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).