Re: [PATCH v4 3/4] x86/boot: Get the max address from SRAT

From: Baoquan He
Date: Sun Nov 03 2019 - 19:33:43 EST


On 11/01/19 at 09:09pm, Masayoshi Mizuma wrote:
> From: Masayoshi Mizuma <m.mizuma@xxxxxxxxxxxxxx>
>
> Get the max address from SRAT and write it into boot_params->max_addr.
>
> Signed-off-by: Masayoshi Mizuma <m.mizuma@xxxxxxxxxxxxxx>
> ---
> arch/x86/boot/compressed/acpi.c | 26 ++++++++++++++++++++------
> 1 file changed, 20 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/boot/compressed/acpi.c b/arch/x86/boot/compressed/acpi.c
> index a0f81438a..764206c23 100644
> --- a/arch/x86/boot/compressed/acpi.c
> +++ b/arch/x86/boot/compressed/acpi.c
> @@ -362,17 +362,25 @@ static unsigned long get_acpi_srat_table(void)
> return 0;
> }
>
> -static void subtable_parse(struct acpi_subtable_header *sub_table, int *num)
> +static unsigned long subtable_parse(struct acpi_subtable_header *sub_table,
> + int *num)
> {
> struct acpi_srat_mem_affinity *ma;
> + unsigned long addr = 0;
>
> ma = (struct acpi_srat_mem_affinity *)sub_table;
>
> - if (!(ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && ma->length) {
> - immovable_mem[*num].start = ma->base_address;
> - immovable_mem[*num].size = ma->length;
> - (*num)++;
> + if (ma->length) {
> + if (ma->flags & ACPI_SRAT_MEM_HOT_PLUGGABLE)
> + addr = ma->base_address + ma->length;
> + else {
> + immovable_mem[*num].start = ma->base_address;
> + immovable_mem[*num].size = ma->length;
> + (*num)++;

Here maybe add code comment or doc above the subtable_parse() to explain
why we only get the end address of hotpluggable region. We assume hot
pluggable memory board will be added above the existed system RAM,
right?

Otherwise, this patch looks good to me. Thanks.

Acked-by: Baoquan He <bhe@xxxxxxxxxx>

Thanks
Baoquan

> + }
> }
> +
> + return addr;
> }
>
> /**
> @@ -391,6 +399,7 @@ int count_immovable_mem_regions(void)
> struct acpi_subtable_header *sub_table;
> struct acpi_table_header *table_header;
> char arg[MAX_ACPI_ARG_LENGTH];
> + unsigned long max_addr = 0, addr;
> int num = 0;
>
> if (cmdline_find_option("acpi", arg, sizeof(arg)) == 3 &&
> @@ -409,7 +418,9 @@ int count_immovable_mem_regions(void)
> sub_table = (struct acpi_subtable_header *)table;
> if (sub_table->type == ACPI_SRAT_TYPE_MEMORY_AFFINITY) {
>
> - subtable_parse(sub_table, &num);
> + addr = subtable_parse(sub_table, &num);
> + if (addr > max_addr)
> + max_addr = addr;
>
> if (num >= MAX_NUMNODES*2) {
> debug_putstr("Too many immovable memory regions, aborting.\n");
> @@ -418,6 +429,9 @@ int count_immovable_mem_regions(void)
> }
> table += sub_table->length;
> }
> +
> + boot_params->max_addr = max_addr;
> +
> return num;
> }
> #endif /* CONFIG_RANDOMIZE_BASE && CONFIG_MEMORY_HOTREMOVE */
> --
> 2.20.1
>