linux-stable/fs/btrfs
Filipe Manana 7e9422d35d btrfs: fix data race at btrfs_use_block_rsv() when accessing block reserve
[ Upstream commit c7bb26b847 ]

At btrfs_use_block_rsv() we read the size of a block reserve without
locking its spinlock, which makes KCSAN complain because the size of a
block reserve is always updated while holding its spinlock. The report
from KCSAN is the following:

  [653.313148] BUG: KCSAN: data-race in btrfs_update_delayed_refs_rsv [btrfs] / btrfs_use_block_rsv [btrfs]

  [653.314755] read to 0x000000017f5871b8 of 8 bytes by task 7519 on cpu 0:
  [653.314779]  btrfs_use_block_rsv+0xe4/0x2f8 [btrfs]
  [653.315606]  btrfs_alloc_tree_block+0xdc/0x998 [btrfs]
  [653.316421]  btrfs_force_cow_block+0x220/0xe38 [btrfs]
  [653.317242]  btrfs_cow_block+0x1ac/0x568 [btrfs]
  [653.318060]  btrfs_search_slot+0xda2/0x19b8 [btrfs]
  [653.318879]  btrfs_del_csums+0x1dc/0x798 [btrfs]
  [653.319702]  __btrfs_free_extent.isra.0+0xc24/0x2028 [btrfs]
  [653.320538]  __btrfs_run_delayed_refs+0xd3c/0x2390 [btrfs]
  [653.321340]  btrfs_run_delayed_refs+0xae/0x290 [btrfs]
  [653.322140]  flush_space+0x5e4/0x718 [btrfs]
  [653.322958]  btrfs_preempt_reclaim_metadata_space+0x102/0x2f8 [btrfs]
  [653.323781]  process_one_work+0x3b6/0x838
  [653.323800]  worker_thread+0x75e/0xb10
  [653.323817]  kthread+0x21a/0x230
  [653.323836]  __ret_from_fork+0x6c/0xb8
  [653.323855]  ret_from_fork+0xa/0x30

  [653.323887] write to 0x000000017f5871b8 of 8 bytes by task 576 on cpu 3:
  [653.323906]  btrfs_update_delayed_refs_rsv+0x1a4/0x250 [btrfs]
  [653.324699]  btrfs_add_delayed_data_ref+0x468/0x6d8 [btrfs]
  [653.325494]  btrfs_free_extent+0x76/0x120 [btrfs]
  [653.326280]  __btrfs_mod_ref+0x6a8/0x6b8 [btrfs]
  [653.327064]  btrfs_dec_ref+0x50/0x70 [btrfs]
  [653.327849]  walk_up_proc+0x236/0xa50 [btrfs]
  [653.328633]  walk_up_tree+0x21c/0x448 [btrfs]
  [653.329418]  btrfs_drop_snapshot+0x802/0x1328 [btrfs]
  [653.330205]  btrfs_clean_one_deleted_snapshot+0x184/0x238 [btrfs]
  [653.330995]  cleaner_kthread+0x2b0/0x2f0 [btrfs]
  [653.331781]  kthread+0x21a/0x230
  [653.331800]  __ret_from_fork+0x6c/0xb8
  [653.331818]  ret_from_fork+0xa/0x30

