diff mbox

mips: switch to NO_BOOTMEM

Message ID 1531727262-11520-1-git-send-email-rppt@linux.vnet.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mike Rapoport July 16, 2018, 7:47 a.m. UTC
MIPS already has memblock support and all the memory is already registered
with it.

This patch replaces bootmem memory reservations with memblock ones and
removes the bootmem initialization.

Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
---
The "generic" part was tested with qemu-system-mipsel (both 32 and 64
bits).
loongson3, sgi-ip27 and allyesconfig are build tested only.

 arch/mips/Kconfig                      |  1 +
 arch/mips/kernel/setup.c               | 89 +++++-----------------------------
 arch/mips/loongson64/loongson-3/numa.c | 34 ++++++-------
 arch/mips/sgi-ip27/ip27-memory.c       | 11 ++---
 4 files changed, 33 insertions(+), 102 deletions(-)

Comments

Mike Rapoport July 26, 2018, 7:03 a.m. UTC | #1
Any comments on this?

On Mon, Jul 16, 2018 at 10:47:42AM +0300, Mike Rapoport wrote:
> MIPS already has memblock support and all the memory is already registered
> with it.
> 
> This patch replaces bootmem memory reservations with memblock ones and
> removes the bootmem initialization.
> 
> Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
> ---
> The "generic" part was tested with qemu-system-mipsel (both 32 and 64
> bits).
> loongson3, sgi-ip27 and allyesconfig are build tested only.
> 
>  arch/mips/Kconfig                      |  1 +
>  arch/mips/kernel/setup.c               | 89 +++++-----------------------------
>  arch/mips/loongson64/loongson-3/numa.c | 34 ++++++-------
>  arch/mips/sgi-ip27/ip27-memory.c       | 11 ++---
>  4 files changed, 33 insertions(+), 102 deletions(-)
> 
> diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
> index 08c10c5..bd15bad 100644
> --- a/arch/mips/Kconfig
> +++ b/arch/mips/Kconfig
> @@ -76,6 +76,7 @@ config MIPS
>  	select RTC_LIB if !MACH_LOONGSON64
>  	select SYSCTL_EXCEPTION_TRACE
>  	select VIRT_TO_BUS
> +	select NO_BOOTMEM
> 
>  menu "Machine selection"
> 
> diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
> index 2c96c0c..10f46aa 100644
> --- a/arch/mips/kernel/setup.c
> +++ b/arch/mips/kernel/setup.c
> @@ -327,7 +327,7 @@ static void __init finalize_initrd(void)
> 
>  	maybe_bswap_initrd();
> 
> -	reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT);
> +	memblock_reserve(__pa(initrd_start), size);
>  	initrd_below_start_ok = 1;
> 
>  	pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n",
> @@ -364,20 +364,10 @@ static void __init bootmem_init(void)
> 
>  #else  /* !CONFIG_SGI_IP27 */
> 
> -static unsigned long __init bootmap_bytes(unsigned long pages)
> -{
> -	unsigned long bytes = DIV_ROUND_UP(pages, 8);
> -
> -	return ALIGN(bytes, sizeof(long));
> -}
> -
>  static void __init bootmem_init(void)
>  {
>  	unsigned long reserved_end;
> -	unsigned long mapstart = ~0UL;
> -	unsigned long bootmap_size;
>  	phys_addr_t ramstart = PHYS_ADDR_MAX;
> -	bool bootmap_valid = false;
>  	int i;
> 
>  	/*
> @@ -389,6 +379,8 @@ static void __init bootmem_init(void)
>  	init_initrd();
>  	reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end));
> 
> +	memblock_reserve(PHYS_OFFSET, reserved_end << PAGE_SHIFT);
> +
>  	/*
>  	 * max_low_pfn is not a number of pages. The number of pages
>  	 * of the system is given by 'max_low_pfn - min_low_pfn'.
> @@ -436,17 +428,16 @@ static void __init bootmem_init(void)
>  		if (initrd_end && end <= (unsigned long)PFN_UP(__pa(initrd_end)))
>  			continue;
>  #endif
> -		if (start >= mapstart)
> -			continue;
> -		mapstart = max(reserved_end, start);
>  	}
> 
>  	/*
>  	 * Reserve any memory between the start of RAM and PHYS_OFFSET
>  	 */
> -	if (ramstart > PHYS_OFFSET)
> +	if (ramstart > PHYS_OFFSET) {
>  		add_memory_region(PHYS_OFFSET, ramstart - PHYS_OFFSET,
>  				  BOOT_MEM_RESERVED);
> +		memblock_reserve(PHYS_OFFSET, ramstart - PHYS_OFFSET);
> +	}
> 
>  	if (min_low_pfn >= max_low_pfn)
>  		panic("Incorrect memory mapping !!!");
> @@ -472,52 +463,6 @@ static void __init bootmem_init(void)
>  		max_low_pfn = PFN_DOWN(HIGHMEM_START);
>  	}
> 
> -#ifdef CONFIG_BLK_DEV_INITRD
> -	/*
> -	 * mapstart should be after initrd_end
> -	 */
> -	if (initrd_end)
> -		mapstart = max(mapstart, (unsigned long)PFN_UP(__pa(initrd_end)));
> -#endif
> -
> -	/*
> -	 * check that mapstart doesn't overlap with any of
> -	 * memory regions that have been reserved through eg. DTB
> -	 */
> -	bootmap_size = bootmap_bytes(max_low_pfn - min_low_pfn);
> -
> -	bootmap_valid = memory_region_available(PFN_PHYS(mapstart),
> -						bootmap_size);
> -	for (i = 0; i < boot_mem_map.nr_map && !bootmap_valid; i++) {
> -		unsigned long mapstart_addr;
> -
> -		switch (boot_mem_map.map[i].type) {
> -		case BOOT_MEM_RESERVED:
> -			mapstart_addr = PFN_ALIGN(boot_mem_map.map[i].addr +
> -						boot_mem_map.map[i].size);
> -			if (PHYS_PFN(mapstart_addr) < mapstart)
> -				break;
> -
> -			bootmap_valid = memory_region_available(mapstart_addr,
> -								bootmap_size);
> -			if (bootmap_valid)
> -				mapstart = PHYS_PFN(mapstart_addr);
> -			break;
> -		default:
> -			break;
> -		}
> -	}
> -
> -	if (!bootmap_valid)
> -		panic("No memory area to place a bootmap bitmap");
> -
> -	/*
> -	 * Initialize the boot-time allocator with low memory only.
> -	 */
> -	if (bootmap_size != init_bootmem_node(NODE_DATA(0), mapstart,
> -					 min_low_pfn, max_low_pfn))
> -		panic("Unexpected memory size required for bootmap");
> -
>  	for (i = 0; i < boot_mem_map.nr_map; i++) {
>  		unsigned long start, end;
> 
> @@ -566,9 +511,9 @@ static void __init bootmem_init(void)
>  		default:
>  			/* Not usable memory */
>  			if (start > min_low_pfn && end < max_low_pfn)
> -				reserve_bootmem(boot_mem_map.map[i].addr,
> -						boot_mem_map.map[i].size,
> -						BOOTMEM_DEFAULT);
> +				memblock_reserve(boot_mem_map.map[i].addr,
> +						boot_mem_map.map[i].size);
> +
>  			continue;
>  		}
> 
> @@ -591,15 +536,9 @@ static void __init bootmem_init(void)
>  		size = end - start;
> 
>  		/* Register lowmem ranges */
> -		free_bootmem(PFN_PHYS(start), size << PAGE_SHIFT);
>  		memory_present(0, start, end);
>  	}
> 
> -	/*
> -	 * Reserve the bootmap memory.
> -	 */
> -	reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);
> -
>  #ifdef CONFIG_RELOCATABLE
>  	/*
>  	 * The kernel reserves all memory below its _end symbol as bootmem,
> @@ -901,17 +840,15 @@ static void __init arch_mem_init(char **cmdline_p)
>  	if (setup_elfcorehdr && setup_elfcorehdr_size) {
>  		printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
>  		       setup_elfcorehdr, setup_elfcorehdr_size);
> -		reserve_bootmem(setup_elfcorehdr, setup_elfcorehdr_size,
> -				BOOTMEM_DEFAULT);
> +		memblock_reserve(setup_elfcorehdr, setup_elfcorehdr_size);
>  	}
>  #endif
> 
>  	mips_parse_crashkernel();
>  #ifdef CONFIG_KEXEC
>  	if (crashk_res.start != crashk_res.end)
> -		reserve_bootmem(crashk_res.start,
> -				crashk_res.end - crashk_res.start + 1,
> -				BOOTMEM_DEFAULT);
> +		memblock_reserve(crashk_res.start,
> +				 crashk_res.end - crashk_res.start + 1);
>  #endif
>  	device_tree_init();
>  	sparse_init();
> @@ -921,7 +858,7 @@ static void __init arch_mem_init(char **cmdline_p)
>  	/* Tell bootmem about cma reserved memblock section */
>  	for_each_memblock(reserved, reg)
>  		if (reg->size != 0)
> -			reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
> +			memblock_reserve(reg->base, reg->size);
> 
>  	reserve_bootmem_region(__pa_symbol(&__nosave_begin),
>  			__pa_symbol(&__nosave_end)); /* Reserve for hibernation */
> diff --git a/arch/mips/loongson64/loongson-3/numa.c b/arch/mips/loongson64/loongson-3/numa.c
> index 9717106..c1e6ec5 100644
> --- a/arch/mips/loongson64/loongson-3/numa.c
> +++ b/arch/mips/loongson64/loongson-3/numa.c
> @@ -180,43 +180,39 @@ static void __init szmem(unsigned int node)
> 
>  static void __init node_mem_init(unsigned int node)
>  {
> -	unsigned long bootmap_size;
>  	unsigned long node_addrspace_offset;
> -	unsigned long start_pfn, end_pfn, freepfn;
> +	unsigned long start_pfn, end_pfn;
> 
>  	node_addrspace_offset = nid_to_addroffset(node);
>  	pr_info("Node%d's addrspace_offset is 0x%lx\n",
>  			node, node_addrspace_offset);
> 
>  	get_pfn_range_for_nid(node, &start_pfn, &end_pfn);
> -	freepfn = start_pfn;
> -	if (node == 0)
> -		freepfn = PFN_UP(__pa_symbol(&_end)); /* kernel end address */
> -	pr_info("Node%d: start_pfn=0x%lx, end_pfn=0x%lx, freepfn=0x%lx\n",
> -		node, start_pfn, end_pfn, freepfn);
> +	pr_info("Node%d: start_pfn=0x%lx, end_pfn=0x%lx\n",
> +		node, start_pfn, end_pfn);
> 
>  	__node_data[node] = prealloc__node_data + node;
> 
> -	NODE_DATA(node)->bdata = &bootmem_node_data[node];
>  	NODE_DATA(node)->node_start_pfn = start_pfn;
>  	NODE_DATA(node)->node_spanned_pages = end_pfn - start_pfn;
> 
> -	bootmap_size = init_bootmem_node(NODE_DATA(node), freepfn,
> -					start_pfn, end_pfn);
>  	free_bootmem_with_active_regions(node, end_pfn);
> -	if (node == 0) /* used by finalize_initrd() */
> +
> +	if (node == 0) {
> +		/* kernel end address */
> +		unsigned long kernel_end_pfn = PFN_UP(__pa_symbol(&_end));
> +
> +		/* used by finalize_initrd() */
>  		max_low_pfn = end_pfn;
> 
> -	/* This is reserved for the kernel and bdata->node_bootmem_map */
> -	reserve_bootmem_node(NODE_DATA(node), start_pfn << PAGE_SHIFT,
> -		((freepfn - start_pfn) << PAGE_SHIFT) + bootmap_size,
> -		BOOTMEM_DEFAULT);
> +		/* Reserve the kernel text/data/bss */
> +		memblock_reserve(start_pfn << PAGE_SHIFT,
> +				 ((kernel_end_pfn - start_pfn) << PAGE_SHIFT));
> 
> -	if (node == 0 && node_end_pfn(0) >= (0xffffffff >> PAGE_SHIFT)) {
>  		/* Reserve 0xfe000000~0xffffffff for RS780E integrated GPU */
> -		reserve_bootmem_node(NODE_DATA(node),
> -				(node_addrspace_offset | 0xfe000000),
> -				32 << 20, BOOTMEM_DEFAULT);
> +		if (node_end_pfn(0) >= (0xffffffff >> PAGE_SHIFT))
> +			memblock_reserve((node_addrspace_offset | 0xfe000000),
> +					 32 << 20);
>  	}
> 
>  	sparse_memory_present_with_active_regions(node);
> diff --git a/arch/mips/sgi-ip27/ip27-memory.c b/arch/mips/sgi-ip27/ip27-memory.c
> index 59133d0a..6f7bef0 100644
> --- a/arch/mips/sgi-ip27/ip27-memory.c
> +++ b/arch/mips/sgi-ip27/ip27-memory.c
> @@ -389,7 +389,6 @@ static void __init node_mem_init(cnodeid_t node)
>  {
>  	unsigned long slot_firstpfn = slot_getbasepfn(node, 0);
>  	unsigned long slot_freepfn = node_getfirstfree(node);
> -	unsigned long bootmap_size;
>  	unsigned long start_pfn, end_pfn;
> 
>  	get_pfn_range_for_nid(node, &start_pfn, &end_pfn);
> @@ -400,7 +399,6 @@ static void __init node_mem_init(cnodeid_t node)
>  	__node_data[node] = __va(slot_freepfn << PAGE_SHIFT);
>  	memset(__node_data[node], 0, PAGE_SIZE);
> 
> -	NODE_DATA(node)->bdata = &bootmem_node_data[node];
>  	NODE_DATA(node)->node_start_pfn = start_pfn;
>  	NODE_DATA(node)->node_spanned_pages = end_pfn - start_pfn;
> 
> @@ -409,12 +407,11 @@ static void __init node_mem_init(cnodeid_t node)
>  	slot_freepfn += PFN_UP(sizeof(struct pglist_data) +
>  			       sizeof(struct hub_data));
> 
> -	bootmap_size = init_bootmem_node(NODE_DATA(node), slot_freepfn,
> -					start_pfn, end_pfn);
>  	free_bootmem_with_active_regions(node, end_pfn);
> -	reserve_bootmem_node(NODE_DATA(node), slot_firstpfn << PAGE_SHIFT,
> -		((slot_freepfn - slot_firstpfn) << PAGE_SHIFT) + bootmap_size,
> -		BOOTMEM_DEFAULT);
> +
> +	memblock_reserve(slot_firstpfn << PAGE_SHIFT,
> +			 ((slot_freepfn - slot_firstpfn) << PAGE_SHIFT));
> +
>  	sparse_memory_present_with_active_regions(node);
>  }
> 
> -- 
> 2.7.4
>
Paul Burton July 26, 2018, 5:20 p.m. UTC | #2
Hi Mike,

On Thu, Jul 26, 2018 at 10:03:56AM +0300, Mike Rapoport wrote:
> Any comments on this?

I haven't looked at this in detail yet, but there was a much larger
series submitted to accomplish this not too long ago, which needed
another revision:

    https://patchwork.linux-mips.org/project/linux-mips/list/?series=787&state=*

Given that, I'd be (pleasantly) surprised if this one smaller patch is
enough.

Thanks,
    Paul
Serge Semin July 26, 2018, 7:55 p.m. UTC | #3
Hello, folks
Regarding the no_bootmem patchset I've sent earlier.
I'm terribly sorry about huge delay with response. I got sucked in a new
project, so just didn't have a time to proceed with the series, answer to
the questions and resend the set.
If it is still relevant and needed for community, I can get back to the
series on the next week, answer to the Mett's questions (sorry, man, for
doing it so long), rebase it on top of the kernel 4.18 and resend the new
version. We also can try to combine it with this patch, if it is found
convenient.

Regards,
-Sergey


On Thu, 26 Jul 2018, 20:20 Paul Burton, <paul.burton@mips.com> wrote:

> Hi Mike,
>
> On Thu, Jul 26, 2018 at 10:03:56AM +0300, Mike Rapoport wrote:
> > Any comments on this?
>
> I haven't looked at this in detail yet, but there was a much larger
> series submitted to accomplish this not too long ago, which needed
> another revision:
>
>
> https://patchwork.linux-mips.org/project/linux-mips/list/?series=787&state=*
>
> Given that, I'd be (pleasantly) surprised if this one smaller patch is
> enough.
>
> Thanks,
>     Paul
>
<div dir="auto">Hello, folks<div dir="auto">Regarding the no_bootmem patchset I&#39;ve sent earlier.</div><div dir="auto">I&#39;m terribly sorry about huge delay with response. I got sucked in a new project, so just didn&#39;t have a time to proceed with the series, answer to the questions and resend the set.</div><div dir="auto">If it is still relevant and needed for community, I can get back to the series on the next week, answer to the Mett&#39;s questions (sorry, man, for doing it so long), rebase it on top of the kernel 4.18 and resend the new version. We also can try to combine it with this patch, if it is found convenient.</div><div dir="auto"><br></div><div dir="auto">Regards,</div><div dir="auto">-Sergey</div><div dir="auto"><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, 26 Jul 2018, 20:20 Paul Burton, &lt;<a href="mailto:paul.burton@mips.com">paul.burton@mips.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Mike,<br>
<br>
On Thu, Jul 26, 2018 at 10:03:56AM +0300, Mike Rapoport wrote:<br>
&gt; Any comments on this?<br>
<br>
I haven&#39;t looked at this in detail yet, but there was a much larger<br>
series submitted to accomplish this not too long ago, which needed<br>
another revision:<br>
<br>
    <a href="https://patchwork.linux-mips.org/project/linux-mips/list/?series=787&amp;state=*" rel="noreferrer noreferrer" target="_blank">https://patchwork.linux-mips.org/project/linux-mips/list/?series=787&amp;state=*</a><br>
<br>
Given that, I&#39;d be (pleasantly) surprised if this one smaller patch is<br>
enough.<br>
<br>
Thanks,<br>
    Paul<br>
</blockquote></div>
Mike Rapoport July 27, 2018, 9:23 p.m. UTC | #4
On Thu, Jul 26, 2018 at 10:20:05AM -0700, Paul Burton wrote:
> Hi Mike,
> 
> On Thu, Jul 26, 2018 at 10:03:56AM +0300, Mike Rapoport wrote:
> > Any comments on this?
> 
> I haven't looked at this in detail yet, but there was a much larger
> series submitted to accomplish this not too long ago, which needed
> another revision:
> 
>     https://patchwork.linux-mips.org/project/linux-mips/list/?series=787&state=*
> 
> Given that, I'd be (pleasantly) surprised if this one smaller patch is
> enough.

I didn't test it on the real hardware, so I could have missed something.
I've looked at Sergey's patches, largely we are doing the same things. 
 
> Thanks,
>     Paul
>
Mike Rapoport Aug. 2, 2018, 11:55 a.m. UTC | #5
Hi,

On Thu, Jul 26, 2018 at 10:55:53PM +0300, Fancer's opinion wrote:
> Hello, folks
> Regarding the no_bootmem patchset I've sent earlier.
> I'm terribly sorry about huge delay with response. I got sucked in a new
> project, so just didn't have a time to proceed with the series, answer to the
> questions and resend the set.
> If it is still relevant and needed for community, I can get back to the series
> on the next week, answer to the Mett's questions (sorry, man, for doing it so
> long), rebase it on top of the kernel 4.18 and resend the new version. We also
> can try to combine it with this patch, if it is found convenient.

