android_kernel_sony_sdm845/drivers/md/bcache
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Zhiqiang Liu be676835b2 bcache: fix potential deadlock problem in btree_gc_coalesce
[ Upstream commit be23e837333a914df3f24bf0b32e87b0331ab8d1 ]

coccicheck reports:
  drivers/md//bcache/btree.c:1538:1-7: preceding lock on line 1417

In btree_gc_coalesce func, if the coalescing process fails, we will goto
to out_nocoalesce tag directly without releasing new_nodes[i]->write_lock.
Then, it will cause a deadlock when trying to acquire new_nodes[i]->
write_lock for freeing new_nodes[i] before return.

btree_gc_coalesce func details as follows:
	if alloc new_nodes[i] fails:
		goto out_nocoalesce;
	// obtain new_nodes[i]->write_lock
	mutex_lock(&new_nodes[i]->write_lock)
	// main coalescing process
	for (i = nodes - 1; i > 0; --i)
		[snipped]
		if coalescing process fails:
			// Here, directly goto out_nocoalesce
			 // tag will cause a deadlock
			goto out_nocoalesce;
		[snipped]
	// release new_nodes[i]->write_lock
	mutex_unlock(&new_nodes[i]->write_lock)
	// coalesing succ, return
	return;
out_nocoalesce:
	btree_node_free(new_nodes[i])	// free new_nodes[i]
	// obtain new_nodes[i]->write_lock
	mutex_lock(&new_nodes[i]->write_lock);
	// set flag for reuse
	clear_bit(BTREE_NODE_dirty, &ew_nodes[i]->flags);
	// release new_nodes[i]->write_lock
	mutex_unlock(&new_nodes[i]->write_lock);

To fix the problem, we add a new tag 'out_unlock_nocoalesce' for
releasing new_nodes[i]->write_lock before out_nocoalesce tag. If
coalescing process fails, we will go to out_unlock_nocoalesce tag
for releasing new_nodes[i]->write_lock before free new_nodes[i] in
out_nocoalesce tag.

(Coly Li helps to clean up commit log format.)

Fixes: 2a285686c1 ("bcache: btree locking rework")
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-06-30 15:38:30 -04:00
..
alloc.c bcache: avoid clang -Wunintialized warning 2019-05-31 06:48:16 -07:00
bcache.h bcache: fix for data collapse after re-attaching an attached device 2018-05-30 07:50:25 +02:00
bset.c bcache: fix stack corruption by PRECEDING_KEY() 2019-06-22 08:17:19 +02:00
bset.h bcache: explicity type cast in bset_bkey_last() 2020-02-28 15:42:41 +01:00
btree.c bcache: fix potential deadlock problem in btree_gc_coalesce 2020-06-30 15:38:30 -04:00
btree.h bcache: Make gc wakeup sane, remove set_task_state() 2017-02-23 17:44:36 +01:00
closure.c bcache: update document info 2016-07-05 11:34:49 -06:00
closure.h bcache: update document info 2016-07-05 11:34:49 -06:00
debug.c block: export bio_free_pages to other modules 2016-09-22 07:48:03 -06:00
debug.h
extents.c bcache: Fix building error on MIPS 2017-12-05 11:24:34 +01:00
extents.h
io.c block: simplify and cleanup bvec pool handling 2016-07-20 17:37:02 -06:00
journal.c bcache: fix failure in journal relplay 2019-05-31 06:48:16 -07:00
journal.h
Kconfig
Makefile
movinggc.c block: export bio_free_pages to other modules 2016-09-22 07:48:03 -06:00
request.c bcache: fix kcrashes with fio in RAID5 backend dev 2018-05-30 07:50:32 +02:00
request.h
stats.c
stats.h
super.c bcache: silence static checker warning 2020-01-29 10:24:40 +01:00
sysfs.c bcache: fix input overflow to sequential_cutoff 2019-04-05 22:29:12 +02:00
sysfs.h bcache: improve sysfs_strtoul_clamp() 2019-04-05 22:29:12 +02:00
trace.c
util.c bcache: fix bch_hprint crash and improve output 2017-09-27 14:39:25 +02:00
util.h
writeback.c bcache: release dc->writeback_lock properly in bch_writeback_thread() 2018-09-09 20:01:25 +02:00
writeback.h bcache: never writeback a discard operation 2019-03-23 13:19:53 +01:00