linux-stable/fs/bcachefs
Brian Foster 385a82f62a bcachefs: serialize on cached key in early bucket allocator
bcachefs had a transient bug where freespace_initialized was not
properly being set, which lead to unexpected use of the early bucket
allocator at runtime. This issue has been fixed, but the existence
of it uncovered a coherency issue in the early bucket allocation
code that is somewhat related to how uncached iterators deal with
the key cache.

The problem itself manifests as occasional failure of generic/113
due to corruption, often seen as a duplicate backpointer or multiple
data types per-bucket error. The immediate cause of the error is a
racing bucket allocation along the lines of the following sequence:

- Task 1 selects key A in bch2_bucket_alloc_early() and schedules.
- Task 2 selects the same key A, but proceeds to complete the
  allocation and associated I/O, after which it releases the
  open_bucket.
- Task 1 resumes with key A, but does not recognize the bucket is
  now allocated because the open_bucket has been removed
  from the hash when it was released in the previous step.

This generally shouldn't happen because the allocating task updates
the alloc btree key before releasing the bucket. This is not
sufficient in this particular instance, however, because an uncached
iterator for a cached btree doesn't actually lock the key cache slot
when no key exists for a given slot in the cache. Thus the fact that
the allocation side updates the cached key means that multiple
uncached iters can stumble across the same alloc key and duplicate
the bucket allocation as described above.

