diff mbox series

[14/46] sh: reserved_mem: Implement the new processing order for reserved memory

Message ID 20240126235425.12233-15-quic_obabatun@quicinc.com (mailing list archive)
State Not Applicable
Headers show
Series Dynamic allocation of reserved_mem array. | expand

Commit Message

Oreoluwa Babatunde Jan. 26, 2024, 11:53 p.m. UTC
Call early_fdt_scan_reserved_mem() in place of
early_init_fdt_scan_reserved_mem() to carry out the first stage of the
reserved memory processing only.

The early_fdt_scan_reserved_mem() function is used to scan through the
DT and mark all the reserved memory regions as reserved or nomap as
needed, as well as allocate the memory required by the
dynamically-placed
reserved memory regions.

The second stage of the reserved memory processing is done by
fdt_init_reserved_mem(). This function is used to store the information
of the statically-placed reserved memory nodes in the reserved_mem
array as well as call the region specific initialization function on all
the stored reserved memory regions.

The call to fdt_init_reserved_mem() is placed right after
early_fdt_scan_reserved_mem() because memblock allocated memory should
already be writable at this point.

Signed-off-by: Oreoluwa Babatunde <quic_obabatun@quicinc.com>
---
 arch/sh/boards/of-generic.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Rob Herring Jan. 31, 2024, 3:41 p.m. UTC | #1
On Fri, Jan 26, 2024 at 03:53:53PM -0800, Oreoluwa Babatunde wrote:
> Call early_fdt_scan_reserved_mem() in place of
> early_init_fdt_scan_reserved_mem() to carry out the first stage of the
> reserved memory processing only.
> 
> The early_fdt_scan_reserved_mem() function is used to scan through the
> DT and mark all the reserved memory regions as reserved or nomap as
> needed, as well as allocate the memory required by the
> dynamically-placed
> reserved memory regions.
> 
> The second stage of the reserved memory processing is done by
> fdt_init_reserved_mem(). This function is used to store the information
> of the statically-placed reserved memory nodes in the reserved_mem
> array as well as call the region specific initialization function on all
> the stored reserved memory regions.
> 
> The call to fdt_init_reserved_mem() is placed right after
> early_fdt_scan_reserved_mem() because memblock allocated memory should
> already be writable at this point.
> 
> Signed-off-by: Oreoluwa Babatunde <quic_obabatun@quicinc.com>
> ---
>  arch/sh/boards/of-generic.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/sh/boards/of-generic.c b/arch/sh/boards/of-generic.c
> index f7f3e618e85b..7bec409f077c 100644
> --- a/arch/sh/boards/of-generic.c
> +++ b/arch/sh/boards/of-generic.c
> @@ -8,6 +8,7 @@
>  #include <linux/of.h>
>  #include <linux/of_clk.h>
>  #include <linux/of_fdt.h>
> +#include <linux/of_reserved_mem.h>
>  #include <linux/clocksource.h>
>  #include <linux/irqchip.h>
>  #include <asm/machvec.h>
> @@ -110,7 +111,8 @@ static int noopi(void)
>  static void __init sh_of_mem_reserve(void)
>  {
>  	early_init_fdt_reserve_self();
> -	early_init_fdt_scan_reserved_mem();
> +	early_fdt_scan_reserved_mem();
> +	fdt_init_reserved_mem();

Looking at the sh code, there's an existing problem with the order of
init. This is called from paging_init() and is done after unflattening
and copying the DT. That means the kernel could freely allocate memory
for the DT in a reserved region.

Rob
Oreoluwa Babatunde Feb. 1, 2024, 5:15 p.m. UTC | #2
On 1/31/2024 7:41 AM, Rob Herring wrote:
> On Fri, Jan 26, 2024 at 03:53:53PM -0800, Oreoluwa Babatunde wrote:
>> Call early_fdt_scan_reserved_mem() in place of
>> early_init_fdt_scan_reserved_mem() to carry out the first stage of the
>> reserved memory processing only.
>>
>> The early_fdt_scan_reserved_mem() function is used to scan through the
>> DT and mark all the reserved memory regions as reserved or nomap as
>> needed, as well as allocate the memory required by the
>> dynamically-placed
>> reserved memory regions.
>>
>> The second stage of the reserved memory processing is done by
>> fdt_init_reserved_mem(). This function is used to store the information
>> of the statically-placed reserved memory nodes in the reserved_mem
>> array as well as call the region specific initialization function on all
>> the stored reserved memory regions.
>>
>> The call to fdt_init_reserved_mem() is placed right after
>> early_fdt_scan_reserved_mem() because memblock allocated memory should
>> already be writable at this point.
>>
>> Signed-off-by: Oreoluwa Babatunde <quic_obabatun@quicinc.com>
>> ---
>>  arch/sh/boards/of-generic.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/sh/boards/of-generic.c b/arch/sh/boards/of-generic.c
>> index f7f3e618e85b..7bec409f077c 100644
>> --- a/arch/sh/boards/of-generic.c
>> +++ b/arch/sh/boards/of-generic.c
>> @@ -8,6 +8,7 @@
>>  #include <linux/of.h>
>>  #include <linux/of_clk.h>
>>  #include <linux/of_fdt.h>
>> +#include <linux/of_reserved_mem.h>
>>  #include <linux/clocksource.h>
>>  #include <linux/irqchip.h>
>>  #include <asm/machvec.h>
>> @@ -110,7 +111,8 @@ static int noopi(void)
>>  static void __init sh_of_mem_reserve(void)
>>  {
>>  	early_init_fdt_reserve_self();
>> -	early_init_fdt_scan_reserved_mem();
>> +	early_fdt_scan_reserved_mem();
>> +	fdt_init_reserved_mem();
> Looking at the sh code, there's an existing problem with the order of
> init. This is called from paging_init() and is done after unflattening
> and copying the DT. That means the kernel could freely allocate memory
> for the DT in a reserved region.
>
> Rob

Hi Rob,

Yes I agree! I can try to restructure the code to address
this. I think we should be able to move the call to
early_init_fdt_scan_reserved_mem() higher in the init
sequence without having any issues.

Will try this out and see.

Regards,
Oreoluwa
diff mbox series

Patch

diff --git a/arch/sh/boards/of-generic.c b/arch/sh/boards/of-generic.c
index f7f3e618e85b..7bec409f077c 100644
--- a/arch/sh/boards/of-generic.c
+++ b/arch/sh/boards/of-generic.c
@@ -8,6 +8,7 @@ 
 #include <linux/of.h>
 #include <linux/of_clk.h>
 #include <linux/of_fdt.h>
+#include <linux/of_reserved_mem.h>
 #include <linux/clocksource.h>
 #include <linux/irqchip.h>
 #include <asm/machvec.h>
@@ -110,7 +111,8 @@  static int noopi(void)
 static void __init sh_of_mem_reserve(void)
 {
 	early_init_fdt_reserve_self();
-	early_init_fdt_scan_reserved_mem();
+	early_fdt_scan_reserved_mem();
+	fdt_init_reserved_mem();
 }
 
 static void __init sh_of_setup(char **cmdline_p)