[PATCH] btrfs: grab delalloc inode before dropping lock

From: Haoli Zhang

Date: Fri Dec 04 2026 - 23:06:57 EST


During transaction cleanup, btrfs_destroy_delalloc_inodes() removes an
inode from the delalloc list while holding root->delalloc_lock, but drops
the lock before calling igrab(). Inode eviction can then clear the
delalloc state and free the inode before igrab() has acquired a reference.

Call igrab() before releasing root->delalloc_lock. This serializes the
reference acquisition with the delalloc cleanup performed during
eviction. Keep page invalidation and iput() after unlocking, as they may
sleep.

Fixes: fe816d0f1d4c ("btrfs: Fix delalloc inodes invalidation during transaction abort")
Reported-by: syzbot+9b287ab048073bea5a2c@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=9b287ab048073bea5a2c
Co-developed-by: Jinning Zhang <25031212117@xxxxxxxxxxxxxxxxx>
Signed-off-by: Jinning Zhang <25031212117@xxxxxxxxxxxxxxxxx>
Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Signed-off-by: Haoli Zhang <26031212468@xxxxxxxxxxxxxxxxx>
---
fs/btrfs/disk-io.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
base-commit: d06ce6f1eb5eeffd4ebcfde345dc34a98131d106

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -4470,10 +4470,10 @@ static void btrfs_destroy_delalloc_inodes(struct btrfs_root *root)
btrfs_del_delalloc_inode(btrfs_inode);
- spin_unlock(&root->delalloc_lock);

/*
* Make sure we get a live inode and that it'll not disappear
* meanwhile.
*/
inode = igrab(&btrfs_inode->vfs_inode);
+ spin_unlock(&root->delalloc_lock);
if (inode) {
unsigned int nofs_flag;
--
2.43.0