Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	 Bart Van Assche <bvanassche@acm.org>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
	 Dave Kleikamp <shaggy@kernel.org>,
	jfs-discussion@lists.sourceforge.net,
	 Edward Adam Davis <eadavis@qq.com>, Jens Axboe <axboe@kernel.dk>,
	 Ming Lei <tom.leiming@gmail.com>,
	Hillf Danton <hdanton@sina.com>,  Tao Cui <cui.tao@linux.dev>,
	Al Viro <viro@zeniv.linux.org.uk>,
	 Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	 Clark Williams <clrkwllms@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	 linux-rt-devel@lists.linux.dev, linux-block@vger.kernel.org,
	 "Christian Brauner (Amutable)" <brauner@kernel.org>,
	stable@vger.kernel.org,
	 syzbot+2e5cf2352e9f69ebf172@syzkaller.appspotmail.com
Subject: [PATCH 2/2] jfs: set lbmDONE before dropping LCACHE_LOCK for lmPostGC()
Date: Mon, 23 Nov 2026 14:02:19 +0100	[thread overview]
Message-ID: <20261123-work-loop-backing-file-v1-2-48f83eaf2499@kernel.org> (raw)
In-Reply-To: <20261123-work-loop-backing-file-v1-0-48f83eaf2499@kernel.org>

Since commit b15e4310633f ("jfs: Set the lbmDone flag at the end of
lbmIODone") lbmIODone() sets lbmDONE as the very last thing. For a group
commit write that means after it dropped LCACHE_LOCK, called lmPostGC()
and took the lock again. But lmPostGC() can hand the buffer back to the
freelist via lbmFree() or queue it for the next write via lbmWrite(),
and the buffer of the current log page is written by group commit over
and over. So the lbmDONE set afterwards can land on the next I/O of the
buffer.

At unmount lmLogShutdown() writes the current log page via lbmWrite()
and waits for it via lbmIOWait(log->bp, lbmFREE). If the completion of
an earlier group commit write of that page sets its lbmDONE in between
then lbmIOWait() returns while the page is still in flight and on the
write queue and lbmfree() asserts:

  BUG at fs/jfs/jfs_logmgr.c:1919 assert(bp->l_wqnext == NULL)
  kernel BUG at fs/jfs/jfs_logmgr.c:1919!
  RIP: 0010:lbmfree fs/jfs/jfs_logmgr.c:1919 [inline]
  RIP: 0010:lbmIOWait+0x5ab/0x5b0 fs/jfs/jfs_logmgr.c:2154
  Call Trace:
   lmLogShutdown+0x1ff/0x850 fs/jfs/jfs_logmgr.c:1657
   lmLogClose+0x28c/0x530 fs/jfs/jfs_logmgr.c:1457
   jfs_umount+0x2da/0x3b0 fs/jfs/jfs_umount.c:124
   jfs_put_super+0x8c/0x190 fs/jfs/super.c:194
   generic_shutdown_super+0x13d/0x2d0 fs/super.c:751
   kill_block_super+0x44/0xa0 fs/super.c:1903
   deactivate_locked_super+0xbe/0x110 fs/super.c:586
   cleanup_mnt+0x204/0x2a0 fs/namespace.c:1396

In my build of the same config R12 holds bp->l_flag at that point and in
the report it is 0x2e, i.e., lbmWRITE | lbmRELEASE | lbmSYNC | lbmDONE.
So the completion of the write lmLogShutdown() waits for hasn't run yet
and lbmDONE came from somewhere else. A completion that only gets to the
buffer after lbmWrite() stored those flags takes them for its own,
clears lbmWRITE and takes the buffer off the write queue. A read
completion clears lbmREAD and sets lbmDONE under the same LCACHE_LOCK.
The group commit branch is the only place in lbmIODone() that drops
LCACHE_LOCK before it sets lbmDONE.

With a workload that writes and fsyncs a few files before every unmount
on PREEMPT_RT the late lbmDONE lands on a new I/O of the buffer in about
one out of ten group commit completions. Mostly that's the next write
lmPostGC() itself just queued. But in about one out of 1800 completions
another task reinitialized the buffer while the lock was dropped.
Preempted completions kept it dropped for up to 14 ms. I haven't seen
the late lbmDONE land on lmLogShutdown()'s final write on its own in
about a million unmounts. But with a debug patch that holds the
completion right after lmPostGC() until lmLogShutdown() has submitted
that write every VM hits exactly the BUG above within the first few
unmounts, with the same 0x2e in R12. With this patch the same delay
leaves the completion nothing to do after lmPostGC() and 15400 unmounts
run clean.

So set lbmDONE before dropping the lock for lmPostGC() like lbmIODone()
did before commit b15e4310633f ("jfs: Set the lbmDone flag at the end of
lbmIODone") and don't touch the buffer after lmPostGC(). That doesn't
bring back what that commit fixed. That was lbmRead() returning while
lbmIODone() still used the buffer. Nobody waits for lbmDONE on a group
commit write. The transactions wait for their commit records via
tblkGC_COMMITTED instead.

Fixes: b15e4310633f ("jfs: Set the lbmDone flag at the end of lbmIODone")
Cc: stable@vger.kernel.org
Reported-by: syzbot+2e5cf2352e9f69ebf172@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=2e5cf2352e9f69ebf172
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 fs/jfs/jfs_logmgr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index e96593d79a1df..ae3bd0cd85471 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -2279,9 +2279,11 @@ static void lbmIODone(struct bio *bio)
 	 *	Group Commit pageout:
 	 */
 	else if (bp->l_flag & lbmGC) {
+		/* lmPostGC() may free or requeue @bp. */
+		bp->l_flag |= lbmDONE;
 		LCACHE_UNLOCK(flags);
 		lmPostGC(bp);
-		LCACHE_LOCK(flags);		/* disable+lock */
+		return;
 	}
 
 	/*

-- 
2.53.0


      parent reply	other threads:[~2026-11-23 13:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 13:02 [PATCH 0/2] jfs: fix lbmDONE races in lbmIODone() (was "loop bug saga") Christian Brauner
2026-11-23 13:02 ` [PATCH 1/2] jfs: wait for lbmDONE under LCACHE_LOCK in lbmRead() Christian Brauner
2026-11-23 13:02 ` Christian Brauner [this message]

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=20261123-work-loop-backing-file-v1-2-48f83eaf2499@kernel.org \
    --to=brauner@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=bigeasy@linutronix.de \
    --cc=bvanassche@acm.org \
    --cc=clrkwllms@kernel.org \
    --cc=cui.tao@linux.dev \
    --cc=eadavis@qq.com \
    --cc=hch@lst.de \
    --cc=hdanton@sina.com \
    --cc=jfs-discussion@lists.sourceforge.net \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=rostedt@goodmis.org \
    --cc=shaggy@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+2e5cf2352e9f69ebf172@syzkaller.appspotmail.com \
    --cc=tom.leiming@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /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