From nobody Wed Mar 12 23:56:47 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5D8022D4F9 for ; Fri, 14 Feb 2025 09:07:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739524026; cv=none; b=F2cJOfumiGSWE0G6Q9YTgS/rLXeocJbhLM15dzl4ZOpSgynBjcg7znfi8O33wJsL13KJJ9Uz9i41I2AtU1SIneYXS12JYrHaljyqHDmLX4VHceM2LblIGwCRjfMHwFOPFSxhs5S5NPtkQ8BxeJr/mV07GvqYT+B5r/2Ou/8a7UY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739524026; c=relaxed/simple; bh=VY5cC0OoCHotTTh2bcJ4AeYC0N/aiMEZXSr5lf6qmUs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BQmcecFwmiNtZ6HZsQZpbSQpmq7QwBFPcHNPtnQm8eVSX2k2kmWmqqUiHyWFhyg/aBX0i5RZkZlCoj6dqSAgMRuXU/WD1wJhjsEBFwciZW74aCuAods14jXAX3d9SKZRIeTha+3f04/9HY+sCOpso8JJNbON5sHxFoDGLsP2WMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KTxvwHqi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KTxvwHqi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEE96C4CEDF; Fri, 14 Feb 2025 09:07:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739524025; bh=VY5cC0OoCHotTTh2bcJ4AeYC0N/aiMEZXSr5lf6qmUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KTxvwHqiRGf1kGHE5okKZoB3eZhB8Fyu6VPQTx3MO7VMl1rWT7+t9gd5mHuTx/sJm KR0ycYlWdjX8/88Sg9Sf1GIhuilwv6tYTRbooWigXCKpgsmvu7eyfwMnyqsz8fzAgJ HAzeSyXURUZqGDbLlohAJeP0/no1x/z6eLx7DMVlgz+ZrzmLuC+ZCBD37dwzLqrTrn 9C4jR+65jSUW03p4pJK5tymKSlcWBCEQ4cqMRdEeFDY0GnO6xEFm/FnBU1tEDkpHHX a1J79cj9umO9s7VgSKfovEmo9dszNPGB+S/RazXkc4J/tNVtFheKQz43qn3OtBfmw/ Piudi6JV9sU+A== From: Mike Rapoport To: x86@kernel.org Cc: Andy Lutomirski , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Mike Rapoport , Ning Sun , Peter Zijlstra , Thomas Gleixner , linux-kernel@vger.kernel.org, tboot-devel@lists.sourceforge.net Subject: [RESEND PATCH v2 1/4] x86/boot: move setting of memblock parameters to e820__memblock_setup() Date: Fri, 14 Feb 2025 11:06:48 +0200 Message-ID: <20250214090651.3331663-2-rppt@kernel.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250214090651.3331663-1-rppt@kernel.org> References: <20250214090651.3331663-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" 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. Signed-off-by: Mike Rapoport (Microsoft) --- arch/x86/kernel/e820.c | 30 ++++++++++++++++++++++++++++++ arch/x86/kernel/setup.c | 25 ------------------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index 82b96ed9890a..8d8bd039d2ac 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -1302,6 +1302,36 @@ void __init e820__memblock_setup(void) int i; u64 end; =20 +#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 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index cebee310e200..4baadeab8a2e 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -866,30 +866,6 @@ void __init setup_arch(char **cmdline_p) if (efi_enabled(EFI_BOOT)) efi_memblock_x86_reserve_range(); =20 -#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(); =20 apic_setup_apic_calls(); @@ -990,7 +966,6 @@ void __init setup_arch(char **cmdline_p) =20 cleanup_highmap(); =20 - memblock_set_current_limit(ISA_END_ADDRESS); e820__memblock_setup(); =20 /* --=20 2.47.2 From nobody Wed Mar 12 23:56:47 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B364822333E for ; Fri, 14 Feb 2025 09:07:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739524029; cv=none; b=ZvJj1fIhK9Ch9FRvOAGlK4WtuNMixnkge9aVN430jUKAH2wS5iVl312FO9HN+HBEtc60IWdlW2seBv0ktiDxPgg+C4z5rRHxBHuga9fftRg2RYx5BIR8+TMQkBJzGd8kxz4Inl5ZDBb491tkBikCGOpLK5c7/WaFVchChjTqMCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739524029; c=relaxed/simple; bh=JBOCSEE2UFn2Mr+tW+G9E3WK4Id0nTUslPRT+LCjlO4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qYL+OCCCmCW0sF66xoKb7MZx/HYdU3RFadCfNF7tZetUe5VfzjCR1yJnaJOyUNumCngL8KCWwu2X94KRKit1Ez89CU56xJXWifU6ABIEs2UIFxmgRG/7ifzi7gkG9ldF6II+SfaEZ9ydPuQeN7p0j6Bctj74x73Weih8myREdB8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=d/aMYHmA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="d/aMYHmA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42EB4C4CED1; Fri, 14 Feb 2025 09:07:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739524029; bh=JBOCSEE2UFn2Mr+tW+G9E3WK4Id0nTUslPRT+LCjlO4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d/aMYHmAF7zXztPDyAwgYfwNCW2vmWaYmKokDIt/nzkXBNrZPsSKUvNwG6FTyTglC 8xzbeAPUIsHl91YslgBcQsbfqB5VR2pjzn4LDsp7nHP0WvEu34brRy7gMYxRnFZ6WJ uAVCTYEjbgGubFlMnbb1WIEMj/jGb2gcsGRVzCHsOTwTyxb54iXH8swGhEEkSRPm+8 6BhyxRFKxmtby+3h4lCH5tZwJEQ07UI9BBkPVJTfeZx4hQd2wkBBUMDRSkoA6b6kMp Arp6ELnb4c4HHl2vAvu0tUwhlMruAyM1q6AeLkIAOYPzSuCJ1bktuZqGzOPx7aG5Vu aAXCc2FwWRTqw== From: Mike Rapoport To: x86@kernel.org Cc: Andy Lutomirski , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Mike Rapoport , Ning Sun , Peter Zijlstra , Thomas Gleixner , linux-kernel@vger.kernel.org, tboot-devel@lists.sourceforge.net Subject: [RESEND PATCH v2 2/4] x86/boot: split kernel resources setup into a helper function Date: Fri, 14 Feb 2025 11:06:49 +0200 Message-ID: <20250214090651.3331663-3-rppt@kernel.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250214090651.3331663-1-rppt@kernel.org> References: <20250214090651.3331663-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Makes setup_arch a bit easier to comprehend. No functional changes. Signed-off-by: Mike Rapoport (Microsoft) --- arch/x86/kernel/setup.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 4baadeab8a2e..3d95946ab749 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -527,6 +527,23 @@ void __init reserve_standard_io_resources(void) =20 } =20 +static void __init setup_kernel_resources(void) +{ + code_resource.start =3D __pa_symbol(_text); + code_resource.end =3D __pa_symbol(_etext)-1; + rodata_resource.start =3D __pa_symbol(__start_rodata); + rodata_resource.end =3D __pa_symbol(__end_rodata)-1; + data_resource.start =3D __pa_symbol(_sdata); + data_resource.end =3D __pa_symbol(_edata)-1; + bss_resource.start =3D __pa_symbol(__bss_start); + bss_resource.end =3D __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 &=3D ~MS_RDONLY; setup_initial_init_mm(_text, _etext, _edata, (void *)_brk_end); =20 - code_resource.start =3D __pa_symbol(_text); - code_resource.end =3D __pa_symbol(_etext)-1; - rodata_resource.start =3D __pa_symbol(__start_rodata); - rodata_resource.end =3D __pa_symbol(__end_rodata)-1; - data_resource.start =3D __pa_symbol(_sdata); - data_resource.end =3D __pa_symbol(_edata)-1; - bss_resource.start =3D __pa_symbol(__bss_start); - bss_resource.end =3D __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(); =20 - /* 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(); =20 e820_add_kernel_range(); trim_bios_range(); --=20 2.47.2 From nobody Wed Mar 12 23:56:47 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1FD622D7B9 for ; Fri, 14 Feb 2025 09:07:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739524032; cv=none; b=fxYJWbzNn0dagTEewPDd35ABqMMEcGv2tESQ3D4WXfLMWV8tWheKk+Iss+RRtckzaKziZIngKYrl9iXteGBDyjaZ8b7pnt6iY4n/RHKMTiYwI/VWqqz1p/I113tU6ZQ0ON7mQ945I7OLIui7+ZcwREmkscGoMWO35ZL3rYwBAyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739524032; c=relaxed/simple; bh=PgMTMw6Oe7ITbA6641p6eI75CKgUid8ZfAzIAJaAUb8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jO+/zZhuX6OQdcWpScdnBMlHb3Hxku9pA4eqzLrmPePOg9ITAtQbB/FUhyciqO3r81txAs/VAXfM5ec+CNeB4j+tnj0cifcCWIySM9SdjshAVqf0IQX3OBGAb1PnLeXbuJyljrYpxZRLAHNh4/Tw3NWvgYeXYnmD0vLn6R5zPW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IfM2x2LC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IfM2x2LC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99202C4CEDF; Fri, 14 Feb 2025 09:07:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739524032; bh=PgMTMw6Oe7ITbA6641p6eI75CKgUid8ZfAzIAJaAUb8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IfM2x2LCoE9YYe/wB6RKPzRQRcdlw80BkC/ZDVfBemLWNbdlPQMyp9otWou9RWXTB 6/gYq7DIA1nc5zNtCskkqUn9dhP8ZixR/RpEmkzTPb1LoN2qXGRRZjmxCGjoJly4VF iEjiYCx4WDkQ+glS4Ih+aOZb+4Irdrkj5gp0x32eCznO7bERCG+Q/wqq2PKZyGYnrl v4Q8u/sSK77zWluLWcq/kgxRBf/RphS+H1JufOXx/bkq7/7non8m3KhoHyFfi44Tei ipLkUhgTPZ908tzx1RfsSS13JiCsqj7eHUhRZyhtuOCSr+PDyhl9nvhvDlTaXx5Z7q Xmckj1moRgZnQ== From: Mike Rapoport To: x86@kernel.org Cc: Andy Lutomirski , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Mike Rapoport , Ning Sun , Peter Zijlstra , Thomas Gleixner , linux-kernel@vger.kernel.org, tboot-devel@lists.sourceforge.net Subject: [RESEND PATCH v2 3/4] x86/boot: split parsing of boot_params into a helper function Date: Fri, 14 Feb 2025 11:06:50 +0200 Message-ID: <20250214090651.3331663-4-rppt@kernel.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250214090651.3331663-1-rppt@kernel.org> References: <20250214090651.3331663-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" Makes setup_arch a bit easier to comprehend. No functional changes. Signed-off-by: Mike Rapoport (Microsoft) --- arch/x86/kernel/setup.c | 72 +++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 31 deletions(-) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 3d95946ab749..6fb9a851bc19 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -429,6 +429,46 @@ static void __init parse_setup_data(void) } } =20 +/* + * Translate the fields of 'struct boot_param' into global variables + * representing these parameters. + */ +static void __init parse_boot_params(void) +{ + ROOT_DEV =3D old_decode_dev(boot_params.hdr.root_dev); + screen_info =3D boot_params.screen_info; + edid_info =3D boot_params.edid_info; +#ifdef CONFIG_X86_32 + apm_info.bios =3D boot_params.apm_bios_info; + ist_info =3D boot_params.ist_info; +#endif + saved_video_mode =3D boot_params.hdr.vid_mode; + bootloader_type =3D boot_params.hdr.type_of_loader; + if ((bootloader_type >> 4) =3D=3D 0xe) { + bootloader_type &=3D 0xf; + bootloader_type |=3D (boot_params.hdr.ext_loader_type+0x10) << 4; + } + bootloader_version =3D bootloader_type & 0xf; + bootloader_version |=3D boot_params.hdr.ext_loader_ver << 4; + +#ifdef CONFIG_BLK_DEV_RAM + rd_image_start =3D 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 &=3D ~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) =20 setup_olpc_ofw_pgd(); =20 - ROOT_DEV =3D old_decode_dev(boot_params.hdr.root_dev); - screen_info =3D boot_params.screen_info; - edid_info =3D boot_params.edid_info; -#ifdef CONFIG_X86_32 - apm_info.bios =3D boot_params.apm_bios_info; - ist_info =3D boot_params.ist_info; -#endif - saved_video_mode =3D boot_params.hdr.vid_mode; - bootloader_type =3D boot_params.hdr.type_of_loader; - if ((bootloader_type >> 4) =3D=3D 0xe) { - bootloader_type &=3D 0xf; - bootloader_type |=3D (boot_params.hdr.ext_loader_type+0x10) << 4; - } - bootloader_version =3D bootloader_type & 0xf; - bootloader_version |=3D boot_params.hdr.ext_loader_ver << 4; - -#ifdef CONFIG_BLK_DEV_RAM - rd_image_start =3D 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(); =20 x86_init.oem.arch_setup(); =20 @@ -858,8 +870,6 @@ void __init setup_arch(char **cmdline_p) =20 copy_edd(); =20 - if (!boot_params.hdr.root_flags) - root_mountflags &=3D ~MS_RDONLY; setup_initial_init_mm(_text, _etext, _edata, (void *)_brk_end); =20 /* --=20 2.47.2 From nobody Wed Mar 12 23:56:47 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C5D922D4EF for ; Fri, 14 Feb 2025 09:07:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739524036; cv=none; b=gPtAzAEk/VFfhUNujTq3dJ7DoW8FPuFjyd4QZnik+SH08ol0OQi03Jb4WQSgJgU7Fv9VHaH26wChiX5ZN8T11FJ3Jc5BiTJJXM32buC4iDK4YrlZ5bfNJFjn/sLfF3dowPMfmLIQu734p2tpFiCB33at9cujTFMNRBRiZoOXYvE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739524036; c=relaxed/simple; bh=2JkMZLvpPxVlVD0hd7fvvaAj7UzAfO3Tyh4smrCg3hg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uXcdCev3BHrsVN9oStjsrl2Ts/gUaYhdusTr3qA4SiLckY2MKR5xPBWo9Ltf10L6tJVkmfn0jpkVGYBE+Mrh8sH542PS5XGS7TnjfUtDFZN1sVoMCG9FA1Lu6wnSKFHkoAYrw+hPxkndKM6SRw7ekebJahvp3McY1abPMb616hU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lqeSrcI4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lqeSrcI4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1B2FC4CED1; Fri, 14 Feb 2025 09:07:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1739524035; bh=2JkMZLvpPxVlVD0hd7fvvaAj7UzAfO3Tyh4smrCg3hg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lqeSrcI4U/5EAKHzXtjKNM1DDzpBBsR376g2vgHNrLp0x4EMEYI1LfV+GhKaeXRMz vRyRBYlPSHZYwK1D2rNv766aAUfbvy3DOv/bGbVhpxmZlZc81fSaIMKRQL14illqKJ e3jsG0H4M3a4x79uLzFw5fejE5lcC/MKuNfWUBHAyHGrGgHFTP0SdsNZp8XmCYkDxH 4yM9UqKV5tTX702co9JaxDGHMDQR72vUKESQnWub/+ZAzq0/qiRzZbJwQeZba6wXh3 7eJykoIrrmeinhhOAQGHqAE2Qkc149f3UBTj/UgDxC0L30DsdQoTdTk3maP9BN6efD mYu34R1wzntgw== From: Mike Rapoport To: x86@kernel.org Cc: Andy Lutomirski , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Ingo Molnar , Mike Rapoport , Ning Sun , Peter Zijlstra , Thomas Gleixner , linux-kernel@vger.kernel.org, tboot-devel@lists.sourceforge.net Subject: [RESEND PATCH v2 4/4] x86/e820: drop E820_TYPE_RESERVED_KERN and related code Date: Fri, 14 Feb 2025 11:06:51 +0200 Message-ID: <20250214090651.3331663-5-rppt@kernel.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250214090651.3331663-1-rppt@kernel.org> References: <20250214090651.3331663-1-rppt@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" 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. Signed-off-by: Mike Rapoport (Microsoft) --- 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(-) diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/ap= i.h index 2e74a7f0e935..c83645d5b2a8 100644 --- a/arch/x86/include/asm/e820/api.h +++ b/arch/x86/include/asm/e820/api.h @@ -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); =20 -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); diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/= types.h index 314f75d886d0..80c4a7266629 100644 --- a/arch/x86/include/asm/e820/types.h +++ b/arch/x86/include/asm/e820/types.h @@ -35,15 +35,6 @@ enum e820_type { * marking it with the IORES_DESC_SOFT_RESERVED designation. */ E820_TYPE_SOFT_RESERVED =3D 0xefffffff, - - /* - * Reserved RAM used by the kernel itself if - * CONFIG_INTEL_TXT=3Dy 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 =3D 128, }; =20 /* diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index 8d8bd039d2ac..9fb67abc32cc 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -187,8 +187,7 @@ void __init e820__range_add(u64 start, u64 size, enum e= 820_type type) static void __init e820_print_type(enum e820_type type) { switch (type) { - case E820_TYPE_RAM: /* Fall through: */ - case E820_TYPE_RESERVED_KERN: pr_cont("usable"); break; + case E820_TYPE_RAM: pr_cont("usable"); break; case E820_TYPE_RESERVED: pr_cont("reserved"); break; case E820_TYPE_SOFT_RESERVED: pr_cont("soft reserved"); break; case E820_TYPE_ACPI: pr_cont("ACPI data"); break; @@ -764,7 +763,7 @@ void __init e820__register_nosave_regions(unsigned long= limit_pfn) =20 pfn =3D PFN_DOWN(entry->addr + entry->size); =20 - if (entry->type !=3D E820_TYPE_RAM && entry->type !=3D E820_TYPE_RESERVE= D_KERN) + if (entry->type !=3D E820_TYPE_RAM) register_nosave_region(PFN_UP(entry->addr), pfn); =20 if (pfn >=3D limit_pfn) @@ -990,60 +989,6 @@ static int __init parse_memmap_opt(char *str) } early_param("memmap", parse_memmap_opt); =20 -/* - * Reserve all entries from the bootloader's extensible data nodes list, - * because if present we are going to use it later on to fetch e820 - * entries from it: - */ -void __init e820__reserve_setup_data(void) -{ - struct setup_indirect *indirect; - struct setup_data *data; - u64 pa_data, pa_next; - u32 len; - - pa_data =3D boot_params.hdr.setup_data; - if (!pa_data) - return; - - while (pa_data) { - data =3D early_memremap(pa_data, sizeof(*data)); - if (!data) { - pr_warn("e820: failed to memremap setup_data entry\n"); - return; - } - - len =3D sizeof(*data); - pa_next =3D data->next; - - e820__range_update(pa_data, sizeof(*data)+data->len, E820_TYPE_RAM, E820= _TYPE_RESERVED_KERN); - - if (data->type =3D=3D SETUP_INDIRECT) { - len +=3D data->len; - early_memunmap(data, sizeof(*data)); - data =3D early_memremap(pa_data, len); - if (!data) { - pr_warn("e820: failed to memremap indirect setup_data\n"); - return; - } - - indirect =3D (struct setup_indirect *)data->data; - - if (indirect->type !=3D SETUP_INDIRECT) - e820__range_update(indirect->addr, indirect->len, - E820_TYPE_RAM, E820_TYPE_RESERVED_KERN); - } - - pa_data =3D pa_next; - early_memunmap(data, len); - } - - e820__update_table(e820_table); - - pr_info("extended physical RAM map:\n"); - e820__print_table("reserve setup_data"); -} - /* * Called after parse_early_param(), after early parameters (such as mem= =3D) * have been processed, in which case we already have an E820 table filled= in @@ -1063,7 +1008,6 @@ void __init e820__finish_early_params(void) static const char *__init e820_type_to_string(struct e820_entry *entry) { switch (entry->type) { - case E820_TYPE_RESERVED_KERN: /* Fall-through: */ case E820_TYPE_RAM: return "System RAM"; case E820_TYPE_ACPI: return "ACPI Tables"; case E820_TYPE_NVS: return "ACPI Non-volatile Storage"; @@ -1079,7 +1023,6 @@ static const char *__init e820_type_to_string(struct = e820_entry *entry) static unsigned long __init e820_type_to_iomem_type(struct e820_entry *ent= ry) { switch (entry->type) { - case E820_TYPE_RESERVED_KERN: /* Fall-through: */ case E820_TYPE_RAM: return IORESOURCE_SYSTEM_RAM; case E820_TYPE_ACPI: /* Fall-through: */ case E820_TYPE_NVS: /* Fall-through: */ @@ -1101,7 +1044,6 @@ static unsigned long __init e820_type_to_iores_desc(s= truct e820_entry *entry) case E820_TYPE_PRAM: return IORES_DESC_PERSISTENT_MEMORY_LEGACY; case E820_TYPE_RESERVED: return IORES_DESC_RESERVED; case E820_TYPE_SOFT_RESERVED: return IORES_DESC_SOFT_RESERVED; - case E820_TYPE_RESERVED_KERN: /* Fall-through: */ case E820_TYPE_RAM: /* Fall-through: */ case E820_TYPE_UNUSABLE: /* Fall-through: */ default: return IORES_DESC_NONE; @@ -1124,7 +1066,6 @@ static bool __init do_mark_busy(enum e820_type type, = struct resource *res) case E820_TYPE_PRAM: case E820_TYPE_PMEM: return false; - case E820_TYPE_RESERVED_KERN: case E820_TYPE_RAM: case E820_TYPE_ACPI: case E820_TYPE_NVS: @@ -1353,7 +1294,7 @@ void __init e820__memblock_setup(void) if (entry->type =3D=3D E820_TYPE_SOFT_RESERVED) memblock_reserve(entry->addr, entry->size); =20 - if (entry->type !=3D E820_TYPE_RAM && entry->type !=3D E820_TYPE_RESERVE= D_KERN) + if (entry->type !=3D E820_TYPE_RAM) continue; =20 memblock_add(entry->addr, entry->size); diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index 6fb9a851bc19..46d92d04b6da 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -895,7 +895,6 @@ void __init setup_arch(char **cmdline_p) setup_clear_cpu_cap(X86_FEATURE_APIC); } =20 - e820__reserve_setup_data(); e820__finish_early_params(); =20 if (efi_enabled(EFI_BOOT)) diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c index 4c1bcb6053fc..46b8f1f16676 100644 --- a/arch/x86/kernel/tboot.c +++ b/arch/x86/kernel/tboot.c @@ -200,8 +200,7 @@ static int tboot_setup_sleep(void) tboot->num_mac_regions =3D 0; =20 for (i =3D 0; i < e820_table->nr_entries; i++) { - if ((e820_table->entries[i].type !=3D E820_TYPE_RAM) - && (e820_table->entries[i].type !=3D E820_TYPE_RESERVED_KERN)) + if (e820_table->entries[i].type !=3D E820_TYPE_RAM) continue; =20 add_mac_region(e820_table->entries[i].addr, e820_table->entries[i].size); diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 01ea7c6df303..519aa53114fa 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -468,8 +468,6 @@ phys_pte_init(pte_t *pte_page, unsigned long paddr, uns= igned 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, uns= igned 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, uns= igned 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, uns= igned 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); --=20 2.47.2