Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp577341imm; Wed, 6 Jun 2018 02:27:46 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK5c61PcSnVOyfRKBQ3f9AhIuazoCAFrKb0RiURX1rqKDdeGnRtqWR+yg+l9sBpalEm3b7Q X-Received: by 2002:a62:5d83:: with SMTP id n3-v6mr1717845pfj.68.1528277266322; Wed, 06 Jun 2018 02:27:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528277266; cv=none; d=google.com; s=arc-20160816; b=CyvP6/6ZrwBSxxELfeAFCdBNGcp7HaRlPLiZcpJw+8ag3Myw3ZHSQipibmw0psj4+j /51LM/7cRIpLX1KiQz+czZKaI/DX3HOrAvz1p1vHYU3CztliZ0MMV3g1s1QIUMVHho3o 8fcrv6aiJYla70V91tYXxS8kRuNUsrMVQiBUQzOGyIsNnm7cy+fbk7RLVH6TZSJ5SkBn Bn2DuGR/pnMekHZ8SgBKKPe7EV2gkblTLqyHazi3fyBsmmk3c4/e06ic94bjMBokVqIS khJABd3Q9W43BgVSfMuvGRTPbQBToW4rYayDWPJDbHu1FI/8Hxk7up0cW1ARGq08FsmG kEXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :arc-authentication-results; bh=B7lyOLd3PW/O9wj0pB4m3oVJ/PmWZl2W/L9i+Xqecwo=; b=SIpzu1QKnpFKj5TWq/QVjq40Ah9eDiIeevx7LFuos+oJcxHvpKTrNe9aN/JyEFEvRT J6BPdscnDWUaN/PKHI7/699ozAjx1U5Y8NCBjWZFxOlG3RCDjrmlltxjHGWsRXyVWG2j Kbgg5m7wX+VbggoqtAlFmVvrfnCQ6XUPo60ulckICiiXcD5c2Mkhvm/8Qn6gLBNcWBWf IjihQSW4qNL1eI00grWTY1kuoZtYtstH/AHD+ZWI5DNKrjI5XMbYosqI0rBDTrBYhRA0 T/Nyqr8aQ31NYXJ4F2/t/nVzsHW4JYVCcCJDaK39SWlWXx71ZJexHddWxgaMJpjn0jbe pqmA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f10-v6si5811815pgn.0.2018.06.06.02.27.32; Wed, 06 Jun 2018 02:27:46 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932497AbeFFJZw convert rfc822-to-8bit (ORCPT + 99 others); Wed, 6 Jun 2018 05:25:52 -0400 Received: from tyo162.gate.nec.co.jp ([114.179.232.162]:45886 "EHLO tyo162.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932361AbeFFJZu (ORCPT ); Wed, 6 Jun 2018 05:25:50 -0400 Received: from mailgate02.nec.co.jp ([114.179.233.122]) by tyo162.gate.nec.co.jp (8.15.1/8.15.1) with ESMTPS id w569PHi3021906 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 6 Jun 2018 18:25:17 +0900 Received: from mailsv02.nec.co.jp (mailgate-v.nec.co.jp [10.204.236.94]) by mailgate02.nec.co.jp (8.15.1/8.15.1) with ESMTP id w569PHPE014352; Wed, 6 Jun 2018 18:25:17 +0900 Received: from mail02.kamome.nec.co.jp (mail02.kamome.nec.co.jp [10.25.43.5]) by mailsv02.nec.co.jp (8.15.1/8.15.1) with ESMTP id w569Oi74008455; Wed, 6 Jun 2018 18:25:17 +0900 Received: from bpxc99gp.gisp.nec.co.jp ([10.38.151.147] [10.38.151.147]) by mail02.kamome.nec.co.jp with ESMTP id BT-MMP-1007862; Wed, 6 Jun 2018 18:24:06 +0900 Received: from BPXM23GP.gisp.nec.co.jp ([10.38.151.215]) by BPXC19GP.gisp.nec.co.jp ([10.38.151.147]) with mapi id 14.03.0319.002; Wed, 6 Jun 2018 18:24:06 +0900 From: Naoya Horiguchi To: Oscar Salvador CC: Matthew Wilcox , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , Andrew Morton , Michal Hocko , "mingo@kernel.org" , "dan.j.williams@intel.com" , Huang Ying , Pavel Tatashin Subject: Re: kernel panic in reading /proc/kpageflags when enabling RAM-simulated PMEM Thread-Topic: kernel panic in reading /proc/kpageflags when enabling RAM-simulated PMEM Thread-Index: AQHT/GeymmpDVR1XWE69lshFJtmzcqRQRpEAgABpKgCAAWucAIAALt0AgAANvoCAAAOvAIAABOqA Date: Wed, 6 Jun 2018 09:24:05 +0000 Message-ID: <20180606092405.GA6562@hori1.linux.bs1.fc.nec.co.jp> References: <20180605005402.GA22975@hori1.linux.bs1.fc.nec.co.jp> <20180605011836.GA32444@bombadil.infradead.org> <20180605073500.GA23766@hori1.linux.bs1.fc.nec.co.jp> <20180606051624.GA16021@hori1.linux.bs1.fc.nec.co.jp> <20180606080408.GA31794@techadventures.net> <20180606085319.GA32052@techadventures.net> <20180606090630.GA27065@hori1.linux.bs1.fc.nec.co.jp> In-Reply-To: <20180606090630.GA27065@hori1.linux.bs1.fc.nec.co.jp> Accept-Language: en-US, ja-JP Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.51.8.81] Content-Type: text/plain; charset="iso-2022-jp" Content-ID: <00CCDBC604631D4AA83A74F3C49903A6@gisp.nec.co.jp> Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-TM-AS-MML: disable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 06, 2018 at 09:06:30AM +0000, Horiguchi Naoya(堀口 直也) wrote: > On Wed, Jun 06, 2018 at 10:53:19AM +0200, Oscar Salvador wrote: > > On Wed, Jun 06, 2018 at 10:04:08AM +0200, Oscar Salvador wrote: > > > On Wed, Jun 06, 2018 at 05:16:24AM +0000, Naoya Horiguchi wrote: > > > > On Tue, Jun 05, 2018 at 07:35:01AM +0000, Horiguchi Naoya(堀口 直也) wrote: > > > > > On Mon, Jun 04, 2018 at 06:18:36PM -0700, Matthew Wilcox wrote: > > > > > > On Tue, Jun 05, 2018 at 12:54:03AM +0000, Naoya Horiguchi wrote: > > > > > > > Reproduction precedure is like this: > > > > > > > - enable RAM based PMEM (with a kernel boot parameter like memmap=1G!4G) > > > > > > > - read /proc/kpageflags (or call tools/vm/page-types with no arguments) > > > > > > > (- my kernel config is attached) > > > > > > > > > > > > > > I spent a few days on this, but didn't reach any solutions. > > > > > > > So let me report this with some details below ... > > > > > > > > > > > > > > In the critial page request, stable_page_flags() is called with an argument > > > > > > > page whose ->compound_head was somehow filled with '0xffffffffffffffff'. > > > > > > > And compound_head() returns (struct page *)(head - 1), which explains the > > > > > > > address 0xfffffffffffffffe in the above message. > > > > > > > > > > > > Hm. compound_head shares with: > > > > > > > > > > > > struct list_head lru; > > > > > > struct list_head slab_list; /* uses lru */ > > > > > > struct { /* Partial pages */ > > > > > > struct page *next; > > > > > > unsigned long _compound_pad_1; /* compound_head */ > > > > > > unsigned long _pt_pad_1; /* compound_head */ > > > > > > struct dev_pagemap *pgmap; > > > > > > struct rcu_head rcu_head; > > > > > > > > > > > > None of them should be -1. > > > > > > > > > > > > > It seems that this kernel panic happens when reading kpageflags of pfn range > > > > > > > [0xbffd7, 0xc0000), which coresponds to a 'reserved' range. > > > > > > > > > > > > > > [ 0.000000] user-defined physical RAM map: > > > > > > > [ 0.000000] user: [mem 0x0000000000000000-0x000000000009fbff] usable > > > > > > > [ 0.000000] user: [mem 0x000000000009fc00-0x000000000009ffff] reserved > > > > > > > [ 0.000000] user: [mem 0x00000000000f0000-0x00000000000fffff] reserved > > > > > > > [ 0.000000] user: [mem 0x0000000000100000-0x00000000bffd6fff] usable > > > > > > > [ 0.000000] user: [mem 0x00000000bffd7000-0x00000000bfffffff] reserved > > > > > > > [ 0.000000] user: [mem 0x00000000feffc000-0x00000000feffffff] reserved > > > > > > > [ 0.000000] user: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved > > > > > > > [ 0.000000] user: [mem 0x0000000100000000-0x000000013fffffff] persistent (type 12) > > > > > > > > > > > > > > So I guess 'memmap=' parameter might badly affect the memory initialization process. > > > > > > > > > > > > > > This problem doesn't reproduce on v4.17, so some pre-released patch introduces it. > > > > > > > I hope this info helps you find the solution/workaround. > > > > > > > > > > > > Can you try bisecting this? It could be one of my patches to reorder struct > > > > > > page, or it could be one of Pavel's deferred page initialisation patches. > > > > > > Or something else ;-) > > > > > > > > > > Thank you for the comment. I'm trying bisecting now, let you know the result later. > > > > > > > > > > And I found that my statement "not reproduce on v4.17" was wrong (I used > > > > > different kvm guests, which made some different test condition and misguided me), > > > > > this seems an older (at least < 4.15) bug. > > > > > > > > (Cc: Pavel) > > > > > > > > Bisection showed that the following commit introduced this issue: > > > > > > > > commit f7f99100d8d95dbcf09e0216a143211e79418b9f > > > > Author: Pavel Tatashin > > > > Date: Wed Nov 15 17:36:44 2017 -0800 > > > > > > > > mm: stop zeroing memory during allocation in vmemmap > > > > > > > > This patch postpones struct page zeroing to later stage of memory initialization. > > > > My kernel config disabled CONFIG_DEFERRED_STRUCT_PAGE_INIT so two callsites of > > > > __init_single_page() were never reached. So in such case, struct pages populated > > > > by vmemmap_pte_populate() could be left uninitialized? > > > > And I'm not sure yet how this issue becomes visible with memmap= setting. > > > > > > I think that this becomes visible because memmap=x!y creates a persistent memory region: > > > > > > parse_memmap_one > > > { > > > ... > > > } else if (*p == '!') { > > > start_at = memparse(p+1, &p); > > > e820__range_add(start_at, mem_size, E820_TYPE_PRAM); > > > ... > > > } > > > > > > and this region it is not added neither in memblock.memory nor in memblock.reserved. > > > Ranges in memblock.memory get zeroed in memmap_init_zone(), while memblock.reserved get zeroed > > > in free_low_memory_core_early(): > > > > > > static unsigned long __init free_low_memory_core_early(void) > > > { > > > ... > > > for_each_reserved_mem_region(i, &start, &end) > > > reserve_bootmem_region(start, end); > > > ... > > > } > > > > > > > > > Maybe I am mistaken, but I think that persistent memory regions should be marked as reserved. > > > A comment in do_mark_busy() suggests this: > > > > > > static bool __init do_mark_busy(enum e820_type type, struct resource *res) > > > { > > > > > > ... > > > /* > > > * Treat persistent memory like device memory, i.e. reserve it > > > * for exclusive use of a driver > > > */ > > > ... > > > } > > > > > > > > > I wonder if something like this could work and if so, if it is right (i haven't tested it yet): > > > > > > diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c > > > index 71c11ad5643e..3c9686ef74e5 100644 > > > --- a/arch/x86/kernel/e820.c > > > +++ b/arch/x86/kernel/e820.c > > > @@ -1247,6 +1247,11 @@ void __init e820__memblock_setup(void) > > > if (end != (resource_size_t)end) > > > continue; > > > > > > + if (entry->type == E820_TYPE_PRAM || entry->type == E820_TYPE_PMEM) { > > > + memblock_reserve(entry->addr, entry->size); > > > + continue; > > > + } > > > + > > > if (entry->type != E820_TYPE_RAM && entry->type != E820_TYPE_RESERVED_KERN) > > > continue; > > > > It does not seem to work, so the reasoning might be incorrect. > > Thank you for the comment. > > One note is that the memory region with "broken struct page" is a typical > reserved region, not a pmem region. Strangely reading offset 0xbffd7 of > /proc/kpageflags is OK if pmem region does not exist, but NG if pmem region exists. > Reading the offset like 0x100000 (on pmem region) does not cause the crash, > so pmem region seems properly set up. > > [ 0.000000] user-defined physical RAM map: > [ 0.000000] user: [mem 0x0000000000000000-0x000000000009fbff] usable > [ 0.000000] user: [mem 0x000000000009fc00-0x000000000009ffff] reserved > [ 0.000000] user: [mem 0x00000000000f0000-0x00000000000fffff] reserved > [ 0.000000] user: [mem 0x0000000000100000-0x00000000bffd6fff] usable > [ 0.000000] user: [mem 0x00000000bffd7000-0x00000000bfffffff] reserved ===> "broken struct page" region > [ 0.000000] user: [mem 0x00000000feffc000-0x00000000feffffff] reserved > [ 0.000000] user: [mem 0x00000000fffc0000-0x00000000ffffffff] reserved > [ 0.000000] user: [mem 0x0000000100000000-0x000000013fffffff] persistent (type 12) => pmem region > [ 0.000000] user: [mem 0x0000000140000000-0x000000023fffffff] usable > I have another note: > My kernel config disabled CONFIG_DEFERRED_STRUCT_PAGE_INIT so two callsites of > __init_single_page() were never reached. So in such case, struct pages populated > by vmemmap_pte_populate() could be left uninitialized? I quickly checked whether enabling CONFIG_DEFERRED_STRUCT_PAGE_INIT affect the issue. And found that the kernel panic happens even with this config enabled. So I'm still confused... - Naoya