Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752172Ab0AKHwW (ORCPT ); Mon, 11 Jan 2010 02:52:22 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752034Ab0AKHwV (ORCPT ); Mon, 11 Jan 2010 02:52:21 -0500 Received: from mga09.intel.com ([134.134.136.24]:59166 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751895Ab0AKHwV (ORCPT ); Mon, 11 Jan 2010 02:52:21 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.49,255,1262592000"; d="scan'208";a="586051701" From: "Zheng, Shaohui" To: "linux-mm@kvack.org" , "akpm@linux-foundation.org" CC: "linux-kernel@vger.kernel.org" , "ak@linux.intel.com" , "y-goto@jp.fujitsu.com" , Dave Hansen , "Wu, Fengguang" , "x86@kernel.org" , "Li, Haicheng" Date: Mon, 11 Jan 2010 15:49:05 +0800 Subject: [RESEND PATCH v2] Memory-Hotplug: Fix the bug on interface /dev/mem for 64-bit kernel Thread-Topic: [RESEND PATCH v2] Memory-Hotplug: Fix the bug on interface /dev/mem for 64-bit kernel Thread-Index: AcqSkox7FnH4OeCgToOV6ARhk6GeMw== 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_DA586906BA1FFC4384FCFD6429ECE860316BFBE2shzsmsx502ccrco_" MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9806 Lines: 217 --_002_DA586906BA1FFC4384FCFD6429ECE860316BFBE2shzsmsx502ccrco_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable After reviewed by Fengguang, resend the v2 patch to mailing-list. 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. Memory hotplug still has critical issues for 32-bit kernel, and it is more= =20 important for 64-bit kernel, we fix it on 64-bit first. We add a function=20 update_end_of_memory_vars in file arch/x86/mm/init.c to update these variab= les. Signed-off-by: Shaohui Zheng CC: Andi Kleen CC: Li Haicheng Reviewed-by: Wu Fengguang diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index a1a7876..a9b6bae 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..51ff734 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,31 @@ 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_end_of_memory_vars(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 PFN_UP(start + size); + + 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..84533a5 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_end_of_memory_vars(u64 start, u64 size); =20 /* * highest page diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 030ce8a..cd54ad1 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -523,6 +523,13 @@ int __ref add_memory(int nid, u64 start, u64 size) BUG_ON(ret); } =20 + 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_end_of_memory_vars(start, size); + goto out; =20 error: Thanks & Regards, Shaohui --_002_DA586906BA1FFC4384FCFD6429ECE860316BFBE2shzsmsx502ccrco_ Content-Type: application/octet-stream; name="memory-hotplug-fix-the-bug-on-interface-dev-mem-v2.patch" Content-Description: memory-hotplug-fix-the-bug-on-interface-dev-mem-v2.patch Content-Disposition: attachment; filename="memory-hotplug-fix-the-bug-on-interface-dev-mem-v2.patch"; size=3695; creation-date="Mon, 11 Jan 2010 15:46:27 GMT"; modification-date="Mon, 11 Jan 2010 23:36:52 GMT" Content-Transfer-Encoding: base64 TWVtb3J5LUhvdHBsdWc6IEZpeCB0aGUgYnVnIG9uIGludGVyZmFjZSAvZGV2L21lbSBmb3IgNjQt Yml0IGtlcm5lbAoKVGhlIG5ldyBhZGRlZCBtZW1vcnkgY2FuIG5vdCBiZSBhY2Nlc3MgYnkga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BfX3JlZiBhZGRfbWVtb3J5KGludCBuaWQsIHU2NCBzdGFydCwgdTY0IHNpemUp CiAJCUJVR19PTihyZXQpOwogCX0KIAorCXByaW50ayhLRVJOX0lORk8gIkFkZGluZyBtZW1vcnkg cmVnaW9uIHRvIGU4MjAgdGFibGUgKHN0YXJ0OiUwMTZMeCwgc2l6ZTolMDE2THgpLlxuIiwKKwkJ CSAodW5zaWduZWQgbG9uZyBsb25nKXN0YXJ0LCAodW5zaWduZWQgbG9uZyBsb25nKXNpemUpOwor CWU4MjBfYWRkX3JlZ2lvbihzdGFydCwgc2l6ZSwgRTgyMF9SQU0pOworCisJLyogdXBkYXRlIG1h eF9wZm4sIG1heF9sb3dfcGZuIGFuZCBoaWdoX21lbW9yeSAqLworCXVwZGF0ZV9lbmRfb2ZfbWVt b3J5X3ZhcnMoc3RhcnQsIHNpemUpOworCiAJZ290byBvdXQ7CiAKIGVycm9yOgo= --_002_DA586906BA1FFC4384FCFD6429ECE860316BFBE2shzsmsx502ccrco_-- -- 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/