RE: [PATCH 1/3] memblock, nobootmem: Add memblock_virt_alloc_low()

From: Strashko, Grygorii
Date: Tue Jan 28 2014 - 15:18:56 EST


Hi all,

Sorry, for the invalid mail & patch format - have no way to send it properly now.

Suppose there is another way to fix this issue (more generic)
- Correct memblock_virt_allocX() API to limit allocations below memblock.current_limit
(patch attached).

Then the code behavior will become more similar to _alloc_memory_core_early.

Not tested.


Best regards,
- grygorii

________________________________________
From: Konrad Rzeszutek Wilk [konrad.wilk@xxxxxxxxxx]
Sent: Tuesday, January 28, 2014 8:56 PM
To: Shilimkar, Santosh
Cc: Russell King - ARM Linux; Yinghai Lu; Kevin Hilman; Olof Johansson; Linus Torvalds; Andrew Morton; Ingo Molnar; H. Peter Anvin; Dave Hansen; linux-kernel@xxxxxxxxxxxxxxx; Strashko, Grygorii; xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: Re: [PATCH 1/3] memblock, nobootmem: Add memblock_virt_alloc_low()

On Tue, Jan 28, 2014 at 01:36:28PM -0500, Santosh Shilimkar wrote:
> + Gryagorii,
> On Tuesday 28 January 2014 01:22 PM, Russell King - ARM Linux wrote:
> > On Tue, Jan 28, 2014 at 12:23:02PM -0500, Santosh Shilimkar wrote:
> >> On Tuesday 28 January 2014 12:12 PM, Yinghai Lu wrote:
> >>> Index: linux-2.6/include/linux/bootmem.h
> >>> ===================================================================
> >>> --- linux-2.6.orig/include/linux/bootmem.h
> >>> +++ linux-2.6/include/linux/bootmem.h
> >>> @@ -179,6 +179,9 @@ static inline void * __init memblock_vir
> >>> NUMA_NO_NODE);
> >>> }
> >>>
> >>> +/* Take arch's ARCH_LOW_ADDRESS_LIMIT at first*/
> >>> +#include <asm/processor.h>
> >>> +
> >>> #ifndef ARCH_LOW_ADDRESS_LIMIT
> >>> #define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL
> >>> #endif
> >>
> >> This won't help mostly since the ARM 32 arch don't set ARCH_LOW_ADDRESS_LIMIT.
> >> Sorry i couldn't respond to the thread earlier because of travel and
> >> don't have access to my board to try out the patches.
> >
> > Let's think about this for a moment, shall we...
> >
> > What does memblock_alloc_virt*() return? It returns a virtual address.
> >
> > How is that virtual address obtained? ptr = phys_to_virt(alloc);
> >
> > What is the valid address range for passing into phys_to_virt() ? Only
> > lowmem addresses.
> >
> > Hence, having ARCH_LOW_ADDRESS_LIMIT set to 4GB-1 by default seems to be
> > completely rediculous - and presumably this also fails on x86_32 if it
> > returns memory up at 4GB.
> >
> > So... yes, I think reverting the arch/arm part of this patch is the right
> > solution, whether the rest of it should be reverted is something I can't
> > comment on.
> >
> Grygorri mentioned an alternate to update the memblock_find_in_range_node() so
> that it takes into account the limit.

This patch breaks also Xen and 32-bit guests (see
http://lists.xen.org/archives/html/xen-devel/2014-01/msg02476.html)

Reverting it fixes it.

>
> Regards,
> Santosh
From ee31afb9c5c0e78819ce624e3a930d31b97527cd Mon Sep 17 00:00:00 2001
From: grygoriis <grygorii.strashko@xxxxxxxxxxxxxxx>
Date: Tue, 28 Jan 2014 21:59:30 +0200
Subject: [PATCH] mm/memblock: fix upper boundary of allocating region

Correct memblock_virt_allocX() API to limit allocations below
memblock.current_limit.

Signed-off-by: grygoriis <grygorii.strashko@xxxxxxxxxxxxxxx>
---
mm/memblock.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index 87d21a6..e93d669 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -1077,6 +1077,9 @@ static void * __init memblock_virt_alloc_internal(
if (!align)
align = SMP_CACHE_BYTES;

+ if (max_addr > memblock.current_limit)
+ max_addr = memblock.current_limit;
+
again:
alloc = memblock_find_in_range_node(size, align, min_addr, max_addr,
nid);
--
1.7.4.1