These patches switch nios2 boot time memory allocators from bootmem to
memblock + no_bootmem.
As nios2 uses fdt, the conversion is pretty much about actually using the
existing fdt infrastructure for the early memory management.
The first patch in the series is not strictly related to nios2. It's just
I've got really interesting memory layout without it because of 1K long
memory ranges defined in arch/nios2/boot/dts/10m50_devboard.dts.
Mike Rapoport (3):
of: ignore sub-page memory regions
nios2: use generic early_init_dt_add_memory_arch
nios2: switch to NO_BOOTMEM
arch/nios2/Kconfig | 3 +++
arch/nios2/kernel/prom.c | 17 -----------------
arch/nios2/kernel/setup.c | 39 +++++++--------------------------------
drivers/of/fdt.c | 11 ++++++-----
4 files changed, 16 insertions(+), 54 deletions(-)
--
2.7.4
Memory region size is rounded down to page boundary and with sub-page
region it becomes 0 and there is no point to add an empty region.
Moreover, when the base is less than PAGE_SIZE we get a bogus size as
(base + size - 1) evaluates to -1.
The commit 8cccffc52694 ("of: check for size < 0 after rounding in
early_init_dt_add_memory_arch") introduced a test for wrap around for the
case when base is not page aligned, the same test can be used to ignore
sub-page region sizes.
Signed-off-by: Mike Rapoport <[email protected]>
---
drivers/of/fdt.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 6da20b9..e866745 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -1134,12 +1134,13 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
{
const u64 phys_offset = MIN_MEMBLOCK_ADDR;
+ if (size < PAGE_SIZE - (base & ~PAGE_MASK)) {
+ pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",
+ base, base + size);
+ return;
+ }
+
if (!PAGE_ALIGNED(base)) {
- if (size < PAGE_SIZE - (base & ~PAGE_MASK)) {
- pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",
- base, base + size);
- return;
- }
size -= PAGE_SIZE - (base & ~PAGE_MASK);
base = PAGE_ALIGN(base);
}
--
2.7.4
Remove bootmem bitmap initialization and replace reserve_bootmem() with
memblock_reserve().
Signed-off-by: Mike Rapoport <[email protected]>
---
arch/nios2/Kconfig | 2 ++
arch/nios2/kernel/prom.c | 7 -------
arch/nios2/kernel/setup.c | 37 +++++--------------------------------
3 files changed, 7 insertions(+), 39 deletions(-)
diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
index 5db8fa1..661f7f9 100644
--- a/arch/nios2/Kconfig
+++ b/arch/nios2/Kconfig
@@ -20,6 +20,8 @@ config NIOS2
select USB_ARCH_HAS_HCD if USB_SUPPORT
select CPU_NO_EFFICIENT_FFS
select HAVE_MEMBLOCK
+ select ARCH_DISCARD_MEMBLOCK
+ select NO_BOOTMEM
config GENERIC_CSUM
def_bool y
diff --git a/arch/nios2/kernel/prom.c b/arch/nios2/kernel/prom.c
index ba96a49..a6d4f75 100644
--- a/arch/nios2/kernel/prom.c
+++ b/arch/nios2/kernel/prom.c
@@ -32,13 +32,6 @@
#include <asm/sections.h>
-int __init early_init_dt_reserve_memory_arch(phys_addr_t base, phys_addr_t size,
- bool nomap)
-{
- reserve_bootmem(base, size, BOOTMEM_DEFAULT);
- return 0;
-}
-
void __init early_init_devtree(void *params)
{
__be32 *dtb = (u32 *)__dtb_start;
diff --git a/arch/nios2/kernel/setup.c b/arch/nios2/kernel/setup.c
index 0946840..2d0011d 100644
--- a/arch/nios2/kernel/setup.c
+++ b/arch/nios2/kernel/setup.c
@@ -144,10 +144,11 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
void __init setup_arch(char **cmdline_p)
{
- int bootmap_size;
+ int dram_start;
console_verbose();
+ dram_start = memblock_start_of_DRAM();
memory_size = memblock_phys_mem_size();
memory_start = PAGE_ALIGN((unsigned long)__pa(_end));
memory_end = (unsigned long) CONFIG_NIOS2_MEM_BASE + memory_size;
@@ -165,39 +166,11 @@ void __init setup_arch(char **cmdline_p)
max_low_pfn = PFN_DOWN(memory_end);
max_mapnr = max_low_pfn;
- /*
- * give all the memory to the bootmap allocator, tell it to put the
- * boot mem_map at the start of memory
- */
- pr_debug("init_bootmem_node(?,%#lx, %#x, %#lx)\n",
- min_low_pfn, PFN_DOWN(PHYS_OFFSET), max_low_pfn);
- bootmap_size = init_bootmem_node(NODE_DATA(0),
- min_low_pfn, PFN_DOWN(PHYS_OFFSET),
- max_low_pfn);
-
- /*
- * free the usable memory, we have to make sure we do not free
- * the bootmem bitmap so we then reserve it after freeing it :-)
- */
- pr_debug("free_bootmem(%#lx, %#lx)\n",
- memory_start, memory_end - memory_start);
- free_bootmem(memory_start, memory_end - memory_start);
-
- /*
- * Reserve the bootmem bitmap itself as well. We do this in two
- * steps (first step was init_bootmem()) because this catches
- * the (very unlikely) case of us accidentally initializing the
- * bootmem allocator with an invalid RAM area.
- *
- * Arguments are start, size
- */
- pr_debug("reserve_bootmem(%#lx, %#x)\n", memory_start, bootmap_size);
- reserve_bootmem(memory_start, bootmap_size, BOOTMEM_DEFAULT);
-
+ memblock_reserve(dram_start, memory_start - dram_start);
#ifdef CONFIG_BLK_DEV_INITRD
if (initrd_start) {
- reserve_bootmem(virt_to_phys((void *)initrd_start),
- initrd_end - initrd_start, BOOTMEM_DEFAULT);
+ memblock_reserve(virt_to_phys((void *)initrd_start),
+ initrd_end - initrd_start);
}
#endif /* CONFIG_BLK_DEV_INITRD */
--
2.7.4
All we have to do is to enable memblock, the generic FDT code will take
care of the rest.
Signed-off-by: Mike Rapoport <[email protected]>
---
arch/nios2/Kconfig | 1 +
arch/nios2/kernel/prom.c | 10 ----------
arch/nios2/kernel/setup.c | 2 ++
3 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
index 3d4ec88..5db8fa1 100644
--- a/arch/nios2/Kconfig
+++ b/arch/nios2/Kconfig
@@ -19,6 +19,7 @@ config NIOS2
select SPARSE_IRQ
select USB_ARCH_HAS_HCD if USB_SUPPORT
select CPU_NO_EFFICIENT_FFS
+ select HAVE_MEMBLOCK
config GENERIC_CSUM
def_bool y
diff --git a/arch/nios2/kernel/prom.c b/arch/nios2/kernel/prom.c
index 8d7446a..ba96a49 100644
--- a/arch/nios2/kernel/prom.c
+++ b/arch/nios2/kernel/prom.c
@@ -32,16 +32,6 @@
#include <asm/sections.h>
-void __init early_init_dt_add_memory_arch(u64 base, u64 size)
-{
- u64 kernel_start = (u64)virt_to_phys(_text);
-
- if (!memory_size &&
- (kernel_start >= base) && (kernel_start < (base + size)))
- memory_size = size;
-
-}
-
int __init early_init_dt_reserve_memory_arch(phys_addr_t base, phys_addr_t size,
bool nomap)
{
diff --git a/arch/nios2/kernel/setup.c b/arch/nios2/kernel/setup.c
index 926a02b..0946840 100644
--- a/arch/nios2/kernel/setup.c
+++ b/arch/nios2/kernel/setup.c
@@ -17,6 +17,7 @@
#include <linux/sched/task.h>
#include <linux/console.h>
#include <linux/bootmem.h>
+#include <linux/memblock.h>
#include <linux/initrd.h>
#include <linux/of_fdt.h>
#include <linux/screen_info.h>
@@ -147,6 +148,7 @@ void __init setup_arch(char **cmdline_p)
console_verbose();
+ memory_size = memblock_phys_mem_size();
memory_start = PAGE_ALIGN((unsigned long)__pa(_end));
memory_end = (unsigned long) CONFIG_NIOS2_MEM_BASE + memory_size;
--
2.7.4
Any updates on this?
On Wed, Jul 04, 2018 at 04:18:12PM +0300, Mike Rapoport wrote:
> These patches switch nios2 boot time memory allocators from bootmem to
> memblock + no_bootmem.
>
> As nios2 uses fdt, the conversion is pretty much about actually using the
> existing fdt infrastructure for the early memory management.
>
> The first patch in the series is not strictly related to nios2. It's just
> I've got really interesting memory layout without it because of 1K long
> memory ranges defined in arch/nios2/boot/dts/10m50_devboard.dts.
>
> Mike Rapoport (3):
> of: ignore sub-page memory regions
> nios2: use generic early_init_dt_add_memory_arch
> nios2: switch to NO_BOOTMEM
>
> arch/nios2/Kconfig | 3 +++
> arch/nios2/kernel/prom.c | 17 -----------------
> arch/nios2/kernel/setup.c | 39 +++++++--------------------------------
> drivers/of/fdt.c | 11 ++++++-----
> 4 files changed, 16 insertions(+), 54 deletions(-)
>
> --
> 2.7.4
>
--
Sincerely yours,
Mike.
On Wed, 2018-07-04 at 16:18 +0300, Mike Rapoport wrote:
> Remove bootmem bitmap initialization and replace reserve_bootmem()
> with
> memblock_reserve().
>
> Signed-off-by: Mike Rapoport <[email protected]>
> ---
> arch/nios2/Kconfig | 2 ++
> arch/nios2/kernel/prom.c | 7 -------
> arch/nios2/kernel/setup.c | 37 +++++--------------------------------
> 3 files changed, 7 insertions(+), 39 deletions(-)
>
> diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
> index 5db8fa1..661f7f9 100644
> --- a/arch/nios2/Kconfig
> +++ b/arch/nios2/Kconfig
> @@ -20,6 +20,8 @@ config NIOS2
> select USB_ARCH_HAS_HCD if USB_SUPPORT
> select CPU_NO_EFFICIENT_FFS
> select HAVE_MEMBLOCK
> + select ARCH_DISCARD_MEMBLOCK
> + select NO_BOOTMEM
>
> config GENERIC_CSUM
> def_bool y
> diff --git a/arch/nios2/kernel/prom.c b/arch/nios2/kernel/prom.c
> index ba96a49..a6d4f75 100644
> --- a/arch/nios2/kernel/prom.c
> +++ b/arch/nios2/kernel/prom.c
> @@ -32,13 +32,6 @@
>
> #include <asm/sections.h>
>
> -int __init early_init_dt_reserve_memory_arch(phys_addr_t base,
> phys_addr_t size,
> - bool nomap)
> -{
> - reserve_bootmem(base, size, BOOTMEM_DEFAULT);
> - return 0;
> -}
> -
> void __init early_init_devtree(void *params)
> {
> __be32 *dtb = (u32 *)__dtb_start;
> diff --git a/arch/nios2/kernel/setup.c b/arch/nios2/kernel/setup.c
> index 0946840..2d0011d 100644
> --- a/arch/nios2/kernel/setup.c
> +++ b/arch/nios2/kernel/setup.c
> @@ -144,10 +144,11 @@ asmlinkage void __init nios2_boot_init(unsigned
> r4, unsigned r5, unsigned r6,
>
> void __init setup_arch(char **cmdline_p)
> {
> - int bootmap_size;
> + int dram_start;
>
> console_verbose();
>
> + dram_start = memblock_start_of_DRAM();
> memory_size = memblock_phys_mem_size();
> memory_start = PAGE_ALIGN((unsigned long)__pa(_end));
> memory_end = (unsigned long) CONFIG_NIOS2_MEM_BASE +
> memory_size;
> @@ -165,39 +166,11 @@ void __init setup_arch(char **cmdline_p)
> max_low_pfn = PFN_DOWN(memory_end);
> max_mapnr = max_low_pfn;
>
> - /*
> - * give all the memory to the bootmap allocator, tell it to
> put the
> - * boot mem_map at the start of memory
> - */
> - pr_debug("init_bootmem_node(?,%#lx, %#x, %#lx)\n",
> - min_low_pfn, PFN_DOWN(PHYS_OFFSET), max_low_pfn);
> - bootmap_size = init_bootmem_node(NODE_DATA(0),
> - min_low_pfn,
> PFN_DOWN(PHYS_OFFSET),
> - max_low_pfn);
> -
> - /*
> - * free the usable memory, we have to make sure we do not
> free
> - * the bootmem bitmap so we then reserve it after freeing it
> :-)
> - */
> - pr_debug("free_bootmem(%#lx, %#lx)\n",
> - memory_start, memory_end - memory_start);
> - free_bootmem(memory_start, memory_end - memory_start);
> -
> - /*
> - * Reserve the bootmem bitmap itself as well. We do this in
> two
> - * steps (first step was init_bootmem()) because this catches
> - * the (very unlikely) case of us accidentally initializing
> the
> - * bootmem allocator with an invalid RAM area.
> - *
> - * Arguments are start, size
> - */
> - pr_debug("reserve_bootmem(%#lx, %#x)\n", memory_start,
> bootmap_size);
> - reserve_bootmem(memory_start, bootmap_size, BOOTMEM_DEFAULT);
> -
> + memblock_reserve(dram_start, memory_start - dram_start);
> #ifdef CONFIG_BLK_DEV_INITRD
> if (initrd_start) {
> - reserve_bootmem(virt_to_phys((void *)initrd_start),
> - initrd_end - initrd_start,
> BOOTMEM_DEFAULT);
> + memblock_reserve(virt_to_phys((void *)initrd_start),
> + initrd_end - initrd_start);
> }
> #endif /* CONFIG_BLK_DEV_INITRD */
>
> --
> 2.7.4
Acked-by: Ley Foon Tan <[email protected]>
On Wed, 2018-07-04 at 16:18 +0300, Mike Rapoport wrote:
> All we have to do is to enable memblock, the generic FDT code will
> take
> care of the rest.
>
> Signed-off-by: Mike Rapoport <[email protected]>
> ---
> arch/nios2/Kconfig | 1 +
> arch/nios2/kernel/prom.c | 10 ----------
> arch/nios2/kernel/setup.c | 2 ++
> 3 files changed, 3 insertions(+), 10 deletions(-)
>
> diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
> index 3d4ec88..5db8fa1 100644
> --- a/arch/nios2/Kconfig
> +++ b/arch/nios2/Kconfig
> @@ -19,6 +19,7 @@ config NIOS2
> select SPARSE_IRQ
> select USB_ARCH_HAS_HCD if USB_SUPPORT
> select CPU_NO_EFFICIENT_FFS
> + select HAVE_MEMBLOCK
>
> config GENERIC_CSUM
> def_bool y
> diff --git a/arch/nios2/kernel/prom.c b/arch/nios2/kernel/prom.c
> index 8d7446a..ba96a49 100644
> --- a/arch/nios2/kernel/prom.c
> +++ b/arch/nios2/kernel/prom.c
> @@ -32,16 +32,6 @@
>
> #include <asm/sections.h>
>
> -void __init early_init_dt_add_memory_arch(u64 base, u64 size)
> -{
> - u64 kernel_start = (u64)virt_to_phys(_text);
> -
> - if (!memory_size &&
> - (kernel_start >= base) && (kernel_start < (base + size)))
> - memory_size = size;
> -
> -}
> -
> int __init early_init_dt_reserve_memory_arch(phys_addr_t base,
> phys_addr_t size,
> bool nomap)
> {
> diff --git a/arch/nios2/kernel/setup.c b/arch/nios2/kernel/setup.c
> index 926a02b..0946840 100644
> --- a/arch/nios2/kernel/setup.c
> +++ b/arch/nios2/kernel/setup.c
> @@ -17,6 +17,7 @@
> #include <linux/sched/task.h>
> #include <linux/console.h>
> #include <linux/bootmem.h>
> +#include <linux/memblock.h>
> #include <linux/initrd.h>
> #include <linux/of_fdt.h>
> #include <linux/screen_info.h>
> @@ -147,6 +148,7 @@ void __init setup_arch(char **cmdline_p)
>
> console_verbose();
>
> + memory_size = memblock_phys_mem_size();
> memory_start = PAGE_ALIGN((unsigned long)__pa(_end));
> memory_end = (unsigned long) CONFIG_NIOS2_MEM_BASE +
> memory_size;
>
> --
Acked-by: Ley Foon Tan <[email protected]>