Skip to content

Commit 887554a

Browse files
zoumingzheColy Li
authored andcommitted
bcache: fixup multiple threads crash
When multiple threads to check btree nodes in parallel, the main thread wait for all threads to stop or CACHE_SET_IO_DISABLE flag: wait_event_interruptible(check_state->wait, atomic_read(&check_state->started) == 0 || test_bit(CACHE_SET_IO_DISABLE, &c->flags)); However, the bch_btree_node_read and bch_btree_node_read_done maybe call bch_cache_set_error, then the CACHE_SET_IO_DISABLE will be set. If the flag already set, the main thread return error. At the same time, maybe some threads still running and read NULL pointer, the kernel will crash. This patch change the event wait condition, the main thread must wait for all threads to stop. Fixes: 8e71022 ("bcache: make bch_btree_check() to be multithreaded") Signed-off-by: Mingzhe Zou <mingzhe.zou@easystack.cn> Cc: stable@vger.kernel.org # v5.7+ Signed-off-by: Coly Li <colyli@suse.de>
1 parent 7b1002f commit 887554a

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

drivers/md/bcache/btree.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,9 +2060,11 @@ int bch_btree_check(struct cache_set *c)
20602060
}
20612061
}
20622062

2063+
/*
2064+
* Must wait for all threads to stop.
2065+
*/
20632066
wait_event_interruptible(check_state->wait,
2064-
atomic_read(&check_state->started) == 0 ||
2065-
test_bit(CACHE_SET_IO_DISABLE, &c->flags));
2067+
atomic_read(&check_state->started) == 0);
20662068

20672069
for (i = 0; i < check_state->total_threads; i++) {
20682070
if (check_state->infos[i].result) {

drivers/md/bcache/writeback.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,9 +1001,11 @@ void bch_sectors_dirty_init(struct bcache_device *d)
10011001
}
10021002
}
10031003

1004+
/*
1005+
* Must wait for all threads to stop.
1006+
*/
10041007
wait_event_interruptible(state->wait,
1005-
atomic_read(&state->started) == 0 ||
1006-
test_bit(CACHE_SET_IO_DISABLE, &c->flags));
1008+
atomic_read(&state->started) == 0);
10071009

10081010
out:
10091011
kfree(state);

0 commit comments

Comments
 (0)