So add a helper to get the size of a block reserve while holding the lock.
Reading the field while holding the lock instead of using the data_race()
annotation is used in order to prevent load tearing.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-03-26 18:17:54 -04:00
..
tests btrfs: abort transaction on generation mismatch when marking eb as dirty 2023-10-12 16:44:07 +02:00
accessors.c
accessors.h btrfs: qgroup: check generation when recording simple quota delta 2023-10-12 16:44:11 +02:00
acl.c
acl.h
async-thread.c btrfs: merge ordered work callbacks in btrfs_work into one 2023-10-12 16:44:10 +02:00
async-thread.h btrfs: merge ordered work callbacks in btrfs_work into one 2023-10-12 16:44:10 +02:00
backref.c for-6.7-tag 2023-10-30 10:42:06 -10:00
backref.h for-6.7-tag 2023-10-30 10:42:06 -10:00
bio.c btrfs: merge ordered work callbacks in btrfs_work into one 2023-10-12 16:44:10 +02:00
bio.h btrfs: add an ordered_extent pointer to struct btrfs_bio 2023-06-19 13:59:36 +02:00
block-group.c btrfs: add new unused block groups to the list of unused block groups 2024-02-23 09:51:21 +01:00
block-group.h btrfs: add and use helper to check if block group is used 2024-02-23 09:51:21 +01:00
block-rsv.c btrfs: fix data race at btrfs_use_block_rsv() when accessing block reserve 2024-03-26 18:17:54 -04:00
block-rsv.h btrfs: fix data race at btrfs_use_block_rsv() when accessing block reserve 2024-03-26 18:17:54 -04:00
btrfs_inode.h btrfs: open code timespec64 in struct btrfs_inode 2023-10-12 16:44:19 +02:00
compression.c btrfs: rename errno identifiers to error 2023-10-12 16:44:07 +02:00
compression.h btrfs: pass an ordered_extent to btrfs_submit_compressed_write 2023-06-19 13:59:36 +02:00
ctree.c for-6.7-rc1-tag 2023-11-13 09:09:12 -08:00
ctree.h for-6.7-tag 2023-10-30 10:42:06 -10:00
defrag.c btrfs: defrag: avoid unnecessary defrag caused by incorrect extent size 2024-03-01 13:41:45 +01:00
defrag.h btrfs: move btrfs_defrag_root() to defrag.{c,h} 2023-10-12 16:44:13 +02:00
delalloc-space.c btrfs: don't reserve space for checksums when writing to nocow files 2024-02-23 09:51:22 +01:00
delalloc-space.h
delayed-inode.c for-6.7-tag 2023-10-30 10:42:06 -10:00
delayed-inode.h btrfs: remove redundant root argument from btrfs_delayed_update_inode() 2023-10-12 16:44:12 +02:00
delayed-ref.c btrfs: fix qgroup record leaks when using simple quotas 2023-11-09 14:01:59 +01:00
delayed-ref.h btrfs: stop reserving excessive space for block group item insertions 2023-10-12 16:44:16 +02:00
dev-replace.c btrfs: dev-replace: properly validate device names 2024-03-06 14:53:55 +00:00
dev-replace.h
dir-item.c btrfs: abort transaction on generation mismatch when marking eb as dirty 2023-10-12 16:44:07 +02:00
dir-item.h btrfs: add fscrypt related dependencies to respective headers 2023-10-12 16:44:02 +02:00
discard.c
discard.h
disk-io.c btrfs: fix double free of anonymous device after snapshot creation failure 2024-03-06 14:53:55 +00:00
disk-io.h btrfs: fix double free of anonymous device after snapshot creation failure 2024-03-06 14:53:55 +00:00
export.c
export.h
extent-io-tree.c btrfs: make sure we cache next state in find_first_extent_bit() 2023-10-12 16:44:15 +02:00
extent-io-tree.h btrfs: make wait_extent_bit() static 2023-10-12 16:44:15 +02:00
extent-tree.c btrfs: zoned: optimize hint byte for zoned allocator 2024-01-31 16:21:16 -08:00
extent-tree.h btrfs: get correct owning_root when dropping snapshot 2023-11-03 16:39:06 +01:00
extent_io.c btrfs: fix race between ordered extent completion and fiemap 2024-03-06 14:53:54 +00:00
extent_io.h btrfs: move extent_buffer::lock_owner to debug section 2023-10-12 16:44:05 +02:00
extent_map.c btrfs: fix incorrect splitting in btrfs_drop_extent_map_range 2023-08-18 14:38:10 +02:00
extent_map.h btrfs: pass the new logical address to split_extent_map 2023-06-19 13:59:33 +02:00
file-item.c btrfs: abort transaction on generation mismatch when marking eb as dirty 2023-10-12 16:44:07 +02:00
file-item.h btrfs: scrub: avoid unnecessary csum tree search preparing stripes 2023-08-21 14:54:48 +02:00
file.c for-6.7-rc5-tag 2023-12-14 11:53:00 -08:00
file.h
free-space-cache.c btrfs: remove redundant root argument from btrfs_update_inode() 2023-10-12 16:44:12 +02:00
free-space-cache.h
free-space-tree.c btrfs: abort transaction on generation mismatch when marking eb as dirty 2023-10-12 16:44:07 +02:00
free-space-tree.h
fs.c
fs.h btrfs: add and use helpers for reading and writing last_trans_committed 2023-10-12 16:44:17 +02:00
inode-item.c btrfs: track owning root in btrfs_ref 2023-10-12 16:44:11 +02:00
inode-item.h btrfs: add fscrypt related dependencies to respective headers 2023-10-12 16:44:02 +02:00
inode.c btrfs: don't drop extent_map for free space inode on write error 2024-02-23 09:51:22 +01:00
ioctl.c btrfs: fix double free of anonymous device after snapshot creation failure 2024-03-06 14:53:55 +00:00
ioctl.h
Kconfig btrfs: check-integrity: remove CONFIG_BTRFS_FS_CHECK_INTEGRITY option 2023-10-12 16:44:05 +02:00
locking.c btrfs: add raid stripe tree definitions 2023-10-12 16:44:09 +02:00
locking.h btrfs: do not block starts waiting on previous transaction commit 2023-09-08 14:10:49 +02:00
lru_cache.c
lru_cache.h
lzo.c btrfs: disable allocation warnings for compression workspaces 2023-06-19 13:59:34 +02:00
Makefile btrfs: add support for inserting raid stripe extents 2023-10-12 16:44:09 +02:00
messages.c btrfs: rename errno identifiers to error 2023-10-12 16:44:07 +02:00
messages.h btrfs: rename errno identifiers to error 2023-10-12 16:44:07 +02:00
misc.h minmax: add in_range() macro 2023-08-24 16:20:18 -07:00
ordered-data.c btrfs: fix qgroup_free_reserved_data int overflow 2023-12-06 22:32:46 +01:00
ordered-data.h btrfs: open code btrfs_ordered_inode_tree in btrfs_inode 2023-10-12 16:44:16 +02:00
orphan.c
orphan.h
print-tree.c btrfs: new inline ref storing owning subvol of data extents 2023-10-12 16:44:11 +02:00
print-tree.h
props.c btrfs: move btrfs_name_hash to dir-item.h 2023-10-12 16:44:02 +02:00
props.h
qgroup.c btrfs: forbid deleting live subvol qgroup 2024-02-23 09:51:22 +01:00
qgroup.h btrfs: ensure releasing squota reserve on head refs 2023-12-06 22:32:57 +01:00
raid-stripe-tree.c btrfs: directly return 0 on no error code in btrfs_insert_raid_extent() 2023-11-03 16:38:51 +01:00
raid-stripe-tree.h btrfs: zoned: support RAID0/1/10 on top of raid stripe tree 2023-10-12 16:44:09 +02:00
raid56.c btrfs: scrub: avoid unnecessary csum tree search preparing stripes 2023-08-21 14:54:48 +02:00
raid56.h btrfs: raid56: remove unused BTRFS_RBIO_REBUILD_MISSING 2023-08-21 14:52:12 +02:00
rcu-string.h
ref-verify.c btrfs: ref-verify: free ref cache before clearing mount opt 2024-01-31 16:21:11 -08:00
ref-verify.h
reflink.c for-6.7-tag 2023-10-30 10:42:06 -10:00
reflink.h
relocation.c for-6.7-tag 2023-10-30 10:42:06 -10:00
relocation.h btrfs: relocation: constify parameters where possible 2023-10-12 16:44:13 +02:00
root-tree.c btrfs: qgroup: add new quota mode for simple quotas 2023-10-12 16:44:10 +02:00
root-tree.h btrfs: drop __must_check annotations 2023-10-12 16:44:04 +02:00
scrub.c btrfs: scrub: avoid use-after-free when chunk length is not 64K aligned 2024-01-31 16:21:04 -08:00
scrub.h
send.c btrfs: send: don't issue unnecessary zero writes for trailing hole 2024-03-06 14:53:55 +00:00
send.h
space-info.c btrfs: fix data races when accessing the reserved amount of block reserves 2024-03-26 18:17:54 -04:00
space-info.h btrfs: pass a space_info argument to btrfs_reserve_metadata_bytes() 2023-10-12 16:44:05 +02:00
subpage.c btrfs: stop setting PageError in the data I/O path 2023-06-19 13:59:35 +02:00
subpage.h btrfs: stop setting PageError in the data I/O path 2023-06-19 13:59:35 +02:00
super.c for-6.7-rc3-tag 2023-11-28 11:16:04 -08:00
super.h
sysfs.c btrfs: sysfs: validate scrub_speed_max value 2024-01-31 16:20:54 -08:00
sysfs.h
transaction.c btrfs: fix double free of anonymous device after snapshot creation failure 2024-03-06 14:53:55 +00:00
transaction.h btrfs: free qgroup pertrans reserve on transaction abort 2023-12-06 22:32:49 +01:00
tree-checker.c btrfs: tree-checker: fix inline ref size in error messages 2024-01-31 16:21:11 -08:00
tree-checker.h
tree-log.c for-6.7-tag 2023-10-30 10:42:06 -10:00
tree-log.h
tree-mod-log.c btrfs: avoid tree mod log ENOMEM failures when we don't need to log 2023-06-19 13:59:38 +02:00
tree-mod-log.h
ulist.c btrfs: reformat remaining kdoc style comments 2023-10-12 16:44:04 +02:00
ulist.h
uuid-tree.c btrfs: abort transaction on generation mismatch when marking eb as dirty 2023-10-12 16:44:07 +02:00
uuid-tree.h
verity.c btrfs: remove redundant root argument from btrfs_update_inode() 2023-10-12 16:44:12 +02:00
verity.h
volumes.c for-6.7-rc3-tag 2023-11-28 11:16:04 -08:00
volumes.h for-6.7-tag 2023-10-30 10:42:06 -10:00
xattr.c for-6.7-tag 2023-10-30 10:42:06 -10:00
xattr.h btrfs: move btrfs_xattr_handlers to .rodata 2023-10-09 16:24:17 +02:00
zlib.c btrfs: disable allocation warnings for compression workspaces 2023-06-19 13:59:34 +02:00
zoned.c btrfs: zoned: don't skip block group profile checks on conventional zones 2024-03-26 18:17:54 -04:00
zoned.h btrfs: zoned: reserve zones for an active metadata/system block group 2023-08-21 14:52:19 +02:00
zstd.c btrfs: reformat remaining kdoc style comments 2023-10-12 16:44:04 +02:00