Re: [PATCH/v2] mm/memblock: Properly handle overlaps and fix errorpath

From: Yinghai Lu
Date: Wed Mar 09 2011 - 15:43:38 EST


On 03/06/2011 07:03 PM, Benjamin Herrenschmidt wrote:
> Currently memblock_reserve() or memblock_free() don't handle overlaps
> of any kind. There is some special casing for coalescing exactly
> adjacent regions but that's about it.
>
> This is annoying because typically memblock_reserve() is used to
> mark regions passed by the firmware as reserved and we all know
> how much we can trust our firmwares...
>
> Also, with the current code, if we do something it doesn't handle
> right such as trying to memblock_reserve() a large range spanning
> multiple existing smaller reserved regions for example, or doing
> overlapping reservations, it can silently corrupt the internal
> region array, causing odd errors much later on, such as allocations
> returning reserved regions etc...
>
> This patch rewrites the underlying functions that add or remove a
> region to the arrays. The new code is a lot more robust as it fully
> handles overlapping regions. It's also, imho, simpler than the previous
> implementation.
>
> In addition, while doing so, I found a bug where if we fail to double
> the array while adding a region, we would remove the last region of
> the array rather than the region we just allocated. This fixes it too.
>
> Signed-off-by: Benjamin Herrenschmidt <benh@xxxxxxxxxxxxxxxxxxx>
> ---
>
> Hopefully not damaged with a spurious bit of email header this
> time around... sorry about that.

works on my setups...

[ 0.000000] Subtract (26 early reservations)
[ 0.000000] [000009a000-000009efff]
[ 0.000000] [000009f400-00000fffff]
[ 0.000000] [0001000000-0003495048]
...
before:
[ 0.000000] Subtract (27 early reservations)
[ 0.000000] [000009a000-000009efff]
[ 0.000000] [000009f400-00000fffff]
[ 0.000000] [00000f85b0-00000f86b3]
[ 0.000000] [0001000000-0003495048]

Acked-by: Yinghai Lu <yinghai@xxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/