linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] m68k: switch to MEMBLOCK + NO_BOOTMEM
@ 2018-07-03 10:29 Mike Rapoport
  2018-07-03 10:29 ` [PATCH 1/3] m68k/bitops: convert __ffs to match generic declaration Mike Rapoport
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Mike Rapoport @ 2018-07-03 10:29 UTC (permalink / raw)
  To: Geert Uytterhoeven, Greg Ungerer, Sam Creasey
  Cc: Michal Hocko, linux-m68k, linux-mm, linux-kernel, Mike Rapoport

Hi,

These patches switch m68k boot time memory allocators from bootmem to
memblock + no_bootmem.

The first two patches update __ffs() and __va() definitions to be inline
with other arches and asm-generic. This is required to avoid compilation
warnings in mm/memblock.c and mm/nobootmem.c.

The third patch performs the actual switch of the boot time mm. Its
changelog has detailed description of the changes.

I've tested the !MMU version with qemu-system-m68k -M mcf5208evb
and the MMU version with q800 using qemu from [1].

I've also build tested allyesconfig and *_defconfig.

[1] https://github.com/vivier/qemu-m68k.git

Mike Rapoport (3):
  m68k/bitops: convert __ffs to match generic declaration
  m68k/page_no.h: force __va argument to be unsigned long
  m68k: switch to MEMBLOCK + NO_BOOTMEM

 arch/m68k/Kconfig               |  3 +++
 arch/m68k/include/asm/bitops.h  |  8 ++++++--
 arch/m68k/include/asm/page_no.h |  2 +-
 arch/m68k/kernel/setup_mm.c     | 14 ++++----------
 arch/m68k/kernel/setup_no.c     | 20 ++++----------------
 arch/m68k/mm/init.c             |  1 -
 arch/m68k/mm/mcfmmu.c           | 11 +++++++----
 arch/m68k/mm/motorola.c         | 35 +++++++++++------------------------
 arch/m68k/sun3/config.c         |  4 ----
 9 files changed, 36 insertions(+), 62 deletions(-)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/3] m68k/bitops: convert __ffs to match generic declaration
  2018-07-03 10:29 [PATCH 0/3] m68k: switch to MEMBLOCK + NO_BOOTMEM Mike Rapoport
@ 2018-07-03 10:29 ` Mike Rapoport
  2018-07-03 10:29 ` [PATCH 2/3] m68k/page_no.h: force __va argument to be unsigned long Mike Rapoport
  2018-07-03 10:29 ` [PATCH 3/3] m68k: switch to MEMBLOCK + NO_BOOTMEM Mike Rapoport
  2 siblings, 0 replies; 17+ messages in thread
From: Mike Rapoport @ 2018-07-03 10:29 UTC (permalink / raw)
  To: Geert Uytterhoeven, Greg Ungerer, Sam Creasey
  Cc: Michal Hocko, linux-m68k, linux-mm, linux-kernel, Mike Rapoport

The generic bitops declare __ffs as

	static inline unsigned long __ffs(unsigned long word);

Convert the m68k version to match the generic declaration.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
 arch/m68k/include/asm/bitops.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/m68k/include/asm/bitops.h b/arch/m68k/include/asm/bitops.h
index 93b47b1..54009ea 100644
--- a/arch/m68k/include/asm/bitops.h
+++ b/arch/m68k/include/asm/bitops.h
@@ -454,7 +454,7 @@ static inline unsigned long ffz(unsigned long word)
  */
 #if (defined(__mcfisaaplus__) || defined(__mcfisac__)) && \
 	!defined(CONFIG_M68000) && !defined(CONFIG_MCPU32)
-static inline int __ffs(int x)
+static inline unsigned long __ffs(unsigned long x)
 {
 	__asm__ __volatile__ ("bitrev %0; ff1 %0"
 		: "=d" (x)
@@ -493,7 +493,11 @@ static inline int ffs(int x)
 		: "dm" (x & -x));
 	return 32 - cnt;
 }
-#define __ffs(x) (ffs(x) - 1)
+
+static inline unsigned long __ffs(unsigned long x)
+{
+	return ffs(x) - 1;
+}
 
 /*
  *	fls: find last bit set.
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/3] m68k/page_no.h: force __va argument to be unsigned long
  2018-07-03 10:29 [PATCH 0/3] m68k: switch to MEMBLOCK + NO_BOOTMEM Mike Rapoport
  2018-07-03 10:29 ` [PATCH 1/3] m68k/bitops: convert __ffs to match generic declaration Mike Rapoport
@ 2018-07-03 10:29 ` Mike Rapoport
  2018-07-03 14:20   ` Michal Hocko
  2018-07-03 10:29 ` [PATCH 3/3] m68k: switch to MEMBLOCK + NO_BOOTMEM Mike Rapoport
  2 siblings, 1 reply; 17+ messages in thread
From: Mike Rapoport @ 2018-07-03 10:29 UTC (permalink / raw)
  To: Geert Uytterhoeven, Greg Ungerer, Sam Creasey
  Cc: Michal Hocko, linux-m68k, linux-mm, linux-kernel, Mike Rapoport

Add explicit casting to unsigned long to the __va() parameter

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
 arch/m68k/include/asm/page_no.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/m68k/include/asm/page_no.h b/arch/m68k/include/asm/page_no.h
index e644c4d..6bbe520 100644
--- a/arch/m68k/include/asm/page_no.h
+++ b/arch/m68k/include/asm/page_no.h
@@ -18,7 +18,7 @@ extern unsigned long memory_end;
 #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
 
 #define __pa(vaddr)		((unsigned long)(vaddr))
-#define __va(paddr)		((void *)(paddr))
+#define __va(paddr)		((void *)((unsigned long)(paddr)))
 
 #define virt_to_pfn(kaddr)	(__pa(kaddr) >> PAGE_SHIFT)
 #define pfn_to_virt(pfn)	__va((pfn) << PAGE_SHIFT)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/3] m68k: switch to MEMBLOCK + NO_BOOTMEM
  2018-07-03 10:29 [PATCH 0/3] m68k: switch to MEMBLOCK + NO_BOOTMEM Mike Rapoport
  2018-07-03 10:29 ` [PATCH 1/3] m68k/bitops: convert __ffs to match generic declaration Mike Rapoport
  2018-07-03 10:29 ` [PATCH 2/3] m68k/page_no.h: force __va argument to be unsigned long Mike Rapoport
@ 2018-07-03 10:29 ` Mike Rapoport
  2018-07-04  1:39   ` Greg Ungerer
  2 siblings, 1 reply; 17+ messages in thread
From: Mike Rapoport @ 2018-07-03 10:29 UTC (permalink / raw)
  To: Geert Uytterhoeven, Greg Ungerer, Sam Creasey
  Cc: Michal Hocko, linux-m68k, linux-mm, linux-kernel, Mike Rapoport

In m68k the physical memory is described by [memory_start, memory_end] for
!MMU variant and by m68k_memory array of memory ranges for the MMU version.
This information is directly used to register the physical memory with
memblock.

The reserve_bootmem() calls are replaced with memblock_reserve() and the
bootmap bitmap allocation is simply dropped.

Since the MMU variant creates early mappings only for the small part of the
memory we force bottom-up allocations in memblock because otherwise we will
attempt to access memory that not yet mapped

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
 arch/m68k/Kconfig           |  3 +++
 arch/m68k/kernel/setup_mm.c | 14 ++++----------
 arch/m68k/kernel/setup_no.c | 20 ++++----------------
 arch/m68k/mm/init.c         |  1 -
 arch/m68k/mm/mcfmmu.c       | 11 +++++++----
 arch/m68k/mm/motorola.c     | 35 +++++++++++------------------------
 arch/m68k/sun3/config.c     |  4 ----
 7 files changed, 29 insertions(+), 59 deletions(-)

diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
index 785612b..bd7f38a 100644
--- a/arch/m68k/Kconfig
+++ b/arch/m68k/Kconfig
@@ -24,6 +24,9 @@ config M68K
 	select MODULES_USE_ELF_RELA
 	select OLD_SIGSUSPEND3
 	select OLD_SIGACTION
+	select HAVE_MEMBLOCK
+	select ARCH_DISCARD_MEMBLOCK
+	select NO_BOOTMEM
 
 config CPU_BIG_ENDIAN
 	def_bool y
diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c
index f35e3eb..6512955 100644
--- a/arch/m68k/kernel/setup_mm.c
+++ b/arch/m68k/kernel/setup_mm.c
@@ -21,6 +21,7 @@
 #include <linux/string.h>
 #include <linux/init.h>
 #include <linux/bootmem.h>
+#include <linux/memblock.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
 #include <linux/module.h>
@@ -165,6 +166,8 @@ static void __init m68k_parse_bootinfo(const struct bi_record *record)
 					be32_to_cpu(m->addr);
 				m68k_memory[m68k_num_memory].size =
 					be32_to_cpu(m->size);
+				memblock_add(m68k_memory[m68k_num_memory].addr,
+					     m68k_memory[m68k_num_memory].size);
 				m68k_num_memory++;
 			} else
 				pr_warn("%s: too many memory chunks\n",
@@ -224,10 +227,6 @@ static void __init m68k_parse_bootinfo(const struct bi_record *record)
 
 void __init setup_arch(char **cmdline_p)
 {
-#ifndef CONFIG_SUN3
-	int i;
-#endif
-
 	/* The bootinfo is located right after the kernel */
 	if (!CPU_IS_COLDFIRE)
 		m68k_parse_bootinfo((const struct bi_record *)_end);
@@ -356,14 +355,9 @@ void __init setup_arch(char **cmdline_p)
 #endif
 
 #ifndef CONFIG_SUN3
