]> git.baikalelectronics.ru Git - kernel.git/commit
mtd: sm_ftl: Fix deadlock caused by cancel_work_sync in sm_release
authorDuoming Zhou <duoming@zju.edu.cn>
Tue, 24 May 2022 04:48:41 +0000 (12:48 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Aug 2022 09:17:51 +0000 (11:17 +0200)
commitf1e683c5a6e8d8e2980bf0f56fb8751afbf47c72
tree81f84e9341c3d37c638a0310564e1c1bdeb8b62e
parentfd801c1d6f841acc03cb3d5d7bfb857d2f5c4ff7
mtd: sm_ftl: Fix deadlock caused by cancel_work_sync in sm_release

[ Upstream commit 8a688a8fa95c9c06a1ec0d4dcbdf7e331d8cedab ]

There is a deadlock between sm_release and sm_cache_flush_work
which is a work item. The cancel_work_sync in sm_release will
not return until sm_cache_flush_work is finished. If we hold
mutex_lock and use cancel_work_sync to wait the work item to
finish, the work item also requires mutex_lock. As a result,
the sm_release will be blocked forever. The race condition is
shown below:

    (Thread 1)             |   (Thread 2)
sm_release                 |
  mutex_lock(&ftl->mutex)  | sm_cache_flush_work
                           |   mutex_lock(&ftl->mutex)
  cancel_work_sync         |   ...

This patch moves del_timer_sync and cancel_work_sync out of
mutex_lock in order to mitigate deadlock.

Fixes: 046e09730c73 ("mtd: Add new SmartMedia/xD FTL")
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20220524044841.10517-1-duoming@zju.edu.cn
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/mtd/sm_ftl.c