Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3919809pxj; Mon, 21 Jun 2021 09:22:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxzvWBHANcj6JdKVyxPiE7WRUJwaEZ974dV5eIKn687SEirYcJH1an3y0aSqwBytgGqjrw X-Received: by 2002:a05:6402:1d56:: with SMTP id dz22mr2491398edb.376.1624292569697; Mon, 21 Jun 2021 09:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624292569; cv=none; d=google.com; s=arc-20160816; b=W+BWArm6PFqVOvXbEWk2oD6SB6OyPtsAr+WQFELidFvKEsT2eiBsuN8U44n9hXNjYe dgRIM67T1JkIJrsjfRBC3UxazZmD1wwrmuZ/uug8DuCXkWPySfuamj/FcrU5nsa6QYxh F+nULap2o3dvBW9B4iHRlIehAQnGwbQFzkHFA2Xh3OXDx9ow0HAsQQ48CQz4guONM3At 3yLOUTxspLHwCcA+vwzZwicVxrMLnOSJfeyeeXcNNtnyQgefLexpLgNh/QC3OlTxcop/ bkGT3ZfzEELXYsagNE3KAB080GG2sMoRKWWE/sAfXXPn/uXFUrljSJj54ro1CyBkoZkK iprQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yJ9QeTnFHtk8FZqOruD7xi/Orri3s6EG1ezNRcu22J4=; b=E9fUgVnVyj3P/zzbvFd9plR5ztU7UW98YoFAaMWLcw91ojrnFMgvpEm4NxdI/asHz4 daclWUvMGL5iAwn2PFJzG9ynJbiJs/crz6mIGTtINUPU5quQWEvKwV7lBbGA7mjvBfT5 2lkUPWHlmHY/zQx7HaRmAoC1ELX2KMJAl8VsuwGS/68SqrI5MFNsZphU2+T6isK1N9MW RJ3mPZe9YPfQyJ1nQqqMjS8+eyUqf8zspp+Usfky/Xas+DKosXjrFv0CdfNSBXNnzjcz c+QoB9I0p34CNKEsUhlAmCDl7Mq3TkU7ZZKPi8PDv0NkH2NVcMFimPZ55ku8THwaZ4i8 v0SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lNoh0Jqd; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ce29si10639806ejc.92.2021.06.21.09.22.27; Mon, 21 Jun 2021 09:22:49 -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=@linuxfoundation.org header.s=korg header.b=lNoh0Jqd; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230332AbhFUQVL (ORCPT + 99 others); Mon, 21 Jun 2021 12:21:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:41018 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231512AbhFUQU0 (ORCPT ); Mon, 21 Jun 2021 12:20:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B24A361261; Mon, 21 Jun 2021 16:18:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292291; bh=BfcxwXBcXcvzQa5qNwWMT71hfahYqQitpH+93irEsVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lNoh0JqdXMGsbXZYSVW71c9nzlWHey8yaOOfmAQTLQcbdPii1gHLBZVXi4oeAvqoP TvPqH+n2q/Bmv3x478i+3zTIKpMpl4utyAKDfRtHK1Pzmv6WxTplik3mEJztcFyPUX g1P0pB47bnJ52/eibBv44gCZUFCyfev7j1s1Btg0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, yangerkun , Naoya Horiguchi , Jan Kara , Theodore Tso , Oscar Salvador , Yu Kuai , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.4 05/90] mm/memory-failure: make sure wait for page writeback in memory_failure Date: Mon, 21 Jun 2021 18:14:40 +0200 Message-Id: <20210621154904.338424013@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154904.159672728@linuxfoundation.org> References: <20210621154904.159672728@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 d823ec74f3fc..9030ab0d9d97 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1382,7 +1382,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