From: Ojaswin Mujoo <ojaswin@linux.ibm.com>
To: linux-ext4@vger.kernel.org, "Theodore Ts'o" <tytso@mit.edu>
Cc: Jan Kara <jack@suse.cz>,
linux-kernel@vger.kernel.org,
Mahesh Kumar <maheshkumar657g@gmail.com>,
Ritesh Harjani <ritesh.list@gmail.com>
Subject: [PATCH 1/2] ext4: only defer sb update on error if SB_ACTIVE
Date: Sat, 22 Feb 2025 14:10:22 +0530 [thread overview]
Message-ID: <da8af2e5170f0d94031b812d7d50c6ec1967db1b.1740212945.git.ojaswin@linux.ibm.com> (raw)
In-Reply-To: <cover.1740212945.git.ojaswin@linux.ibm.com>
Presently we always BUG_ON if trying to start a transaction on a journal
marked with JBD2_UNMOUNT, since this should never happen. However while
running stress tests it was observed that in case of some error handling
paths, it is possible for update_super_work to start a transaction after
the journal is destroyed eg:
(umount)
ext4_kill_sb
kill_block_super
generic_shutdown_super
sync_filesystem /* commits all txns */
evict_inodes
/* might start a new txn */
ext4_put_super
flush_work(&sbi->s_sb_upd_work) /* flush the workqueue */
jbd2_journal_destroy
journal_kill_thread
journal->j_flags |= JBD2_UNMOUNT;
jbd2_journal_commit_transaction
jbd2_journal_get_descriptor_buffer
jbd2_journal_bmap
ext4_journal_bmap
ext4_map_blocks
...
ext4_inode_error
ext4_handle_error
schedule_work(&sbi->s_sb_upd_work)
/* work queue kicks in */
update_super_work
jbd2_journal_start
start_this_handle
BUG_ON(journal->j_flags &
JBD2_UNMOUNT)
Hence, make sure we only defer the update of ext4 sb if the sb is still
active. Otherwise, just fallback to an un-journaled commit.
The important thing to note here is that we must only defer sb update if
we have not yet flushed the s_sb_update_work queue in umount path else
this race can be hit (point 1 below). Since we don't have a direct way
to check for that we use SB_ACTIVE instead. The SB_ACTIVE check is a bit
subtle so adding some notes below for future reference:
1. Ideally we would want to have a something like (flags & JBD2_UNMOUNT
== 0) however this is not correct since we could end up scheduling work
after it has been flushed:
ext4_put_super
flush_work(&sbi->s_sb_upd_work)
**kjournald2**
jbd2_journal_commit_transaction
...
ext4_inode_error
/* JBD2_UNMOUNT not set */
schedule_work(s_sb_upd_work)
jbd2_journal_destroy
journal->j_flags |= JBD2_UNMOUNT;
**workqueue**
update_super_work
jbd2_journal_start
start_this_handle
BUG_ON(JBD2_UNMOUNT)
Something like the above doesn't happen with SB_ACTIVE check because we
are sure that the workqueue would be flushed at a later point if we are
in the umount path.
2. We don't need a similar check in ext4_grp_locked_error since it is
only called from mballoc and AFAICT it would be always valid to schedule
work here.
Fixes: 2d01ddc86606 ("ext4: save error info to sb through journal if available")
Reported-by: Mahesh Kumar <maheshkumar657g@gmail.com>
Suggested-by: Ritesh Harjani <ritesh.list@gmail.com>
Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
fs/ext4/super.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index a963ffda692a..b7341e9acf62 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -706,7 +706,7 @@ static void ext4_handle_error(struct super_block *sb, bool force_ro, int error,
* constraints, it may not be safe to do it right here so we
* defer superblock flushing to a workqueue.
*/
- if (continue_fs && journal)
+ if (continue_fs && journal && (sb->s_flags & SB_ACTIVE))
schedule_work(&EXT4_SB(sb)->s_sb_upd_work);
else
ext4_commit_super(sb);
--
2.48.1
next prev parent reply other threads:[~2025-02-22 8:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-22 8:40 [PATCH 0/2] Fix a BUG_ON crashing the kernel in start_this_handle Ojaswin Mujoo
2025-02-22 8:40 ` Ojaswin Mujoo [this message]
2025-02-24 14:52 ` [PATCH 1/2] ext4: only defer sb update on error if SB_ACTIVE Jan Kara
2025-02-27 11:20 ` Ojaswin Mujoo
2025-03-04 10:25 ` Jan Kara
2025-03-04 12:54 ` Ojaswin Mujoo
2025-03-05 4:14 ` Ritesh Harjani
2025-02-25 1:53 ` Baokun Li
2025-02-25 12:06 ` Ojaswin Mujoo
2025-02-26 1:55 ` Baokun Li
2025-02-27 11:43 ` Ojaswin Mujoo
2025-02-27 12:51 ` Baokun Li
2025-03-03 17:30 ` Ojaswin Mujoo
2025-02-22 8:40 ` [PATCH 2/2] ext4: Make sb update interval tunable Ojaswin Mujoo
2025-02-22 9:32 ` Ritesh Harjani (IBM)
2025-02-24 14:27 ` Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=da8af2e5170f0d94031b812d7d50c6ec1967db1b.1740212945.git.ojaswin@linux.ibm.com \
--to=ojaswin@linux.ibm.com \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maheshkumar657g@gmail.com \
--cc=ritesh.list@gmail.com \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®