[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210717100719.728829-1-desmondcheongzx@gmail.com>
Date: Sat, 17 Jul 2021 18:07:19 +0800
From: Desmond Cheong Zhi Xi <desmondcheongzx@...il.com>
To: miquel.raynal@...tlin.com, richard@....at, vigneshr@...com
Cc: Desmond Cheong Zhi Xi <desmondcheongzx@...il.com>,
linux-mtd@...ts.infradead.org, linux-kernel@...r.kernel.org,
skhan@...uxfoundation.org, gregkh@...uxfoundation.org,
linux-kernel-mentees@...ts.linuxfoundation.org,
Hillf Danton <hdanton@...a.com>
Subject: [PATCH] mtd: fix lock hierarchy in deregister_mtd_blktrans
There is a lock hierarchy of major_names_lock --> mtd_table_mutex. One
existing chain is as follows:
1. major_names_lock --> loop_ctl_mutex (when blk_request_module calls
loop_probe)
2. loop_ctl_mutex --> bdev->bd_mutex (when loop_control_ioctl calls
loop_remove, which then calls del_gendisk)
3. bdev->bd_mutex --> mtd_table_mutex (when blkdev_get_by_dev calls
__blkdev_get, which then calls blktrans_open)
Since unregister_blkdev grabs the major_names_lock, we need to call it
outside the critical section for mtd_table_mutex, otherwise we invert
the lock hierarchy.
Reported-by: Hillf Danton <hdanton@...a.com>
Signed-off-by: Desmond Cheong Zhi Xi <desmondcheongzx@...il.com>
---
drivers/mtd/mtd_blkdevs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 7d26cfe24d05..87e26788ef60 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -563,8 +563,8 @@ int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
list_for_each_entry_safe(dev, next, &tr->devs, list)
tr->remove_dev(dev);
- unregister_blkdev(tr->major, tr->name);
mutex_unlock(&mtd_table_mutex);
+ unregister_blkdev(tr->major, tr->name);
BUG_ON(!list_empty(&tr->devs));
return 0;
--
2.25.1
Powered by blists - more mailing lists