acrn-kernel/fs/btrfs
Josef Bacik 02f2b95b00 btrfs: don't drop extent_map for free space inode on write error
commit 5571e41ec6e56e35f34ae9f5b3a335ef510e0ade upstream.

While running the CI for an unrelated change I hit the following panic
with generic/648 on btrfs_holes_spacecache.

assertion failed: block_start != EXTENT_MAP_HOLE, in fs/btrfs/extent_io.c:1385
------------[ cut here ]------------
kernel BUG at fs/btrfs/extent_io.c:1385!
invalid opcode: 0000 [#1] PREEMPT SMP NOPTI
CPU: 1 PID: 2695096 Comm: fsstress Kdump: loaded Tainted: G        W          6.8.0-rc2+ #1
RIP: 0010:__extent_writepage_io.constprop.0+0x4c1/0x5c0
Call Trace:
 <TASK>
 extent_write_cache_pages+0x2ac/0x8f0
 extent_writepages+0x87/0x110
 do_writepages+0xd5/0x1f0
 filemap_fdatawrite_wbc+0x63/0x90
 __filemap_fdatawrite_range+0x5c/0x80
 btrfs_fdatawrite_range+0x1f/0x50
 btrfs_write_out_cache+0x507/0x560
 btrfs_write_dirty_block_groups+0x32a/0x420
 commit_cowonly_roots+0x21b/0x290
 btrfs_commit_transaction+0x813/0x1360
 btrfs_sync_file+0x51a/0x640
 __x64_sys_fdatasync+0x52/0x90
 do_syscall_64+0x9c/0x190
 entry_SYSCALL_64_after_hwframe+0x6e/0x76

This happens because we fail to write out the free space cache in one
instance, come back around and attempt to write it again.  However on
the second pass through we go to call btrfs_get_extent() on the inode to
get the extent mapping.  Because this is a new block group, and with the
free space inode we always search the commit root to avoid deadlocking
with the tree, we find nothing and return a EXTENT_MAP_HOLE for the
requested range.

This happens because the first time we try to write the space cache out
we hit an error, and on an error we drop the extent mapping.  This is
normal for normal files, but the free space cache inode is special.  We
always expect the extent map to be correct.  Thus the second time
through we end up with a bogus extent map.

Since we're deprecating this feature, the most straightforward way to
fix this is to simply skip dropping the extent map range for this failed
range.

I shortened the test by using error injection to stress the area to make
it easier to reproduce.  With this patch in place we no longer panic
with my error injection test.

CC: stable@vger.kernel.org # 4.14+
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-02-23 09:12:29 +01:00
..
tests btrfs: convert btrfs_block_group::needs_free_space to runtime flag 2023-08-23 17:52:28 +02:00
Kconfig
Makefile
acl.c
async-thread.c
async-thread.h
backref.c
backref.h
block-group.c btrfs: do not delete unused block group if it may be used soon 2024-02-23 09:12:28 +01:00
block-group.h btrfs: add and use helper to check if block group is used 2024-02-23 09:12:28 +01:00
block-rsv.c
block-rsv.h
btrfs_inode.h
check-integrity.c
check-integrity.h
compression.c
compression.h
ctree.c btrfs: error out when reallocating block for defrag using a stale transaction 2023-10-25 12:03:11 +02:00
ctree.h btrfs: fix infinite directory reads 2024-01-31 16:17:05 -08:00
delalloc-space.c btrfs: don't reserve space for checksums when writing to nocow files 2024-02-23 09:12:29 +01:00
delalloc-space.h
delayed-inode.c btrfs: fix infinite directory reads 2024-01-31 16:17:05 -08:00
delayed-inode.h btrfs: fix infinite directory reads 2024-01-31 16:17:05 -08:00
delayed-ref.c btrfs: prevent transaction block reserve underflow when starting transaction 2023-10-25 12:03:09 +02:00
delayed-ref.h btrfs: prevent transaction block reserve underflow when starting transaction 2023-10-25 12:03:09 +02:00
dev-replace.c
dev-replace.h
dir-item.c btrfs: use struct fscrypt_str instead of struct qstr 2023-10-10 22:00:36 +02:00
discard.c
discard.h
disk-io.c btrfs: do not ASSERT() if the newly created subvolume already got read 2024-02-23 09:12:29 +01:00
disk-io.h
export.c
export.h
extent-io-tree.c
extent-io-tree.h
extent-tree.c btrfs: zoned: optimize hint byte for zoned allocator 2024-01-31 16:17:10 -08:00
extent_io.c btrfs: don't clear qgroup reserved bit in release_folio 2023-12-20 17:00:26 +01:00
extent_io.h
extent_map.c btrfs: fix incorrect splitting in btrfs_drop_extent_map_range 2023-08-23 17:52:31 +02:00
extent_map.h
file-item.c btrfs: mark the len field in struct btrfs_ordered_sum as unsigned 2024-01-10 17:10:35 +01:00
file.c btrfs: fix qgroup_free_reserved_data int overflow 2024-01-10 17:10:35 +01:00
free-space-cache.c btrfs: zoned: no longer count fresh BG region as zone unusable 2024-01-01 12:39:06 +00:00
free-space-cache.h
free-space-tree.c btrfs: convert btrfs_block_group::needs_free_space to runtime flag 2023-08-23 17:52:28 +02:00
free-space-tree.h
inode-item.c btrfs: use struct fscrypt_str instead of struct qstr 2023-10-10 22:00:36 +02:00
inode-item.h btrfs: use struct fscrypt_str instead of struct qstr 2023-10-10 22:00:36 +02:00
inode.c btrfs: don't drop extent_map for free space inode on write error 2024-02-23 09:12:29 +01:00
ioctl.c btrfs: forbid creating subvol qgroups 2024-02-23 09:12:28 +01:00
locking.c
locking.h
lzo.c
misc.h
ordered-data.c btrfs: fix qgroup_free_reserved_data int overflow 2024-01-10 17:10:35 +01:00
ordered-data.h btrfs: mark the len field in struct btrfs_ordered_sum as unsigned 2024-01-10 17:10:35 +01:00
orphan.c
print-tree.c
print-tree.h
props.c
props.h
qgroup.c btrfs: forbid deleting live subvol qgroup 2024-02-23 09:12:29 +01:00
qgroup.h btrfs: fix qgroup_free_reserved_data int overflow 2024-01-10 17:10:35 +01:00
raid56.c
raid56.h
rcu-string.h
ref-verify.c btrfs: ref-verify: free ref cache before clearing mount opt 2024-01-31 16:17:07 -08:00
ref-verify.h
reflink.c
reflink.h
relocation.c btrfs: set page extent mapped after read_folio in relocate_one_page 2023-09-19 12:28:06 +02:00
root-tree.c btrfs: use struct fscrypt_str instead of struct qstr 2023-10-10 22:00:36 +02:00
scrub.c
send.c btrfs: send: return EOPNOTSUPP on unknown flags 2024-02-23 09:12:29 +01:00
send.h
space-info.c btrfs: zoned: re-enable metadata over-commit for zoned mode 2023-09-19 12:28:06 +02:00
space-info.h
struct-funcs.c
subpage.c
subpage.h
super.c btrfs: add dmesg output for first mount and last unmount of a filesystem 2023-12-08 08:51:16 +01:00
sysfs.c btrfs: sysfs: validate scrub_speed_max value 2024-01-31 16:16:58 -08:00
sysfs.h
transaction.c btrfs: prevent transaction block reserve underflow when starting transaction 2023-10-25 12:03:09 +02:00
transaction.h
tree-checker.c btrfs: tree-checker: fix inline ref size in error messages 2024-01-31 16:17:07 -08:00
tree-checker.h
tree-defrag.c
tree-log.c btrfs: initialize start_slot in btrfs_log_prealloc_extents 2023-10-25 12:03:09 +02:00
tree-log.h btrfs: use struct fscrypt_str instead of struct qstr 2023-10-10 22:00:36 +02:00
tree-mod-log.c
tree-mod-log.h
ulist.c
ulist.h
uuid-tree.c
verity.c
volumes.c btrfs: make error messages more clear when getting a chunk map 2023-12-08 08:51:16 +01:00
volumes.h btrfs: add a helper to read the superblock metadata_uuid 2023-09-23 11:11:08 +02:00
xattr.c
xattr.h
zlib.c
zoned.c btrfs: zoned: no longer count fresh BG region as zone unusable 2024-01-01 12:39:06 +00:00
zoned.h
zstd.c