So, what would be the best way to move forward?

> Regards,
> -Sergey
> 
> 
> On Thu, 26 Jul 2018, 20:20 Paul Burton, <paul.burton@mips.com> wrote:
> 
>     Hi Mike,
> 
>     On Thu, Jul 26, 2018 at 10:03:56AM +0300, Mike Rapoport wrote:
>     > Any comments on this?
> 
>     I haven't looked at this in detail yet, but there was a much larger
>     series submitted to accomplish this not too long ago, which needed
>     another revision:
> 
>         https://patchwork.linux-mips.org/project/linux-mips/list/?series=787&
>     state=*
> 
>     Given that, I'd be (pleasantly) surprised if this one smaller patch is
>     enough.
> 
>     Thanks,
>         Paul
>
Serge Semin Aug. 8, 2018, 9:30 p.m. UTC | #6
Hello Mike,
I haven't read your patch text yet. I am waiting for the subsystem
maintainers response at least
about the necessity to have this type of changes being merged into the
sources (I mean
memblock/no-bootmem alteration). If they find it pointless (although I
would strongly disagree), then
nothing to discuss. Otherwise we can come up with a solution.

-Sergey


On Thu, Aug 2, 2018 at 2:56 PM Mike Rapoport <rppt@linux.vnet.ibm.com>
wrote:

