memory hotplug: fix a bug on /dev/mem for 64-bit kernels

Newly added memory can not be accessed via /dev/mem, because we do not
update the variables high_memory, max_pfn and max_low_pfn.

Add a function update_end_of_memory_vars() to update these variables for
64-bit kernels.

[akpm@linux-foundation.org: simplify comment]
Signed-off-by: Shaohui Zheng <shaohui.zheng@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Li Haicheng <haicheng.li@intel.com>
Reviewed-by: Wu Fengguang <fengguang.wu@intel.com>
Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Shaohui Zheng and committed by Linus Torvalds ea085417 a225a5cc

+19
+19
arch/x86/mm/init_64.c
··· 49 #include <asm/numa.h> 50 #include <asm/cacheflush.h> 51 #include <asm/init.h> 52 53 static unsigned long dma_reserve __initdata; 54 ··· 617 */ 618 #ifdef CONFIG_MEMORY_HOTPLUG 619 /* 620 * Memory is added always to NORMAL zone. This means you will never get 621 * additional DMA/DMA32 memory. 622 */ ··· 649 650 ret = __add_pages(nid, zone, start_pfn, nr_pages); 651 WARN_ON_ONCE(ret); 652 653 return ret; 654 }
··· 49 #include <asm/numa.h> 50 #include <asm/cacheflush.h> 51 #include <asm/init.h> 52 + #include <linux/bootmem.h> 53 54 static unsigned long dma_reserve __initdata; 55 ··· 616 */ 617 #ifdef CONFIG_MEMORY_HOTPLUG 618 /* 619 + * After memory hotplug the variables max_pfn, max_low_pfn and high_memory need 620 + * updating. 621 + */ 622 + static void update_end_of_memory_vars(u64 start, u64 size) 623 + { 624 + unsigned long end_pfn = PFN_UP(start + size); 625 + 626 + if (end_pfn > max_pfn) { 627 + max_pfn = end_pfn; 628 + max_low_pfn = end_pfn; 629 + high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; 630 + } 631 + } 632 + 633 + /* 634 * Memory is added always to NORMAL zone. This means you will never get 635 * additional DMA/DMA32 memory. 636 */ ··· 633 634 ret = __add_pages(nid, zone, start_pfn, nr_pages); 635 WARN_ON_ONCE(ret); 636 + 637 + /* update max_pfn, max_low_pfn and high_memory */ 638 + update_end_of_memory_vars(start, size); 639 640 return ret; 641 }