gfs2: wait for bio in gfs2_write_log_header
Andreas Gruenbacher
maintainerPATCH 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
@@ -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
[email protected]
AI reviewThank 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_headerDuring journal recovery,
clean_journal()callsgfs2_write_log_header(), which allocates a page fromgfs2_page_pool, puts that page in a bio, and submits the bio. If a subsequent step ingfs2_fill_super()fails after journal replay, or a read-only mount that replayed a journal is unmounted (wheregfs2_put_super()skipsgfs2_make_fs_ro()), the journal glock can get dropped before the bio completes. Also, if the module is immediately removed,gfs2_page_poolcan 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()fromlog_write_header()togfs2_write_log_header().Signed-off-by Andreas Gruenbacher <[email protected]>
[Severity: Low]
Should this include a Fixes tag for the commit that moved log_flush_wait() out of gfs2_write_log_header()?
Quoted 13 lines
fs/gfs2/log.c +1
-0@@ -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