This is something that probably needs a longer term fix in the
iterator code. As a short term fix, close the race through explicit
use of a cached iterator for likely allocation candidates. We don't
want to scan the btree with a cached iterator because that would
unnecessarily pollute the cache. This mitigates cache pollution by
primarily scanning the tree with an uncached iterator, but closes
the race by creating a key cache entry for any prospective slot
prior to the bucket allocation attempt (also similar to how
_alloc_freelist() works via try_alloc_bucket()). This survives many
iterations of generic/113 on a kernel hacked to always use the early
bucket allocator.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-11-04 22:19:13 -04:00
..
acl.c bcachefs: acl: Add missing check in bch2_acl_chmod() 2023-10-22 17:10:14 -04:00
acl.h bcachefs: bch2_acl_to_text() 2023-10-22 17:10:12 -04:00
alloc_background.c bcachefs: Ensure copygc does not spin 2023-11-04 14:17:11 -04:00
alloc_background.h bcachefs: Ensure copygc does not spin 2023-11-04 14:17:11 -04:00
alloc_foreground.c bcachefs: serialize on cached key in early bucket allocator 2023-11-04 22:19:13 -04:00
alloc_foreground.h bcachefs: sb-members.c 2023-10-22 17:10:10 -04:00
alloc_types.h bcachefs: Fix assorted checkpatch nits 2023-10-22 17:10:10 -04:00
backpointers.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
backpointers.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
bbpos_types.h bcachefs: move: convert to bbpos 2023-10-31 12:18:37 -04:00
bbpos.h bcachefs: move: convert to bbpos 2023-10-31 12:18:37 -04:00
bcachefs_format.h bcachefs: Fix build errors with gcc 10 2023-11-04 14:17:11 -04:00
bcachefs_ioctl.h bcachefs: Convert to __packed and __aligned 2023-10-22 17:09:45 -04:00
bcachefs.h bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
bkey_buf.h bcachefs: Move bkey bkey_unpack_key() to bkey.h 2023-10-22 17:09:45 -04:00
bkey_cmp.h bcachefs: bch2_bkey_cmp_packed_inlined() 2023-10-22 17:09:45 -04:00
bkey_methods.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
bkey_methods.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
bkey_sort.c bcachefs: Use memcpy_u64s_small() for copying keys 2023-10-22 17:10:01 -04:00
bkey_sort.h bcachefs: Array bounds fixes 2023-10-22 17:10:12 -04:00
bkey.c bcachefs: Fix W=12 build errors 2023-10-22 17:10:13 -04:00
bkey.h bcachefs: Array bounds fixes 2023-10-22 17:10:12 -04:00
bset.c bcachefs: Kill other unreachable() uses 2023-10-22 17:10:13 -04:00
bset.h bcachefs: bch2_btree_node_to_text() const correctness 2023-10-22 17:09:56 -04:00
btree_cache.c bcachefs: Fix shrinker names 2023-10-31 12:18:37 -04:00
btree_cache.h bcachefs: bch2_btree_id_str() 2023-10-31 12:18:37 -04:00
btree_gc.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
btree_gc.h bcachefs: Split up btree_update_leaf.c 2023-10-22 17:10:10 -04:00
btree_io.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
btree_io.h bcachefs: Break up io.c 2023-10-22 17:10:12 -04:00
btree_iter.c bcachefs: Data move path now uses bch2_trans_unlock_long() 2023-11-04 22:19:11 -04:00
btree_iter.h bcachefs: Ensure srcu lock is not held too long 2023-11-04 14:17:11 -04:00
btree_journal_iter.c bcachefs: btree_journal_iter.c 2023-10-22 17:10:10 -04:00
btree_journal_iter.h bcachefs: btree_journal_iter.c 2023-10-22 17:10:10 -04:00
btree_key_cache.c bcachefs: Don't downgrade locks on transaction restart 2023-11-01 21:11:08 -04:00
btree_key_cache.h bcachefs: don't bump key cache journal seq on nojournal commits 2023-10-22 17:09:56 -04:00
btree_locking.c bcachefs: Ensure srcu lock is not held too long 2023-11-04 14:17:11 -04:00
btree_locking.h bcachefs: Don't downgrade locks on transaction restart 2023-11-01 21:11:08 -04:00
btree_trans_commit.c bcachefs: Fix build errors with gcc 10 2023-11-04 14:17:11 -04:00
btree_types.h bcachefs: Ensure srcu lock is not held too long 2023-11-04 14:17:11 -04:00
btree_update_interior.c bcachefs: Fix build errors with gcc 10 2023-11-04 14:17:11 -04:00
btree_update_interior.h bcachefs: Fix build errors with gcc 10 2023-11-04 14:17:11 -04:00
btree_update.c bcachefs: More minor smatch fixes 2023-10-22 17:10:14 -04:00
btree_update.h bcachefs: Remove duplicate include 2023-10-22 17:10:14 -04:00
btree_write_buffer_types.h bcachefs: Btree write buffer 2023-10-22 17:09:50 -04:00
btree_write_buffer.c bcachefs: Heap allocate btree_trans 2023-10-22 17:10:13 -04:00
btree_write_buffer.h bcachefs: Btree write buffer 2023-10-22 17:09:50 -04:00
buckets_types.h bcachefs: Fragmentation LRU 2023-10-22 17:09:53 -04:00
buckets_waiting_for_journal_types.h bcachefs: New data structure for buckets waiting on journal commit 2023-10-22 17:09:22 -04:00
buckets_waiting_for_journal.c bcachefs: Fix -Wformat in bch2_set_bucket_needs_journal_commit() 2023-10-22 17:10:13 -04:00
buckets_waiting_for_journal.h bcachefs: New data structure for buckets waiting on journal commit 2023-10-22 17:09:22 -04:00
buckets.c bcachefs: Fix an integer overflow 2023-11-01 21:11:08 -04:00
buckets.h bcachefs: All triggers are BTREE_TRIGGER_WANTS_OLD_AND_NEW 2023-10-31 12:18:37 -04:00
chardev.c bcachefs: move: convert to bbpos 2023-10-31 12:18:37 -04:00
chardev.h bcachefs: Fix assorted checkpatch nits 2023-10-22 17:10:10 -04:00
checksum.c bcachefs: bch2_sb_field_get() refactoring 2023-10-22 17:10:16 -04:00
checksum.h bcachefs: Fixes for building in userspace 2023-10-22 17:10:15 -04:00
clock_types.h bcachefs: Persist 64 bit io clocks 2023-10-22 17:08:52 -04:00
clock.c bcachefs: Private error codes: ENOMEM 2023-10-22 17:09:57 -04:00
clock.h bcachefs: Convert various code to printbuf 2023-10-22 17:08:43 -04:00
compress.c bcachefs: rebalance_work 2023-11-01 21:11:05 -04:00
compress.h bcachefs: rebalance_work 2023-11-01 21:11:05 -04:00
counters.c bcachefs: bch2_sb_field_get() refactoring 2023-10-22 17:10:16 -04:00
counters.h bcachefs: Add persistent counters 2023-10-22 17:09:32 -04:00
darray.h bcachefs: Assorted fixes for clang 2023-10-22 17:10:09 -04:00
data_update.c bcachefs: Don't downgrade locks on transaction restart 2023-11-01 21:11:08 -04:00
data_update.h bcachefs: move: convert to bbpos 2023-10-31 12:18:37 -04:00
debug.c bcachefs: bch2_btree_id_str() 2023-10-31 12:18:37 -04:00
debug.h bcachefs: bch2_btree_node_ondisk_to_text() 2023-10-22 17:09:56 -04:00
dirent.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
dirent.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
disk_groups_types.h bcachefs: bch2_disk_path_to_text() no longer takes sb_lock 2023-10-31 12:18:37 -04:00
disk_groups.c bcachefs: bch2_disk_path_to_text() no longer takes sb_lock 2023-10-31 12:18:37 -04:00
disk_groups.h bcachefs: bch2_disk_path_to_text() no longer takes sb_lock 2023-10-31 12:18:37 -04:00
ec_types.h bcachefs: Simplify ec stripes heap 2023-10-22 17:09:54 -04:00
ec.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
ec.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
errcode.c bcachefs: Fix W=12 build errors 2023-10-22 17:10:13 -04:00
errcode.h bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
error.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
error.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
extent_update.c bcachefs: Use for_each_btree_key_upto() more consistently 2023-10-22 17:09:50 -04:00
extent_update.h bcachefs: Reduce iter->trans usage 2023-10-22 17:09:10 -04:00
extents_types.h bcachefs: Limit pointers to being in only one stripe 2023-10-22 17:08:29 -04:00
extents.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
extents.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
eytzinger.h bcachefs: Make eytzinger size parameter more conventional 2023-10-22 17:09:21 -04:00
fifo.h bcachefs: More style fixes 2023-10-22 17:09:45 -04:00
fs-common.c bcachefs: Convert -ENOENT to private error codes 2023-10-22 17:10:03 -04:00
fs-common.h bcachefs: Add BCH_SUBVOLUME_UNLINKED 2023-10-22 17:09:15 -04:00
fs-io-buffered.c bcachefs: Heap allocate btree_trans 2023-10-22 17:10:13 -04:00
fs-io-buffered.h bcachefs: Split up fs-io.[ch] 2023-10-22 17:10:10 -04:00
fs-io-direct.c closures: Fix race in closure_sync() 2023-10-30 21:48:22 -04:00
fs-io-direct.h bcachefs: Split up fs-io.[ch] 2023-10-22 17:10:10 -04:00
fs-io-pagecache.c bcachefs: Heap allocate btree_trans 2023-10-22 17:10:13 -04:00
fs-io-pagecache.h bcachefs: Split up fs-io.[ch] 2023-10-22 17:10:10 -04:00
fs-io.c bcachefs: Heap allocate btree_trans 2023-10-22 17:10:13 -04:00
fs-io.h bcachefs: New io_misc.c helpers 2023-10-22 17:10:12 -04:00
fs-ioctl.c bcachefs: snapshot_create_lock 2023-10-22 17:10:16 -04:00
fs-ioctl.h bcachefs: Fix W=12 build errors 2023-10-22 17:10:13 -04:00
fs.c Initial bcachefs pull request for 6.7-rc1 2023-10-30 11:09:38 -10:00
fs.h bcachefs: Fixes for building in userspace 2023-10-22 17:10:15 -04:00
fsck.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
fsck.h bcachefs: Check for too-large encoded extents 2023-10-31 12:18:37 -04:00
inode.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
inode.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
io_misc.c bcachefs: Fix an integer overflow 2023-11-01 21:11:08 -04:00
io_misc.h bcachefs: Fix an integer overflow 2023-11-01 21:11:08 -04:00
io_read.c bcachefs: Add IO error counts to bch_member 2023-11-01 21:11:08 -04:00
io_read.h bcachefs: Break up io.c 2023-10-22 17:10:12 -04:00
io_write_types.h bcachefs: Break up io.c 2023-10-22 17:10:12 -04:00
io_write.c bcachefs: Add IO error counts to bch_member 2023-11-01 21:11:08 -04:00
io_write.h bcachefs: Break up io.c 2023-10-22 17:10:12 -04:00
journal_io.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
journal_io.h bcachefs: Convert journal validation to bkey_invalid_flags 2023-10-22 17:10:10 -04:00
journal_reclaim.c bcachefs: refactor pin put helpers 2023-10-22 17:10:14 -04:00
journal_reclaim.h bcachefs: refactor pin put helpers 2023-10-22 17:10:14 -04:00
journal_sb.c bcachefs: bch2_sb_field_get() refactoring 2023-10-22 17:10:16 -04:00
journal_sb.h bcachefs: Journal resize fixes 2023-10-22 17:09:56 -04:00
journal_seq_blacklist.c bcachefs: bch2_sb_field_get() refactoring 2023-10-22 17:10:16 -04:00
journal_seq_blacklist.h Revert "bcachefs: Delete some obsolete journal_seq_blacklist code" 2023-10-22 17:09:21 -04:00
journal_types.h bcachefs: Kill JOURNAL_WATERMARK 2023-10-22 17:10:05 -04:00
journal.c bcachefs: Ensure devices are always correctly initialized 2023-10-31 12:18:37 -04:00
journal.h bcachefs: Ensure devices are always correctly initialized 2023-10-31 12:18:37 -04:00
Kconfig bcachefs: Fix MEAN_AND_VARIANCE kconfig options 2023-11-04 14:17:11 -04:00
keylist_types.h
keylist.c bcachefs: GFP_NOIO -> GFP_NOFS 2023-10-22 17:10:03 -04:00
keylist.h bcachefs: Kill bch2_keylist_add_in_order() 2023-10-22 17:09:54 -04:00
logged_ops.c bcachefs: Heap allocate btree_trans 2023-10-22 17:10:13 -04:00
logged_ops.h bcachefs: Log finsert/fcollapse operations 2023-10-22 17:10:12 -04:00
lru.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
lru.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
Makefile bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
mean_and_variance_test.c mean and variance: More tests 2023-10-22 17:10:02 -04:00
mean_and_variance.c bcachefs: Mean and variance 2023-10-22 17:09:43 -04:00
mean_and_variance.h mean and variance: Add a missing include 2023-10-22 17:10:02 -04:00
migrate.c bcachefs: Heap allocate btree_trans 2023-10-22 17:10:13 -04:00
migrate.h
move_types.h bcachefs: move: move_stats refactoring 2023-10-31 12:18:38 -04:00
move.c bcachefs: Data move path now uses bch2_trans_unlock_long() 2023-11-04 22:19:11 -04:00
move.h bcachefs: Data move path now uses bch2_trans_unlock_long() 2023-11-04 22:19:11 -04:00
movinggc.c bcachefs: Data move path now uses bch2_trans_unlock_long() 2023-11-04 22:19:11 -04:00
movinggc.h bcachefs: bch2_copygc_wait_to_text() 2023-10-22 17:09:55 -04:00
nocow_locking_types.h bcachefs: Improved nocow locking 2023-10-22 17:09:52 -04:00
nocow_locking.c bcachefs: More assertions for nocow locking 2023-10-22 17:10:15 -04:00
nocow_locking.h bcachefs: More assertions for nocow locking 2023-10-22 17:10:15 -04:00
opts.c bcachefs: Add IO error counts to bch_member 2023-11-01 21:11:08 -04:00
opts.h bcachefs: Add IO error counts to bch_member 2023-11-01 21:11:08 -04:00
printbuf.c bcachefs: Fix bch2_prt_bitflags() 2023-10-31 12:18:37 -04:00
printbuf.h bcachefs: Improve dev_alloc_debug_to_text() 2023-10-22 17:09:55 -04:00
quota_types.h bcachefs: bch2_fs_quota_transfer 2023-10-22 17:08:13 -04:00
quota.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
quota.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
rebalance_types.h bcachefs: rebalance_work 2023-11-01 21:11:05 -04:00
rebalance.c bcachefs: Data move path now uses bch2_trans_unlock_long() 2023-11-04 22:19:11 -04:00
rebalance.h bcachefs: rebalance_work 2023-11-01 21:11:05 -04:00
recovery_types.h bcachefs: rebalance_work 2023-11-01 21:11:05 -04:00
recovery.c bcachefs: Fix build errors with gcc 10 2023-11-04 14:17:11 -04:00
recovery.h bcachefs: btree_journal_iter.c 2023-10-22 17:10:10 -04:00
reflink.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
reflink.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
replicas_types.h bcachefs: Fix bch2_trans_reset_updates() 2023-10-22 17:09:50 -04:00
replicas.c bcachefs: Fix error path in bch2_replicas_gc_end() 2023-11-01 21:11:08 -04:00
replicas.h bcachefs: Fix bch2_trans_reset_updates() 2023-10-22 17:09:50 -04:00
sb-clean.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
sb-clean.h bcachefs: sb-clean.c 2023-10-22 17:10:10 -04:00
sb-errors_types.h bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
sb-errors.c bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
sb-errors.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
sb-members.c bcachefs: Skip deleted members in member_to_text() 2023-11-01 21:11:08 -04:00
sb-members.h bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
seqmutex.h bcachefs: seqmutex; fix a lockdep splat 2023-10-22 17:10:04 -04:00
siphash.c bcachefs: Assorted checkpatch fixes 2023-10-22 17:09:44 -04:00
siphash.h
six.c six locks: Lock contended tracepoints 2023-10-30 22:26:45 -04:00
six.h six locks: Split out seq, use atomic_t instead of atomic64_t 2023-10-22 17:10:02 -04:00
snapshot.c bcachefs: Fix deleted inodes btree in snapshot deletion 2023-11-01 21:11:08 -04:00
snapshot.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
str_hash.h bcachefs: Convert -ENOENT to private error codes 2023-10-22 17:10:03 -04:00
subvolume_types.h bcachefs: is_ancestor bitmap 2023-10-22 17:10:07 -04:00
subvolume.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
subvolume.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
super_types.h bcachefs: Split out disk_groups_types.h 2023-10-31 12:18:37 -04:00
super-io.c bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
super-io.h bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
super.c bcachefs: bch_sb_field_errors 2023-11-01 21:11:08 -04:00
super.h bcachefs: sb-members.c 2023-10-22 17:10:10 -04:00
sysfs.c bcachefs: Add IO error counts to bch_member 2023-11-01 21:11:08 -04:00
sysfs.h bcachefs: Add persistent counters 2023-10-22 17:09:32 -04:00
tests.c bcachefs: bch_err_msg(), bch_err_fn() now filters out transaction restart errors 2023-10-22 17:10:15 -04:00
tests.h bcachefs: Add error handling to unit & perf tests 2023-10-22 17:08:48 -04:00
trace.c bcachefs: move: move_stats refactoring 2023-10-31 12:18:38 -04:00
trace.h bcachefs: Don't downgrade locks on transaction restart 2023-11-01 21:11:08 -04:00
two_state_shared_lock.c bcachefs: Inline bch2_two_state_(trylock|unlock) 2023-10-22 17:09:51 -04:00
two_state_shared_lock.h bcachefs: Inline bch2_two_state_(trylock|unlock) 2023-10-22 17:09:51 -04:00
util.c bcachefs: Fix W=12 build errors 2023-10-22 17:10:13 -04:00
util.h bcachefs: Fix W=12 build errors 2023-10-22 17:10:13 -04:00
varint.c bcachefs: Fix W=12 build errors 2023-10-22 17:10:13 -04:00
varint.h bcachefs: Add safe versions of varint encode/decode 2023-10-22 17:09:08 -04:00
vstructs.h bcachefs: Array bounds fixes 2023-10-22 17:10:12 -04:00
xattr.c bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00
xattr.h bcachefs: Enumerate fsck errors 2023-11-01 21:11:08 -04:00