x86/boot: a few cleanups
Subsystems (3)
v2 cover x86/boot: a few cleanups
From: "Mike Rapoport (Microsoft)" <[email protected]>
Hi,
These patches cleanup x86::setup_arch() and e820.c. No functional changes intended.
This is a resend of v2 rebased on v6.14-rc2
v2: update comments as suggested by Ingo
v1: https://lore.kernel.org/all/[email protected]
Mike Rapoport (Microsoft) (4):
x86/boot: move setting of memblock parameters to e820__memblock_setup() x86/boot: split kernel resources setup into a helper function x86/boot: split parsing of boot_params into a helper function x86/e820: drop E820_TYPE_RESERVED_KERN and related code
arch/x86/include/asm/e820/api.h | 1 - arch/x86/include/asm/e820/types.h | 9 -- arch/x86/kernel/e820.c | 95 ++++++++------------- arch/x86/kernel/setup.c | 134 ++++++++++++++---------------- arch/x86/kernel/tboot.c | 3 +- arch/x86/mm/init_64.c | 8 -- 6 files changed, 97 insertions(+), 153 deletions(-)
base-commit: a64dcfb451e254085a7daee5fe51bf22959d52d3
Signature · 1 line
2.47.2
PATCH RESEND v2 1/4 x86/boot: move setting of memblock parameters to e820__memblock_setup()
From: "Mike Rapoport (Microsoft)" <[email protected]>
Changing memblock parameters, namely bottom_up and allocation upper limit does not have any effect before memblock initialization in e820__memblock_setup().
Move the calls to memblock_set_bottom_up() and memblock_set_current_limit() to e820__memblock_setup() to group all the memblock initial setup and make setup_arch() more readable.
No functional changes.
--- arch/x86/kernel/e820.c | 30 ++++++++++++++++++++++++++++++ arch/x86/kernel/setup.c | 25 ------------------------- 2 files changed, 30 insertions(+), 25 deletions(-)
arch/x86/kernel/e820.c +30 -0
@@ -1302,6 +1302,36 @@ void __init e820__memblock_setup(void)int i;u64 end; +#ifdef CONFIG_MEMORY_HOTPLUG +/* +* Memory used by the kernel cannot be hot-removed because Linux +* cannot migrate the kernel pages. When memory hotplug is +* enabled, we should prevent memblock from allocating memory +* for the kernel. +* +* ACPI SRAT records all hotpluggable memory ranges. But before +* SRAT is parsed, we don't know about it. +* +* The kernel image is loaded into memory at very early time. We +* cannot prevent this anyway. So on NUMA system, we set any +* node the kernel resides in as un-hotpluggable. +* +* Since on modern servers, one node could have double-digit +* gigabytes memory, we can assume the memory around the kernel +* image is also un-hotpluggable. So before SRAT is parsed, just +* allocate memory near the kernel image to try the best to keep +* the kernel away from hotpluggable memory. +*/ +if (movable_node_is_enabled ()) +memblock_set_bottom_up (true); +#endif + +/* +* At this point only the first megabyte is mapped for sure, the +* rest of the memory cannot be used for memblock resizing +*/ +memblock_set_current_limit (ISA_END_ADDRESS ); +/* * The bootstrap memblock region count maximum is 128 entries * (INIT_MEMBLOCK_REGIONS), but EFI might pass us more E820 entries
arch/x86/kernel/setup.c +0 -25
@@ -866,30 +866,6 @@ void __init setup_arch(char **cmdline_p)if (efi_enabled (EFI_BOOT ))efi_memblock_x86_reserve_range (); -#ifdef CONFIG_MEMORY_HOTPLUG -/* -* Memory used by the kernel cannot be hot-removed because Linux -* cannot migrate the kernel pages. When memory hotplug is -* enabled, we should prevent memblock from allocating memory -* for the kernel. -* -* ACPI SRAT records all hotpluggable memory ranges. But before -* SRAT is parsed, we don't know about it. -* -* The kernel image is loaded into memory at very early time. We -* cannot prevent this anyway. So on NUMA system, we set any -* node the kernel resides in as un-hotpluggable. -* -* Since on modern servers, one node could have double-digit -* gigabytes memory, we can assume the memory around the kernel -* image is also un-hotpluggable. So before SRAT is parsed, just -* allocate memory near the kernel image to try the best to keep -* the kernel away from hotpluggable memory. -*/ -if (movable_node_is_enabled ()) -memblock_set_bottom_up (true); -#endif -x86_report_nx ();apic_setup_apic_calls ();
@@ -990,7 +966,6 @@ void __init setup_arch(char **cmdline_p)cleanup_highmap (); -memblock_set_current_limit (ISA_END_ADDRESS );e820__memblock_setup ();/*
Signature · 1 line
2.47.2
PATCH RESEND v2 2/4 x86/boot: split kernel resources setup into a helper function
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Makes setup_arch a bit easier to comprehend.
No functional changes.
--- arch/x86/kernel/setup.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-)
arch/x86/kernel/setup.c +22 -14
@@ -527,6 +527,23 @@ void __init reserve_standard_io_resources(void) } +static void __init setup_kernel_resources (void ) +{ + code_resource.start =__pa_symbol (_text); + code_resource.end =__pa_symbol (_etext)-1 ; + rodata_resource.start =__pa_symbol (__start_rodata); + rodata_resource.end =__pa_symbol (__end_rodata)-1 ; + data_resource.start =__pa_symbol (_sdata); + data_resource.end =__pa_symbol (_edata)-1 ; + bss_resource.start =__pa_symbol (__bss_start); + bss_resource.end =__pa_symbol (__bss_stop)-1 ; + +insert_resource (&iomem_resource, &code_resource); +insert_resource (&iomem_resource, &rodata_resource); +insert_resource (&iomem_resource, &data_resource); +insert_resource (&iomem_resource, &bss_resource); +} +static bool __init snb_gfx_workaround_needed (void ) {#ifdef CONFIG_PCI
@@ -845,15 +862,6 @@ void __init setup_arch(char **cmdline_p) root_mountflags &= ~MS_RDONLY ;setup_initial_init_mm (_text, _etext, _edata, (void *)_brk_end); - code_resource.start =__pa_symbol (_text); - code_resource.end =__pa_symbol (_etext)-1 ; - rodata_resource.start =__pa_symbol (__start_rodata); - rodata_resource.end =__pa_symbol (__end_rodata)-1 ; - data_resource.start =__pa_symbol (_sdata); - data_resource.end =__pa_symbol (_edata)-1 ; - bss_resource.start =__pa_symbol (__bss_start); - bss_resource.end =__pa_symbol (__bss_stop)-1 ; -/* * x86_configure_nx() is called before parse_early_param() to detect * whether hardware doesn't support NX (so that the early EHCI debug
@@ -897,11 +905,11 @@ void __init setup_arch(char **cmdline_p)tsc_early_init (); x86_init.resources.probe_roms (); -/* after parse_early_param, so could debug it */ -insert_resource (&iomem_resource, &code_resource); -insert_resource (&iomem_resource, &rodata_resource); -insert_resource (&iomem_resource, &data_resource); -insert_resource (&iomem_resource, &bss_resource); +/* +* Add resources for kernel text and data to the iomem_resource. +* Do it after parse_early_param, so it can be debugged. +*/ +setup_kernel_resources ();e820_add_kernel_range ();trim_bios_range ();
Signature · 1 line
2.47.2
PATCH RESEND v2 3/4 x86/boot: split parsing of boot_params into a helper function
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
Makes setup_arch a bit easier to comprehend.
No functional changes.
--- arch/x86/kernel/setup.c | 72 +++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 31 deletions(-)
arch/x86/kernel/setup.c +41 -31
@@ -429,6 +429,46 @@ static void __init parse_setup_data(void) } } +/* +* Translate the fields of 'struct boot_param' into global variables +* representing these parameters. +*/ +static void __init parse_boot_params (void ) +{ +ROOT_DEV =old_decode_dev (boot_params.hdr.root_dev); + screen_info = boot_params.screen_info; + edid_info = boot_params.edid_info; +#ifdef CONFIG_X86_32 + apm_info.bios = boot_params.apm_bios_info; + ist_info = boot_params.ist_info; +#endif + saved_video_mode = boot_params.hdr.vid_mode; + bootloader_type = boot_params.hdr.type_of_loader; +if ((bootloader_type >>4 ) ==0xe ) { + bootloader_type &=0xf ; + bootloader_type |= (boot_params.hdr.ext_loader_type+0x10 ) <<4 ; + } + bootloader_version = bootloader_type &0xf ; + bootloader_version |= boot_params.hdr.ext_loader_ver <<4 ; + +#ifdef CONFIG_BLK_DEV_RAM + rd_image_start = boot_params.hdr.ram_size &RAMDISK_IMAGE_START_MASK ; +#endif +#ifdef CONFIG_EFI +if (!strncmp ((char *)&boot_params.efi_info.efi_loader_signature, +EFI32_LOADER_SIGNATURE ,4 )) { +set_bit (EFI_BOOT , &efi.flags); + }else if (!strncmp ((char *)&boot_params.efi_info.efi_loader_signature, +EFI64_LOADER_SIGNATURE ,4 )) { +set_bit (EFI_BOOT , &efi.flags); +set_bit (EFI_64BIT , &efi.flags); + } +#endif + +if (!boot_params.hdr.root_flags) + root_mountflags &= ~MS_RDONLY ; +} +static void __init memblock_x86_reserve_range_setup_data (void ) {struct setup_indirect *indirect;
@@ -806,35 +846,7 @@ void __init setup_arch(char **cmdline_p)setup_olpc_ofw_pgd (); -ROOT_DEV =old_decode_dev (boot_params.hdr.root_dev); - screen_info = boot_params.screen_info; - edid_info = boot_params.edid_info; -#ifdef CONFIG_X86_32 - apm_info.bios = boot_params.apm_bios_info; - ist_info = boot_params.ist_info; -#endif - saved_video_mode = boot_params.hdr.vid_mode; - bootloader_type = boot_params.hdr.type_of_loader; -if ((bootloader_type >>4 ) ==0xe ) { - bootloader_type &=0xf ; - bootloader_type |= (boot_params.hdr.ext_loader_type+0x10 ) <<4 ; - } - bootloader_version = bootloader_type &0xf ; - bootloader_version |= boot_params.hdr.ext_loader_ver <<4 ; - -#ifdef CONFIG_BLK_DEV_RAM - rd_image_start = boot_params.hdr.ram_size &RAMDISK_IMAGE_START_MASK ; -#endif -#ifdef CONFIG_EFI -if (!strncmp ((char *)&boot_params.efi_info.efi_loader_signature, -EFI32_LOADER_SIGNATURE ,4 )) { -set_bit (EFI_BOOT , &efi.flags); - }else if (!strncmp ((char *)&boot_params.efi_info.efi_loader_signature, -EFI64_LOADER_SIGNATURE ,4 )) { -set_bit (EFI_BOOT , &efi.flags); -set_bit (EFI_64BIT , &efi.flags); - } -#endif +parse_boot_params (); x86_init.oem.arch_setup ();
@@ -858,8 +870,6 @@ void __init setup_arch(char **cmdline_p)copy_edd (); -if (!boot_params.hdr.root_flags) - root_mountflags &= ~MS_RDONLY ;setup_initial_init_mm (_text, _etext, _edata, (void *)_brk_end);/*
Signature · 1 line
2.47.2
PATCH RESEND v2 4/4 x86/e820: drop E820_TYPE_RESERVED_KERN and related code
In reply to Mike RapoportFrom: "Mike Rapoport (Microsoft)" <[email protected]>
E820_TYPE_RESERVED_KERN is a relict from the ancient history that was used to early reserve setup_data (see commit 28bb22379513 ("x86: move reserve_setup_data to setup.c")).
Nowadays setup_data is anyway reserved in memblock and there is no point in carrying E820_TYPE_RESERVED_KERN that behaves exactly like E820_TYPE_RAM but only complicates the code.
A bonus for removing E820_TYPE_RESERVED_KERN is a small but measurable speedup of 20 microseconds in init_mem_mappings() on a VM with 32GB or RAM.
--- arch/x86/include/asm/e820/api.h | 1 - arch/x86/include/asm/e820/types.h | 9 ----- arch/x86/kernel/e820.c | 65 ++----------------------------- arch/x86/kernel/setup.c | 1 - arch/x86/kernel/tboot.c | 3 +- arch/x86/mm/init_64.c | 8 ---- 6 files changed, 4 insertions(+), 83 deletions(-)
arch/x86/include/asm/e820/api.h +0 -1
@@ -29,7 +29,6 @@ extern unsigned long e820__end_of_low_ram_pfn(void);extern u64 e820__memblock_alloc_reserved (u64 size,u64 align);extern void e820__memblock_setup (void ); -extern void e820__reserve_setup_data (void );extern void e820__finish_early_params (void );extern void e820__reserve_resources (void );extern void e820__reserve_resources_late (void );
arch/x86/include/asm/e820/types.h +0 -9
@@ -35,15 +35,6 @@ enum e820_type {* marking it with the IORES_DESC_SOFT_RESERVED designation. */ E820_TYPE_SOFT_RESERVED = 0xefffffff, - -/* -* Reserved RAM used by the kernel itself if -* CONFIG_INTEL_TXT=y is enabled, memory of this type -* will be included in the S3 integrity calculation -* and so should not include any memory that the BIOS -* might alter over the S3 transition: -*/ - E820_TYPE_RESERVED_KERN = 128, };/*
arch/x86/kernel/e820.c +3 -62
113 lines not on this page · raw message
arch/x86/kernel/setup.c +0 -1
@@ -895,7 +895,6 @@ void __init setup_arch(char **cmdline_p)setup_clear_cpu_cap (X86_FEATURE_APIC ); } -e820__reserve_setup_data ();e820__finish_early_params ();if (efi_enabled (EFI_BOOT ))
arch/x86/kernel/tboot.c +1 -2
@@ -200,8 +200,7 @@ static int tboot_setup_sleep(void) tboot->num_mac_regions =0 ;for (i =0 ; i < e820_table->nr_entries; i++) { -if ((e820_table->entries[i].type !=E820_TYPE_RAM ) - && (e820_table->entries[i].type !=E820_TYPE_RESERVED_KERN )) +if (e820_table->entries[i].type !=E820_TYPE_RAM )continue ;add_mac_region (e820_table->entries[i].addr, e820_table->entries[i].size);
arch/x86/mm/init_64.c +0 -8
@@ -468,8 +468,6 @@ phys_pte_init(pte_t *pte_page, unsigned long paddr, unsigned long paddr_end,if (!after_bootmem && !e820__mapped_any (paddr &PAGE_MASK , paddr_next,E820_TYPE_RAM ) && - !e820__mapped_any (paddr &PAGE_MASK , paddr_next, -E820_TYPE_RESERVED_KERN ) && !e820__mapped_any (paddr &PAGE_MASK , paddr_next,E820_TYPE_ACPI ))set_pte_init (pte,__pte (0 ), init);
@@ -525,8 +523,6 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long paddr, unsigned long paddr_end,if (!after_bootmem && !e820__mapped_any (paddr &PMD_MASK , paddr_next,E820_TYPE_RAM ) && - !e820__mapped_any (paddr &PMD_MASK , paddr_next, -E820_TYPE_RESERVED_KERN ) && !e820__mapped_any (paddr &PMD_MASK , paddr_next,E820_TYPE_ACPI ))set_pmd_init (pmd,__pmd (0 ), init);
@@ -614,8 +610,6 @@ phys_pud_init(pud_t *pud_page, unsigned long paddr, unsigned long paddr_end,if (!after_bootmem && !e820__mapped_any (paddr &PUD_MASK , paddr_next,E820_TYPE_RAM ) && - !e820__mapped_any (paddr &PUD_MASK , paddr_next, -E820_TYPE_RESERVED_KERN ) && !e820__mapped_any (paddr &PUD_MASK , paddr_next,E820_TYPE_ACPI ))set_pud_init (pud,__pud (0 ), init);
@@ -703,8 +697,6 @@ phys_p4d_init(p4d_t *p4d_page, unsigned long paddr, unsigned long paddr_end,if (!after_bootmem && !e820__mapped_any (paddr &P4D_MASK , paddr_next,E820_TYPE_RAM ) && - !e820__mapped_any (paddr &P4D_MASK , paddr_next, -E820_TYPE_RESERVED_KERN ) && !e820__mapped_any (paddr &P4D_MASK , paddr_next,E820_TYPE_ACPI ))set_p4d_init (p4d,__p4d (0 ), init);
Signature · 1 line
2.47.2
[tip: x86/boot] x86/boot: Split kernel resources setup into the setup_kernel_resources() helper function
In reply to Mike RapoportThe following commit has been merged into the x86/boot branch of tip:
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: 297fb82ebaad50e1c40aab7ac61897bf372842ba Gitweb: https://git.kernel.org/tip/297fb82ebaad50e1c40aab7ac61897bf372842ba Author: Mike Rapoport (Microsoft) <[email protected]> AuthorDate: Fri, 14 Feb 2025 11:06:49 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 21 Feb 2025 16:05:00 +01:00
x86/boot: Split kernel resources setup into the setup_kernel_resources() helper function
Makes setup_arch() a bit easier to comprehend.
No functional changes.
--- arch/x86/kernel/setup.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-)
arch/x86/kernel/setup.c +22 -14
@@ -527,6 +527,23 @@ void __init reserve_standard_io_resources(void) } +static void __init setup_kernel_resources (void ) +{ + code_resource.start =__pa_symbol (_text); + code_resource.end =__pa_symbol (_etext)-1 ; + rodata_resource.start =__pa_symbol (__start_rodata); + rodata_resource.end =__pa_symbol (__end_rodata)-1 ; + data_resource.start =__pa_symbol (_sdata); + data_resource.end =__pa_symbol (_edata)-1 ; + bss_resource.start =__pa_symbol (__bss_start); + bss_resource.end =__pa_symbol (__bss_stop)-1 ; + +insert_resource (&iomem_resource, &code_resource); +insert_resource (&iomem_resource, &rodata_resource); +insert_resource (&iomem_resource, &data_resource); +insert_resource (&iomem_resource, &bss_resource); +} +static bool __init snb_gfx_workaround_needed (void ) {#ifdef CONFIG_PCI
@@ -845,15 +862,6 @@ void __init setup_arch(char **cmdline_p) root_mountflags &= ~MS_RDONLY ;setup_initial_init_mm (_text, _etext, _edata, (void *)_brk_end); - code_resource.start =__pa_symbol (_text); - code_resource.end =__pa_symbol (_etext)-1 ; - rodata_resource.start =__pa_symbol (__start_rodata); - rodata_resource.end =__pa_symbol (__end_rodata)-1 ; - data_resource.start =__pa_symbol (_sdata); - data_resource.end =__pa_symbol (_edata)-1 ; - bss_resource.start =__pa_symbol (__bss_start); - bss_resource.end =__pa_symbol (__bss_stop)-1 ; -/* * x86_configure_nx() is called before parse_early_param() to detect * whether hardware doesn't support NX (so that the early EHCI debug
@@ -897,11 +905,11 @@ void __init setup_arch(char **cmdline_p)tsc_early_init (); x86_init.resources.probe_roms (); -/* after parse_early_param, so could debug it */ -insert_resource (&iomem_resource, &code_resource); -insert_resource (&iomem_resource, &rodata_resource); -insert_resource (&iomem_resource, &data_resource); -insert_resource (&iomem_resource, &bss_resource); +/* +* Add resources for kernel text and data to the iomem_resource. +* Do it after parse_early_param, so it can be debugged. +*/ +setup_kernel_resources ();e820_add_kernel_range ();trim_bios_range ();
[tip: x86/boot] x86/boot: Split parsing of boot_params into the parse_boot_params() helper function
In reply to Mike RapoportThe following commit has been merged into the x86/boot branch of tip:
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: d45dd0a9b27ee8be7792ae186bc33ed700144224 Gitweb: https://git.kernel.org/tip/d45dd0a9b27ee8be7792ae186bc33ed700144224 Author: Mike Rapoport (Microsoft) <[email protected]> AuthorDate: Fri, 14 Feb 2025 11:06:50 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 21 Feb 2025 16:05:00 +01:00
x86/boot: Split parsing of boot_params into the parse_boot_params() helper function
Makes setup_arch() a bit easier to comprehend.
No functional changes.
--- arch/x86/kernel/setup.c | 72 ++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 31 deletions(-)
arch/x86/kernel/setup.c +41 -31
@@ -429,6 +429,46 @@ static void __init parse_setup_data(void) } } +/* +* Translate the fields of 'struct boot_param' into global variables +* representing these parameters. +*/ +static void __init parse_boot_params (void ) +{ +ROOT_DEV =old_decode_dev (boot_params.hdr.root_dev); + screen_info = boot_params.screen_info; + edid_info = boot_params.edid_info; +#ifdef CONFIG_X86_32 + apm_info.bios = boot_params.apm_bios_info; + ist_info = boot_params.ist_info; +#endif + saved_video_mode = boot_params.hdr.vid_mode; + bootloader_type = boot_params.hdr.type_of_loader; +if ((bootloader_type >>4 ) ==0xe ) { + bootloader_type &=0xf ; + bootloader_type |= (boot_params.hdr.ext_loader_type+0x10 ) <<4 ; + } + bootloader_version = bootloader_type &0xf ; + bootloader_version |= boot_params.hdr.ext_loader_ver <<4 ; + +#ifdef CONFIG_BLK_DEV_RAM + rd_image_start = boot_params.hdr.ram_size &RAMDISK_IMAGE_START_MASK ; +#endif +#ifdef CONFIG_EFI +if (!strncmp ((char *)&boot_params.efi_info.efi_loader_signature, +EFI32_LOADER_SIGNATURE ,4 )) { +set_bit (EFI_BOOT , &efi.flags); + }else if (!strncmp ((char *)&boot_params.efi_info.efi_loader_signature, +EFI64_LOADER_SIGNATURE ,4 )) { +set_bit (EFI_BOOT , &efi.flags); +set_bit (EFI_64BIT , &efi.flags); + } +#endif + +if (!boot_params.hdr.root_flags) + root_mountflags &= ~MS_RDONLY ; +} +static void __init memblock_x86_reserve_range_setup_data (void ) {struct setup_indirect *indirect;
@@ -806,35 +846,7 @@ void __init setup_arch(char **cmdline_p)setup_olpc_ofw_pgd (); -ROOT_DEV =old_decode_dev (boot_params.hdr.root_dev); - screen_info = boot_params.screen_info; - edid_info = boot_params.edid_info; -#ifdef CONFIG_X86_32 - apm_info.bios = boot_params.apm_bios_info; - ist_info = boot_params.ist_info; -#endif - saved_video_mode = boot_params.hdr.vid_mode; - bootloader_type = boot_params.hdr.type_of_loader; -if ((bootloader_type >>4 ) ==0xe ) { - bootloader_type &=0xf ; - bootloader_type |= (boot_params.hdr.ext_loader_type+0x10 ) <<4 ; - } - bootloader_version = bootloader_type &0xf ; - bootloader_version |= boot_params.hdr.ext_loader_ver <<4 ; - -#ifdef CONFIG_BLK_DEV_RAM - rd_image_start = boot_params.hdr.ram_size &RAMDISK_IMAGE_START_MASK ; -#endif -#ifdef CONFIG_EFI -if (!strncmp ((char *)&boot_params.efi_info.efi_loader_signature, -EFI32_LOADER_SIGNATURE ,4 )) { -set_bit (EFI_BOOT , &efi.flags); - }else if (!strncmp ((char *)&boot_params.efi_info.efi_loader_signature, -EFI64_LOADER_SIGNATURE ,4 )) { -set_bit (EFI_BOOT , &efi.flags); -set_bit (EFI_64BIT , &efi.flags); - } -#endif +parse_boot_params (); x86_init.oem.arch_setup ();
@@ -858,8 +870,6 @@ void __init setup_arch(char **cmdline_p)copy_edd (); -if (!boot_params.hdr.root_flags) - root_mountflags &= ~MS_RDONLY ;setup_initial_init_mm (_text, _etext, _edata, (void *)_brk_end);/*
[tip: x86/boot] x86/e820: Drop obsolete E820_TYPE_RESERVED_KERN and related code
In reply to Mike RapoportThe following commit has been merged into the x86/boot branch of tip:
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: efe659ac014647eb048d62475e55cce42d8951d7 Gitweb: https://git.kernel.org/tip/efe659ac014647eb048d62475e55cce42d8951d7 Author: Mike Rapoport (Microsoft) <[email protected]> AuthorDate: Fri, 14 Feb 2025 11:06:51 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 21 Feb 2025 16:05:00 +01:00
x86/e820: Drop obsolete E820_TYPE_RESERVED_KERN and related code
E820_TYPE_RESERVED_KERN is a relict from the ancient history that was used to early reserve setup_data, see:
28bb22379513 ("x86: move reserve_setup_data to setup.c")
Nowadays setup_data is anyway reserved in memblock and there is no point in carrying E820_TYPE_RESERVED_KERN that behaves exactly like E820_TYPE_RAM but only complicates the code.
A bonus for removing E820_TYPE_RESERVED_KERN is a small but measurable speedup of 20 microseconds in init_mem_mappings() on a VM with 32GB or RAM.
--- arch/x86/include/asm/e820/api.h | 1 +- arch/x86/include/asm/e820/types.h | 9 +---- arch/x86/kernel/e820.c | 65 +----------------------------- arch/x86/kernel/setup.c | 1 +- arch/x86/kernel/tboot.c | 3 +- arch/x86/mm/init_64.c | 8 +---- 6 files changed, 4 insertions(+), 83 deletions(-)
arch/x86/include/asm/e820/api.h +0 -1
@@ -29,7 +29,6 @@ extern unsigned long e820__end_of_low_ram_pfn(void);extern u64 e820__memblock_alloc_reserved (u64 size,u64 align);extern void e820__memblock_setup (void ); -extern void e820__reserve_setup_data (void );extern void e820__finish_early_params (void );extern void e820__reserve_resources (void );extern void e820__reserve_resources_late (void );
arch/x86/include/asm/e820/types.h +0 -9
@@ -35,15 +35,6 @@ enum e820_type {* marking it with the IORES_DESC_SOFT_RESERVED designation. */ E820_TYPE_SOFT_RESERVED = 0xefffffff, - -/* -* Reserved RAM used by the kernel itself if -* CONFIG_INTEL_TXT=y is enabled, memory of this type -* will be included in the S3 integrity calculation -* and so should not include any memory that the BIOS -* might alter over the S3 transition: -*/ - E820_TYPE_RESERVED_KERN = 128, };/*
arch/x86/kernel/e820.c +3 -62
113 lines not on this page · raw message
arch/x86/kernel/setup.c +0 -1
@@ -895,7 +895,6 @@ void __init setup_arch(char **cmdline_p)setup_clear_cpu_cap (X86_FEATURE_APIC ); } -e820__reserve_setup_data ();e820__finish_early_params ();if (efi_enabled (EFI_BOOT ))
arch/x86/kernel/tboot.c +1 -2
@@ -200,8 +200,7 @@ static int tboot_setup_sleep(void) tboot->num_mac_regions =0 ;for (i =0 ; i < e820_table->nr_entries; i++) { -if ((e820_table->entries[i].type !=E820_TYPE_RAM ) - && (e820_table->entries[i].type !=E820_TYPE_RESERVED_KERN )) +if (e820_table->entries[i].type !=E820_TYPE_RAM )continue ;add_mac_region (e820_table->entries[i].addr, e820_table->entries[i].size);
arch/x86/mm/init_64.c +0 -8
@@ -469,8 +469,6 @@ phys_pte_init(pte_t *pte_page, unsigned long paddr, unsigned long paddr_end, !e820__mapped_any(paddr & PAGE_MASK, paddr_next, E820_TYPE_RAM) && !e820__mapped_any(paddr & PAGE_MASK, paddr_next, -E820_TYPE_RESERVED_KERN ) && - !e820__mapped_any (paddr &PAGE_MASK , paddr_next, E820_TYPE_ACPI))set_pte_init (pte,__pte (0 ), init);continue ;
@@ -526,8 +524,6 @@ phys_pmd_init(pmd_t *pmd_page, unsigned long paddr, unsigned long paddr_end, !e820__mapped_any(paddr & PMD_MASK, paddr_next, E820_TYPE_RAM) && !e820__mapped_any(paddr & PMD_MASK, paddr_next, -E820_TYPE_RESERVED_KERN ) && - !e820__mapped_any (paddr &PMD_MASK , paddr_next, E820_TYPE_ACPI))set_pmd_init (pmd,__pmd (0 ), init);continue ;
@@ -615,8 +611,6 @@ phys_pud_init(pud_t *pud_page, unsigned long paddr, unsigned long paddr_end, !e820__mapped_any(paddr & PUD_MASK, paddr_next, E820_TYPE_RAM) && !e820__mapped_any(paddr & PUD_MASK, paddr_next, -E820_TYPE_RESERVED_KERN ) && - !e820__mapped_any (paddr &PUD_MASK , paddr_next, E820_TYPE_ACPI))set_pud_init (pud,__pud (0 ), init);continue ;
@@ -704,8 +698,6 @@ phys_p4d_init(p4d_t *p4d_page, unsigned long paddr, unsigned long paddr_end, !e820__mapped_any(paddr & P4D_MASK, paddr_next, E820_TYPE_RAM) && !e820__mapped_any(paddr & P4D_MASK, paddr_next, -E820_TYPE_RESERVED_KERN ) && - !e820__mapped_any (paddr &P4D_MASK , paddr_next, E820_TYPE_ACPI))set_p4d_init (p4d,__p4d (0 ), init);continue ;
[tip: x86/boot] x86/boot: Move setting of memblock parameters to e820__memblock_setup()
In reply to Mike RapoportThe following commit has been merged into the x86/boot branch of tip:
The following commit has been merged into the x86/boot branch of tip:
Commit-ID: 2d6bff31399b2443aba230cd20f120acb2d4eeb1 Gitweb: https://git.kernel.org/tip/2d6bff31399b2443aba230cd20f120acb2d4eeb1 Author: Mike Rapoport (Microsoft) <[email protected]> AuthorDate: Fri, 14 Feb 2025 11:06:48 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Fri, 21 Feb 2025 16:05:00 +01:00
x86/boot: Move setting of memblock parameters to e820__memblock_setup()
Changing memblock parameters, namely bottom_up and allocation upper limit does not have any effect before memblock initialization in e820__memblock_setup().
Move the calls to memblock_set_bottom_up() and memblock_set_current_limit() to e820__memblock_setup() to group all the memblock initial setup and make setup_arch() more readable.
No functional changes.
--- arch/x86/kernel/e820.c | 30 ++++++++++++++++++++++++++++++ arch/x86/kernel/setup.c | 25 ------------------------- 2 files changed, 30 insertions(+), 25 deletions(-)
arch/x86/kernel/e820.c +30 -0
@@ -1302,6 +1302,36 @@ void __init e820__memblock_setup(void)int i;u64 end; +#ifdef CONFIG_MEMORY_HOTPLUG +/* +* Memory used by the kernel cannot be hot-removed because Linux +* cannot migrate the kernel pages. When memory hotplug is +* enabled, we should prevent memblock from allocating memory +* for the kernel. +* +* ACPI SRAT records all hotpluggable memory ranges. But before +* SRAT is parsed, we don't know about it. +* +* The kernel image is loaded into memory at very early time. We +* cannot prevent this anyway. So on NUMA system, we set any +* node the kernel resides in as un-hotpluggable. +* +* Since on modern servers, one node could have double-digit +* gigabytes memory, we can assume the memory around the kernel +* image is also un-hotpluggable. So before SRAT is parsed, just +* allocate memory near the kernel image to try the best to keep +* the kernel away from hotpluggable memory. +*/ +if (movable_node_is_enabled ()) +memblock_set_bottom_up (true); +#endif + +/* +* At this point only the first megabyte is mapped for sure, the +* rest of the memory cannot be used for memblock resizing +*/ +memblock_set_current_limit (ISA_END_ADDRESS ); +/* * The bootstrap memblock region count maximum is 128 entries * (INIT_MEMBLOCK_REGIONS), but EFI might pass us more E820 entries
arch/x86/kernel/setup.c +0 -25
@@ -866,30 +866,6 @@ void __init setup_arch(char **cmdline_p)if (efi_enabled (EFI_BOOT ))efi_memblock_x86_reserve_range (); -#ifdef CONFIG_MEMORY_HOTPLUG -/* -* Memory used by the kernel cannot be hot-removed because Linux -* cannot migrate the kernel pages. When memory hotplug is -* enabled, we should prevent memblock from allocating memory -* for the kernel. -* -* ACPI SRAT records all hotpluggable memory ranges. But before -* SRAT is parsed, we don't know about it. -* -* The kernel image is loaded into memory at very early time. We -* cannot prevent this anyway. So on NUMA system, we set any -* node the kernel resides in as un-hotpluggable. -* -* Since on modern servers, one node could have double-digit -* gigabytes memory, we can assume the memory around the kernel -* image is also un-hotpluggable. So before SRAT is parsed, just -* allocate memory near the kernel image to try the best to keep -* the kernel away from hotpluggable memory. -*/ -if (movable_node_is_enabled ()) -memblock_set_bottom_up (true); -#endif -x86_report_nx ();apic_setup_apic_calls ();
@@ -990,7 +966,6 @@ void __init setup_arch(char **cmdline_p)cleanup_highmap (); -memblock_set_current_limit (ISA_END_ADDRESS );e820__memblock_setup ();/*