Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp769350ybc; Sat, 16 Nov 2019 08:22:10 -0800 (PST) X-Google-Smtp-Source: APXvYqxK/tGrsbJUEunknuZlsn4j1diMm9HytmvwCOV16Qr7gDnCenh8vc6TKUaJaPBnM9bfuefJ X-Received: by 2002:adf:e942:: with SMTP id m2mr23048712wrn.26.1573921330458; Sat, 16 Nov 2019 08:22:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573921330; cv=none; d=google.com; s=arc-20160816; b=x4fjkB6NMpKeMgLwe10NyryJRie69GD8SNEozB9Bo1os/ZMD45+knniR+yQJRl09Lp P8ZMX1CmE0GDrvtOIePDajpkR3nVTPvtI+VcO69cqhPGFQEjp3g5X5At10LEKgyZLLOH GO948jOrXo4LRx9AVr2JGU3AxGzn59qN5UGwgmc5K2HLOti8bVzL3gofmCchpVp9AmdE k8UhOJs4IscLlsRijOw+mEHYXgbkaFSoegTwW4cPBORxTFa0ZSDe4/oXXCoYu0zWSsBr ZAyEYubpT+JHIIeGPRz06qsfu1krSkaSmaP6kDPCxDdGChaMSVNsvDDFJAnUt0nqzttw 9A5w== 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 :dkim-signature; bh=Al2roM1yR7MjwxRjp3T0Svag//jW7fq/gLVK/yWy9oA=; b=OHSlU3351NfW5tLaXYkFMG21UvAF/BSjA+CV58ujFXEAV94wrhLNzDq8vByrnw0yAg pz2fuG8HSUrVuddUrBo0ENZlBIHtcApa/uYDpmdEaYqoE3bcYR4o4GGtL1SRFCAMmFzb kkZ8prtQtA3ITOnjaA/g4JV9gePZifVpyTNxalNumHsvlRQP2qs5frxTd3gOxw1kwTRY mb1kSpXMqCf6JC+sAbk/JyygDFWGiMpodF0JAfDE5UxuVLMDgLdavsRZVfFb+nFOK136 RpRmwa5JgVL/4dXrK6lIVPAVgSpoh37hiBIxa89eACKzhKVXENk4j/5gvCG9E87gtRRZ ALbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GKnIuVN5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k7si6469855edk.34.2019.11.16.08.21.45; Sat, 16 Nov 2019 08:22:10 -0800 (PST) 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=GKnIuVN5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732045AbfKPQTa (ORCPT + 99 others); Sat, 16 Nov 2019 11:19:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:52324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729306AbfKPPqJ (ORCPT ); Sat, 16 Nov 2019 10:46:09 -0500 Received: from sasha-vm.mshome.net (unknown [50.234.116.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 275CF2086A; Sat, 16 Nov 2019 15:46:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573919168; bh=iLeu/7+A59mHww5wMPQ7+f/gfyrQdTMOJFAQRguBkd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GKnIuVN5+bvLWzD2MSCnXJpfOgeMH2FO6qQ/ZfW2zvmu3H1sq+c+0QyPugSJqgyVw jOKcDOhWex0NbNfBv09PpiR1ESQHMY+a7qJHxpdhxkTDz4El9yKomOyS4FPPb5K+w8 jy5FZvTOFDGZaCbNo/MfySuLuC0KcNlHhLVQ5oyQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Roman Gushchin , Mike Galbraith , Rik van Riel , Michal Hocko , Johannes Weiner , Vladimir Davydov , Shakeel Butt , Andrew Morton , Linus Torvalds , Sasha Levin , cgroups@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH AUTOSEL 4.19 178/237] mm: handle no memcg case in memcg_kmem_charge() properly Date: Sat, 16 Nov 2019 10:40:13 -0500 Message-Id: <20191116154113.7417-178-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191116154113.7417-1-sashal@kernel.org> References: <20191116154113.7417-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Roman Gushchin [ Upstream commit e68599a3c3ad0f3171a7cb4e48aa6f9a69381902 ] Mike Galbraith reported a regression caused by the commit 9b6f7e163cd0 ("mm: rework memcg kernel stack accounting") on a system with "cgroup_disable=memory" boot option: the system panics with the following stack trace: BUG: unable to handle kernel NULL pointer dereference at 00000000000000f8 PGD 0 P4D 0 Oops: 0002 [#1] PREEMPT SMP PTI CPU: 0 PID: 1 Comm: systemd Not tainted 4.19.0-preempt+ #410 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20180531_142017-buildhw-08.phx2.fed4 RIP: 0010:page_counter_try_charge+0x22/0xc0 Code: 41 5d c3 c3 0f 1f 40 00 0f 1f 44 00 00 48 85 ff 0f 84 a7 00 00 00 41 56 48 89 f8 49 89 fe 49 Call Trace: try_charge+0xcb/0x780 memcg_kmem_charge_memcg+0x28/0x80 memcg_kmem_charge+0x8b/0x1d0 copy_process.part.41+0x1ca/0x2070 _do_fork+0xd7/0x3d0 do_syscall_64+0x5a/0x180 entry_SYSCALL_64_after_hwframe+0x49/0xbe The problem occurs because get_mem_cgroup_from_current() returns the NULL pointer if memory controller is disabled. Let's check if this is a case at the beginning of memcg_kmem_charge() and just return 0 if mem_cgroup_disabled() returns true. This is how we handle this case in many other places in the memory controller code. Link: http://lkml.kernel.org/r/20181029215123.17830-1-guro@fb.com Fixes: 9b6f7e163cd0 ("mm: rework memcg kernel stack accounting") Signed-off-by: Roman Gushchin Reported-by: Mike Galbraith Acked-by: Rik van Riel Acked-by: Michal Hocko Cc: Johannes Weiner Cc: Vladimir Davydov Cc: Shakeel Butt Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index e0f7b94a4e9bc..b3220d2102461 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2678,7 +2678,7 @@ int memcg_kmem_charge(struct page *page, gfp_t gfp, int order) struct mem_cgroup *memcg; int ret = 0; - if (memcg_kmem_bypass()) + if (mem_cgroup_disabled() || memcg_kmem_bypass()) return 0; memcg = get_mem_cgroup_from_current(); -- 2.20.1