From patchwork Thu Dec 20 18:50:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qian Cai X-Patchwork-Id: 10739357 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E86D6C5 for ; Thu, 20 Dec 2018 18:50:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E05128E06 for ; Thu, 20 Dec 2018 18:50:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE43228E2A; Thu, 20 Dec 2018 18:50:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 864F128E06 for ; Thu, 20 Dec 2018 18:50:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9489A8E000B; Thu, 20 Dec 2018 13:50:48 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 91FA58E0001; Thu, 20 Dec 2018 13:50:48 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80EBC8E000B; Thu, 20 Dec 2018 13:50:48 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by kanga.kvack.org (Postfix) with ESMTP id 590418E0001 for ; Thu, 20 Dec 2018 13:50:48 -0500 (EST) Received: by mail-qt1-f197.google.com with SMTP id d35so2828204qtd.20 for ; Thu, 20 Dec 2018 10:50:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=yq3ZTpArJ65xR7vS5wrDTyHhQPaJMh6dRpk8JU+kLhI=; b=i48bV+1ayfFCELbUrOyYfnYae2Ncop6/QSVPxpUbJxuIqXXyF756YGaxwgAj+EDUFq jnMTFQV1nb5Gvhkn+gC8YZhbJ/lvauFjiARkrLlOmtqLWPh4pudnNetFMAtyzqXGdM/x OVb7HJYVYO6cdmzV5uvNEtAlks7Ee21EMApxlmKqB/MIGd1uo10W6wEeaZdsbdk7kfpL KhtEHxqJ+LxD/eWn/ckKyYqegL75iFoG+ZcHrDmQ+rwhwaWHV85NbqdXhxj05yo7kVfF O05ITHbMH2R93Anv8YekGVQRj97vkm6otTxve5+/HxzGxatxwNpRcftWLGA8s8DpZsb+ BwDg== X-Gm-Message-State: AA+aEWZzhKISUb1IO/JL+f6w/ztmkq6IYth0ZW6wGPMQy6aprKx4Ueqg nDzzxWptCAMjeouWUhuLWcVVgmS9IstWcAMIBIYtt7B4FHUo6pZvrMr65DywC0Jg2s+igdJ+40v qaVOWYtuyedN5PjwGIq1K4AHVzOBXdju3/OiWmTa7Qz/S8DTrQQtcbluZaWGwvuxxb6b1JAgsTp QGMtiO7k5zEfOkl5mDz2j3ynza2RTb5MKptNPsrP7TctAF5Oa7xaVscp2NWekua2R6WVWakW6ms U9SVlyP1BobrNQvSu4/136rbZXb+WPLwWI7taMtV0Be471QWXLDbAtM52DzGJ/dAWptsxe9XqDo l1nsYshMdP3tjmCWqdgk9mTS18cc5AU1kkhJ/IOMdWMXeP4zQsCJpZkGH7y+AMOJQJzyhaG1Uuj K X-Received: by 2002:a37:8e41:: with SMTP id q62mr26742539qkd.290.1545331848048; Thu, 20 Dec 2018 10:50:48 -0800 (PST) X-Received: by 2002:a37:8e41:: with SMTP id q62mr26742499qkd.290.1545331847336; Thu, 20 Dec 2018 10:50:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545331847; cv=none; d=google.com; s=arc-20160816; b=oSO7k4144vye5CktCN+sbSmH7c019uOoHDJHi5ig/qaiSrFrUm7hNWquu7UN52fODO wOv8jdrAW3lojmtTloSVbZyQO4jgxBmGgh/YjSLAqOcLBedb23S9si+jbMos8cTO238w edSYYn+jy7Qow14sQRejWuyjQ504RZ8jakAjr75M+zmNvVEnOZQiyT9Lmrid2OwhpY/r d1xHLDqylXo7XCOiZqtLsjw2J75byNydNPkp5EMMXbUVyuDCeyw9TA2kU0ViaNJN5Inc qCBWfZui+HZ1V/SzY0msa1U6w712QV9uDdMaEiOSWkzpBRlW6ylbtycABbQFt6VNHZct WaXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yq3ZTpArJ65xR7vS5wrDTyHhQPaJMh6dRpk8JU+kLhI=; b=ly4Jq4P4k55Y3oF4kUwyAb/8qZyQ4ba2QJn7UBF86cyWwbR3Xi2YFIN4KrKBQCZPde jQAgdAXdp/51mqsXPm31yOk4DOg2ajmNY5L8HniHXI+KJ9esB1eSVVjGHJG8Sa48D5LX JKyzHcqqp1lA9XhCjrMk/uLe+KhiArNuN96EOpeABfao5CZj13eBPQMDQqj6UW2K3Etn bOBy2JV9WZVpCMQQ1Xx6VrMR7QxT3i2X8UqrD3gQPfXvuIBHA03md2oB4pa4AtQ+w8F1 0YUUTjKzS5IotOMDxdR0KoS9QAqsy+qqbUctr9uYBxT8P8NuRknnJ3NBbnQiH0TG5gGJ kP3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=HZ3RnyoZ; spf=pass (google.com: domain of cai@lca.pw designates 209.85.220.65 as permitted sender) smtp.mailfrom=cai@lca.pw Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id o29sor7677357qve.37.2018.12.20.10.50.47 for (Google Transport Security); Thu, 20 Dec 2018 10:50:47 -0800 (PST) Received-SPF: pass (google.com: domain of cai@lca.pw designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@lca.pw header.s=google header.b=HZ3RnyoZ; spf=pass (google.com: domain of cai@lca.pw designates 209.85.220.65 as permitted sender) smtp.mailfrom=cai@lca.pw 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-Smtp-Source: AFSGD/UUZQ+L2tM6RsHMVVOTnr7egfA7T30tyafFfjmccIjIdQ9b94Q51cnQbFjN67cp6omFQObPQw== 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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Michal Hocko --- 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;