
Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
---

 memhotplug1-dave/arch/i386/kernel/traps.c  |    2 -
 memhotplug1-dave/arch/i386/mm/init.c       |   11 ++++++----
 memhotplug1-dave/drivers/base/memory.c     |   16 +++++++++++++--
 memhotplug1-dave/fs/dcache.c               |    3 ++
 memhotplug1-dave/fs/sysfs/file.c           |    4 ++-
 memhotplug1-dave/include/linux/nonlinear.h |   14 +++++++++++--
 memhotplug1-dave/kernel/panic.c            |    2 +
 memhotplug1-dave/mm/memory_hotplug.c       |    8 ++++++-
 memhotplug1-dave/mm/nonlinear.c            |   30 ++++++++++++++++++++++++++---
 memhotplug1-dave/mm/page_alloc.c           |   12 ++++++++++-
 mm/rmap.c                                  |    0 
 11 files changed, 87 insertions(+), 15 deletions(-)

diff -puN mm/memory_hotplug.c~Z2-debug mm/memory_hotplug.c
--- memhotplug1/mm/memory_hotplug.c~Z2-debug	2004-11-04 16:46:42.000000000 -0800
+++ memhotplug1-dave/mm/memory_hotplug.c	2004-11-04 16:46:43.000000000 -0800
@@ -147,6 +147,9 @@ int online_pages(unsigned long pfn, unsi
 
 	page_zone(pfn_to_page(pfn))->present_pages += nr_pages;
 
+	printk(KERN_DEBUG "%s: onlining if 0x%lx pages done.\n",
+		__func__, nr_pages);
+
 	/* need error checking */
 	return 0;
 }
