1 From bc0c88889784544219b105d48b313218514965d9 Mon Sep 17 00:00:00 2001
2 From: Qian Cai <cai@lca.pw>
3 Date: Tue, 12 Feb 2019 15:36:03 -0800
4 Subject: Revert "mm: use early_pfn_to_nid in page_ext_init"
6 [ Upstream commit 2f1ee0913ce58efe7f18fbd518bd54c598559b89 ]
8 This reverts commit fe53ca54270a ("mm: use early_pfn_to_nid in
11 When booting a system with "page_owner=on",
18 init_early_allocated_pages
24 The issue here is that page_to_nid() will not work since some page flags
25 have no node information until later in page_alloc_init_late() due to
26 DEFERRED_STRUCT_PAGE_INIT. Hence, it could trigger an out-of-bounds
27 access with an invalid nid.
29 UBSAN: Undefined behaviour in ./include/linux/mm.h:1104:50
30 index 7 is out of range for type 'zone [5]'
32 Also, kernel will panic since flags were poisoned earlier with,
34 CONFIG_DEBUG_VM_PGFLAGS=y
35 CONFIG_NODE_NOT_IN_PAGE_FLAGS=n
43 memblock_alloc_try_nid_raw
45 It did not handle it well in init_pages_in_zone() which ends up calling
48 page:ffffea0004200000 is uninitialized and poisoned
49 raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff
50 raw: ffffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffff
51 page dumped because: VM_BUG_ON_PAGE(PagePoisoned(p))
52 page_owner info is not active (free page?)
53 kernel BUG at include/linux/mm.h:990!
54 RIP: 0010:init_page_owner+0x486/0x520
56 This means that assumptions behind commit fe53ca54270a ("mm: use
57 early_pfn_to_nid in page_ext_init") are incomplete. Therefore, revert
58 the commit for now. A proper way to move the page_owner initialization
59 to sooner is to hook into memmap initialization.
61 Link: http://lkml.kernel.org/r/20190115202812.75820-1-cai@lca.pw
62 Signed-off-by: Qian Cai <cai@lca.pw>
63 Acked-by: Michal Hocko <mhocko@kernel.org>
64 Cc: Pasha Tatashin <Pavel.Tatashin@microsoft.com>
65 Cc: Mel Gorman <mgorman@techsingularity.net>
66 Cc: Yang Shi <yang.shi@linaro.org>
67 Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
68 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
69 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
70 Signed-off-by: Sasha Levin <sashal@kernel.org>
73 mm/page_ext.c | 4 +---
74 2 files changed, 3 insertions(+), 4 deletions(-)
76 diff --git a/init/main.c b/init/main.c
77 index c4a45145e102..3d3d79c5a232 100644
80 @@ -663,7 +663,6 @@ asmlinkage __visible void __init start_kernel(void)
86 debug_objects_mem_init();
87 setup_per_cpu_pageset();
88 @@ -1069,6 +1068,8 @@ static noinline void __init kernel_init_freeable(void)
91 page_alloc_init_late();
92 + /* Initialize page ext after all struct pages are initialized. */
97 diff --git a/mm/page_ext.c b/mm/page_ext.c
98 index 2c16216c29b6..2c44f5b78435 100644
101 @@ -396,10 +396,8 @@ void __init page_ext_init(void)
102 * We know some arch can have a nodes layout such as
103 * -------------pfn-------------->
104 * N0 | N1 | N2 | N0 | N1 | N2|....
106 - * Take into account DEFERRED_STRUCT_PAGE_INIT.
108 - if (early_pfn_to_nid(pfn) != nid)
109 + if (pfn_to_nid(pfn) != nid)
111 if (init_section_page_ext(pfn, nid))