Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3777328pxv; Mon, 28 Jun 2021 12:36:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpnvuAoWAk+URaSteJA0z0vPezw+/IQZQIPTnyKsMDqOkIfZ/SWGtLY8gmnrGk0wEHemgo X-Received: by 2002:a02:3705:: with SMTP id r5mr1059963jar.144.1624908979706; Mon, 28 Jun 2021 12:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624908979; cv=none; d=google.com; s=arc-20160816; b=MoUlSy/4r5vDS2iR9MLOZeC4B7JvrTDlfrH8vds4I/aYLEj8Xfs7zJJL3k40nbM8zr Mqx9b+p+6fcHhR40K0bQpu5FXA6oL85cPSqOzpg4qx2Zh8sIqKYB52YUm7WDusR/Z1wD s0BhdVSpp5m3lGJgvNWB5Fg9nThzAvruKG1tiA0SCP/qn/WvjA5HtSYYD+um+RNr3MQ3 sYA5BZyza3bnzTqfz3ZgBaA2i/SMfZndk52u3p5Y5TYyyh/ED7XObPlVH7gK0mxa5YD8 QCF09neD8rGDmNNHZaKCzApPLjzp8f1oi2XVZOK6obKBpzdXdJY4lx2/2SUEjAMJ6R6r qIrg== 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=Qmth7bdC3panzUIbqUTxOvt46VVwTKL6MehDdVQFGC8=; b=prAUc8fBnXKqsQlRils899CrJy573nvnTHWQ8V2F44PSrEbdNahQuhWjCgh5zuXZ1z ABSOaGr3qWiE6RTpyRLLVfK5MqBWa1mImNw/cmd7Yt8lsmw3lZkOgMzMgWaussMVkrsQ br13xkDjGXZH/T3h9bV/dywAySj9rs8HhsUollW2vwSOz5ez+2ZRkYbP4JtiIejzu314 18X6mZR8GajeB5JOXL8QPvgVDLonIMze9lXbKKzcLq428DGH/i7CMrYB94fDg3ckCBq+ VBG4qfOYnJk9Fq1/pVt46Q2LtwLRKWQsu2qmBmgyUcoOP4MQKOpSY6hZfK94TO84NSDn c1sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ob0OuSqu; 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 e1si16117489ilu.2.2021.06.28.12.36.06; Mon, 28 Jun 2021 12:36:19 -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=Ob0OuSqu; 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 S236712AbhF1Oz5 (ORCPT + 99 others); Mon, 28 Jun 2021 10:55:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:51480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234371AbhF1Olk (ORCPT ); Mon, 28 Jun 2021 10:41:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E7A2D61CCB; Mon, 28 Jun 2021 14:33:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624890810; bh=/hMOqfr6QmAnCwcftbwlqwZsdAX+X+QlggWlqc7i1Vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ob0OuSqu8uq29uNuZtmb38qfXarhaYQ2hNonw06MiRF6l5mLCL7bb7tEoEaFdi7H8 T+RO25Nrfs2Vm0lWvSVfq1704jeC+v6fVwrXZJAlURV7DrbaPt8/DKAivVBnY0FLDv TzAw/tNLVj/lel1vcUzt+jWMohI45W331nxezGggHZTvnr2BXxLlLXk+qNADoTRARH s+BOnHo3tGj18l/3jD2ti2g+ucEDiE3w17RPDD0uKSrGN1hWIp/81FK4+v0mD6P16l cH8JHwr63A3qtObVzKsv5V36Qk34Z2gjL9JvkDu9zcseyx+1XdnDJBCrcX3+etJdAI kQ39rxb0n4AOA== 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.19 025/109] mm/memory-failure: make sure wait for page writeback in memory_failure Date: Mon, 28 Jun 2021 10:31:41 -0400 Message-Id: <20210628143305.32978-26-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143305.32978-1-sashal@kernel.org> References: <20210628143305.32978-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.19.196-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.19.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.19.196-rc1 X-KernelTest-Deadline: 2021-06-30T14:32+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 034607a68ccb..3da3c63dccd1 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1387,7 +1387,12 @@ int memory_failure(unsigned long pfn, 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