Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp243355ybm; Wed, 22 May 2019 02:21:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDWGsfBi65lr88vHUj+IHmoKuCI+XJ9/pKLIPgtINUS/nO2q4+V221uTVsd82ndPu2/Z5C X-Received: by 2002:a17:902:c85:: with SMTP id 5mr15203273plt.172.1558516881446; Wed, 22 May 2019 02:21:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558516881; cv=none; d=google.com; s=arc-20160816; b=Gm/QdJxAU/OxV6Zv/HP3J52b26Dnw+cgbn66M2CGXjO1MD03Zhkc4aVearM55GDvOj 3aFLDuhxQODKAkwpS+XNtIqWDUZSDVtt+oAIFTEaCA90cNRqer6hludBKXCj8KbmkWWD +f2pezMmOm8z3rkA6RBva7OETkztzGLg9dADv7xhlek6dAq4b6MOwjRy7rY/pQGPEMud NNZSa86XyEYt/2oVHEAySsIrINfxPpfMFDQv7eNP1osHDoLwTMj9QzrqgD27gfblLw74 zbQXYMfXg2lRn0Swf++tHxVKdu5Oa2ud56rrABXvc3fdWYI4FfNVqKYOD+OQcXhRpTMU BJOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lMElx65Axj93ye3zkwy7bUqF5kBfrAiHucP2i3h/184=; b=BIQYq/9yJZWXQC29tE6nxBVV+7aqFv67uDUyLnVmn5y5QUnZjkEuegLb4+2NfNoozD GyrUKWYG1P2JhZYdzvMFQvxUJD6C5UiuaG+x0RSRowKAjBIS01T0xcpzQ2Ehet3CGtqe GEENtV7U78kDmloFWWdV3IaTevfTFY/OW4sgs+GiiqFCFvUuLMCwHa3nLthMQpF8N9ZZ khwYyxncW399DfhzhiE7wCUS1k8gHS+SJ9EbyZYiJCK0y2JSanLdSkGceCqwztaQy9du 7al/OPvOmoKFiy01B6zDzd0PxpHgKn74vVvFmcb8H2F/wX1REuPvdGvPZKLSuT0q8hlZ GEyg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d21si24468713pgl.591.2019.05.22.02.21.06; Wed, 22 May 2019 02:21:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728863AbfEVJTo (ORCPT + 99 others); Wed, 22 May 2019 05:19:44 -0400 Received: from mx2.suse.de ([195.135.220.15]:48888 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726552AbfEVJTo (ORCPT ); Wed, 22 May 2019 05:19:44 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 843E1ADEC; Wed, 22 May 2019 09:19:42 +0000 (UTC) From: Jiri Slaby To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, Jiri Slaby , Johannes Weiner , Michal Hocko , Vladimir Davydov , Shakeel Butt , cgroups@vger.kernel.org, stable@vger.kernel.org, linux-mm@kvack.org, Raghavendra K T Subject: [PATCH -resend v2] memcg: make it work on sparse non-0-node systems Date: Wed, 22 May 2019 11:19:40 +0200 Message-Id: <20190522091940.3615-1-jslaby@suse.cz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190517114204.6330-1-jslaby@suse.cz> References: <20190517114204.6330-1-jslaby@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: d_lru_add+0x44/0x50 dput.part.34+0xfc/0x110 __fput+0x108/0x230 task_work_run+0x9f/0xc0 exit_to_usermode_loop+0xf5/0x100 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 avoiding checks on node 0. Remember the memcg-awareness by a bool flag in struct list_lru. [v2] use the idea proposed by Vladimir -- the bool flag. Signed-off-by: Jiri Slaby Fixes: 60d3fd32a7a9 ("list_lru: introduce per-memcg lists") Cc: Johannes Weiner Acked-by: Michal Hocko Suggested-by: Vladimir Davydov Acked-by: Vladimir Davydov Reviewed-by: Shakeel Butt Cc: Cc: Cc: Cc: Raghavendra K T --- This is only a resent patch. I did not send it the akpm's way previously. include/linux/list_lru.h | 1 + mm/list_lru.c | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h index aa5efd9351eb..d5ceb2839a2d 100644 --- a/include/linux/list_lru.h +++ b/include/linux/list_lru.h @@ -54,6 +54,7 @@ struct list_lru { #ifdef CONFIG_MEMCG_KMEM struct list_head list; int shrinker_id; + bool memcg_aware; #endif }; diff --git a/mm/list_lru.c b/mm/list_lru.c index 0730bf8ff39f..d3b538146efd 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[0].memcg_lrus; + return lru->memcg_aware; } static inline struct list_lru_one * @@ -451,6 +447,8 @@ static int memcg_init_list_lru(struct list_lru *lru, bool memcg_aware) { int i; + lru->memcg_aware = memcg_aware; + if (!memcg_aware) return 0; -- 2.21.0