From patchwork Fri Oct 5 02:25:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yasuaki Ishimatsu X-Patchwork-Id: 189390 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id 5D1D02C03DC for ; Fri, 5 Oct 2012 12:26:38 +1000 (EST) Received: from fgwmail5.fujitsu.co.jp (fgwmail5.fujitsu.co.jp [192.51.44.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 891B32C0095 for ; Fri, 5 Oct 2012 12:26:10 +1000 (EST) Received: from m4.gw.fujitsu.co.jp (unknown [10.0.50.74]) by fgwmail5.fujitsu.co.jp (Postfix) with ESMTP id B00FD3EE0BD for ; Fri, 5 Oct 2012 11:26:08 +0900 (JST) Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 8FEAA45DE53 for ; Fri, 5 Oct 2012 11:26:08 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 743D945DE4F for ; Fri, 5 Oct 2012 11:26:08 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 645D51DB803B for ; Fri, 5 Oct 2012 11:26:08 +0900 (JST) Received: from g01jpexchkw02.g01.fujitsu.local (g01jpexchkw02.g01.fujitsu.local [10.0.194.41]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 1446E1DB8041 for ; Fri, 5 Oct 2012 11:26:08 +0900 (JST) Received: from [127.0.0.1] (10.124.101.33) by g01jpexchkw02.g01.fujitsu.local (10.0.194.41) with Microsoft SMTP Server id 14.2.309.2; Fri, 5 Oct 2012 11:26:06 +0900 X-SecurityPolicyCheck: OK by SHieldMailChecker v1.7.4 Message-ID: <506E451E.1050403@jp.fujitsu.com> Date: Fri, 5 Oct 2012 11:25:34 +0900 From: Yasuaki Ishimatsu User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 MIME-Version: 1.0 To: , , , , , , , , , Subject: [PATCH 1/10] memory-hotplug : check whether memory is offline or not when removing memory References: <506E43E0.70507@jp.fujitsu.com> In-Reply-To: <506E43E0.70507@jp.fujitsu.com> Cc: len.brown@intel.com, wency@cn.fujitsu.com, Yasuaki Ishimatsu , minchan.kim@gmail.com, kosaki.motohiro@jp.fujitsu.com, rientjes@google.com, cl@linux.com, akpm@linux-foundation.org, liuj97@gmail.com X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" When calling remove_memory(), the memory should be offline. If the function is used to online memory, kernel panic may occur. So the patch checks whether memory is offline or not. CC: David Rientjes CC: Jiang Liu CC: Len Brown CC: Christoph Lameter Cc: Minchan Kim CC: Andrew Morton CC: KOSAKI Motohiro Signed-off-by: Wen Congyang Signed-off-by: Yasuaki Ishimatsu --- drivers/base/memory.c | 39 +++++++++++++++++++++++++++++++++++++++ include/linux/memory.h | 5 +++++ mm/memory_hotplug.c | 17 +++++++++++++++-- 3 files changed, 59 insertions(+), 2 deletions(-) Index: linux-3.6/drivers/base/memory.c =================================================================== --- linux-3.6.orig/drivers/base/memory.c 2012-10-04 14:22:57.000000000 +0900 +++ linux-3.6/drivers/base/memory.c 2012-10-04 14:45:46.653585860 +0900 @@ -70,6 +70,45 @@ void unregister_memory_isolate_notifier( } EXPORT_SYMBOL(unregister_memory_isolate_notifier); +bool is_memblk_offline(unsigned long start, unsigned long size) +{ + struct memory_block *mem = NULL; + struct mem_section *section; + unsigned long start_pfn, end_pfn; + unsigned long pfn, section_nr; + + start_pfn = PFN_DOWN(start); + end_pfn = PFN_UP(start + size); + + for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) { + section_nr = pfn_to_section_nr(pfn); + if (!present_section_nr(section_nr)) + continue; + + section = __nr_to_section(section_nr); + /* same memblock? */ + if (mem) + if ((section_nr >= mem->start_section_nr) && + (section_nr <= mem->end_section_nr)) + continue; + + mem = find_memory_block_hinted(section, mem); + if (!mem) + continue; + if (mem->state == MEM_OFFLINE) + continue; + + kobject_put(&mem->dev.kobj); + return false; + } + + if (mem) + kobject_put(&mem->dev.kobj); + + return true; +} +EXPORT_SYMBOL(is_memblk_offline); + /* * register_memory - Setup a sysfs device for a memory block */ Index: linux-3.6/include/linux/memory.h =================================================================== --- linux-3.6.orig/include/linux/memory.h 2012-10-02 18:00:22.000000000 +0900 +++ linux-3.6/include/linux/memory.h 2012-10-04 14:44:40.902581028 +0900 @@ -106,6 +106,10 @@ static inline int memory_isolate_notify( { return 0; } +static inline bool is_memblk_offline(unsigned long start, unsigned long size) +{ + return false; +} #else extern int register_memory_notifier(struct notifier_block *nb); extern void unregister_memory_notifier(struct notifier_block *nb); @@ -120,6 +124,7 @@ extern int memory_isolate_notify(unsigne extern struct memory_block *find_memory_block_hinted(struct mem_section *, struct memory_block *); extern struct memory_block *find_memory_block(struct mem_section *); +extern bool is_memblk_offline(unsigned long start, unsigned long size); #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<