From patchwork Mon Sep 23 08:30:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11156267 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AE34B112B for ; Mon, 23 Sep 2019 08:30:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7A55920882 for ; Mon, 23 Sep 2019 08:30:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7A55920882 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BA00F6B0007; Mon, 23 Sep 2019 04:30:41 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B506D6B0008; Mon, 23 Sep 2019 04:30:41 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3EC26B000A; Mon, 23 Sep 2019 04:30:41 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id 835DC6B0007 for ; Mon, 23 Sep 2019 04:30:41 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 290A2180AD802 for ; Mon, 23 Sep 2019 08:30:41 +0000 (UTC) X-FDA: 75965514282.26.glass62_401677b925b0d X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,:tj@kernel.org:akpm@linux-foundation.org:linux-kernel@vger.kernel.org::bhe@redhat.com,RULES_HIT:30003:30012:30029:30054:30056,0,RBL:209.132.183.28:@redhat.com:.lbl8.mailshell.net-62.18.0.0 64.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: glass62_401677b925b0d X-Filterd-Recvd-Size: 4314 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Mon, 23 Sep 2019 08:30:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3FDF8308FBA6; Mon, 23 Sep 2019 08:30:39 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-214.pek2.redhat.com [10.72.12.214]) by smtp.corp.redhat.com (Postfix) with ESMTP id 601E21001B07; Mon, 23 Sep 2019 08:30:37 +0000 (UTC) From: Baoquan He To: tj@kernel.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Baoquan He Subject: [PATCH] memcg: Only record foreign writebacks with dirty pages when memcg is not disabled Date: Mon, 23 Sep 2019 16:30:30 +0800 Message-Id: <20190923083030.6442-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 23 Sep 2019 08:30:39 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In kdump kernel, memcg usually is disabled with 'cgroup_disable=memory' for saving memory. Now kdump kernel will always panic when dump vmcore to local disk: BUG: kernel NULL pointer dereference, address: 0000000000000ab8 PGD 5fcab067 P4D 5fcab067 PUD 5ff73067 PMD 0 Oops: 0000 [#1] SMP NOPTI CPU: 0 PID: 598 Comm: makedumpfile Not tainted 5.3.0+ #26 Hardware name: HPE ProLiant DL385 Gen10/ProLiant DL385 Gen10, BIOS A40 10/02/2018 RIP: 0010:mem_cgroup_track_foreign_dirty_slowpath+0x38/0x140 Code: 55 48 8b 2d 6a bd 12 01 53 4c 8b 67 38 0f 1f 44 00 00 49 8b 06 48 89 e9 31 db be ff ff ff ff 48 8b 38 49 8d 84 24 d0 0a 00 00 <48> 39 78 e8 74 5a 48 8b 50 f8 48 39 ca 79 0e 44 8b 00 41 83 f8 01 RSP: 0018:ffffbc9300817bd0 EFLAGS: 00010046 RAX: 0000000000000ad0 RBX: 0000000000000000 RCX: 00000000fffba227 RDX: fffffffffffffff8 RSI: 00000000ffffffff RDI: 0000000000000004 RBP: 00000000fffba227 R08: 0000000000030340 R09: ffffbc9300817d10 R10: 0000000000000000 R11: 0000000000001000 R12: 0000000000000000 R13: ffff999c1fa2bcf0 R14: ffff999c1f7bcc78 R15: ffffe51fc177a8c0 FS: 00007f84f14c2b80(0000) GS:ffff999c22200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000ab8 CR3: 000000005f564000 CR4: 00000000003406b0 Call Trace: __set_page_dirty+0x52/0xc0 iomap_set_page_dirty+0x50/0x90 iomap_write_end+0x6e/0x270 iomap_write_actor+0xce/0x170 ? iomap_write_end+0x270/0x270 iomap_apply+0xba/0x11e ? iomap_write_end+0x270/0x270 iomap_file_buffered_write+0x62/0x90 ? iomap_write_end+0x270/0x270 xfs_file_buffered_aio_write+0xca/0x320 [xfs] new_sync_write+0x12d/0x1d0 vfs_write+0xa5/0x1a0 ksys_write+0x59/0xd0 do_syscall_64+0x59/0x1e0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x7f84f1093ab5 And this will corrupt the 1st kernel too with 'cgroup_disable=memory'. From the trace and with debugging, it is pointing to commit 97b27821b485 ("writeback, memcg: Implement foreign dirty flushing") which introduced this regression. Disabling memcg causes the null pointer dereference at uninitialized data in function mem_cgroup_track_foreign_dirty_slowpath(). Fix it by returning directly if memcg is disabled, but not trying to record the foreign writebacks with dirty pages. Fixed: 97b27821b485 ("writeback, memcg: Implement foreign dirty flushing") Signed-off-by: Baoquan He --- include/linux/memcontrol.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index ad8f1a397ae4..fa53f9d51205 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1261,7 +1261,8 @@ void mem_cgroup_track_foreign_dirty_slowpath(struct page *page, static inline void mem_cgroup_track_foreign_dirty(struct page *page, struct bdi_writeback *wb) { - if (unlikely(&page->mem_cgroup->css != wb->memcg_css)) + if (unlikely(&page->mem_cgroup->css != wb->memcg_css) + && !mem_cgroup_disabled()) mem_cgroup_track_foreign_dirty_slowpath(page, wb); }