Re: [PATCH v2 2/4] kaslr: select the memory region in immovable node to process

From: Baoquan He
Date: Thu Nov 09 2017 - 22:14:46 EST


On 11/10/17 at 11:03am, Chao Fan wrote:
> On Thu, Nov 09, 2017 at 04:21:32PM +0800, Baoquan He wrote:
> >Hi Chao,
> >
> >On 11/01/17 at 07:32pm, Chao Fan wrote:
> >> Compare the region of memmap entry and immovable_mem, then choose the
> >> intersection to process_mem_region.
> >>
> >> Since the interrelationship between e820 or efi entries and memory
> >> region in immovable_mem is different:
> >
> >Could you paste a bootlog with efi=debug specified in cmdline on the
> >system you tested? I want to check what kind of intersection between
> >them. The adding makes code pretty ugly, want to make sure if we have
> >to do like this.
> Hi Baoquan,
>
> Here is a machine with efi.

Thanks, do you have the whole boot log? I want to have a look at e820.
And this is a special system, or a customized system? I mean you just
customize the firmware for better testing to cover kinds of cases.

If it's too big, please attach it and send to me privately.

Anyway, seems your considering about the intersection is right.

Thanks
Baoquan
>
> The memory information in SRAT from dmesg:
> [ 0.000000] ACPI: SRAT: Node 0 PXM 0 [mem 0x00000000-0x0009ffff]
> [ 0.000000] ACPI: SRAT: Node 0 PXM 0 [mem 0x00100000-0x1f3fffff]
> [ 0.000000] ACPI: SRAT: Node 1 PXM 1 [mem 0x1f400000-0x3e7fffff]
> [ 0.000000] ACPI: SRAT: Node 2 PXM 2 [mem 0x3e800000-0x5dbfffff]
> [ 0.000000] ACPI: SRAT: Node 3 PXM 3 [mem 0x5dc00000-0x7cffffff]
> [ 0.000000] ACPI: SRAT: Node 4 PXM 4 [mem 0x7d000000-0x9c3fffff]
> [ 0.000000] ACPI: SRAT: Node 5 PXM 5 [mem 0x9c400000-0xbb7fffff]
> [ 0.000000] ACPI: SRAT: Node 6 PXM 6 [mem 0xbb800000-0xbfffffff]
> [ 0.000000] ACPI: SRAT: Node 6 PXM 6 [mem 0x100000000-0x11abfffff]
> [ 0.000000] ACPI: SRAT: Node 7 PXM 7 [mem 0x11ac00000-0x139ffffff]
> [ 0.000000] ACPI: SRAT: Node 8 PXM 8 [mem 0x13a000000-0x1593fffff]
> [ 0.000000] ACPI: SRAT: Node 9 PXM 9 [mem 0x159400000-0x1787fffff]
>
> There are 10 nodes, and 500M memory in every node.
> And node0 and node 6 has two parts.
>
>
> Here is the efi mem:
> [ 0.000000] efi: mem00: [Boot Code | | | | | | | | |WB|WT|WC|UC] range=[0x0000000000000000-0x0000000000000fff] (0MB)
> [ 0.000000] efi: mem01: [Loader Data | | | | | | | | |WB|WT|WC|UC] range=[0x0000000000001000-0x0000000000001fff] (0MB)
> [ 0.000000] efi: mem02: [Conventional Memory| | | | | | | | |WB|WT|WC|UC] range=[0x0000000000002000-0x000000000009ffff] (0MB)
> [ 0.000000] efi: mem03: [Conventional Memory| | | | | | | | |WB|WT|WC|UC] range=[0x0000000000100000-0x0000000000805fff] (7MB)
> [ 0.000000] efi: mem04: [Boot Data | | | | | | | | |WB|WT|WC|UC] range=[0x0000000000806000-0x0000000000806fff] (0MB)
> [ 0.000000] efi: mem05: [Conventional Memory| | | | | | | | |WB|WT|WC|UC] range=[0x0000000000807000-0x000000000081ffff] (0MB)
> [ 0.000000] efi: mem06: [Boot Data | | | | | | | | |WB|WT|WC|UC] range=[0x0000000000820000-0x00000000012fffff] (10MB)
> [ 0.000000] efi: mem07: [Conventional Memory| | | | | | | | |WB|WT|WC|UC] range=[0x0000000001300000-0x0000000001ffffff] (13MB)
> [ 0.000000] efi: mem08: [Loader Data | | | | | | | | |WB|WT|WC|UC] range=[0x0000000002000000-0x00000000036e3fff] (22MB)
> (From mem00 to mem08, belongs to node0)
> [ 0.000000] efi: mem09: [Conventional Memory| | | | | | | | |WB|WT|WC|UC] range=[0x00000000036e4000-0x000000003d626fff] (927MB)
> (mem09 has part of node0 and part of node1, but not the whole of node0 and node1)
> [ 0.000000] efi: mem10: [Loader Data | | | | | | | | |WB|WT|WC|UC] range=[0x000000003d627000-0x000000003fffffff] (41MB)
> (part of node1 and part of node2)
> [ 0.000000] efi: mem11: [Conventional Memory| | | | | | | | |WB|WT|WC|UC] range=[0x0000000040000000-0x000000008c92dfff] (1225MB)
> [ 0.000000] efi: mem12: [Loader Data | | | | | | | | |WB|WT|WC|UC] range=[0x000000008c92e000-0x00000000bbfbdfff] (758MB)
> [ 0.000000] efi: mem13: [Boot Data | | | | | | | | |WB|WT|WC|UC] range=[0x00000000bbfbe000-0x00000000bbfddfff] (0MB)
> [ 0.000000] efi: mem14: [Conventional Memory| | | | | | | | |WB|WT|WC|UC] range=[0x00000000bbfde000-0x00000000be350fff] (35MB)
> [ 0.000000] efi: mem15: [Loader Data | | | | | | | | |WB|WT|WC|UC] range=[0x00000000be351000-0x00000000be579fff] (2MB)
> [ 0.000000] efi: mem16: [Loader Code | | | | | | | | |WB|WT|WC|UC] range=[0x00000000be57a000-0x00000000be6a0fff] (1MB)
> [ 0.000000] efi: mem17: [Boot Data | | | | | | | | |WB|WT|WC|UC] range=[0x00000000be6a1000-0x00000000beb21fff] (4MB)
> [ 0.000000] efi: mem18: [Boot Code | | | | | | | | |WB|WT|WC|UC] range=[0x00000000beb22000-0x00000000bed95fff] (2MB)
> [ 0.000000] efi: mem19: [Runtime Data |RUN| | | | | | | |WB|WT|WC|UC] range=[0x00000000bed96000-0x00000000bed9afff] (0MB)
> [ 0.000000] efi: mem20: [Runtime Code |RUN| | | | | | | |WB|WT|WC|UC] range=[0x00000000bed9b000-0x00000000beda1fff] (0MB)
> [ 0.000000] efi: mem21: [Runtime Data |RUN| | | | | | | |WB|WT|WC|UC] range=[0x00000000beda2000-0x00000000beda6fff] (0MB)
> [ 0.000000] efi: mem22: [Runtime Code |RUN| | | | | | | |WB|WT|WC|UC] range=[0x00000000beda7000-0x00000000bedacfff] (0MB)
> [ 0.000000] efi: mem23: [Runtime Data |RUN| | | | | | | |WB|WT|WC|UC] range=[0x00000000bedad000-0x00000000bedb1fff] (0MB)
> [ 0.000000] efi: mem24: [Runtime Code |RUN| | | | | | | |WB|WT|WC|UC] range=[0x00000000bedb2000-0x00000000bedbafff] (0MB)
> [ 0.000000] efi: mem25: [Runtime Data |RUN| | | | | | | |WB|WT|WC|UC] range=[0x00000000bedbb000-0x00000000bedbffff] (0MB)
> [ 0.000000] efi: mem26: [Runtime Code |RUN| | | | | | | |WB|WT|WC|UC] range=[0x00000000bedc0000-0x00000000bedc6fff] (0MB)
> [ 0.000000] efi: mem27: [Runtime Data |RUN| | | | | | | |WB|WT|WC|UC] range=[0x00000000bedc7000-0x00000000bede6fff] (0MB)
> [ 0.000000] efi: mem28: [Conventional Memory| | | | | | | | |WB|WT|WC|UC] range=[0x00000000bede7000-0x00000000bf07efff] (2MB)
> [ 0.000000] efi: mem29: [Boot Data | | | | | | | | |WB|WT|WC|UC] range=[0x00000000bf07f000-0x00000000bf3c3fff] (3MB)
> [ 0.000000] efi: mem30: [Conventional Memory| | | | | | | | |WB|WT|WC|UC] range=[0x00000000bf3c4000-0x00000000bf3cdfff] (0MB)
> [ 0.000000] efi: mem31: [Boot Data | | | | | | | | |WB|WT|WC|UC] range=[0x00000000bf3ce000-0x00000000bfce6fff] (9MB)
> [ 0.000000] efi: mem32: [Conventional Memory| | | | | | | | |WB|WT|WC|UC] range=[0x00000000bfce7000-0x00000000bfce8fff] (0MB)
> [ 0.000000] efi: mem33: [Boot Code | | | | | | | | |WB|WT|WC|UC] range=[0x00000000bfce9000-0x00000000bfe66fff] (1MB)
> [ 0.000000] efi: mem34: [Runtime Code |RUN| | | | | | | |WB|WT|WC|UC] range=[0x00000000bfe67000-0x00000000bfe96fff] (0MB)
> [ 0.000000] efi: mem35: [Runtime Data |RUN| | | | | | | |WB|WT|WC|UC] range=[0x00000000bfe97000-0x00000000bfebafff] (0MB)
> [ 0.000000] efi: mem36: [Reserved | | | | | | | | |WB|WT|WC|UC] range=[0x00000000bfebb000-0x00000000bfebefff] (0MB)
> [ 0.000000] efi: mem37: [ACPI Reclaim Memory| | | | | | | | |WB|WT|WC|UC] range=[0x00000000bfebf000-0x00000000bfec6fff] (0MB)
> [ 0.000000] efi: mem38: [ACPI Memory NVS | | | | | | | | |WB|WT|WC|UC] range=[0x00000000bfec7000-0x00000000bfecafff] (0MB)
> [ 0.000000] efi: mem39: [Boot Data | | | | | | | | |WB|WT|WC|UC] range=[0x00000000bfecb000-0x00000000bffcffff] (1MB)
> [ 0.000000] efi: mem40: [Runtime Data |RUN| | | | | | | |WB|WT|WC|UC] range=[0x00000000bffd0000-0x00000000bffeffff] (0MB)
> [ 0.000000] efi: mem41: [Conventional Memory| | | | | | | | |WB|WT|WC|UC] range=[0x00000000bfff0000-0x00000000bfffffff] (0MB)
> [ 0.000000] efi: mem42: [Runtime Data |RUN| | | | | | | | | | |UC] range=[0x00000000ffe00000-0x00000000ffffffff] (2MB)
> [ 0.000000] efi: mem43: [Conventional Memory| | | | | | | | |WB|WT|WC|UC] range=[0x0000000100000000-0x00000001787fffff] (1928MB)
>
>
> If the information is not enough, I can add more.
>
> Thanks,
> Chao Fan
>
> >
> >Thanks
> >Baoquan
> >
> >> One memory region in one node may contain several entries of e820 or
> >> efi sometimes, and one entry of e820 or efi may contain the memory in
> >> different nodes sometimes.
> >> It may split one node or one entry to several regions.
> >>
> >> Signed-off-by: Chao Fan <fanc.fnst@xxxxxxxxxxxxxx>
> >> ---
> >> arch/x86/boot/compressed/kaslr.c | 60 ++++++++++++++++++++++++++++++++++------
> >> 1 file changed, 52 insertions(+), 8 deletions(-)
> >>
> >> diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
> >> index 0a591c0023f1..fcd640fdeaed 100644
> >> --- a/arch/x86/boot/compressed/kaslr.c
> >> +++ b/arch/x86/boot/compressed/kaslr.c
> >> @@ -634,6 +634,54 @@ static void process_mem_region(struct mem_vector *entry,
> >> }
> >> }
> >>
> >> +static bool select_immovable_node(struct mem_vector region,
> >> + unsigned long long minimum,
> >> + unsigned long long image_size)
> >> +{
> >> + int i;
> >> +
> >> + /* If no immovable_mem stored, use region directly */
> >> + if (num_immovable_region == 0) {
> >> + process_mem_region(&region, minimum, image_size);
> >> +
> >> + if (slot_area_index == MAX_SLOT_AREA) {
> >> + debug_putstr("Aborted memmap scan (slot_areas full)!\n");
> >> + return 1;
> >> + }
> >> + } else {
> >> + /*
> >> + * Walk all immovable regions, and filter the intersection
> >> + * to process_mem_region.
> >> + */
> >> + for (i = 0; i < num_immovable_region; i++) {
> >> + struct mem_vector entry;
> >> + unsigned long long start, end, select_end, region_end;
> >> +
> >> + region_end = region.start + region.size - 1;
> >> + start = immovable_mem[i].start;
> >> + end = start + immovable_mem[i].size - 1;
> >> +
> >> + if (region_end < start || region.start > end)
> >> + continue;
> >> +
> >> + /* May split one region to several entries. */
> >> + entry.start = start > region.start ?
> >> + start : region.start;
> >> + select_end = end > region_end ? region_end : end;
> >> +
> >> + entry.size = select_end - entry.start + 1;
> >> +
> >> + process_mem_region(&entry, minimum, image_size);
> >> +
> >> + if (slot_area_index == MAX_SLOT_AREA) {
> >> + debug_putstr("Aborted memmap scan (slot_areas full)!\n");
> >> + return 1;
> >> + }
> >> + }
> >> + }
> >> + return 0;
> >> +}
> >> +
> >> #ifdef CONFIG_EFI
> >> /*
> >> * Returns true if mirror region found (and must have been processed
> >> @@ -699,11 +747,9 @@ process_efi_entries(unsigned long minimum, unsigned long image_size)
> >>
> >> region.start = md->phys_addr;
> >> region.size = md->num_pages << EFI_PAGE_SHIFT;
> >> - process_mem_region(&region, minimum, image_size);
> >> - if (slot_area_index == MAX_SLOT_AREA) {
> >> - debug_putstr("Aborted EFI scan (slot_areas full)!\n");
> >> +
> >> + if (select_immovable_node(region, minimum, image_size))
> >> break;
> >> - }
> >> }
> >> return true;
> >> }
> >> @@ -730,11 +776,9 @@ static void process_e820_entries(unsigned long minimum,
> >> continue;
> >> region.start = entry->addr;
> >> region.size = entry->size;
> >> - process_mem_region(&region, minimum, image_size);
> >> - if (slot_area_index == MAX_SLOT_AREA) {
> >> - debug_putstr("Aborted e820 scan (slot_areas full)!\n");
> >> +
> >> + if (select_immovable_node(region, minimum, image_size))
> >> break;
> >> - }
> >> }
> >> }
> >>
> >> --
> >> 2.13.6
> >>
> >>
> >>
> >
> >
>
>