Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3804947pxb; Mon, 4 Oct 2021 09:58:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAydWxiDxPkp0MsE3jD4Ygenjei/0SL6Ar+FXtm36B+53ozHSWIKVT14SHn9ztTLYt2VQk X-Received: by 2002:a17:90a:ba0e:: with SMTP id s14mr38969956pjr.213.1633366737257; Mon, 04 Oct 2021 09:58:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633366737; cv=none; d=google.com; s=arc-20160816; b=nz2rHvnzUr5PRglGVv5PhNMR6ABa+JWD4pFvugF0LCuhnG27z2O5B7aMR6yrXZ2YGl DVkIBI3+amX+hfHE8an2t/clwRPo5sHLkrimSUhMMexl2CKhjo0SjiZ3ilk2xafEnCoR Rb0G+xHMtGXWFPE9vNcxvF/dglg0J1bKeL/SEDnnU5yKc24QVWOPvSAUT8lXv/uQg3iS 5NnXKATXI3nrTNDwFYNQ2nv0pDMbJ4t3StFLIOOcycSwQqLObdvPpVPf+A9LGfV6OS9K plz05Bxkl5ROSw5SIHwHhNHxl1efXi80mvIuVrBC4hRYBfUpRyshNI9V/4H9nEEtUN8r rtoQ== 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=ZjaaV8KoegDf8ewqrhpyUpFNpntXmbhFdXxAK+kGe28=; b=Jzvu0mVCVfD3QjqE0Ybcx+TLA58tTHR5zv07d6xdfGVL/AJxwGmNpRXKijZS3YKNjp Hl865n98VZ6KEju5ZtKxtQiEsiMxnWmWIdOhBANxmGJDWNje3lHSH4wvUvIz1BPoPwdi tWZTvGmLVqUUMz8ijODyuqgdIX1xCzBngHMk5fi3kIawB2bA4fKa8AE3i3VZBCCEedvm 9surAx0kouPpmvQ+3ZQqhAEBmmpMJv2tjnn+UAhU1ZQaCNXLBVYCQCcU0H/66g+aeD/A rMW3AydbmA/aS92XvbyN38lBubHk/hAfDmoIjQgLCfrid+kTsHXRvdbtIJJiLHp4uDU1 8cPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ywc15LXX; 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 j73si11979780pge.385.2021.10.04.09.58.44; Mon, 04 Oct 2021 09:58:57 -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=Ywc15LXX; 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 S238700AbhJDNmN (ORCPT + 99 others); Mon, 4 Oct 2021 09:42:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:53132 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238401AbhJDNkY (ORCPT ); Mon, 4 Oct 2021 09:40:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B774E63241; Mon, 4 Oct 2021 13:18:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353514; bh=sOVzJxwK84o5XNM1rfS3b5If5JqEFxjGHjgIVU5UD90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ywc15LXXkTL6M5NJfdVfFnlbIcLJ0RvnCyXCEgzvtFAB9mYDZoUs7NsD1EksUV6ru vvo/RKVP8OO5Zs+CSNAP+PFYX+b0+vZBqlATvWYM/avOL3E0SmUDQVa+mDtATLe5DX 3nNIOciZoJXknWDQqi5BpBhsjoNoPgfpjieGfbtw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, yangerkun , Jan Kara , Theodore Tso Subject: [PATCH 5.14 158/172] ext4: flush s_error_work before journal destroy in ext4_fill_super Date: Mon, 4 Oct 2021 14:53:28 +0200 Message-Id: <20211004125050.070888021@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@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 commit bb9464e08309f6befe80866f5be51778ca355ee9 upstream. The error path in ext4_fill_super forget to flush s_error_work before journal destroy, and it may trigger the follow bug since flush_stashed_error_work can run concurrently with journal destroy without any protection for sbi->s_journal. [32031.740193] EXT4-fs (loop66): get root inode failed [32031.740484] EXT4-fs (loop66): mount failed [32031.759805] ------------[ cut here ]------------ [32031.759807] kernel BUG at fs/jbd2/transaction.c:373! [32031.760075] invalid opcode: 0000 [#1] SMP PTI [32031.760336] CPU: 5 PID: 1029268 Comm: kworker/5:1 Kdump: loaded 4.18.0 [32031.765112] Call Trace: [32031.765375] ? __switch_to_asm+0x35/0x70 [32031.765635] ? __switch_to_asm+0x41/0x70 [32031.765893] ? __switch_to_asm+0x35/0x70 [32031.766148] ? __switch_to_asm+0x41/0x70 [32031.766405] ? _cond_resched+0x15/0x40 [32031.766665] jbd2__journal_start+0xf1/0x1f0 [jbd2] [32031.766934] jbd2_journal_start+0x19/0x20 [jbd2] [32031.767218] flush_stashed_error_work+0x30/0x90 [ext4] [32031.767487] process_one_work+0x195/0x390 [32031.767747] worker_thread+0x30/0x390 [32031.768007] ? process_one_work+0x390/0x390 [32031.768265] kthread+0x10d/0x130 [32031.768521] ? kthread_flush_work_fn+0x10/0x10 [32031.768778] ret_from_fork+0x35/0x40 static int start_this_handle(...) BUG_ON(journal->j_flags & JBD2_UNMOUNT); <---- Trigger this Besides, after we enable fast commit, ext4_fc_replay can add work to s_error_work but return success, so the latter journal destroy in ext4_load_journal can trigger this problem too. Fix this problem with two steps: 1. Call ext4_commit_super directly in ext4_handle_error for the case that called from ext4_fc_replay 2. Since it's hard to pair the init and flush for s_error_work, we'd better add a extras flush_work before journal destroy in ext4_fill_super Besides, this patch will call ext4_commit_super in ext4_handle_error for any nojournal case too. But it seems safe since the reason we call schedule_work was that we should save error info to sb through journal if available. Conversely, for the nojournal case, it seems useless delay commit superblock to s_error_work. Fixes: c92dc856848f ("ext4: defer saving error info from atomic context") Fixes: 2d01ddc86606 ("ext4: save error info to sb through journal if available") Cc: stable@kernel.org Signed-off-by: yangerkun Reviewed-by: Jan Kara Signed-off-by: Theodore Ts'o Link: https://lore.kernel.org/r/20210924093917.1953239-1-yangerkun@huawei.com Signed-off-by: Greg Kroah-Hartman --- fs/ext4/super.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -661,7 +661,7 @@ static void ext4_handle_error(struct sup * constraints, it may not be safe to do it right here so we * defer superblock flushing to a workqueue. */ - if (continue_fs) + if (continue_fs && journal) schedule_work(&EXT4_SB(sb)->s_error_work); else ext4_commit_super(sb); @@ -5189,12 +5189,15 @@ failed_mount_wq: sbi->s_ea_block_cache = NULL; if (sbi->s_journal) { + /* flush s_error_work before journal destroy. */ + flush_work(&sbi->s_error_work); jbd2_journal_destroy(sbi->s_journal); sbi->s_journal = NULL; } failed_mount3a: ext4_es_unregister_shrinker(sbi); failed_mount3: + /* flush s_error_work before sbi destroy */ flush_work(&sbi->s_error_work); del_timer_sync(&sbi->s_err_report); ext4_stop_mmpd(sbi);