Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3593097pxv; Mon, 28 Jun 2021 08:09:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6pZGeFhI7L6FxYFsgLZ/qZCgDUh0UG1lflqe0jsNAK07vuIjjuIiTjfZhY7irJzj/lB9p X-Received: by 2002:a92:dac3:: with SMTP id o3mr18395039ilq.290.1624892964921; Mon, 28 Jun 2021 08:09:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624892964; cv=none; d=google.com; s=arc-20160816; b=HmC+H1OuRKdjRjsTdyFoROut9aPhdijnDBGGW2CSo4n8wSz0FZs/5reGBz5/Ja42UT UMaji+5EqQjY7n6lwIAfa9brfgKAFGBE+v1u0Xx6oj+aT23HRbgTKL1YoPfVrH1TZs8t 1zM5uBfQbgsLhgFim27ADE9NsLTQlUj14zWKEB6jrtA0y41ksrZyizkBUFX/CbSaBWA3 l4L27LR1ZvrfXpGzCjv1PKWOsM/oWkuXFc6CZ7nRY3axO8+llHBA47j1Lryp2DJ077U9 PaBacYCVQD5f2/Oo7pcxp4C6MCfYrhE1Ryg1vElKNUuHZ8JclWX/GNWumS9psQkbqVaV 154w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aMKYSKoYDDG4xp0Fdz8/EeElau7SXEPwhjEoErmzP44=; b=iCj9a/knEt9onCNwm6mKLjylkg5P7JnKYayg2sfLQKRwmxU0reddu35VB7jXES3XFL roE9ZeqVPi9KwJGvtHwctgSw4o7C+0CBA960zu/SUhOiNBZYzHlyMsACKrsXo29CEVuv mjBT3MzUnMVAfxMLqhNmpg9QkzeYfK0JadY7u20TKRnpe/WHiaMcLWsVepRwZB3C07nz ZLDs0bdtnAyErMODesJlaHNygvnYR3qJDwW4qL2OJ7dS11+61nNl2UUpbI4z2BPOKzsx 1RRTPsHvHeT6eP9pY9kMQvoph3wT22ino6bDUbgBCoP/LyM/VPutFb/Ou8UUD+psq33X jAew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eRNBnezx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id n1si19549837ilt.140.2021.06.28.08.09.09; Mon, 28 Jun 2021 08:09:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eRNBnezx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S237146AbhF1PJi (ORCPT + 99 others); Mon, 28 Jun 2021 11:09:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:54462 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234653AbhF1Os4 (ORCPT ); Mon, 28 Jun 2021 10:48:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3189661D1C; Mon, 28 Jun 2021 14:36:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891009; bh=Rx8xXZlYFyehzv+DkWtvp+RVqPT53j4PgF4OT5QzZ7o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eRNBnezxg2XMwwskB4EVDJcoJslDcBlOImEMHGsLnalFkbH2Kax9wZyEQnd3GF4I9 BK+L5hk1FBln7tNE0SHteDhIc5YSRVHjdUQYxwMMr9rmGtkZnGj0wkdaaZa74Yuht2 7Oa5CiFFKXBZpuvJik1pCW1EePK4Lhd7n0vzToEMYVGgXcw51uotDb+bzD6aDx4TuV XZ+/2hiKjrwcZDd0cmor6i7iVPL+U3+PsK3bDHfoEsCuAGQY9l9WiyobWKFEyahB9e bfhhPz7udC9hpIho3ns5jJF0+gPb68Uyc8VCLezVzx0zzD/qVHk1h6WhDDxuxZ8cd4 CXGv/1LOjYMdQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: yangerkun , Naoya Horiguchi , Jan Kara , Theodore Ts'o , Oscar Salvador , Yu Kuai , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.14 21/88] mm/memory-failure: make sure wait for page writeback in memory_failure Date: Mon, 28 Jun 2021 10:35:21 -0400 Message-Id: <20210628143628.33342-22-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143628.33342-1-sashal@kernel.org> References: <20210628143628.33342-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.238-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.14.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.14.238-rc1 X-KernelTest-Deadline: 2021-06-30T14:36+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: yangerkun [ Upstream commit e8675d291ac007e1c636870db880f837a9ea112a ] Our syzkaller trigger the "BUG_ON(!list_empty(&inode->i_wb_list))" in clear_inode: kernel BUG at fs/inode.c:519! Internal error: Oops - BUG: 0 [#1] SMP Modules linked in: Process syz-executor.0 (pid: 249, stack limit = 0x00000000a12409d7) CPU: 1 PID: 249 Comm: syz-executor.0 Not tainted 4.19.95 Hardware name: linux,dummy-virt (DT) pstate: 80000005 (Nzcv daif -PAN -UAO) pc : clear_inode+0x280/0x2a8 lr : clear_inode+0x280/0x2a8 Call trace: clear_inode+0x280/0x2a8 ext4_clear_inode+0x38/0xe8 ext4_free_inode+0x130/0xc68 ext4_evict_inode+0xb20/0xcb8 evict+0x1a8/0x3c0 iput+0x344/0x460 do_unlinkat+0x260/0x410 __arm64_sys_unlinkat+0x6c/0xc0 el0_svc_common+0xdc/0x3b0 el0_svc_handler+0xf8/0x160 el0_svc+0x10/0x218 Kernel panic - not syncing: Fatal exception A crash dump of this problem show that someone called __munlock_pagevec to clear page LRU without lock_page: do_mmap -> mmap_region -> do_munmap -> munlock_vma_pages_range -> __munlock_pagevec. As a result memory_failure will call identify_page_state without wait_on_page_writeback. And after truncate_error_page clear the mapping of this page. end_page_writeback won't call sb_clear_inode_writeback to clear inode->i_wb_list. That will trigger BUG_ON in clear_inode! Fix it by checking PageWriteback too to help determine should we skip wait_on_page_writeback. Link: https://lkml.kernel.org/r/20210604084705.3729204-1-yangerkun@huawei.com Fixes: 0bc1f8b0682c ("hwpoison: fix the handling path of the victimized page frame that belong to non-LRU") Signed-off-by: yangerkun Acked-by: Naoya Horiguchi Cc: Jan Kara Cc: Theodore Ts'o Cc: Oscar Salvador Cc: Yu Kuai Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/memory-failure.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 001b6bfccbfb..e7827b9e6397 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1267,7 +1267,12 @@ int memory_failure(unsigned long pfn, int trapno, int flags) return 0; } - if (!PageTransTail(p) && !PageLRU(p)) + /* + * __munlock_pagevec may clear a writeback page's LRU flag without + * page_lock. We need wait writeback completion for this page or it + * may trigger vfs BUG while evict inode. + */ + if (!PageTransTail(p) && !PageLRU(p) && !PageWriteback(p)) goto identify_page_state; /* -- 2.30.2