From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795704222; b=lxxetKNYl2VfvIlJG4eCpD3eIkCFAAsWQKFDw6H6/EMlT3dDRKnXnmqYaHagDMqidkw9 BaHI4uCrPTjnyY82cmK4SCOvh54C8wEng37l7QIMfMQ76JtELuyzxkLomQoQWob17D/GJ vJyRI20gAQynXoFtOunWoLSD1SXxSk0kB6JZBeQDXmp7F11iES1pu07VvzFGFO4kRlZTq nxvMEEwc8pnrWZvMQ7EIlFxQaoJMM05VhvQ6RsFF+9Q9UH3p9KMLdX/V4N+/BtBdh1Sin fwBkTCC1rrvZLl9pasIaYQJZ7Q6t370dN3Q++/rAp9saCj4cGUEEBolEYnG3F+ipjfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795704222; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=ZO5Jx0XPv6KQzSuL2B17YwNZkXWWTssurJHvFkCrKvY=; b=PNcs4nrnhPde6ASEJffr1t+vUzdLUT/u0NTYKZc6ehSPbDZZw1L5tU66mWztbRspc7h5 Ke1KWIvIn9jhkOhEGRdEv3xCSHSuRCTLLXPxcvKB9qcdG9K4eK4RFCxDY0h4nQvus3BnG Hs+6MSNTMvdgdnZ3OC2ArnuwXI0EdNS2G29AufWnzKQ3cU9MJAgOCRnBm78n/7pjQzL7e ZiJwCBxHzY0khaDZ4+ztlmUKUI4pHddB3pF7fKJxeerRUUZZ19CvHUIZ4QdqaT9bu7+9u JOzCuCK65sqCyDcbiKHwIbd2zUsGH9l2BenkcdXlo3a6b2vS1XKMJinSb2XJ12QUGXg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=lTGQHDf4; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E06E606A321; Thu, 26 Nov 2026 14:43:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=lTGQHDf4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6957B1F000C0; Thu, 26 Nov 2026 14:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795704221; bh=ZO5Jx0XPv6KQzSuL2B17YwNZkXWWTssurJHvFkCrKvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lTGQHDf4oQ/xTBtiBNE3TJFMlhMFtEx61eg5x+3z0/k9DARD9CcTJ+DmD3jc+ThPO BDdIk0RpLoXN69Xw6EbUb6xQ4iRabWExUFC4ROFgYTcKISO4YgQT7OSRz+cbv5bFKZ kLh//tGTmW3VP2vTZO/FX9f2uZBt7Rkic/rRaq8A= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Adrian Hunter , Frank Li , Alexandre Belloni , Claudiu Beznea , Sasha Levin Subject: [PATCH 5.10 007/265] i3c: master: Fix recursive locking during device registration Date: Thu, 26 Nov 2026 15:35:37 +0100 Message-ID: <20261126143605.589150377@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261126143605.076581697@linuxfoundation.org> References: <20261126143605.076581697@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Adrian Hunter commit 456f832e5fc26fbfd3b8200fd4553eee520cc377 upstream. i3c_master_register_new_i3c_devs() registers newly discovered devices while holding i3c_bus_normaluse_lock(), a down_read(). device_register() can immediately probe the device, and probe callbacks typically invoke I3C helpers that take i3c_bus_normaluse_lock() again, leading to a recursive acquisition of the same rwsem. rwsems do not support recursive read locking and can deadlock when a writer is waiting. See the "Recursive read locks" section of Documentation/locking/lockdep-design.rst. For example, with Intel LPSS I3C, LOCKDEP generates a WARNING like: # echo intel-lpss-i3c.0 > /sys/bus/platform/drivers/mipi-i3c-hci/unbind # echo intel-lpss-i3c.0 > /sys/bus/platform/drivers/mipi-i3c-hci/bind WARNING: possible recursive locking detected kworker/5:1/94 is trying to acquire lock: ffff88811c810d78 (&i3cbus->lock){++++}-{4:4}, at: i3c_device_match_id+0x45/0x370 but task is already holding lock: ffff88811c810d78 (&i3cbus->lock){++++}-{4:4}, at: i3c_master_reg_work_fn+0x21/0x5f0 Fix this by separating device creation from device registration. Populate desc->dev under the maintenance lock, collect the devices that still need registration into a local list, then release the lock before calling device_register(). Finally retake the lock and clean up any devices that failed to register. Use the maintenance lock rather than the normal-use lock while adding device objects. A write-side maintenance lock prevents readers from observing a partially initialized desc->dev during initial device population, or desc->dev disappearing if registration fails. The local list requires a list node, so add a list node member to struct i3c_device. Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure") Cc: stable@vger.kernel.org Signed-off-by: Adrian Hunter Reviewed-by: Frank Li Link: https://patch.msgid.link/20260807145638.168865-2-adrian.hunter@intel.com Signed-off-by: Alexandre Belloni [claudiu.beznea: - drop the i3c_bus_normaluse_{lock,unlock}() around i3c_master_register_new_i3c_devs() calls from i3c_master_do_daa() and i3c_master_register() - drop master->shutting_down specific code since this is not available in v5.10] Signed-off-by: Claudiu Beznea Signed-off-by: Sasha Levin --- drivers/i3c/master.c | 39 ++++++++++++++++++++++++++------------ include/linux/i3c/master.h | 3 +++ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 457e112dbc0f9..5595d980a2c8e 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -1520,12 +1520,16 @@ static int i3c_master_early_i3c_dev_add(struct i3c_master_controller *master, static void i3c_master_register_new_i3c_devs(struct i3c_master_controller *master) { + struct i3c_device *i3cdev, *tmp; struct i3c_dev_desc *desc; + LIST_HEAD(i3c_unreg_devs); int ret; if (!master->init_done) return; + i3c_bus_maintenance_lock(&master->bus); + i3c_bus_for_each_i3cdev(&master->bus, desc) { if (desc->dev || !desc->info.dyn_addr || desc == master->this) continue; @@ -1546,15 +1550,30 @@ i3c_master_register_new_i3c_devs(struct i3c_master_controller *master) if (desc->boardinfo) desc->dev->dev.of_node = desc->boardinfo->of_node; - ret = device_register(&desc->dev->dev); - if (ret) { - dev_err(&master->dev, - "Failed to add I3C device (err = %d)\n", ret); - desc->dev->desc = NULL; - put_device(&desc->dev->dev); - desc->dev = NULL; - } + list_add_tail(&desc->dev->node, &i3c_unreg_devs); + } + + i3c_bus_maintenance_unlock(&master->bus); + + list_for_each_entry_safe(i3cdev, tmp, &i3c_unreg_devs, node) { + ret = device_register(&i3cdev->dev); + if (ret) + dev_err(&master->dev, "Failed to add I3C device (err = %d)\n", ret); + else + list_del_init(&i3cdev->node); } + + i3c_bus_maintenance_lock(&master->bus); + + list_for_each_entry_safe(i3cdev, tmp, &i3c_unreg_devs, node) { + list_del(&i3cdev->node); + desc = i3cdev->desc; + i3cdev->desc = NULL; + put_device(&i3cdev->dev); + desc->dev = NULL; + } + + i3c_bus_maintenance_unlock(&master->bus); } /** @@ -1583,9 +1602,7 @@ int i3c_master_do_daa(struct i3c_master_controller *master) if (ret) return ret; - i3c_bus_normaluse_lock(&master->bus); i3c_master_register_new_i3c_devs(master); - i3c_bus_normaluse_unlock(&master->bus); return 0; } @@ -2627,9 +2644,7 @@ int i3c_master_register(struct i3c_master_controller *master, * register I3C devices discovered during the initial DAA. */ master->init_done = true; - i3c_bus_normaluse_lock(&master->bus); i3c_master_register_new_i3c_devs(master); - i3c_bus_normaluse_unlock(&master->bus); return 0; diff --git a/include/linux/i3c/master.h b/include/linux/i3c/master.h index b31170e37655f..1b646b2067db2 100644 --- a/include/linux/i3c/master.h +++ b/include/linux/i3c/master.h @@ -219,6 +219,8 @@ struct i3c_dev_desc { * every time the I3C device is rediscovered with a different dynamic * address assigned * @bus: I3C bus this device is attached to + * @node: unregistered device list node, only for use by + * i3c_master_register_new_i3c_devs(), it is not protected by a lock * * I3C device object exposed to I3C device drivers. The takes care of linking * this object to the relevant &struct_i3c_dev_desc one. @@ -229,6 +231,7 @@ struct i3c_device { struct device dev; struct i3c_dev_desc *desc; struct i3c_bus *bus; + struct list_head node; }; /* -- 2.53.0