Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp6972429imm; Tue, 28 Aug 2018 04:27:08 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbh5eBCnjf+nyCoWwhdHC6N8BmO075fVmb7zISgVQ7UdMkK5ENAcRtBGs5mTy9gPkuOgpB/ X-Received: by 2002:a17:902:8a90:: with SMTP id p16-v6mr1164162plo.106.1535455628087; Tue, 28 Aug 2018 04:27:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535455628; cv=none; d=google.com; s=arc-20160816; b=h6/1NaSqaODSxIti/plCWLq7zn+1JP14Mky58uxR2SCVbeYQbLsmS6ww8oBhr/1Wkm tyOHIachGR+tgX0NeHjdDuYakI9lGmc8UGJbufUr0Gcl0oaul9cmOadSWg0cFr/q/Y/p sy5KkwEaJbHxXH/hfp5M+z3GyXJXQh6avuzKRagHGetOOEbMPvgUHHJ8bECiFyA8IUBK NX7W+faUWi2UUJM375JD1Kie+KB7wG8z17L79hnZiY0+Dlf4qh+5g2g8WD0lJoN7ysjy fusL0jPxWB0hyVzJkP1WUFJCg6GVfdUOII+SWpgF6CsCrxdfuhgeKT9E3qeXG+EWmpiH Wrzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=KnzUXGTXpBqATXc0b4FKQGcxyScQHn5OR6X8aFVugFo=; b=UTZVGmi1imPQyizndNq7cucC4LxAN56GLc8Z74CNEizHWKApZWhEQiO94LxqERYx9q 3EX6uBX/JRPTrbyY2k7gNy7AAtwCzmhar7+NbSZHs05fBpQvQiTdF2lo7UTfbYnLwFsu Pi4k37h7gxDuig5oC9cMu0vbfYLj79bPEw8+q7xct1mppFYPZldo9EYuLwZsKMFxndvL hKh4GGPsyJrC1osGxn0+WLEMwii/Pa+j6L9+3qU24XJRohtiV3ct9NgQsX2zWxCtYKkm h97Yn9OZuzZD+oBhmHU/tV8Irqc5ZcTtfgfBi8+YYVdQj5Bv0C8I3ks7JXHDeH4SaFcP m4VA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e27-v6si843454pgn.253.2018.08.28.04.26.52; Tue, 28 Aug 2018 04:27:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727671AbeH1PQ5 (ORCPT + 99 others); Tue, 28 Aug 2018 11:16:57 -0400 Received: from mx2.suse.de ([195.135.220.15]:50938 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727201AbeH1PQ5 (ORCPT ); Tue, 28 Aug 2018 11:16:57 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DA266AEA5; Tue, 28 Aug 2018 11:25:43 +0000 (UTC) Date: Tue, 28 Aug 2018 13:25:43 +0200 From: Michal Hocko To: Mikhail Zaslonko Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, pasha.tatashin@oracle.com Subject: Re: [PATCH] memory_hotplug: fix kernel_panic on offline page processing Message-ID: <20180828112543.GK10223@dhcp22.suse.cz> References: <20180828090539.41491-1-zaslonko@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180828090539.41491-1-zaslonko@linux.ibm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 28-08-18 11:05:39, Mikhail Zaslonko wrote: > Within show_valid_zones() the function test_pages_in_a_zone() should be > called for online memory blocks only. Otherwise it might lead to the > VM_BUG_ON due to uninitialized struct pages (when CONFIG_DEBUG_VM_PGFLAGS > kernel option is set): > > page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p)) > ------------[ cut here ]------------ > Call Trace: > ([<000000000038f91e>] test_pages_in_a_zone+0xe6/0x168) > [<0000000000923472>] show_valid_zones+0x5a/0x1a8 > [<0000000000900284>] dev_attr_show+0x3c/0x78 > [<000000000046f6f0>] sysfs_kf_seq_show+0xd0/0x150 > [<00000000003ef662>] seq_read+0x212/0x4b8 > [<00000000003bf202>] __vfs_read+0x3a/0x178 > [<00000000003bf3ca>] vfs_read+0x8a/0x148 > [<00000000003bfa3a>] ksys_read+0x62/0xb8 > [<0000000000bc2220>] system_call+0xdc/0x2d8 > > That VM_BUG_ON was triggered by the page poisoning introduced in > mm/sparse.c with the git commit d0dc12e86b31 ("mm/memory_hotplug: optimize > memory hotplug") > With the same commit the new 'nid' field has been added to the struct > memory_block in order to store and later on derive the node id for offline > pages (instead of accessing struct page which might be uninitialized). But > one reference to nid in show_valid_zones() function has been overlooked. > Fixed with current commit. > Also, nr_pages will not be used any more after test_pages_in_a_zone() call, > do not update it. > > Fixes: d0dc12e86b31 ("mm/memory_hotplug: optimize memory hotplug") > Cc: # v4.17+ > Cc: Pavel Tatashin > Signed-off-by: Mikhail Zaslonko Btw. this land mines which are basically impossible to find during the review are the reason why I was not all that happy about d0dc12e86b31. It added a margninal improvement but opened a can of warms. On the other hand maybe we just had to open that can one day... Acked-by: Michal Hocko Thanks! > --- > drivers/base/memory.c | 20 +++++++++----------- > 1 file changed, 9 insertions(+), 11 deletions(-) > > diff --git a/drivers/base/memory.c b/drivers/base/memory.c > index f5e560188a18..622ab8edc035 100644 > --- a/drivers/base/memory.c > +++ b/drivers/base/memory.c > @@ -416,26 +416,24 @@ static ssize_t show_valid_zones(struct device *dev, > struct zone *default_zone; > int nid; > > - /* > - * The block contains more than one zone can not be offlined. > - * This can happen e.g. for ZONE_DMA and ZONE_DMA32 > - */ > - if (!test_pages_in_a_zone(start_pfn, start_pfn + nr_pages, &valid_start_pfn, &valid_end_pfn)) > - return sprintf(buf, "none\n"); > - > - start_pfn = valid_start_pfn; > - nr_pages = valid_end_pfn - start_pfn; > - > /* > * Check the existing zone. Make sure that we do that only on the > * online nodes otherwise the page_zone is not reliable > */ > if (mem->state == MEM_ONLINE) { > + /* > + * The block contains more than one zone can not be offlined. > + * This can happen e.g. for ZONE_DMA and ZONE_DMA32 > + */ > + if (!test_pages_in_a_zone(start_pfn, start_pfn + nr_pages, > + &valid_start_pfn, &valid_end_pfn)) > + return sprintf(buf, "none\n"); > + start_pfn = valid_start_pfn; > strcat(buf, page_zone(pfn_to_page(start_pfn))->name); > goto out; > } > > - nid = pfn_to_nid(start_pfn); > + nid = mem->nid; > default_zone = zone_for_pfn_range(MMOP_ONLINE_KEEP, nid, start_pfn, nr_pages); > strcat(buf, default_zone->name); > > -- > 2.16.4 -- Michal Hocko SUSE Labs