linux-stable/fs/btrfs
Josef Bacik 819a613012 btrfs: call __btrfs_remove_free_space_cache_locked on cache load failure
[ Upstream commit 8a1ae2781d ]

Now that lockdep is staying enabled through our entire CI runs I started
seeing the following stack in generic/475

------------[ cut here ]------------
WARNING: CPU: 1 PID: 2171864 at fs/btrfs/discard.c:604 btrfs_discard_update_discardable+0x98/0xb0
CPU: 1 PID: 2171864 Comm: kworker/u4:0 Not tainted 5.19.0-rc8+ #789
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014
Workqueue: btrfs-cache btrfs_work_helper
RIP: 0010:btrfs_discard_update_discardable+0x98/0xb0
RSP: 0018:ffffb857c2f7bad0 EFLAGS: 00010246
RAX: 0000000000000000 RBX: ffff8c85c605c200 RCX: 0000000000000001
RDX: 0000000000000000 RSI: ffffffff86807c5b RDI: ffffffff868a831e
RBP: ffff8c85c4c54000 R08: 0000000000000000 R09: 0000000000000000
R10: ffff8c85c66932f0 R11: 0000000000000001 R12: ffff8c85c3899010
R13: ffff8c85d5be4f40 R14: ffff8c85c4c54000 R15: ffff8c86114bfa80
FS:  0000000000000000(0000) GS:ffff8c863bd00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f2e7f168160 CR3: 000000010289a004 CR4: 0000000000370ee0
Call Trace:

 __btrfs_remove_free_space_cache+0x27/0x30
 load_free_space_cache+0xad2/0xaf0
 caching_thread+0x40b/0x650
 ? lock_release+0x137/0x2d0
 btrfs_work_helper+0xf2/0x3e0
 ? lock_is_held_type+0xe2/0x140
 process_one_work+0x271/0x590
 ? process_one_work+0x590/0x590
 worker_thread+0x52/0x3b0
 ? process_one_work+0x590/0x590
 kthread+0xf0/0x120
 ? kthread_complete_and_exit+0x20/0x20
 ret_from_fork+0x1f/0x30

This is the code

        ctl = block_group->free_space_ctl;
        discard_ctl = &block_group->fs_info->discard_ctl;

        lockdep_assert_held(&ctl->tree_lock);

