Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752182AbZLUETL (ORCPT ); Sun, 20 Dec 2009 23:19:11 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751049AbZLUETJ (ORCPT ); Sun, 20 Dec 2009 23:19:09 -0500 Received: from mga11.intel.com ([192.55.52.93]:28176 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750890AbZLUETI (ORCPT ); Sun, 20 Dec 2009 23:19:08 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.47,429,1257148800"; d="scan'208";a="757957854" From: "Zheng, Shaohui" To: "linux-kernel@vger.kernel.org" CC: "linux-mm@kvack.org" , "ak@linux.intel.com" , "y-goto@jp.fujitsu.com" Date: Mon, 21 Dec 2009 12:18:57 +0800 Subject: [PATCH] Memory-Hotplug: Fix the bug on interface /dev/mem for 64-bit kernel(v1) Thread-Topic: [PATCH] Memory-Hotplug: Fix the bug on interface /dev/mem for 64-bit kernel(v1) Thread-Index: AcqB9LbuxzhSfyl+QB6zNtoJSzTFMQ== Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: yes X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: multipart/mixed; boundary="_002_DA586906BA1FFC4384FCFD6429ECE86030203729shzsmsx502ccrco_" MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9296 Lines: 211 --_002_DA586906BA1FFC4384FCFD6429ECE86030203729shzsmsx502ccrco_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Memory-Hotplug: Fix the bug on interface /dev/mem for 64-bit kernel The new added memory can not be access by interface /dev/mem, because we do= not update the variable high_memory. This patch add a new e820 entry in e820 t= able, and update max_pfn, max_low_pfn and high_memory. We add a function update_pfn in file arch/x86/mm/init.c to udpate these varibles. Memory hotplug does not make sense on 32-bit kernel, so we did n= ot concern it in this function. Signed-off-by: Shaohui Zheng --- diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index f50447d..b986246 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -110,8 +110,8 @@ int __init e820_all_mapped(u64 start, u64 end, unsigned= type) /* * Add a memory region to the kernel e820 map. */ -static void __init __e820_add_region(struct e820map *e820x, u64 start, u64= size, - int type) +static void __meminit __e820_add_region(struct e820map *e820x, u64 start, + u64 size, int type) { int x =3D e820x->nr_map; =20 @@ -126,7 +126,7 @@ static void __init __e820_add_region(struct e820map *e8= 20x, u64 start, u64 size, e820x->nr_map++; } =20 -void __init e820_add_region(u64 start, u64 size, int type) +void __meminit e820_add_region(u64 start, u64 size, int type) { __e820_add_region(&e820, start, size, type); } diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index d406c52..0474459 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -1,6 +1,7 @@ #include #include #include +#include =20 #include #include @@ -386,3 +387,30 @@ void free_initrd_mem(unsigned long start, unsigned lon= g end) free_init_pages("initrd memory", start, end); } #endif + +/** + * After memory hotplug, the variable max_pfn, max_low_pfn and high_memory= will + * be affected, it will be updated in this function. Memory hotplug does n= ot + * make sense on 32-bit kernel, so we do did not concern it in this functi= on. + */ +void __meminit __attribute__((weak)) update_pfn(u64 start, u64 size) +{ +#ifdef CONFIG_X86_64 + unsigned long limit_low_pfn =3D 1UL<<(32 - PAGE_SHIFT); + unsigned long start_pfn =3D start >> PAGE_SHIFT; + unsigned long end_pfn =3D (start + size) >> PAGE_SHIFT; + + if (end_pfn > max_pfn) { + max_pfn =3D end_pfn; + high_memory =3D (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; + } + + /* if add to low memory, update max_low_pfn */ + if (unlikely(start_pfn < limit_low_pfn)) { + if (end_pfn <=3D limit_low_pfn) + max_low_pfn =3D end_pfn; + else + max_low_pfn =3D limit_low_pfn; + } +#endif /* CONFIG_X86_64 */ +} diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h index b10ec49..6693414 100644 --- a/include/linux/bootmem.h +++ b/include/linux/bootmem.h @@ -13,6 +13,7 @@ =20 extern unsigned long max_low_pfn; extern unsigned long min_low_pfn; +extern void update_pfn(u64 start, u64 size); =20 /* * highest page diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 030ce8a..ee7b2d6 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -523,6 +523,14 @@ int __ref add_memory(int nid, u64 start, u64 size) BUG_ON(ret); } =20 + /* update e820 table */ + printk(KERN_INFO "Adding memory region to e820 table (start:%016Lx, size:= %016Lx).\n", + (unsigned long long)start, (unsigned long long)size); + e820_add_region(start, size, E820_RAM); + + /* update max_pfn, max_low_pfn and high_memory */ + update_pfn(start, size); + goto out; =20 error: Thanks & Regards, Shaohui --_002_DA586906BA1FFC4384FCFD6429ECE86030203729shzsmsx502ccrco_ Content-Type: application/octet-stream; name="memory-hotplug-Fix-the-bug-on-interface-dev-mem-v1.patch" Content-Description: memory-hotplug-Fix-the-bug-on-interface-dev-mem-v1.patch Content-Disposition: attachment; filename="memory-hotplug-Fix-the-bug-on-interface-dev-mem-v1.patch"; size=3508; creation-date="Fri, 18 Dec 2009 17:36:26 GMT"; modification-date="Sat, 19 Dec 2009 01:25:10 GMT" Content-Transfer-Encoding: base64 TWVtb3J5LUhvdHBsdWc6IEZpeCB0aGUgYnVnIG9uIGludGVyZmFjZSAvZGV2L21lbSBmb3IgNjQt Yml0IGtlcm5lbAoKVGhlIG5ldyBhZGRlZCBtZW1vcnkgY2FuIG5vdCBiZSBhY2Nlc3MgYnkgaW50 ZXJmYWNlIC9kZXYvbWVtLCBiZWNhdXNlIHdlIGRvIG5vdAogdXBkYXRlIHRoZSB2YXJpYWJsZSBo aWdoX21lbW9yeS4gVGhpcyBwYXRjaCBhZGQgYSBuZXcgZTgyMCBlbnRyeSBpbiBlODIwIHRhYmxl LAogYW5kIHV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xvd19wZm4gYW5kIGhpZ2hfbWVtb3J5ICovCisJdXBkYXRlX3BmbihzdGFydCwg c2l6ZSk7CisKIAlnb3RvIG91dDsKIAogZXJyb3I6Cg== --_002_DA586906BA1FFC4384FCFD6429ECE86030203729shzsmsx502ccrco_-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/