Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp273239imu; Thu, 20 Dec 2018 22:05:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/WL2SO7JbrEE0G/3ymI/9Rw5z2CqABeUKOOcGJR669hhdZl51FAh0/MGLICarMoEXBP7yTd X-Received: by 2002:a62:6f88:: with SMTP id k130mr1195426pfc.234.1545372329417; Thu, 20 Dec 2018 22:05:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545372329; cv=none; d=google.com; s=arc-20160816; b=W1i+/GzfifBGQz57cnFrFlFoxDfap2VPcY4k/V8K7hEHN7u7DEPv/XQWWQ/YmwLEyX qzCdbcmqEhMnuwkmQHb1Ecd/T5bCInI6zSHQ9TPB9hZYDRWZzoArbdGy4/8Fn7icGJxn V78kumLLamKNzlIH1dxfvBuYl4QIfLHToAYGYbHVTR+hE4uLWlVBiZyuHiCfqWA5x7M0 gI0k4CDTtsaMHUrQNb3uRhqB+fEZxZ86QH6zdvgcgiiPUf32SHHrsBh5Ir3MJkIesCBx cIdUAv2VA10o7eUheJzYQyPlzSF0B27m9e7BrXKPPILgikXsLKmUwQ/jxrtkO6rCGX4R iuGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=yq3ZTpArJ65xR7vS5wrDTyHhQPaJMh6dRpk8JU+kLhI=; b=XepWY5NiDgqBZLSFMuVN3AdXHmbkaOlV9gKIAFgZH6Gg3D2Hqul1LrXnVSyXRydye2 iSNUIEcBDLVji+HAbkgeuuHz3kgWsTdK/NhEALsJY5qBkOIMVajhgCI9XUI1aAIfX2SE 72Wd9gmjnIJGK5T0nx/vriOwqIej8fgm4V7z07l8b7EcYEdSL3yxiPx67219FjgjtEnt po1lMMCiU4p3MGJ9ZaCKt/ihDL5qM5M04GPHTNvBMBGSIT0HLEzMuirmRZNjfS41VRoo ZqTVYV2pnrD00gN/WrvE1SI0sTc4t1ZeFtSdEfdc78A9TfrefI0fHhs8J2hr0bBuF5QW 5cqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=HZ3RnyoZ; 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 b11si21147469pla.405.2018.12.20.22.05.13; Thu, 20 Dec 2018 22:05:29 -0800 (PST) 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=@lca.pw header.s=google header.b=HZ3RnyoZ; 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 S1730621AbeLTSus (ORCPT + 99 others); Thu, 20 Dec 2018 13:50:48 -0500 Received: from mail-qt1-f194.google.com ([209.85.160.194]:45482 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725790AbeLTSus (ORCPT ); Thu, 20 Dec 2018 13:50:48 -0500 Received: by mail-qt1-f194.google.com with SMTP id e5so2945858qtr.12 for ; Thu, 20 Dec 2018 10:50:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lca.pw; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yq3ZTpArJ65xR7vS5wrDTyHhQPaJMh6dRpk8JU+kLhI=; b=HZ3RnyoZNMY522zSp+KvJeNvFAbnkoBvV/STbY1JVwgxqfObTw6doYEoRFV71G5Nj1 Z9z3BA2oRfpjVsRwORk8NasgatBYjl11tXnbsa8OtRuxPeVduwEV/2pJ9jSwVvvLYVaV ojQ2bvmCJhGKtyKsxWxLArAA0YnRfIP4DO4AljsqqY3bdK4f0FYygzo7xylYaBzF9VHS k41nTz/yYTAMtHG9jJDQgNaM17w6IENllMH6NsRLx7bxtW5K4GPyThADeQEjeggqsHCA zcsXaHLR2bZasQ2H4QGi/ifnyS+n9zdPhvWuGyy6ngjK5wKIHP4NxkNkI+o+rJz8ko3l +1Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yq3ZTpArJ65xR7vS5wrDTyHhQPaJMh6dRpk8JU+kLhI=; b=L6J2KpC1pYcRiQGstphOcb82rTdUmEOGQ7IxoRDiFO9cG6LWBlL6iWL3maboG2F1iK EclPAL3DYKDb0lMuEZLhNCbQ5ku4xe+2M9V/jnEvR/NuWxQYdQo3SjWrdJkcwwkfaTd7 7OqQC8mQlUfWovMpZ3NycLFowbiY1Xp9GCbpNebfsaFmIzh+NzfwbO+yjxuJ/p3IAfd9 phA55FBOLAgSCjWoK0GQKKj1iAQ/8UgiEbqsYxq/wrAk7JHRCDJIMXamTqMGADoSEv68 IQPv3qum7tbYVwkzWCNaUKeWvXkMhm9akMvgH7b2XfWRcIOCC7pMgvkWMJ0Z3dK9Rt7p FuDQ== X-Gm-Message-State: AA+aEWbpCK6jj8LXPtN74FEx0roPVbOEjDGCp8KH0676cWBeG14MWP+B Ti2AsiDqNNqkW4hHoGzGWfR1XA== X-Received: by 2002:a0c:c138:: with SMTP id f53mr27296546qvh.225.1545331847044; Thu, 20 Dec 2018 10:50:47 -0800 (PST) Received: from ovpn-120-55.rdu2.redhat.com (pool-71-184-117-43.bstnma.fios.verizon.net. [71.184.117.43]) by smtp.gmail.com with ESMTPSA id x41sm5039029qth.92.2018.12.20.10.50.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Dec 2018 10:50:46 -0800 (PST) From: Qian Cai To: akpm@linux-foundation.org Cc: mhocko@suse.com, Pavel.Tatashin@microsoft.com, mingo@kernel.org, hpa@zytor.com, mgorman@techsingularity.net, tglx@linutronix.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qian Cai Subject: [PATCH v2] mm/page_owner: fix for deferred struct page init Date: Thu, 20 Dec 2018 13:50:31 -0500 Message-Id: <20181220185031.43146-1-cai@lca.pw> X-Mailer: git-send-email 2.17.2 (Apple Git-113) In-Reply-To: <20181220092202.GD14234@dhcp22.suse.cz> References: <20181220092202.GD14234@dhcp22.suse.cz> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. [ 8.666047] UBSAN: Undefined behaviour in ./include/linux/mm.h:1104:50 [ 8.672603] 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 Although later it tries to set page flags for pages in reserved bootmem regions, mm_init mem_init memblock_free_all free_low_memory_core_early reserve_bootmem_region there could still have some freed pages from the page allocator but yet to be initialized due to DEFERRED_STRUCT_PAGE_INIT. It have already been dealt with a bit in page_ext_init(). * Take into account DEFERRED_STRUCT_PAGE_INIT. */ if (early_pfn_to_nid(pfn) != nid) continue; However it did not handle it well in init_pages_in_zone() which end up calling page_to_nid(). [ 11.917212] page:ffffea0004200000 is uninitialized and poisoned [ 11.917220] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff [ 11.921745] raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff [ 11.924523] page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p)) [ 11.926498] page_owner info is not active (free page?) [ 12.329560] kernel BUG at include/linux/mm.h:990! [ 12.337632] RIP: 0010:init_page_owner+0x486/0x520 Since there is no other routines depend on page_ext_init() in start_kernel() and no real benefit to call it so early, just move it after page_alloc_init_late() to ensure that there is no deferred pages need to de dealt with. Suggested-by: Michal Hocko Signed-off-by: Qian Cai --- v2: postpone init_page_ext() to after page_alloc_init_late(). init/main.c | 2 +- mm/page_ext.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/init/main.c b/init/main.c index 2b7b7fe173c9..1aeb062b2cb7 100644 --- a/init/main.c +++ b/init/main.c @@ -696,7 +696,6 @@ asmlinkage __visible void __init start_kernel(void) initrd_start = 0; } #endif - page_ext_init(); kmemleak_init(); setup_per_cpu_pageset(); numa_policy_init(); @@ -1147,6 +1146,7 @@ static noinline void __init kernel_init_freeable(void) sched_init_smp(); page_alloc_init_late(); + page_ext_init(); do_basic_setup(); diff --git a/mm/page_ext.c b/mm/page_ext.c index ae44f7adbe07..d76fd51e312a 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -399,9 +399,8 @@ void __init page_ext_init(void) * -------------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.17.2 (Apple Git-113)