From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Fri, 9 Feb 2007 15:10:30 +1100 From: David Gibson To: Paul Mackerras Subject: powerpc: Allow duplicate lmb_reserve() calls Message-ID: <20070209041030.GG3489@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linuxppc-dev@ozlabs.org List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Paulus, please apply. At present calling lmb_reserve() (and hence lmb_add_region()) twice for exactly the same memory region will cause strange behaviour. This makes life difficult when booting from a flat device tree with memory reserve map. Which regions are automatically reserved by the kernel has changed over time, so it's quite possible a newer kernel could attempt to auto-reserve a region which is also explicitly listed in the device tree's reserve map, leading to trouble. This patch avoids the problem by making lmb_reserve() ignore a call to reserve a previously reserved region. It also removes a now redundant test designed to avoid one specific case of the problem noted above. At present, this patch deals only with duplicate reservations of an identical region. Attempting to reserve two different, but overlapping regions will still cause problems. I might post another patch later dealing with this case, but I'm avoiding it now since it is substantially more complicated to deal with, less likely to occur and more likely to indicate a genuine bug elsewhere if it does occur. Signed-off-by: David Gibson Index: working-2.6/arch/powerpc/mm/lmb.c =================================================================== --- working-2.6.orig/arch/powerpc/mm/lmb.c 2007-02-06 16:21:02.000000000 +1100 +++ working-2.6/arch/powerpc/mm/lmb.c 2007-02-06 16:22:32.000000000 +1100 @@ -146,6 +146,10 @@ static long __init lmb_add_region(struct unsigned long rgnbase = rgn->region[i].base; unsigned long rgnsize = rgn->region[i].size; + if ((rgnbase == base) && (rgnsize == size)) + /* Already have this region, so we're done */ + return 0; + adjacent = lmb_addrs_adjacent(base,size,rgnbase,rgnsize); if ( adjacent > 0 ) { rgn->region[i].base -= size; Index: working-2.6/arch/powerpc/kernel/prom.c =================================================================== --- working-2.6.orig/arch/powerpc/kernel/prom.c 2007-02-06 16:22:48.000000000 +1100 +++ working-2.6/arch/powerpc/kernel/prom.c 2007-02-06 16:22:57.000000000 +1100 @@ -954,9 +954,6 @@ static void __init early_reserve_mem(voi size = *(reserve_map++); if (size == 0) break; - /* skip if the reservation is for the blob */ - if (base == self_base && size == self_size) - continue; DBG("reserving: %llx -> %llx\n", base, size); lmb_reserve(base, size); } -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson