Re: [PATCH] memcg: make it work on sparse non-0-node systems
From: Jiri Slaby
Date: Thu May 09 2019 - 03:22:57 EST
as you are perhaps the one most familiar with the code, could you take a
look on this?
On 29. 04. 19, 12:59, Jiri Slaby wrote:
> We have a single node system with node 0 disabled:
> Scanning NUMA topology in Northbridge 24
> Number of physical nodes 2
> Skipping disabled node 0
> Node 1 MemBase 0000000000000000 Limit 00000000fbff0000
> NODE_DATA(1) allocated [mem 0xfbfda000-0xfbfeffff]
> This causes crashes in memcg when system boots:
> BUG: unable to handle kernel NULL pointer dereference at 0000000000000008
> #PF error: [normal kernel read fault]
> RIP: 0010:list_lru_add+0x94/0x170
> Call Trace:
> It is reproducible as far as 4.12. I did not try older kernels. You have
> to have a new enough systemd, e.g. 241 (the reason is unknown -- was not
> investigated). Cannot be reproduced with systemd 234.
> The system crashes because the size of lru array is never updated in
> memcg_update_all_list_lrus and the reads are past the zero-sized array,
> causing dereferences of random memory.
> The root cause are list_lru_memcg_aware checks in the list_lru code.
> The test in list_lru_memcg_aware is broken: it assumes node 0 is always
> present, but it is not true on some systems as can be seen above.
> So fix this by checking the first online node instead of node 0.
> Signed-off-by: Jiri Slaby <jslaby@xxxxxxx>
> Cc: Johannes Weiner <hannes@xxxxxxxxxxx>
> Cc: Michal Hocko <mhocko@xxxxxxxxxx>
> Cc: Vladimir Davydov <vdavydov.dev@xxxxxxxxx>
> Cc: <cgroups@xxxxxxxxxxxxxxx>
> Cc: <linux-mm@xxxxxxxxx>
> Cc: Raghavendra K T <raghavendra.kt@xxxxxxxxxxxxxxxxxx>
> mm/list_lru.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
> diff --git a/mm/list_lru.c b/mm/list_lru.c
> index 0730bf8ff39f..7689910f1a91 100644
> --- a/mm/list_lru.c
> +++ b/mm/list_lru.c
> @@ -37,11 +37,7 @@ static int lru_shrinker_id(struct list_lru *lru)
> static inline bool list_lru_memcg_aware(struct list_lru *lru)
> - /*
> - * This needs node 0 to be always present, even
> - * in the systems supporting sparse numa ids.
> - */
> - return !!lru->node.memcg_lrus;
> + return !!lru->node[first_online_node].memcg_lrus;
> static inline struct list_lru_one *