From patchwork Wed Nov 7 07:40:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tang Chen X-Patchwork-Id: 197630 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 134662C008C for ; Wed, 7 Nov 2012 18:42:07 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753404Ab2KGHmE (ORCPT ); Wed, 7 Nov 2012 02:42:04 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:8313 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751726Ab2KGHmB (ORCPT ); Wed, 7 Nov 2012 02:42:01 -0500 X-IronPort-AV: E=Sophos;i="4.80,727,1344182400"; d="scan'208";a="6153615" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 07 Nov 2012 15:40:20 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id qA77fpqY013651; Wed, 7 Nov 2012 15:41:51 +0800 Received: from [10.167.225.117] ([10.167.225.117]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2012110715405759-998082 ; Wed, 7 Nov 2012 15:40:57 +0800 Message-ID: <509A107C.9050702@cn.fujitsu.com> Date: Wed, 07 Nov 2012 15:40:44 +0800 From: Tang Chen User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: wency@cn.fujitsu.com CC: x86@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-acpi@vger.kernel.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-ia64@vger.kernel.org, cmetcalf@tilera.com, sparclinux@vger.kernel.org, rientjes@google.com, liuj97@gmail.com, len.brown@intel.com, benh@kernel.crashing.org, paulus@samba.org, cl@linux.com, minchan.kim@gmail.com, akpm@linux-foundation.org, kosaki.motohiro@jp.fujitsu.com, isimatu.yasuaki@jp.fujitsu.com Subject: [PATCH] Update start_pfn in zone and pg_data when spanned_pages == 0. References: <1350988250-31294-1-git-send-email-wency@cn.fujitsu.com> <1350988250-31294-11-git-send-email-wency@cn.fujitsu.com> In-Reply-To: <1350988250-31294-11-git-send-email-wency@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/11/07 15:40:57, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/11/07 15:41:03, Serialize complete at 2012/11/07 15:41:03 Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org On 10/23/2012 06:30 PM, wency@cn.fujitsu.com wrote: > From: Yasuaki Ishimatsu ...... > + /* The zone has no valid section */ > + zone->zone_start_pfn = 0; > + zone->spanned_pages = 0; > + zone_span_writeunlock(zone); > +} > + > +static void shrink_pgdat_span(struct pglist_data *pgdat, > + unsigned long start_pfn, unsigned long end_pfn) > +{ ...... > + /* The pgdat has no valid section */ > + pgdat->node_start_pfn = 0; > + pgdat->node_spanned_pages = 0; > +} Hi, If we hot-remove memory only and leave the cpus alive, the corresponding node will not be removed. But the node_start_pfn and node_spanned_pages in pg_data will be reset to 0. In this case, when we hot-add the memory back next time, the node_start_pfn will always be 0 because no pfn is less than 0. After that, if we hot-remove the memory again, it will cause kernel panic in function find_biggest_section_pfn() when it tries to scan all the pfns. The zone will also have the same problem. This patch sets start_pfn to the start_pfn of the section being added when spanned_pages of the zone or pg_data is 0. ---How to reproduce--- 1. hot-add a container with some memory and cpus; 2. hot-remove the container's memory, and leave cpus there; 3. hot-add these memory again; 4. hot-remove them again; then, the kernel will panic. ---Call trace--- [10530.646285] BUG: unable to handle kernel paging request at 00000fff82a8cc38 [10530.729670] IP: [] find_biggest_section_pfn+0xe5/0x180 ...... [10533.064975] Call Trace: [10533.094162] [] ? __remove_zone+0x2f/0x1b0 [10533.161757] [] __remove_zone+0x184/0x1b0 [10533.228318] [] __remove_section+0x8c/0xb0 [10533.295916] [] __remove_pages+0xe7/0x120 [10533.362476] [] arch_remove_memory+0x2c/0x80 [10533.432151] [] remove_memory+0x56/0x90 [10533.496633] [] acpi_memory_device_remove_memory+0x48/0x73 [10533.580846] [] acpi_memory_device_notify+0x153/0x274 [10533.659865] [] ? acpi_bus_get_device+0x2f/0x77 [10533.732653] [] ? acpi_bus_notify+0xb5/0xec [10533.801291] [] acpi_ev_notify_dispatch+0x41/0x5f [10533.876156] [] acpi_os_execute_deferred+0x27/0x34 [10533.952062] [] process_one_work+0x219/0x680 [10534.021736] [] ? process_one_work+0x1b8/0x680 [10534.093488] [] ? acpi_os_wait_events_complete+0x23/0x23 [10534.175622] [] worker_thread+0x12e/0x320 [10534.242181] [] ? manage_workers+0x110/0x110 [10534.311855] [] kthread+0xc6/0xd0 [10534.370111] [] kernel_thread_helper+0x4/0x10 [10534.440824] [] ? retint_restore_args+0x13/0x13 [10534.513612] [] ? __init_kthread_worker+0x70/0x70 [10534.588480] [] ? gs_change+0x13/0x13 ...... [10535.045543] ---[ end trace 96d845dbf33fee11 ]--- Signed-off-by: Tang Chen --- mm/memory_hotplug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) zone->spanned_pages = max(old_zone_end_pfn, end_pfn) - @@ -227,7 +227,7 @@ static void grow_pgdat_span(struct pglist_data *pgdat, unsigned long start_pfn, unsigned long old_pgdat_end_pfn = pgdat->node_start_pfn + pgdat->node_spanned_pages; - if (start_pfn < pgdat->node_start_pfn) + if (!pgdat->node_spanned_pages || start_pfn < pgdat->node_start_pfn) pgdat->node_start_pfn = start_pfn; pgdat->node_spanned_pages = max(old_pgdat_end_pfn, end_pfn) - diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 56b758a..4aa313c 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -212,7 +212,7 @@ static void grow_zone_span(struct zone *zone, unsigned long start_pfn, zone_span_writelock(zone); old_zone_end_pfn = zone->zone_start_pfn + zone->spanned_pages; - if (start_pfn < zone->zone_start_pfn) + if (!zone->spanned_pages || start_pfn < zone->zone_start_pfn) zone->zone_start_pfn = start_pfn;