x86/boot/KASLR: Parse ACPI table and limit kaslr in immovable memory
Subsystems (4)
v11 cover x86/boot/KASLR: Parse ACPI table and limit kaslr in immovable memory
***Background:
People reported that kaslr may randomly chooses some positions which are located in movable memory regions. This will break memory hotplug feature and make the movable memory chosen by KASLR can't be removed.
***Solutions:
There should be a method to limit kaslr to choosing immovable memory regions, so there are 2 solutions:
1) Add a kernel parameter to specify the memory regions.
2) Get the information of memory hot-remove, then kaslr will know the right regions.
In method 2, information about memory hot-remove is in ACPI tables, which will be parsed after start_kernel(), kaslr can't get the information.
In method 1, users should know the regions address and specify in kernel parameter.
In the earliest time, I tried to dig ACPI tabls to solve this problem. But I didn't splite the code in 'compressed/' and ACPI code, so the patch is hard to follow so refused by community.
Somebody suggest to add a kernel parameter to specify the immovable memory so that limit kaslr in these regions. Then I make a new patchset. After several versions, Ingo gave a suggestion:
https://www.mail-archive.com/[email protected]/msg1634024.html
Follow Ingo's suggestion, imitate the ACPI code to parse the acpi tables, so that the kaslr can get necessary memory information in ACPI tables.
I think ACPI code is an independent part, so imitate the codes and functions to 'compressed/' directory, so that kaslr won't influence the initialization of ACPI.
PATCH 1/7 Add efi_get_rsdp_addr() to dig out RSDP from EFI table when
booting from EFI.
PATCH 2/7 Add bios_get_rsdp_addr() to search RSDP in memory when EFI
table not found.
PATCH 3/7 Add get_acpi_rsdp() to parse RSDP in cmdline from kexec PATCH 4/7 Dig out SRAT table from RSDP and walk SRAT table to store
the immovable memory regions.
PATCH 5/7 Calculate the intersection between memory regions from e820/efi
memory table and immovable memory regions. Limit KASLR choose these regions for randomization.
v1->v2:
- Simplify some code.
Follow Baoquan He's suggestion:
- Reuse the head file of acpi code.
v2->v3:
- Test in more conditions, so remove the 'RFC' tag.
- Change some comments.
v3->v4:
Follow Thomas Gleixner's suggetsion:
- Put the whole efi related function into #define CONFIG_EFI and return false in the other stub.
v4->v5:
Follow Dou Liyang's suggestion:
- Add more comments about some functions based on kernel code.
- Change some typo in comments.
- Clean useless variable.
- Add check for the boundary of array.
- Add check for 'movable_node' parameter
v5->v6:
Follow Baoquan He's suggestion:
- Change some log.
- Add the check for acpi_rsdp
- Change some code logical to make code clear
v6->v7:
Follow Rafael's suggestion:
- Add more comments and patch log.
Follow test robot's suggestion:
- Add "static" tag for function
v7-v8:
Follow Kees Cook's suggestion:
- Use mem_overlaps() to check memory region.
- Use #ifdef in the definition of function.
v8-v9:
Follow Boris' suggestion:
- Change code style.
- Splite PATCH 1/3 to more path.
- Introduce some new function
- Use existing function to rework some code
Follow Masayoshi's suggetion:
- Make code more readable
v9->v10:
Follow Baoquan's suggestion:
- Change some log
- Merge last two patch together.
v10->v11:
Follow Boris' suggestion:
- Link kstrtoull() instead of copying it.
- Drop the useless wraped function.
Any comments will be welcome.
Chao Fan (5):
x86/boot: Add efi_get_rsdp_addr() to dig out RSDP from EFI table x86/boot: Add bios_get_rsdp_addr() to search RSDP in memory x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec x86/boot: Dig out SRAT table from RSDP and find immovable memory x86/boot/KASLR: Walk srat tables to filter immovable memory
arch/x86/boot/compressed/Makefile | 4 + arch/x86/boot/compressed/acpitb.c | 367 ++++++++++++++++++++++++++++++ arch/x86/boot/compressed/kaslr.c | 81 +++++-- arch/x86/boot/compressed/misc.h | 15 ++ arch/x86/boot/string.h | 4 + lib/kstrtox.c | 4 + 6 files changed, 460 insertions(+), 15 deletions(-) create mode 100644 arch/x86/boot/compressed/acpitb.c
Signature · 1 line
2.19.1
PATCH v11 1/5 x86/boot: Add efi_get_rsdp_addr() to dig out RSDP from EFI table
In order to parse SRAT table and get memory information, RSDP pointer should be found. In kernel, there are three methods to get RSDP:
EFI condition, BIOS condition and KEXEC condition. The first works for EFI condition.
Imitate ACPI code and EFI code to dig RSDP pointer from EFI tables.
Process: boot_param->systab->efi_config_table->RSDP. Based on efi_init(), efi_config_init(), efi_config_parse_tables().
--- arch/x86/boot/compressed/acpitb.c | 96 +++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 arch/x86/boot/compressed/acpitb.c
arch/x86/boot/compressed/acpitb.c new file +96 -0
@@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0 +#define BOOT_CTYPE_H +#include "misc.h" +#include "error.h" + +#include <linux/efi.h> +#include <asm/efi.h> +#include <linux/numa.h> +#include <linux/acpi.h> + +/* Search EFI table for RSDP table. */ +static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr) +{ +#ifdef CONFIG_EFI +efi_system_table_t *systab; +bool efi_64 = false; +void *config_tables; +struct efi_info *e; +char *sig; +int size; +int i; + + e = &boot_params->efi_info; + sig = (char *)&e->efi_loader_signature; + +if (!strncmp (sig,EFI64_LOADER_SIGNATURE ,4 )) + efi_64 = true; +else if (!strncmp (sig,EFI32_LOADER_SIGNATURE ,4 )) + efi_64 = false; +else { +debug_putstr ("Wrong EFI loader signature.\n" ); +return ; + } + +/* Get systab from boot params. Based on efi_init(). */ +#ifdef CONFIG_X86_64 + systab = (efi_system_table_t *)( + e->efi_systab | ((__u64 )e->efi_systab_hi<<32 )); +#else +if (e->efi_systab_hi || e->efi_memmap_hi) { +debug_putstr ("Table located above 4GB. EFI should be disabled.\n" ); +return ; + } + systab = (efi_system_table_t *)e->efi_systab; +#endif + +if (!systab) +return ; + +/* +* Get EFI tables from systab. Based on efi_config_init() and +* efi_config_parse_tables(). Only dig out the config_table. +*/ + size = efi_64 ?sizeof (efi_config_table_64_t) : +sizeof (efi_config_table_32_t); + +for (i =0 ; i < systab->nr_tables; i++) { +efi_guid_t guid; +unsigned long table; + + config_tables = (void *)(systab->tables + size * i); +if (efi_64) { +efi_config_table_64_t *tmp_table; + + tmp_table = (efi_config_table_64_t *)config_tables; + guid = tmp_table->guid; + table = tmp_table->table; +#ifndef CONFIG_64BIT +if (table >>32 ) { +debug_putstr ("Table located above 4G. EFI should be disabled.\n" ); +return ; + } +#endif + }else { +efi_config_table_32_t *tmp_table; + + tmp_table = (efi_config_table_32_t *)config_tables; + guid = tmp_table->guid; + table = tmp_table->table; + } + +/* +* Get RSDP from EFI tables. +* If ACPI20 table found, use it. +* If ACPI20 table not found, but ACPI table found, +* use the ACPI table. +*/ +if (!(efi_guidcmp (guid,ACPI_TABLE_GUID ))) { + *rsdp_addr = (acpi_physical_address )table; + }else if (!(efi_guidcmp (guid,ACPI_20_TABLE_GUID ))) { + *rsdp_addr = (acpi_physical_address )table; +return ; + } + } +#endif +}
Signature · 1 line
2.19.1
Borislav Petkov
maintainerRe: [PATCH v11 1/5] x86/boot: Add efi_get_rsdp_addr() to dig out RSDP from EFI table
Quoted 4 lines · Chao Fan
In order to parse SRAT table and get memory information, RSDP pointer should be found. In kernel, there are three methods to get RSDP:
EFI condition, BIOS condition and KEXEC condition. The first works for EFI condition.
"condition"?
Also, please explain shortly what all those abbreviations mean: think of a person reading your commit message who doesn't have any clue from ACPI.
Quoted 18 lines
Imitate ACPI code and EFI code to dig RSDP pointer from EFI tables.
Process:boot_param->systab->efi_config_table->RSDP. Based onefi_init(),efi_config_init(),efi_config_parse_tables().Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/acpitb.c | 96 +++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 arch/x86/boot/compressed/acpitb.carch/x86/boot/compressed/acpitb.c new file +2
-0@@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0 +#define BOOT_CTYPE_H
arch/x86/boot/compressed/acpitb.c line 12
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c new file +10
-0+#include "misc.h" +#include "error.h" + +#include <linux/efi.h> +#include <asm/efi.h> +#include <linux/numa.h> +#include <linux/acpi.h> + +/* Search EFI table for RSDP table. */ +static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr)
This is just silly: the function returns void and has a single parameter which is an *output* parameter?!
Why isn't the signature
static acpi_physical_address *efi_get_rsdp_addr(void)
instead?
arch/x86/boot/compressed/acpitb.c line 16
Quoted 4 lines
arch/x86/boot/compressed/acpitb.c new file +4
-0+{ +#ifdef CONFIG_EFI +efi_system_table_t *systab; +bool efi_64 = false;
You're setting it below already, why here too?
Quoted 12 lines
arch/x86/boot/compressed/acpitb.c new file +12
-0+void *config_tables; +struct efi_info *e; +char *sig; +int size; +int i; + + e = &boot_params->efi_info; + sig = (char *)&e->efi_loader_signature; + +if (!strncmp (sig,EFI64_LOADER_SIGNATURE ,4 )) + efi_64 = true; +else if (!strncmp (sig,EFI32_LOADER_SIGNATURE ,4 ))
arch/x86/boot/compressed/acpitb.c line 38
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c new file +10
-0+ efi_64 = false; + else { +debug_putstr ("Wrong EFI loader signature.\n" ); +return ; + } + +/* Get systab from boot params. Based on efi_init(). */ +#ifdef CONFIG_X86_64 + systab = (efi_system_table_t *)( + e->efi_systab | ((__u64 )e->efi_systab_hi<<32 ));
No ugly line breaks with open braces trailing like that, pls - just let it stick out.
arch/x86/boot/compressed/acpitb.c line 41
Quoted 3 lines
arch/x86/boot/compressed/acpitb.c new file +3
-0+#else +if (e->efi_systab_hi || e->efi_memmap_hi) { +debug_putstr ("Table located above 4GB. EFI should be disabled.\n" );
You need to say here what really happens here:
debug_putstr("Error getting RSDP address: EFI system table located above 4GB.\n");The same below.
Quoted 8 lines
arch/x86/boot/compressed/acpitb.c new file +8
-0+ return; + } + systab = (efi_system_table_t *)e->efi_systab; +#endif + +if (!systab) +return ; +
arch/x86/boot/compressed/acpitb.c line 59
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c new file +10
-0+/* +* Get EFI tables from systab. Based on efi_config_init() and +* efi_config_parse_tables(). Only dig out the config_table. +*/ + size = efi_64 ?sizeof (efi_config_table_64_t) : +sizeof (efi_config_table_32_t); + +for (i =0 ; i < systab->nr_tables; i++) { +efi_guid_t guid; +unsigned long table;
Put the void *config_tables declaration here.
arch/x86/boot/compressed/acpitb.c line 68
Quoted 9 lines
arch/x86/boot/compressed/acpitb.c new file +9
-0+ + config_tables = (void *)(systab->tables + size * i); +if (efi_64) { +efi_config_table_64_t *tmp_table; + + tmp_table = (efi_config_table_64_t *)config_tables; + guid = tmp_table->guid; + table = tmp_table->table; +#ifndef CONFIG_64BIT
Above you have CONFIG_X86_64, here CONFIG_64BIT. Please use one only.
Also, use IS_ENABLED() instead.
Quoted 9 lines
arch/x86/boot/compressed/acpitb.c new file +9
-0+if (table >>32 ) { +debug_putstr ("Table located above 4G. EFI should be disabled.\n" ); +return ; + } +#endif + }else { +efi_config_table_32_t *tmp_table; + + tmp_table = (efi_config_table_32_t *)config_tables;
arch/x86/boot/compressed/acpitb.c line 87
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c new file +10
-0+ guid = tmp_table->guid; + table = tmp_table->table; + } + +/* +* Get RSDP from EFI tables. +* If ACPI20 table found, use it. +* If ACPI20 table not found, but ACPI table found, +* use the ACPI table. +*/
That comment is the opposite of what the code does. Also, why is that comment needed at all? If anything, it should say *why* ACPI_TABLE_GUID is preferred and then the fallback to ACPI_20_TABLE_GUID is done - not *what* it does. That's easily visible in the code.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [PATCH v11 1/5] x86/boot: Add efi_get_rsdp_addr() to dig out RSDP from EFI table
Quoted 11 lines · Borislav Petkov
Quoted 4 lines · Chao Fan
In order to parse SRAT table and get memory information, RSDP pointer should be found. In kernel, there are three methods to get RSDP:
EFI condition, BIOS condition and KEXEC condition. The first works for EFI condition."condition"?
Also, please explain shortly what all those abbreviations mean: think of a person reading your commit message who doesn't have any clue from ACPI.
I will try to improve in next version.
Quoted 33 lines
Quoted 19 lines
Imitate ACPI code and EFI code to dig RSDP pointer from EFI tables.
Process:boot_param->systab->efi_config_table->RSDP. Based onefi_init(),efi_config_init(),efi_config_parse_tables().Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/acpitb.c | 96 +++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 arch/x86/boot/compressed/acpitb.carch/x86/boot/compressed/acpitb.c new file +2
-0@@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0 +#define BOOT_CTYPE_H arch/x86/boot/compressed/acpitb.c line 12
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c new file +10
-0+#include "misc.h" +#include "error.h" + +#include <linux/efi.h> +#include <asm/efi.h> +#include <linux/numa.h> +#include <linux/acpi.h> + +/* Search EFI table for RSDP table. */ +static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr)This is just silly: the function returns void and has a single parameter which is an *output* parameter?!
Quoted 5 lines
Why isn't the signature
static
acpi_physical_address*efi_get_rsdp_addr(void)instead?
I will change the function style.
Quoted 7 lines
arch/x86/boot/compressed/acpitb.c line 16
Quoted 5 lines
arch/x86/boot/compressed/acpitb.c new file +4
-0+{ +#ifdef CONFIG_EFI +efi_system_table_t *systab; +bool efi_64 = false;You're setting it below already, why here too?
I will drop.
Quoted 18 lines
Quoted 18 lines
arch/x86/boot/compressed/acpitb.c new file +17
-0+void *config_tables; +struct efi_info *e; +char *sig; +int size; +int i; + + e = &boot_params->efi_info; + sig = (char *)&e->efi_loader_signature; + +if (!strncmp (sig,EFI64_LOADER_SIGNATURE ,4 )) + efi_64 = true; +else if (!strncmp (sig,EFI32_LOADER_SIGNATURE ,4 )) + efi_64 = false; +else { +debug_putstr ("Wrong EFI loader signature.\n" ); +return ; + }
Quoted 8 lines
arch/x86/boot/compressed/acpitb.c line 38
Quoted 5 lines
arch/x86/boot/compressed/acpitb.c new file +5
-0+ +/* Get systab from boot params. Based on efi_init(). */ +#ifdef CONFIG_X86_64 + systab = (efi_system_table_t *)( + e->efi_systab | ((__u64 )e->efi_systab_hi<<32 ));No ugly line breaks with open braces trailing like that, pls - just let it stick out.
Thanks for this suggestion.
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c line 41
Quoted 4 lines
arch/x86/boot/compressed/acpitb.c new file +3
-0+#else +if (e->efi_systab_hi || e->efi_memmap_hi) { +debug_putstr ("Table located above 4GB. EFI should be disabled.\n" );You need to say here what really happens here:
debug_putstr("Error getting RSDP address: EFI system table located above 4GB.\n");The same below.
I will change all the all the same message.
Quoted 13 lines
Quoted 13 lines
arch/x86/boot/compressed/acpitb.c new file +12
-0+ return; + } + systab = (efi_system_table_t *)e->efi_systab; +#endif + +if (!systab) +return ; + +/* +* Get EFI tables from systab. Based on efi_config_init() and +* efi_config_parse_tables(). Only dig out the config_table. +*/
Quoted 8 lines
arch/x86/boot/compressed/acpitb.c line 59
Quoted 6 lines
arch/x86/boot/compressed/acpitb.c new file +6
-0+ size = efi_64 ?sizeof (efi_config_table_64_t) : +sizeof (efi_config_table_32_t); + +for (i =0 ; i < systab->nr_tables; i++) { +efi_guid_t guid; +unsigned long table;Put the void
*config_tablesdeclaration here.
OK.
Quoted 13 lines
arch/x86/boot/compressed/acpitb.c line 68
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c new file +9
-0+ + config_tables = (void *)(systab->tables + size * i); +if (efi_64) { +efi_config_table_64_t *tmp_table; + + tmp_table = (efi_config_table_64_t *)config_tables; + guid = tmp_table->guid; + table = tmp_table->table; +#ifndef CONFIG_64BIT Above you have
CONFIG_X86_64, hereCONFIG_64BIT. Please use one only.
Quoted 1 line
Also, use
IS_ENABLED()instead.
OK.
Quoted 17 lines
Quoted 17 lines
arch/x86/boot/compressed/acpitb.c new file +16
-0+if (table >>32 ) { +debug_putstr ("Table located above 4G. EFI should be disabled.\n" ); +return ; + } +#endif + }else { +efi_config_table_32_t *tmp_table; + + tmp_table = (efi_config_table_32_t *)config_tables; + guid = tmp_table->guid; + table = tmp_table->table; + } + +/* +* Get RSDP from EFI tables. +* If ACPI20 table found, use it.
Quoted 8 lines
arch/x86/boot/compressed/acpitb.c line 87
Quoted 3 lines
arch/x86/boot/compressed/acpitb.c new file +3
-0+* If ACPI20 table not found, but ACPI table found, +* use the ACPI table. +*/ That comment is the opposite of what the code does. Also, why is that comment needed at all? If anything, it should say *why*
ACPI_TABLE_GUIDis preferred and then the fallback toACPI_20_TABLE_GUIDis done - not *what* it does. That's easily visible in the code.
I will drop the comment.
Thanks,
Chao Fan
Quoted 10 lines
Thx.
Signature · 4 lines
Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.
PATCH v11 2/5 x86/boot: Add bios_get_rsdp_addr() to search RSDP in memory
In reply to Chao FanImitate ACPI code to search RSDP pointer from memory.
Walk memory and check the signature until get the RSDP signature. Based on acpi_tb_scan_memory_for_rsdp() and acpi_find_root_pointer(). If didn't get RSDP from EFI table, will run this function.
Used for later patch to dig out SRAT table and get the memory information. And figure out the immovable memory regions to avoid KASLR extracts kernel on movable memory, slove the conflict between KASLR and movable_node feature.
--- arch/x86/boot/compressed/acpitb.c | 106 ++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+)
arch/x86/boot/compressed/acpitb.c +106 -0
@@ -94,3 +94,109 @@ static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) }#endif } + +static u8 compute_checksum (u8 *buffer,u32 length) +{ +u8 sum =0 ; +u8 *end = buffer + length; + +while (buffer < end) + sum = (u8)(sum + *(buffer++)); + +return sum; +} + +/* +* Used to search a block of memory for the RSDP signature. +* Return Pointer to the RSDP if found, otherwise NULL. +* Based on acpi_tb_scan_memory_for_rsdp(). +*/ +static u8 *scan_mem_for_rsdp (u8 *start,u32 length) +{ +struct acpi_table_rsdp *rsdp; +u8 *end; +u8 *rover; + + end = start + length; + +/* Search from given start address for the requested length */ +for (rover = start; rover < end; rover +=ACPI_RSDP_SCAN_STEP ) { +/* +* The RSDP signature and checksum must both be correct +* Note: Sometimes there exists more than one RSDP in memory; +* the valid RSDP has a valid checksum, all others have an +* invalid checksum. +*/ + rsdp = (struct acpi_table_rsdp *)rover; + +/* Nope, BAD Signature */ +if (!ACPI_VALIDATE_RSDP_SIG (rsdp->signature)) +continue ; + +/* Check the standard checksum */ +if (compute_checksum ((u8 *) rsdp,ACPI_RSDP_CHECKSUM_LENGTH )) +continue ; + +/* Check extended checksum if table version >= 2 */ +if ((rsdp->revision >=2 ) && + (compute_checksum ((u8 *) rsdp,ACPI_RSDP_XCHECKSUM_LENGTH ))) +continue ; + +/* Sig and checksum valid, we have found a real RSDP */ +return rover; + } +return NULL ; +} + +/* +* Used to search RSDP physical address. +* Based on acpi_find_root_pointer(). Since only use physical address +* in this period, so there is no need to do the memory map jobs. +*/ +static void bios_get_rsdp_addr (acpi_physical_address *rsdp_addr) +{ +struct acpi_table_rsdp *rsdp; +u8 *table_ptr; +u8 *mem_rover; +u32 address; + +/* +* Get the location of the Extended BIOS Data Area (EBDA) +* Since we use physical address directely, so +* acpi_os_map_memory() and acpi_os_unmap_memory() are +* not needed here. +*/ + table_ptr = (u8 *)ACPI_EBDA_PTR_LOCATION ; + *(u32 *)(void *)&address = *(u16 *)(void *)table_ptr; + address <<=4 ; + table_ptr = (u8 *)address; + +/* +* Search EBDA paragraphs (EBDA is required to be a minimum of +* 1K length) +*/ +if (address >0x400 ) { + mem_rover =scan_mem_for_rsdp (table_ptr,ACPI_EBDA_WINDOW_SIZE ); + +if (mem_rover) { + address += (u32 )ACPI_PTR_DIFF (mem_rover, table_ptr); + *rsdp_addr = (acpi_physical_address )address; +return ; + } + } + + table_ptr = (u8 *)ACPI_HI_RSDP_WINDOW_BASE ; + mem_rover =scan_mem_for_rsdp (table_ptr,ACPI_HI_RSDP_WINDOW_SIZE ); + +/* +* Search upper memory: 16-byte boundaries in E0000h-FFFFFh +* Since we use physical address directely, so +* acpi_os_map_memory() and acpi_os_unmap_memory() are +* not needed here. +*/ +if (mem_rover) { + address = (u32)(ACPI_HI_RSDP_WINDOW_BASE + +ACPI_PTR_DIFF (mem_rover, table_ptr)); + *rsdp_addr = (acpi_physical_address )address; + } +}
Signature · 1 line
2.19.1
Borislav Petkov
maintainerRe: [PATCH v11 2/5] x86/boot: Add bios_get_rsdp_addr() to search RSDP in memory
Quoted 4 lines · Chao Fan
Imitate ACPI code to search RSDP pointer from memory.
Walk memory and check the signature until get the RSDP signature. Based onacpi_tb_scan_memory_for_rsdp()andacpi_find_root_pointer(). If didn't get RSDP from EFI table, will run this function.
That's some very strange english. Please improve.
Quoted 3 lines
Used for later patch to dig out SRAT table and get the memory information. And figure out the immovable memory regions to avoid KASLR extracts kernel on movable memory, slove the
^^^^^^
Please introduce a spellchecker into your patch creation workflow.
Quoted 1 line
conflict between KASLR and
movable_nodefeature.
Btw, this paragraph could be used for a CONFIG_ item you could define for your particular use case. Because right now you have funnies like:
+#if (defined CONFIG_MEMORY_HOTREMOVE) && (defined CONFIG_RANDOMIZE_BASE) +vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/acpitb.o +#endif
where CONFIG_RANDOMIZE_BASE is repeated for no good reason.
But we'll see - need to get to the end of your patch series first.
Quoted 11 lines
Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/acpitb.c | 106 ++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+)arch/x86/boot/compressed/acpitb.c +0
-0@@ -94,3 +94,109 @@ static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) }
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 104
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +8
-0#endif } + +static u8 compute_checksum (u8 *buffer,u32 length) +{ +u8 sum =0 ; +u8 *end = buffer + length; + +while (buffer < end) + sum = (u8)(sum + *(buffer++));
What's that cast for?
Ah, this is the version in acpi_tb_checksum(). Well, I'd write this simply as:
sum += *(buffer++);
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 111
Quoted 7 lines
arch/x86/boot/compressed/acpitb.c +7
-0+ +return sum; +} + +/* +* Used to search a block of memory for the RSDP signature. +* Return Pointer to the RSDP if found, otherwise NULL.
"Returns pointer... "
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 118
Quoted 7 lines
arch/x86/boot/compressed/acpitb.c +7
-0+* Based on acpi_tb_scan_memory_for_rsdp(). +*/ +static u8 *scan_mem_for_rsdp (u8 *start,u32 length) +{ +struct acpi_table_rsdp *rsdp; +u8 *end; +u8 *rover;
rover?
Quoted 26 lines
arch/x86/boot/compressed/acpitb.c +26
-0+ + end = start + length; + +/* Search from given start address for the requested length */ +for (rover = start; rover < end; rover +=ACPI_RSDP_SCAN_STEP ) { +/* +* The RSDP signature and checksum must both be correct +* Note: Sometimes there exists more than one RSDP in memory; +* the valid RSDP has a valid checksum, all others have an +* invalid checksum. +*/ + rsdp = (struct acpi_table_rsdp *)rover; + +/* Nope, BAD Signature */ +if (!ACPI_VALIDATE_RSDP_SIG (rsdp->signature)) +continue ; + +/* Check the standard checksum */ +if (compute_checksum ((u8 *) rsdp,ACPI_RSDP_CHECKSUM_LENGTH )) +continue ; + +/* Check extended checksum if table version >= 2 */ +if ((rsdp->revision >=2 ) && + (compute_checksum ((u8 *) rsdp,ACPI_RSDP_XCHECKSUM_LENGTH ))) +continue ; +
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 154
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +10
-0+/* Sig and checksum valid, we have found a real RSDP */ +return rover; + } +return NULL ; +} + +/* +* Used to search RSDP physical address. +* Based on acpi_find_root_pointer(). Since only use physical address +* in this period, so there is no need to do the memory map jobs.
You mean: "All addresses used here are physical."?
"memory map jobs"?
Please be more careful when writing comments which are going to be read by other people. "jobs" means a lot of things and you don't want "jobs" in that context here.
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 156
Quoted 2 lines
arch/x86/boot/compressed/acpitb.c +2
-0+*/ +static void bios_get_rsdp_addr (acpi_physical_address *rsdp_addr)
Same remark as before: the function is void and you're returning through its parameter. Make it return acpi_physical_address instead.
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 160
Quoted 4 lines
arch/x86/boot/compressed/acpitb.c +4
-0+{ +struct acpi_table_rsdp *rsdp; +u8 *table_ptr; +u8 *mem_rover;
rover?
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 165
Quoted 5 lines
arch/x86/boot/compressed/acpitb.c +5
-0+u32 address; + +/* +* Get the location of the Extended BIOS Data Area (EBDA) +* Since we use physical address directely, so
It is "directly" - what about that spellchecker?
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 167
Quoted 2 lines
arch/x86/boot/compressed/acpitb.c +2
-0+* acpi_os_map_memory() and acpi_os_unmap_memory() are +* not needed here.
Why do you even need to say that here?
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 172
Quoted 5 lines
arch/x86/boot/compressed/acpitb.c +5
-0+*/ + table_ptr = (u8 *)ACPI_EBDA_PTR_LOCATION ; + *(u32 *)(void *)&address = *(u16 *)(void *)table_ptr; + address <<=4 ; + table_ptr = (u8 *)address;
arch/x86/boot/compressed/acpitb.c: In function ‘bios_get_rsdp_addr’:arch/x86/boot/compressed/acpitb.c:172:14: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
table_ptr = (u8 *)address;
^Also, that is some crazy casting here and I think you could use unsigned longs here for all the address arithmetic and cast to acpi_physical_address only at the end.
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 180
Quoted 8 lines
arch/x86/boot/compressed/acpitb.c +8
-0+ +/* +* Search EBDA paragraphs (EBDA is required to be a minimum of +* 1K length) +*/ +if (address >0x400 ) { + mem_rover =scan_mem_for_rsdp (table_ptr,ACPI_EBDA_WINDOW_SIZE ); +
Superfluous new line.
Quoted 6 lines
arch/x86/boot/compressed/acpitb.c +6
-0+if (mem_rover) { + address += (u32 )ACPI_PTR_DIFF (mem_rover, table_ptr); + *rsdp_addr = (acpi_physical_address )address; +return ; + } + }
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 196
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +10
-0+ + table_ptr = (u8 *)ACPI_HI_RSDP_WINDOW_BASE ; + mem_rover =scan_mem_for_rsdp (table_ptr,ACPI_HI_RSDP_WINDOW_SIZE ); + +/* +* Search upper memory: 16-byte boundaries in E0000h-FFFFFh +* Since we use physical address directely, so +* acpi_os_map_memory() and acpi_os_unmap_memory() are +* not needed here. +*/
And this comment needs to be repeated here because... ?
Quoted 7 lines
arch/x86/boot/compressed/acpitb.c +6
-0+if (mem_rover) { + address = (u32)(ACPI_HI_RSDP_WINDOW_BASE + +ACPI_PTR_DIFF (mem_rover, table_ptr)); + *rsdp_addr = (acpi_physical_address )address; + } +}
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [PATCH v11 2/5] x86/boot: Add bios_get_rsdp_addr() to search RSDP in memory
Quoted 6 lines · Borislav Petkov
Quoted 4 lines · Chao Fan
Imitate ACPI code to search RSDP pointer from memory.
Walk memory and check the signature until get the RSDP signature. Based onacpi_tb_scan_memory_for_rsdp()andacpi_find_root_pointer(). If didn't get RSDP from EFI table, will run this function.
Quoted 9 lines
That's some very strange english. Please improve.
Quoted 3 lines
Used for later patch to dig out SRAT table and get the memory information. And figure out the immovable memory regions to avoid KASLR extracts kernel on movable memory, slove the
^^^^^^Please introduce a spellchecker into your patch creation workflow.
Thanks.
Quoted 37 lines
Quoted 1 line
conflict between KASLR and
movable_nodefeature.Btw, this paragraph could be used for a
CONFIG_item you could define for your particular use case. Because right now you have funnies like:(quoted diff) +3
-0+#if (defined CONFIG_MEMORY_HOTREMOVE) && (defined CONFIG_RANDOMIZE_BASE) +vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/acpitb.o +#endifwhere
CONFIG_RANDOMIZE_BASEis repeated for no good reason.But we'll see - need to get to the end of your patch series first.
Quoted 11 lines
Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/acpitb.c | 106 ++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+)arch/x86/boot/compressed/acpitb.c +0
-0@@ -94,3 +94,109 @@ static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) }arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 104
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +8
-0#endif } + +static u8 compute_checksum (u8 *buffer,u32 length) +{ +u8 sum =0 ; +u8 *end = buffer + length; + +while (buffer < end) + sum = (u8)(sum + *(buffer++));What's that cast for?
Quoted 4 lines
Ah, this is the version in
acpi_tb_checksum(). Well, I'd write this simply as:sum += *(buffer++);
Thanks for your suggestion.
Quoted 21 lines
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 111
Quoted 8 lines
arch/x86/boot/compressed/acpitb.c +7
-0+ +return sum; +} + +/* +* Used to search a block of memory for the RSDP signature. +* Return Pointer to the RSDP if found, otherwise NULL. "Returns pointer... "
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 118
Quoted 7 lines
arch/x86/boot/compressed/acpitb.c +7
-0+* Based on acpi_tb_scan_memory_for_rsdp(). +*/ +static u8 *scan_mem_for_rsdp (u8 *start,u32 length) +{ +struct acpi_table_rsdp *rsdp; +u8 *end; +u8 *rover;rover?
Quoted 5 lines
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 123
Quoted 5 lines
arch/x86/boot/compressed/acpitb.c +5
-0+ + end = start + length; + +/* Search from given start address for the requested length */ +for (rover = start; rover < end; rover +=ACPI_RSDP_SCAN_STEP ) {
The 'rover' was named as 'mem_rover', but the length of this line is too long. So shorten it as 'rever' so that they can keep in one line.
Quoted 34 lines
Quoted 21 lines
arch/x86/boot/compressed/acpitb.c +21
-0+/* +* The RSDP signature and checksum must both be correct +* Note: Sometimes there exists more than one RSDP in memory; +* the valid RSDP has a valid checksum, all others have an +* invalid checksum. +*/ + rsdp = (struct acpi_table_rsdp *)rover; + +/* Nope, BAD Signature */ +if (!ACPI_VALIDATE_RSDP_SIG (rsdp->signature)) +continue ; + +/* Check the standard checksum */ +if (compute_checksum ((u8 *) rsdp,ACPI_RSDP_CHECKSUM_LENGTH )) +continue ; + +/* Check extended checksum if table version >= 2 */ +if ((rsdp->revision >=2 ) && + (compute_checksum ((u8 *) rsdp,ACPI_RSDP_XCHECKSUM_LENGTH ))) +continue ; +arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 154
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +10
-0+/* Sig and checksum valid, we have found a real RSDP */ +return rover; + } +return NULL ; +} + +/* +* Used to search RSDP physical address. +* Based on acpi_find_root_pointer(). Since only use physical address +* in this period, so there is no need to do the memory map jobs. You mean: "All addresses used here are physical."?
Quoted 5 lines
"memory map jobs"?
Please be more careful when writing comments which are going to be read by other people. "jobs" means a lot of things and you don't want "jobs" in that context here.
OK.
Quoted 7 lines
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 156
Quoted 3 lines
arch/x86/boot/compressed/acpitb.c +2
-0+*/ +static void bios_get_rsdp_addr (acpi_physical_address *rsdp_addr)Same remark as before: the function is void and you're returning through its parameter. Make it return
acpi_physical_addressinstead.
I will change all these functions.
Quoted 6 lines
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 160
Quoted 4 lines
arch/x86/boot/compressed/acpitb.c +4
-0+{ +struct acpi_table_rsdp *rsdp; +u8 *table_ptr; +u8 *mem_rover;rover?
This name came from ACPI driver code, acpi_find_root_pointer(). Used for the loop. If you have a better name, please tell me.
Quoted 9 lines
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 165
Quoted 6 lines
arch/x86/boot/compressed/acpitb.c +5
-0+u32 address; + +/* +* Get the location of the Extended BIOS Data Area (EBDA) +* Since we use physical address directely, so It is "directly" - what about that spellchecker?
Quoted 4 lines
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 167
Quoted 2 lines
arch/x86/boot/compressed/acpitb.c +2
-0+* acpi_os_map_memory() and acpi_os_unmap_memory() are +* not needed here. Why do you even need to say that here?
I will try to improve all the comment.
Quoted 9 lines
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 172
Quoted 6 lines
arch/x86/boot/compressed/acpitb.c +5
-0+*/ + table_ptr = (u8 *)ACPI_EBDA_PTR_LOCATION ; + *(u32 *)(void *)&address = *(u16 *)(void *)table_ptr; + address <<=4 ; + table_ptr = (u8 *)address;
arch/x86/boot/compressed/acpitb.c: In function ‘bios_get_rsdp_addr’:arch/x86/boot/compressed/acpitb.c:172:14: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
Quoted 6 lines
table_ptr = (u8 *)address; ^Also, that is some crazy casting here and I think you could use unsigned longs here for all the address arithmetic and cast to
acpi_physical_addressonly at the end.
That's a good suggestion.
Quoted 22 lines
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 180
Quoted 9 lines
arch/x86/boot/compressed/acpitb.c +8
-0+ +/* +* Search EBDA paragraphs (EBDA is required to be a minimum of +* 1K length) +*/ +if (address >0x400 ) { + mem_rover =scan_mem_for_rsdp (table_ptr,ACPI_EBDA_WINDOW_SIZE ); +Superfluous new line.
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +10
-0+if (mem_rover) { + address += (u32 )ACPI_PTR_DIFF (mem_rover, table_ptr); + *rsdp_addr = (acpi_physical_address )address; +return ; + } + } + + table_ptr = (u8 *)ACPI_HI_RSDP_WINDOW_BASE ; + mem_rover =scan_mem_for_rsdp (table_ptr,ACPI_HI_RSDP_WINDOW_SIZE ); +
Quoted 8 lines
arch/x86/boot/compressed/acpitb.c static void efi_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 196
Quoted 6 lines
arch/x86/boot/compressed/acpitb.c +6
-0+/* +* Search upper memory: 16-byte boundaries in E0000h-FFFFFh +* Since we use physical address directely, so +* acpi_os_map_memory() and acpi_os_unmap_memory() are +* not needed here. +*/ And this comment needs to be repeated here because... ?
I will try to improve all the comment.
Thanks,
Chao Fan
Quoted 16 lines
Quoted 8 lines
arch/x86/boot/compressed/acpitb.c +6
-0+if (mem_rover) { + address = (u32)(ACPI_HI_RSDP_WINDOW_BASE + +ACPI_PTR_DIFF (mem_rover, table_ptr)); + *rsdp_addr = (acpi_physical_address )address; + } +}Signature · 4 lines
Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.
Borislav Petkov
maintainerRe: [PATCH v11 2/5] x86/boot: Add bios_get_rsdp_addr() to search RSDP in memory
Quoted 2 lines · Chao Fan
The 'rover' was named as '
mem_rover', but the length of this line is too long. So shorten it as 'rever' so that they can keep in one line.
I still have no clue what "rover" or "rever" means...
Quoted 2 lines
This name came from ACPI driver code,
acpi_find_root_pointer(). Used for the loop. If you have a better name, please tell me.
I would if I knew what it meant. If you don't know either, then name it to something descriptive so that it is clear what it is when reading the code.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.PATCH v11 3/5 x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
In reply to Chao FanImitate setup_acpi_rsdp() for the early_param of 'acpi_rsdp'. KEXEC writes the RSDP pointer to cmdline for EFI booting. So if 'acpi_rsdp' found in cmdline, use it directely.
Since function kstrtoull() is needed, include it in arch/x86/boot/string.h. To solve the definition conflict problem, set BOOT_STRING tag to expose only kstrtoull() and functions used by it. Other functions in lib/kstrtox.c will be covered.
--- arch/x86/boot/compressed/acpitb.c | 26 ++++++++++++++++++++++++++ arch/x86/boot/string.h | 4 ++++ lib/kstrtox.c | 4 ++++ 3 files changed, 34 insertions(+)
arch/x86/boot/compressed/acpitb.c +26 -0
@@ -8,6 +8,12 @@#include <linux/numa.h> #include <linux/acpi.h> +#define STATIC +#include <linux/decompress/mm.h> + +#define BOOT_STRING +#include "../string.h" +/* Search EFI table for RSDP table. */ static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr) {
@@ -200,3 +206,23 @@ static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) *rsdp_addr = (acpi_physical_address )address; } } + +static void get_acpi_rsdp (acpi_physical_address *rsdp_addr) +{ +#ifdef CONFIG_KEXEC +unsigned long long res; +int len =0 ; +char *val; + + val =malloc (19 ); + len =cmdline_find_option ("acpi_rsdp" , val,19 ); + +if (len ==-1 ) +return ; + +if (len >0 ) { + val[len] =0 ; + *rsdp_addr = (acpi_physical_address )kstrtoull (val,16 , &res); + } +#endif +}
arch/x86/boot/string.h +4 -0
@@ -30,3 +30,7 @@ extern unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base);#endif /* BOOT_STRING_H */ + +#ifdef BOOT_STRING +#include "../../../lib/kstrtox.c" +#endif
lib/kstrtox.c +4 -0
@@ -126,6 +126,8 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res) }EXPORT_SYMBOL (kstrtoull); +#ifndef BOOT_STRING +/** * kstrtoll - convert a string to a long long * @s: The start of the string. The string must be null-terminated, and may also
@@ -408,3 +410,5 @@ kstrto_from_user(kstrtou16_from_user, kstrtou16, u16);kstrto_from_user (kstrtos16_from_user, kstrtos16, s16);kstrto_from_user (kstrtou8_from_user, kstrtou8, u8);kstrto_from_user (kstrtos8_from_user, kstrtos8, s8); + +#endif
Signature · 1 line
2.19.1
Re: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
Hi Boris,
I try to include lib/kstrtox.c in arch/x86/boot/string.c and define the kstrtoull() function in arch/x86/boot/string.h. But the definition problem is hard to solve, so I include it in arch/x86/boot/string.c directely.
Then use BOOT_STRING tag to cover other functions and only kstrtoull() is exposed.
I am not sure whether this is OK.
Thanks,
Chao Fan
Quoted 92 lines · Chao Fan
Imitate
setup_acpi_rsdp()for theearly_paramof 'acpi_rsdp'. KEXEC writes the RSDP pointer to cmdline for EFI booting. So if 'acpi_rsdp' found in cmdline, use it directely.Since function
kstrtoull()is needed, include it inarch/x86/boot/string.h. To solve the definition conflict problem, setBOOT_STRINGtag to expose onlykstrtoull()and functions used by it. Other functions inlib/kstrtox.cwill be covered.Signed-off-by Chao Fan <[email protected]>---
arch/x86/boot/compressed/acpitb.c | 26 ++++++++++++++++++++++++++ arch/x86/boot/string.h | 4 ++++ lib/kstrtox.c | 4 ++++ 3 files changed, 34 insertions(+)arch/x86/boot/compressed/acpitb.c +26
-0@@ -8,6 +8,12 @@#include <linux/numa.h> #include <linux/acpi.h> +#define STATIC +#include <linux/decompress/mm.h> + +#define BOOT_STRING +#include "../string.h" +/* Search EFI table for RSDP table. */ static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr) {@@ -200,3 +206,23 @@ static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) *rsdp_addr = (acpi_physical_address )address; } } + +static void get_acpi_rsdp (acpi_physical_address *rsdp_addr) +{ +#ifdef CONFIG_KEXEC +unsigned long long res; +int len =0 ; +char *val; + + val =malloc (19 ); + len =cmdline_find_option ("acpi_rsdp" , val,19 ); + +if (len ==-1 ) +return ; + +if (len >0 ) { + val[len] =0 ; + *rsdp_addr = (acpi_physical_address )kstrtoull (val,16 , &res); + } +#endif +}arch/x86/boot/string.h +4
-0@@ -30,3 +30,7 @@ extern unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base);#endif /* BOOT_STRING_H */ + +#ifdef BOOT_STRING +#include "../../../lib/kstrtox.c" +#endif lib/kstrtox.c +4
-0@@ -126,6 +126,8 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res) }EXPORT_SYMBOL (kstrtoull); +#ifndef BOOT_STRING +/** * kstrtoll - convert a string to a long long * @s: The start of the string. The string must be null-terminated, and may also @@ -408,3 +410,5 @@ kstrto_from_user(kstrtou16_from_user, kstrtou16, u16);kstrto_from_user (kstrtos16_from_user, kstrtos16, s16);kstrto_from_user (kstrtou8_from_user, kstrtou8, u8);kstrto_from_user (kstrtos8_from_user, kstrtos8, s8); + +#endif Signature · 1 line
2.19.1
Re: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
In reply to Chao FanHi Chao,
Quoted 10 lines · Chao Fan
Imitate
setup_acpi_rsdp()for theearly_paramof 'acpi_rsdp'. KEXEC writes the RSDP pointer to cmdline for EFI booting. So if 'acpi_rsdp' found in cmdline, use it directely.Since function
kstrtoull()is needed, include it inarch/x86/boot/string.h. To solve the definition conflict problem, setBOOT_STRINGtag to expose onlykstrtoull()and functions used by it. Other functions inlib/kstrtox.cwill be covered.
How about the following get_acpi_rsdp()...? It doesn't use kstrtoull().
static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) {
#ifdef CONFIG_KEXEC
unsigned long addr;
char val[32];
if (cmdline_find_option("acpi_rsdp", val, sizeof(val)) > 0) {
char *e;
if (!strncmp(val, "0x", 2)) {
addr = simple_strtoull(val + 2, &e, 16);
if ((addr == 0) || ((val + 2) == e))
return;
*rsdp_addr = (acpi_physical_address)addr;
}
}#endif
}
Thanks,
Masa
Quoted 85 lines
Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/acpitb.c | 26 ++++++++++++++++++++++++++ arch/x86/boot/string.h | 4 ++++ lib/kstrtox.c | 4 ++++ 3 files changed, 34 insertions(+)arch/x86/boot/compressed/acpitb.c +26
-0@@ -8,6 +8,12 @@#include <linux/numa.h> #include <linux/acpi.h> +#define STATIC +#include <linux/decompress/mm.h> + +#define BOOT_STRING +#include "../string.h" +/* Search EFI table for RSDP table. */ static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr) {@@ -200,3 +206,23 @@ static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) *rsdp_addr = (acpi_physical_address )address; } } + +static void get_acpi_rsdp (acpi_physical_address *rsdp_addr) +{ +#ifdef CONFIG_KEXEC +unsigned long long res; +int len =0 ; +char *val; + + val =malloc (19 ); + len =cmdline_find_option ("acpi_rsdp" , val,19 ); + +if (len ==-1 ) +return ; + +if (len >0 ) { + val[len] =0 ; + *rsdp_addr = (acpi_physical_address )kstrtoull (val,16 , &res); + } +#endif +}arch/x86/boot/string.h +4
-0@@ -30,3 +30,7 @@ extern unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base);#endif /* BOOT_STRING_H */ + +#ifdef BOOT_STRING +#include "../../../lib/kstrtox.c" +#endif lib/kstrtox.c +4
-0@@ -126,6 +126,8 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res) }EXPORT_SYMBOL (kstrtoull); +#ifndef BOOT_STRING +/** * kstrtoll - convert a string to a long long * @s: The start of the string. The string must be null-terminated, and may also @@ -408,3 +410,5 @@ kstrto_from_user(kstrtou16_from_user, kstrtou16, u16);kstrto_from_user (kstrtos16_from_user, kstrtos16, s16);kstrto_from_user (kstrtou8_from_user, kstrtou8, u8);kstrto_from_user (kstrtos8_from_user, kstrtos8, s8); + +#endif Signature · 1 line
2.19.1
Re: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
Quoted 32 lines · Masayoshi Mizuma
Hi Chao,
Quoted 10 lines · Chao Fan
Imitate
setup_acpi_rsdp()for theearly_paramof 'acpi_rsdp'. KEXEC writes the RSDP pointer to cmdline for EFI booting. So if 'acpi_rsdp' found in cmdline, use it directely.Since function
kstrtoull()is needed, include it inarch/x86/boot/string.h. To solve the definition conflict problem, setBOOT_STRINGtag to expose onlykstrtoull()and functions used by it. Other functions inlib/kstrtox.cwill be covered.How about the following
get_acpi_rsdp()...? It doesn't usekstrtoull().static void
get_acpi_rsdp(acpi_physical_address *rsdp_addr){#ifdef CONFIG_KEXEC unsigned long addr; char val[32]; if (cmdline_find_option("acpi_rsdp", val, sizeof(val)) > 0) { char *e; if (!strncmp(val, "0x", 2)) { addr = simple_strtoull(val + 2, &e, 16); if ((addr == 0) || ((val + 2) == e)) return; *rsdp_addr = (acpi_physical_address)addr; } }
Quoted 2 lines
#endif
}
Thanks for the suggestion.
I used this function. In the old version, Boris said simple_strtoull() is the old function and told me use the new kstrtoull().
Thanks,
Chao Fan
Quoted 91 lines
Thanks,
MasaQuoted 85 lines
Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/acpitb.c | 26 ++++++++++++++++++++++++++ arch/x86/boot/string.h | 4 ++++ lib/kstrtox.c | 4 ++++ 3 files changed, 34 insertions(+)arch/x86/boot/compressed/acpitb.c +26
-0@@ -8,6 +8,12 @@#include <linux/numa.h> #include <linux/acpi.h> +#define STATIC +#include <linux/decompress/mm.h> + +#define BOOT_STRING +#include "../string.h" +/* Search EFI table for RSDP table. */ static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr) {@@ -200,3 +206,23 @@ static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) *rsdp_addr = (acpi_physical_address )address; } } + +static void get_acpi_rsdp (acpi_physical_address *rsdp_addr) +{ +#ifdef CONFIG_KEXEC +unsigned long long res; +int len =0 ; +char *val; + + val =malloc (19 ); + len =cmdline_find_option ("acpi_rsdp" , val,19 ); + +if (len ==-1 ) +return ; + +if (len >0 ) { + val[len] =0 ; + *rsdp_addr = (acpi_physical_address )kstrtoull (val,16 , &res); + } +#endif +}arch/x86/boot/string.h +4
-0@@ -30,3 +30,7 @@ extern unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base);#endif /* BOOT_STRING_H */ + +#ifdef BOOT_STRING +#include "../../../lib/kstrtox.c" +#endif lib/kstrtox.c +4
-0@@ -126,6 +126,8 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res) }EXPORT_SYMBOL (kstrtoull); +#ifndef BOOT_STRING +/** * kstrtoll - convert a string to a long long * @s: The start of the string. The string must be null-terminated, and may also @@ -408,3 +410,5 @@ kstrto_from_user(kstrtou16_from_user, kstrtou16, u16);kstrto_from_user (kstrtos16_from_user, kstrtos16, s16);kstrto_from_user (kstrtou8_from_user, kstrtou8, u8);kstrto_from_user (kstrtos8_from_user, kstrtos8, s8); + +#endif Signature · 1 line
2.19.1
Re: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
Hi Chao and Boris,
Quoted 22 lines · Chao Fan
Quoted 18 lines · Masayoshi Mizuma
How about the following
get_acpi_rsdp()...? It doesn't usekstrtoull().static void
get_acpi_rsdp(acpi_physical_address *rsdp_addr){#ifdef CONFIG_KEXEC unsigned long addr; char val[32]; if (cmdline_find_option("acpi_rsdp", val, sizeof(val)) > 0) { char *e; if (!strncmp(val, "0x", 2)) { addr = simple_strtoull(val + 2, &e, 16); if ((addr == 0) || ((val + 2) == e)) return; *rsdp_addr = (acpi_physical_address)addr; } }Quoted 2 lines
#endif
}
Quoted 3 lines
Thanks for the suggestion.
I used this function. In the old version, Boris saidsimple_strtoull()is the old function and told me use the newkstrtoull().
I think it's not very good idea to use kstrtoull() in arch/x86/boot/compressed/* because some tricks are needed to use the function, looks like Chao is trying...
It is the simple way here to use simple_strtoull() defined in arch/x86/boot/boot.h, I think.
I know checkpatch.pl says an warning about simple_strtoull(), however, I believe the warning is for simple_strtoull() defined in lib/vsprintf.c.
Thanks,
Masa
Borislav Petkov
maintainerRe: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
Quoted 3 lines · Masayoshi Mizuma
I know checkpatch.pl says an warning about
simple_strtoull(), however, I believe the warning is forsimple_strtoull()defined inlib/vsprintf.c.
simple_strtoull is deprecated for various reasons. I'll take a look at Chao's patch soon.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Borislav Petkov
maintainerRe: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
In reply to Masayoshi MizumaQuoted 3 lines · Masayoshi Mizuma
I think it's not very good idea to use
kstrtoull()inarch/x86/boot/compressed/*because some tricks are needed to use the function, looks like Chao is trying...
Ok, I had a look at the patch. And frankly, I don't see anything wrong with the aspect of using kstrtoull() in the compressed stage too and getting rid of simple_strtoull().
So what are your reservations?
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
Quoted 10 lines · Borislav Petkov
Quoted 3 lines · Masayoshi Mizuma
I think it's not very good idea to use
kstrtoull()inarch/x86/boot/compressed/*because some tricks are needed to use the function, looks like Chao is trying...Ok, I had a look at the patch. And frankly, I don't see anything wrong with the aspect of using
kstrtoull()in the compressed stage too and getting rid ofsimple_strtoull().So what are your reservations?
Thank you for your checking.
I just felt the BOOT_STRING thing in lib/kstrtox.c confuses... I'm OK for now if it's applied your below comment.
Quoted 5 lines
lib/kstrtox.c int kstrtoull(const char *s, unsigned int base, unsigned long long *res) · line 127
Quoted 3 lines
lib/kstrtox.c +0
-0@@ -126,6 +126,8 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res) }EXPORT_SYMBOL (kstrtoull);This needs a comment to explain what is that guard used for.
Thanks,
Masa
Borislav Petkov
maintainerRe: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
Quoted 2 lines · Masayoshi Mizuma
I just felt the
BOOT_STRINGthing inlib/kstrtox.cconfuses... I'm OK for now if it's applied your below comment.
Well, actually, upon a second look, I don't think that including a .c file into a header is ok:
arch/x86/boot/string.h +4 -0
@@ -30,3 +30,7 @@ extern unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base);#endif /* BOOT_STRING_H */ + +#ifdef BOOT_STRING +#include "../../../lib/kstrtox.c" +#endif
Chao, why isn't this part of arch/x86/boot/compressed/misc.c ?
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
Hi Boris, Masa, and Baoquan,
Quoted 20 lines · Borislav Petkov
Quoted 2 lines · Masayoshi Mizuma
I just felt the
BOOT_STRINGthing inlib/kstrtox.cconfuses... I'm OK for now if it's applied your below comment.Well, actually, upon a second look, I don't think that including a .c file into a header is ok:
arch/x86/boot/string.h +4
-0@@ -30,3 +30,7 @@ extern unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base);#endif /* BOOT_STRING_H */ + +#ifdef BOOT_STRING +#include "../../../lib/kstrtox.c" +#endif
Quoted 2 lines
Chao, why isn't this part of
arch/x86/boot/compressed/misc.c?
Fine, I have put it to misc.c:
arch/x86/boot/compressed/misc.c +4 -0
@@ -426,3 +426,7 @@ void fortify_panic(const char *name) {error ("detected buffer overflow" ); } + +#ifdef BOOT_STRING +#include "../../../../lib/kstrtox.c" +#endif
And define it in misc.h:
arch/x86/boot/compressed/misc.h +2 -0
@@ -131,3 +131,5 @@ int num_immovable_mem;void get_immovable_mem (void );#endif #endif +#define BOOT_STRING +extern int kstrtoull (const char *s,unsigned int base,unsigned long long *res);
But isdigit() would be redefine, so:
include/linux/ctype.h +2 -0
@@ -23,10 +23,12 @@ extern const unsigned char _ctype[];#define isalnum (c) ((__ismask(c)&(_U|_L|_D)) != 0)#define isalpha (c) ((__ismask(c)&(_U|_L)) != 0)#define iscntrl (c) ((__ismask(c)&(_C)) != 0) +#ifndef BOOT_STRING static inline int isdigit (int c) {return '0' <= c && c <='9' ; } +#endif #define isgraph (c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)#define islower (c) ((__ismask(c)&(_L)) != 0)#define isprint (c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
Now I can make it.
I wonder whether this is OK to cover isdigit() with 'BOOT_STRING' tag.
Thanks,
Chao Fan
Quoted 7 lines
Signature · 4 lines
Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.
Borislav Petkov
maintainerRe: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
Quoted 20 lines · Chao Fan
But
isdigit()would be redefine, so:include/linux/ctype.h +2
-0@@ -23,10 +23,12 @@ extern const unsigned char _ctype[];#define isalnum (c) ((__ismask(c)&(_U|_L|_D)) != 0)#define isalpha (c) ((__ismask(c)&(_U|_L)) != 0)#define iscntrl (c) ((__ismask(c)&(_C)) != 0) +#ifndef BOOT_STRING static inline int isdigit (int c) {return '0' <= c && c <='9' ; } +#endif #define isgraph (c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)#define islower (c) ((__ismask(c)&(_L)) != 0)#define isprint (c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
Quoted 2 lines
Now I can make it.
I wonder whether this is OK to coverisdigit()with 'BOOT_STRING' tag.
See the beginning of arch/x86/boot/compressed/kaslr.c for a possible way to disable boot/ctype.h
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
Quoted 21 lines · Borislav Petkov
Quoted 20 lines · Chao Fan
But
isdigit()would be redefine, so:include/linux/ctype.h +2
-0@@ -23,10 +23,12 @@ extern const unsigned char _ctype[];#define isalnum (c) ((__ismask(c)&(_U|_L|_D)) != 0)#define isalpha (c) ((__ismask(c)&(_U|_L)) != 0)#define iscntrl (c) ((__ismask(c)&(_C)) != 0) +#ifndef BOOT_STRING static inline int isdigit (int c) {return '0' <= c && c <='9' ; } +#endif #define isgraph (c) ((__ismask(c)&(_P|_U|_L|_D)) != 0)#define islower (c) ((__ismask(c)&(_L)) != 0)#define isprint (c) ((__ismask(c)&(_P|_U|_L|_D|_SP)) != 0)
Quoted 5 lines
Quoted 2 lines
Now I can make it.
I wonder whether this is OK to coverisdigit()with 'BOOT_STRING' tag.See the beginning of
arch/x86/boot/compressed/kaslr.cfor a possible way to disableboot/ctype.h
I have done this with BOOT_CTYPE_H.
So misc.c can only use isdigit() and isxdigit() in include/linux/ctype.h.
arch/x86/boot/compressed/misc.c +5 -0
@@ -12,6 +12,7 @@* High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996 */ +#define BOOT_CTYPE_H #include "misc.h" #include "error.h" #include "pgtable.h"
@@ -426,3 +427,7 @@ void fortify_panic(const char *name) {error ("detected buffer overflow" ); } + +#ifdef BOOT_STRING +#include "../../../../lib/kstrtox.c" +#endif
This looks better than before.
Thanks,
Chao Fan
Quoted 8 lines
Signature · 5 lines
-- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.
Borislav Petkov
maintainerRe: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
In reply to Chao FanQuoted 35 lines · Chao Fan
Imitate
setup_acpi_rsdp()for theearly_paramof 'acpi_rsdp'. KEXEC writes the RSDP pointer to cmdline for EFI booting. So if 'acpi_rsdp' found in cmdline, use it directely.Since function
kstrtoull()is needed, include it inarch/x86/boot/string.h. To solve the definition conflict problem, setBOOT_STRINGtag to expose onlykstrtoull()and functions used by it. Other functions inlib/kstrtox.cwill be covered.Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/acpitb.c | 26 ++++++++++++++++++++++++++ arch/x86/boot/string.h | 4 ++++ lib/kstrtox.c | 4 ++++ 3 files changed, 34 insertions(+)arch/x86/boot/compressed/acpitb.c +6
-0@@ -8,6 +8,12 @@#include <linux/numa.h> #include <linux/acpi.h> +#define STATIC +#include <linux/decompress/mm.h> + +#define BOOT_STRING +#include "../string.h" +/* Search EFI table for RSDP table. */ static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr) {
arch/x86/boot/compressed/acpitb.c static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 212
Quoted 7 lines
arch/x86/boot/compressed/acpitb.c +4
-0@@ -200,3 +206,23 @@ static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) *rsdp_addr = (acpi_physical_address )address; } } + +static void get_acpi_rsdp (acpi_physical_address *rsdp_addr) +{ +#ifdef CONFIG_KEXEC
Ok, why is that CONFIG_KEXEC dependency needed now too?
Ok, let's recap: so far, for your use case you need:
CONFIG_MEMORY_HOTREMOVECONFIG_RANDOMIZE_BASE
and nowCONFIG_KEXEC
So, you can clean up all that ifdeffery by defining a new config item CONFIG_EARLY_PARSE_RSDP or so which depends on all those three items and then you can do
vmlinux-objs-$(CONFIG_EARLY_PARSE_RSDP) += $(obj)/acpitb.o
and get rid of the most of the ifdeffery.
Yes?
arch/x86/boot/compressed/acpitb.c static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 219
Quoted 7 lines
arch/x86/boot/compressed/acpitb.c +7
-0+unsigned long long res; +int len =0 ; +char *val; + + val =malloc (19 ); + len =cmdline_find_option ("acpi_rsdp" , val,19 ); +
^ Superfluous newline.
arch/x86/boot/compressed/acpitb.c static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 221
Quoted 2 lines
arch/x86/boot/compressed/acpitb.c +2
-0+if (len ==-1 ) +return ;
That check is not needed since you do > 0 below.
Quoted 24 lines
arch/x86/boot/compressed/acpitb.c +7
-0+ +if (len >0 ) { + val[len] =0 ; + *rsdp_addr = (acpi_physical_address )kstrtoull (val,16 , &res); + } +#endif +}arch/x86/boot/string.h +4
-0@@ -30,3 +30,7 @@ extern unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base);#endif /* BOOT_STRING_H */ + +#ifdef BOOT_STRING +#include "../../../lib/kstrtox.c" +#endif lib/kstrtox.c +0
-0
lib/kstrtox.c int kstrtoull(const char *s, unsigned int base, unsigned long long *res) · line 127
Quoted 2 lines
lib/kstrtox.c +0
-0@@ -126,6 +126,8 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res) }EXPORT_SYMBOL (kstrtoull);
This needs a comment to explain what is that guard used for.
lib/kstrtox.c kstrto_from_user(kstrtou16_from_user, kstrtou16, u16); · line 414
Quoted 11 lines
lib/kstrtox.c +4
-0+#ifndef BOOT_STRING +/** * kstrtoll - convert a string to a long long * @s: The start of the string. The string must be null-terminated, and may also @@ -408,3 +410,5 @@ kstrto_from_user(kstrtou16_from_user, kstrtou16, u16);kstrto_from_user (kstrtos16_from_user, kstrtos16, s16);kstrto_from_user (kstrtou8_from_user, kstrtou8, u8);kstrto_from_user (kstrtos8_from_user, kstrtos8, s8); + +#endif
#endif /* BOOT_STRING */
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
Quoted 37 lines · Borislav Petkov
Quoted 36 lines · Chao Fan
Imitate
setup_acpi_rsdp()for theearly_paramof 'acpi_rsdp'. KEXEC writes the RSDP pointer to cmdline for EFI booting. So if 'acpi_rsdp' found in cmdline, use it directely.Since function
kstrtoull()is needed, include it inarch/x86/boot/string.h. To solve the definition conflict problem, setBOOT_STRINGtag to expose onlykstrtoull()and functions used by it. Other functions inlib/kstrtox.cwill be covered.Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/acpitb.c | 26 ++++++++++++++++++++++++++ arch/x86/boot/string.h | 4 ++++ lib/kstrtox.c | 4 ++++ 3 files changed, 34 insertions(+)arch/x86/boot/compressed/acpitb.c +6
-0@@ -8,6 +8,12 @@#include <linux/numa.h> #include <linux/acpi.h> +#define STATIC +#include <linux/decompress/mm.h> + +#define BOOT_STRING +#include "../string.h" +/* Search EFI table for RSDP table. */ static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr) {@@ -200,3 +206,23 @@ static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) *rsdp_addr = (acpi_physical_address )address;
Quoted 9 lines
arch/x86/boot/compressed/acpitb.c static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 212
Quoted 6 lines
arch/x86/boot/compressed/acpitb.c +4
-0} } + +static void get_acpi_rsdp (acpi_physical_address *rsdp_addr) +{ +#ifdef CONFIG_KEXEC Ok, why is that
CONFIG_KEXECdependency needed now too?
CONFIG_KEXEC is only needed in this function.
When searching RSDP, there are three methods in order:
1. When booting from KEXEC, 'acpi_rsdp' is added to cmdline by KEXEC, so it can be parsed and used. CONFIG_KEXEC is needed here.
2. When booting from EFI, parse EFI table and find RSDP.
3. When booting from BIOS, search memory for RSDP just like acpi_find_root_pointer() in drivers/acpi/acpica/tbxfroot.c did.
So, CONFIG_KEXEC is only needed in 1, exactly in this function get_acpi_rsdp() of my PATCH.
Thanks,
Chao Fan
Quoted 82 lines
Ok, let's recap: so far, for your use case you need:
CONFIG_MEMORY_HOTREMOVECONFIG_RANDOMIZE_BASE
and nowCONFIG_KEXECSo, you can clean up all that ifdeffery by defining a new config item
CONFIG_EARLY_PARSE_RSDPor so which depends on all those three items and then you can dovmlinux-objs-$(CONFIG_EARLY_PARSE_RSDP) += $(obj)/acpitb.o
and get rid of the most of the ifdeffery.
Yes?
arch/x86/boot/compressed/acpitb.c static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 219
Quoted 7 lines
arch/x86/boot/compressed/acpitb.c +7
-0+unsigned long long res; +int len =0 ; +char *val; + + val =malloc (19 ); + len =cmdline_find_option ("acpi_rsdp" , val,19 ); +^ Superfluous newline.
arch/x86/boot/compressed/acpitb.c static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 221
Quoted 2 lines
arch/x86/boot/compressed/acpitb.c +2
-0+if (len ==-1 ) +return ;That check is not needed since you do > 0 below.
Quoted 24 lines
arch/x86/boot/compressed/acpitb.c +7
-0+ +if (len >0 ) { + val[len] =0 ; + *rsdp_addr = (acpi_physical_address )kstrtoull (val,16 , &res); + } +#endif +}arch/x86/boot/string.h +4
-0@@ -30,3 +30,7 @@ extern unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base);#endif /* BOOT_STRING_H */ + +#ifdef BOOT_STRING +#include "../../../lib/kstrtox.c" +#endif lib/kstrtox.c +0
-0lib/kstrtox.c int kstrtoull(const char *s, unsigned int base, unsigned long long *res) · line 127
Quoted 2 lines
lib/kstrtox.c +0
-0@@ -126,6 +126,8 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res) }EXPORT_SYMBOL (kstrtoull);This needs a comment to explain what is that guard used for.
lib/kstrtox.c kstrto_from_user(kstrtou16_from_user, kstrtou16, u16); · line 414
Quoted 11 lines
lib/kstrtox.c +4
-0+#ifndef BOOT_STRING +/** * kstrtoll - convert a string to a long long * @s: The start of the string. The string must be null-terminated, and may also @@ -408,3 +410,5 @@ kstrto_from_user(kstrtou16_from_user, kstrtou16, u16);kstrto_from_user (kstrtos16_from_user, kstrtos16, s16);kstrto_from_user (kstrtou8_from_user, kstrtou8, u8);kstrto_from_user (kstrtos8_from_user, kstrtos8, s8); + +#endif #endif /*
BOOT_STRING*/Signature · 4 lines
Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.
Re: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
Quoted 57 lines · Chao Fan
Quoted 37 lines · Borislav Petkov
Quoted 36 lines · Chao Fan
Imitate
setup_acpi_rsdp()for theearly_paramof 'acpi_rsdp'. KEXEC writes the RSDP pointer to cmdline for EFI booting. So if 'acpi_rsdp' found in cmdline, use it directely.Since function
kstrtoull()is needed, include it inarch/x86/boot/string.h. To solve the definition conflict problem, setBOOT_STRINGtag to expose onlykstrtoull()and functions used by it. Other functions inlib/kstrtox.cwill be covered.Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/acpitb.c | 26 ++++++++++++++++++++++++++ arch/x86/boot/string.h | 4 ++++ lib/kstrtox.c | 4 ++++ 3 files changed, 34 insertions(+)arch/x86/boot/compressed/acpitb.c +6
-0@@ -8,6 +8,12 @@#include <linux/numa.h> #include <linux/acpi.h> +#define STATIC +#include <linux/decompress/mm.h> + +#define BOOT_STRING +#include "../string.h" +/* Search EFI table for RSDP table. */ static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr) {@@ -200,3 +206,23 @@ static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) *rsdp_addr = (acpi_physical_address )address;Quoted 9 lines
arch/x86/boot/compressed/acpitb.c static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 212
Quoted 6 lines
arch/x86/boot/compressed/acpitb.c +4
-0} } + +static void get_acpi_rsdp (acpi_physical_address *rsdp_addr) +{ +#ifdef CONFIG_KEXEC Ok, why is that
CONFIG_KEXECdependency needed now too?
CONFIG_KEXECis only needed in this function.When searching RSDP, there are three methods in order:
1. When booting from KEXEC, 'acpi_rsdp' is added to cmdline by KEXEC, so it can be parsed and used.CONFIG_KEXECis needed here.
2. When booting from EFI, parse EFI table and find RSDP.
3. When booting from BIOS, search memory for RSDP just likeacpi_find_root_pointer()indrivers/acpi/acpica/tbxfroot.cdid.
Quoted 6 lines
So,
CONFIG_KEXECis only needed in 1, exactly in this functionget_acpi_rsdp()of my PATCH.Thanks,
Chao Fan
That means, CONFIG_KEXEC is needed by a little part of the whole PATCHSET. Without CONFIG_KEXEC, RSDP can only be found in other methods.
Thanks,
Chao Fan
Quoted 82 lines
Quoted 82 lines
Ok, let's recap: so far, for your use case you need:
CONFIG_MEMORY_HOTREMOVECONFIG_RANDOMIZE_BASE
and nowCONFIG_KEXECSo, you can clean up all that ifdeffery by defining a new config item
CONFIG_EARLY_PARSE_RSDPor so which depends on all those three items and then you can dovmlinux-objs-$(CONFIG_EARLY_PARSE_RSDP) += $(obj)/acpitb.o
and get rid of the most of the ifdeffery.
Yes?
arch/x86/boot/compressed/acpitb.c static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 219
Quoted 7 lines
arch/x86/boot/compressed/acpitb.c +7
-0+unsigned long long res; +int len =0 ; +char *val; + + val =malloc (19 ); + len =cmdline_find_option ("acpi_rsdp" , val,19 ); +^ Superfluous newline.
arch/x86/boot/compressed/acpitb.c static void bios_get_rsdp_addr(acpi_physical_address *rsdp_addr) · line 221
Quoted 2 lines
arch/x86/boot/compressed/acpitb.c +2
-0+if (len ==-1 ) +return ;That check is not needed since you do > 0 below.
Quoted 24 lines
arch/x86/boot/compressed/acpitb.c +7
-0+ +if (len >0 ) { + val[len] =0 ; + *rsdp_addr = (acpi_physical_address )kstrtoull (val,16 , &res); + } +#endif +}arch/x86/boot/string.h +4
-0@@ -30,3 +30,7 @@ extern unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base);#endif /* BOOT_STRING_H */ + +#ifdef BOOT_STRING +#include "../../../lib/kstrtox.c" +#endif lib/kstrtox.c +0
-0lib/kstrtox.c int kstrtoull(const char *s, unsigned int base, unsigned long long *res) · line 127
Quoted 2 lines
lib/kstrtox.c +0
-0@@ -126,6 +126,8 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res) }EXPORT_SYMBOL (kstrtoull);This needs a comment to explain what is that guard used for.
lib/kstrtox.c kstrto_from_user(kstrtou16_from_user, kstrtou16, u16); · line 414
Quoted 11 lines
lib/kstrtox.c +4
-0+#ifndef BOOT_STRING +/** * kstrtoll - convert a string to a long long * @s: The start of the string. The string must be null-terminated, and may also @@ -408,3 +410,5 @@ kstrto_from_user(kstrtou16_from_user, kstrtou16, u16);kstrto_from_user (kstrtos16_from_user, kstrtos16, s16);kstrto_from_user (kstrtou8_from_user, kstrtou8, u8);kstrto_from_user (kstrtos8_from_user, kstrtos8, s8); + +#endif #endif /*
BOOT_STRING*/Signature · 4 lines
Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.
Borislav Petkov
maintainerRe: [PATCH v11 3/5] x86/boot: Add get_acpi_rsdp() to parse RSDP in cmdlien from kexec
In reply to Chao FanQuoted 5 lines · Chao Fan
CONFIG_KEXECis only needed in this function.When searching RSDP, there are three methods in order:
1. When booting from KEXEC, 'acpi_rsdp' is added to cmdline by KEXEC, so it can be parsed and used.CONFIG_KEXECis needed here.
But theoretically acpi_rsdp can be supplied by the first kernel too, right?
So you don't need that CONFIG_KEXEC here at all?
Quoted 7 lines
Quoted 7 lines
Ok, let's recap: so far, for your use case you need:
CONFIG_MEMORY_HOTREMOVECONFIG_RANDOMIZE_BASE
and nowCONFIG_KEXEC
Quoted 7 lines
Quoted 7 lines
So, you can clean up all that ifdeffery by defining a new config item
CONFIG_EARLY_PARSE_RSDPor so which depends on all those three items and then you can dovmlinux-objs-$(CONFIG_EARLY_PARSE_RSDP) += $(obj)/acpitb.o
and get rid of the most of the ifdeffery.
Regardless of CONFIG_KEXEC - you still need to define a CONFIG_ symbol for your use case. We won't be parsing RSDP early on !MEMORY_HOTREMOVE machines, which is the majority.
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.PATCH v11 4/5 x86/boot: Dig out SRAT table from RSDP and find immovable memory
In reply to Chao FanTo avoid KASLR extracting kernel on movable memory, slove the conflict between KASLR and movable_node feature, dig the SRAT tables from RSDP pointer. Walk the SRAT tables and store the immovable memory regions in immovable_mem[].
There are three methods to get RSDP pointer: KEXEC condition, EFI confition, BIOS condition.
If KEXEC add 'acpi_rsdp' to cmdline, use it. Otherwise, parse EFI table for RSDP.
Then, search memory for RSDP.
Imitate from ACPI code, based on acpi_os_get_root_pointer().
Process: RSDP->RSDT/XSDT->ACPI root table->SRAT.
--- arch/x86/boot/compressed/Makefile | 4 + arch/x86/boot/compressed/acpitb.c | 139 ++++++++++++++++++++++++++++++ arch/x86/boot/compressed/kaslr.c | 4 - arch/x86/boot/compressed/misc.h | 15 ++++ 4 files changed, 158 insertions(+), 4 deletions(-)
arch/x86/boot/compressed/Makefile +4 -0
@@ -84,6 +84,10 @@ ifdef CONFIG_X86_64 vmlinux-objs-y += $(obj)/pgtable_64.o endif +#if (defined CONFIG_MEMORY_HOTREMOVE) && (defined CONFIG_RANDOMIZE_BASE) +vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/acpitb.o +#endif + $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \
arch/x86/boot/compressed/acpitb.c +139 -0
148 lines not on this page · raw message
arch/x86/boot/compressed/kaslr.c +0 -4
@@ -87,10 +87,6 @@ static unsigned long get_boot_seed(void)#define KASLR_COMPRESSED_BOOT #include "../../lib/kaslr.c" -struct mem_vector { -unsigned long long start; -unsigned long long size; -};/* Only supporting at most 4 unusable memmap regions with kaslr */ #define MAX_MEMMAP_REGIONS 4
arch/x86/boot/compressed/misc.h +15 -0
@@ -77,6 +77,11 @@ void choose_random_location(unsigned long input,unsigned long *output, unsigned long output_size, unsigned long *virt_addr); +struct mem_vector { +unsigned long long start; +unsigned long long size; +}; +/* cpuflags.c */ bool has_cpuflag (int flag);#else
@@ -116,3 +121,13 @@ static inline void console_init(void)void set_sev_encryption_mask (void );#endif + +/* acpitb.c */ +#ifdef CONFIG_RANDOMIZE_BASE +int num_immovable_mem; +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the amount of immovable memory regions */ +#define ACPI_MAX_TABLES 128 +void get_immovable_mem (void ); +#endif +#endif
Signature · 1 line
2.19.1
Re: [PATCH v11 4/5] x86/boot: Dig out SRAT table from RSDP and find immovable memory
Quoted 92 lines · Chao Fan
To avoid KASLR extracting kernel on movable memory, slove the conflict between KASLR and
movable_nodefeature, dig the SRAT tables from RSDP pointer. Walk the SRAT tables and store the immovable memory regions in immovable_mem[].There are three methods to get RSDP pointer: KEXEC condition, EFI confition, BIOS condition.
If KEXEC add 'acpi_rsdp' to cmdline, use it. Otherwise, parse EFI table for RSDP.
Then, search memory for RSDP.Imitate from ACPI code, based on
acpi_os_get_root_pointer().
Process: RSDP->RSDT/XSDT->ACPI roottable->SRAT.Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/Makefile | 4 + arch/x86/boot/compressed/acpitb.c | 139 ++++++++++++++++++++++++++++++ arch/x86/boot/compressed/kaslr.c | 4 - arch/x86/boot/compressed/misc.h | 15 ++++ 4 files changed, 158 insertions(+), 4 deletions(-)arch/x86/boot/compressed/Makefile +4
-0@@ -84,6 +84,10 @@ ifdef CONFIG_X86_64 vmlinux-objs-y += $(obj)/pgtable_64.o endif +#if (defined CONFIG_MEMORY_HOTREMOVE) && (defined CONFIG_RANDOMIZE_BASE) +vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/acpitb.o +#endif + $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \arch/x86/boot/compressed/acpitb.c +40
-0@@ -14,6 +14,11 @@#define BOOT_STRING #include "../string.h" +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the immovable memory regions */ +struct mem_vector immovable_mem[MAX_NUMNODES *2 ]; +#endif +/* Search EFI table for RSDP table. */ static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr) {@@ -226,3 +231,137 @@ static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) }#endif } + +/* +* Used to dig RSDP table from EFI table or BIOS. +* If RSDP table found in EFI table, use it. Or search BIOS. +* Based on acpi_os_get_root_pointer(). +*/ +static acpi_physical_address get_rsdp_addr (void ) +{ +acpi_physical_address pa =0 ; + +get_acpi_rsdp (&pa); + +if (!pa) +efi_get_rsdp_addr (&pa); + +if (!pa) +bios_get_rsdp_addr (&pa); + +return pa; +} + +static struct acpi_table_header *get_acpi_srat_table (void ) +{ +acpi_physical_address acpi_table; +acpi_physical_address root_table; +struct acpi_table_header *header; +struct acpi_table_rsdp *rsdp; +bool acpi_use_rsdt = false; +char *signature; +char arg[10 ]; +u8 *entry; +u32 count; +u32 size; +int i, j; +int ret;
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 277
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +9
-0+u32 len; + + rsdp = (struct acpi_table_rsdp *)get_rsdp_addr (); +if (!rsdp) +return NULL ; + + ret =cmdline_find_option ("acpi" , arg,sizeof (arg)); +if (ret ==4 && !strncmp (arg,"rsdt" ,4 )) + acpi_use_rsdt = true;
All have to do for ret is checking whether it's above 0, right? So how about the following?
if ((cmdline_find_option("acpi", arg, sizeof(arg)) > 0) &&
!strncmp(arg, "rsdt", 4))
acpi_use_rsdt = true;Quoted 22 lines
arch/x86/boot/compressed/acpitb.c +22
-0+ +/* Get RSDT or XSDT from RSDP. */ +if (!acpi_use_rsdt && + rsdp->xsdt_physical_address && rsdp->revision >1 ) { + root_table = rsdp->xsdt_physical_address; + size =ACPI_XSDT_ENTRY_SIZE ; + }else { + root_table = rsdp->rsdt_physical_address; + size =ACPI_RSDT_ENTRY_SIZE ; + } + +/* Get ACPI root table from RSDT or XSDT.*/ + header = (struct acpi_table_header *)root_table; + len = header->length; + count = (u32)((len -sizeof (struct acpi_table_header )) / size); + entry =ACPI_ADD_PTR (u8, header,sizeof (struct acpi_table_header )); + +for (i =0 ; i < count; i++) { +u64 address64; + +if (size ==ACPI_RSDT_ENTRY_SIZE ) + acpi_table = ((acpi_physical_address)
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 308
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +9
-0+ (*ACPI_CAST_PTR(u32, entry))); + else { + *(u64 *)(void *)&address64 = *(u64 *)(void *)entry; + acpi_table = (acpi_physical_address ) address64; + } + +if (acpi_table) { + header = (struct acpi_table_header *)acpi_table; + signature = header->signature;
this isn't needed.
Quoted 17 lines
arch/x86/boot/compressed/acpitb.c +17
-0+ +if (ACPI_COMPARE_NAME (header->signature,ACPI_SIG_SRAT )) +return header; + } + entry += size; + } +return NULL ; +} + +/* +* According to ACPI table, filter the immvoable memory regions +* and store them in immovable_mem[]. +*/ +void get_immovable_mem (void ) +{ +struct acpi_table_header *table_header; +struct acpi_subtable_header *table;
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 334
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +9
-0+struct acpi_srat_mem_affinity *ma; +unsigned long table_end; +char arg[10 ]; +int i =0 ; +int ret; + + ret =cmdline_find_option ("acpi" , arg,sizeof (arg)); +if (ret ==3 && !strncmp (arg,"off" ,3 )) +return ;
Same as above.
if ((cmdline_find_option("acpi", arg, sizeof(arg)) > 0) &&
!strncmp(arg, "off", 3))
return;arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 337
Quoted 3 lines
arch/x86/boot/compressed/acpitb.c +3
-0+ +if (!cmdline_find_option_bool ("movable_node" )) +return ;
I think this check isn't needed.
The SRAT parsing is needed to the kaslr issue which I'm trying to fix. The issue may happen even if movable_node isn't set.
Quoted 12 lines
arch/x86/boot/compressed/acpitb.c +12
-0+ + table_header =get_acpi_srat_table (); +if (!table_header) +return ; + + table_end = (unsigned long )table_header + table_header->length; + + table = (struct acpi_subtable_header *) + ((unsigned long )table_header +sizeof (struct acpi_table_srat )); + +while (((unsigned long )table) + +sizeof (struct acpi_subtable_header ) < table_end) {
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 359
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +10
-0+if (table->type ==ACPI_SRAT_TYPE_MEMORY_AFFINITY ) { + ma = (struct acpi_srat_mem_affinity *)table; +if (!(ma->flags &ACPI_SRAT_MEM_HOT_PLUGGABLE )) { + immovable_mem[i].start = ma->base_address; + immovable_mem[i].size = ma->length; + i++; + } + +if (i >=MAX_NUMNODES *2 ) { +debug_putstr ("Too many immovable memory regions, aborted.\n" );
I'm not sure this statement gets true actually,
but if so, should it be set 0 to fallback in process_mem_region()?
Thanks,
Masa
Quoted 58 lines
arch/x86/boot/compressed/acpitb.c +8
-0+break ; + } + } + table = (struct acpi_subtable_header *) + ((unsigned long )table + table->length); + } + num_immovable_mem = i; +}arch/x86/boot/compressed/kaslr.c +0
-4@@ -87,10 +87,6 @@ static unsigned long get_boot_seed(void)#define KASLR_COMPRESSED_BOOT #include "../../lib/kaslr.c" -struct mem_vector { -unsigned long long start; -unsigned long long size; -};/* Only supporting at most 4 unusable memmap regions with kaslr */ #define MAX_MEMMAP_REGIONS 4arch/x86/boot/compressed/misc.h +15
-0@@ -77,6 +77,11 @@ void choose_random_location(unsigned long input,unsigned long *output, unsigned long output_size, unsigned long *virt_addr); +struct mem_vector { +unsigned long long start; +unsigned long long size; +}; +/* cpuflags.c */ bool has_cpuflag (int flag);#else @@ -116,3 +121,13 @@ static inline void console_init(void)void set_sev_encryption_mask (void );#endif + +/* acpitb.c */ +#ifdef CONFIG_RANDOMIZE_BASE +int num_immovable_mem; +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the amount of immovable memory regions */ +#define ACPI_MAX_TABLES 128 +void get_immovable_mem (void ); +#endif +#endif Signature · 1 line
2.19.1
Re: [PATCH v11 4/5] x86/boot: Dig out SRAT table from RSDP and find immovable memory
On Mon, Nov 12, 2018 at 03:52:54PM -0500, Masayoshi Mizuma wrote:
[...]
Quoted 9 lines
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 277
Quoted 5 lines
arch/x86/boot/compressed/acpitb.c +4
-0+ + ret =cmdline_find_option ("acpi" , arg,sizeof (arg)); +if (ret ==4 && !strncmp (arg,"rsdt" ,4 )) + acpi_use_rsdt = true;All have to do for ret is checking whether it's above 0, right? So how about the following?
Quoted 3 lines
if ((cmdline_find_option("acpi", arg, sizeof(arg)) > 0) &&
!strncmp(arg, "rsdt", 4))
acpi_use_rsdt = true;Maybe:
Quoted 3 lines
if ((cmdline_find_option("acpi", arg, sizeof(arg)) == 4) &&
!strncmp(arg, "rsdt", 4))
acpi_use_rsdt = true;looks better. Thanks for your suggestion.
Quoted 32 lines
Quoted 31 lines
arch/x86/boot/compressed/acpitb.c +30
-0+ +/* Get RSDT or XSDT from RSDP. */ +if (!acpi_use_rsdt && + rsdp->xsdt_physical_address && rsdp->revision >1 ) { + root_table = rsdp->xsdt_physical_address; + size =ACPI_XSDT_ENTRY_SIZE ; + }else { + root_table = rsdp->rsdt_physical_address; + size =ACPI_RSDT_ENTRY_SIZE ; + } + +/* Get ACPI root table from RSDT or XSDT.*/ + header = (struct acpi_table_header *)root_table; + len = header->length; + count = (u32)((len -sizeof (struct acpi_table_header )) / size); + entry =ACPI_ADD_PTR (u8, header,sizeof (struct acpi_table_header )); + +for (i =0 ; i < count; i++) { +u64 address64; + +if (size ==ACPI_RSDT_ENTRY_SIZE ) + acpi_table = ((acpi_physical_address) + (*ACPI_CAST_PTR (u32, entry))); +else { + *(u64 *)(void *)&address64 = *(u64 *)(void *)entry; + acpi_table = (acpi_physical_address ) address64; + } + +if (acpi_table) { + header = (struct acpi_table_header *)acpi_table;
Quoted 3 lines
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 308
Quoted 1 line
arch/x86/boot/compressed/acpitb.c +1
-0+ signature = header->signature;this isn't needed.
Yes, will change it.
Quoted 34 lines
Quoted 18 lines
arch/x86/boot/compressed/acpitb.c +17
-0+ +if (ACPI_COMPARE_NAME (header->signature,ACPI_SIG_SRAT )) +return header; + } + entry += size; + } +return NULL ; +} + +/* +* According to ACPI table, filter the immvoable memory regions +* and store them in immovable_mem[]. +*/ +void get_immovable_mem (void ) +{ +struct acpi_table_header *table_header; +struct acpi_subtable_header *table;arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 334
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +9
-0+struct acpi_srat_mem_affinity *ma; +unsigned long table_end; +char arg[10 ]; +int i =0 ; +int ret; + + ret =cmdline_find_option ("acpi" , arg,sizeof (arg)); +if (ret ==3 && !strncmp (arg,"off" ,3 )) +return ;Same as above.
if ((cmdline_find_option("acpi", arg, sizeof(arg)) > 0) && !strncmp(arg, "off", 3)) return;
Quoted 7 lines
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 337
Quoted 3 lines
arch/x86/boot/compressed/acpitb.c +3
-0+ +if (!cmdline_find_option_bool ("movable_node" )) +return ;I think this check isn't needed.
The SRAT parsing is needed to the kaslr issue which I'm trying to fix. The issue may happen even ifmovable_nodeisn't set.
Got it.
Quoted 18 lines
Quoted 18 lines
arch/x86/boot/compressed/acpitb.c +17
-0+ + table_header =get_acpi_srat_table (); +if (!table_header) +return ; + + table_end = (unsigned long )table_header + table_header->length; + + table = (struct acpi_subtable_header *) + ((unsigned long )table_header +sizeof (struct acpi_table_srat )); + +while (((unsigned long )table) + +sizeof (struct acpi_subtable_header ) < table_end) { +if (table->type ==ACPI_SRAT_TYPE_MEMORY_AFFINITY ) { + ma = (struct acpi_srat_mem_affinity *)table; +if (!(ma->flags &ACPI_SRAT_MEM_HOT_PLUGGABLE )) { + immovable_mem[i].start = ma->base_address; + immovable_mem[i].size = ma->length;
Quoted 8 lines
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 359
Quoted 5 lines
arch/x86/boot/compressed/acpitb.c +5
-0+ i++; + } + +if (i >=MAX_NUMNODES *2 ) { +debug_putstr ("Too many immovable memory regions, aborted.\n" );I'm not sure this statement gets true actually,
but if so, should it be set 0 to fallback inprocess_mem_region()?
That's a good problem.
Well, I don't know what will cause "i >= MAX_NUMNODES*2", maybe some error in SRAT table or failed to parse table.
Anyway, it's a good idea to set it 0.
Thanks,
Chao Fan
Quoted 64 lines
Thanks,
MasaQuoted 58 lines
arch/x86/boot/compressed/acpitb.c +8
-0+break ; + } + } + table = (struct acpi_subtable_header *) + ((unsigned long )table + table->length); + } + num_immovable_mem = i; +}arch/x86/boot/compressed/kaslr.c +0
-4@@ -87,10 +87,6 @@ static unsigned long get_boot_seed(void)#define KASLR_COMPRESSED_BOOT #include "../../lib/kaslr.c" -struct mem_vector { -unsigned long long start; -unsigned long long size; -};/* Only supporting at most 4 unusable memmap regions with kaslr */ #define MAX_MEMMAP_REGIONS 4arch/x86/boot/compressed/misc.h +15
-0@@ -77,6 +77,11 @@ void choose_random_location(unsigned long input,unsigned long *output, unsigned long output_size, unsigned long *virt_addr); +struct mem_vector { +unsigned long long start; +unsigned long long size; +}; +/* cpuflags.c */ bool has_cpuflag (int flag);#else @@ -116,3 +121,13 @@ static inline void console_init(void)void set_sev_encryption_mask (void );#endif + +/* acpitb.c */ +#ifdef CONFIG_RANDOMIZE_BASE +int num_immovable_mem; +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the amount of immovable memory regions */ +#define ACPI_MAX_TABLES 128 +void get_immovable_mem (void ); +#endif +#endif Signature · 1 line
2.19.1
Re: [PATCH v11 4/5] x86/boot: Dig out SRAT table from RSDP and find immovable memory
In reply to Chao FanQuoted 27 lines · Chao Fan
To avoid KASLR extracting kernel on movable memory, slove the conflict between KASLR and
movable_nodefeature, dig the SRAT tables from RSDP pointer. Walk the SRAT tables and store the immovable memory regions in immovable_mem[].There are three methods to get RSDP pointer: KEXEC condition, EFI confition, BIOS condition.
If KEXEC add 'acpi_rsdp' to cmdline, use it. Otherwise, parse EFI table for RSDP.
Then, search memory for RSDP.Imitate from ACPI code, based on
acpi_os_get_root_pointer().
Process: RSDP->RSDT/XSDT->ACPI roottable->SRAT.Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/Makefile | 4 + arch/x86/boot/compressed/acpitb.c | 139 ++++++++++++++++++++++++++++++ arch/x86/boot/compressed/kaslr.c | 4 - arch/x86/boot/compressed/misc.h | 15 ++++ 4 files changed, 158 insertions(+), 4 deletions(-)arch/x86/boot/compressed/Makefile +0
-0
arch/x86/boot/compressed/Makefile ifdef CONFIG_X86_64 · line 89
Quoted 6 lines
arch/x86/boot/compressed/Makefile +3
-0@@ -84,6 +84,10 @@ ifdef CONFIG_X86_64 vmlinux-objs-y += $(obj)/pgtable_64.o endif +#if (defined CONFIG_MEMORY_HOTREMOVE) && (defined CONFIG_RANDOMIZE_BASE) +vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/acpitb.o +#endif
'#' in Makefile means comment out...
ifdef CONFIG_MEMORY_HOTREMOVE
vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/acpitb.o
endif
Quoted 9 lines
arch/x86/boot/compressed/Makefile +1
-0+ $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \arch/x86/boot/compressed/acpitb.c +0
-0
arch/x86/boot/compressed/acpitb.c line 21
Quoted 8 lines
arch/x86/boot/compressed/acpitb.c +4
-0@@ -14,6 +14,11 @@#define BOOT_STRING #include "../string.h" +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the immovable memory regions */ +struct mem_vector immovable_mem[MAX_NUMNODES *2 ]; +#endif
This #ifdef isn't needed.
Could you please check the other #ifdef statement as well?
Thanks,
Masa
Quoted 192 lines
arch/x86/boot/compressed/acpitb.c +1
-0+/* Search EFI table for RSDP table. */ static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr){
arch/x86/boot/compressed/acpitb.c +134
-0@@ -226,3 +231,137 @@ static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) }#endif } + +/* +* Used to dig RSDP table from EFI table or BIOS. +* If RSDP table found in EFI table, use it. Or search BIOS. +* Based on acpi_os_get_root_pointer(). +*/ +static acpi_physical_address get_rsdp_addr (void ) +{ +acpi_physical_address pa =0 ; + +get_acpi_rsdp (&pa); + +if (!pa) +efi_get_rsdp_addr (&pa); + +if (!pa) +bios_get_rsdp_addr (&pa); + +return pa; +} + +static struct acpi_table_header *get_acpi_srat_table (void ) +{ +acpi_physical_address acpi_table; +acpi_physical_address root_table; +struct acpi_table_header *header; +struct acpi_table_rsdp *rsdp; +bool acpi_use_rsdt = false; +char *signature; +char arg[10 ]; +u8 *entry; +u32 count; +u32 size; +int i, j; +int ret; +u32 len; + + rsdp = (struct acpi_table_rsdp *)get_rsdp_addr (); +if (!rsdp) +return NULL ; + + ret =cmdline_find_option ("acpi" , arg,sizeof (arg)); +if (ret ==4 && !strncmp (arg,"rsdt" ,4 )) + acpi_use_rsdt = true; + +/* Get RSDT or XSDT from RSDP. */ +if (!acpi_use_rsdt && + rsdp->xsdt_physical_address && rsdp->revision >1 ) { + root_table = rsdp->xsdt_physical_address; + size =ACPI_XSDT_ENTRY_SIZE ; + }else { + root_table = rsdp->rsdt_physical_address; + size =ACPI_RSDT_ENTRY_SIZE ; + } + +/* Get ACPI root table from RSDT or XSDT.*/ + header = (struct acpi_table_header *)root_table; + len = header->length; + count = (u32)((len -sizeof (struct acpi_table_header )) / size); + entry =ACPI_ADD_PTR (u8, header,sizeof (struct acpi_table_header )); + +for (i =0 ; i < count; i++) { +u64 address64; + +if (size ==ACPI_RSDT_ENTRY_SIZE ) + acpi_table = ((acpi_physical_address) + (*ACPI_CAST_PTR (u32, entry))); +else { + *(u64 *)(void *)&address64 = *(u64 *)(void *)entry; + acpi_table = (acpi_physical_address ) address64; + } + +if (acpi_table) { + header = (struct acpi_table_header *)acpi_table; + signature = header->signature; + +if (ACPI_COMPARE_NAME (header->signature,ACPI_SIG_SRAT )) +return header; + } + entry += size; + } +return NULL ; +} + +/* +* According to ACPI table, filter the immvoable memory regions +* and store them in immovable_mem[]. +*/ +void get_immovable_mem (void ) +{ +struct acpi_table_header *table_header; +struct acpi_subtable_header *table; +struct acpi_srat_mem_affinity *ma; +unsigned long table_end; +char arg[10 ]; +int i =0 ; +int ret; + + ret =cmdline_find_option ("acpi" , arg,sizeof (arg)); +if (ret ==3 && !strncmp (arg,"off" ,3 )) +return ; + +if (!cmdline_find_option_bool ("movable_node" )) +return ; + + table_header =get_acpi_srat_table (); +if (!table_header) +return ; + + table_end = (unsigned long )table_header + table_header->length; + + table = (struct acpi_subtable_header *) + ((unsigned long )table_header +sizeof (struct acpi_table_srat )); + +while (((unsigned long )table) + +sizeof (struct acpi_subtable_header ) < table_end) { +if (table->type ==ACPI_SRAT_TYPE_MEMORY_AFFINITY ) { + ma = (struct acpi_srat_mem_affinity *)table; +if (!(ma->flags &ACPI_SRAT_MEM_HOT_PLUGGABLE )) { + immovable_mem[i].start = ma->base_address; + immovable_mem[i].size = ma->length; + i++; + } + +if (i >=MAX_NUMNODES *2 ) { +debug_putstr ("Too many immovable memory regions, aborted.\n" ); +break ; + } + } + table = (struct acpi_subtable_header *) + ((unsigned long )table + table->length); + } + num_immovable_mem = i; +}arch/x86/boot/compressed/kaslr.c +0
-4@@ -87,10 +87,6 @@ static unsigned long get_boot_seed(void)#define KASLR_COMPRESSED_BOOT #include "../../lib/kaslr.c" -struct mem_vector { -unsigned long long start; -unsigned long long size; -};/* Only supporting at most 4 unusable memmap regions with kaslr */ #define MAX_MEMMAP_REGIONS 4arch/x86/boot/compressed/misc.h +15
-0@@ -77,6 +77,11 @@ void choose_random_location(unsigned long input,unsigned long *output, unsigned long output_size, unsigned long *virt_addr); +struct mem_vector { +unsigned long long start; +unsigned long long size; +}; +/* cpuflags.c */ bool has_cpuflag (int flag);#else @@ -116,3 +121,13 @@ static inline void console_init(void)void set_sev_encryption_mask (void );#endif + +/* acpitb.c */ +#ifdef CONFIG_RANDOMIZE_BASE +int num_immovable_mem; +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the amount of immovable memory regions */ +#define ACPI_MAX_TABLES 128 +void get_immovable_mem (void ); +#endif +#endif Signature · 1 line
2.19.1
Re: [PATCH v11 4/5] x86/boot: Dig out SRAT table from RSDP and find immovable memory
Quoted 37 lines · Masayoshi Mizuma
Quoted 27 lines · Chao Fan
To avoid KASLR extracting kernel on movable memory, slove the conflict between KASLR and
movable_nodefeature, dig the SRAT tables from RSDP pointer. Walk the SRAT tables and store the immovable memory regions in immovable_mem[].There are three methods to get RSDP pointer: KEXEC condition, EFI confition, BIOS condition.
If KEXEC add 'acpi_rsdp' to cmdline, use it. Otherwise, parse EFI table for RSDP.
Then, search memory for RSDP.Imitate from ACPI code, based on
acpi_os_get_root_pointer().
Process: RSDP->RSDT/XSDT->ACPI roottable->SRAT.Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/Makefile | 4 + arch/x86/boot/compressed/acpitb.c | 139 ++++++++++++++++++++++++++++++ arch/x86/boot/compressed/kaslr.c | 4 - arch/x86/boot/compressed/misc.h | 15 ++++ 4 files changed, 158 insertions(+), 4 deletions(-)arch/x86/boot/compressed/Makefile +0
-0arch/x86/boot/compressed/Makefile ifdef CONFIG_X86_64 · line 89
Quoted 6 lines
arch/x86/boot/compressed/Makefile +3
-0@@ -84,6 +84,10 @@ ifdef CONFIG_X86_64 vmlinux-objs-y += $(obj)/pgtable_64.o endif +#if (defined CONFIG_MEMORY_HOTREMOVE) && (defined CONFIG_RANDOMIZE_BASE) +vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/acpitb.o +#endif'#' in
Makefilemeans comment out...
Quoted 4 lines
ifdef
CONFIG_MEMORY_HOTREMOVEvmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/acpitb.oendif
Thanks,
Quoted 13 lines
Quoted 12 lines
arch/x86/boot/compressed/Makefile +1
-0+ $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \arch/x86/boot/compressed/acpitb.c +0
-0@@ -14,6 +14,11 @@#define BOOT_STRING #include "../string.h"
Quoted 8 lines
arch/x86/boot/compressed/acpitb.c line 20
Quoted 4 lines
arch/x86/boot/compressed/acpitb.c +4
-0+#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the immovable memory regions */ +struct mem_vector immovable_mem[MAX_NUMNODES *2 ]; +#endif This #ifdef isn't needed.
Could you please check the other #ifdef statement as well?
Sure, I will check all the #ifdef.
Thanks,
Chao Fan
Quoted 198 lines
Thanks,
MasaQuoted 192 lines
arch/x86/boot/compressed/acpitb.c +135
-0+/* Search EFI table for RSDP table. */ static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr) {@@ -226,3 +231,137 @@ static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) }#endif } + +/* +* Used to dig RSDP table from EFI table or BIOS. +* If RSDP table found in EFI table, use it. Or search BIOS. +* Based on acpi_os_get_root_pointer(). +*/ +static acpi_physical_address get_rsdp_addr (void ) +{ +acpi_physical_address pa =0 ; + +get_acpi_rsdp (&pa); + +if (!pa) +efi_get_rsdp_addr (&pa); + +if (!pa) +bios_get_rsdp_addr (&pa); + +return pa; +} + +static struct acpi_table_header *get_acpi_srat_table (void ) +{ +acpi_physical_address acpi_table; +acpi_physical_address root_table; +struct acpi_table_header *header; +struct acpi_table_rsdp *rsdp; +bool acpi_use_rsdt = false; +char *signature; +char arg[10 ]; +u8 *entry; +u32 count; +u32 size; +int i, j; +int ret; +u32 len; + + rsdp = (struct acpi_table_rsdp *)get_rsdp_addr (); +if (!rsdp) +return NULL ; + + ret =cmdline_find_option ("acpi" , arg,sizeof (arg)); +if (ret ==4 && !strncmp (arg,"rsdt" ,4 )) + acpi_use_rsdt = true; + +/* Get RSDT or XSDT from RSDP. */ +if (!acpi_use_rsdt && + rsdp->xsdt_physical_address && rsdp->revision >1 ) { + root_table = rsdp->xsdt_physical_address; + size =ACPI_XSDT_ENTRY_SIZE ; + }else { + root_table = rsdp->rsdt_physical_address; + size =ACPI_RSDT_ENTRY_SIZE ; + } + +/* Get ACPI root table from RSDT or XSDT.*/ + header = (struct acpi_table_header *)root_table; + len = header->length; + count = (u32)((len -sizeof (struct acpi_table_header )) / size); + entry =ACPI_ADD_PTR (u8, header,sizeof (struct acpi_table_header )); + +for (i =0 ; i < count; i++) { +u64 address64; + +if (size ==ACPI_RSDT_ENTRY_SIZE ) + acpi_table = ((acpi_physical_address) + (*ACPI_CAST_PTR (u32, entry))); +else { + *(u64 *)(void *)&address64 = *(u64 *)(void *)entry; + acpi_table = (acpi_physical_address ) address64; + } + +if (acpi_table) { + header = (struct acpi_table_header *)acpi_table; + signature = header->signature; + +if (ACPI_COMPARE_NAME (header->signature,ACPI_SIG_SRAT )) +return header; + } + entry += size; + } +return NULL ; +} + +/* +* According to ACPI table, filter the immvoable memory regions +* and store them in immovable_mem[]. +*/ +void get_immovable_mem (void ) +{ +struct acpi_table_header *table_header; +struct acpi_subtable_header *table; +struct acpi_srat_mem_affinity *ma; +unsigned long table_end; +char arg[10 ]; +int i =0 ; +int ret; + + ret =cmdline_find_option ("acpi" , arg,sizeof (arg)); +if (ret ==3 && !strncmp (arg,"off" ,3 )) +return ; + +if (!cmdline_find_option_bool ("movable_node" )) +return ; + + table_header =get_acpi_srat_table (); +if (!table_header) +return ; + + table_end = (unsigned long )table_header + table_header->length; + + table = (struct acpi_subtable_header *) + ((unsigned long )table_header +sizeof (struct acpi_table_srat )); + +while (((unsigned long )table) + +sizeof (struct acpi_subtable_header ) < table_end) { +if (table->type ==ACPI_SRAT_TYPE_MEMORY_AFFINITY ) { + ma = (struct acpi_srat_mem_affinity *)table; +if (!(ma->flags &ACPI_SRAT_MEM_HOT_PLUGGABLE )) { + immovable_mem[i].start = ma->base_address; + immovable_mem[i].size = ma->length; + i++; + } + +if (i >=MAX_NUMNODES *2 ) { +debug_putstr ("Too many immovable memory regions, aborted.\n" ); +break ; + } + } + table = (struct acpi_subtable_header *) + ((unsigned long )table + table->length); + } + num_immovable_mem = i; +}arch/x86/boot/compressed/kaslr.c +0
-4@@ -87,10 +87,6 @@ static unsigned long get_boot_seed(void)#define KASLR_COMPRESSED_BOOT #include "../../lib/kaslr.c" -struct mem_vector { -unsigned long long start; -unsigned long long size; -};/* Only supporting at most 4 unusable memmap regions with kaslr */ #define MAX_MEMMAP_REGIONS 4arch/x86/boot/compressed/misc.h +15
-0@@ -77,6 +77,11 @@ void choose_random_location(unsigned long input,unsigned long *output, unsigned long output_size, unsigned long *virt_addr); +struct mem_vector { +unsigned long long start; +unsigned long long size; +}; +/* cpuflags.c */ bool has_cpuflag (int flag);#else @@ -116,3 +121,13 @@ static inline void console_init(void)void set_sev_encryption_mask (void );#endif + +/* acpitb.c */ +#ifdef CONFIG_RANDOMIZE_BASE +int num_immovable_mem; +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the amount of immovable memory regions */ +#define ACPI_MAX_TABLES 128 +void get_immovable_mem (void ); +#endif +#endif Signature · 1 line
2.19.1
Borislav Petkov
maintainerRe: [PATCH v11 4/5] x86/boot: Dig out SRAT table from RSDP and find immovable memory
In reply to Chao FanQuoted 1 line · Chao Fan
To avoid KASLR extracting kernel on movable memory, slove the
^^^^^
Please introduce a spellchecker into your patch creation workflow.
Quoted 1 line
conflict between KASLR and
movable_nodefeature, dig the SRAT tables
s/dig/determine/ or "compute SRAT table's address" or so.
Also, replace "dig" with a more suitable verb in all your patches.
Quoted 2 lines
from RSDP pointer. Walk the SRAT tables and store the immovable memory regions in immovable_mem[].
"... in an array called immovable_mem[]."
Quoted 2 lines
There are three methods to get RSDP pointer: KEXEC condition, EFI confition, BIOS condition.
"condition" is not the right word here.
Quoted 6 lines
If KEXEC add '
acpi_rsdp' to cmdline, use it.
Otherwise, parse EFI table for RSDP.
Then, search memory for RSDP.Imitate from ACPI code, based on
acpi_os_get_root_pointer().
Process: RSDP->RSDT/XSDT->ACPI roottable->SRAT.
What?!
This looks like a comment you've added as a note for yourself but not part of the final commit message. If you wanna explain the process, then write it out in plain english as if you're explaining it to someone who doesn't know what you're doing.
Quoted 14 lines
Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/Makefile | 4 + arch/x86/boot/compressed/acpitb.c | 139 ++++++++++++++++++++++++++++++ arch/x86/boot/compressed/kaslr.c | 4 - arch/x86/boot/compressed/misc.h | 15 ++++ 4 files changed, 158 insertions(+), 4 deletions(-)arch/x86/boot/compressed/Makefile +0
-0
arch/x86/boot/compressed/Makefile ifdef CONFIG_X86_64 · line 89
Quoted 6 lines
arch/x86/boot/compressed/Makefile +3
-0@@ -84,6 +84,10 @@ ifdef CONFIG_X86_64 vmlinux-objs-y += $(obj)/pgtable_64.o endif +#if (defined CONFIG_MEMORY_HOTREMOVE) && (defined CONFIG_RANDOMIZE_BASE) +vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/acpitb.o +#endif
Right, as previously pointed out, this needs that CONFIG_ symbol and then you can save yourself most (if not all) of the ifdeffery in the rest of the patchset.
Quoted 68 lines
arch/x86/boot/compressed/Makefile +1
-0+ $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \arch/x86/boot/compressed/acpitb.c +49
-0@@ -14,6 +14,11 @@#define BOOT_STRING #include "../string.h" +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the immovable memory regions */ +struct mem_vector immovable_mem[MAX_NUMNODES *2 ]; +#endif +/* Search EFI table for RSDP table. */ static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr) {@@ -226,3 +231,137 @@ static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) }#endif } + +/* +* Used to dig RSDP table from EFI table or BIOS. +* If RSDP table found in EFI table, use it. Or search BIOS. +* Based on acpi_os_get_root_pointer(). +*/ +static acpi_physical_address get_rsdp_addr (void ) +{ +acpi_physical_address pa =0 ; + +get_acpi_rsdp (&pa); + +if (!pa) +efi_get_rsdp_addr (&pa); + +if (!pa) +bios_get_rsdp_addr (&pa); + +return pa; +} + +static struct acpi_table_header *get_acpi_srat_table (void ) +{ +acpi_physical_address acpi_table; +acpi_physical_address root_table; +struct acpi_table_header *header; +struct acpi_table_rsdp *rsdp; +bool acpi_use_rsdt = false; +char *signature; +char arg[10 ]; +u8 *entry; +u32 count; +u32 size; +int i, j; +int ret; +u32 len; + + rsdp = (struct acpi_table_rsdp *)get_rsdp_addr (); +if (!rsdp) +return NULL ; + + ret =cmdline_find_option ("acpi" , arg,sizeof (arg)); +if (ret ==4 && !strncmp (arg,"rsdt" ,4 )) + acpi_use_rsdt = true;
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 287
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +10
-0+ +/* Get RSDT or XSDT from RSDP. */ +if (!acpi_use_rsdt && + rsdp->xsdt_physical_address && rsdp->revision >1 ) { + root_table = rsdp->xsdt_physical_address; + size =ACPI_XSDT_ENTRY_SIZE ; + }else { + root_table = rsdp->rsdt_physical_address; + size =ACPI_RSDT_ENTRY_SIZE ; + }
Reorganize that code here to get rid of acpi_use_rsdt.
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 291
Quoted 4 lines
arch/x86/boot/compressed/acpitb.c +4
-0+ +/* Get ACPI root table from RSDT or XSDT.*/ + header = (struct acpi_table_header *)root_table; + len = header->length;
No checking of that header pointer before dereffing it?
If it is NUL, that gives you a very nasty bug to try to debug in the early code.
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 292
Quoted 1 line
arch/x86/boot/compressed/acpitb.c +1
-0+ count = (u32)((len -sizeof (struct acpi_table_header )) / size);
Uuh, no checking for count wrapping around here due to wrong len? That would give you a *lot* of looping below if it wraps.
IOW, you need to verify all those values before doing arithmetic with them - it is early code and it is BIOS - there's no trusting it.
Also, it is not "count" but "num_entries" or so.
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 295
Quoted 3 lines
arch/x86/boot/compressed/acpitb.c +3
-0+ entry =ACPI_ADD_PTR (u8, header,sizeof (struct acpi_table_header )); + +for (i =0 ; i < count; i++) {
That variable i is not needed, right?
while (num_entries--)
?
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 306
Quoted 11 lines
arch/x86/boot/compressed/acpitb.c +11
-0+u64 address64; + +if (size ==ACPI_RSDT_ENTRY_SIZE ) + acpi_table = ((acpi_physical_address) + (*ACPI_CAST_PTR (u32, entry))); +else { + *(u64 *)(void *)&address64 = *(u64 *)(void *)entry; + acpi_table = (acpi_physical_address ) address64; + } + +if (acpi_table) {
Now can acpi_table be NUL here?
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 319
Quoted 13 lines
arch/x86/boot/compressed/acpitb.c +13
-0+ header = (struct acpi_table_header *)acpi_table; + signature = header->signature; + +if (ACPI_COMPARE_NAME (header->signature,ACPI_SIG_SRAT )) +return header; + } + entry += size; + } +return NULL ; +} + +/* +* According to ACPI table, filter the immvoable memory regions
^^^^^^^^^
Typo.
Quoted 30 lines
arch/x86/boot/compressed/acpitb.c +30
-0+* and store them in immovable_mem[]. +*/ +void get_immovable_mem (void ) +{ +struct acpi_table_header *table_header; +struct acpi_subtable_header *table; +struct acpi_srat_mem_affinity *ma; +unsigned long table_end; +char arg[10 ]; +int i =0 ; +int ret; + + ret =cmdline_find_option ("acpi" , arg,sizeof (arg)); +if (ret ==3 && !strncmp (arg,"off" ,3 )) +return ; + +if (!cmdline_find_option_bool ("movable_node" )) +return ; + + table_header =get_acpi_srat_table (); +if (!table_header) +return ; + + table_end = (unsigned long )table_header + table_header->length; + + table = (struct acpi_subtable_header *) + ((unsigned long )table_header +sizeof (struct acpi_table_srat )); + +while (((unsigned long )table) + +sizeof (struct acpi_subtable_header ) < table_end) {
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 359
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +10
-0+if (table->type ==ACPI_SRAT_TYPE_MEMORY_AFFINITY ) { + ma = (struct acpi_srat_mem_affinity *)table; +if (!(ma->flags &ACPI_SRAT_MEM_HOT_PLUGGABLE )) { + immovable_mem[i].start = ma->base_address; + immovable_mem[i].size = ma->length; + i++; + } + +if (i >=MAX_NUMNODES *2 ) { +debug_putstr ("Too many immovable memory regions, aborted.\n" );
"..., aborting."
Quoted 40 lines
arch/x86/boot/compressed/acpitb.c +8
-0+break ; + } + } + table = (struct acpi_subtable_header *) + ((unsigned long )table + table->length); + } + num_immovable_mem = i; +}arch/x86/boot/compressed/kaslr.c +0
-4@@ -87,10 +87,6 @@ static unsigned long get_boot_seed(void)#define KASLR_COMPRESSED_BOOT #include "../../lib/kaslr.c" -struct mem_vector { -unsigned long long start; -unsigned long long size; -};/* Only supporting at most 4 unusable memmap regions with kaslr */ #define MAX_MEMMAP_REGIONS 4arch/x86/boot/compressed/misc.h +5
-0@@ -77,6 +77,11 @@ void choose_random_location(unsigned long input,unsigned long *output, unsigned long output_size, unsigned long *virt_addr); +struct mem_vector { +unsigned long long start; +unsigned long long size; +}; +/* cpuflags.c */ bool has_cpuflag (int flag);#else
arch/x86/boot/compressed/misc.h static inline void console_init(void) · line 129
Quoted 9 lines
arch/x86/boot/compressed/misc.h +6
-0@@ -116,3 +121,13 @@ static inline void console_init(void)void set_sev_encryption_mask (void );#endif + +/* acpitb.c */ +#ifdef CONFIG_RANDOMIZE_BASE +int num_immovable_mem; +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the amount of immovable memory regions */
Above says "regions" but define below is "TABLES". Hmmm?
Quoted 5 lines
arch/x86/boot/compressed/misc.h +4
-0+#define ACPI_MAX_TABLES 128 +void get_immovable_mem (void ); +#endif +#endif
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [PATCH v11 4/5] x86/boot: Dig out SRAT table from RSDP and find immovable memory
Quoted 5 lines · Borislav Petkov
Quoted 1 line · Chao Fan
To avoid KASLR extracting kernel on movable memory, slove the
^^^^^Please introduce a spellchecker into your patch creation workflow.
OK.
Quoted 6 lines
Quoted 2 lines
conflict between KASLR and
movable_nodefeature, dig the SRAT tabless/dig/determine/ or "compute SRAT table's address" or so.
Also, replace "dig" with a more suitable verb in all your patches.
How about "search RSDP pointer"
Quoted 5 lines
Quoted 3 lines
from RSDP pointer. Walk the SRAT tables and store the immovable memory regions in immovable_mem[].
"... in an array called immovable_mem[]."
Looks good.
Quoted 13 lines
Quoted 3 lines
There are three methods to get RSDP pointer: KEXEC condition, EFI confition, BIOS condition.
"condition" is not the right word here.
Quoted 6 lines
If KEXEC add '
acpi_rsdp' to cmdline, use it.
Otherwise, parse EFI table for RSDP.
Then, search memory for RSDP.Imitate from ACPI code, based on
acpi_os_get_root_pointer().
Process: RSDP->RSDT/XSDT->ACPI roottable->SRAT.
Quoted 6 lines
What?!
This looks like a comment you've added as a note for yourself but not part of the final commit message. If you wanna explain the process, then write it out in plain english as if you're explaining it to someone who doesn't know what you're doing.
OK.
Quoted 18 lines
Quoted 18 lines
Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/Makefile | 4 + arch/x86/boot/compressed/acpitb.c | 139 ++++++++++++++++++++++++++++++ arch/x86/boot/compressed/kaslr.c | 4 - arch/x86/boot/compressed/misc.h | 15 ++++ 4 files changed, 158 insertions(+), 4 deletions(-)arch/x86/boot/compressed/Makefile +0
-0@@ -84,6 +84,10 @@ ifdef CONFIG_X86_64 vmlinux-objs-y += $(obj)/pgtable_64.o endif
Quoted 7 lines
arch/x86/boot/compressed/Makefile ifdef CONFIG_X86_64 · line 89
Quoted 3 lines
arch/x86/boot/compressed/Makefile +3
-0+#if (defined CONFIG_MEMORY_HOTREMOVE) && (defined CONFIG_RANDOMIZE_BASE) +vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/acpitb.o +#endifRight, as previously pointed out, this needs that
CONFIG_symbol and then you can save yourself most (if not all) of the ifdeffery in the rest of the patchset.
That makes sense, I will do that.
Quoted 73 lines
Quoted 73 lines
arch/x86/boot/compressed/Makefile +1
-0+ $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \arch/x86/boot/compressed/acpitb.c +53
-0@@ -14,6 +14,11 @@#define BOOT_STRING #include "../string.h" +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the immovable memory regions */ +struct mem_vector immovable_mem[MAX_NUMNODES *2 ]; +#endif +/* Search EFI table for RSDP table. */ static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr) {@@ -226,3 +231,137 @@ static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) }#endif } + +/* +* Used to dig RSDP table from EFI table or BIOS. +* If RSDP table found in EFI table, use it. Or search BIOS. +* Based on acpi_os_get_root_pointer(). +*/ +static acpi_physical_address get_rsdp_addr (void ) +{ +acpi_physical_address pa =0 ; + +get_acpi_rsdp (&pa); + +if (!pa) +efi_get_rsdp_addr (&pa); + +if (!pa) +bios_get_rsdp_addr (&pa); + +return pa; +} + +static struct acpi_table_header *get_acpi_srat_table (void ) +{ +acpi_physical_address acpi_table; +acpi_physical_address root_table; +struct acpi_table_header *header; +struct acpi_table_rsdp *rsdp; +bool acpi_use_rsdt = false; +char *signature; +char arg[10 ]; +u8 *entry; +u32 count; +u32 size; +int i, j; +int ret; +u32 len; + + rsdp = (struct acpi_table_rsdp *)get_rsdp_addr (); +if (!rsdp) +return NULL ; + + ret =cmdline_find_option ("acpi" , arg,sizeof (arg)); +if (ret ==4 && !strncmp (arg,"rsdt" ,4 )) + acpi_use_rsdt = true; + +/* Get RSDT or XSDT from RSDP. */ +if (!acpi_use_rsdt && + rsdp->xsdt_physical_address && rsdp->revision >1 ) {
Quoted 8 lines
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 287
Quoted 6 lines
arch/x86/boot/compressed/acpitb.c +6
-0+ root_table = rsdp->xsdt_physical_address; + size =ACPI_XSDT_ENTRY_SIZE ; + }else { + root_table = rsdp->rsdt_physical_address; + size =ACPI_RSDT_ENTRY_SIZE ; + }Reorganize that code here to get rid of
acpi_use_rsdt.
OK.
Quoted 11 lines
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 291
Quoted 5 lines
arch/x86/boot/compressed/acpitb.c +4
-0+ +/* Get ACPI root table from RSDT or XSDT.*/ + header = (struct acpi_table_header *)root_table; + len = header->length;No checking of that header pointer before dereffing it?
If it is NUL, that gives you a very nasty bug to try to debug in the early code.
Quoted 7 lines
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 292
Quoted 1 line
arch/x86/boot/compressed/acpitb.c +1
-0+ count = (u32)((len -sizeof (struct acpi_table_header )) / size);Uuh, no checking for count wrapping around here due to wrong len? That would give you a *lot* of looping below if it wraps.
IOW, you need to verify all those values before doing arithmetic with them - it is early code and it is BIOS - there's no trusting it.
I will add the check.
Quoted 9 lines
Also, it is not "count" but "
num_entries" or so.arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 295
Quoted 3 lines
arch/x86/boot/compressed/acpitb.c +3
-0+ entry =ACPI_ADD_PTR (u8, header,sizeof (struct acpi_table_header )); + +for (i =0 ; i < count; i++) {That variable i is not needed, right?
Quoted 3 lines
while (num_entries--)
?
Yes
Quoted 15 lines
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 306
Quoted 12 lines
arch/x86/boot/compressed/acpitb.c +11
-0+u64 address64; + +if (size ==ACPI_RSDT_ENTRY_SIZE ) + acpi_table = ((acpi_physical_address) + (*ACPI_CAST_PTR (u32, entry))); +else { + *(u64 *)(void *)&address64 = *(u64 *)(void *)entry; + acpi_table = (acpi_physical_address ) address64; + } + +if (acpi_table) {Now can
acpi_tablebe NUL here?
Thank you,
I will change all of these.
Thanks,
Chao Fan
Quoted 124 lines
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 319
Quoted 13 lines
arch/x86/boot/compressed/acpitb.c +13
-0+ header = (struct acpi_table_header *)acpi_table; + signature = header->signature; + +if (ACPI_COMPARE_NAME (header->signature,ACPI_SIG_SRAT )) +return header; + } + entry += size; + } +return NULL ; +} + +/* +* According to ACPI table, filter the immvoable memory regions ^^^^^^^^^Typo.
Quoted 30 lines
arch/x86/boot/compressed/acpitb.c +30
-0+* and store them in immovable_mem[]. +*/ +void get_immovable_mem (void ) +{ +struct acpi_table_header *table_header; +struct acpi_subtable_header *table; +struct acpi_srat_mem_affinity *ma; +unsigned long table_end; +char arg[10 ]; +int i =0 ; +int ret; + + ret =cmdline_find_option ("acpi" , arg,sizeof (arg)); +if (ret ==3 && !strncmp (arg,"off" ,3 )) +return ; + +if (!cmdline_find_option_bool ("movable_node" )) +return ; + + table_header =get_acpi_srat_table (); +if (!table_header) +return ; + + table_end = (unsigned long )table_header + table_header->length; + + table = (struct acpi_subtable_header *) + ((unsigned long )table_header +sizeof (struct acpi_table_srat )); + +while (((unsigned long )table) + +sizeof (struct acpi_subtable_header ) < table_end) {arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 359
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +10
-0+if (table->type ==ACPI_SRAT_TYPE_MEMORY_AFFINITY ) { + ma = (struct acpi_srat_mem_affinity *)table; +if (!(ma->flags &ACPI_SRAT_MEM_HOT_PLUGGABLE )) { + immovable_mem[i].start = ma->base_address; + immovable_mem[i].size = ma->length; + i++; + } + +if (i >=MAX_NUMNODES *2 ) { +debug_putstr ("Too many immovable memory regions, aborted.\n" );"..., aborting."
Quoted 40 lines
arch/x86/boot/compressed/acpitb.c +8
-0+break ; + } + } + table = (struct acpi_subtable_header *) + ((unsigned long )table + table->length); + } + num_immovable_mem = i; +}arch/x86/boot/compressed/kaslr.c +0
-4@@ -87,10 +87,6 @@ static unsigned long get_boot_seed(void)#define KASLR_COMPRESSED_BOOT #include "../../lib/kaslr.c" -struct mem_vector { -unsigned long long start; -unsigned long long size; -};/* Only supporting at most 4 unusable memmap regions with kaslr */ #define MAX_MEMMAP_REGIONS 4arch/x86/boot/compressed/misc.h +5
-0@@ -77,6 +77,11 @@ void choose_random_location(unsigned long input,unsigned long *output, unsigned long output_size, unsigned long *virt_addr); +struct mem_vector { +unsigned long long start; +unsigned long long size; +}; +/* cpuflags.c */ bool has_cpuflag (int flag);#else arch/x86/boot/compressed/misc.h static inline void console_init(void) · line 129
Quoted 9 lines
arch/x86/boot/compressed/misc.h +6
-0@@ -116,3 +121,13 @@ static inline void console_init(void)void set_sev_encryption_mask (void );#endif + +/* acpitb.c */ +#ifdef CONFIG_RANDOMIZE_BASE +int num_immovable_mem; +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the amount of immovable memory regions */ Above says "regions" but define below is "TABLES". Hmmm?
Quoted 5 lines
arch/x86/boot/compressed/misc.h +4
-0+#define ACPI_MAX_TABLES 128 +void get_immovable_mem (void ); +#endif +#endif Signature · 4 lines
Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.
Re: [PATCH v11 4/5] x86/boot: Dig out SRAT table from RSDP and find immovable memory
In reply to Borislav PetkovHi Boris,
Quoted 172 lines · Borislav Petkov
Quoted 1 line · Chao Fan
To avoid KASLR extracting kernel on movable memory, slove the
^^^^^Please introduce a spellchecker into your patch creation workflow.
Quoted 1 line
conflict between KASLR and
movable_nodefeature, dig the SRAT tabless/dig/determine/ or "compute SRAT table's address" or so.
Also, replace "dig" with a more suitable verb in all your patches.
Quoted 2 lines
from RSDP pointer. Walk the SRAT tables and store the immovable memory regions in immovable_mem[].
"... in an array called immovable_mem[]."Quoted 2 lines
There are three methods to get RSDP pointer: KEXEC condition, EFI confition, BIOS condition.
"condition" is not the right word here.
Quoted 6 lines
If KEXEC add '
acpi_rsdp' to cmdline, use it.
Otherwise, parse EFI table for RSDP.
Then, search memory for RSDP.Imitate from ACPI code, based on
acpi_os_get_root_pointer().
Process: RSDP->RSDT/XSDT->ACPI roottable->SRAT.What?!
This looks like a comment you've added as a note for yourself but not part of the final commit message. If you wanna explain the process, then write it out in plain english as if you're explaining it to someone who doesn't know what you're doing.
Quoted 14 lines
Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/Makefile | 4 + arch/x86/boot/compressed/acpitb.c | 139 ++++++++++++++++++++++++++++++ arch/x86/boot/compressed/kaslr.c | 4 - arch/x86/boot/compressed/misc.h | 15 ++++ 4 files changed, 158 insertions(+), 4 deletions(-)arch/x86/boot/compressed/Makefile +0
-0arch/x86/boot/compressed/Makefile ifdef CONFIG_X86_64 · line 89
Quoted 6 lines
arch/x86/boot/compressed/Makefile +3
-0@@ -84,6 +84,10 @@ ifdef CONFIG_X86_64 vmlinux-objs-y += $(obj)/pgtable_64.o endif +#if (defined CONFIG_MEMORY_HOTREMOVE) && (defined CONFIG_RANDOMIZE_BASE) +vmlinux-objs-$(CONFIG_RANDOMIZE_BASE) += $(obj)/acpitb.o +#endifRight, as previously pointed out, this needs that
CONFIG_symbol and then you can save yourself most (if not all) of the ifdeffery in the rest of the patchset.Quoted 68 lines
arch/x86/boot/compressed/Makefile +1
-0+ $(obj)/eboot.o: KBUILD_CFLAGS += -fshort-wchar -mno-red-zone vmlinux-objs-$(CONFIG_EFI_STUB) += $(obj)/eboot.o $(obj)/efi_stub_$(BITS).o \arch/x86/boot/compressed/acpitb.c +49
-0@@ -14,6 +14,11 @@#define BOOT_STRING #include "../string.h" +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the immovable memory regions */ +struct mem_vector immovable_mem[MAX_NUMNODES *2 ]; +#endif +/* Search EFI table for RSDP table. */ static void efi_get_rsdp_addr (acpi_physical_address *rsdp_addr) {@@ -226,3 +231,137 @@ static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) }#endif } + +/* +* Used to dig RSDP table from EFI table or BIOS. +* If RSDP table found in EFI table, use it. Or search BIOS. +* Based on acpi_os_get_root_pointer(). +*/ +static acpi_physical_address get_rsdp_addr (void ) +{ +acpi_physical_address pa =0 ; + +get_acpi_rsdp (&pa); + +if (!pa) +efi_get_rsdp_addr (&pa); + +if (!pa) +bios_get_rsdp_addr (&pa); + +return pa; +} + +static struct acpi_table_header *get_acpi_srat_table (void ) +{ +acpi_physical_address acpi_table; +acpi_physical_address root_table; +struct acpi_table_header *header; +struct acpi_table_rsdp *rsdp; +bool acpi_use_rsdt = false; +char *signature; +char arg[10 ]; +u8 *entry; +u32 count; +u32 size; +int i, j; +int ret; +u32 len; + + rsdp = (struct acpi_table_rsdp *)get_rsdp_addr (); +if (!rsdp) +return NULL ; + + ret =cmdline_find_option ("acpi" , arg,sizeof (arg)); +if (ret ==4 && !strncmp (arg,"rsdt" ,4 )) + acpi_use_rsdt = true;arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 287
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +10
-0+ +/* Get RSDT or XSDT from RSDP. */ +if (!acpi_use_rsdt && + rsdp->xsdt_physical_address && rsdp->revision >1 ) { + root_table = rsdp->xsdt_physical_address; + size =ACPI_XSDT_ENTRY_SIZE ; + }else { + root_table = rsdp->rsdt_physical_address; + size =ACPI_RSDT_ENTRY_SIZE ; + }Reorganize that code here to get rid of
acpi_use_rsdt.arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 291
Quoted 4 lines
arch/x86/boot/compressed/acpitb.c +4
-0+ +/* Get ACPI root table from RSDT or XSDT.*/ + header = (struct acpi_table_header *)root_table; + len = header->length;No checking of that header pointer before dereffing it?
If it is NUL, that gives you a very nasty bug to try to debug in the early code.
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 292
Quoted 1 line
arch/x86/boot/compressed/acpitb.c +1
-0+ count = (u32)((len -sizeof (struct acpi_table_header )) / size);Uuh, no checking for count wrapping around here due to wrong len? That would give you a *lot* of looping below if it wraps.
IOW, you need to verify all those values before doing arithmetic with them - it is early code and it is BIOS - there's no trusting it.
Also, it is not "count" but "
num_entries" or so.arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 295
Quoted 3 lines
arch/x86/boot/compressed/acpitb.c +3
-0+ entry =ACPI_ADD_PTR (u8, header,sizeof (struct acpi_table_header )); + +for (i =0 ; i < count; i++) {That variable i is not needed, right?
while (num_entries--)
?
Quoted 13 lines
arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 306
Quoted 11 lines
arch/x86/boot/compressed/acpitb.c +11
-0+u64 address64; + +if (size ==ACPI_RSDT_ENTRY_SIZE ) + acpi_table = ((acpi_physical_address) + (*ACPI_CAST_PTR (u32, entry))); +else { + *(u64 *)(void *)&address64 = *(u64 *)(void *)entry; + acpi_table = (acpi_physical_address ) address64; + } + +if (acpi_table) {Now can
acpi_tablebe NUL here?
In iacpi_tb_parse_root_table() of drivers/acpi/acpica/tbutils.c:
/* Skip NULL entries in RSDT/XSDT */
if (!address) {
goto next_table;
}So I think the table might be NULL and did the similar operation.
Thanks,
Chao Fan
Quoted 125 lines
Quoted 4 lines
arch/x86/boot/compressed/acpitb.c +3
-0+ header = (struct acpi_table_header *)acpi_table; + signature = header->signature; +arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 319
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +10
-0+if (ACPI_COMPARE_NAME (header->signature,ACPI_SIG_SRAT )) +return header; + } + entry += size; + } +return NULL ; +} + +/* +* According to ACPI table, filter the immvoable memory regions ^^^^^^^^^Typo.
Quoted 30 lines
arch/x86/boot/compressed/acpitb.c +30
-0+* and store them in immovable_mem[]. +*/ +void get_immovable_mem (void ) +{ +struct acpi_table_header *table_header; +struct acpi_subtable_header *table; +struct acpi_srat_mem_affinity *ma; +unsigned long table_end; +char arg[10 ]; +int i =0 ; +int ret; + + ret =cmdline_find_option ("acpi" , arg,sizeof (arg)); +if (ret ==3 && !strncmp (arg,"off" ,3 )) +return ; + +if (!cmdline_find_option_bool ("movable_node" )) +return ; + + table_header =get_acpi_srat_table (); +if (!table_header) +return ; + + table_end = (unsigned long )table_header + table_header->length; + + table = (struct acpi_subtable_header *) + ((unsigned long )table_header +sizeof (struct acpi_table_srat )); + +while (((unsigned long )table) + +sizeof (struct acpi_subtable_header ) < table_end) {arch/x86/boot/compressed/acpitb.c static void get_acpi_rsdp(acpi_physical_address *rsdp_addr) · line 359
Quoted 10 lines
arch/x86/boot/compressed/acpitb.c +10
-0+if (table->type ==ACPI_SRAT_TYPE_MEMORY_AFFINITY ) { + ma = (struct acpi_srat_mem_affinity *)table; +if (!(ma->flags &ACPI_SRAT_MEM_HOT_PLUGGABLE )) { + immovable_mem[i].start = ma->base_address; + immovable_mem[i].size = ma->length; + i++; + } + +if (i >=MAX_NUMNODES *2 ) { +debug_putstr ("Too many immovable memory regions, aborted.\n" );"..., aborting."
Quoted 40 lines
arch/x86/boot/compressed/acpitb.c +8
-0+break ; + } + } + table = (struct acpi_subtable_header *) + ((unsigned long )table + table->length); + } + num_immovable_mem = i; +}arch/x86/boot/compressed/kaslr.c +0
-4@@ -87,10 +87,6 @@ static unsigned long get_boot_seed(void)#define KASLR_COMPRESSED_BOOT #include "../../lib/kaslr.c" -struct mem_vector { -unsigned long long start; -unsigned long long size; -};/* Only supporting at most 4 unusable memmap regions with kaslr */ #define MAX_MEMMAP_REGIONS 4arch/x86/boot/compressed/misc.h +5
-0@@ -77,6 +77,11 @@ void choose_random_location(unsigned long input,unsigned long *output, unsigned long output_size, unsigned long *virt_addr); +struct mem_vector { +unsigned long long start; +unsigned long long size; +}; +/* cpuflags.c */ bool has_cpuflag (int flag);#else arch/x86/boot/compressed/misc.h static inline void console_init(void) · line 129
Quoted 9 lines
arch/x86/boot/compressed/misc.h +6
-0@@ -116,3 +121,13 @@ static inline void console_init(void)void set_sev_encryption_mask (void );#endif + +/* acpitb.c */ +#ifdef CONFIG_RANDOMIZE_BASE +int num_immovable_mem; +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the amount of immovable memory regions */ Above says "regions" but define below is "TABLES". Hmmm?
Quoted 5 lines
arch/x86/boot/compressed/misc.h +4
-0+#define ACPI_MAX_TABLES 128 +void get_immovable_mem (void ); +#endif +#endif Signature · 4 lines
Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.
PATCH v11 5/5 x86/boot/KASLR: Walk srat tables to filter immovable memory
In reply to Chao FanKASLR may randomly chooses some positions which are located in movable memory regions. This will break memory hotplug feature and make the movable memory chosen by KASLR can't be removed.
The solution is limite KASLR to choose memory regions in immovable node according to SRAT tables.
If CONFIG_MEMORY_HOTREMOVE enabled, walk through the SRAT memory tables and store those immovable memory regions so that KASLR can get where to choose for randomization.
If the amount of immovable memory regions is not zero, which means the immovable memory regions existing. Calculate the intersection between memory regions from e820/efi memory table and immovable memory regions.
--- arch/x86/boot/compressed/kaslr.c | 77 +++++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 11 deletions(-)
arch/x86/boot/compressed/kaslr.c +66 -11
@@ -97,6 +97,11 @@ static bool memmap_too_large;/* Store memory limit specified by "mem=nn[KMG]" or "memmap=nn[KMG]" */ static unsigned long long mem_limit =ULLONG_MAX ; +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the immovable memory regions */ +extern struct mem_vector immovable_mem[MAX_NUMNODES *2 ]; +#endif +enum mem_avoid_index {MEM_AVOID_ZO_RANGE =0 ,
@@ -413,6 +418,11 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size,/* Mark the memmap regions we need to avoid */ handle_mem_options (); +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Mark the immovable regions we need to choose */ +get_immovable_mem (); +#endif +#ifdef CONFIG_X86_VERBOSE_BOOTUP /* Make sure video RAM can be used. */ add_identity_map (0 ,PMD_SIZE );
@@ -568,9 +578,9 @@ static unsigned long slots_fetch_random(void)return 0 ; } -static void process_mem_region (struct mem_vector *entry, -unsigned long minimum, -unsigned long image_size) +static void slots_count (struct mem_vector *entry, +unsigned long minimum, +unsigned long image_size) {struct mem_vector region, overlap;unsigned long start_orig, end;
@@ -646,6 +656,57 @@ static void process_mem_region(struct mem_vector *entry, } } +static bool process_mem_region (struct mem_vector *region, +unsigned long long minimum, +unsigned long long image_size) +{ +int i; +/* +* If no immovable memory found, or MEMORY_HOTREMOVE disabled, +* walk all the regions, so use region directely. +*/ +if (num_immovable_mem ==0 ) { +slots_count (region, minimum, image_size); + +if (slot_area_index ==MAX_SLOT_AREA ) { +debug_putstr ("Aborted e820/efi memmap scan (slot_areas full)!\n" ); +return 1 ; + } +return 0 ; + } + +#ifdef CONFIG_MEMORY_HOTREMOVE +/* +* If immovable memory found, filter the intersection between +* immovable memory and region to slots_count. +* Otherwise, go on old code. +*/ +for (i =0 ; i < num_immovable_mem; i++) { +struct mem_vector entry; +unsigned long long start, end, entry_end, region_end; + +if (!mem_overlaps (region, &immovable_mem[i])) +continue ; + + start = immovable_mem[i].start; + end = start + immovable_mem[i].size; + region_end = region->start + region->size; + + entry.start =clamp (region->start, start, end); + entry_end =clamp (region_end, start, end); + entry.size = entry_end - entry.start; + +slots_count (&entry, minimum, image_size); + +if (slot_area_index ==MAX_SLOT_AREA ) { +debug_putstr ("Aborted e820/efi memmap scan (slot_areas full)!\n" ); +return 1 ; + } + } +return 0 ; +#endif +} +#ifdef CONFIG_EFI /* * Returns true if mirror region found (and must have been processed
@@ -711,11 +772,8 @@ 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 (®ion, minimum, image_size); -if (slot_area_index ==MAX_SLOT_AREA ) { -debug_putstr ("Aborted EFI scan (slot_areas full)!\n" ); +if (process_mem_region (®ion, minimum, image_size))break ; - } }return true; }
@@ -742,11 +800,8 @@ static void process_e820_entries(unsigned long minimum,continue ; region.start = entry->addr; region.size = entry->size; -process_mem_region (®ion, minimum, image_size); -if (slot_area_index ==MAX_SLOT_AREA ) { -debug_putstr ("Aborted e820 scan (slot_areas full)!\n" ); +if (process_mem_region (®ion, minimum, image_size))break ; - } } }
Signature · 1 line
2.19.1
Borislav Petkov
maintainerRe: [PATCH v11 5/5] x86/boot/KASLR: Walk srat tables to filter immovable memory
Subject: Re: [PATCH v11 5/5] x86/boot/KASLR: Walk srat tables to filter immovable memory
s/srat/SRAT/g
Quoted 1 line · Chao Fan
KASLR may randomly chooses some positions which are located in movable
choose
Quoted 2 lines
memory regions. This will break memory hotplug feature and make the movable memory chosen by KASLR can't be removed.
by KASLR practically immovable.
:)
Quoted 1 line
The solution is limite KASLR to choose memory regions in immovable
limite?
"to limit"
Quoted 3 lines
node according to SRAT tables.
If
CONFIG_MEMORY_HOTREMOVEenabled, walk through the SRAT memory
*is* enabled,
Quoted 7 lines
tables and store those immovable memory regions so that KASLR can get where to choose for randomization.
If the amount of immovable memory regions is not zero, which means the immovable memory regions existing. Calculate the intersection between memory regions from e820/efi memory table and immovable memory regions.
This is explaining *what* the patch does and generally doesn't need to be in the commit messge as people can read it in the patch itself.
Quoted 10 lines
Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/kaslr.c | 77 +++++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 11 deletions(-)arch/x86/boot/compressed/kaslr.c +0
-0
arch/x86/boot/compressed/kaslr.c static bool memmap_too_large; · line 103
Quoted 7 lines
arch/x86/boot/compressed/kaslr.c +4
-0@@ -97,6 +97,11 @@ static bool memmap_too_large;/* Store memory limit specified by "mem=nn[KMG]" or "memmap=nn[KMG]" */ static unsigned long long mem_limit =ULLONG_MAX ; +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the immovable memory regions */ +extern struct mem_vector immovable_mem[MAX_NUMNODES *2 ]; +#endif
For this and the other occurrences of ifdef CONFIG_MEMORY_HOTREMOVE, define empty stubs for those functions in a header and remove the ifdeffery at the call sites.
Quoted 17 lines
arch/x86/boot/compressed/kaslr.c +6
-0+enum mem_avoid_index {MEM_AVOID_ZO_RANGE =0 ,@@ -413,6 +418,11 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size,/* Mark the memmap regions we need to avoid */ handle_mem_options (); +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Mark the immovable regions we need to choose */ +get_immovable_mem (); +#endif +#ifdef CONFIG_X86_VERBOSE_BOOTUP /* Make sure video RAM can be used. */ add_identity_map (0 ,PMD_SIZE );
arch/x86/boot/compressed/kaslr.c static unsigned long slots_fetch_random(void) · line 581
Quoted 7 lines
arch/x86/boot/compressed/kaslr.c +1
-3@@ -568,9 +578,9 @@ static unsigned long slots_fetch_random(void)return 0 ; } -static void process_mem_region (struct mem_vector *entry, -unsigned long minimum, -unsigned long image_size) +static void slots_count(struct mem_vector *entry,
That's a strange rename.
__process_mem_region() makes more sense to me.
Quoted 7 lines
arch/x86/boot/compressed/kaslr.c +2
-0+unsigned long minimum, + unsigned long image_size) { struct mem_vector region, overlap;unsigned long start_orig, end;@@ -646,6 +656,57 @@ static void process_mem_region(struct mem_vector *entry, }
arch/x86/boot/compressed/kaslr.c static void process_mem_region(struct mem_vector *entry, · line 666
Quoted 10 lines
arch/x86/boot/compressed/kaslr.c +8
-0} +static bool process_mem_region (struct mem_vector *region, +unsigned long long minimum, +unsigned long long image_size) +{ +int i; +/* +* If no immovable memory found, or MEMORY_HOTREMOVE disabled, +* walk all the regions, so use region directely.
"directly"
arch/x86/boot/compressed/kaslr.c static void process_mem_region(struct mem_vector *entry, · line 668
Quoted 2 lines
arch/x86/boot/compressed/kaslr.c +2
-0+*/ +if (num_immovable_mem ==0 ) {
if (!...
Quoted 9 lines
arch/x86/boot/compressed/kaslr.c +9
-0+slots_count (region, minimum, image_size); + +if (slot_area_index ==MAX_SLOT_AREA ) { +debug_putstr ("Aborted e820/efi memmap scan (slot_areas full)!\n" ); +return 1 ; + } +return 0 ; + } +
Signature · 4 lines
Regards/Gruss,
Boris.
Good mailing practices for 400: avoid top-posting and trim the reply.Re: [PATCH v11 5/5] x86/boot/KASLR: Walk srat tables to filter immovable memory
Quoted 5 lines · Borislav Petkov
Subject: Re: [PATCH v11 5/5] x86/boot/KASLR: Walk srat tables to filter immovable memory
s/srat/SRAT/g
On Mon, Nov 12, 2018 at 05:46:45PM +0800, Chao Fan wrote:
Quoted 8 lines
Quoted 1 line
KASLR may randomly chooses some positions which are located in movable
choose
Quoted 2 lines
memory regions. This will break memory hotplug feature and make the movable memory chosen by KASLR can't be removed.
by KASLR practically immovable.
Thanks,
Quoted 18 lines
:)
Quoted 1 line
The solution is limite KASLR to choose memory regions in immovable
limite?
"to limit"
Quoted 3 lines
node according to SRAT tables.
If
CONFIG_MEMORY_HOTREMOVEenabled, walk through the SRAT memory*is* enabled,
Quoted 3 lines
tables and store those immovable memory regions so that KASLR can get where to choose for randomization.
Quoted 7 lines
Quoted 4 lines
If the amount of immovable memory regions is not zero, which means the immovable memory regions existing. Calculate the intersection between memory regions from e820/efi memory table and immovable memory regions.
This is explaining *what* the patch does and generally doesn't need to be in the commit messge as people can read it in the patch itself.
OK,
Quoted 14 lines
Quoted 14 lines
Signed-off-by Chao Fan <[email protected]>--- arch/x86/boot/compressed/kaslr.c | 77 +++++++++++++++++++++++++++----- 1 file changed, 66 insertions(+), 11 deletions(-)arch/x86/boot/compressed/kaslr.c +0
-0@@ -97,6 +97,11 @@ static bool memmap_too_large;/* Store memory limit specified by "mem=nn[KMG]" or "memmap=nn[KMG]" */ static unsigned long long mem_limit =ULLONG_MAX ;
Quoted 8 lines
arch/x86/boot/compressed/kaslr.c static bool memmap_too_large; · line 103
Quoted 4 lines
arch/x86/boot/compressed/kaslr.c +4
-0+#ifdef CONFIG_MEMORY_HOTREMOVE +/* Store the immovable memory regions */ +extern struct mem_vector immovable_mem[MAX_NUMNODES *2 ]; +#endif For this and the other occurrences of ifdef
CONFIG_MEMORY_HOTREMOVE, define empty stubs for those functions in a header and remove the ifdeffery at the call sites.
OK,
Quoted 21 lines
Quoted 21 lines
arch/x86/boot/compressed/kaslr.c +6
-0+enum mem_avoid_index {MEM_AVOID_ZO_RANGE =0 ,@@ -413,6 +418,11 @@ static void mem_avoid_init(unsigned long input, unsigned long input_size,/* Mark the memmap regions we need to avoid */ handle_mem_options (); +#ifdef CONFIG_MEMORY_HOTREMOVE +/* Mark the immovable regions we need to choose */ +get_immovable_mem (); +#endif +#ifdef CONFIG_X86_VERBOSE_BOOTUP /* Make sure video RAM can be used. */ add_identity_map (0 ,PMD_SIZE );@@ -568,9 +578,9 @@ static unsigned long slots_fetch_random(void)return 0 ; }
Quoted 7 lines
arch/x86/boot/compressed/kaslr.c static unsigned long slots_fetch_random(void) · line 581
Quoted 4 lines
arch/x86/boot/compressed/kaslr.c +1
-3-static void process_mem_region (struct mem_vector *entry, -unsigned long minimum, -unsigned long image_size) +static void slots_count(struct mem_vector *entry,That's a strange rename.
I will change it.
Thanks,
Chao Fan
Quoted 44 lines
__process_mem_region()makes more sense to me.Quoted 7 lines
arch/x86/boot/compressed/kaslr.c +2
-0+unsigned long minimum, + unsigned long image_size) { struct mem_vector region, overlap;unsigned long start_orig, end;@@ -646,6 +656,57 @@ static void process_mem_region(struct mem_vector *entry, }arch/x86/boot/compressed/kaslr.c static void process_mem_region(struct mem_vector *entry, · line 666
Quoted 10 lines
arch/x86/boot/compressed/kaslr.c +8
-0} +static bool process_mem_region (struct mem_vector *region, +unsigned long long minimum, +unsigned long long image_size) +{ +int i; +/* +* If no immovable memory found, or MEMORY_HOTREMOVE disabled, +* walk all the regions, so use region directely. "directly"
arch/x86/boot/compressed/kaslr.c static void process_mem_region(struct mem_vector *entry, · line 668
Quoted 2 lines
arch/x86/boot/compressed/kaslr.c +2
-0+*/ +if (num_immovable_mem ==0 ) {if (!...Quoted 9 lines
arch/x86/boot/compressed/kaslr.c +9
-0+slots_count (region, minimum, image_size); + +if (slot_area_index ==MAX_SLOT_AREA ) { +debug_putstr ("Aborted e820/efi memmap scan (slot_areas full)!\n" ); +return 1 ; + } +return 0 ; + } +Signature · 4 lines
Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.