]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/memcg-make-it-work-on-sparse-non-0-node-systems.patch
Linux 4.9.181
[thirdparty/kernel/stable-queue.git] / queue-4.4 / memcg-make-it-work-on-sparse-non-0-node-systems.patch
1 From 3e8589963773a5c23e2f1fe4bcad0e9a90b7f471 Mon Sep 17 00:00:00 2001
2 From: Jiri Slaby <jslaby@suse.cz>
3 Date: Fri, 31 May 2019 22:30:26 -0700
4 Subject: memcg: make it work on sparse non-0-node systems
5
6 From: Jiri Slaby <jslaby@suse.cz>
7
8 commit 3e8589963773a5c23e2f1fe4bcad0e9a90b7f471 upstream.
9
10 We have a single node system with node 0 disabled:
11 Scanning NUMA topology in Northbridge 24
12 Number of physical nodes 2
13 Skipping disabled node 0
14 Node 1 MemBase 0000000000000000 Limit 00000000fbff0000
15 NODE_DATA(1) allocated [mem 0xfbfda000-0xfbfeffff]
16
17 This causes crashes in memcg when system boots:
18 BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
19 #PF error: [normal kernel read fault]
20 ...
21 RIP: 0010:list_lru_add+0x94/0x170
22 ...
23 Call Trace:
24 d_lru_add+0x44/0x50
25 dput.part.34+0xfc/0x110
26 __fput+0x108/0x230
27 task_work_run+0x9f/0xc0
28 exit_to_usermode_loop+0xf5/0x100
29
30 It is reproducible as far as 4.12. I did not try older kernels. You have
31 to have a new enough systemd, e.g. 241 (the reason is unknown -- was not
32 investigated). Cannot be reproduced with systemd 234.
33
34 The system crashes because the size of lru array is never updated in
35 memcg_update_all_list_lrus and the reads are past the zero-sized array,
36 causing dereferences of random memory.
37
38 The root cause are list_lru_memcg_aware checks in the list_lru code. The
39 test in list_lru_memcg_aware is broken: it assumes node 0 is always
40 present, but it is not true on some systems as can be seen above.
41
42 So fix this by avoiding checks on node 0. Remember the memcg-awareness by
43 a bool flag in struct list_lru.
44
45 Link: http://lkml.kernel.org/r/20190522091940.3615-1-jslaby@suse.cz
46 Fixes: 60d3fd32a7a9 ("list_lru: introduce per-memcg lists")
47 Signed-off-by: Jiri Slaby <jslaby@suse.cz>
48 Acked-by: Michal Hocko <mhocko@suse.com>
49 Suggested-by: Vladimir Davydov <vdavydov.dev@gmail.com>
50 Acked-by: Vladimir Davydov <vdavydov.dev@gmail.com>
51 Reviewed-by: Shakeel Butt <shakeelb@google.com>
52 Cc: Johannes Weiner <hannes@cmpxchg.org>
53 Cc: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
54 Cc: <stable@vger.kernel.org>
55 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
56 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
57 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
58
59 ---
60 include/linux/list_lru.h | 1 +
61 mm/list_lru.c | 8 +++-----
62 2 files changed, 4 insertions(+), 5 deletions(-)
63
64 --- a/include/linux/list_lru.h
65 +++ b/include/linux/list_lru.h
66 @@ -51,6 +51,7 @@ struct list_lru {
67 struct list_lru_node *node;
68 #ifdef CONFIG_MEMCG_KMEM
69 struct list_head list;
70 + bool memcg_aware;
71 #endif
72 };
73
74 --- a/mm/list_lru.c
75 +++ b/mm/list_lru.c
76 @@ -42,11 +42,7 @@ static void list_lru_unregister(struct l
77 #ifdef CONFIG_MEMCG_KMEM
78 static inline bool list_lru_memcg_aware(struct list_lru *lru)
79 {
80 - /*
81 - * This needs node 0 to be always present, even
82 - * in the systems supporting sparse numa ids.
83 - */
84 - return !!lru->node[0].memcg_lrus;
85 + return lru->memcg_aware;
86 }
87
88 static inline struct list_lru_one *
89 @@ -389,6 +385,8 @@ static int memcg_init_list_lru(struct li
90 {
91 int i;
92
93 + lru->memcg_aware = memcg_aware;
94 +
95 if (!memcg_aware)
96 return 0;
97