LoongArch: Call early_init_fdt_scan_reserved_mem() earlier

Message ID 20240218151403.2206980-1-chenhuacai@loongson.cn
State New
Headers
Series LoongArch: Call early_init_fdt_scan_reserved_mem() earlier |

Commit Message

Huacai Chen Feb. 18, 2024, 3:14 p.m. UTC
  The unflatten_and_copy_device_tree() function contains a call to
memblock_alloc(). This means that memblock is allocating memory before
any of the reserved memory regions are set aside in the arch_mem_init()
function which calls early_init_fdt_scan_reserved_mem(). Therefore,
there is a possibility for memblock to allocate from any of the
reserved memory regions.

Hence, move the call to early_init_fdt_scan_reserved_mem() to be earlier
in the init sequence, so that the reserved memory regions are set aside
before any allocations are done using memblock.

Signed-off-by: Oreoluwa Babatunde <quic_obabatun@quicinc.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
 arch/loongarch/kernel/setup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Oreoluwa Babatunde Feb. 20, 2024, 5:37 p.m. UTC | #1
On 2/18/2024 7:14 AM, Huacai Chen wrote:
> The unflatten_and_copy_device_tree() function contains a call to
> memblock_alloc(). This means that memblock is allocating memory before
> any of the reserved memory regions are set aside in the arch_mem_init()
> function which calls early_init_fdt_scan_reserved_mem(). Therefore,
> there is a possibility for memblock to allocate from any of the
> reserved memory regions.
>
> Hence, move the call to early_init_fdt_scan_reserved_mem() to be earlier
> in the init sequence, so that the reserved memory regions are set aside
> before any allocations are done using memblock.
>
> Signed-off-by: Oreoluwa Babatunde <quic_obabatun@quicinc.com>
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
>  arch/loongarch/kernel/setup.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
> index edf2bba80130..634ef17fd38b 100644
> --- a/arch/loongarch/kernel/setup.c
> +++ b/arch/loongarch/kernel/setup.c
> @@ -357,6 +357,8 @@ void __init platform_init(void)
>  	acpi_gbl_use_default_register_widths = false;
>  	acpi_boot_table_init();
>  #endif
> +
> +	early_init_fdt_scan_reserved_mem();
>  	unflatten_and_copy_device_tree();
>  
>  #ifdef CONFIG_NUMA
> @@ -390,8 +392,6 @@ static void __init arch_mem_init(char **cmdline_p)
>  
>  	check_kernel_sections_mem();
>  
> -	early_init_fdt_scan_reserved_mem();
> -
>  	/*
>  	 * In order to reduce the possibility of kernel panic when failed to
>  	 * get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate
Hi Huacai,

Thank you! This change looks good to me.

Regards,

Oreoluwa
  

Patch

diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
index edf2bba80130..634ef17fd38b 100644
--- a/arch/loongarch/kernel/setup.c
+++ b/arch/loongarch/kernel/setup.c
@@ -357,6 +357,8 @@  void __init platform_init(void)
 	acpi_gbl_use_default_register_widths = false;
 	acpi_boot_table_init();
 #endif
+
+	early_init_fdt_scan_reserved_mem();
 	unflatten_and_copy_device_tree();
 
 #ifdef CONFIG_NUMA
@@ -390,8 +392,6 @@  static void __init arch_mem_init(char **cmdline_p)
 
 	check_kernel_sections_mem();
 
-	early_init_fdt_scan_reserved_mem();
-
 	/*
 	 * In order to reduce the possibility of kernel panic when failed to
 	 * get IO TLB memory under CONFIG_SWIOTLB, it is better to allocate