> Hi,
>
> On Thu, Jul 26, 2018 at 10:55:53PM +0300, Fancer's opinion wrote:
> > Hello, folks
> > Regarding the no_bootmem patchset I've sent earlier.
> > I'm terribly sorry about huge delay with response. I got sucked in a new
> > project, so just didn't have a time to proceed with the series, answer
> to the
> > questions and resend the set.
> > If it is still relevant and needed for community, I can get back to the
> series
> > on the next week, answer to the Mett's questions (sorry, man, for doing
> it so
> > long), rebase it on top of the kernel 4.18 and resend the new version.
> We also
> > can try to combine it with this patch, if it is found convenient.
>
> So, what would be the best way to move forward?
>
> > Regards,
> > -Sergey
> >
> >
> > On Thu, 26 Jul 2018, 20:20 Paul Burton, <paul.burton@mips.com> wrote:
> >
> >     Hi Mike,
> >
> >     On Thu, Jul 26, 2018 at 10:03:56AM +0300, Mike Rapoport wrote:
> >     > Any comments on this?
> >
> >     I haven't looked at this in detail yet, but there was a much larger
> >     series submitted to accomplish this not too long ago, which needed
> >     another revision:
> >
> >
> https://patchwork.linux-mips.org/project/linux-mips/list/?series=787&
> >     state=*
> >
> >     Given that, I'd be (pleasantly) surprised if this one smaller patch
> is
> >     enough.
> >
> >     Thanks,
> >         Paul
> >
>
> --
> Sincerely yours,
> Mike.
>
>
<div dir="ltr">Hello Mike,<br><div>I haven&#39;t read your patch text yet. I am waiting for the subsystem maintainers response at least</div><div>about the necessity to have this type of changes being merged into the sources (I mean</div><div>memblock/no-bootmem alteration). If they find it pointless (although I would strongly disagree), then</div><div>nothing to discuss. Otherwise we can come up with a solution.  </div><div><br></div><div>-Sergey<br><div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 2, 2018 at 2:56 PM Mike Rapoport &lt;<a href="mailto:rppt@linux.vnet.ibm.com">rppt@linux.vnet.ibm.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
On Thu, Jul 26, 2018 at 10:55:53PM +0300, Fancer&#39;s opinion wrote:<br>
&gt; Hello, folks<br>
&gt; Regarding the no_bootmem patchset I&#39;ve sent earlier.<br>
&gt; I&#39;m terribly sorry about huge delay with response. I got sucked in a new<br>
&gt; project, so just didn&#39;t have a time to proceed with the series, answer to the<br>
&gt; questions and resend the set.<br>
&gt; If it is still relevant and needed for community, I can get back to the series<br>
&gt; on the next week, answer to the Mett&#39;s questions (sorry, man, for doing it so<br>
&gt; long), rebase it on top of the kernel 4.18 and resend the new version. We also<br>
&gt; can try to combine it with this patch, if it is found convenient.<br>
<br>
So, what would be the best way to move forward?<br>
<br>
&gt; Regards,<br>
&gt; -Sergey<br>
&gt; <br>
&gt; <br>
&gt; On Thu, 26 Jul 2018, 20:20 Paul Burton, &lt;<a href="mailto:paul.burton@mips.com" target="_blank">paul.burton@mips.com</a>&gt; wrote:<br>
&gt; <br>
&gt;     Hi Mike,<br>
&gt; <br>
&gt;     On Thu, Jul 26, 2018 at 10:03:56AM +0300, Mike Rapoport wrote:<br>
&gt;     &gt; Any comments on this?<br>
&gt; <br>
&gt;     I haven&#39;t looked at this in detail yet, but there was a much larger<br>
&gt;     series submitted to accomplish this not too long ago, which needed<br>
&gt;     another revision:<br>
&gt; <br>
&gt;         <a href="https://patchwork.linux-mips.org/project/linux-mips/list/?series=787&amp;" rel="noreferrer" target="_blank">https://patchwork.linux-mips.org/project/linux-mips/list/?series=787&amp;</a><br>
&gt;     state=*<br>
&gt; <br>
&gt;     Given that, I&#39;d be (pleasantly) surprised if this one smaller patch is<br>
&gt;     enough.<br>
&gt; <br>
&gt;     Thanks,<br>
&gt;         Paul<br>
&gt; <br>
<br>
-- <br>
Sincerely yours,<br>
Mike.<br>
<br>
</blockquote></div>
Paul Burton Aug. 8, 2018, 9:42 p.m. UTC | #7
Hi Sergey & Mike,

