The loongarch, openric, and sh architectures allocate memory from
memblock before it gets the chance to set aside reserved memory regions.
This means that there is a possibility for memblock to allocate from
memory regions that are supposed to be reserved.
This series makes changes to the arch specific setup code to call the
functions responsible for setting aside the reserved memory regions earlier
in the init sequence.
Hence, by the time memblock starts being used to allocate memory, the
reserved memory regions should already be set aside, and it will no
longer be possible for allocations to come from them.
I am currnetly using an arm64 device, and so I will need assistance from
the relevant arch maintainers to help check if this breaks anything from
compilation to device bootup.
Oreoluwa Babatunde (3):
loongarch: Call arch_mem_init() before platform_init() in the init
sequence
openrisc: Call setup_memory() earlier in the init sequence
sh: Call paging_init() earlier in the init sequence
arch/loongarch/kernel/setup.c | 2 +-
arch/openrisc/kernel/setup.c | 6 +++---
arch/sh/kernel/setup.c | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
--
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 setup_memory()
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 setup_memory() 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 <[email protected]>
---
arch/openrisc/kernel/setup.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/openrisc/kernel/setup.c b/arch/openrisc/kernel/setup.c
index 9cf7fb6..be56eaa 100644
--- a/arch/openrisc/kernel/setup.c
+++ b/arch/openrisc/kernel/setup.c
@@ -255,6 +255,9 @@ void calibrate_delay(void)
void __init setup_arch(char **cmdline_p)
{
+ /* setup memblock allocator */
+ setup_memory();
+
unflatten_and_copy_device_tree();
setup_cpuinfo();
@@ -278,9 +281,6 @@ void __init setup_arch(char **cmdline_p)
}
#endif
- /* setup memblock allocator */
- setup_memory();
-
/* paging_init() sets up the MMU and marks all pages as reserved */
paging_init();
--
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 is set aside in paging_init().
This means that there is a possibility for memblock to allocate from
any of the memory regions that are supposed to be set aside as reserved.
Hence, move the call to paging_init() 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 <[email protected]>
---
arch/sh/kernel/setup.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/sh/kernel/setup.c b/arch/sh/kernel/setup.c
index d3175f0..ea40798 100644
--- a/arch/sh/kernel/setup.c
+++ b/arch/sh/kernel/setup.c
@@ -322,6 +322,8 @@ void __init setup_arch(char **cmdline_p)
/* Let earlyprintk output early console messages */
sh_early_platform_driver_probe("earlyprintk", 1, 1);
+ paging_init();
+
#ifdef CONFIG_OF_EARLY_FLATTREE
#ifdef CONFIG_USE_BUILTIN_DTB
unflatten_and_copy_device_tree();
@@ -330,8 +332,6 @@ void __init setup_arch(char **cmdline_p)
#endif
#endif
- paging_init();
-
/* Perform the machine specific initialisation */
if (likely(sh_mv.mv_setup))
sh_mv.mv_setup(cmdline_p);
--
On 2/9/2024 4:29 PM, Oreoluwa Babatunde wrote:
> The loongarch, openric, and sh architectures allocate memory from
> memblock before it gets the chance to set aside reserved memory regions.
> This means that there is a possibility for memblock to allocate from
> memory regions that are supposed to be reserved.
>
> This series makes changes to the arch specific setup code to call the
> functions responsible for setting aside the reserved memory regions earlier
> in the init sequence.
> Hence, by the time memblock starts being used to allocate memory, the
> reserved memory regions should already be set aside, and it will no
> longer be possible for allocations to come from them.
>
> I am currnetly using an arm64 device, and so I will need assistance from
> the relevant arch maintainers to help check if this breaks anything from
> compilation to device bootup.
>
> Oreoluwa Babatunde (3):
> loongarch: Call arch_mem_init() before platform_init() in the init
> sequence
> openrisc: Call setup_memory() earlier in the init sequence
> sh: Call paging_init() earlier in the init sequence
>
> arch/loongarch/kernel/setup.c | 2 +-
> arch/openrisc/kernel/setup.c | 6 +++---
> arch/sh/kernel/setup.c | 4 ++--
> 3 files changed, 6 insertions(+), 6 deletions(-)
Hello,
Loongarch patch has already merged for this, but review is still pending
from openrisc and sh architectures.
Could someone please comment on these?
Regards,
Oreoluwa
On Tue, Mar 05, 2024 at 10:59:20AM -0800, Oreoluwa Babatunde wrote:
>
> On 2/9/2024 4:29 PM, Oreoluwa Babatunde wrote:
> > The loongarch, openric, and sh architectures allocate memory from
> > memblock before it gets the chance to set aside reserved memory regions.
> > This means that there is a possibility for memblock to allocate from
> > memory regions that are supposed to be reserved.
> >
> > This series makes changes to the arch specific setup code to call the
> > functions responsible for setting aside the reserved memory regions earlier
> > in the init sequence.
> > Hence, by the time memblock starts being used to allocate memory, the
> > reserved memory regions should already be set aside, and it will no
> > longer be possible for allocations to come from them.
> >
> > I am currnetly using an arm64 device, and so I will need assistance from
> > the relevant arch maintainers to help check if this breaks anything from
> > compilation to device bootup.
> >
> > Oreoluwa Babatunde (3):
> > loongarch: Call arch_mem_init() before platform_init() in the init
> > sequence
> > openrisc: Call setup_memory() earlier in the init sequence
> > sh: Call paging_init() earlier in the init sequence
> >
> > arch/loongarch/kernel/setup.c | 2 +-
> > arch/openrisc/kernel/setup.c | 6 +++---
> > arch/sh/kernel/setup.c | 4 ++--
> > 3 files changed, 6 insertions(+), 6 deletions(-)
> Hello,
>
> Loongarch patch has already merged for this, but review is still pending
> from openrisc and sh architectures.
> Could someone please comment on these?
Hello,
The OpenRISC patch looks fine to me. I will test it out. Sorry, I thought you
were getting this merged via other means.
-Stafford
On Fri, Feb 09, 2024 at 04:29:30PM -0800, Oreoluwa Babatunde 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 setup_memory()
> 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 setup_memory() 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 <[email protected]>
> ---
> arch/openrisc/kernel/setup.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/openrisc/kernel/setup.c b/arch/openrisc/kernel/setup.c
> index 9cf7fb6..be56eaa 100644
> --- a/arch/openrisc/kernel/setup.c
> +++ b/arch/openrisc/kernel/setup.c
> @@ -255,6 +255,9 @@ void calibrate_delay(void)
>
> void __init setup_arch(char **cmdline_p)
> {
> + /* setup memblock allocator */
> + setup_memory();
> +
> unflatten_and_copy_device_tree();
>
> setup_cpuinfo();
> @@ -278,9 +281,6 @@ void __init setup_arch(char **cmdline_p)
> }
> #endif
>
> - /* setup memblock allocator */
> - setup_memory();
> -
> /* paging_init() sets up the MMU and marks all pages as reserved */
> paging_init();
This looks good. I will merge it via the openrisc queue as you requested.
-Stafford
On Fri, Feb 9, 2024 at 5:29 PM Oreoluwa Babatunde
<[email protected]> 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 is set aside in paging_init().
> This means that there is a possibility for memblock to allocate from
> any of the memory regions that are supposed to be set aside as reserved.
>
> Hence, move the call to paging_init() 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 <[email protected]>
> ---
> arch/sh/kernel/setup.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Rob Herring <[email protected]>