]> www.infradead.org Git - users/willy/xarray.git/commit
bcachefs: Fix race between trans_put() and btree_transactions_read()
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 23 Jun 2024 02:02:09 +0000 (22:02 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 23 Jun 2024 04:57:21 +0000 (00:57 -0400)
commitde611ab6fc5ed0d68dd46319b9913353e3b459e9
treee2578031174805e2c275dda00eb154242ab2e2fe
parent06efa5f30c28eaf237247ca8c4cb46eb62cb6bd9
bcachefs: Fix race between trans_put() and btree_transactions_read()

debug.c was using closure_get() on a different thread's closure where
the we don't know if the object being refcounted is alive.

We keep btree_trans objects on a list so they can be printed by debug
code, and because it is cost prohibitive to touch the btree_trans list
every time we allocate and free btree_trans objects, cached objects are
also on this list.

However, we do not want the debug code to see cached but not in use
btree_trans objects - critically because the btree_paths array will have
been freed (if it was reallocated).

closure_get() is also incorrect to use when that get may race with it
hitting zero, i.e. we must already have a ref on the object or know the
ref can't currently hit 0 for other reasons (as used in the cycle
detector).

to fix this, use the previously introduced closure_get_not_zero(),
closure_return_sync(), and closure_init_stack_release(); the debug code
now can only take a ref on a trans object if it's alive and in use.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_iter.c
fs/bcachefs/debug.c