Skip to content

Commit a705b11

Browse files
YuKuai-huaweiliu-song-6
authored andcommitted
md/raid5-cache: fix a deadlock in r5l_exit_log()
Commit b13015a ("md/raid5-cache: Clear conf->log after finishing work") introduce a new problem: // caller hold reconfig_mutex r5l_exit_log flush_work(&log->disable_writeback_work) r5c_disable_writeback_async wait_event /* * conf->log is not NULL, and mddev_trylock() * will fail, wait_event() can never pass. */ conf->log = NULL Fix this problem by setting 'config->log' to NULL before wake_up() as it used to be, so that wait_event() from r5c_disable_writeback_async() can exist. In the meantime, move forward md_unregister_thread() so that null-ptr-deref this commit fixed can still be fixed. Fixes: b13015a ("md/raid5-cache: Clear conf->log after finishing work") Signed-off-by: Yu Kuai <yukuai3@huawei.com> Link: https://lore.kernel.org/r/20230708091727.1417894-1-yukuai1@huaweicloud.com Signed-off-by: Song Liu <song@kernel.org>
1 parent 66a6a5d commit a705b11

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

drivers/md/raid5-cache.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3168,12 +3168,15 @@ void r5l_exit_log(struct r5conf *conf)
31683168
{
31693169
struct r5l_log *log = conf->log;
31703170

3171-
/* Ensure disable_writeback_work wakes up and exits */
3172-
wake_up(&conf->mddev->sb_wait);
3173-
flush_work(&log->disable_writeback_work);
31743171
md_unregister_thread(&log->reclaim_thread);
31753172

3173+
/*
3174+
* 'reconfig_mutex' is held by caller, set 'confg->log' to NULL to
3175+
* ensure disable_writeback_work wakes up and exits.
3176+
*/
31763177
conf->log = NULL;
3178+
wake_up(&conf->mddev->sb_wait);
3179+
flush_work(&log->disable_writeback_work);
31773180

31783181
mempool_exit(&log->meta_pool);
31793182
bioset_exit(&log->bs);

0 commit comments

Comments
 (0)