-	for (i = 1; i < m68k_num_memory; i++)
-		free_bootmem_node(NODE_DATA(i), m68k_memory[i].addr,
-				  m68k_memory[i].size);
 #ifdef CONFIG_BLK_DEV_INITRD
 	if (m68k_ramdisk.size) {
-		reserve_bootmem_node(__virt_to_node(phys_to_virt(m68k_ramdisk.addr)),
-				     m68k_ramdisk.addr, m68k_ramdisk.size,
-				     BOOTMEM_DEFAULT);
+		memblock_reserve(m68k_ramdisk.addr, m68k_ramdisk.size);
 		initrd_start = (unsigned long)phys_to_virt(m68k_ramdisk.addr);
 		initrd_end = initrd_start + m68k_ramdisk.size;
 		pr_info("initrd: %08lx - %08lx\n", initrd_start, initrd_end);
diff --git a/arch/m68k/kernel/setup_no.c b/arch/m68k/kernel/setup_no.c
index a98af10..3e8d87a 100644
--- a/arch/m68k/kernel/setup_no.c
+++ b/arch/m68k/kernel/setup_no.c
@@ -28,6 +28,7 @@
 #include <linux/errno.h>
 #include <linux/string.h>
 #include <linux/bootmem.h>
+#include <linux/memblock.h>
 #include <linux/seq_file.h>
 #include <linux/init.h>
 #include <linux/initrd.h>
@@ -86,8 +87,6 @@ void (*mach_power_off)(void);
 
 void __init setup_arch(char **cmdline_p)
 {
-	int bootmap_size;
-
 	memory_start = PAGE_ALIGN(_ramstart);
 	memory_end = _ramend;
 
@@ -142,6 +141,8 @@ void __init setup_arch(char **cmdline_p)
 	pr_debug("MEMORY -> ROMFS=0x%p-0x%06lx MEM=0x%06lx-0x%06lx\n ",
 		 __bss_stop, memory_start, memory_start, memory_end);
 
+	memblock_add(memory_start, memory_end - memory_start);
+
 	/* Keep a copy of command line */
 	*cmdline_p = &command_line[0];
 	memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
@@ -158,23 +159,10 @@ void __init setup_arch(char **cmdline_p)
 	min_low_pfn = PFN_DOWN(memory_start);
 	max_pfn = max_low_pfn = PFN_DOWN(memory_end);
 
-	bootmap_size = init_bootmem_node(
-			NODE_DATA(0),
-			min_low_pfn,		/* map goes here */
-			PFN_DOWN(PAGE_OFFSET),
-			max_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 :-)
-	 */
-	free_bootmem(memory_start, memory_end - memory_start);
-	reserve_bootmem(memory_start, bootmap_size, BOOTMEM_DEFAULT);
-
 #if defined(CONFIG_UBOOT) && defined(CONFIG_BLK_DEV_INITRD)
 	if ((initrd_start > 0) && (initrd_start < initrd_end) &&
 			(initrd_end < memory_end))
-		reserve_bootmem(initrd_start, initrd_end - initrd_start,
-				 BOOTMEM_DEFAULT);
+		memblock_reserve(initrd_start, initrd_end - initrd_start);
 #endif /* if defined(CONFIG_BLK_DEV_INITRD) */
 
 	/*
diff --git a/arch/m68k/mm/init.c b/arch/m68k/mm/init.c
index 8827b7f..38e2b27 100644
--- a/arch/m68k/mm/init.c
+++ b/arch/m68k/mm/init.c
@@ -71,7 +71,6 @@ void __init m68k_setup_node(int node)
 		pg_data_table[i] = pg_data_map + node;
 	}
 #endif
-	pg_data_map[node].bdata = bootmem_node_data + node;
 	node_set_online(node);
 }
 
diff --git a/arch/m68k/mm/mcfmmu.c b/arch/m68k/mm/mcfmmu.c
index 2925d79..e9e60e1 100644
--- a/arch/m68k/mm/mcfmmu.c
+++ b/arch/m68k/mm/mcfmmu.c
@@ -14,6 +14,7 @@
 #include <linux/init.h>
 #include <linux/string.h>
 #include <linux/bootmem.h>
+#include <linux/memblock.h>
 
 #include <asm/setup.h>
 #include <asm/page.h>
@@ -160,6 +161,8 @@ void __init cf_bootmem_alloc(void)
 	m68k_memory[0].addr = _rambase;
 	m68k_memory[0].size = _ramend - _rambase;
 
+	memblock_add(m68k_memory[0].addr, m68k_memory[0].size);
+
 	/* compute total pages in system */
 	num_pages = PFN_DOWN(_ramend - _rambase);
 
@@ -170,14 +173,14 @@ void __init cf_bootmem_alloc(void)
 	max_pfn = max_low_pfn = PFN_DOWN(_ramend);
 	high_memory = (void *)_ramend;
 
+	/* Reserve kernel text/data/bss */
+	memblock_reserve(memstart, _ramend - memstart);
+
 	m68k_virt_to_node_shift = fls(_ramend - 1) - 6;
 	module_fixup(NULL, __start_fixup, __stop_fixup);
 
-	/* setup bootmem data */
+	/* setup node data */
 	m68k_setup_node(0);
-	memstart += init_bootmem_node(NODE_DATA(0), start_pfn,
-		min_low_pfn, max_low_pfn);
-	free_bootmem_node(NODE_DATA(0), memstart, _ramend - memstart);
 }
 
 /*
diff --git a/arch/m68k/mm/motorola.c b/arch/m68k/mm/motorola.c
index e490ecc..4e17ecb 100644
--- a/arch/m68k/mm/motorola.c
+++ b/arch/m68k/mm/motorola.c
@@ -19,6 +19,7 @@
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/bootmem.h>
+#include <linux/memblock.h>
 #include <linux/gfp.h>
 
 #include <asm/setup.h>
@@ -208,7 +209,7 @@ void __init paging_init(void)
 {
 	unsigned long zones_size[MAX_NR_ZONES] = { 0, };
 	unsigned long min_addr, max_addr;
-	unsigned long addr, size, end;
+	unsigned long addr;
 	int i;
 
 #ifdef DEBUG
@@ -253,34 +254,20 @@ void __init paging_init(void)
 	min_low_pfn = availmem >> PAGE_SHIFT;
 	max_pfn = max_low_pfn = max_addr >> PAGE_SHIFT;
 
-	for (i = 0; i < m68k_num_memory; i++) {
-		addr = m68k_memory[i].addr;
-		end = addr + m68k_memory[i].size;
-		m68k_setup_node(i);
-		availmem = PAGE_ALIGN(availmem);
-		availmem += init_bootmem_node(NODE_DATA(i),
-					      availmem >> PAGE_SHIFT,
-					      addr >> PAGE_SHIFT,
-					      end >> PAGE_SHIFT);
-	}
+	/* Reserve kernel text/data/bss and the memory allocated in head.S */
+	memblock_reserve(m68k_memory[0].addr, availmem - m68k_memory[0].addr);
 
 	/*
 	 * Map the physical memory available into the kernel virtual
-	 * address space. First initialize the bootmem allocator with
-	 * the memory we already mapped, so map_node() has something
-	 * to allocate.
+	 * address space. Make sure memblock will not try to allocate
+	 * pages beyond the memory we already mapped in head.S
 	 */
-	addr = m68k_memory[0].addr;
-	size = m68k_memory[0].size;
-	free_bootmem_node(NODE_DATA(0), availmem,
-			  min(m68k_init_mapped_size, size) - (availmem - addr));
-	map_node(0);
-	if (size > m68k_init_mapped_size)
-		free_bootmem_node(NODE_DATA(0), addr + m68k_init_mapped_size,
-				  size - m68k_init_mapped_size);
-
-	for (i = 1; i < m68k_num_memory; i++)
+	memblock_set_bottom_up(true);
+
+	for (i = 0; i < m68k_num_memory; i++) {
+		m68k_setup_node(i);
 		map_node(i);
+	}
 
 	flush_tlb_all();
 
diff --git a/arch/m68k/sun3/config.c b/arch/m68k/sun3/config.c
index 1d28d38..79a2bb8 100644
--- a/arch/m68k/sun3/config.c
+++ b/arch/m68k/sun3/config.c
@@ -123,10 +123,6 @@ static void __init sun3_bootmem_alloc(unsigned long memory_start,
 	availmem = memory_start;
 
 	m68k_setup_node(0);
-	availmem += init_bootmem(start_page, num_pages);
-	availmem = (availmem + (PAGE_SIZE-1)) & PAGE_MASK;
-
-	free_bootmem(__pa(availmem), memory_end - (availmem));
 }
 
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] m68k/page_no.h: force __va argument to be unsigned long
  2018-07-03 10:29 ` [PATCH 2/3] m68k/page_no.h: force __va argument to be unsigned long Mike Rapoport
@ 2018-07-03 14:20   ` Michal Hocko
  2018-07-03 15:03     ` Mike Rapoport
  0 siblings, 1 reply; 17+ messages in thread
From: Michal Hocko @ 2018-07-03 14:20 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Geert Uytterhoeven, Greg Ungerer, Sam Creasey, linux-m68k,
	linux-mm, linux-kernel

On Tue 03-07-18 13:29:54, Mike Rapoport wrote:
> Add explicit casting to unsigned long to the __va() parameter

Why is this needed?

> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> ---
>  arch/m68k/include/asm/page_no.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/m68k/include/asm/page_no.h b/arch/m68k/include/asm/page_no.h
> index e644c4d..6bbe520 100644
> --- a/arch/m68k/include/asm/page_no.h
> +++ b/arch/m68k/include/asm/page_no.h
> @@ -18,7 +18,7 @@ extern unsigned long memory_end;
>  #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
>  
>  #define __pa(vaddr)		((unsigned long)(vaddr))
> -#define __va(paddr)		((void *)(paddr))
> +#define __va(paddr)		((void *)((unsigned long)(paddr)))
>  
>  #define virt_to_pfn(kaddr)	(__pa(kaddr) >> PAGE_SHIFT)
>  #define pfn_to_virt(pfn)	__va((pfn) << PAGE_SHIFT)
> -- 
> 2.7.4

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] m68k/page_no.h: force __va argument to be unsigned long
  2018-07-03 14:20   ` Michal Hocko
@ 2018-07-03 15:03     ` Mike Rapoport
  2018-07-03 15:05       ` Matthew Wilcox
  0 siblings, 1 reply; 17+ messages in thread
From: Mike Rapoport @ 2018-07-03 15:03 UTC (permalink / raw)
  To: Michal Hocko
  Cc: Geert Uytterhoeven, Greg Ungerer, Sam Creasey, linux-m68k,
	linux-mm, linux-kernel

On Tue, Jul 03, 2018 at 04:20:54PM +0200, Michal Hocko wrote:
> On Tue 03-07-18 13:29:54, Mike Rapoport wrote:
> > Add explicit casting to unsigned long to the __va() parameter
> 
> Why is this needed?

To make it consitent with other architecures and asm-generic :)

But more importantly, __memblock_free_late() passes u64 to page_to_pfn().
On m68k-nommu this results in:

  CC      mm/nobootmem.o
In file included from
arch/m68k/include/asm/page.h:49,
                 from
arch/m68k/include/asm/thread_info.h:6,
                 from
include/linux/thread_info.h:38,
                 from
include/asm-generic/preempt.h:5,
                 from ./arch/m68k/include/generated/asm/preempt.h:1,
                 from include/linux/preempt.h:81,
                 from include/linux/spinlock.h:51,
                 from include/linux/mmzone.h:8,
                 from include/linux/gfp.h:6,
                 from include/linux/slab.h:15,
                 from mm/memblock.c:14:
mm/memblock.c: In function '__memblock_free_late':
arch/m68k/include/asm/page_no.h:21:23: warning:
cast to pointer from integer of different size [-Wint-to-pointer-cast]
 #define __va(paddr)  ((void *)(paddr))
                       ^
arch/m68k/include/asm/page_no.h:26:57: note: in
definition of macro 'virt_to_page'
 #define virt_to_page(addr) (mem_map + (((unsigned long)(addr)-PAGE_OFFSET)
>> PAGE_SHIFT))
                                                         ^~~~
arch/m68k/include/asm/page_no.h:24:26: note: in
expansion of macro '__va'
 #define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)
                          ^~~~
arch/m68k/include/asm/page_no.h:29:39: note: in
expansion of macro 'pfn_to_virt'
 #define pfn_to_page(pfn) virt_to_page(pfn_to_virt(pfn))
                                       ^~~~~~~~~~~
mm/memblock.c:1473:24: note: in expansion of macro
'pfn_to_page'
   __free_pages_bootmem(pfn_to_page(cursor), cursor, 0);
                        ^~~~~~~~~~~

 
> > Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> > ---
> >  arch/m68k/include/asm/page_no.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/m68k/include/asm/page_no.h b/arch/m68k/include/asm/page_no.h
> > index e644c4d..6bbe520 100644
> > --- a/arch/m68k/include/asm/page_no.h
> > +++ b/arch/m68k/include/asm/page_no.h
> > @@ -18,7 +18,7 @@ extern unsigned long memory_end;
> >  #define __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
> >  
> >  #define __pa(vaddr)		((unsigned long)(vaddr))
> > -#define __va(paddr)		((void *)(paddr))
> > +#define __va(paddr)		((void *)((unsigned long)(paddr)))
> >  
> >  #define virt_to_pfn(kaddr)	(__pa(kaddr) >> PAGE_SHIFT)
> >  #define pfn_to_virt(pfn)	__va((pfn) << PAGE_SHIFT)
> > -- 
> > 2.7.4
> 
> -- 
> Michal Hocko
> SUSE Labs
> 

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] m68k/page_no.h: force __va argument to be unsigned long
  2018-07-03 15:03     ` Mike Rapoport
@ 2018-07-03 15:05       ` Matthew Wilcox
  2018-07-03 15:14         ` Michal Hocko
  2018-07-03 15:30         ` Mike Rapoport
  0 siblings, 2 replies; 17+ messages in thread
From: Matthew Wilcox @ 2018-07-03 15:05 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Michal Hocko, Geert Uytterhoeven, Greg Ungerer, Sam Creasey,
	linux-m68k, linux-mm, linux-kernel

On Tue, Jul 03, 2018 at 06:03:16PM +0300, Mike Rapoport wrote:
> On Tue, Jul 03, 2018 at 04:20:54PM +0200, Michal Hocko wrote:
> > On Tue 03-07-18 13:29:54, Mike Rapoport wrote:
> > > Add explicit casting to unsigned long to the __va() parameter
> > 
> > Why is this needed?
> 
> To make it consitent with other architecures and asm-generic :)
> 
> But more importantly, __memblock_free_late() passes u64 to page_to_pfn().

Why does memblock work in terms of u64 instead of phys_addr_t?


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] m68k/page_no.h: force __va argument to be unsigned long
  2018-07-03 15:05       ` Matthew Wilcox
@ 2018-07-03 15:14         ` Michal Hocko
  2018-07-03 15:39           ` Mike Rapoport
  2018-07-03 15:47           ` Mike Rapoport
  2018-07-03 15:30         ` Mike Rapoport
  1 sibling, 2 replies; 17+ messages in thread
From: Michal Hocko @ 2018-07-03 15:14 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Mike Rapoport, Geert Uytterhoeven, Greg Ungerer, Sam Creasey,
	linux-m68k, linux-mm, linux-kernel

On Tue 03-07-18 08:05:35, Matthew Wilcox wrote:
> On Tue, Jul 03, 2018 at 06:03:16PM +0300, Mike Rapoport wrote:
> > On Tue, Jul 03, 2018 at 04:20:54PM +0200, Michal Hocko wrote:
> > > On Tue 03-07-18 13:29:54, Mike Rapoport wrote:
> > > > Add explicit casting to unsigned long to the __va() parameter
> > > 
> > > Why is this needed?
> > 
> > To make it consitent with other architecures and asm-generic :)
> > 
> > But more importantly, __memblock_free_late() passes u64 to page_to_pfn().
> 
> Why does memblock work in terms of u64 instead of phys_addr_t?

Yes, phys_addr_t was exactly that came to my mind as well. Casting
physical address to unsigned long just screams for potential problems.

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] m68k/page_no.h: force __va argument to be unsigned long
  2018-07-03 15:05       ` Matthew Wilcox
  2018-07-03 15:14         ` Michal Hocko
@ 2018-07-03 15:30         ` Mike Rapoport
  1 sibling, 0 replies; 17+ messages in thread
From: Mike Rapoport @ 2018-07-03 15:30 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Michal Hocko, Geert Uytterhoeven, Greg Ungerer, Sam Creasey,
	linux-m68k, linux-mm, linux-kernel

On Tue, Jul 03, 2018 at 08:05:35AM -0700, Matthew Wilcox wrote:
> On Tue, Jul 03, 2018 at 06:03:16PM +0300, Mike Rapoport wrote:
> > On Tue, Jul 03, 2018 at 04:20:54PM +0200, Michal Hocko wrote:
> > > On Tue 03-07-18 13:29:54, Mike Rapoport wrote:
> > > > Add explicit casting to unsigned long to the __va() parameter
> > > 
> > > Why is this needed?
> > 
> > To make it consitent with other architecures and asm-generic :)
> > 
> > But more importantly, __memblock_free_late() passes u64 to page_to_pfn().
> 
> Why does memblock work in terms of u64 instead of phys_addr_t?

Historically?