We have a temporary free space ctl for loading the free space cache in
order to avoid having allocations happening while we're loading the
cache.  When we hit an error we free it all up, however this also calls
btrfs_discard_update_discardable, which requires
block_group->free_space_ctl->tree_lock to be held.  However this is our
temporary ctl so this lock isn't held.  Fix this by calling
__btrfs_remove_free_space_cache_locked instead so that we only clean up
the entries and do not mess with the discardable stats.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-10-24 09:58:22 +02:00
..
tests Revert "btrfs: turn fs_info member buffer_radix into XArray" 2022-07-15 19:14:33 +02:00
Kconfig btrfs: use generic Kconfig option for 256kB page size limit 2022-01-20 08:52:55 +02:00
Makefile Kbuild: add -Wno-shift-negative-value where -Wextra is used 2022-03-13 17:30:31 +09:00
acl.c btrfs: reserve correct number of items for inode creation 2022-05-16 17:03:08 +02:00
async-thread.c btrfs: simplify WQ_HIGHPRI handling in struct btrfs_workqueue 2022-05-16 17:03:15 +02:00
async-thread.h btrfs: simplify WQ_HIGHPRI handling in struct btrfs_workqueue 2022-05-16 17:03:15 +02:00
backref.c btrfs: unify the error handling pattern for read_tree_block() 2022-03-14 13:13:53 +01:00
backref.h btrfs: remove ignore_offset argument from btrfs_find_all_roots() 2021-08-23 13:19:01 +02:00
block-group.c btrfs: enhance unsupported compat RO flags handling 2022-10-24 09:56:52 +02:00
block-group.h btrfs: fix space cache corruption and potential double allocations 2022-08-31 17:18:12 +02:00
block-rsv.c btrfs: reserve extra space for the free space tree 2022-01-07 14:18:25 +01:00
block-rsv.h btrfs: init root block_rsv at init root time 2022-01-03 15:09:48 +01:00
btrfs_inode.h btrfs: move struct btrfs_dio_private to inode.c 2022-05-16 17:17:32 +02:00
check-integrity.c btrfs: check-integrity: simplify bio allocation in btrfsic_read_block 2022-05-16 17:03:12 +02:00
check-integrity.h btrfs: check-integrity: split submit_bio from btrfsic checking 2022-05-16 17:03:12 +02:00
compression.c btrfs: derive compression type from extent map during reads 2022-05-16 17:17:31 +02:00
compression.h btrfs: derive compression type from extent map during reads 2022-05-16 17:17:31 +02:00
ctree.c btrfs: fix lockdep splat with reloc root extent buffers 2022-09-05 10:31:35 +02:00
ctree.h btrfs: zoned: fix API misuse of zone finish waiting 2022-09-15 10:47:10 +02:00
delalloc-space.c btrfs: convert count_max_extents() to use fs_info->max_extent_size 2022-08-17 15:16:11 +02:00
delalloc-space.h
delayed-inode.c Revert "btrfs: turn delayed_nodes_tree into an XArray" 2022-07-15 19:15:19 +02:00
delayed-inode.h
delayed-ref.c btrfs: remove btrfs_delayed_extent_op::is_data 2022-05-16 17:17:31 +02:00
delayed-ref.h btrfs: remove btrfs_delayed_extent_op::is_data 2022-05-16 17:17:31 +02:00
dev-replace.c btrfs: add info when mount fails due to stale replace target 2022-08-31 17:18:12 +02:00
dev-replace.h
dir-item.c btrfs: use btrfs_for_each_slot in btrfs_search_dir_index_item 2022-05-16 17:03:07 +02:00
discard.c btrfs: fix typos in comments 2021-06-22 14:11:57 +02:00
discard.h
disk-io.c btrfs: fix hang during unmount when stopping a space reclaim worker 2022-09-28 11:32:04 +02:00
disk-io.h btrfs: move lockdep class helpers to locking.c 2022-09-05 10:31:35 +02:00
export.c
export.h
extent-io-tree.h btrfs: Convert from invalidatepage to invalidate_folio 2022-03-15 08:23:29 -04:00
extent-tree.c btrfs: set generation before calling btrfs_clean_tree_block in btrfs_init_new_buffer 2022-10-24 09:56:53 +02:00
extent_io.c btrfs: fix lockdep splat with reloc root extent buffers 2022-09-05 10:31:35 +02:00
extent_io.h Page cache changes for 5.19 2022-05-24 19:55:07 -07:00
extent_map.c btrfs: assert we have a write lock when removing and replacing extent maps 2022-03-14 13:13:50 +01:00
extent_map.h btrfs: defrag: don't use merged extent map for their generation check 2022-02-23 17:43:13 +01:00
file-item.c btrfs: handle csum lookup errors properly on reads 2022-03-14 13:13:51 +01:00
file.c btrfs: fix missed extent on fsync after dropping extent maps 2022-10-24 09:56:52 +02:00
free-space-cache.c btrfs: call __btrfs_remove_free_space_cache_locked on cache load failure 2022-10-24 09:58:22 +02:00
free-space-cache.h btrfs: change name and type of private member of btrfs_free_space_ctl 2022-01-03 15:09:50 +01:00
free-space-tree.c btrfs: use rbtree with leftmost node cached for tracking lowest block group 2022-05-16 17:03:13 +02:00
free-space-tree.h
inode-item.c btrfs: make should_throttle loop local in btrfs_truncate_inode_items 2022-01-07 14:18:25 +01:00
inode-item.h btrfs: add inode to truncate control 2022-01-07 14:18:24 +01:00
inode.c btrfs: zoned: fix API misuse of zone finish waiting 2022-09-15 10:47:10 +02:00
ioctl.c Page cache changes for 5.19 2022-05-24 19:55:07 -07:00
locking.c btrfs: fix lockdep splat with reloc root extent buffers 2022-09-05 10:31:35 +02:00
locking.h btrfs: fix lockdep splat with reloc root extent buffers 2022-09-05 10:31:35 +02:00
lzo.c btrfs: add lzo workspace buffer length constants 2022-03-14 13:13:50 +01:00
misc.h btrfs: use correct header for div_u64 in misc.h 2021-09-07 14:29:50 +02:00
ordered-data.c btrfs: add BTRFS_IOC_ENCODED_WRITE 2022-03-14 13:13:51 +01:00
ordered-data.h btrfs: add BTRFS_IOC_ENCODED_WRITE 2022-03-14 13:13:51 +01:00
orphan.c
print-tree.c btrfs: unify the error handling pattern for read_tree_block() 2022-03-14 13:13:53 +01:00
print-tree.h
props.c btrfs: move common inode creation code into btrfs_create_new_inode() 2022-05-16 17:03:08 +02:00
props.h btrfs: move common inode creation code into btrfs_create_new_inode() 2022-05-16 17:03:08 +02:00
qgroup.c btrfs: fix race between quota enable and quota rescan ioctl 2022-10-24 09:56:52 +02:00
qgroup.h btrfs: avoid blocking on space revervation when doing nowait dio writes 2022-05-16 17:03:10 +02:00
raid56.c btrfs: raid56: don't trust any cached sector in __raid56_parity_recover() 2022-08-21 15:20:08 +02:00
raid56.h btrfs: raid56: make raid56_add_scrub_pages() subpage compatible 2022-05-16 17:03:15 +02:00
rcu-string.h
ref-verify.c btrfs: stop accessing ->extent_root directly 2022-01-03 15:09:49 +01:00
ref-verify.h
reflink.c btrfs: add missing inode updates on each iteration when replacing extents 2022-06-21 14:43:21 +02:00
reflink.h
relocation.c btrfs: fix lockdep splat with reloc root extent buffers 2022-09-05 10:31:35 +02:00
root-tree.c btrfs: fix silent failure when deleting root reference 2022-08-31 17:18:12 +02:00
scrub.c btrfs: scrub: try to fix super block errors 2022-10-24 09:58:22 +02:00
send.c for-5.19-rc7-tag 2022-07-16 13:48:55 -07:00
send.h btrfs: reuse existing inode from btrfs_ioctl 2022-03-14 13:13:46 +01:00
space-info.c btrfs: fix the max chunk size and stripe length calculation 2022-09-15 10:47:16 +02:00
space-info.h btrfs: zoned: introduce space_info->active_total_bytes 2022-08-17 15:16:12 +02:00
struct-funcs.c btrfs: add special case to setget helpers for 64k pages 2021-08-23 13:18:58 +02:00
subpage.c btrfs: remove unnecessary type casts 2022-05-16 17:03:11 +02:00
subpage.h btrfs: make nodesize >= PAGE_SIZE case to reuse the non-subpage routine 2022-05-16 17:03:11 +02:00
super.c btrfs: don't print information about space cache or tree every remount 2022-10-24 09:58:22 +02:00
sysfs.c btrfs: change the bg_reclaim_threshold valid region from 0 to 100 2022-05-16 17:03:11 +02:00
sysfs.h
transaction.c Revert "btrfs: turn fs_roots_radix in btrfs_fs_info into an XArray" 2022-07-15 19:14:28 +02:00
transaction.h btrfs: pass btrfs_fs_info for deleting snapshots and cleaner 2022-03-14 13:13:52 +01:00
tree-checker.c btrfs: tree-checker: check for overlapping extent items 2022-09-05 10:31:35 +02:00
tree-checker.h btrfs: tree-checker: check extent buffer owner against owner rootid 2022-05-16 17:03:09 +02:00
tree-defrag.c btrfs: remove unnecessary extent root check in btrfs_defrag_leaves 2022-01-03 15:09:48 +01:00
tree-log.c btrfs: fix warning during log replay when bumping inode link count 2022-08-25 11:45:08 +02:00
tree-log.h btrfs: tree-log: make the return value for log syncing consistent 2022-08-17 15:16:10 +02:00
tree-mod-log.c btrfs: fix race when picking most recent mod log operation for an old root 2021-04-20 19:27:17 +02:00
tree-mod-log.h btrfs: add and use helper to get lowest sequence number for the tree mod log 2021-04-19 17:25:17 +02:00
ulist.c
ulist.h
uuid-tree.c btrfs: drop the _nr from the item helpers 2022-01-03 15:09:43 +01:00
verity.c btrfs: drop the _nr from the item helpers 2022-01-03 15:09:43 +01:00
volumes.c btrfs: fix the max chunk size and stripe length calculation 2022-09-15 10:47:16 +02:00
volumes.h for-5.19-tag 2022-05-24 18:52:35 -07:00
xattr.c btrfs: check if root is readonly while setting security xattr 2022-08-31 17:18:12 +02:00
xattr.h
zlib.c Revert "btrfs: compression: drop kmap/kunmap from zlib" 2021-10-29 13:03:05 +02:00
zoned.c btrfs: zoned: wait for extent buffer IOs before finishing a zone 2022-09-28 11:32:04 +02:00
zoned.h btrfs: zoned: activate metadata block group on flush_space 2022-08-17 15:16:12 +02:00
zstd.c btrfs: use non-bh spin_lock in zstd timer callback 2022-05-16 17:03:13 +02:00