diff mbox series

[v5,2/2] sh: Restructure setup code to reserve memory regions earlier

Message ID 20240718021822.1545976-3-quic_obabatun@quicinc.com (mailing list archive)
State New
Headers show
Series sh: Restructure setup code to reserve memory regions earlier | expand

Commit Message

Oreoluwa Babatunde July 18, 2024, 2:18 a.m. UTC
The unflatten_device_tree() function contains a call to
memblock_alloc(). This is a problem because this allocation is done
before any of the reserved memory regions are set aside in
paging_init().
As a result, there is a possibility for memblock to unknowingly allocate
from any of the memory regions that are meant to be reserved.

Hence, restructure the setup code to reserve the memory regions before
any allocation is done by the unflatten_devicetree*() using memblock.

Signed-off-by: Oreoluwa Babatunde <quic_obabatun@quicinc.com>
---
 arch/sh/mm/init.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

Comments

Artur Rojek Sept. 29, 2024, 9:15 p.m. UTC | #1
On 2024-07-18 04:18, Oreoluwa Babatunde wrote:
> The unflatten_device_tree() function contains a call to
> memblock_alloc(). This is a problem because this allocation is done
> before any of the reserved memory regions are set aside in
> paging_init().
> As a result, there is a possibility for memblock to unknowingly 
> allocate
> from any of the memory regions that are meant to be reserved.
> 
> Hence, restructure the setup code to reserve the memory regions before
> any allocation is done by the unflatten_devicetree*() using memblock.
> 
> Signed-off-by: Oreoluwa Babatunde <quic_obabatun@quicinc.com>

Hi Oreoluwa,

> ---
>  arch/sh/mm/init.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c
> index 643e3617c6a6..857ce8cc84bd 100644
> --- a/arch/sh/mm/init.c
> +++ b/arch/sh/mm/init.c
> @@ -249,6 +249,7 @@ void __init early_reserve_mem(void)
>  	u32 zero_base = (u32)__MEMORY_START + (u32)PHYSICAL_OFFSET;
>  	u32 start = zero_base + (u32)CONFIG_ZERO_PAGE_OFFSET;
> 
> +	sh_mv.mv_mem_init();

One side effect of moving mv_mem_init here is that it makes cache
operations available earlier. But I see no harm in doing that.

Otherwise the patch is looking good. Verified on J2 Turtle Board.

Reviewed-by: Artur Rojek <contact@artur-rojek.eu>

Cheers,
Artur

>  	/*
>  	 * Partially used pages are not usable - thus
>  	 * we are rounding upwards:
> @@ -274,14 +275,6 @@ void __init early_reserve_mem(void)
>  	 */
>  	check_for_initrd();
>  	reserve_crashkernel();
> -}
> -
> -void __init paging_init(void)
> -{
> -	unsigned long max_zone_pfns[MAX_NR_ZONES];
> -	unsigned long vaddr, end;
> -
> -	sh_mv.mv_mem_init();
> 
>  	/*
>  	 * Once the early reservations are out of the way, give the
> @@ -289,6 +282,12 @@ void __init paging_init(void)
>  	 */
>  	if (sh_mv.mv_mem_reserve)
>  		sh_mv.mv_mem_reserve();
> +}
> +
> +void __init paging_init(void)
> +{
> +	unsigned long max_zone_pfns[MAX_NR_ZONES];
> +	unsigned long vaddr, end;
> 
>  	memblock_enforce_memory_limit(memory_limit);
>  	memblock_allow_resize();
Oreoluwa Babatunde Oct. 10, 2024, 7:04 p.m. UTC | #2
On 9/29/2024 2:15 PM, Artur Rojek wrote:
> On 2024-07-18 04:18, Oreoluwa Babatunde wrote:
>> The unflatten_device_tree() function contains a call to
>> memblock_alloc(). This is a problem because this allocation is done
>> before any of the reserved memory regions are set aside in
>> paging_init().
>> As a result, there is a possibility for memblock to unknowingly allocate
>> from any of the memory regions that are meant to be reserved.
>>
>> Hence, restructure the setup code to reserve the memory regions before
>> any allocation is done by the unflatten_devicetree*() using memblock.
>>
>> Signed-off-by: Oreoluwa Babatunde <quic_obabatun@quicinc.com>
>
> Hi Oreoluwa,
>
>> ---
>>  arch/sh/mm/init.c | 15 +++++++--------
>>  1 file changed, 7 insertions(+), 8 deletions(-)
>>
>> diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c
>> index 643e3617c6a6..857ce8cc84bd 100644
>> --- a/arch/sh/mm/init.c
>> +++ b/arch/sh/mm/init.c
>> @@ -249,6 +249,7 @@ void __init early_reserve_mem(void)
>>      u32 zero_base = (u32)__MEMORY_START + (u32)PHYSICAL_OFFSET;
>>      u32 start = zero_base + (u32)CONFIG_ZERO_PAGE_OFFSET;
>>
>> +    sh_mv.mv_mem_init();
>
> One side effect of moving mv_mem_init here is that it makes cache
> operations available earlier. But I see no harm in doing that.
>
> Otherwise the patch is looking good. Verified on J2 Turtle Board.
>
> Reviewed-by: Artur Rojek <contact@artur-rojek.eu>
>
ack.

Thank you for the review Artur!

Regards,
Oreoluwa
diff mbox series

Patch

diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c
index 643e3617c6a6..857ce8cc84bd 100644
--- a/arch/sh/mm/init.c
+++ b/arch/sh/mm/init.c
@@ -249,6 +249,7 @@  void __init early_reserve_mem(void)
 	u32 zero_base = (u32)__MEMORY_START + (u32)PHYSICAL_OFFSET;
 	u32 start = zero_base + (u32)CONFIG_ZERO_PAGE_OFFSET;
 
+	sh_mv.mv_mem_init();
 	/*
 	 * Partially used pages are not usable - thus
 	 * we are rounding upwards:
@@ -274,14 +275,6 @@  void __init early_reserve_mem(void)
 	 */
 	check_for_initrd();
 	reserve_crashkernel();
-}
-
-void __init paging_init(void)
-{
-	unsigned long max_zone_pfns[MAX_NR_ZONES];
-	unsigned long vaddr, end;
-
-	sh_mv.mv_mem_init();
 
 	/*
 	 * Once the early reservations are out of the way, give the
@@ -289,6 +282,12 @@  void __init paging_init(void)
 	 */
 	if (sh_mv.mv_mem_reserve)
 		sh_mv.mv_mem_reserve();
+}
+
+void __init paging_init(void)
+{
+	unsigned long max_zone_pfns[MAX_NR_ZONES];
+	unsigned long vaddr, end;
 
 	memblock_enforce_memory_limit(memory_limit);
 	memblock_allow_resize();