lkml.org 
[lkml]   [2022]   [Aug]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 5.4 158/389] mtd: sm_ftl: Fix deadlock caused by cancel_work_sync in sm_release
    Date
    From: Duoming Zhou <duoming@zju.edu.cn>

    [ Upstream commit a61528d997619a518ee8c51cf0ef0513021afaff ]

    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: 7d17c02a01a1 ("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 | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)

    diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
    index 4744bf94ad9a..d4e72fd5e5b3 100644
    --- a/drivers/mtd/sm_ftl.c
    +++ b/drivers/mtd/sm_ftl.c
    @@ -1097,9 +1097,9 @@ static void sm_release(struct mtd_blktrans_dev *dev)
    {
    struct sm_ftl *ftl = dev->priv;

    - mutex_lock(&ftl->mutex);
    del_timer_sync(&ftl->timer);
    cancel_work_sync(&ftl->flush_work);
    + mutex_lock(&ftl->mutex);
    sm_cache_flush(ftl);
    mutex_unlock(&ftl->mutex);
    }
    --
    2.35.1


    \
     
     \ /
      Last update: 2022-08-23 13:29    [W:3.888 / U:0.220 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site