On Thu, Aug 09, 2018 at 12:30:03AM +0300, Fancer's opinion wrote:
> Hello Mike,
> I haven't read your patch text yet. I am waiting for the subsystem
> maintainers response at least
> about the necessity to have this type of changes being merged into the
> sources (I mean
> memblock/no-bootmem alteration). If they find it pointless (although I
> would strongly disagree), then
> nothing to discuss. Otherwise we can come up with a solution.
> 
> -Sergey

I'm all for dropping bootmem.

It's too late for something this invasive in 4.19, but I'd love to get
it into 4.20.

Thanks,
    Paul
Mike Rapoport Aug. 9, 2018, 12:34 p.m. UTC | #8
On Wed, Aug 08, 2018 at 02:42:15PM -0700, Paul Burton wrote:
> Hi Sergey & Mike,
> 
> On Thu, Aug 09, 2018 at 12:30:03AM +0300, Fancer's opinion wrote:
> > Hello Mike,
> > I haven't read your patch text yet. I am waiting for the subsystem
> > maintainers response at least
> > about the necessity to have this type of changes being merged into the
> > sources (I mean
> > memblock/no-bootmem alteration). If they find it pointless (although I
> > would strongly disagree), then
> > nothing to discuss. Otherwise we can come up with a solution.
> > 
> > -Sergey
> 
> I'm all for dropping bootmem.
> 
> It's too late for something this invasive in 4.19, but I'd love to get
> it into 4.20.

