Re: [PATCH 18/39] lmb: Add lmb_reserve_area_overlap_ok()

Previous thread: [PATCH 16/39] lmb: Add lmb_free_memory_size() by Yinghai Lu on Thursday, April 8, 2010 - 11:03 pm. (1 message)

Next thread: [PATCH -v12 00/39] use lmb with x86 by Yinghai Lu on Thursday, April 8, 2010 - 11:03 pm. (48 messages)
From: Yinghai Lu
Date: Thursday, April 8, 2010 - 11:03 pm

Some areas from firmware could be reserved several times from different callers.

If these area are overlapped, We may have overlapped entries in lmb.reserved.

Try to free the area at first, before rerserve them again.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 include/linux/lmb.h |    1 +
 mm/lmb.c            |   27 +++++++++++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/include/linux/lmb.h b/include/linux/lmb.h
index 8332934..3c8095f 100644
--- a/include/linux/lmb.h
+++ b/include/linux/lmb.h
@@ -86,6 +86,7 @@ lmb_end_pfn(struct lmb_region *type, unsigned long region_nr)
 }
 
 void lmb_reserve_area(u64 start, u64 end, char *name);
+void lmb_reserve_area_overlap_ok(u64 start, u64 end, char *name);
 void lmb_free_area(u64 start, u64 end);
 void lmb_add_memory(u64 start, u64 end);
 u64 __lmb_find_area(u64 ei_start, u64 ei_last, u64 start, u64 end,
diff --git a/mm/lmb.c b/mm/lmb.c
index feb3dfa..34fc030 100644
--- a/mm/lmb.c
+++ b/mm/lmb.c
@@ -605,6 +605,12 @@ void __init lmb_add_memory(u64 start, u64 end)
 	__check_and_double_region_array(&lmb.memory, &lmb_memory_region[0]);
 }
 
+static void __init __lmb_reserve_area(u64 start, u64 end, char *name)
+{
+	lmb_add_region(&lmb.reserved, start, end - start);
+	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0]);
+}
+
 void __init lmb_reserve_area(u64 start, u64 end, char *name)
 {
 	if (start == end)
@@ -613,8 +619,25 @@ void __init lmb_reserve_area(u64 start, u64 end, char *name)
 	if (WARN_ONCE(start > end, "lmb_reserve_area: wrong range [%#llx, %#llx]\n", start, end))
 		return;
 
-	lmb_add_region(&lmb.reserved, start, end - start);
-	__check_and_double_region_array(&lmb.reserved, &lmb_reserved_region[0]);
+	__lmb_reserve_area(start, end, name);
+}
+
+/*
+ * Could be used to avoid having overlap entries in lmb.reserved.region.
+ *  Don't need to use it with area that is from lmb_find_area()
+ *  Only use it for the area that fw hidden area.
+ ...
From: Benjamin Herrenschmidt
Date: Monday, April 12, 2010 - 9:21 pm

That is going to only work with one overlap. IE. lmb_free() will not do
very well unless it's a one and only match.

You should modify it to work in a loop.

Besides, lmb_reserve_area_overlap_ok() sucks as a name :-)

Cheers,
Ben.




--

From: Yinghai
Date: Monday, April 12, 2010 - 9:44 pm

that is only for some special cases about area that is reserved for fw region.

and even there is overlapped area, it the code still can go through when lmb_to_bootmem or create range list for slab.

any suggestion for better name?

YH
--

From: Benjamin Herrenschmidt
Date: Monday, April 12, 2010 - 10:10 pm

And ? From what I can see in the code, it will still not work properly
unless all your special cases end up fitting right with the bug you

Well, either we just have overlapped areas or we don't ... we shouldn't
have some kind of overlap_ok() thing that does the right thing ..
sometimes, but maybe not, but we don't care anyways, which is what you

Well, what you actually implemented is 

lmb_reserve_area_overlap_maybe_ok_not_too_sure_though()

What we should decide is once for all, is it ok to have lmb_reserve() be
called for overlapping ranges. I think the answer is yes and in fact, we
don't take special care in powerpc either there so overlap could happen
in theory.

Now, do we want to avoid actually creating overlapping regions in the
array ? I think we should look into it, but then we should fix
lmb_reserve() to do the right thing here and coalesce all the overlaps.

Cheers,


--

From: Yinghai
Date: Monday, April 12, 2010 - 10:37 pm

not sure.


not sure if is needed. lmb_free/lmb_reserve seems work.

YH
--

Previous thread: [PATCH 16/39] lmb: Add lmb_free_memory_size() by Yinghai Lu on Thursday, April 8, 2010 - 11:03 pm. (1 message)

Next thread: [PATCH -v12 00/39] use lmb with x86 by Yinghai Lu on Thursday, April 8, 2010 - 11:03 pm. (48 messages)