Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1682420iob; Thu, 5 May 2022 06:25:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8MTjzUQqFILwGp4VheX5Dhpufdv4wXG2BJkcZ4bnjctL1fxCGW2TOc8dKs1bvnf6yyAmf X-Received: by 2002:a17:902:cecf:b0:15e:b10a:9f3a with SMTP id d15-20020a170902cecf00b0015eb10a9f3amr17264463plg.118.1651757123225; Thu, 05 May 2022 06:25:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651757123; cv=none; d=google.com; s=arc-20160816; b=Qn1rpclhZwrPTDUTj0gp/UiMtw2vTpPrmLncEfAw+tn4oo8JTiQld0INoFCEfEiePr lCiJgqC1dDfrYClmT3OtSp/0WoSgT+h+Wu8kd3+dvgBuaZOh3bv1yzKCoi19R0Cn35yZ TkBvfk8koUb8XI2SWFiTt4Y/pkSrsTv5xWhODg0J33MfRpyK6rOoaibQOVYDULVXA9Dd H6AdGG05rZ/qB/HjjO96HremqaigvxfbB0ozuBOQyxP3meByKlWLvcZr4qbP8ZnN24HT fYGOAqD37ks6aX6sD1G3hopyOAIfY2lrdApD8NHHK15p9QRL0lOXz4wk1hEcxxkiCLoa qSDw== 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=ziWSuNi6R9zOpY5/1ej2AVZJVNo2sM1juFzoTitpVUU=; b=lfq8VRhM4Gp0hy0fPpQv4rigBmiEMq272fnx4C2A1VsD9JQxLs9ew6B43a4qDhcSHM KSyHVf7Fjf6rvR8AJA1q4Cxc56UNbXL9pfwqmUcQ0Xf5D7fFxF7y7GhT/ETI9rGuOxP7 9/Vin4EPS+rvJeAh4fgGDFvvN1ugydwRxojmLkaNk6taXL9SYT1f993M66widtQ3CFbr X9W/mMSdJOghe2vf+8YiW8z32zDpn6q1oj8tUvCjjWYzkydtO6bDlrNR7IDd3db1Uvcg V7iO0u0q/AdSfKifrWcTWFuw82K9JKN86byUn353zQaY6MzxujmW0hUWqN71DAadu+sq k6DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qxPDo81C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b23-20020a6567d7000000b00398a2b708c9si1679841pgs.211.2022.05.05.06.25.08; Thu, 05 May 2022 06:25:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qxPDo81C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1358988AbiEDRsu (ORCPT + 99 others); Wed, 4 May 2022 13:48:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357439AbiEDRPC (ORCPT ); Wed, 4 May 2022 13:15:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B86853E21; Wed, 4 May 2022 09:58:35 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DBA0BB8279C; Wed, 4 May 2022 16:58:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E785C385B5; Wed, 4 May 2022 16:58:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683489; bh=MCu1XbXxTHzmzdl3yftxbmZRAzoGurMjUSAy0MHNp+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qxPDo81COK4O22naJLdzbLFIWblWx2T/n/XKJ40ET2BtTJmYTS2K/LhI+fYZpcjHv 2Ui02VN/FHauHjHkku8DQeX/TM4pBEjDZQjj6fY9fGr+9m4TQ9xyIZdJNvYKeVocBt 4keurjCps5XsPKAO6mjxb2l3A1BQSPcnu+0EU/Q0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ye Bin , Jan Kara , Ritesh Harjani , Theodore Tso , Sasha Levin Subject: [PATCH 5.17 164/225] ext4: fix bug_on in start_this_handle during umount filesystem Date: Wed, 4 May 2022 18:46:42 +0200 Message-Id: <20220504153124.620459447@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153110.096069935@linuxfoundation.org> References: <20220504153110.096069935@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ye Bin [ Upstream commit b98535d091795a79336f520b0708457aacf55c67 ] We got issue as follows: ------------[ cut here ]------------ kernel BUG at fs/jbd2/transaction.c:389! invalid opcode: 0000 [#1] PREEMPT SMP KASAN PTI CPU: 9 PID: 131 Comm: kworker/9:1 Not tainted 5.17.0-862.14.0.6.x86_64-00001-g23f87daf7d74-dirty #197 Workqueue: events flush_stashed_error_work RIP: 0010:start_this_handle+0x41c/0x1160 RSP: 0018:ffff888106b47c20 EFLAGS: 00010202 RAX: ffffed10251b8400 RBX: ffff888128dc204c RCX: ffffffffb52972ac RDX: 0000000000000200 RSI: 0000000000000004 RDI: ffff888128dc2050 RBP: 0000000000000039 R08: 0000000000000001 R09: ffffed10251b840a R10: ffff888128dc204f R11: ffffed10251b8409 R12: ffff888116d78000 R13: 0000000000000000 R14: dffffc0000000000 R15: ffff888128dc2000 FS: 0000000000000000(0000) GS:ffff88839d680000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000001620068 CR3: 0000000376c0e000 CR4: 00000000000006e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: jbd2__journal_start+0x38a/0x790 jbd2_journal_start+0x19/0x20 flush_stashed_error_work+0x110/0x2b3 process_one_work+0x688/0x1080 worker_thread+0x8b/0xc50 kthread+0x26f/0x310 ret_from_fork+0x22/0x30 Modules linked in: ---[ end trace 0000000000000000 ]--- Above issue may happen as follows: umount read procfs error_work ext4_put_super flush_work(&sbi->s_error_work); ext4_mb_seq_groups_show ext4_mb_load_buddy_gfp ext4_mb_init_group ext4_mb_init_cache ext4_read_block_bitmap_nowait ext4_validate_block_bitmap ext4_error ext4_handle_error schedule_work(&EXT4_SB(sb)->s_error_work); ext4_unregister_sysfs(sb); jbd2_journal_destroy(sbi->s_journal); journal_kill_thread journal->j_flags |= JBD2_UNMOUNT; flush_stashed_error_work jbd2_journal_start start_this_handle BUG_ON(journal->j_flags & JBD2_UNMOUNT); To solve this issue, we call 'ext4_unregister_sysfs() before flushing s_error_work in ext4_put_super(). Signed-off-by: Ye Bin Reviewed-by: Jan Kara Reviewed-by: Ritesh Harjani Link: https://lore.kernel.org/r/20220322012419.725457-1-yebin10@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/super.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index ba6530c2d271..fe30f483c59f 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1199,20 +1199,25 @@ static void ext4_put_super(struct super_block *sb) int aborted = 0; int i, err; - ext4_unregister_li_request(sb); - ext4_quota_off_umount(sb); - - flush_work(&sbi->s_error_work); - destroy_workqueue(sbi->rsv_conversion_wq); - ext4_release_orphan_info(sb); - /* * Unregister sysfs before destroying jbd2 journal. * Since we could still access attr_journal_task attribute via sysfs * path which could have sbi->s_journal->j_task as NULL + * Unregister sysfs before flush sbi->s_error_work. + * Since user may read /proc/fs/ext4/xx/mb_groups during umount, If + * read metadata verify failed then will queue error work. + * flush_stashed_error_work will call start_this_handle may trigger + * BUG_ON. */ ext4_unregister_sysfs(sb); + ext4_unregister_li_request(sb); + ext4_quota_off_umount(sb); + + flush_work(&sbi->s_error_work); + destroy_workqueue(sbi->rsv_conversion_wq); + ext4_release_orphan_info(sb); + if (sbi->s_journal) { aborted = is_journal_aborted(sbi->s_journal); err = jbd2_journal_destroy(sbi->s_journal); -- 2.35.1