Skip to contentSkip to conversation

ext4: Fix two bugs in journalled writepages rework

PATCH In review Jan Kara 2 participants 4 messages Mar 23, 2023 – Apr 15, 2023 ext4 file system

lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

cover ext4: Fix two bugs in journalled writepages rework

Hello!

These two patches fix two problems introduced by the rewrite of journalled writeback path.

Honza

author reviewer
#1 lore raw

PATCH 1/2 ext4: Fix data=journal writeback of DMA pinned page

The condition in ext4_writepages() checking whether the filesystem is frozen had a brown paper bag bug resulting in us never writing back DMA pinned pages. Fix the condition.

Fixes 18b7f4107219 ("ext4: Fix warnings when freezing filesystem with journaled data")
---
 fs/ext4/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/inode.c +1 -1
index 3e311c85df08..15bac8181798 100644
@@ -2436,7 +2436,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
 	 * loop clears them.
 	 */
 	if (ext4_should_journal_data(mpd->inode) &&
-	    sb->s_writers.frozen >= SB_FREEZE_FS) {
+	    sb->s_writers.frozen < SB_FREEZE_FS) {
 		handle = ext4_journal_start(mpd->inode, EXT4_HT_WRITE_PAGE,
 					    bpp);
 		if (IS_ERR(handle))
Signature · 1 line
2.35.3
author reviewer
#2 lore raw

PATCH 2/2 ext4: Fix crash on shutdown filesystem

In reply to Jan Kara

Test generic/388 triggered a crash in mpage_release_unused_pages() because a page in mpd->first_page..mpd->next_page range was not locked. This can happen in data=journal mode when we exit from mpage_prepare_extent_to_map() before actually initializing mpd->next_page. Move the initialization to a place before we can exit with error from mpage_prepare_extent_to_map().

Fixes f7233fb54d18 ("ext4: Convert data=journal writeback to use ext4_writepages()")
---
 fs/ext4/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ext4/inode.c +2 -2
index 15bac8181798..dbcc8b48c7ba 100644
@@ -2428,6 +2428,8 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
 	else
 		tag = PAGECACHE_TAG_DIRTY;
 
+	mpd->map.m_len = 0;
+	mpd->next_page = index;
 	/*
 	 * Start a transaction for writeback of journalled data. We don't start
 	 * the transaction if the filesystem is frozen. In that case we
@@ -2443,8 +2445,6 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
 			return PTR_ERR(handle);
 	}
 	folio_batch_init(&fbatch);
-	mpd->map.m_len = 0;
-	mpd->next_page = index;
 	while (index <= end) {
 		nr_folios = filemap_get_folios_tag(mapping, &index, end,
 				tag, &fbatch);
Signature · 1 line
2.35.3
maintainer
#3 lore raw
In reply to Jan Kara
Quoted 4 lines · Jan Kara

Hello!

These two patches fix two problems introduced by the rewrite of journalled writeback path.

I've folded these patches into the "ext4: Covert data=journal writeback to use ext4_writepages()" commit in my tree. Thanks,

- Ted