It started off with unsigned long, then commit e5f270954364 ("[LMB]: Make
lmb support large physical addressing") converted it to u64 for 32-bit
systems sake.

And the definition of ARCH_PHYS_ADDR_T_64BIT in commit 600715dcdf56
("generic: add phys_addr_t for holding physical addresses")) came in later.
    

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] m68k/page_no.h: force __va argument to be unsigned long
  2018-07-03 15:14         ` Michal Hocko
@ 2018-07-03 15:39           ` Mike Rapoport
  2018-07-03 15:47           ` Mike Rapoport
  1 sibling, 0 replies; 17+ messages in thread
From: Mike Rapoport @ 2018-07-03 15:39 UTC (permalink / raw)
  To: Michal Hocko
  Cc: Matthew Wilcox, Geert Uytterhoeven, Greg Ungerer, Sam Creasey,
	linux-m68k, linux-mm, linux-kernel

On Tue, Jul 03, 2018 at 05:14:01PM +0200, Michal Hocko wrote:
> On Tue 03-07-18 08:05:35, Matthew Wilcox wrote:
> > On Tue, Jul 03, 2018 at 06:03:16PM +0300, Mike Rapoport wrote:
> > > On Tue, Jul 03, 2018 at 04:20:54PM +0200, Michal Hocko wrote:
> > > > On Tue 03-07-18 13:29:54, Mike Rapoport wrote:
> > > > > Add explicit casting to unsigned long to the __va() parameter
> > > > 
> > > > Why is this needed?
> > > 
> > > To make it consitent with other architecures and asm-generic :)
> > > 
> > > But more importantly, __memblock_free_late() passes u64 to page_to_pfn().
> > 
> > Why does memblock work in terms of u64 instead of phys_addr_t?
> 
> Yes, phys_addr_t was exactly that came to my mind as well. Casting
> physical address to unsigned long just screams for potential problems.

Heh, that's what we have:

~/git/linux $ git grep 'define __va.*\(unsigned long\)' | wc -l
22
 
> -- 
> Michal Hocko
> SUSE Labs
> 

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] m68k/page_no.h: force __va argument to be unsigned long
  2018-07-03 15:14         ` Michal Hocko
  2018-07-03 15:39           ` Mike Rapoport
@ 2018-07-03 15:47           ` Mike Rapoport
  2018-07-03 15:55             ` Michal Hocko
  1 sibling, 1 reply; 17+ messages in thread
From: Mike Rapoport @ 2018-07-03 15:47 UTC (permalink / raw)
  To: Michal Hocko
  Cc: Matthew Wilcox, Geert Uytterhoeven, Greg Ungerer, Sam Creasey,
	linux-m68k, linux-mm, linux-kernel

On Tue, Jul 03, 2018 at 05:14:01PM +0200, Michal Hocko wrote:
> On Tue 03-07-18 08:05:35, Matthew Wilcox wrote:
> > On Tue, Jul 03, 2018 at 06:03:16PM +0300, Mike Rapoport wrote:
> > > On Tue, Jul 03, 2018 at 04:20:54PM +0200, Michal Hocko wrote:
> > > > On Tue 03-07-18 13:29:54, Mike Rapoport wrote:
> > > > > Add explicit casting to unsigned long to the __va() parameter
> > > > 
> > > > Why is this needed?
> > > 
> > > To make it consitent with other architecures and asm-generic :)
> > > 
> > > But more importantly, __memblock_free_late() passes u64 to page_to_pfn().
> > 
> > Why does memblock work in terms of u64 instead of phys_addr_t?
> 
> Yes, phys_addr_t was exactly that came to my mind as well. Casting
> physical address to unsigned long just screams for potential problems.

Not sure if for m68k-nommu the physical address can really go beyond 32
bits, but in general this is something that should be taken care of.

I think adding the cast in m68k-nommu case is a viable band aid to allow
sorting out the bootmem vs nobootmem.

In any case care should be taken of all those

	#define __va(x)	((void *)((unsigned long)(x))) 

all around.

Regardless, I can s/u64/phys_addr_t/ in memblock.c.

> -- 
> Michal Hocko
> SUSE Labs
> 

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 2/3] m68k/page_no.h: force __va argument to be unsigned long
  2018-07-03 15:47           ` Mike Rapoport
@ 2018-07-03 15:55             ` Michal Hocko
  0 siblings, 0 replies; 17+ messages in thread
From: Michal Hocko @ 2018-07-03 15:55 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Matthew Wilcox, Geert Uytterhoeven, Greg Ungerer, Sam Creasey,
	linux-m68k, linux-mm, linux-kernel

On Tue 03-07-18 18:47:51, Mike Rapoport wrote:
> On Tue, Jul 03, 2018 at 05:14:01PM +0200, Michal Hocko wrote:
> > On Tue 03-07-18 08:05:35, Matthew Wilcox wrote:
> > > On Tue, Jul 03, 2018 at 06:03:16PM +0300, Mike Rapoport wrote:
> > > > On Tue, Jul 03, 2018 at 04:20:54PM +0200, Michal Hocko wrote:
> > > > > On Tue 03-07-18 13:29:54, Mike Rapoport wrote:
> > > > > > Add explicit casting to unsigned long to the __va() parameter
> > > > > 
> > > > > Why is this needed?
> > > > 
> > > > To make it consitent with other architecures and asm-generic :)
> > > > 
> > > > But more importantly, __memblock_free_late() passes u64 to page_to_pfn().
> > > 
> > > Why does memblock work in terms of u64 instead of phys_addr_t?
> > 
> > Yes, phys_addr_t was exactly that came to my mind as well. Casting
> > physical address to unsigned long just screams for potential problems.
> 
> Not sure if for m68k-nommu the physical address can really go beyond 32
> bits, but in general this is something that should be taken care of.
> 
> I think adding the cast in m68k-nommu case is a viable band aid to allow
> sorting out the bootmem vs nobootmem.
> 
> In any case care should be taken of all those
> 
> 	#define __va(x)	((void *)((unsigned long)(x))) 

Yeah, sounds like a good idea to me.

> all around.
> 
> Regardless, I can s/u64/phys_addr_t/ in memblock.c.

Yeah, sounds like a good thing to me.

-- 
Michal Hocko
SUSE Labs

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/3] m68k: switch to MEMBLOCK + NO_BOOTMEM
  2018-07-03 10:29 ` [PATCH 3/3] m68k: switch to MEMBLOCK + NO_BOOTMEM Mike Rapoport
@ 2018-07-04  1:39   ` Greg Ungerer
  2018-07-04  2:02     ` Greg Ungerer
  0 siblings, 1 reply; 17+ messages in thread
From: Greg Ungerer @ 2018-07-04  1:39 UTC (permalink / raw)
  To: Mike Rapoport, Geert Uytterhoeven, Sam Creasey
  Cc: Michal Hocko, linux-m68k, linux-mm, linux-kernel

Hi Mike,

On 03/07/18 20:29, Mike Rapoport wrote:
> In m68k the physical memory is described by [memory_start, memory_end] for
> !MMU variant and by m68k_memory array of memory ranges for the MMU version.
> This information is directly used to register the physical memory with
> memblock.
> 
> The reserve_bootmem() calls are replaced with memblock_reserve() and the
> bootmap bitmap allocation is simply dropped.
> 
> Since the MMU variant creates early mappings only for the small part of the
> memory we force bottom-up allocations in memblock because otherwise we will
> attempt to access memory that not yet mapped
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>

This builds cleanly for me with a m5475_defconfig, but it fails
to boot on real hardware. No console, no nothing on startup.
I haven't debugged any further yet.

The M5475 is a ColdFire with MMU enabled target.

Regards
Greg


