Skip to content

Commit 0292f5d

Browse files
Ye BinSasha Levin
authored andcommitted
ext4: fix bug_on in start_this_handle during umount filesystem
[ Upstream commit b98535d ] 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 torvalds#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: <TASK> 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 </TASK> 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 <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Ritesh Harjani <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 1cbea68 commit 0292f5d

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

fs/ext4/super.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,20 +1167,25 @@ static void ext4_put_super(struct super_block *sb)
11671167
int aborted = 0;
11681168
int i, err;
11691169

1170-
ext4_unregister_li_request(sb);
1171-
ext4_quota_off_umount(sb);
1172-
1173-
flush_work(&sbi->s_error_work);
1174-
destroy_workqueue(sbi->rsv_conversion_wq);
1175-
ext4_release_orphan_info(sb);
1176-
11771170
/*
11781171
* Unregister sysfs before destroying jbd2 journal.
11791172
* Since we could still access attr_journal_task attribute via sysfs
11801173
* path which could have sbi->s_journal->j_task as NULL
1174+
* Unregister sysfs before flush sbi->s_error_work.
1175+
* Since user may read /proc/fs/ext4/xx/mb_groups during umount, If
1176+
* read metadata verify failed then will queue error work.
1177+
* flush_stashed_error_work will call start_this_handle may trigger
1178+
* BUG_ON.
11811179
*/
11821180
ext4_unregister_sysfs(sb);
11831181

1182+
ext4_unregister_li_request(sb);
1183+
ext4_quota_off_umount(sb);
1184+
1185+
flush_work(&sbi->s_error_work);
1186+
destroy_workqueue(sbi->rsv_conversion_wq);
1187+
ext4_release_orphan_info(sb);
1188+
11841189
if (sbi->s_journal) {
11851190
aborted = is_journal_aborted(sbi->s_journal);
11861191
err = jbd2_journal_destroy(sbi->s_journal);

0 commit comments

Comments
 (0)