From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB036C4338F for ; Fri, 6 Aug 2021 19:46:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A59BF611CC for ; Fri, 6 Aug 2021 19:46:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244000AbhHFTqR (ORCPT ); Fri, 6 Aug 2021 15:46:17 -0400 Received: from relay8-d.mail.gandi.net ([217.70.183.201]:36137 "EHLO relay8-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231362AbhHFTqQ (ORCPT ); Fri, 6 Aug 2021 15:46:16 -0400 Received: (Authenticated sender: miquel.raynal@bootlin.com) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 52BBA1BF203; Fri, 6 Aug 2021 19:45:58 +0000 (UTC) From: Miquel Raynal To: Desmond Cheong Zhi Xi , miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, gregkh@linuxfoundation.org, linux-kernel-mentees@lists.linuxfoundation.org, Hillf Danton Subject: Re: [PATCH] mtd: fix lock hierarchy in deregister_mtd_blktrans Date: Fri, 6 Aug 2021 21:45:56 +0200 Message-Id: <20210806194556.392389-1-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210717100719.728829-1-desmondcheongzx@gmail.com> References: MIME-Version: 1.0 X-linux-mtd-patch-notification: thanks X-linux-mtd-patch-commit: b'b7abb051682263e51866bc78762fd0083d64c5ed' Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 2021-07-17 at 10:07:19 UTC, Desmond Cheong Zhi Xi wrote: > 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 > Signed-off-by: Desmond Cheong Zhi Xi Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/fixes, thanks. Miquel