> ---
>   arch/m68k/Kconfig           |  3 +++
>   arch/m68k/kernel/setup_mm.c | 14 ++++----------
>   arch/m68k/kernel/setup_no.c | 20 ++++----------------
>   arch/m68k/mm/init.c         |  1 -
>   arch/m68k/mm/mcfmmu.c       | 11 +++++++----
>   arch/m68k/mm/motorola.c     | 35 +++++++++++------------------------
>   arch/m68k/sun3/config.c     |  4 ----
>   7 files changed, 29 insertions(+), 59 deletions(-)
> 
> diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
> index 785612b..bd7f38a 100644
> --- a/arch/m68k/Kconfig
> +++ b/arch/m68k/Kconfig
> @@ -24,6 +24,9 @@ config M68K
>   	select MODULES_USE_ELF_RELA
>   	select OLD_SIGSUSPEND3
>   	select OLD_SIGACTION
> +	select HAVE_MEMBLOCK
> +	select ARCH_DISCARD_MEMBLOCK
> +	select NO_BOOTMEM
>   
>   config CPU_BIG_ENDIAN
>   	def_bool y
> diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c
> index f35e3eb..6512955 100644
> --- a/arch/m68k/kernel/setup_mm.c
> +++ b/arch/m68k/kernel/setup_mm.c
> @@ -21,6 +21,7 @@
>   #include <linux/string.h>
>   #include <linux/init.h>
>   #include <linux/bootmem.h>
> +#include <linux/memblock.h>
>   #include <linux/proc_fs.h>
>   #include <linux/seq_file.h>
>   #include <linux/module.h>
> @@ -165,6 +166,8 @@ static void __init m68k_parse_bootinfo(const struct bi_record *record)
>   					be32_to_cpu(m->addr);
>   				m68k_memory[m68k_num_memory].size =
>   					be32_to_cpu(m->size);
> +				memblock_add(m68k_memory[m68k_num_memory].addr,
> +					     m68k_memory[m68k_num_memory].size);
>   				m68k_num_memory++;
>   			} else
>   				pr_warn("%s: too many memory chunks\n",
> @@ -224,10 +227,6 @@ static void __init m68k_parse_bootinfo(const struct bi_record *record)
>   
>   void __init setup_arch(char **cmdline_p)
>   {
> -#ifndef CONFIG_SUN3
> -	int i;
> -#endif
> -
>   	/* The bootinfo is located right after the kernel */
>   	if (!CPU_IS_COLDFIRE)
>   		m68k_parse_bootinfo((const struct bi_record *)_end);
> @@ -356,14 +355,9 @@ void __init setup_arch(char **cmdline_p)
>   #endif
>   
>   #ifndef CONFIG_SUN3
> -	for (i = 1; i < m68k_num_memory; i++)
> -		free_bootmem_node(NODE_DATA(i), m68k_memory[i].addr,
> -				  m68k_memory[i].size);
>   #ifdef CONFIG_BLK_DEV_INITRD
>   	if (m68k_ramdisk.size) {
> -		reserve_bootmem_node(__virt_to_node(phys_to_virt(m68k_ramdisk.addr)),
> -				     m68k_ramdisk.addr, m68k_ramdisk.size,
> -				     BOOTMEM_DEFAULT);
> +		memblock_reserve(m68k_ramdisk.addr, m68k_ramdisk.size);
>   		initrd_start = (unsigned long)phys_to_virt(m68k_ramdisk.addr);
>   		initrd_end = initrd_start + m68k_ramdisk.size;
>   		pr_info("initrd: %08lx - %08lx\n", initrd_start, initrd_end);
> diff --git a/arch/m68k/kernel/setup_no.c b/arch/m68k/kernel/setup_no.c
> index a98af10..3e8d87a 100644
> --- a/arch/m68k/kernel/setup_no.c
> +++ b/arch/m68k/kernel/setup_no.c
> @@ -28,6 +28,7 @@
>   #include <linux/errno.h>
>   #include <linux/string.h>
>   #include <linux/bootmem.h>
> +#include <linux/memblock.h>
>   #include <linux/seq_file.h>
>   #include <linux/init.h>
>   #include <linux/initrd.h>
> @@ -86,8 +87,6 @@ void (*mach_power_off)(void);
>   
>   void __init setup_arch(char **cmdline_p)
>   {
> -	int bootmap_size;
> -
>   	memory_start = PAGE_ALIGN(_ramstart);
>   	memory_end = _ramend;
>   
> @@ -142,6 +141,8 @@ void __init setup_arch(char **cmdline_p)
>   	pr_debug("MEMORY -> ROMFS=0x%p-0x%06lx MEM=0x%06lx-0x%06lx\n ",
>   		 __bss_stop, memory_start, memory_start, memory_end);
>   
> +	memblock_add(memory_start, memory_end - memory_start);
> +
>   	/* Keep a copy of command line */
>   	*cmdline_p = &command_line[0];
>   	memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
> @@ -158,23 +159,10 @@ void __init setup_arch(char **cmdline_p)
>   	min_low_pfn = PFN_DOWN(memory_start);
>   	max_pfn = max_low_pfn = PFN_DOWN(memory_end);
>   
> -	bootmap_size = init_bootmem_node(
> -			NODE_DATA(0),
> -			min_low_pfn,		/* map goes here */
> -			PFN_DOWN(PAGE_OFFSET),
> -			max_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 :-)
> -	 */
> -	free_bootmem(memory_start, memory_end - memory_start);
> -	reserve_bootmem(memory_start, bootmap_size, BOOTMEM_DEFAULT);
> -
>   #if defined(CONFIG_UBOOT) && defined(CONFIG_BLK_DEV_INITRD)
>   	if ((initrd_start > 0) && (initrd_start < initrd_end) &&
>   			(initrd_end < memory_end))
> -		reserve_bootmem(initrd_start, initrd_end - initrd_start,
> -				 BOOTMEM_DEFAULT);
> +		memblock_reserve(initrd_start, initrd_end - initrd_start);
>   #endif /* if defined(CONFIG_BLK_DEV_INITRD) */
>   
>   	/*
> diff --git a/arch/m68k/mm/init.c b/arch/m68k/mm/init.c
> index 8827b7f..38e2b27 100644
> --- a/arch/m68k/mm/init.c
> +++ b/arch/m68k/mm/init.c
> @@ -71,7 +71,6 @@ void __init m68k_setup_node(int node)
>   		pg_data_table[i] = pg_data_map + node;
>   	}
>   #endif
> -	pg_data_map[node].bdata = bootmem_node_data + node;
>   	node_set_online(node);
>   }
>   
> diff --git a/arch/m68k/mm/mcfmmu.c b/arch/m68k/mm/mcfmmu.c
> index 2925d79..e9e60e1 100644
> --- a/arch/m68k/mm/mcfmmu.c
> +++ b/arch/m68k/mm/mcfmmu.c
> @@ -14,6 +14,7 @@
>   #include <linux/init.h>
>   #include <linux/string.h>
>   #include <linux/bootmem.h>
> +#include <linux/memblock.h>
>   
>   #include <asm/setup.h>
>   #include <asm/page.h>
> @@ -160,6 +161,8 @@ void __init cf_bootmem_alloc(void)
>   	m68k_memory[0].addr = _rambase;
>   	m68k_memory[0].size = _ramend - _rambase;
>   
> +	memblock_add(m68k_memory[0].addr, m68k_memory[0].size);
> +
>   	/* compute total pages in system */
>   	num_pages = PFN_DOWN(_ramend - _rambase);
>   
> @@ -170,14 +173,14 @@ void __init cf_bootmem_alloc(void)
>   	max_pfn = max_low_pfn = PFN_DOWN(_ramend);
>   	high_memory = (void *)_ramend;
>   
> +	/* Reserve kernel text/data/bss */
> +	memblock_reserve(memstart, _ramend - memstart);
> +
>   	m68k_virt_to_node_shift = fls(_ramend - 1) - 6;
>   	module_fixup(NULL, __start_fixup, __stop_fixup);
>   
> -	/* setup bootmem data */
> +	/* setup node data */
>   	m68k_setup_node(0);
> -	memstart += init_bootmem_node(NODE_DATA(0), start_pfn,
> -		min_low_pfn, max_low_pfn);
> -	free_bootmem_node(NODE_DATA(0), memstart, _ramend - memstart);
>   }
>   
>   /*
> diff --git a/arch/m68k/mm/motorola.c b/arch/m68k/mm/motorola.c
> index e490ecc..4e17ecb 100644
> --- a/arch/m68k/mm/motorola.c
> +++ b/arch/m68k/mm/motorola.c
> @@ -19,6 +19,7 @@
>   #include <linux/types.h>
>   #include <linux/init.h>
>   #include <linux/bootmem.h>
> +#include <linux/memblock.h>
>   #include <linux/gfp.h>
>   
>   #include <asm/setup.h>
> @@ -208,7 +209,7 @@ void __init paging_init(void)
>   {
>   	unsigned long zones_size[MAX_NR_ZONES] = { 0, };
>   	unsigned long min_addr, max_addr;
> -	unsigned long addr, size, end;
> +	unsigned long addr;
>   	int i;
>   
>   #ifdef DEBUG
> @@ -253,34 +254,20 @@ void __init paging_init(void)
>   	min_low_pfn = availmem >> PAGE_SHIFT;
>   	max_pfn = max_low_pfn = max_addr >> PAGE_SHIFT;
>   
> -	for (i = 0; i < m68k_num_memory; i++) {
> -		addr = m68k_memory[i].addr;
> -		end = addr + m68k_memory[i].size;
> -		m68k_setup_node(i);
> -		availmem = PAGE_ALIGN(availmem);
> -		availmem += init_bootmem_node(NODE_DATA(i),
> -					      availmem >> PAGE_SHIFT,
> -					      addr >> PAGE_SHIFT,
> -					      end >> PAGE_SHIFT);
> -	}
> +	/* Reserve kernel text/data/bss and the memory allocated in head.S */
> +	memblock_reserve(m68k_memory[0].addr, availmem - m68k_memory[0].addr);
>   
>   	/*
>   	 * Map the physical memory available into the kernel virtual
> -	 * address space. First initialize the bootmem allocator with
> -	 * the memory we already mapped, so map_node() has something
> -	 * to allocate.
> +	 * address space. Make sure memblock will not try to allocate
> +	 * pages beyond the memory we already mapped in head.S
>   	 */
> -	addr = m68k_memory[0].addr;
> -	size = m68k_memory[0].size;
> -	free_bootmem_node(NODE_DATA(0), availmem,
> -			  min(m68k_init_mapped_size, size) - (availmem - addr));
> -	map_node(0);
> -	if (size > m68k_init_mapped_size)
> -		free_bootmem_node(NODE_DATA(0), addr + m68k_init_mapped_size,
> -				  size - m68k_init_mapped_size);
> -
> -	for (i = 1; i < m68k_num_memory; i++)
> +	memblock_set_bottom_up(true);
> +
> +	for (i = 0; i < m68k_num_memory; i++) {
> +		m68k_setup_node(i);
>   		map_node(i);
> +	}
>   
>   	flush_tlb_all();
>   
> diff --git a/arch/m68k/sun3/config.c b/arch/m68k/sun3/config.c
> index 1d28d38..79a2bb8 100644
> --- a/arch/m68k/sun3/config.c
> +++ b/arch/m68k/sun3/config.c
> @@ -123,10 +123,6 @@ static void __init sun3_bootmem_alloc(unsigned long memory_start,
>   	availmem = memory_start;
>   
>   	m68k_setup_node(0);
> -	availmem += init_bootmem(start_page, num_pages);
> -	availmem = (availmem + (PAGE_SIZE-1)) & PAGE_MASK;
> -
> -	free_bootmem(__pa(availmem), memory_end - (availmem));
>   }
>   
>   
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/3] m68k: switch to MEMBLOCK + NO_BOOTMEM
  2018-07-04  1:39   ` Greg Ungerer
@ 2018-07-04  2:02     ` Greg Ungerer
  2018-07-04  4:22       ` Mike Rapoport
  0 siblings, 1 reply; 17+ messages in thread
From: Greg Ungerer @ 2018-07-04  2:02 UTC (permalink / raw)
  To: Mike Rapoport, Geert Uytterhoeven, Sam Creasey
  Cc: Michal Hocko, linux-m68k, linux-mm, linux-kernel

Hi Mike,

On 04/07/18 11:39, Greg Ungerer wrote:
> On 03/07/18 20:29, Mike Rapoport wrote:
>> In m68k the physical memory is described by [memory_start, memory_end] for
>> !MMU variant and by m68k_memory array of memory ranges for the MMU version.
>> This information is directly used to register the physical memory with
>> memblock.
>>
>> The reserve_bootmem() calls are replaced with memblock_reserve() and the
>> bootmap bitmap allocation is simply dropped.
>>
>> Since the MMU variant creates early mappings only for the small part of the
>> memory we force bottom-up allocations in memblock because otherwise we will
>> attempt to access memory that not yet mapped
>>
>> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> 
> This builds cleanly for me with a m5475_defconfig, but it fails
> to boot on real hardware. No console, no nothing on startup.
> I haven't debugged any further yet.
> 
> The M5475 is a ColdFire with MMU enabled target.

With some early serial debug trace I see:

Linux version 4.18.0-rc3-00003-g109f5e551b18-dirty (gerg@goober) (gcc version 5.4.0 (GCC)) #5 Wed Jul 4 12:00:03 AEST 2018
On node 0 totalpages: 4096
   DMA zone: 18 pages used for memmap
   DMA zone: 0 pages reserved
   DMA zone: 4096 pages, LIFO batch:0
pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
pcpu-alloc: [0] 0
Built 1 zonelists, mobility grouping off.  Total pages: 4078
Kernel command line: root=/dev/mtdblock0
Dentry cache hash table entries: 4096 (order: 1, 16384 bytes)
Inode-cache hash table entries: 2048 (order: 0, 8192 bytes)
Sorting __ex_table...
Memory: 3032K/32768K available (1489K kernel code, 96K rwdata, 240K rodata, 56K init, 77K bss, 29736K reserved, 0K cma-reserved)
SLUB: HWalign=16, Order=0-3, MinObjects=0, CPUs=1, Nodes=8
NR_IRQS: 256
clocksource: slt: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 14370379300 ns
Calibrating delay loop... 264.19 BogoMIPS (lpj=1320960)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 2048 (order: 0, 8192 bytes)
Mountpoint-cache hash table entries: 2048 (order: 0, 8192 bytes)
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
ColdFire: PCI bus initialization...
Coldfire: PCI IO/config window mapped to 0xe0000000
PCI host bridge to bus 0000:00
pci_bus 0000:00: root bus resource [io  0x0000-0xffff]
pci_bus 0000:00: root bus resource [mem 0x00000000-0xffffffff]
pci_bus 0000:00: root bus resource [bus 00-ff]
pci 0000:00:14.0: [8086:1229] type 00 class 0x020000
pci 0000:00:14.0: reg 0x10: [mem 0x00000000-0x00000fff]
pci 0000:00:14.0: reg 0x14: [io  0x0000-0x003f]
pci 0000:00:14.0: reg 0x18: [mem 0x00000000-0x000fffff]
pci 0000:00:14.0: reg 0x30: [mem 0x00000000-0x000fffff pref]
pci 0000:00:14.0: supports D1 D2
pci 0000:00:14.0: PME# supported from D0 D1 D2 D3hot
pci 0000:00:14.0: BAR 2: assigned [mem 0xf0000000-0xf00fffff]
pci 0000:00:14.0: BAR 6: assigned [mem 0xf0100000-0xf01fffff pref]
pci 0000:00:14.0: BAR 0: assigned [mem 0xf0200000-0xf0200fff]
pci 0000:00:14.0: BAR 1: assigned [io  0x0400-0x043f]
vgaarb: loaded
clocksource: Switched to clocksource slt
PCI: CLS 32 bytes, default 16
workingset: timestamp_bits=27 max_order=9 bucket_order=0
kobject_add_internal failed for slab (error: -12 parent: kernel)
Cannot register slab subsystem.
romfs: ROMFS MTD (C) 2007 Red Hat, Inc.
io scheduler noop registered (default)
io scheduler mq-deadline registered
io scheduler kyber registered
kobject_add_internal failed for ptyp0 (error: -12 parent: tty)
Kernel panic - not syncing: Couldn't register pty driver
CPU: 0 PID: 1 Comm: swapper Not tainted 4.18.0-rc3-00003-g109f5e551b18-dirty #5
Stack from 00283ee4:
         00283ee4 001bc27a 000287ea 0019075c 00000019 001f5390 0018ba36 002c6a00
         002c6a80 0014ab82 00148816 001f2c2a 001b948c 00000000 001f2ad0 001f6ce8
         0002118e 00283f8c 000211b4 00000006 00000019 001f5390 0018ba36 00000007
         00000000 001f53cc 00305fb0 0002118e 0003df6a 00000000 00000006 00000006
         00305fb0 00305fb5 001ea7f6 001ba406 00305fb0 001d1c58 00000019 00000006
         00000006 00000000 0003df6a 001ea804 001f2ad0 00000000 001e5964 00282001
Call Trace:
         [<000287ea>] 0x000287ea
  [<0019075c>] 0x0019075c
  [<0018ba36>] 0x0018ba36
  [<0014ab82>] 0x0014ab82
  [<00148816>] 0x00148816

         [<001f2c2a>] 0x001f2c2a
  [<001f2ad0>] 0x001f2ad0
  [<0002118e>] 0x0002118e
  [<000211b4>] 0x000211b4
  [<0018ba36>] 0x0018ba36

         [<0002118e>] 0x0002118e
  [<0003df6a>] 0x0003df6a
  [<001ea7f6>] 0x001ea7f6
  [<0003df6a>] 0x0003df6a
  [<001ea804>] 0x001ea804

         [<001f2ad0>] 0x001f2ad0
  [<00190bae>] 0x00190bae
  [<00190bb6>] 0x00190bb6
  [<00190bae>] 0x00190bae
  [<00021aac>] 0x00021aac

---[ end Kernel panic - not syncing: Couldn't register pty driver ]---
random: fast init done

Regards
Greg



>> ---
>>   arch/m68k/Kconfig           |  3 +++
>>   arch/m68k/kernel/setup_mm.c | 14 ++++----------
>>   arch/m68k/kernel/setup_no.c | 20 ++++----------------
>>   arch/m68k/mm/init.c         |  1 -
>>   arch/m68k/mm/mcfmmu.c       | 11 +++++++----
>>   arch/m68k/mm/motorola.c     | 35 +++++++++++------------------------
>>   arch/m68k/sun3/config.c     |  4 ----
>>   7 files changed, 29 insertions(+), 59 deletions(-)
>>
>> diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
>> index 785612b..bd7f38a 100644
>> --- a/arch/m68k/Kconfig
>> +++ b/arch/m68k/Kconfig
>> @@ -24,6 +24,9 @@ config M68K
>>       select MODULES_USE_ELF_RELA
>>       select OLD_SIGSUSPEND3
>>       select OLD_SIGACTION
>> +    select HAVE_MEMBLOCK
>> +    select ARCH_DISCARD_MEMBLOCK
>> +    select NO_BOOTMEM
>>   config CPU_BIG_ENDIAN
>>       def_bool y
>> diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c
>> index f35e3eb..6512955 100644
>> --- a/arch/m68k/kernel/setup_mm.c
>> +++ b/arch/m68k/kernel/setup_mm.c
>> @@ -21,6 +21,7 @@
>>   #include <linux/string.h>
>>   #include <linux/init.h>
>>   #include <linux/bootmem.h>
>> +#include <linux/memblock.h>
>>   #include <linux/proc_fs.h>
>>   #include <linux/seq_file.h>
>>   #include <linux/module.h>
>> @@ -165,6 +166,8 @@ static void __init m68k_parse_bootinfo(const struct bi_record *record)
>>                       be32_to_cpu(m->addr);
>>                   m68k_memory[m68k_num_memory].size =
>>                       be32_to_cpu(m->size);
>> +                memblock_add(m68k_memory[m68k_num_memory].addr,
>> +                         m68k_memory[m68k_num_memory].size);
>>                   m68k_num_memory++;
>>               } else
>>                   pr_warn("%s: too many memory chunks\n",
>> @@ -224,10 +227,6 @@ static void __init m68k_parse_bootinfo(const struct bi_record *record)
>>   void __init setup_arch(char **cmdline_p)
>>   {
>> -#ifndef CONFIG_SUN3
>> -    int i;
>> -#endif
>> -
>>       /* The bootinfo is located right after the kernel */
>>       if (!CPU_IS_COLDFIRE)
>>           m68k_parse_bootinfo((const struct bi_record *)_end);
>> @@ -356,14 +355,9 @@ void __init setup_arch(char **cmdline_p)
>>   #endif
>>   #ifndef CONFIG_SUN3
>> -    for (i = 1; i < m68k_num_memory; i++)
>> -        free_bootmem_node(NODE_DATA(i), m68k_memory[i].addr,
>> -                  m68k_memory[i].size);
>>   #ifdef CONFIG_BLK_DEV_INITRD
>>       if (m68k_ramdisk.size) {
>> -        reserve_bootmem_node(__virt_to_node(phys_to_virt(m68k_ramdisk.addr)),
>> -                     m68k_ramdisk.addr, m68k_ramdisk.size,
>> -                     BOOTMEM_DEFAULT);
>> +        memblock_reserve(m68k_ramdisk.addr, m68k_ramdisk.size);
>>           initrd_start = (unsigned long)phys_to_virt(m68k_ramdisk.addr);
>>           initrd_end = initrd_start + m68k_ramdisk.size;
>>           pr_info("initrd: %08lx - %08lx\n", initrd_start, initrd_end);
>> diff --git a/arch/m68k/kernel/setup_no.c b/arch/m68k/kernel/setup_no.c
>> index a98af10..3e8d87a 100644
>> --- a/arch/m68k/kernel/setup_no.c
>> +++ b/arch/m68k/kernel/setup_no.c
>> @@ -28,6 +28,7 @@
>>   #include <linux/errno.h>
>>   #include <linux/string.h>
>>   #include <linux/bootmem.h>
>> +#include <linux/memblock.h>
>>   #include <linux/seq_file.h>
>>   #include <linux/init.h>
>>   #include <linux/initrd.h>
>> @@ -86,8 +87,6 @@ void (*mach_power_off)(void);
>>   void __init setup_arch(char **cmdline_p)
>>   {
>> -    int bootmap_size;
>> -
>>       memory_start = PAGE_ALIGN(_ramstart);
>>       memory_end = _ramend;
>> @@ -142,6 +141,8 @@ void __init setup_arch(char **cmdline_p)
>>       pr_debug("MEMORY -> ROMFS=0x%p-0x%06lx MEM=0x%06lx-0x%06lx\n ",
>>            __bss_stop, memory_start, memory_start, memory_end);
>> +    memblock_add(memory_start, memory_end - memory_start);
>> +
>>       /* Keep a copy of command line */
>>       *cmdline_p = &command_line[0];
>>       memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
>> @@ -158,23 +159,10 @@ void __init setup_arch(char **cmdline_p)
>>       min_low_pfn = PFN_DOWN(memory_start);
>>       max_pfn = max_low_pfn = PFN_DOWN(memory_end);
>> -    bootmap_size = init_bootmem_node(
>> -            NODE_DATA(0),
>> -            min_low_pfn,        /* map goes here */
>> -            PFN_DOWN(PAGE_OFFSET),
>> -            max_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 :-)
>> -     */
>> -    free_bootmem(memory_start, memory_end - memory_start);
>> -    reserve_bootmem(memory_start, bootmap_size, BOOTMEM_DEFAULT);
>> -
>>   #if defined(CONFIG_UBOOT) && defined(CONFIG_BLK_DEV_INITRD)
>>       if ((initrd_start > 0) && (initrd_start < initrd_end) &&
>>               (initrd_end < memory_end))
>> -        reserve_bootmem(initrd_start, initrd_end - initrd_start,
>> -                 BOOTMEM_DEFAULT);
>> +        memblock_reserve(initrd_start, initrd_end - initrd_start);
>>   #endif /* if defined(CONFIG_BLK_DEV_INITRD) */
>>       /*
>> diff --git a/arch/m68k/mm/init.c b/arch/m68k/mm/init.c
>> index 8827b7f..38e2b27 100644
>> --- a/arch/m68k/mm/init.c
>> +++ b/arch/m68k/mm/init.c
>> @@ -71,7 +71,6 @@ void __init m68k_setup_node(int node)
>>           pg_data_table[i] = pg_data_map + node;
>>       }
>>   #endif
>> -    pg_data_map[node].bdata = bootmem_node_data + node;
>>       node_set_online(node);
>>   }
>> diff --git a/arch/m68k/mm/mcfmmu.c b/arch/m68k/mm/mcfmmu.c
>> index 2925d79..e9e60e1 100644
>> --- a/arch/m68k/mm/mcfmmu.c
>> +++ b/arch/m68k/mm/mcfmmu.c
>> @@ -14,6 +14,7 @@
>>   #include <linux/init.h>
>>   #include <linux/string.h>
>>   #include <linux/bootmem.h>
>> +#include <linux/memblock.h>
>>   #include <asm/setup.h>
>>   #include <asm/page.h>
>> @@ -160,6 +161,8 @@ void __init cf_bootmem_alloc(void)
>>       m68k_memory[0].addr = _rambase;
>>       m68k_memory[0].size = _ramend - _rambase;
>> +    memblock_add(m68k_memory[0].addr, m68k_memory[0].size);
>> +
>>       /* compute total pages in system */
>>       num_pages = PFN_DOWN(_ramend - _rambase);
>> @@ -170,14 +173,14 @@ void __init cf_bootmem_alloc(void)
>>       max_pfn = max_low_pfn = PFN_DOWN(_ramend);
>>       high_memory = (void *)_ramend;
>> +    /* Reserve kernel text/data/bss */
>> +    memblock_reserve(memstart, _ramend - memstart);
>> +
>>       m68k_virt_to_node_shift = fls(_ramend - 1) - 6;
>>       module_fixup(NULL, __start_fixup, __stop_fixup);
>> -    /* setup bootmem data */
>> +    /* setup node data */
>>       m68k_setup_node(0);
>> -    memstart += init_bootmem_node(NODE_DATA(0), start_pfn,
>> -        min_low_pfn, max_low_pfn);
>> -    free_bootmem_node(NODE_DATA(0), memstart, _ramend - memstart);
>>   }
>>   /*
>> diff --git a/arch/m68k/mm/motorola.c b/arch/m68k/mm/motorola.c
>> index e490ecc..4e17ecb 100644
>> --- a/arch/m68k/mm/motorola.c
>> +++ b/arch/m68k/mm/motorola.c
>> @@ -19,6 +19,7 @@
>>   #include <linux/types.h>
>>   #include <linux/init.h>
>>   #include <linux/bootmem.h>
>> +#include <linux/memblock.h>
>>   #include <linux/gfp.h>
>>   #include <asm/setup.h>
>> @@ -208,7 +209,7 @@ void __init paging_init(void)
>>   {
>>       unsigned long zones_size[MAX_NR_ZONES] = { 0, };
>>       unsigned long min_addr, max_addr;
>> -    unsigned long addr, size, end;
>> +    unsigned long addr;
>>       int i;
>>   #ifdef DEBUG
>> @@ -253,34 +254,20 @@ void __init paging_init(void)
>>       min_low_pfn = availmem >> PAGE_SHIFT;
>>       max_pfn = max_low_pfn = max_addr >> PAGE_SHIFT;
>> -    for (i = 0; i < m68k_num_memory; i++) {
>> -        addr = m68k_memory[i].addr;
>> -        end = addr + m68k_memory[i].size;
>> -        m68k_setup_node(i);
>> -        availmem = PAGE_ALIGN(availmem);
>> -        availmem += init_bootmem_node(NODE_DATA(i),
>> -                          availmem >> PAGE_SHIFT,
>> -                          addr >> PAGE_SHIFT,
>> -                          end >> PAGE_SHIFT);
>> -    }
>> +    /* Reserve kernel text/data/bss and the memory allocated in head.S */
>> +    memblock_reserve(m68k_memory[0].addr, availmem - m68k_memory[0].addr);
>>       /*
>>        * Map the physical memory available into the kernel virtual
>> -     * address space. First initialize the bootmem allocator with
>> -     * the memory we already mapped, so map_node() has something
>> -     * to allocate.
>> +     * address space. Make sure memblock will not try to allocate
>> +     * pages beyond the memory we already mapped in head.S
>>        */
>> -    addr = m68k_memory[0].addr;
>> -    size = m68k_memory[0].size;
>> -    free_bootmem_node(NODE_DATA(0), availmem,
>> -              min(m68k_init_mapped_size, size) - (availmem - addr));
>> -    map_node(0);
>> -    if (size > m68k_init_mapped_size)
>> -        free_bootmem_node(NODE_DATA(0), addr + m68k_init_mapped_size,
>> -                  size - m68k_init_mapped_size);
>> -
>> -    for (i = 1; i < m68k_num_memory; i++)
>> +    memblock_set_bottom_up(true);
>> +
>> +    for (i = 0; i < m68k_num_memory; i++) {
>> +        m68k_setup_node(i);
>>           map_node(i);
>> +    }
>>       flush_tlb_all();
>> diff --git a/arch/m68k/sun3/config.c b/arch/m68k/sun3/config.c
>> index 1d28d38..79a2bb8 100644
>> --- a/arch/m68k/sun3/config.c
>> +++ b/arch/m68k/sun3/config.c
>> @@ -123,10 +123,6 @@ static void __init sun3_bootmem_alloc(unsigned long memory_start,
>>       availmem = memory_start;
>>       m68k_setup_node(0);
>> -    availmem += init_bootmem(start_page, num_pages);
>> -    availmem = (availmem + (PAGE_SIZE-1)) & PAGE_MASK;
>> -
>> -    free_bootmem(__pa(availmem), memory_end - (availmem));
>>   }
>>
> -- 
> To unsubscribe from this list: send the line "unsubscribe linux-m68k" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/3] m68k: switch to MEMBLOCK + NO_BOOTMEM
  2018-07-04  2:02     ` Greg Ungerer
@ 2018-07-04  4:22       ` Mike Rapoport
  2018-07-04  4:39         ` Greg Ungerer
  0 siblings, 1 reply; 17+ messages in thread
From: Mike Rapoport @ 2018-07-04  4:22 UTC (permalink / raw)
  To: Greg Ungerer
  Cc: Geert Uytterhoeven, Sam Creasey, Michal Hocko, linux-m68k,
	linux-mm, linux-kernel

On Wed, Jul 04, 2018 at 12:02:52PM +1000, Greg Ungerer wrote:
> Hi Mike,
> 
> On 04/07/18 11:39, Greg Ungerer wrote:
> >On 03/07/18 20:29, Mike Rapoport wrote:
> >>In m68k the physical memory is described by [memory_start, memory_end] for
> >>!MMU variant and by m68k_memory array of memory ranges for the MMU version.
> >>This information is directly used to register the physical memory with
> >>memblock.
> >>
> >>The reserve_bootmem() calls are replaced with memblock_reserve() and the
> >>bootmap bitmap allocation is simply dropped.
> >>
> >>Since the MMU variant creates early mappings only for the small part of the
> >>memory we force bottom-up allocations in memblock because otherwise we will
> >>attempt to access memory that not yet mapped
> >>
> >>Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> >
> >This builds cleanly for me with a m5475_defconfig, but it fails
> >to boot on real hardware. No console, no nothing on startup.
> >I haven't debugged any further yet.
> >
> >The M5475 is a ColdFire with MMU enabled target.
> 
> With some early serial debug trace I see:
> 
> Linux version 4.18.0-rc3-00003-g109f5e551b18-dirty (gerg@goober) (gcc version 5.4.0 (GCC)) #5 Wed Jul 4 12:00:03 AEST 2018
> On node 0 totalpages: 4096
>   DMA zone: 18 pages used for memmap
>   DMA zone: 0 pages reserved
>   DMA zone: 4096 pages, LIFO batch:0
> pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
> pcpu-alloc: [0] 0
> Built 1 zonelists, mobility grouping off.  Total pages: 4078
> Kernel command line: root=/dev/mtdblock0
> Dentry cache hash table entries: 4096 (order: 1, 16384 bytes)
> Inode-cache hash table entries: 2048 (order: 0, 8192 bytes)
> Sorting __ex_table...
> Memory: 3032K/32768K available (1489K kernel code, 96K rwdata, 240K rodata, 56K init, 77K bss, 29736K reserved, 0K cma-reserved)
                                                                                                 ^^^^^^
It seems I was over enthusiastic when I reserved the memory for the kernel.
Can you please try with the below patch:

diff --git a/arch/m68k/mm/mcfmmu.c b/arch/m68k/mm/mcfmmu.c
index e9e60e1..18c7bf6 100644
--- a/arch/m68k/mm/mcfmmu.c
+++ b/arch/m68k/mm/mcfmmu.c
@@ -174,7 +174,7 @@ void __init cf_bootmem_alloc(void)
 	high_memory = (void *)_ramend;
 
 	/* Reserve kernel text/data/bss */
-	memblock_reserve(memstart, _ramend - memstart);
+	memblock_reserve(memstart, memstart - _rambase);
 
 	m68k_virt_to_node_shift = fls(_ramend - 1) - 6;
 	module_fixup(NULL, __start_fixup, __stop_fixup);
diff --git a/mm/memblock.c b/mm/memblock.c
index 03d48d8..98661be 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -54,7 +54,7 @@ struct memblock memblock __initdata_memblock = {
 	.current_limit		= MEMBLOCK_ALLOC_ANYWHERE,
 };
 
-int memblock_debug __initdata_memblock;
+int memblock_debug __initdata_memblock = 1;
 static bool system_has_some_mirror __initdata_memblock = false;
 static int memblock_can_resize __initdata_memblock;
 static int memblock_memory_in_slab __initdata_memblock = 0;


The memblock hunk is needed to see early memblock debug messages as all the
setup happens before parsing of the command line.

> SLUB: HWalign=16, Order=0-3, MinObjects=0, CPUs=1, Nodes=8
> NR_IRQS: 256
> clocksource: slt: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 14370379300 ns
> Calibrating delay loop... 264.19 BogoMIPS (lpj=1320960)
> pid_max: default: 32768 minimum: 301
> Mount-cache hash table entries: 2048 (order: 0, 8192 bytes)
> Mountpoint-cache hash table entries: 2048 (order: 0, 8192 bytes)
> clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
> ColdFire: PCI bus initialization...
> Coldfire: PCI IO/config window mapped to 0xe0000000
> PCI host bridge to bus 0000:00
> pci_bus 0000:00: root bus resource [io  0x0000-0xffff]
> pci_bus 0000:00: root bus resource [mem 0x00000000-0xffffffff]
> pci_bus 0000:00: root bus resource [bus 00-ff]
> pci 0000:00:14.0: [8086:1229] type 00 class 0x020000
> pci 0000:00:14.0: reg 0x10: [mem 0x00000000-0x00000fff]
> pci 0000:00:14.0: reg 0x14: [io  0x0000-0x003f]
> pci 0000:00:14.0: reg 0x18: [mem 0x00000000-0x000fffff]
> pci 0000:00:14.0: reg 0x30: [mem 0x00000000-0x000fffff pref]
> pci 0000:00:14.0: supports D1 D2
> pci 0000:00:14.0: PME# supported from D0 D1 D2 D3hot
> pci 0000:00:14.0: BAR 2: assigned [mem 0xf0000000-0xf00fffff]
> pci 0000:00:14.0: BAR 6: assigned [mem 0xf0100000-0xf01fffff pref]
> pci 0000:00:14.0: BAR 0: assigned [mem 0xf0200000-0xf0200fff]
> pci 0000:00:14.0: BAR 1: assigned [io  0x0400-0x043f]
> vgaarb: loaded
> clocksource: Switched to clocksource slt
> PCI: CLS 32 bytes, default 16
> workingset: timestamp_bits=27 max_order=9 bucket_order=0
> kobject_add_internal failed for slab (error: -12 parent: kernel)
> Cannot register slab subsystem.
> romfs: ROMFS MTD (C) 2007 Red Hat, Inc.
> io scheduler noop registered (default)
> io scheduler mq-deadline registered
> io scheduler kyber registered
> kobject_add_internal failed for ptyp0 (error: -12 parent: tty)
> Kernel panic - not syncing: Couldn't register pty driver
> CPU: 0 PID: 1 Comm: swapper Not tainted 4.18.0-rc3-00003-g109f5e551b18-dirty #5
> Stack from 00283ee4:
>         00283ee4 001bc27a 000287ea 0019075c 00000019 001f5390 0018ba36 002c6a00
>         002c6a80 0014ab82 00148816 001f2c2a 001b948c 00000000 001f2ad0 001f6ce8
>         0002118e 00283f8c 000211b4 00000006 00000019 001f5390 0018ba36 00000007
>         00000000 001f53cc 00305fb0 0002118e 0003df6a 00000000 00000006 00000006
>         00305fb0 00305fb5 001ea7f6 001ba406 00305fb0 001d1c58 00000019 00000006
>         00000006 00000000 0003df6a 001ea804 001f2ad0 00000000 001e5964 00282001
> Call Trace:
>         [<000287ea>] 0x000287ea
>  [<0019075c>] 0x0019075c
>  [<0018ba36>] 0x0018ba36
>  [<0014ab82>] 0x0014ab82
>  [<00148816>] 0x00148816
> 
>         [<001f2c2a>] 0x001f2c2a
>  [<001f2ad0>] 0x001f2ad0
>  [<0002118e>] 0x0002118e
>  [<000211b4>] 0x000211b4
>  [<0018ba36>] 0x0018ba36
> 
>         [<0002118e>] 0x0002118e
>  [<0003df6a>] 0x0003df6a
>  [<001ea7f6>] 0x001ea7f6
>  [<0003df6a>] 0x0003df6a
>  [<001ea804>] 0x001ea804
> 
>         [<001f2ad0>] 0x001f2ad0
>  [<00190bae>] 0x00190bae
>  [<00190bb6>] 0x00190bb6
>  [<00190bae>] 0x00190bae
>  [<00021aac>] 0x00021aac
> 
> ---[ end Kernel panic - not syncing: Couldn't register pty driver ]---
> random: fast init done
> 
> Regards
> Greg
> 
> 
> 
> >>---
> >>  arch/m68k/Kconfig           |  3 +++
> >>  arch/m68k/kernel/setup_mm.c | 14 ++++----------
> >>  arch/m68k/kernel/setup_no.c | 20 ++++----------------
> >>  arch/m68k/mm/init.c         |  1 -
> >>  arch/m68k/mm/mcfmmu.c       | 11 +++++++----
> >>  arch/m68k/mm/motorola.c     | 35 +++++++++++------------------------
> >>  arch/m68k/sun3/config.c     |  4 ----
> >>  7 files changed, 29 insertions(+), 59 deletions(-)
> >>
> >>diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig
> >>index 785612b..bd7f38a 100644
> >>--- a/arch/m68k/Kconfig
> >>+++ b/arch/m68k/Kconfig
> >>@@ -24,6 +24,9 @@ config M68K
> >>      select MODULES_USE_ELF_RELA
> >>      select OLD_SIGSUSPEND3
> >>      select OLD_SIGACTION
> >>+    select HAVE_MEMBLOCK
> >>+    select ARCH_DISCARD_MEMBLOCK
> >>+    select NO_BOOTMEM
> >>  config CPU_BIG_ENDIAN
> >>      def_bool y
> >>diff --git a/arch/m68k/kernel/setup_mm.c b/arch/m68k/kernel/setup_mm.c
> >>index f35e3eb..6512955 100644
> >>--- a/arch/m68k/kernel/setup_mm.c
> >>+++ b/arch/m68k/kernel/setup_mm.c
> >>@@ -21,6 +21,7 @@
> >>  #include <linux/string.h>
> >>  #include <linux/init.h>
> >>  #include <linux/bootmem.h>
> >>+#include <linux/memblock.h>
> >>  #include <linux/proc_fs.h>
> >>  #include <linux/seq_file.h>
> >>  #include <linux/module.h>
> >>@@ -165,6 +166,8 @@ static void __init m68k_parse_bootinfo(const struct bi_record *record)
> >>                      be32_to_cpu(m->addr);
> >>                  m68k_memory[m68k_num_memory].size =
> >>                      be32_to_cpu(m->size);
> >>+                memblock_add(m68k_memory[m68k_num_memory].addr,
> >>+                         m68k_memory[m68k_num_memory].size);
> >>                  m68k_num_memory++;
> >>              } else
> >>                  pr_warn("%s: too many memory chunks\n",
> >>@@ -224,10 +227,6 @@ static void __init m68k_parse_bootinfo(const struct bi_record *record)
> >>  void __init setup_arch(char **cmdline_p)
> >>  {
> >>-#ifndef CONFIG_SUN3
> >>-    int i;
> >>-#endif
> >>-
> >>      /* The bootinfo is located right after the kernel */
> >>      if (!CPU_IS_COLDFIRE)
> >>          m68k_parse_bootinfo((const struct bi_record *)_end);
> >>@@ -356,14 +355,9 @@ void __init setup_arch(char **cmdline_p)
> >>  #endif
> >>  #ifndef CONFIG_SUN3
> >>-    for (i = 1; i < m68k_num_memory; i++)
> >>-        free_bootmem_node(NODE_DATA(i), m68k_memory[i].addr,
> >>-                  m68k_memory[i].size);
> >>  #ifdef CONFIG_BLK_DEV_INITRD
> >>      if (m68k_ramdisk.size) {
> >>-        reserve_bootmem_node(__virt_to_node(phys_to_virt(m68k_ramdisk.addr)),
> >>-                     m68k_ramdisk.addr, m68k_ramdisk.size,
> >>-                     BOOTMEM_DEFAULT);
> >>+        memblock_reserve(m68k_ramdisk.addr, m68k_ramdisk.size);
> >>          initrd_start = (unsigned long)phys_to_virt(m68k_ramdisk.addr);
> >>          initrd_end = initrd_start + m68k_ramdisk.size;
> >>          pr_info("initrd: %08lx - %08lx\n", initrd_start, initrd_end);
> >>diff --git a/arch/m68k/kernel/setup_no.c b/arch/m68k/kernel/setup_no.c
> >>index a98af10..3e8d87a 100644
> >>--- a/arch/m68k/kernel/setup_no.c
> >>+++ b/arch/m68k/kernel/setup_no.c
> >>@@ -28,6 +28,7 @@
> >>  #include <linux/errno.h>
> >>  #include <linux/string.h>
> >>  #include <linux/bootmem.h>
> >>+#include <linux/memblock.h>
> >>  #include <linux/seq_file.h>
> >>  #include <linux/init.h>
> >>  #include <linux/initrd.h>
> >>@@ -86,8 +87,6 @@ void (*mach_power_off)(void);
> >>  void __init setup_arch(char **cmdline_p)
> >>  {
> >>-    int bootmap_size;
> >>-
> >>      memory_start = PAGE_ALIGN(_ramstart);
> >>      memory_end = _ramend;
> >>@@ -142,6 +141,8 @@ void __init setup_arch(char **cmdline_p)
> >>      pr_debug("MEMORY -> ROMFS=0x%p-0x%06lx MEM=0x%06lx-0x%06lx\n ",
> >>           __bss_stop, memory_start, memory_start, memory_end);
> >>+    memblock_add(memory_start, memory_end - memory_start);
> >>+
> >>      /* Keep a copy of command line */
> >>      *cmdline_p = &command_line[0];
> >>      memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
> >>@@ -158,23 +159,10 @@ void __init setup_arch(char **cmdline_p)
> >>      min_low_pfn = PFN_DOWN(memory_start);
> >>      max_pfn = max_low_pfn = PFN_DOWN(memory_end);
> >>-    bootmap_size = init_bootmem_node(
> >>-            NODE_DATA(0),
> >>-            min_low_pfn,        /* map goes here */
> >>-            PFN_DOWN(PAGE_OFFSET),
> >>-            max_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 :-)
> >>-     */
> >>-    free_bootmem(memory_start, memory_end - memory_start);
> >>-    reserve_bootmem(memory_start, bootmap_size, BOOTMEM_DEFAULT);
> >>-
> >>  #if defined(CONFIG_UBOOT) && defined(CONFIG_BLK_DEV_INITRD)
> >>      if ((initrd_start > 0) && (initrd_start < initrd_end) &&
> >>              (initrd_end < memory_end))
> >>-        reserve_bootmem(initrd_start, initrd_end - initrd_start,
> >>-                 BOOTMEM_DEFAULT);
> >>+        memblock_reserve(initrd_start, initrd_end - initrd_start);
> >>  #endif /* if defined(CONFIG_BLK_DEV_INITRD) */
> >>      /*
> >>diff --git a/arch/m68k/mm/init.c b/arch/m68k/mm/init.c
> >>index 8827b7f..38e2b27 100644
> >>--- a/arch/m68k/mm/init.c
> >>+++ b/arch/m68k/mm/init.c
> >>@@ -71,7 +71,6 @@ void __init m68k_setup_node(int node)
> >>          pg_data_table[i] = pg_data_map + node;
> >>      }
> >>  #endif
> >>-    pg_data_map[node].bdata = bootmem_node_data + node;
> >>      node_set_online(node);
> >>  }
> >>diff --git a/arch/m68k/mm/mcfmmu.c b/arch/m68k/mm/mcfmmu.c
> >>index 2925d79..e9e60e1 100644
> >>--- a/arch/m68k/mm/mcfmmu.c
> >>+++ b/arch/m68k/mm/mcfmmu.c
> >>@@ -14,6 +14,7 @@
> >>  #include <linux/init.h>
> >>  #include <linux/string.h>
> >>  #include <linux/bootmem.h>
> >>+#include <linux/memblock.h>
> >>  #include <asm/setup.h>
> >>  #include <asm/page.h>
> >>@@ -160,6 +161,8 @@ void __init cf_bootmem_alloc(void)
> >>      m68k_memory[0].addr = _rambase;
> >>      m68k_memory[0].size = _ramend - _rambase;
> >>+    memblock_add(m68k_memory[0].addr, m68k_memory[0].size);
> >>+
> >>      /* compute total pages in system */
> >>      num_pages = PFN_DOWN(_ramend - _rambase);
> >>@@ -170,14 +173,14 @@ void __init cf_bootmem_alloc(void)
> >>      max_pfn = max_low_pfn = PFN_DOWN(_ramend);
> >>      high_memory = (void *)_ramend;
> >>+    /* Reserve kernel text/data/bss */
> >>+    memblock_reserve(memstart, _ramend - memstart);
> >>+
> >>      m68k_virt_to_node_shift = fls(_ramend - 1) - 6;
> >>      module_fixup(NULL, __start_fixup, __stop_fixup);
> >>-    /* setup bootmem data */
> >>+    /* setup node data */
> >>      m68k_setup_node(0);
> >>-    memstart += init_bootmem_node(NODE_DATA(0), start_pfn,
> >>-        min_low_pfn, max_low_pfn);
> >>-    free_bootmem_node(NODE_DATA(0), memstart, _ramend - memstart);
> >>  }
> >>  /*
> >>diff --git a/arch/m68k/mm/motorola.c b/arch/m68k/mm/motorola.c
> >>index e490ecc..4e17ecb 100644
> >>--- a/arch/m68k/mm/motorola.c
> >>+++ b/arch/m68k/mm/motorola.c
> >>@@ -19,6 +19,7 @@
> >>  #include <linux/types.h>
> >>  #include <linux/init.h>
> >>  #include <linux/bootmem.h>
> >>+#include <linux/memblock.h>
> >>  #include <linux/gfp.h>
> >>  #include <asm/setup.h>
> >>@@ -208,7 +209,7 @@ void __init paging_init(void)
> >>  {
> >>      unsigned long zones_size[MAX_NR_ZONES] = { 0, };
> >>      unsigned long min_addr, max_addr;
> >>-    unsigned long addr, size, end;
> >>+    unsigned long addr;
> >>      int i;
> >>  #ifdef DEBUG
> >>@@ -253,34 +254,20 @@ void __init paging_init(void)
> >>      min_low_pfn = availmem >> PAGE_SHIFT;
> >>      max_pfn = max_low_pfn = max_addr >> PAGE_SHIFT;
> >>-    for (i = 0; i < m68k_num_memory; i++) {
> >>-        addr = m68k_memory[i].addr;
> >>-        end = addr + m68k_memory[i].size;
> >>-        m68k_setup_node(i);
> >>-        availmem = PAGE_ALIGN(availmem);
> >>-        availmem += init_bootmem_node(NODE_DATA(i),
> >>-                          availmem >> PAGE_SHIFT,
> >>-                          addr >> PAGE_SHIFT,
> >>-                          end >> PAGE_SHIFT);
> >>-    }
> >>+    /* Reserve kernel text/data/bss and the memory allocated in head.S */
> >>+    memblock_reserve(m68k_memory[0].addr, availmem - m68k_memory[0].addr);
> >>      /*
> >>       * Map the physical memory available into the kernel virtual
> >>-     * address space. First initialize the bootmem allocator with
> >>-     * the memory we already mapped, so map_node() has something
> >>-     * to allocate.
> >>+     * address space. Make sure memblock will not try to allocate
> >>+     * pages beyond the memory we already mapped in head.S
> >>       */
> >>-    addr = m68k_memory[0].addr;
> >>-    size = m68k_memory[0].size;
> >>-    free_bootmem_node(NODE_DATA(0), availmem,
> >>-              min(m68k_init_mapped_size, size) - (availmem - addr));
> >>-    map_node(0);
> >>-    if (size > m68k_init_mapped_size)
> >>-        free_bootmem_node(NODE_DATA(0), addr + m68k_init_mapped_size,
> >>-                  size - m68k_init_mapped_size);
> >>-
> >>-    for (i = 1; i < m68k_num_memory; i++)
> >>+    memblock_set_bottom_up(true);
> >>+
> >>+    for (i = 0; i < m68k_num_memory; i++) {
> >>+        m68k_setup_node(i);
> >>          map_node(i);
> >>+    }
> >>      flush_tlb_all();
> >>diff --git a/arch/m68k/sun3/config.c b/arch/m68k/sun3/config.c
> >>index 1d28d38..79a2bb8 100644
> >>--- a/arch/m68k/sun3/config.c
> >>+++ b/arch/m68k/sun3/config.c
> >>@@ -123,10 +123,6 @@ static void __init sun3_bootmem_alloc(unsigned long memory_start,
> >>      availmem = memory_start;
> >>      m68k_setup_node(0);
> >>-    availmem += init_bootmem(start_page, num_pages);
> >>-    availmem = (availmem + (PAGE_SIZE-1)) & PAGE_MASK;
> >>-
> >>-    free_bootmem(__pa(availmem), memory_end - (availmem));
> >>  }
> >>
> >-- 
> >To unsubscribe from this list: send the line "unsubscribe linux-m68k" in
> >the body of a message to majordomo@vger.kernel.org
> >More majordomo info at  http://vger.kernel.org/majordomo-info.html
> >
> 

-- 
Sincerely yours,
Mike.


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/3] m68k: switch to MEMBLOCK + NO_BOOTMEM
  2018-07-04  4:22       ` Mike Rapoport
@ 2018-07-04  4:39         ` Greg Ungerer
  2018-07-04  4:50           ` Mike Rapoport
  0 siblings, 1 reply; 17+ messages in thread
From: Greg Ungerer @ 2018-07-04  4:39 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Geert Uytterhoeven, Sam Creasey, Michal Hocko, linux-m68k,
	linux-mm, linux-kernel

Hi Mike,

On 04/07/18 14:22, Mike Rapoport wrote:
> On Wed, Jul 04, 2018 at 12:02:52PM +1000, Greg Ungerer wrote:
>> On 04/07/18 11:39, Greg Ungerer wrote:
>>> On 03/07/18 20:29, Mike Rapoport wrote:
>>>> In m68k the physical memory is described by [memory_start, memory_end] for
>>>> !MMU variant and by m68k_memory array of memory ranges for the MMU version.
>>>> This information is directly used to register the physical memory with
>>>> memblock.
>>>>
>>>> The reserve_bootmem() calls are replaced with memblock_reserve() and the
>>>> bootmap bitmap allocation is simply dropped.
>>>>
>>>> Since the MMU variant creates early mappings only for the small part of the
>>>> memory we force bottom-up allocations in memblock because otherwise we will
>>>> attempt to access memory that not yet mapped
>>>>
>>>> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
>>>
>>> This builds cleanly for me with a m5475_defconfig, but it fails
>>> to boot on real hardware. No console, no nothing on startup.
>>> I haven't debugged any further yet.
>>>
>>> The M5475 is a ColdFire with MMU enabled target.
>>
>> With some early serial debug trace I see:
>>
>> Linux version 4.18.0-rc3-00003-g109f5e551b18-dirty (gerg@goober) (gcc version 5.4.0 (GCC)) #5 Wed Jul 4 12:00:03 AEST 2018
>> On node 0 totalpages: 4096
>>    DMA zone: 18 pages used for memmap
>>    DMA zone: 0 pages reserved
>>    DMA zone: 4096 pages, LIFO batch:0
>> pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
>> pcpu-alloc: [0] 0
>> Built 1 zonelists, mobility grouping off.  Total pages: 4078
>> Kernel command line: root=/dev/mtdblock0
>> Dentry cache hash table entries: 4096 (order: 1, 16384 bytes)
>> Inode-cache hash table entries: 2048 (order: 0, 8192 bytes)
>> Sorting __ex_table...
>> Memory: 3032K/32768K available (1489K kernel code, 96K rwdata, 240K rodata, 56K init, 77K bss, 29736K reserved, 0K cma-reserved)
>                                                                                                   ^^^^^^
> It seems I was over enthusiastic when I reserved the memory for the kernel.
> Can you please try with the below patch:
> 
> diff --git a/arch/m68k/mm/mcfmmu.c b/arch/m68k/mm/mcfmmu.c
> index e9e60e1..18c7bf6 100644
> --- a/arch/m68k/mm/mcfmmu.c
> +++ b/arch/m68k/mm/mcfmmu.c
> @@ -174,7 +174,7 @@ void __init cf_bootmem_alloc(void)
>   	high_memory = (void *)_ramend;
>   
>   	/* Reserve kernel text/data/bss */
> -	memblock_reserve(memstart, _ramend - memstart);
> +	memblock_reserve(memstart, memstart - _rambase);
>   
>   	m68k_virt_to_node_shift = fls(_ramend - 1) - 6;
>   	module_fixup(NULL, __start_fixup, __stop_fixup);
> diff --git a/mm/memblock.c b/mm/memblock.c
> index 03d48d8..98661be 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -54,7 +54,7 @@ struct memblock memblock __initdata_memblock = {
>   	.current_limit		= MEMBLOCK_ALLOC_ANYWHERE,
>   };
>   
> -int memblock_debug __initdata_memblock;
> +int memblock_debug __initdata_memblock = 1;
>   static bool system_has_some_mirror __initdata_memblock = false;
>   static int memblock_can_resize __initdata_memblock;
>   static int memblock_memory_in_slab __initdata_memblock = 0;
> 
> 
> The memblock hunk is needed to see early memblock debug messages as all the
> setup happens before parsing of the command line.

Ok, that works, boots all the way up now.

Linux version 4.18.0-rc3-00003-g109f5e551b18-dirty (gerg@goober) (gcc version 5.4.0 (GCC)) #7 Wed Jul 4 14:34:48 AEST 2018
memblock_add: [0x00000000-0x01ffffff] 0x001ebaa0
memblock_reserve: [0x00332000-0x00663fff] 0x001ebafa
memblock_reserve: [0x01ffe000-0x01ffffff] 0x001efd38
memblock_reserve: [0x01ff8000-0x01ffdfff] 0x001efd38
memblock_virt_alloc_try_nid_nopanic: 147456 bytes align=0x0 nid=0 from=0x0 max_addr=0x0 0x00190dea
memblock_reserve: [0x01fd4000-0x01ff7fff] 0x001f0466
memblock_virt_alloc_try_nid_nopanic: 4 bytes align=0x0 nid=0 from=0x0 max_addr=0x0 0x001ee234
memblock_reserve: [0x01fd3ff0-0x01fd3ff3] 0x001f0466
memblock_virt_alloc_try_nid: 20 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ea488
memblock_reserve: [0x01fd3fd0-0x01fd3fe3] 0x001f0466
memblock_virt_alloc_try_nid: 20 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ea4a8
memblock_reserve: [0x01fd3fb0-0x01fd3fc3] 0x001f0466
memblock_virt_alloc_try_nid: 20 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ea4c0
memblock_reserve: [0x01fd3f90-0x01fd3fa3] 0x001f0466
memblock_virt_alloc_try_nid_nopanic: 8192 bytes align=0x2000 nid=-1 from=0x0 max_addr=0x0 0x001eef30
memblock_reserve: [0x01fd0000-0x01fd1fff] 0x001f0466
memblock_virt_alloc_try_nid_nopanic: 32768 bytes align=0x2000 nid=-1 from=0x0 max_addr=0x0 0x001ef5d6
memblock_reserve: [0x01fc8000-0x01fcffff] 0x001f0466
memblock_virt_alloc_try_nid: 4 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ef2ac
memblock_reserve: [0x01fd3f80-0x01fd3f83] 0x001f0466
memblock_virt_alloc_try_nid: 4 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ef2c2
memblock_reserve: [0x01fd3f70-0x01fd3f73] 0x001f0466
memblock_virt_alloc_try_nid: 4 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ef2d6
memblock_reserve: [0x01fd3f60-0x01fd3f63] 0x001f0466
memblock_virt_alloc_try_nid: 4 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ef2e6
memblock_reserve: [0x01fd3f50-0x01fd3f53] 0x001f0466
memblock_virt_alloc_try_nid: 120 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ef506
memblock_reserve: [0x01fd3ed0-0x01fd3f47] 0x001f0466
memblock_virt_alloc_try_nid: 67 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001eece0
memblock_reserve: [0x01fd3e80-0x01fd3ec2] 0x001f0466
memblock_virt_alloc_try_nid: 1024 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001eed0e
memblock_reserve: [0x01fd3a80-0x01fd3e7f] 0x001f0466
memblock_virt_alloc_try_nid: 1028 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001eed2c
memblock_reserve: [0x01fd3670-0x01fd3a73] 0x001f0466
memblock_virt_alloc_try_nid: 80 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001eed4e
memblock_reserve: [0x01fd3620-0x01fd366f] 0x001f0466
__memblock_free_early: [0x00000001fd0000-0x00000001fd1fff] 0x001eef80
Built 1 zonelists, mobility grouping off.  Total pages: 4078
Kernel command line: root=/dev/mtdblock0
memblock_virt_alloc_try_nid_nopanic: 16384 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ee828
memblock_reserve: [0x01fc4000-0x01fc7fff] 0x001f0466
Dentry cache hash table entries: 4096 (order: 1, 16384 bytes)
memblock_virt_alloc_try_nid_nopanic: 8192 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ee828
memblock_reserve: [0x01fd1620-0x01fd361f] 0x001f0466
Inode-cache hash table entries: 2048 (order: 0, 8192 bytes)
Sorting __ex_table...
Memory: 29256K/32768K available (1489K kernel code, 96K rwdata, 240K rodata, 56K init, 77K bss, 3512K reserved, 0K cma-reserved)
SLUB: HWalign=16, Order=0-3, MinObjects=0, CPUs=1, Nodes=8
NR_IRQS: 256
clocksource: slt: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 14370379300 ns
Calibrating delay loop... 264.19 BogoMIPS (lpj=1320960)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 2048 (order: 0, 8192 bytes)
Mountpoint-cache hash table entries: 2048 (order: 0, 8192 bytes)
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
ColdFire: PCI bus initialization...
Coldfire: PCI IO/config window mapped to 0xe0000000
PCI host bridge to bus 0000:00
pci_bus 0000:00: root bus resource [io  0x0000-0xffff]
pci_bus 0000:00: root bus resource [mem 0x00000000-0xffffffff]
pci_bus 0000:00: root bus resource [bus 00-ff]
pci 0000:00:14.0: BAR 2: assigned [mem 0xf0000000-0xf00fffff]
pci 0000:00:14.0: BAR 6: assigned [mem 0xf0100000-0xf01fffff pref]
pci 0000:00:14.0: BAR 0: assigned [mem 0xf0200000-0xf0200fff]
pci 0000:00:14.0: BAR 1: assigned [io  0x0400-0x043f]
vgaarb: loaded
clocksource: Switched to clocksource slt
workingset: timestamp_bits=27 max_order=12 bucket_order=0
romfs: ROMFS MTD (C) 2007 Red Hat, Inc.
io scheduler noop registered (default)
io scheduler mq-deadline registered
io scheduler kyber registered
ColdFire internal UART serial driver
mcfuart.0: ttyS0 at MMIO 0xff008600 (irq = 99, base_baud = 8312500) is a ColdFire UART
console [ttyS0] enabled
mcfuart.0: ttyS1 at MMIO 0xff008700 (irq = 98, base_baud = 8312500) is a ColdFire UART
mcfuart.0: ttyS2 at MMIO 0xff008800 (irq = 97, base_baud = 8312500) is a ColdFire UART
mcfuart.0: ttyS3 at MMIO 0xff008900 (irq = 96, base_baud = 8312500) is a ColdFire UART
brd: module loaded
uclinux[mtd]: probe address=0x20bb84 size=0x126000
Creating 1 MTD partitions on "ram":
0x000000000000-0x000000126000 : "ROMfs"
random: get_random_bytes called from 0x000283b6 with crng_init=0
VFS: Mounted root (romfs filesystem) readonly on device 31:0.
Freeing unused kernel memory: 56K
This architecture does not have kernel memory protection.

Regards
Greg


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 3/3] m68k: switch to MEMBLOCK + NO_BOOTMEM
  2018-07-04  4:39         ` Greg Ungerer
@ 2018-07-04  4:50           ` Mike Rapoport
  0 siblings, 0 replies; 17+ messages in thread
From: Mike Rapoport @ 2018-07-04  4:50 UTC (permalink / raw)
  To: Greg Ungerer
  Cc: Geert Uytterhoeven, Sam Creasey, Michal Hocko, linux-m68k,
	linux-mm, linux-kernel

Hi Greg,

On Wed, Jul 04, 2018 at 02:39:05PM +1000, Greg Ungerer wrote:
> Hi Mike,
> 
> On 04/07/18 14:22, Mike Rapoport wrote:
> >On Wed, Jul 04, 2018 at 12:02:52PM +1000, Greg Ungerer wrote:
> >>On 04/07/18 11:39, Greg Ungerer wrote:
> >>>On 03/07/18 20:29, Mike Rapoport wrote:
> >>>>In m68k the physical memory is described by [memory_start, memory_end] for
> >>>>!MMU variant and by m68k_memory array of memory ranges for the MMU version.
> >>>>This information is directly used to register the physical memory with
> >>>>memblock.
> >>>>
> >>>>The reserve_bootmem() calls are replaced with memblock_reserve() and the
> >>>>bootmap bitmap allocation is simply dropped.
> >>>>
> >>>>Since the MMU variant creates early mappings only for the small part of the
> >>>>memory we force bottom-up allocations in memblock because otherwise we will
> >>>>attempt to access memory that not yet mapped
> >>>>
> >>>>Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> >>>
> >>>This builds cleanly for me with a m5475_defconfig, but it fails
> >>>to boot on real hardware. No console, no nothing on startup.
> >>>I haven't debugged any further yet.
> >>>
> >>>The M5475 is a ColdFire with MMU enabled target.
> >>
> >>With some early serial debug trace I see:
> >>
> >>Linux version 4.18.0-rc3-00003-g109f5e551b18-dirty (gerg@goober) (gcc version 5.4.0 (GCC)) #5 Wed Jul 4 12:00:03 AEST 2018
> >>On node 0 totalpages: 4096
> >>   DMA zone: 18 pages used for memmap
> >>   DMA zone: 0 pages reserved
> >>   DMA zone: 4096 pages, LIFO batch:0
> >>pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
> >>pcpu-alloc: [0] 0
> >>Built 1 zonelists, mobility grouping off.  Total pages: 4078
> >>Kernel command line: root=/dev/mtdblock0
> >>Dentry cache hash table entries: 4096 (order: 1, 16384 bytes)
> >>Inode-cache hash table entries: 2048 (order: 0, 8192 bytes)
> >>Sorting __ex_table...
> >>Memory: 3032K/32768K available (1489K kernel code, 96K rwdata, 240K rodata, 56K init, 77K bss, 29736K reserved, 0K cma-reserved)
> >                                                                                                  ^^^^^^
> >It seems I was over enthusiastic when I reserved the memory for the kernel.
> >Can you please try with the below patch:
> >
> >diff --git a/arch/m68k/mm/mcfmmu.c b/arch/m68k/mm/mcfmmu.c
> >index e9e60e1..18c7bf6 100644
> >--- a/arch/m68k/mm/mcfmmu.c
> >+++ b/arch/m68k/mm/mcfmmu.c
> >@@ -174,7 +174,7 @@ void __init cf_bootmem_alloc(void)
> >  	high_memory = (void *)_ramend;
> >  	/* Reserve kernel text/data/bss */
> >-	memblock_reserve(memstart, _ramend - memstart);
> >+	memblock_reserve(memstart, memstart - _rambase);
> >  	m68k_virt_to_node_shift = fls(_ramend - 1) - 6;
> >  	module_fixup(NULL, __start_fixup, __stop_fixup);
> >diff --git a/mm/memblock.c b/mm/memblock.c
> >index 03d48d8..98661be 100644
> >--- a/mm/memblock.c
> >+++ b/mm/memblock.c
> >@@ -54,7 +54,7 @@ struct memblock memblock __initdata_memblock = {
> >  	.current_limit		= MEMBLOCK_ALLOC_ANYWHERE,
> >  };
> >-int memblock_debug __initdata_memblock;
> >+int memblock_debug __initdata_memblock = 1;
> >  static bool system_has_some_mirror __initdata_memblock = false;
> >  static int memblock_can_resize __initdata_memblock;
> >  static int memblock_memory_in_slab __initdata_memblock = 0;
> >
> >
> >The memblock hunk is needed to see early memblock debug messages as all the
> >setup happens before parsing of the command line.
> 
> Ok, that works, boots all the way up now.

Thanks for testing. 
I'll send v2 later on today.
 
> Linux version 4.18.0-rc3-00003-g109f5e551b18-dirty (gerg@goober) (gcc version 5.4.0 (GCC)) #7 Wed Jul 4 14:34:48 AEST 2018
> memblock_add: [0x00000000-0x01ffffff] 0x001ebaa0
> memblock_reserve: [0x00332000-0x00663fff] 0x001ebafa
> memblock_reserve: [0x01ffe000-0x01ffffff] 0x001efd38
> memblock_reserve: [0x01ff8000-0x01ffdfff] 0x001efd38
> memblock_virt_alloc_try_nid_nopanic: 147456 bytes align=0x0 nid=0 from=0x0 max_addr=0x0 0x00190dea
> memblock_reserve: [0x01fd4000-0x01ff7fff] 0x001f0466
> memblock_virt_alloc_try_nid_nopanic: 4 bytes align=0x0 nid=0 from=0x0 max_addr=0x0 0x001ee234
> memblock_reserve: [0x01fd3ff0-0x01fd3ff3] 0x001f0466
> memblock_virt_alloc_try_nid: 20 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ea488
> memblock_reserve: [0x01fd3fd0-0x01fd3fe3] 0x001f0466
> memblock_virt_alloc_try_nid: 20 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ea4a8
> memblock_reserve: [0x01fd3fb0-0x01fd3fc3] 0x001f0466
> memblock_virt_alloc_try_nid: 20 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ea4c0
> memblock_reserve: [0x01fd3f90-0x01fd3fa3] 0x001f0466
> memblock_virt_alloc_try_nid_nopanic: 8192 bytes align=0x2000 nid=-1 from=0x0 max_addr=0x0 0x001eef30
> memblock_reserve: [0x01fd0000-0x01fd1fff] 0x001f0466
> memblock_virt_alloc_try_nid_nopanic: 32768 bytes align=0x2000 nid=-1 from=0x0 max_addr=0x0 0x001ef5d6
> memblock_reserve: [0x01fc8000-0x01fcffff] 0x001f0466
> memblock_virt_alloc_try_nid: 4 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ef2ac
> memblock_reserve: [0x01fd3f80-0x01fd3f83] 0x001f0466
> memblock_virt_alloc_try_nid: 4 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ef2c2
> memblock_reserve: [0x01fd3f70-0x01fd3f73] 0x001f0466
> memblock_virt_alloc_try_nid: 4 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ef2d6
> memblock_reserve: [0x01fd3f60-0x01fd3f63] 0x001f0466
> memblock_virt_alloc_try_nid: 4 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ef2e6
> memblock_reserve: [0x01fd3f50-0x01fd3f53] 0x001f0466
> memblock_virt_alloc_try_nid: 120 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ef506
> memblock_reserve: [0x01fd3ed0-0x01fd3f47] 0x001f0466
> memblock_virt_alloc_try_nid: 67 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001eece0
> memblock_reserve: [0x01fd3e80-0x01fd3ec2] 0x001f0466
> memblock_virt_alloc_try_nid: 1024 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001eed0e
> memblock_reserve: [0x01fd3a80-0x01fd3e7f] 0x001f0466
> memblock_virt_alloc_try_nid: 1028 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001eed2c
> memblock_reserve: [0x01fd3670-0x01fd3a73] 0x001f0466
> memblock_virt_alloc_try_nid: 80 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001eed4e
> memblock_reserve: [0x01fd3620-0x01fd366f] 0x001f0466
> __memblock_free_early: [0x00000001fd0000-0x00000001fd1fff] 0x001eef80
> Built 1 zonelists, mobility grouping off.  Total pages: 4078
> Kernel command line: root=/dev/mtdblock0
> memblock_virt_alloc_try_nid_nopanic: 16384 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ee828
> memblock_reserve: [0x01fc4000-0x01fc7fff] 0x001f0466
> Dentry cache hash table entries: 4096 (order: 1, 16384 bytes)
> memblock_virt_alloc_try_nid_nopanic: 8192 bytes align=0x0 nid=-1 from=0x0 max_addr=0x0 0x001ee828
> memblock_reserve: [0x01fd1620-0x01fd361f] 0x001f0466
> Inode-cache hash table entries: 2048 (order: 0, 8192 bytes)
> Sorting __ex_table...
> Memory: 29256K/32768K available (1489K kernel code, 96K rwdata, 240K rodata, 56K init, 77K bss, 3512K reserved, 0K cma-reserved)
> SLUB: HWalign=16, Order=0-3, MinObjects=0, CPUs=1, Nodes=8
> NR_IRQS: 256
> clocksource: slt: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 14370379300 ns
> Calibrating delay loop... 264.19 BogoMIPS (lpj=1320960)
> pid_max: default: 32768 minimum: 301
> Mount-cache hash table entries: 2048 (order: 0, 8192 bytes)
> Mountpoint-cache hash table entries: 2048 (order: 0, 8192 bytes)
> clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
> ColdFire: PCI bus initialization...
> Coldfire: PCI IO/config window mapped to 0xe0000000
> PCI host bridge to bus 0000:00
> pci_bus 0000:00: root bus resource [io  0x0000-0xffff]
> pci_bus 0000:00: root bus resource [mem 0x00000000-0xffffffff]
> pci_bus 0000:00: root bus resource [bus 00-ff]
> pci 0000:00:14.0: BAR 2: assigned [mem 0xf0000000-0xf00fffff]
> pci 0000:00:14.0: BAR 6: assigned [mem 0xf0100000-0xf01fffff pref]
> pci 0000:00:14.0: BAR 0: assigned [mem 0xf0200000-0xf0200fff]
> pci 0000:00:14.0: BAR 1: assigned [io  0x0400-0x043f]
> vgaarb: loaded
> clocksource: Switched to clocksource slt
> workingset: timestamp_bits=27 max_order=12 bucket_order=0
> romfs: ROMFS MTD (C) 2007 Red Hat, Inc.
> io scheduler noop registered (default)
> io scheduler mq-deadline registered
> io scheduler kyber registered
> ColdFire internal UART serial driver
> mcfuart.0: ttyS0 at MMIO 0xff008600 (irq = 99, base_baud = 8312500) is a ColdFire UART
> console [ttyS0] enabled
> mcfuart.0: ttyS1 at MMIO 0xff008700 (irq = 98, base_baud = 8312500) is a ColdFire UART
> mcfuart.0: ttyS2 at MMIO 0xff008800 (irq = 97, base_baud = 8312500) is a ColdFire UART
> mcfuart.0: ttyS3 at MMIO 0xff008900 (irq = 96, base_baud = 8312500) is a ColdFire UART
> brd: module loaded
> uclinux[mtd]: probe address=0x20bb84 size=0x126000
> Creating 1 MTD partitions on "ram":
> 0x000000000000-0x000000126000 : "ROMfs"
> random: get_random_bytes called from 0x000283b6 with crng_init=0
> VFS: Mounted root (romfs filesystem) readonly on device 31:0.
> Freeing unused kernel memory: 56K
> This architecture does not have kernel memory protection.
> 
> Regards
> Greg
> 

-- 
Sincerely yours,
Mike.


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2018-07-04  4:51 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-03 10:29 [PATCH 0/3] m68k: switch to MEMBLOCK + NO_BOOTMEM Mike Rapoport
2018-07-03 10:29 ` [PATCH 1/3] m68k/bitops: convert __ffs to match generic declaration Mike Rapoport
2018-07-03 10:29 ` [PATCH 2/3] m68k/page_no.h: force __va argument to be unsigned long Mike Rapoport
2018-07-03 14:20   ` Michal Hocko
2018-07-03 15:03     ` Mike Rapoport
2018-07-03 15:05       ` Matthew Wilcox
2018-07-03 15:14         ` Michal Hocko
2018-07-03 15:39           ` Mike Rapoport
2018-07-03 15:47           ` Mike Rapoport
2018-07-03 15:55             ` Michal Hocko
2018-07-03 15:30         ` Mike Rapoport
2018-07-03 10:29 ` [PATCH 3/3] m68k: switch to MEMBLOCK + NO_BOOTMEM Mike Rapoport
2018-07-04  1:39   ` Greg Ungerer
2018-07-04  2:02     ` Greg Ungerer
2018-07-04  4:22       ` Mike Rapoport
2018-07-04  4:39         ` Greg Ungerer
2018-07-04  4:50           ` Mike Rapoport

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).