Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2435491ybi; Sun, 9 Jun 2019 11:44:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxKQQ6uS2YtkFq+F8LvO9+lFtzx8RXRlV6HK6pE/6qbhnDnqXYn4qvLVt/blrPpZfQnocbJ X-Received: by 2002:a17:902:8f8e:: with SMTP id z14mr25326878plo.1.1560105854180; Sun, 09 Jun 2019 11:44:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560105854; cv=none; d=google.com; s=arc-20160816; b=cqiuiNsyqp0LXvj589AeUd2L7jGsr0C5nPFbhpl38qXw9q23DCbv7yuL+28odNOWYT CFjta7DI9mIaTer8RFnw1uZSt/CsVoe6fdGsTALTHfgOtWhR5AOoNsl/YyKbAHytTzfy S52EIFK7uFx5/9z1bl4mQmPEJ1lTQTCcG+rmDDno4BtjqIn+26ruS9e+9mCfTst6c6Os xi6dUqX4gYnuKiI9lgxUUQf0mGHTMKYe6gcP50RVLwfujzHCe/geF0jtJVMd+kwnZdFd CIupgsafnp3TE9xYFvTmxNzmVg6fVCVIIKtDcAtK0CtYeVr5IyaB/TGdcaW1LhtBSKYr BDtA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=L3dlNDXMZ/s5GFWeyDWNMxCEx9jVbBTm8w4YLJPNtL0=; b=xPu07DPUXbOxD9p1UHWQe3dFz0fOLEhVoNacWrT5QaGPtarlxZZm8R6CTJ5aksujGI 6t9qUFL7ltGiRL1tmZ9sELXaXHTk8DLiAiWH0jIyDLm38ucaBldW8JHHv4+svHK9MwM2 uqKaLhKK2KKZfvaHH4rhElkTtwtbY+aJL7E4KFRJOxzhJYMDSp6wJ3N5E+80ETgdFak5 ozN9sXf8JwvPSsHVQ4UpDgvpKFrdF9VEOneHGEozOgGKsIseimCSvYn/HqC0Nx5BuFfz oBrcRlCJ+gnk5AwiXjB2qoVNdzXNPuYTSKw9qfAhrnfVY8UO0m9rag0oDz3PTc+9B75F LeIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KqnzJp6X; 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 j12si7323907pll.196.2019.06.09.11.43.57; Sun, 09 Jun 2019 11:44:14 -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; dkim=pass header.i=@kernel.org header.s=default header.b=KqnzJp6X; 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 S1733006AbfFIRQc (ORCPT + 99 others); Sun, 9 Jun 2019 13:16:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:54336 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732361AbfFIQxM (ORCPT ); Sun, 9 Jun 2019 12:53:12 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F0698204EC; Sun, 9 Jun 2019 16:53:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560099191; bh=mbF+KuK+ApjVYtSxZYdGvM0Yw3p8xtLnmmhXydfoIWM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KqnzJp6XK4qz9gn7YlRpq79ngN5jDEYEnXznj/D2evcC/hL8SNN+O2q+senddS9p9 E3Vz4kTO89pYssNZZjAeDuZDtoVzEbkSIrqrHUqaOoLjoTbIlUJS27W9+YVolJfkHD Ty8MW2cvloe6dQ8GmZc/JUvLtxZ4YkV8Dfubxxoc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Slaby , Michal Hocko , Vladimir Davydov , Shakeel Butt , Johannes Weiner , Raghavendra K T , Andrew Morton , Linus Torvalds Subject: [PATCH 4.9 42/83] memcg: make it work on sparse non-0-node systems Date: Sun, 9 Jun 2019 18:42:12 +0200 Message-Id: <20190609164131.478973899@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190609164127.843327870@linuxfoundation.org> References: <20190609164127.843327870@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiri Slaby commit 3e8589963773a5c23e2f1fe4bcad0e9a90b7f471 upstream. 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. Link: http://lkml.kernel.org/r/20190522091940.3615-1-jslaby@suse.cz Fixes: 60d3fd32a7a9 ("list_lru: introduce per-memcg lists") Signed-off-by: Jiri Slaby Acked-by: Michal Hocko Suggested-by: Vladimir Davydov Acked-by: Vladimir Davydov Reviewed-by: Shakeel Butt Cc: Johannes Weiner Cc: Raghavendra K T Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- include/linux/list_lru.h | 1 + mm/list_lru.c | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) --- a/include/linux/list_lru.h +++ b/include/linux/list_lru.h @@ -51,6 +51,7 @@ struct list_lru { struct list_lru_node *node; #if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB) struct list_head list; + bool memcg_aware; #endif }; --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -42,11 +42,7 @@ static void list_lru_unregister(struct l #if defined(CONFIG_MEMCG) && !defined(CONFIG_SLOB) 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 * @@ -389,6 +385,8 @@ static int memcg_init_list_lru(struct li { int i; + lru->memcg_aware = memcg_aware; + if (!memcg_aware) return 0;