]> git.baikalelectronics.ru Git - kernel.git/commit
bcache: fixup multiple threads crash
authorMingzhe Zou <mingzhe.zou@easystack.cn>
Fri, 11 Feb 2022 06:39:15 +0000 (14:39 +0800)
committerColy Li <colyli@suse.de>
Sun, 6 Mar 2022 14:33:45 +0000 (22:33 +0800)
commitf589bc7b6698117e346380762b7ef1fdae449104
tree0570e2ced54a9570d4d179770b14ce9a206646cf
parentb68a767091b93e4769f27ac316d899da380d5eb3
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: e9a65c2979cc3 ("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>
drivers/md/bcache/btree.c
drivers/md/bcache/writeback.c