I can resend my patch once merge window is closed. We can then apply
additional changes Sergey has done in his set on top.

> Thanks,
>     Paul
>
diff mbox

Patch

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 08c10c5..bd15bad 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -76,6 +76,7 @@  config MIPS
 	select RTC_LIB if !MACH_LOONGSON64
 	select SYSCTL_EXCEPTION_TRACE
 	select VIRT_TO_BUS
+	select NO_BOOTMEM
 
 menu "Machine selection"
 
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index 2c96c0c..10f46aa 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -327,7 +327,7 @@  static void __init finalize_initrd(void)
 
 	maybe_bswap_initrd();
 
-	reserve_bootmem(__pa(initrd_start), size, BOOTMEM_DEFAULT);
+	memblock_reserve(__pa(initrd_start), size);
 	initrd_below_start_ok = 1;
 
 	pr_info("Initial ramdisk at: 0x%lx (%lu bytes)\n",
@@ -364,20 +364,10 @@  static void __init bootmem_init(void)
 
 #else  /* !CONFIG_SGI_IP27 */
 
-static unsigned long __init bootmap_bytes(unsigned long pages)
-{
-	unsigned long bytes = DIV_ROUND_UP(pages, 8);
-
-	return ALIGN(bytes, sizeof(long));
-}
-
 static void __init bootmem_init(void)
 {
 	unsigned long reserved_end;
-	unsigned long mapstart = ~0UL;
-	unsigned long bootmap_size;
 	phys_addr_t ramstart = PHYS_ADDR_MAX;
-	bool bootmap_valid = false;
 	int i;
 
 	/*
@@ -389,6 +379,8 @@  static void __init bootmem_init(void)
 	init_initrd();
 	reserved_end = (unsigned long) PFN_UP(__pa_symbol(&_end));
 
+	memblock_reserve(PHYS_OFFSET, reserved_end << PAGE_SHIFT);
+
 	/*
 	 * max_low_pfn is not a number of pages. The number of pages
 	 * of the system is given by 'max_low_pfn - min_low_pfn'.
@@ -436,17 +428,16 @@  static void __init bootmem_init(void)
 		if (initrd_end && end <= (unsigned long)PFN_UP(__pa(initrd_end)))
 			continue;
 #endif
-		if (start >= mapstart)
-			continue;
-		mapstart = max(reserved_end, start);
 	}
 
 	/*
 	 * Reserve any memory between the start of RAM and PHYS_OFFSET
 	 */
-	if (ramstart > PHYS_OFFSET)
+	if (ramstart > PHYS_OFFSET) {
 		add_memory_region(PHYS_OFFSET, ramstart - PHYS_OFFSET,
 				  BOOT_MEM_RESERVED);
+		memblock_reserve(PHYS_OFFSET, ramstart - PHYS_OFFSET);
+	}
 
 	if (min_low_pfn >= max_low_pfn)
 		panic("Incorrect memory mapping !!!");
@@ -472,52 +463,6 @@  static void __init bootmem_init(void)
 		max_low_pfn = PFN_DOWN(HIGHMEM_START);
 	}
 
-#ifdef CONFIG_BLK_DEV_INITRD
-	/*
-	 * mapstart should be after initrd_end
-	 */
-	if (initrd_end)
-		mapstart = max(mapstart, (unsigned long)PFN_UP(__pa(initrd_end)));
-#endif
-
-	/*
-	 * check that mapstart doesn't overlap with any of
-	 * memory regions that have been reserved through eg. DTB
-	 */
-	bootmap_size = bootmap_bytes(max_low_pfn - min_low_pfn);
-
-	bootmap_valid = memory_region_available(PFN_PHYS(mapstart),
-						bootmap_size);
-	for (i = 0; i < boot_mem_map.nr_map && !bootmap_valid; i++) {
-		unsigned long mapstart_addr;
-
-		switch (boot_mem_map.map[i].type) {
-		case BOOT_MEM_RESERVED:
-			mapstart_addr = PFN_ALIGN(boot_mem_map.map[i].addr +
-						boot_mem_map.map[i].size);
-			if (PHYS_PFN(mapstart_addr) < mapstart)
-				break;
-
-			bootmap_valid = memory_region_available(mapstart_addr,
-								bootmap_size);
-			if (bootmap_valid)
-				mapstart = PHYS_PFN(mapstart_addr);
-			break;
-		default:
-			break;
-		}
-	}
-
-	if (!bootmap_valid)
-		panic("No memory area to place a bootmap bitmap");
-
-	/*
-	 * Initialize the boot-time allocator with low memory only.
-	 */
-	if (bootmap_size != init_bootmem_node(NODE_DATA(0), mapstart,
-					 min_low_pfn, max_low_pfn))
-		panic("Unexpected memory size required for bootmap");
-
 	for (i = 0; i < boot_mem_map.nr_map; i++) {
 		unsigned long start, end;
 
@@ -566,9 +511,9 @@  static void __init bootmem_init(void)
 		default:
 			/* Not usable memory */
 			if (start > min_low_pfn && end < max_low_pfn)
-				reserve_bootmem(boot_mem_map.map[i].addr,
-						boot_mem_map.map[i].size,
-						BOOTMEM_DEFAULT);
+				memblock_reserve(boot_mem_map.map[i].addr,
+						boot_mem_map.map[i].size);
+
 			continue;
 		}
 
@@ -591,15 +536,9 @@  static void __init bootmem_init(void)
 		size = end - start;
 
 		/* Register lowmem ranges */
-		free_bootmem(PFN_PHYS(start), size << PAGE_SHIFT);
 		memory_present(0, start, end);
 	}
 
