Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp602559img; Fri, 22 Mar 2019 04:59:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYq0qWVsrXMWGGmUliRy9SmzHvdyNNoz7oljQesKHJWLJGExXyWbn9g6Dr/fufIUvUPpdt X-Received: by 2002:aa7:8ad4:: with SMTP id b20mr2310732pfd.249.1553255977396; Fri, 22 Mar 2019 04:59:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553255977; cv=none; d=google.com; s=arc-20160816; b=uSpOlBVn8RecUilVz/vfiz0L23R2NIRfN7ZmJnN13IArQT77JrVOMpNAuLoCGID+6o Uj4X8cT4tidgKQUBqrDH0u1BWet7/TbV1vnBqi+M+8RiXaoUhBF4fTBD6iYimgDRgkeT 38qa4xNMXfapxln5t3CowHTxM+RnVMVPPFD5C+IgUwa4qJ2WK0PSsfr6pndj5H08ijll H2ASALK+bQ3I+uM441DeqBM7/Py1mjvwlCkd+M8mGgLK3ETk2ZqXBaJRixldDm+vExJ0 zF60rBgk5pwfXcR8VgVrz4BFsYu4FKwSxzvUOzxgpkNGE5bBaA5Upvy4SX0b/wgoIK2m 6roA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jwy4KaChthfoIR5Mv4MBlDcktRBaWv/8AkGp5moEw6w=; b=p0K/e+bHyB9QgDWbBM+Fedda4YyRFtFJWsaVvXvdSZoV9+k7E4rjTdmE6INHpIicIa FyuWe7U58VP37hCinv6xgPfTsMXdVbdvwbhd5EMaauMqp3u9R7rJrT9jZhc+BvXJTb0P z0xND+9p6nHYXvVfvtLlyB/d7+s6D2MzHnjEChRJt0LDqMPJlb4l3TBsMieA1XKNhUBv 84Egkr6V7aJW0Ia017l7efxwId7PfKEiyjV8cVO5vrFNvcXL5Uk/pWng+N0zmMJIMlmJ DHYT4DRVYk0aVjjahf6ejsSLQB6mKencfCFs+h42VwzW4x2/EyfAxGhni2KPTc8a9OrS qrlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HvClub6w; 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 t18si6859649plr.78.2019.03.22.04.59.22; Fri, 22 Mar 2019 04:59:37 -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; dkim=pass header.i=@kernel.org header.s=default header.b=HvClub6w; 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 S2387891AbfCVL6u (ORCPT + 99 others); Fri, 22 Mar 2019 07:58:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:35634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387864AbfCVL6s (ORCPT ); Fri, 22 Mar 2019 07:58:48 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6B1782192D; Fri, 22 Mar 2019 11:58:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553255927; bh=cpOOE8+ctAfVCGpx4KTQauuKUXK3gmGizv8TwzSMb1s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HvClub6wQkEz/PfHQEaOBqLy+sEHi76It5GbbRErEBUlPc5cUvXEhTbrMDhNHW6VE 7vVMmuWC7sERlGTKO159lkAn9p24fSFEegJROXWDqlPbl7qhJ2c0Egi4E9HdhY6c0Z QMSKAxxQxRZPFoOkj53C/SoX4H2sIloINPaENTYM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qian Cai , Michal Hocko , Pasha Tatashin , Mel Gorman , Yang Shi , Joonsoo Kim , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.19 057/280] Revert "mm: use early_pfn_to_nid in page_ext_init" Date: Fri, 22 Mar 2019 12:13:30 +0100 Message-Id: <20190322111309.483456856@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190322111306.356185024@linuxfoundation.org> References: <20190322111306.356185024@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 2f1ee0913ce58efe7f18fbd518bd54c598559b89 ] This reverts commit fe53ca54270a ("mm: use early_pfn_to_nid in page_ext_init"). When booting a system with "page_owner=on", start_kernel page_ext_init invoke_init_callbacks init_section_page_ext init_page_owner init_early_allocated_pages init_zones_in_node init_pages_in_zone lookup_page_ext page_to_nid The issue here is that page_to_nid() will not work since some page flags have no node information until later in page_alloc_init_late() due to DEFERRED_STRUCT_PAGE_INIT. Hence, it could trigger an out-of-bounds access with an invalid nid. UBSAN: Undefined behaviour in ./include/linux/mm.h:1104:50 index 7 is out of range for type 'zone [5]' Also, kernel will panic since flags were poisoned earlier with, CONFIG_DEBUG_VM_PGFLAGS=y CONFIG_NODE_NOT_IN_PAGE_FLAGS=n start_kernel setup_arch pagetable_init paging_init sparse_init sparse_init_nid memblock_alloc_try_nid_raw It did not handle it well in init_pages_in_zone() which ends up calling page_to_nid(). page:ffffea0004200000 is uninitialized and poisoned raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p)) page_owner info is not active (free page?) kernel BUG at include/linux/mm.h:990! RIP: 0010:init_page_owner+0x486/0x520 This means that assumptions behind commit fe53ca54270a ("mm: use early_pfn_to_nid in page_ext_init") are incomplete. Therefore, revert the commit for now. A proper way to move the page_owner initialization to sooner is to hook into memmap initialization. Link: http://lkml.kernel.org/r/20190115202812.75820-1-cai@lca.pw Signed-off-by: Qian Cai Acked-by: Michal Hocko Cc: Pasha Tatashin Cc: Mel Gorman Cc: Yang Shi Cc: Joonsoo Kim Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- init/main.c | 3 ++- mm/page_ext.c | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/init/main.c b/init/main.c index 18f8f0140fa0..e083fac08aed 100644 --- a/init/main.c +++ b/init/main.c @@ -689,7 +689,6 @@ asmlinkage __visible void __init start_kernel(void) initrd_start = 0; } #endif - page_ext_init(); kmemleak_init(); debug_objects_mem_init(); setup_per_cpu_pageset(); @@ -1140,6 +1139,8 @@ static noinline void __init kernel_init_freeable(void) sched_init_smp(); page_alloc_init_late(); + /* Initialize page ext after all struct pages are initialized. */ + page_ext_init(); do_basic_setup(); diff --git a/mm/page_ext.c b/mm/page_ext.c index a9826da84ccb..4961f13b6ec1 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -398,10 +398,8 @@ void __init page_ext_init(void) * We know some arch can have a nodes layout such as * -------------pfn--------------> * N0 | N1 | N2 | N0 | N1 | N2|.... - * - * Take into account DEFERRED_STRUCT_PAGE_INIT. */ - if (early_pfn_to_nid(pfn) != nid) + if (pfn_to_nid(pfn) != nid) continue; if (init_section_page_ext(pfn, nid)) goto oom; -- 2.19.1