]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.14/revert-mm-use-early_pfn_to_nid-in-page_ext_init.patch
drop some duplicated patches that somehow got merged.
[thirdparty/kernel/stable-queue.git] / queue-4.14 / revert-mm-use-early_pfn_to_nid-in-page_ext_init.patch
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"
5
6 [ Upstream commit 2f1ee0913ce58efe7f18fbd518bd54c598559b89 ]
7
8 This reverts commit fe53ca54270a ("mm: use early_pfn_to_nid in
9 page_ext_init").
10
11 When booting a system with "page_owner=on",
12
13 start_kernel
14 page_ext_init
15 invoke_init_callbacks
16 init_section_page_ext
17 init_page_owner
18 init_early_allocated_pages
19 init_zones_in_node
20 init_pages_in_zone
21 lookup_page_ext
22 page_to_nid
23
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.
28
29 UBSAN: Undefined behaviour in ./include/linux/mm.h:1104:50
30 index 7 is out of range for type 'zone [5]'
31
32 Also, kernel will panic since flags were poisoned earlier with,
33
34 CONFIG_DEBUG_VM_PGFLAGS=y
35 CONFIG_NODE_NOT_IN_PAGE_FLAGS=n
36
37 start_kernel
38 setup_arch
39 pagetable_init
40 paging_init
41 sparse_init
42 sparse_init_nid
43 memblock_alloc_try_nid_raw
44
45 It did not handle it well in init_pages_in_zone() which ends up calling
46 page_to_nid().
47
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
55
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.
60
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>
71 ---
72 init/main.c | 3 ++-
73 mm/page_ext.c | 4 +---
74 2 files changed, 3 insertions(+), 4 deletions(-)
75
76 diff --git a/init/main.c b/init/main.c
77 index c4a45145e102..3d3d79c5a232 100644
78 --- a/init/main.c
79 +++ b/init/main.c
80 @@ -663,7 +663,6 @@ asmlinkage __visible void __init start_kernel(void)
81 initrd_start = 0;
82 }
83 #endif
84 - page_ext_init();
85 kmemleak_init();
86 debug_objects_mem_init();
87 setup_per_cpu_pageset();
88 @@ -1069,6 +1068,8 @@ static noinline void __init kernel_init_freeable(void)
89 sched_init_smp();
90
91 page_alloc_init_late();
92 + /* Initialize page ext after all struct pages are initialized. */
93 + page_ext_init();
94
95 do_basic_setup();
96
97 diff --git a/mm/page_ext.c b/mm/page_ext.c
98 index 2c16216c29b6..2c44f5b78435 100644
99 --- a/mm/page_ext.c
100 +++ b/mm/page_ext.c
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|....
105 - *
106 - * Take into account DEFERRED_STRUCT_PAGE_INIT.
107 */
108 - if (early_pfn_to_nid(pfn) != nid)
109 + if (pfn_to_nid(pfn) != nid)
110 continue;
111 if (init_section_page_ext(pfn, nid))
112 goto oom;
113 --
114 2.19.1
115