android_kernel_motorola_sm6375/fs/btrfs
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Filipe Manana 7ad8aa6635 btrfs: use smp_mb__after_atomic() when forcing COW in create_pending_snapshot()
[ Upstream commit 45c222468d33202c07c41c113301a4b9c8451b8f ]

After setting the BTRFS_ROOT_FORCE_COW flag on the root we are doing a
full write barrier, smp_wmb(), but we don't need to, all we need is a
smp_mb__after_atomic().  The use of the smp_wmb() is from the old days
when we didn't use a bit and used instead an int field in the root to
signal if cow is forced. After the int field was changed to a bit in
the root's state (flags field), we forgot to update the memory barrier
in create_pending_snapshot() to smp_mb__after_atomic(), but we did the
change in commit_fs_roots() after clearing BTRFS_ROOT_FORCE_COW. That
happened in commit 27cdeb7096 ("Btrfs: use bitfield instead of integer
data type for the some variants in btrfs_root"). On the reader side, in
should_cow_block(), we also use the counterpart smp_mb__before_atomic()
which generates further confusion.

So change the smp_wmb() to smp_mb__after_atomic(). In fact we don't
even need any barrier at all since create_pending_snapshot() is called
in the critical section of a transaction commit and therefore no one
can concurrently join/attach the transaction, or start a new one, until
the transaction is unblocked. By the time someone starts a new transaction
and enters should_cow_block(), a lot of implicit memory barriers already
took place by having acquired several locks such as fs_info->trans_lock
and extent buffer locks on the root node at least. Nevertlheless, for
consistency use smp_mb__after_atomic() after setting the force cow bit
in create_pending_snapshot().

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>
2025-12-03 12:45:04 +01:00
..
tests
acl.c
async-thread.c
async-thread.h
backref.c btrfs: fix information leak in btrfs_ioctl_logical_to_ino() 2024-05-02 16:18:36 +02:00
backref.h
block-group.c
block-group.h
block-rsv.c btrfs: fix data race at btrfs_use_block_rsv() when accessing block reserve 2024-03-26 18:22:13 -04:00
block-rsv.h btrfs: fix data race at btrfs_use_block_rsv() when accessing block reserve 2024-03-26 18:22:13 -04:00
btrfs_inode.h
check-integrity.c
check-integrity.h
compression.c
compression.h
ctree.c
ctree.h btrfs: move btrfs_pinned_by_swapfile prototype into volumes.h 2023-09-23 11:00:05 +02:00
delalloc-space.c btrfs: don't arbitrarily slow down delalloc if we're committing 2023-11-28 16:50:19 +00:00
delalloc-space.h
delayed-inode.c btrfs: change BUG_ON to assertion when checking for delayed_node root 2024-09-04 13:14:56 +02:00
delayed-inode.h
delayed-ref.c btrfs: reinitialize delayed ref list after deleting it from the list 2024-11-17 14:58:51 +01:00
delayed-ref.h
dev-replace.c btrfs: dev-replace: properly validate device names 2024-03-06 14:36:09 +00:00
dev-replace.h
dir-item.c
disk-io.c btrfs: wait for fixup workers before stopping cleaner kthread during umount 2024-11-08 16:20:42 +01:00
disk-io.h
export.c btrfs: avoid potential out-of-bounds in btrfs_encode_fh() 2025-10-29 13:59:56 +01:00
export.h
extent-tree.c btrfs: clean up our handling of refs == 0 in snapshot delete 2024-09-12 11:03:54 +02:00
extent_io.c btrfs: avoid linker error in btrfs_find_create_tree_block() 2025-06-04 14:32:30 +02:00
extent_io.h
extent_map.c
extent_map.h
file-item.c
file.c
free-space-cache.c btrfs: rename bitmap_set_bits() -> btrfs_bitmap_set_bits() 2024-09-04 13:14:51 +02:00
free-space-cache.h
free-space-tree.c
free-space-tree.h
inode-item.c
inode-map.c
inode-map.h
inode.c btrfs: use btrfs_record_snapshot_destroy() during rmdir 2025-07-17 18:24:59 +02:00
ioctl.c btrfs: don't abort filesystem when attempting to snapshot deleted subvolume 2025-07-17 18:24:55 +02:00
Kconfig
locking.c
locking.h
lzo.c
Makefile
misc.h
ordered-data.c
ordered-data.h
orphan.c
print-tree.c
print-tree.h
props.c
props.h
qgroup.c btrfs: delete pointless BUG_ON check on quota root in btrfs_qgroup_account_extent() 2024-09-04 13:14:56 +02:00
qgroup.h
raid56.c
raid56.h
rcu-string.h
reada.c
ref-verify.c btrfs: ref-verify: fix use-after-free after invalid ref action 2024-12-14 19:44:42 +01:00
ref-verify.h
relocation.c btrfs: convert BUG_ON in btrfs_reloc_cow_block() to proper error handling 2025-03-13 12:43:02 +01:00
root-tree.c
scrub.c
send.c btrfs: send: return -ENAMETOOLONG when attempting a path that is too long 2025-06-04 14:32:30 +02:00
send.h
space-info.c
space-info.h
struct-funcs.c
super.c btrfs: correctly escape subvol in btrfs_show_options() 2025-05-02 07:39:20 +02:00
sysfs.c
sysfs.h
transaction.c btrfs: use smp_mb__after_atomic() when forcing COW in create_pending_snapshot() 2025-12-03 12:45:04 +01:00
transaction.h
tree-checker.c btrfs: tree-checker: reject inline extent items with 0 ref count 2025-01-09 13:23:29 +01:00
tree-checker.h
tree-defrag.c
tree-log.c btrfs: populate otime when logging an inode item 2025-08-28 16:21:35 +02:00
tree-log.h
ulist.c
ulist.h
uuid-tree.c
volumes.c btrfs: add missing mutex_unlock in btrfs_relocate_sys_chunks() 2024-05-25 16:17:18 +02:00
volumes.h btrfs: add a helper to read the superblock metadata_uuid 2023-09-23 11:00:05 +02:00
xattr.c
xattr.h
zlib.c
zstd.c