Skip to content

Commit 7dbfa42

Browse files
fdmananakdave
authored andcommitted
btrfs: fix harmless race getting delayed ref head count when running delayed refs
When running delayed references we are reading the number of ready delayed ref heads without taking any lock which can make KCSAN report a race since we can have concurrent tasks updating that number, such as for example when freeing a tree block which will end up decrementing that counter or when adding a new delayed ref while COWing a tree block which will increment that counter. This is a harmless race since running one more or one less delayed ref head doesn't result in any problem, in the critical section of a transaction commit we always run any remaining delayed refs and at that point no one can create more. So fix this harmless race by annotating the read with data_race(). Reported-by: cen zhang <[email protected]> Link: https://lore.kernel.org/linux-btrfs/CAFRLqsUCLMz0hY-GaPj1Z=fhkgRHjxVXHZ8kz0PvkFN0b=8L2Q@mail.gmail.com/ Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 4469e95 commit 7dbfa42

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

fs/btrfs/extent-tree.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2006,7 +2006,12 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
20062006

20072007
delayed_refs = &trans->transaction->delayed_refs;
20082008
if (min_bytes == 0) {
2009-
max_count = delayed_refs->num_heads_ready;
2009+
/*
2010+
* We may be subject to a harmless race if some task is
2011+
* concurrently adding or removing a delayed ref, so silence
2012+
* KCSAN and similar tools.
2013+
*/
2014+
max_count = data_race(delayed_refs->num_heads_ready);
20102015
min_bytes = U64_MAX;
20112016
}
20122017

0 commit comments

Comments
 (0)