aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorYinghai Lu <yhlu.kernel@gmail.com>2008-03-24 15:29:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-03-24 22:22:19 -0400
commit5a982cbc7b3fe6cf72266f319286f29963c71b9e (patch)
tree97afbc2ebc81b31ec13e261d0127f5e1639f0e26 /mm
parent2875fb65f8e40401c4b781ebc5002df10485f635 (diff)
mm: fix boundary checking in free_bootmem_core
With numa enabled, some callers could have a range of memory on one node but try to free that on other node. This can cause some pages to be freed wrongly. For example: when we try to allocate 128g boot ram early for gart/swiotlb, and free that range later so gart/swiotlb can get some range afterwards. With this patch, we don't need to care which node holds the range, just loop to call free_bootmem_node for all online nodes. This patch makes free_bootmem_core() more robust by trimming the sidx and eidx according the ram range that the node has. And make the free_bootmem_core handle this out of range case. We could use bdata_list to make sure the range can be freed for sure. So next time, we don't need to loop online nodes and could use free_bootmem directly. Signed-off-by: Yinghai Lu <yhlu.kernel@gmail.com> Cc: Andi Kleen <ak@suse.de> Cc: Yasunori Goto <y-goto@jp.fujitsu.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Acked-by: Ingo Molnar <mingo@elte.hu> Tested-by: Ingo Molnar <mingo@elte.hu> Cc: Christoph Lameter <clameter@sgi.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r--mm/bootmem.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/mm/bootmem.c b/mm/bootmem.c
index f6ff4337b424..2ccea700968f 100644
--- a/mm/bootmem.c
+++ b/mm/bootmem.c
@@ -125,6 +125,7 @@ static int __init reserve_bootmem_core(bootmem_data_t *bdata,
125 BUG_ON(!size); 125 BUG_ON(!size);
126 BUG_ON(PFN_DOWN(addr) >= bdata->node_low_pfn); 126 BUG_ON(PFN_DOWN(addr) >= bdata->node_low_pfn);
127 BUG_ON(PFN_UP(addr + size) > bdata->node_low_pfn); 127 BUG_ON(PFN_UP(addr + size) > bdata->node_low_pfn);
128 BUG_ON(addr < bdata->node_boot_start);
128 129
129 sidx = PFN_DOWN(addr - bdata->node_boot_start); 130 sidx = PFN_DOWN(addr - bdata->node_boot_start);
130 eidx = PFN_UP(addr + size - bdata->node_boot_start); 131 eidx = PFN_UP(addr + size - bdata->node_boot_start);
@@ -156,21 +157,31 @@ static void __init free_bootmem_core(bootmem_data_t *bdata, unsigned long addr,
156 unsigned long sidx, eidx; 157 unsigned long sidx, eidx;
157 unsigned long i; 158 unsigned long i;
158 159
160 BUG_ON(!size);
161
162 /* out range */
163 if (addr + size < bdata->node_boot_start ||
164 PFN_DOWN(addr) > bdata->node_low_pfn)
165 return;
159 /* 166 /*
160 * round down end of usable mem, partially free pages are 167 * round down end of usable mem, partially free pages are
161 * considered reserved. 168 * considered reserved.
162 */ 169 */
163 BUG_ON(!size);
164 BUG_ON(PFN_DOWN(addr + size) > bdata->node_low_pfn);
165 170
166 if (addr < bdata->last_success) 171 if (addr >= bdata->node_boot_start && addr < bdata->last_success)
167 bdata->last_success = addr; 172 bdata->last_success = addr;
168 173
169 /* 174 /*
170 * Round up the beginning of the address. 175 * Round up to index to the range.
171 */ 176 */
172 sidx = PFN_UP(addr) - PFN_DOWN(bdata->node_boot_start); 177 if (PFN_UP(addr) > PFN_DOWN(bdata->node_boot_start))
178 sidx = PFN_UP(addr) - PFN_DOWN(bdata->node_boot_start);
179 else
180 sidx = 0;
181
173 eidx = PFN_DOWN(addr + size - bdata->node_boot_start); 182 eidx = PFN_DOWN(addr + size - bdata->node_boot_start);
183 if (eidx > bdata->node_low_pfn - PFN_DOWN(bdata->node_boot_start))
184 eidx = bdata->node_low_pfn - PFN_DOWN(bdata->node_boot_start);
174 185
175 for (i = sidx; i < eidx; i++) { 186 for (i = sidx; i < eidx; i++) {
176 if (unlikely(!test_and_clear_bit(i, bdata->node_bootmem_map))) 187 if (unlikely(!test_and_clear_bit(i, bdata->node_bootmem_map)))
@@ -421,7 +432,9 @@ int __init reserve_bootmem(unsigned long addr, unsigned long size,
421 432
422void __init free_bootmem(unsigned long addr, unsigned long size) 433void __init free_bootmem(unsigned long addr, unsigned long size)
423{ 434{
424 free_bootmem_core(NODE_DATA(0)->bdata, addr, size); 435 bootmem_data_t *bdata;
436 list_for_each_entry(bdata, &bdata_list, list)
437 free_bootmem_core(bdata, addr, size);
425} 438}
426 439
427unsigned long __init free_all_bootmem(void) 440unsigned long __init free_all_bootmem(void)