@@ -159,8 +162,11 @@ int __remove_pages(struct zone *zone, un
 	/*
 	 * for now, only handle 2^x sized areas
 	 */
-	if (nr_pages != 1<<order)
+	if (nr_pages != 1<<order) {
+		printk(KERN_WARNING "%s() non-2^x-sized area: %ld\n",
+				__func__, nr_pages);
 		return -EINVAL;
+	}
 
 	if (capture_page_range(start_pfn, order)) {
 		printk(KERN_WARNING "%s(): failed to capture page range: %ld -> %ld\n",
diff -puN mm/page_alloc.c~Z2-debug mm/page_alloc.c
--- memhotplug1/mm/page_alloc.c~Z2-debug	2004-11-04 16:46:42.000000000 -0800
+++ memhotplug1-dave/mm/page_alloc.c	2004-11-04 16:46:43.000000000 -0800
@@ -40,6 +40,8 @@
 
 #include <asm/tlbflush.h>
 
+#define inline
+
 nodemask_t node_online_map = NODE_MASK_NONE;
 nodemask_t node_possible_map = NODE_MASK_ALL;
 struct pglist_data *pgdat_list;
@@ -241,7 +243,15 @@ static inline void __free_pages_bulk (st
 	page_idx = page - base;
 
 	BUG_ON(page_idx & (order_size - 1));
-	BUG_ON(bad_range(zone, page));
+	if (bad_range(zone, page)) {
+		printk("BAD RANGE!!\n");
+		printk("page: %p pfn: %08lx\n", page, page_to_pfn(page));
+		printk("zone->zone_start_pfn: %08lx\n", zone->zone_start_pfn);
+		printk("zone->zone_start_pfn + spanned: %08lx\n",
+				zone->zone_start_pfn + zone->spanned_pages);
+		printk("zone->spanned_pages: %08lx\n", zone->spanned_pages);
+		BUG();
+	}
 
 	zone->free_pages += order_size;
 	while (order < MAX_ORDER-1) {
diff -puN include/linux/mm.h~Z2-debug include/linux/mm.h
diff -puN include/asm-i386/page.h~Z2-debug include/asm-i386/page.h
diff -puN arch/i386/Kconfig~Z2-debug arch/i386/Kconfig
diff -puN mm/nonlinear.c~Z2-debug mm/nonlinear.c
--- memhotplug1/mm/nonlinear.c~Z2-debug	2004-11-04 16:46:43.000000000 -0800
+++ memhotplug1-dave/mm/nonlinear.c	2004-11-04 16:46:43.000000000 -0800
@@ -46,6 +46,8 @@ setup_memsections(void)
 {
 	int index;
 
+	printk(KERN_DEBUG "%s()\n", __func__);
+
 	for (index = 0; index < NR_SECTIONS; index++) {
 		mem_section[index].phys_section = INVALID_SECTION;
 		mem_section[index].mem_map = NULL;
@@ -64,17 +66,33 @@ alloc_memsections(unsigned long start_pf
 	unsigned int sect_count;
 	unsigned short sect_index;
 
+	printk(KERN_DEBUG "%s(%08lx, %08lx, %08lx)\n", __func__, start_pfn, start_phys_pfn, pfn_count);
+
 	sect_count = pfn_to_section_roundup(pfn_count);
 	sect_index = index = pfn_to_section(start_pfn);
 	limit = index + sect_count;
 	physid = pfn_to_section(start_phys_pfn);
-	for (; index < limit; index++, physid++)
+	for (; index < limit; index++, physid++) {
+		if (mem_section[index].phys_section != INVALID_SECTION) {
+			printk("%s() mem_section[%d].phys_section: %d\n",
+					__func__, index,
+					mem_section[index].phys_section);
+			BUG();
+		}
 		mem_section[index].phys_section = physid;
+		printk(KERN_DEBUG "set mem_section[%d].phys_section: %d\n", index, mem_section[index].phys_section);
+	}
 
 	index = pfn_to_section(start_phys_pfn);
 	limit = index + sect_count;
-	for (; index < limit; index++, sect_index++)
+	for (; index < limit; index++, sect_index++) {
+		if (phys_section[index] != INVALID_PHYS_SECTION) {
+			printk(KERN_DEBUG "phys_section[%d]: %d\n", index, phys_section[index]);
+			BUG();
+		}
 		phys_section[index] = sect_index;
+		printk(KERN_DEBUG "set phys_section[%d]: %d\n", index, phys_section[index]);
+	}
 }
 
 void
@@ -100,6 +118,7 @@ memmap_init(unsigned long num_pages, int
 {
 	unsigned long offset;
 
+	printk(KERN_DEBUG "nonlinear memmap_init(%ld, %d, %ld, %ld)\n", num_pages, nid, zone, start_pfn);
 	offset = section_offset_pfn(start_pfn);
 	while (num_pages) {
 		unsigned long npages;
@@ -127,7 +146,12 @@ pfn_to_page(unsigned long pfn)
 {
 	struct page *page;
 
-	BUG_ON(!mem_section[phys_section[pfn_to_section(pfn)]].mem_map);
+	if (!mem_section[phys_section[pfn_to_section(pfn)]].mem_map) {
+		printk(KERN_ERR "%s() pfn: %08lx phys_section: %d mem_section: %d has no mem_map\n",
+				__func__, pfn, pfn_to_section(pfn),
+				phys_section[pfn_to_section(pfn)]);
+		BUG();
+	}
 	page = &mem_section[phys_section[pfn_to_section(pfn)]].mem_map[section_offset_pfn(pfn)];
 	return page;
 }
diff -puN mm/bootmem.c~Z2-debug mm/bootmem.c
diff -puN include/linux/rmap.h~Z2-debug include/linux/rmap.h
diff -puN include/linux/nonlinear.h~Z2-debug include/linux/nonlinear.h
--- memhotplug1/include/linux/nonlinear.h~Z2-debug	2004-11-04 16:46:43.000000000 -0800
+++ memhotplug1-dave/include/linux/nonlinear.h	2004-11-04 16:46:43.000000000 -0800
@@ -3,7 +3,9 @@
 
 struct page;
 
+
 #include <asm/bug.h>
+#include <linux/kernel.h>
 
 #ifndef CONFIG_NONLINEAR
 
@@ -91,7 +93,11 @@ __pa(const void *ptr_addr)
 	unsigned long addr = (unsigned long)ptr_addr;
 	unsigned long section = addr_to_section(__boot_pa(addr));
 
-	BUG_ON(mem_section[section].phys_section == INVALID_SECTION);
+	if(mem_section[section].phys_section == INVALID_SECTION) {
+		printk("%s(%p):\n", __func__, ptr_addr);
+		printk("\tmem_section[%ld]: INVALID\n", section);
+		BUG();
+	}
 	return section_to_addr(mem_section[section].phys_section) |
 		section_offset(addr);
 }
@@ -99,7 +105,11 @@ __pa(const void *ptr_addr)
 static inline void *
 __va(const unsigned long addr)
 {
-	BUG_ON(phys_section[addr_to_section(addr)] == INVALID_PHYS_SECTION);
+	if(phys_section[addr_to_section(addr)] == INVALID_PHYS_SECTION) {
+		printk("%s(%08lx) phys_section[%d] is invalid\n",
+				__func__, addr, addr_to_section(addr));
+		BUG();
+	}
 	return __boot_va(section_to_addr(phys_section[addr_to_section(addr)]) |
 		         section_offset(addr));
 }
diff -puN include/linux/memory_hotplug.h~Z2-debug include/linux/memory_hotplug.h
diff -puN drivers/base/memory.c~Z2-debug drivers/base/memory.c
--- memhotplug1/drivers/base/memory.c~Z2-debug	2004-11-04 16:46:43.000000000 -0800
+++ memhotplug1-dave/drivers/base/memory.c	2004-11-04 16:46:43.000000000 -0800
@@ -63,6 +63,7 @@ register_memory(struct memory_block *mem
 
 	memory->sysdev.cls = &memory_sysdev_class;
 	memory->sysdev.id = section;
+	printk(KERN_DEBUG "register_memory() with section: %d\n", section);
 
 	error = sysdev_register(&memory->sysdev);
 
@@ -81,6 +82,8 @@ unregister_memory(struct memory_block *m
 	BUG_ON(memory->sysdev.cls != &memory_sysdev_class);
 	BUG_ON(memory->sysdev.id != section);
 
+	printk(KERN_DEBUG "%s(%p, %d, %p)\n", __func__, memory, section, root);
+
 	sysdev_unregister(&memory->sysdev);
 	if (root)
 		sysfs_remove_link(&root->sysdev.kobj, kobject_name(&memory->sysdev.kobj));
@@ -153,8 +156,10 @@ memory_block_action(struct memory_block 
 	printk(KERN_DEBUG "%s()\n"
 	       KERN_DEBUG "\tpsection: %ld\n"
 	       KERN_DEBUG "\tfirst_page: %p\n"
-	       KERN_DEBUG "\tphys_index: %08lx\n",
-		__func__, psection, first_page, mem->phys_index);
+	       KERN_DEBUG "\t last_page: %p\n"
+	       KERN_DEBUG "\tphys_index: %ld\n",
+		__func__, psection, first_page, first_page + PAGES_PER_SECTION -1,
+		mem->phys_index);
 	printk(KERN_DEBUG "\tphys_section[%2ld]: %d\n", psection, phys_section[psection]);
 	for (i = 0; i < PAGES_PER_SECTION; i++) {
 		if ((action == MEM_ONLINE) && !PageReserved(first_page)) {
@@ -233,6 +238,13 @@ store_mem_state(struct sys_device *dev, 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EACCES;
 
+	/*
+	printk(KERN_DEBUG "%s(%p, \"%s\", %d\n)\n", __func__,
+			dev, buf, count);
+	printk(KERN_DEBUG "\tmem->phys_index: %ld\n", mem->phys_index);
+	printk(KERN_DEBUG "section: %d\n", section);
+	*/
+
 	if (mem_section[section].phys_section == INVALID_SECTION) {
 		printk("%s: Ummm.. this section (%d) is not currently mapped!\n",
 			__func__, section);
diff -puN arch/i386/mm/init.c~Z2-debug arch/i386/mm/init.c
--- memhotplug1/arch/i386/mm/init.c~Z2-debug	2004-11-04 16:46:43.000000000 -0800
+++ memhotplug1-dave/arch/i386/mm/init.c	2004-11-04 16:46:43.000000000 -0800
@@ -344,6 +344,8 @@ int add_memory(u64 start, u64 size, unsi
 	unsigned long start_pfn = start >> PAGE_SHIFT;
 	unsigned long nr_pages = size >> PAGE_SHIFT;
 
+	printk(KERN_DEBUG "%s(%016Lx, %016Lx, %08lx\n", __func__, start, size, attr);
+
 	return __add_pages(zone, start_pfn, nr_pages, attr);
 }
 
@@ -363,8 +365,9 @@ int remove_memory(u64 start, u64 size, u
 	 */
 	zone = page_zone(pfn_to_page(start_pfn));
 
-	printk("%s(): memory will be removed from "
-			"the %s zone\n", __func__, zone->name);
+	printk(KERN_DEBUG "%s(%016Lx, %016Lx, %ld):\n\tmemory will be removed from "
+			"a %s zone\n", __func__, start, size, attr,
+			zone->name);
 
 	/*
 	 * not handling removing memory ranges that
@@ -383,10 +386,10 @@ int remove_memory(u64 start, u64 size, u
 	return __remove_pages(zone, start_pfn, nr_pages, attr);
 
 overlap:
-	printk("%s(): memory range to be removed overlaps "
+	printk(KERN_WARNING "%s(): memory range to be removed overlaps "
 		"multiple zones!!!\n", __func__);
 not_highmem:
-	return -1;
+	return -EINVAL;
 }
 #endif
 
diff -puN mm/vmscan.c~Z2-debug mm/vmscan.c
diff -puN fs/sysfs/file.c~Z2-debug fs/sysfs/file.c
--- memhotplug1/fs/sysfs/file.c~Z2-debug	2004-11-04 16:46:43.000000000 -0800
+++ memhotplug1-dave/fs/sysfs/file.c	2004-11-04 16:46:43.000000000 -0800
@@ -375,7 +375,9 @@ int sysfs_add_file(struct dentry * dir, 
 
 int sysfs_create_file(struct kobject * kobj, const struct attribute * attr)
 {
-	BUG_ON(!kobj || !kobj->dentry || !attr);
+	BUG_ON(!kobj);
+	BUG_ON(!kobj->dentry);
+	BUG_ON(!attr);
 
 	return sysfs_add_file(kobj->dentry, attr, SYSFS_KOBJ_ATTR);
 
diff -puN include/asm-generic/bug.h~Z2-debug include/asm-generic/bug.h
diff -puN kernel/panic.c~Z2-debug kernel/panic.c
--- memhotplug1/kernel/panic.c~Z2-debug	2004-11-04 16:46:43.000000000 -0800
+++ memhotplug1-dave/kernel/panic.c	2004-11-04 16:46:43.000000000 -0800
@@ -68,12 +68,14 @@ NORET_TYPE void panic(const char * fmt, 
 	/* If we have crashed, perform a kexec reboot, for dump write-out */
 	crash_machine_kexec();
 
+	machine_restart(NULL);
 #ifdef CONFIG_SMP
 	smp_send_stop();
 #endif
 
        notifier_call_chain(&panic_notifier_list, 0, buf);
 
+        panic_timeout = 1;
 	if (panic_timeout > 0)
 	{
 		int i;
diff -puN mm/highmem.c~Z2-debug mm/highmem.c
diff -puN include/linux/list.h~Z2-debug include/linux/list.h
diff -puN include/linux/mm_inline.h~Z2-debug include/linux/mm_inline.h
diff -puN include/linux/mmzone.h~Z2-debug include/linux/mmzone.h
diff -puN ./arch/i386/mm/fault.c~Z2-debug ./arch/i386/mm/fault.c
diff -puN arch/i386/kernel/traps.c~Z2-debug arch/i386/kernel/traps.c
--- memhotplug1/arch/i386/kernel/traps.c~Z2-debug	2004-11-04 16:46:43.000000000 -0800
+++ memhotplug1-dave/arch/i386/kernel/traps.c	2004-11-04 16:46:43.000000000 -0800
@@ -385,7 +385,7 @@ void die(const char * str, struct pt_reg
 	if (in_interrupt())
 		panic("Fatal exception in interrupt");
 
-	if (panic_on_oops) {
+	if (1 || panic_on_oops) {
 		printk(KERN_EMERG "Fatal exception: panic in 5 seconds\n");
 		set_current_state(TASK_UNINTERRUPTIBLE);
 		schedule_timeout(5 * HZ);
diff -puN mm/swap.c~Z2-debug mm/swap.c
diff -puN arch/i386/mm/pgtable.c~Z2-debug arch/i386/mm/pgtable.c
diff -puN arch/i386/kernel/setup.c~Z2-debug arch/i386/kernel/setup.c
diff -puN arch/i386/mm/pageattr.c~Z2-debug arch/i386/mm/pageattr.c
diff -puN arch/i386/mm/ioremap.c~Z2-debug arch/i386/mm/ioremap.c
diff -puN fs/dcache.c~Z2-debug fs/dcache.c
--- memhotplug1/fs/dcache.c~Z2-debug	2004-11-04 16:46:43.000000000 -0800
+++ memhotplug1-dave/fs/dcache.c	2004-11-04 16:46:43.000000000 -0800
@@ -1631,8 +1631,11 @@ extern void chrdev_init(void);
 
 void __init vfs_caches_init_early(void)
 {
+	printk("%s()\n", __func__);
 	dcache_init_early();
+	printk("%s() 2\n", __func__);
 	inode_init_early();
+	printk("%s() done\n", __func__);
 }
 
 void __init vfs_caches_init(unsigned long mempages)
diff -puN include/linux/slab.h~Z2-debug include/linux/slab.h
diff -puN mm/slab.c~Z2-debug mm/slab.c
diff -puN mm/rmap.c~Z2-debug mm/rmap.c
_
