Skip to contentSkip to conversation

gfs2: wait for bio in gfs2_write_log_header

PATCH New Andreas Gruenbacher 2 participants 2 messages Nov 26 GFS2 file system

lore
Share & tools
lore

Andreas Gruenbacher

author maintainer
#0 lore raw

PATCH 1/1 gfs2: wait for bio in gfs2_write_log_header

During journal recovery, clean_journal() calls gfs2_write_log_header(), which allocates a page from gfs2_page_pool, puts that page in a bio, and submits the bio. If a subsequent step in gfs2_fill_super() fails after journal replay, or a read-only mount that replayed a journal is unmounted (where gfs2_put_super() skips gfs2_make_fs_ro()), the journal glock can get dropped before the bio completes. Also, if the module is immediately removed, gfs2_page_pool can get destroyed before the page is freed.

This very unlikely race was pointed out by Sashiko.

Fix by moving the call to log_flush_wait() from log_write_header() to gfs2_write_log_header().

---
 fs/gfs2/log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/gfs2/log.c +1 -1
index 1baaaf30c4fa..db40045ee2d0 100644
@@ -908,6 +908,7 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
 	gfs2_log_write(sdp, jd, page, sb->s_blocksize, 0, dblock,
 		       REQ_OP_WRITE | op_flags);
 	gfs2_log_submit_write(&jd->jd_log_bio);
+	log_flush_wait(sdp);
 }
 
 /**
@@ -935,7 +936,6 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
 			      sdp->sd_log_flush_tail, sdp->sd_log_flush_head,
 			      flags, op_flags);
 	gfs2_log_incr_head(sdp);
-	log_flush_wait(sdp);
 	log_pull_tail(sdp);
 	gfs2_log_update_head(sdp);
 }
Signature · 1 line
2.56.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] gfs2: early withdraw returns in gfs2_write_log_header() skip log_flush_wait() - [Low] gfs2…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] gfs2: early withdraw returns in gfs2_write_log_header() skip log_flush_wait()
- [Low] gfs2: missing Fixes: trailer for commit 4a3d049db42b in commit message
--

commit 189e12a17911781cb0db12a8bd02ce7d201fa367
Author: Andreas Gruenbacher <[email protected]>

Quoted 11 lines

gfs2: wait for bio in gfs2_write_log_header

During journal recovery, clean_journal() calls gfs2_write_log_header(), which allocates a page from gfs2_page_pool, puts that page in a bio, and submits the bio. If a subsequent step in gfs2_fill_super() fails after journal replay, or a read-only mount that replayed a journal is unmounted (where gfs2_put_super() skips gfs2_make_fs_ro()), the journal glock can get dropped before the bio completes. Also, if the module is immediately removed, gfs2_page_pool can get destroyed before the page is freed.

Quoted 6 lines

This very unlikely race was pointed out by Sashiko.

Fix by moving the call to log_flush_wait() from log_write_header() to gfs2_write_log_header().

[Severity: Low]
Should this include a Fixes tag for the commit that moved log_flush_wait() out of gfs2_write_log_header()?

Fixes 4a3d049db42b ("gfs2: Don't wait for journal flush in clean_journal")
Quoted 13 lines
fs/gfs2/log.c +1 -0
index 1baaaf30c4fa6..db40045ee2d0a 100644
@@ -908,6 +908,7 @@ void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd,
 	gfs2_log_write(sdp, jd, page, sb->s_blocksize, 0, dblock,
 		       REQ_OP_WRITE | op_flags);
 	gfs2_log_submit_write(&jd->jd_log_bio);
+	log_flush_wait(sdp);
 }
 
 /**

fs/gfs2/log.c static void log_write_header(struct gfs2_sbd *sdp, u32 flags) · line 941

Quoted 7 lines
fs/gfs2/log.c +0 -1
@@ -935,7 +936,6 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags)
 			      sdp->sd_log_flush_tail, sdp->sd_log_flush_head,
 			      flags, op_flags);
 	gfs2_log_incr_head(sdp);
-	log_flush_wait(sdp);
 	log_pull_tail(sdp);
 	gfs2_log_update_head(sdp);
 }

[Severity: Medium]
Can moving log_flush_wait(sdp) to the bottom of gfs2_write_log_header() leave transaction payload bios in flight when the filesystem withdraws?

__gfs2_log_flush() submits payload bios through lops_before_commit() and gfs2_log_submit_write() before calling log_write_header(). If the filesystem withdraws before gfs2_write_log_header() reaches gfs2_log_submit_write() (or if gfs2_get_extent() fails there), the early returns in gfs2_write_log_header() bypass log_flush_wait(sdp):

fs/gfs2/log.c:gfs2_write_log_header() {
	...
	if (gfs2_withdrawn(sdp))
		return;
	...
		ret = gfs2_get_extent(jd->jd_inode, lblock, &dblock, &extlen);
		if (gfs2_assert_withdraw(sdp, ret == 0))
			return;
	...
}

Before 4a3d049db42b ("gfs2: Don't wait for journal flush in clean_journal"), the gfs2_withdrawn(sdp) check jumped to an out label that still called log_flush_wait(sdp). Without that wait, __gfs2_log_flush() finishes while earlier payload bios are still in flight, allowing unmount and module removal to free sdp and destroy gfs2_page_pool before gfs2_end_log_write() runs.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1