-	/*
-	 * Reserve the bootmap memory.
-	 */
-	reserve_bootmem(PFN_PHYS(mapstart), bootmap_size, BOOTMEM_DEFAULT);
-
 #ifdef CONFIG_RELOCATABLE
 	/*
 	 * The kernel reserves all memory below its _end symbol as bootmem,
@@ -901,17 +840,15 @@  static void __init arch_mem_init(char **cmdline_p)
 	if (setup_elfcorehdr && setup_elfcorehdr_size) {
 		printk(KERN_INFO "kdump reserved memory at %lx-%lx\n",
 		       setup_elfcorehdr, setup_elfcorehdr_size);
-		reserve_bootmem(setup_elfcorehdr, setup_elfcorehdr_size,
-				BOOTMEM_DEFAULT);
+		memblock_reserve(setup_elfcorehdr, setup_elfcorehdr_size);
 	}
 #endif
 
 	mips_parse_crashkernel();
 #ifdef CONFIG_KEXEC
 	if (crashk_res.start != crashk_res.end)
-		reserve_bootmem(crashk_res.start,
-				crashk_res.end - crashk_res.start + 1,
-				BOOTMEM_DEFAULT);
+		memblock_reserve(crashk_res.start,
+				 crashk_res.end - crashk_res.start + 1);
 #endif
 	device_tree_init();
 	sparse_init();
@@ -921,7 +858,7 @@  static void __init arch_mem_init(char **cmdline_p)
 	/* Tell bootmem about cma reserved memblock section */
 	for_each_memblock(reserved, reg)
 		if (reg->size != 0)
