Re: [PATCHv3] x86/boot/KASLR: skip the specified crashkernel region

From: Baoquan He
Date: Tue Apr 02 2019 - 02:52:53 EST


On 04/02/19 at 02:19pm, Chao Fan wrote:
> On Tue, Apr 02, 2019 at 12:10:46PM +0800, Pingfan Liu wrote:
> >crashkernel=x@y or or =range1:size1[,range2:size2,...]@offset option may
> or or?
> >fail to reserve the required memory region if KASLR puts kernel into the
> >region. To avoid this uncertainty, asking KASLR to skip the required
> >region.
> >
> >Signed-off-by: Pingfan Liu <kernelfans@xxxxxxxxx>
> >Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> >Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> >Cc: Borislav Petkov <bp@xxxxxxxxx>
> >Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
> >Cc: Baoquan He <bhe@xxxxxxxxxx>
> >Cc: Will Deacon <will.deacon@xxxxxxx>
> >Cc: Nicolas Pitre <nico@xxxxxxxxxx>
> >Cc: Pingfan Liu <kernelfans@xxxxxxxxx>
> >Cc: Chao Fan <fanc.fnst@xxxxxxxxxxxxxx>
> >Cc: "Kirill A. Shutemov" <kirill.shutemov@xxxxxxxxxxxxxxx>
> >Cc: Ard Biesheuvel <ard.biesheuvel@xxxxxxxxxx>
> >Cc: linux-kernel@xxxxxxxxxxxxxxx
> >---
> [...]
> >+
> >+/* handle crashkernel=x@y or =range1:size1[,range2:size2,...]@offset options */
>
> Before review, I want to say more about the background.
> It's very hard to review the code for someone who is not so familiar
> with kdump, so could you please explain more ahout
> the uasge of crashkernel=range1:size1[,range2:size2,...]@offset.
> And also there are so many jobs who are parsing string. So I really
> need your help to understand the PATCH.

The hard part may be handle_crashkernel_mem() itself. However, it's
almost copied from parse_crashkernel_mem() completely. If we can reuse
that function, thing's gonna be perfect.

>
> >+static void mem_avoid_specified_crashkernel_region(char *option)
> >+{
> >+ unsigned long long crash_size, crash_base = 0;
> >+ char *first_colon, *first_space, *cur = option;
> Is there a tab after char?
> >+
> >+ 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;
> I wonder whether it's needed to consider the memory ranges here.
> I think it's OK to only record the regions should to be avoid.
> I remeber I ever talked with Baoquan about the similiar problems.
> @Baoquan, I am not sure if I misunderstand something.

Not sure if I get you. Could you be more specific?