-			reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
+			memblock_reserve(reg->base, reg->size);
 
 	reserve_bootmem_region(__pa_symbol(&__nosave_begin),
 			__pa_symbol(&__nosave_end)); /* Reserve for hibernation */
diff --git a/arch/mips/loongson64/loongson-3/numa.c b/arch/mips/loongson64/loongson-3/numa.c
index 9717106..c1e6ec5 100644
--- a/arch/mips/loongson64/loongson-3/numa.c
+++ b/arch/mips/loongson64/loongson-3/numa.c
@@ -180,43 +180,39 @@  static void __init szmem(unsigned int node)
 
 static void __init node_mem_init(unsigned int node)
 {
-	unsigned long bootmap_size;
 	unsigned long node_addrspace_offset;
-	unsigned long start_pfn, end_pfn, freepfn;
+	unsigned long start_pfn, end_pfn;
 
 	node_addrspace_offset = nid_to_addroffset(node);
 	pr_info("Node%d's addrspace_offset is 0x%lx\n",
 			node, node_addrspace_offset);
 
 	get_pfn_range_for_nid(node, &start_pfn, &end_pfn);
-	freepfn = start_pfn;
-	if (node == 0)
-		freepfn = PFN_UP(__pa_symbol(&_end)); /* kernel end address */
-	pr_info("Node%d: start_pfn=0x%lx, end_pfn=0x%lx, freepfn=0x%lx\n",
-		node, start_pfn, end_pfn, freepfn);
+	pr_info("Node%d: start_pfn=0x%lx, end_pfn=0x%lx\n",
+		node, start_pfn, end_pfn);
 
 	__node_data[node] = prealloc__node_data + node;
 
-	NODE_DATA(node)->bdata = &bootmem_node_data[node];
 	NODE_DATA(node)->node_start_pfn = start_pfn;
 	NODE_DATA(node)->node_spanned_pages = end_pfn - start_pfn;
 
-	bootmap_size = init_bootmem_node(NODE_DATA(node), freepfn,
-					start_pfn, end_pfn);
 	free_bootmem_with_active_regions(node, end_pfn);
-	if (node == 0) /* used by finalize_initrd() */
+
+	if (node == 0) {
+		/* kernel end address */
+		unsigned long kernel_end_pfn = PFN_UP(__pa_symbol(&_end));
+
+		/* used by finalize_initrd() */
 		max_low_pfn = end_pfn;
 
-	/* This is reserved for the kernel and bdata->node_bootmem_map */
-	reserve_bootmem_node(NODE_DATA(node), start_pfn << PAGE_SHIFT,
-		((freepfn - start_pfn) << PAGE_SHIFT) + bootmap_size,
-		BOOTMEM_DEFAULT);
+		/* Reserve the kernel text/data/bss */
+		memblock_reserve(start_pfn << PAGE_SHIFT,
+				 ((kernel_end_pfn - start_pfn) << PAGE_SHIFT));
 
-	if (node == 0 && node_end_pfn(0) >= (0xffffffff >> PAGE_SHIFT)) {
 		/* Reserve 0xfe000000~0xffffffff for RS780E integrated GPU */
-		reserve_bootmem_node(NODE_DATA(node),
-				(node_addrspace_offset | 0xfe000000),
-				32 << 20, BOOTMEM_DEFAULT);
+		if (node_end_pfn(0) >= (0xffffffff >> PAGE_SHIFT))
+			memblock_reserve((node_addrspace_offset | 0xfe000000),
+					 32 << 20);
 	}
 
 	sparse_memory_present_with_active_regions(node);
diff --git a/arch/mips/sgi-ip27/ip27-memory.c b/arch/mips/sgi-ip27/ip27-memory.c
index 59133d0a..6f7bef0 100644
--- a/arch/mips/sgi-ip27/ip27-memory.c
+++ b/arch/mips/sgi-ip27/ip27-memory.c
@@ -389,7 +389,6 @@  static void __init node_mem_init(cnodeid_t node)
 {
 	unsigned long slot_firstpfn = slot_getbasepfn(node, 0);
 	unsigned long slot_freepfn = node_getfirstfree(node);
-	unsigned long bootmap_size;
 	unsigned long start_pfn, end_pfn;
 
 	get_pfn_range_for_nid(node, &start_pfn, &end_pfn);
@@ -400,7 +399,6 @@  static void __init node_mem_init(cnodeid_t node)
 	__node_data[node] = __va(slot_freepfn << PAGE_SHIFT);
 	memset(__node_data[node], 0, PAGE_SIZE);
 
-	NODE_DATA(node)->bdata = &bootmem_node_data[node];
 	NODE_DATA(node)->node_start_pfn = start_pfn;
 	NODE_DATA(node)->node_spanned_pages = end_pfn - start_pfn;
 
@@ -409,12 +407,11 @@  static void __init node_mem_init(cnodeid_t node)
 	slot_freepfn += PFN_UP(sizeof(struct pglist_data) +
 			       sizeof(struct hub_data));
 
-	bootmap_size = init_bootmem_node(NODE_DATA(node), slot_freepfn,
-					start_pfn, end_pfn);
 	free_bootmem_with_active_regions(node, end_pfn);
-	reserve_bootmem_node(NODE_DATA(node), slot_firstpfn << PAGE_SHIFT,
-		((slot_freepfn - slot_firstpfn) << PAGE_SHIFT) + bootmap_size,
-		BOOTMEM_DEFAULT);
+
+	memblock_reserve(slot_firstpfn << PAGE_SHIFT,
+			 ((slot_freepfn - slot_firstpfn) << PAGE_SHIFT));
+
 	sparse_memory_present_with_active_regions(node);
 }