From patchwork Wed Mar 26 18:26:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 14030460 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21C7124A07E; Wed, 26 Mar 2025 18:26:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013591; cv=none; b=f+w+UBTQ6E5k+FDcALfnD3UwIqwKmfuzyIbv17jRp0etIMYH20uFF0EGn+v3A3RgDcKG7AydSh1g1qr7EDaJyEkooKzRUqeHBaqLogtG8L43aIosgpi0j1asvSpOJlxpA/yxaajSbnEoJ4vrRLSVlbCfwJmWj6ucajsF1IwWXsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013591; c=relaxed/simple; bh=gn+/v6cRhBjIEnPOAF3lYIh+p+xfjG6vTeeGnJcNiFw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hl1Kp9nLAUkEG/IO+T/CAudZctrqkmAZ8R5imfWMo7PZlU3az4V4aqVByZi04R1aYj0Uocgv/Re00xUCcnHk/n4w+i55Wa9F/4GTnBlQISPwEkhRTHS2gKjEBXQP/Fh7TPq2M5/FKbrErKmca+7eowW6r5JLcI8ZgYpwJjuNrKg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=IG4wIeSx; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="IG4wIeSx" Received: by mail.gandi.net (Postfix) with ESMTPSA id 672D244440; Wed, 26 Mar 2025 18:26:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1743013587; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iPoylJSd+/GX5nIi3NjyD3T+AJXrnqwS94Z+NkVmwp0=; b=IG4wIeSx82JQe6FTP9/qWcU07pXwenyenDJyN9FrAyqWIFDHWiIE/oy3aFzdY3FhHKOSDD 50JvAh9Qmy+OUMb5NAiH2g67l9KrDBPqFyOzKw6kOr1EB+29HgcSeqUeQCmnVbx+7vXlQi fn3SIzEYxe3pF41EmeOhfgMSpeHMqkZlWFB9tzJuGU2epdcqDjeywlOoOMajxy/Tg4lkhu pA2P0US/bMWr/JlXUUiEfVjz8QoKXowUGf1BbeTgSEvlbdNMiBxKlJ8NgAYH16iBasJgQs XAGFxwrt66doiVBqz0NtuA2PiFPmot3IwWz8tFLglIJSVIhXxW7p782i5XIJgQ== From: Miquel Raynal Date: Wed, 26 Mar 2025 19:26:16 +0100 Subject: [PATCH RFC 01/10] PM: runtime: Add helpers to resume consumers Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250326-cross-lock-dep-v1-1-3199e49e8652@bootlin.com> References: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> In-Reply-To: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> To: "Rafael J. Wysocki" , Pavel Machek , Len Brown , Greg Kroah-Hartman , Danilo Krummrich , Michael Turquette , Stephen Boyd Cc: Thomas Petazzoni , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Chen-Yu Tsai , Lucas Stach , Laurent Pinchart , Marek Vasut , Ulf Hansson , Kevin Hilman , Fabio Estevam , Jacky Bai , Peng Fan , Shawn Guo , Shengjiu Wang , linux-imx@nxp.com, Ian Ray , =?utf-8?q?Herv?= =?utf-8?q?=C3=A9_Codina?= , Luca Ceresoli , Saravana Kannan , Miquel Raynal X-Mailer: b4 0.15-dev X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduieeivdehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepofhiqhhuvghlucftrgihnhgrlhcuoehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeelgfehvdduieefieeikeffgffggfdttdeugeffieetheeuleelfeehffdtffetveenucfkphepledtrdekledrudeifedruddvjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeltddrkeelrdduieefrdduvdejpdhhvghloheplgduledvrdduieekrdegvddrgeeingdpmhgrihhlfhhrohhmpehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvkedprhgtphhtthhopehmrghrvgigseguvghngidruggvpdhrtghpthhtoheplhhinhhugidqihhmgiesnhigphdrtghomhdprhgtphhtthhopehlihhnuhigqdgtlhhksehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihgrnhdrrhgrhiesghgvhhgvrghlthhhtggrrhgvrdgtohhmpdhrtghpthhtohepmhhtuhhrqhhuvghtthgvsegsrgihlhhisghrvgdrtghomhdpr hgtphhtthhopehssghohigusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkhhhilhhmrghnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomh X-GND-Sasl: miquel.raynal@bootlin.com The runtime PM core currently allows to runtime resume/suspend a device, or its suppliers. Let's make it also possible to runtime resume/suspend consumers. Consumers and suppliers are seen here through the description made by device_links. Signed-off-by: Miquel Raynal --- drivers/base/power/runtime.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_runtime.h | 2 ++ 2 files changed, 56 insertions(+) diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 2ee45841486bc73225b3e971164466647b3ce6d3..04bb66c18e3e4a45751fb3f9a6a1267d73757310 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1841,6 +1841,60 @@ void pm_runtime_put_suppliers(struct device *dev) device_links_read_unlock(idx); } +static void __pm_runtime_get_consumers(struct device *dev) +{ + struct device_link *link; + + list_for_each_entry_rcu(link, &dev->links.consumers, s_node, + device_links_read_lock_held()) + if (link->flags & DL_FLAG_PM_RUNTIME) { + pm_runtime_get_sync(link->consumer); + __pm_runtime_get_consumers(link->consumer); + } +} + +/** + * pm_runtime_get_consumers - Resume and reference-count consumer devices. + * @dev: Supplier device. + */ +void pm_runtime_get_consumers(struct device *dev) +{ + int idx; + + idx = device_links_read_lock(); + + __pm_runtime_get_consumers(dev); + + device_links_read_unlock(idx); +} + +static void __pm_runtime_put_consumers(struct device *dev) +{ + struct device_link *link; + + list_for_each_entry_rcu(link, &dev->links.consumers, s_node, + device_links_read_lock_held()) + if (link->flags & DL_FLAG_PM_RUNTIME) { + pm_runtime_put(link->consumer); + __pm_runtime_put_consumers(link->consumer); + } +} + +/** + * pm_runtime_put_consumers - Drop references to consumer devices. + * @dev: Supplier device. + */ +void pm_runtime_put_consumers(struct device *dev) +{ + int idx; + + idx = device_links_read_lock(); + + __pm_runtime_put_consumers(dev); + + device_links_read_unlock(idx); +} + void pm_runtime_new_link(struct device *dev) { spin_lock_irq(&dev->power.lock); diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h index d39dc863f612fe18dc34182117f87908d63c8e6d..151c885a3f421f09509232f144618da62297d61d 100644 --- a/include/linux/pm_runtime.h +++ b/include/linux/pm_runtime.h @@ -89,6 +89,8 @@ extern u64 pm_runtime_autosuspend_expiration(struct device *dev); extern void pm_runtime_set_memalloc_noio(struct device *dev, bool enable); extern void pm_runtime_get_suppliers(struct device *dev); extern void pm_runtime_put_suppliers(struct device *dev); +extern void pm_runtime_get_consumers(struct device *dev); +extern void pm_runtime_put_consumers(struct device *dev); extern void pm_runtime_new_link(struct device *dev); extern void pm_runtime_drop_link(struct device_link *link); extern void pm_runtime_release_supplier(struct device_link *link); From patchwork Wed Mar 26 18:26:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 14030461 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E47F2459CB; Wed, 26 Mar 2025 18:26:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013592; cv=none; b=SqR6oAS/PoyIIeP3MiPhFkXrtGayg5pvv63DSmTHKdEpMW1u5pEKsAfAbiVinPbLGOxVhr3MivJ0IWVjW94eKg8tm7+6zd316RkIzsY2IQci16/Odkm77Z3HbT+KrAmCXbuc2nDfrXQKwAvJmJjU7E8mBqqnwqDu2eau5Rx4C3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013592; c=relaxed/simple; bh=pUdbIzTSWu9FizDsOr0A4bulFwTYwtPu12MdLYGg1c0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Tp+h98jLuVKdLFgkqOoFumidc5ZQPS1oHgaCJWrg8IMqrb2Sojoytiq6z0f4O5oUc1AfRlkzq1NMH94VqwYGKLFNz6BD7xuBShRmXHb0NjPJOGaiGnbLasoYknly91YmSRbNfBP8ExNsdL+/FzdQlfbzv5fv0eCFZOe/6OU4guU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=QcRFWQ6W; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="QcRFWQ6W" Received: by mail.gandi.net (Postfix) with ESMTPSA id A16714441C; Wed, 26 Mar 2025 18:26:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1743013588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2Cfz0a/5S6u6nHzcv1rW0zQzLUAGoNaXxXWFyhaaNgQ=; b=QcRFWQ6WLTgdNy2fray1YCL5Mh7OyoyMSVnWPJZf5cQxDrIdJvzc1f5CHnaHOdjuU9A3If ghl6wjWjwdVhm1wJ8nyGsUnDFHBcNgIS0PeZxyDR22sJ/4mxubnVq6I/zZmboXPAiz8Efp rRjdK2myTh/SJ9CKwxa6/WoCv35itqwrStihuxn8FfV1mLskPHQtJN1h9UF/RYo1b6dAz2 nx42HfGGrlCo+h9L2mZLmaF5pbdN4jfT30fnQv9aQI3ymjJzFSotvh/x0VrFbxFeH3i6EN vstciFxNHiwjApJDO7Z7lFgU0tP3RX8565Cyzc6qgORcN+JGyiA/jEA8dSrVRQ== From: Miquel Raynal Date: Wed, 26 Mar 2025 19:26:17 +0100 Subject: [PATCH RFC 02/10] clk: Improve comments with usual punctuation Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250326-cross-lock-dep-v1-2-3199e49e8652@bootlin.com> References: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> In-Reply-To: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> To: "Rafael J. Wysocki" , Pavel Machek , Len Brown , Greg Kroah-Hartman , Danilo Krummrich , Michael Turquette , Stephen Boyd Cc: Thomas Petazzoni , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Chen-Yu Tsai , Lucas Stach , Laurent Pinchart , Marek Vasut , Ulf Hansson , Kevin Hilman , Fabio Estevam , Jacky Bai , Peng Fan , Shawn Guo , Shengjiu Wang , linux-imx@nxp.com, Ian Ray , =?utf-8?q?Herv?= =?utf-8?q?=C3=A9_Codina?= , Luca Ceresoli , Saravana Kannan , Miquel Raynal X-Mailer: b4 0.15-dev X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduieeivdehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepofhiqhhuvghlucftrgihnhgrlhcuoehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeelgfehvdduieefieeikeffgffggfdttdeugeffieetheeuleelfeehffdtffetveenucfkphepledtrdekledrudeifedruddvjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeltddrkeelrdduieefrdduvdejpdhhvghloheplgduledvrdduieekrdegvddrgeeingdpmhgrihhlfhhrohhmpehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvkedprhgtphhtthhopehmrghrvgigseguvghngidruggvpdhrtghpthhtoheplhhinhhugidqihhmgiesnhigphdrtghomhdprhgtphhtthhopehlihhnuhigqdgtlhhksehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihgrnhdrrhgrhiesghgvhhgvrghlthhhtggrrhgvrdgtohhmpdhrtghpthhtohepmhhtuhhrqhhuvghtthgvsegsrgihlhhisghrvgdrtghomhdpr hgtphhtthhopehssghohigusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkhhhilhhmrghnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomh X-GND-Sasl: miquel.raynal@bootlin.com These two-line comments did not meant anything to me until I figured out they were two separated sentences. Clarify these comments. Signed-off-by: Miquel Raynal --- drivers/clk/clk.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index cf7720b9172ff223d86227aad144e15375ddfd86..7df9965bcbdffd641e6dbf5bff3d3b20079a3af3 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -289,8 +289,8 @@ static bool clk_core_is_prepared(struct clk_core *core) bool ret = false; /* - * .is_prepared is optional for clocks that can prepare - * fall back to software usage counter if it is missing + * .is_prepared is optional for clocks that can prepare. + * Fall back to software usage counter if it is missing. */ if (!core->ops->is_prepared) return core->prepare_count; @@ -308,8 +308,8 @@ static bool clk_core_is_enabled(struct clk_core *core) bool ret = false; /* - * .is_enabled is only mandatory for clocks that gate - * fall back to software usage counter if .is_enabled is missing + * .is_enabled is only mandatory for clocks that gate. + * Fall back to software usage counter if .is_enabled is missing */ if (!core->ops->is_enabled) return core->enable_count; From patchwork Wed Mar 26 18:26:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 14030462 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D167C253329; Wed, 26 Mar 2025 18:26:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013594; cv=none; b=YiULyy7c9BtaOm4dRt8c1LIGaJoZB/2gugD3L46Sh/kHgDLQ6RDxw6J30AEis/1R8GHYWp5mZUkzbBS4tS98/Kd3KURiUfAvJ50RRVyevMOtru5JvvK8JXILojlkfkhX01XrM7tEMgXMOScS++aXaigrybxAHnatqyqIQh4FiVM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013594; c=relaxed/simple; bh=sNLIxfRQxoLMAhgUD68uj8OIlLkhY/ZJlt5ea2wwBSQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SYnqc3I1gJibTq+LGtj8bCDwznCFaMSetUtcW3LIsqDrE3LzsSCCXpOlpMku6HYfDdQDeXl+496EMHeiPI9/sWJe7laetgDk7A+gr/9QIjufHJgVkTA1Rb0Bt0xWZyh4B6QylHWc0XkeJwtGC7zvUPrH2Qou0HtWa7jFzc3zv78= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=HtU8fdh7; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="HtU8fdh7" Received: by mail.gandi.net (Postfix) with ESMTPSA id D5F474443D; Wed, 26 Mar 2025 18:26:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1743013589; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k+D4+TVvLLcIqytfuD7J/XNoklUwFm0W6VvZ8tlYmJk=; b=HtU8fdh7KePPCVVs9OoRBWCkqO2qnhsZ7a3r2bxlZb5tjI2un0xAtctzxTQ6PGahKj9ket J3zoCgV5+dr5QarWYkE5m2NiEGTxbXDuu5680oLiItkhvX9TGmlNELK2j/B5bOzZcdF1lh EEqPyoKT0njR1vzl76N3sko45VurrjY0CfFmL9DLTJPHSc/r7cVK2CPbGNF7eCi1mG2m1/ LFSLM8Y+hnwLTfpJbz8I2RZQFhx55Qr3HkHrNDiVUuICdhcjyY4w5DvM9Z/IgMRrBhLik7 +A3dISVCcSFimQa5Q3TXFLspZrZbpnxYNfHb8bw7ncy7kt/HNiV8TyxeBQQFUA== From: Miquel Raynal Date: Wed, 26 Mar 2025 19:26:18 +0100 Subject: [PATCH RFC 03/10] clk: Avoid non needed runtime PM calls Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250326-cross-lock-dep-v1-3-3199e49e8652@bootlin.com> References: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> In-Reply-To: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> To: "Rafael J. Wysocki" , Pavel Machek , Len Brown , Greg Kroah-Hartman , Danilo Krummrich , Michael Turquette , Stephen Boyd Cc: Thomas Petazzoni , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Chen-Yu Tsai , Lucas Stach , Laurent Pinchart , Marek Vasut , Ulf Hansson , Kevin Hilman , Fabio Estevam , Jacky Bai , Peng Fan , Shawn Guo , Shengjiu Wang , linux-imx@nxp.com, Ian Ray , =?utf-8?q?Herv?= =?utf-8?q?=C3=A9_Codina?= , Luca Ceresoli , Saravana Kannan , Miquel Raynal X-Mailer: b4 0.15-dev X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduieeivdehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepofhiqhhuvghlucftrgihnhgrlhcuoehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeelgfehvdduieefieeikeffgffggfdttdeugeffieetheeuleelfeehffdtffetveenucfkphepledtrdekledrudeifedruddvjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeltddrkeelrdduieefrdduvdejpdhhvghloheplgduledvrdduieekrdegvddrgeeingdpmhgrihhlfhhrohhmpehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvkedprhgtphhtthhopehmrghrvgigseguvghngidruggvpdhrtghpthhtoheplhhinhhugidqihhmgiesnhigphdrtghomhdprhgtphhtthhopehlihhnuhigqdgtlhhksehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihgrnhdrrhgrhiesghgvhhgvrghlthhhtggrrhgvrdgtohhmpdhrtghpthhtohepmhhtuhhrqhhuvghtthgvsegsrgihlhhisghrvgdrtghomhdpr hgtphhtthhopehssghohigusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkhhhilhhmrghnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomh X-GND-Sasl: miquel.raynal@bootlin.com clk_core_is_prepared() needs the clock to be runtime resumed in order to call the ->is_prepared() callback. But at the same time, clk_prepare() runtime resumes the clock and clk_unprepare() runtime disables it. The fact that the clock might be runtime resumed do not indicate it's been prepared, however the fact that it's been prepared implies that it's been runtime resumed. We can safely check the runtime status of the clock (and RPM increment it in this case) instead of actually calling resume. With this little trick, clk_core_is_prepared() can be called from anywhere without extra constraint regarding the fact that the prepare_lock mutex might be acquired or not already. Signed-off-by: Miquel Raynal --- drivers/clk/clk.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 7df9965bcbdffd641e6dbf5bff3d3b20079a3af3..1c15d72cd3daeeb5bb4f0d94c9f387526fab75ae 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -119,6 +119,20 @@ static int clk_pm_runtime_get(struct clk_core *core) return pm_runtime_resume_and_get(core->dev); } +static int clk_pm_runtime_get_if_active(struct clk_core *core) +{ + int ret; + + if (!core || !core->rpm_enabled) + return 0; + + ret = pm_runtime_get_if_active(core->dev); + if (ret == 1) + return 0; + + return -EINVAL; +} + static void clk_pm_runtime_put(struct clk_core *core) { if (!core->rpm_enabled) @@ -295,7 +309,7 @@ static bool clk_core_is_prepared(struct clk_core *core) if (!core->ops->is_prepared) return core->prepare_count; - if (!clk_pm_runtime_get(core)) { + if (!clk_pm_runtime_get_if_active(core)) { ret = core->ops->is_prepared(core->hw); clk_pm_runtime_put(core); } From patchwork Wed Mar 26 18:26:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 14030463 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED63A253B75; Wed, 26 Mar 2025 18:26:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013595; cv=none; b=fB565ImgovAhjF8+NLB5UKzIwxk54XsOVwi6XVpI4u/RCoZ+O47SZkHB7Y3AghC7E4fkEzAspUd/KA9MWe3qDiwXPL/AVPbkAJUwWORaHjjCjFNqo6NtkIipMMk90zDiYyKrVXpCGeMqPBRQz6Mhroc+NHjHCTkpQG31JpsncFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013595; c=relaxed/simple; bh=El6RnnblGHxBDg+fU4YV0UFItKdKeeznwLzVSIgxWPw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qDg2oTywSoIm6E/0mj53aCK4/7M5KCvz7iKlNtwxXDkGdu57cP9UTJR9s2RvSqXVaW5BQOSHOgSA1YWpRri06hT4nVl167Ookqcz0GEefWluNoEPjq2ac5VGEruVQ9umpcIEWzVhUfVH9MB1YMwJyu6IbFH16OgyvZ38/FT2jPc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=ozgXb7WC; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ozgXb7WC" Received: by mail.gandi.net (Postfix) with ESMTPSA id 09A2D44442; Wed, 26 Mar 2025 18:26:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1743013591; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TMDpRFlyrc8/aoAZfTEymjWosNwBMkC80r+GYpVAIsw=; b=ozgXb7WCfn28PDmXmcINhTrtyKUBTMLRCWwumqUkvYFMtwnxp/zsYMTI+fFCSN5BEcvgUx qskkydokGVMGWduF/5/9vYNm/UOm5wkKTvM6g4DzNACO9RBszpSHGj95Cx7j/OP5YK7W/L p7/08miVTHjxwT4BSXCZHHHLD3AL498xszr7oVUiu6xMTfwJlQfc31n7y7mu5N6g1ecbcN MD7IAWT1qSzVIgWXw5X7OEy9ZsVEXRnj6nKb8STlqxd4AWeB9tf+eAkhJvfMkXNsPDKINH xSQ103LUafozh8KzD5oHeDFLF+gwrMu9aZpRDw5Pdkv5nuVKWuetpvxA5Z5Fiw== From: Miquel Raynal Date: Wed, 26 Mar 2025 19:26:19 +0100 Subject: [PATCH RFC 04/10] clk: Avoid open coded-logic when a there is a helper available Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250326-cross-lock-dep-v1-4-3199e49e8652@bootlin.com> References: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> In-Reply-To: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> To: "Rafael J. Wysocki" , Pavel Machek , Len Brown , Greg Kroah-Hartman , Danilo Krummrich , Michael Turquette , Stephen Boyd Cc: Thomas Petazzoni , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Chen-Yu Tsai , Lucas Stach , Laurent Pinchart , Marek Vasut , Ulf Hansson , Kevin Hilman , Fabio Estevam , Jacky Bai , Peng Fan , Shawn Guo , Shengjiu Wang , linux-imx@nxp.com, Ian Ray , =?utf-8?q?Herv?= =?utf-8?q?=C3=A9_Codina?= , Luca Ceresoli , Saravana Kannan , Miquel Raynal X-Mailer: b4 0.15-dev X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduieeivdehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepofhiqhhuvghlucftrgihnhgrlhcuoehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeelgfehvdduieefieeikeffgffggfdttdeugeffieetheeuleelfeehffdtffetveenucfkphepledtrdekledrudeifedruddvjeenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepihhnvghtpeeltddrkeelrdduieefrdduvdejpdhhvghloheplgduledvrdduieekrdegvddrgeeingdpmhgrihhlfhhrohhmpehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvkedprhgtphhtthhopehmrghrvgigseguvghngidruggvpdhrtghpthhtoheplhhinhhugidqihhmgiesnhigphdrtghomhdprhgtphhtthhopehlihhnuhigqdgtlhhksehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihgrnhdrrhgrhiesghgvhhgvrghlthhhtggrrhgvrdgtohhmpdhrtghpthhtohepmhhtuhhrqhhuvghtthgvsegsrgihlhhisghrvgdrtghomhdpr hgtphhtthhopehssghohigusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkhhhilhhmrghnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomh X-GND-Sasl: miquel.raynal@bootlin.com The logic for checking whether a clock is already runtime resumed exists (and increasing the refcounting in this case) is already available. Reuse the helper instead of open-coding the logic here again. Signed-off-by: Miquel Raynal --- drivers/clk/clk.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 1c15d72cd3daeeb5bb4f0d94c9f387526fab75ae..a6148eae7b6615d23d6ac665e8f94e2ae69f93b6 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -338,13 +338,8 @@ static bool clk_core_is_enabled(struct clk_core *core) * taking enable spinlock, but the below check is needed if one tries * to call it from other places. */ - if (core->rpm_enabled) { - pm_runtime_get_noresume(core->dev); - if (!pm_runtime_active(core->dev)) { - ret = false; - goto done; - } - } + if (clk_pm_runtime_get_if_active(core)) + return false; /* * This could be called with the enable lock held, or from atomic @@ -359,8 +354,7 @@ static bool clk_core_is_enabled(struct clk_core *core) ret = core->ops->is_enabled(core->hw); done: - if (core->rpm_enabled) - pm_runtime_put(core->dev); + clk_pm_runtime_put(core); return ret; } From patchwork Wed Mar 26 18:26:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 14030464 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41475255252; Wed, 26 Mar 2025 18:26:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013596; cv=none; b=nVFsgCMg4C8aTZ+UV7timIQy4U9idnoeiBZj67gcoZEVXfwWAhzo+f69/oFRO2VFLSWBcnSm3chG9s5MBwJ7R/cEg0KCRJ/Tj52kaOErXLw6BuKF+JflMJIuMqsQJ755vQVlvGLvLoatKrh0oJI8EfEs0w6M2mcACdCQWBO6Lcs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013596; c=relaxed/simple; bh=TXM7sLhzHfOEVWJ/LZpNHizW5tziUNT8UE+3ZJDD6sE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mlvFD5Gwe1TARNw7O/DShBzQxAzG4ATzFkCEw74pdAsQV3APH1u3XK/DI/WzBmCGGA6DLoZcQ1N4TKLGi8Y17QFKBzLIyY5fr4yxvSfVyHz+IKk9GMjEBwe9a/Q101Y+r2TIVYuNUjLbvz7PC86Uv1y8eREgHht6qkoq+PWaMT8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=L0uNkCSl; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="L0uNkCSl" Received: by mail.gandi.net (Postfix) with ESMTPSA id 52DE14443C; Wed, 26 Mar 2025 18:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1743013592; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DKTpwOtwUs6kWNFE1zxeuftYDJFPwkNiJxs3ZZp0nXc=; b=L0uNkCSlYuuQHMPfS8p0uKgfqzAyfEz5yEv4jcYZc75cfdXbWTL+6CudMjYBoPz3FsFF7r ClVtozGq7/VitKafCS0HZEPZ8eFGBc4cNzmTw0IKK+GenHPNgMWj2LEcZcF5PjpwzipVQX Fw5JZtxtsjuy/CUR7UVKskDWxJqLaAvxVGWKgw2Z9ZgNYkPlSG4A5H9C8OYSnpl/+fhRAP qTsM1+Qlr08hQjIRXmQNwrb9DJyqVS0Kra1i0ofEkfqPjW3iayRBHw+sAfwMQUrFgu5qkI G35jfjrfp7SkTKOahbMA6eMv/+i4AooVCN/0tcypRbzSn3FC8u/6w4GI0p8H/A== From: Miquel Raynal Date: Wed, 26 Mar 2025 19:26:20 +0100 Subject: [PATCH RFC 05/10] clk: Move runtime PM calls out of the prepare_lock in clk_init() Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250326-cross-lock-dep-v1-5-3199e49e8652@bootlin.com> References: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> In-Reply-To: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> To: "Rafael J. Wysocki" , Pavel Machek , Len Brown , Greg Kroah-Hartman , Danilo Krummrich , Michael Turquette , Stephen Boyd Cc: Thomas Petazzoni , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Chen-Yu Tsai , Lucas Stach , Laurent Pinchart , Marek Vasut , Ulf Hansson , Kevin Hilman , Fabio Estevam , Jacky Bai , Peng Fan , Shawn Guo , Shengjiu Wang , linux-imx@nxp.com, Ian Ray , =?utf-8?q?Herv?= =?utf-8?q?=C3=A9_Codina?= , Luca Ceresoli , Saravana Kannan , Miquel Raynal X-Mailer: b4 0.15-dev X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduieeivdehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepofhiqhhuvghlucftrgihnhgrlhcuoehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeelgfehvdduieefieeikeffgffggfdttdeugeffieetheeuleelfeehffdtffetveenucfkphepledtrdekledrudeifedruddvjeenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepihhnvghtpeeltddrkeelrdduieefrdduvdejpdhhvghloheplgduledvrdduieekrdegvddrgeeingdpmhgrihhlfhhrohhmpehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvkedprhgtphhtthhopehmrghrvgigseguvghngidruggvpdhrtghpthhtoheplhhinhhugidqihhmgiesnhigphdrtghomhdprhgtphhtthhopehlihhnuhigqdgtlhhksehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihgrnhdrrhgrhiesghgvhhgvrghlthhhtggrrhgvrdgtohhmpdhrtghpthhtohepmhhtuhhrqhhuvghtthgvsegsrgihlhhisghrvgdrtghomhdpr hgtphhtthhopehssghohigusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkhhhilhhmrghnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomh X-GND-Sasl: miquel.raynal@bootlin.com In order to fix the ABBA locking situation between clock and power domains, let's disimburse these two locks by preventing any runtime PM call to happen with the clk prepare_lock mutex acquired. The __clock_core_init() routine shall preferably call the runtime PM functions before acquiring the prepare lock, which can be achieved by the existing clk_pm_runtime_get_all() call. We have no other choice than waking up all clocks at this stage because we are going the possibly reparent any random orphan clock in the system at this stage, and thus will require all its parents and children to be enabled. Signed-off-by: Miquel Raynal --- drivers/clk/clk.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index a6148eae7b6615d23d6ac665e8f94e2ae69f93b6..b6decfaf8aa6bd50c2173d19f1ece8f08a95afd8 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -3906,6 +3906,14 @@ static int __clk_core_init(struct clk_core *core) unsigned long rate; int phase; + /* + * While reparenting the orphans, it is too late to resume the children + * that will get their rates recalculated. + */ + ret = clk_pm_runtime_get_all(); + if (ret) + return ret; + clk_prepare_lock(); /* @@ -3916,10 +3924,6 @@ static int __clk_core_init(struct clk_core *core) */ core->hw->core = core; - ret = clk_pm_runtime_get(core); - if (ret) - goto unlock; - /* check to see if a clock with this name is already registered */ if (clk_core_lookup(core->name)) { pr_debug("%s: clk %s already initialized\n", @@ -4082,8 +4086,6 @@ static int __clk_core_init(struct clk_core *core) clk_core_reparent_orphans_nolock(); out: - clk_pm_runtime_put(core); -unlock: if (ret) { hlist_del_init(&core->child_node); core->hw->core = NULL; @@ -4091,6 +4093,8 @@ static int __clk_core_init(struct clk_core *core) clk_prepare_unlock(); + clk_pm_runtime_put_all(); + if (!ret) clk_debug_register(core); From patchwork Wed Mar 26 18:26:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 14030465 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BA6324A077; Wed, 26 Mar 2025 18:26:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013597; cv=none; b=DHt6COH8YGjsTri8CBiuW08D5svb0jQKOcvlBf9V5Q0DN5WNrHqlbly6F9zBmYpM5OW7OQKqo9v1xeRJMRZTDQas91xupcuVNA9MtWrDqj+J+UKKtJ4nJo/e7zg9xgICee5T6fkrOWy8wQAlTYKjKruaq1vE246Sn/D+S6zD8ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013597; c=relaxed/simple; bh=fQRi4Amjuf0y/liuUYDVS5GF+DVY1+r5MM+krVbpn0I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EEU/3voNozlEchBsgKwGxnFiKEi+0hS4+GDUtl0GxXCxB5Tbrx/uJquqfiWlvLyl44NGCQo92GHXnczY7p/CGelWU3nrR+VmZbsCPf7PPk4V1aAJQe2Xwag1eSPtPp/y4G9QjYpw22fTTE/IKM5LRXWRanYSV/2SGetxCSUD8jU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=H6VnLgNQ; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="H6VnLgNQ" Received: by mail.gandi.net (Postfix) with ESMTPSA id 9BB2044443; Wed, 26 Mar 2025 18:26:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1743013593; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OcGvc6n0vOnsaoJ5OZPe24saE0nLgPTFQXzjqD1fHgc=; b=H6VnLgNQqzGqJEWF3O579ImX06LL+m/5N6zm4+WilCp6/geOFS71VNrmP4lbZWqEwy23Af reX53yM5P82UMuSWiUmgGBMbF6bGo/FXYtx3VwzJ8MMFuGoC/7xwz9fdK7aeASosz7yD+b dQesEqyIqV3bb0ThryfRcnROgcQDZNLbNJiNVgPyycZjiY1yI/D1e6RqP4SNQtW5WounyG VBJbcMxA6OyM6lyseEYEEIBpvUYYj39koVo3nBT3bkUzZ+TjnCueDBROIkSQJDPVwe4Sdh v2/SN1SqjZgT9kxUv7eHbUKsY2/cu+BUpqGxNKofO5E1AVDXcw7pcG71wJ/Lsw== From: Miquel Raynal Date: Wed, 26 Mar 2025 19:26:21 +0100 Subject: [PATCH RFC 06/10] clk: Move runtime PM calls out of the prepare_lock in clk_prepare() Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250326-cross-lock-dep-v1-6-3199e49e8652@bootlin.com> References: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> In-Reply-To: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> To: "Rafael J. Wysocki" , Pavel Machek , Len Brown , Greg Kroah-Hartman , Danilo Krummrich , Michael Turquette , Stephen Boyd Cc: Thomas Petazzoni , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Chen-Yu Tsai , Lucas Stach , Laurent Pinchart , Marek Vasut , Ulf Hansson , Kevin Hilman , Fabio Estevam , Jacky Bai , Peng Fan , Shawn Guo , Shengjiu Wang , linux-imx@nxp.com, Ian Ray , =?utf-8?q?Herv?= =?utf-8?q?=C3=A9_Codina?= , Luca Ceresoli , Saravana Kannan , Miquel Raynal X-Mailer: b4 0.15-dev X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduieeivdehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepofhiqhhuvghlucftrgihnhgrlhcuoehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeelgfehvdduieefieeikeffgffggfdttdeugeffieetheeuleelfeehffdtffetveenucfkphepledtrdekledrudeifedruddvjeenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepihhnvghtpeeltddrkeelrdduieefrdduvdejpdhhvghloheplgduledvrdduieekrdegvddrgeeingdpmhgrihhlfhhrohhmpehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvkedprhgtphhtthhopehmrghrvgigseguvghngidruggvpdhrtghpthhtoheplhhinhhugidqihhmgiesnhigphdrtghomhdprhgtphhtthhopehlihhnuhigqdgtlhhksehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihgrnhdrrhgrhiesghgvhhgvrghlthhhtggrrhgvrdgtohhmpdhrtghpthhtohepmhhtuhhrqhhuvghtthgvsegsrgihlhhisghrvgdrtghomhdpr hgtphhtthhopehssghohigusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkhhhilhhmrghnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomh X-GND-Sasl: miquel.raynal@bootlin.com In order to fix the ABBA locking situation between clock and power domains, let's disimburse these two locks by preventing any runtime PM call to happen with the clk prepare_lock mutex acquired. The prepare routine shall preferably call the runtime PM functions before acquiring the prepare lock. In practice the prepare helper requires the current clock and all its parents to be runtime resumed. There is no need to perform individual calls as we get inner and inner in recursive calls (ie. following the "clock parents") because, as of today, runtime PM works by already resuming automatically all the suppliers which in this case already include the clock parents. Hence, doing a single runtime PM call at the beginning of the function is enough. One side effect though is that we now need to check for the validity of core clk pointers in the runtime PM clk helpers. Signed-off-by: Miquel Raynal --- drivers/clk/clk.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index b6decfaf8aa6bd50c2173d19f1ece8f08a95afd8..95f53bc427d8980287bfe668d1c993023e0e078b 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -113,7 +113,7 @@ struct clk { /*** runtime pm ***/ static int clk_pm_runtime_get(struct clk_core *core) { - if (!core->rpm_enabled) + if (!core || !core->rpm_enabled) return 0; return pm_runtime_resume_and_get(core->dev); @@ -135,7 +135,7 @@ static int clk_pm_runtime_get_if_active(struct clk_core *core) static void clk_pm_runtime_put(struct clk_core *core) { - if (!core->rpm_enabled) + if (!core || !core->rpm_enabled) return; pm_runtime_put_sync(core->dev); @@ -1081,7 +1081,6 @@ static void clk_core_unprepare(struct clk_core *core) trace_clk_unprepare_complete(core); clk_core_unprepare(core->parent); - clk_pm_runtime_put(core); } static void clk_core_unprepare_lock(struct clk_core *core) @@ -1089,6 +1088,8 @@ static void clk_core_unprepare_lock(struct clk_core *core) clk_prepare_lock(); clk_core_unprepare(core); clk_prepare_unlock(); + + clk_pm_runtime_put(core); } /** @@ -1121,13 +1122,9 @@ static int clk_core_prepare(struct clk_core *core) return 0; if (core->prepare_count == 0) { - ret = clk_pm_runtime_get(core); - if (ret) - return ret; - ret = clk_core_prepare(core->parent); if (ret) - goto runtime_put; + return ret; trace_clk_prepare(core); @@ -1155,8 +1152,7 @@ static int clk_core_prepare(struct clk_core *core) return 0; unprepare: clk_core_unprepare(core->parent); -runtime_put: - clk_pm_runtime_put(core); + return ret; } @@ -1164,10 +1160,17 @@ static int clk_core_prepare_lock(struct clk_core *core) { int ret; + ret = clk_pm_runtime_get(core); + if (ret) + return ret; + clk_prepare_lock(); ret = clk_core_prepare(core); clk_prepare_unlock(); + if (ret) + clk_pm_runtime_put(core); + return ret; } From patchwork Wed Mar 26 18:26:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 14030466 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C58812580D2; Wed, 26 Mar 2025 18:26:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013598; cv=none; b=HyXzicwnyHwnx7KUBidtxEjrdphT4ZnyJv5QEG8ZEy4K6YY0y307m/AVKDlV1dZQQHeYQqtVwOBwJCfXKVgSZtHpUc3zNXH5MK9nZN2NZfAXPZn4Q8B06S3cbtBgq7c6X6HajGkK5G06So3HCR95av6DNZpt9LXyXR7ILGKUfrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013598; c=relaxed/simple; bh=vAlRbDLpBPvP27lE5l60zdFPJjk/fx1iTxJsOyArih8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=f1HchB6EpJEl8XGw/+y+5tuU3iMS9WisUuxv6q6GfQWO4pK5fZG4BWnIniwgag3v5rYGGmWVpcdIjxKxPZbh/IfN2MF0iEOVsH8UU4MIg31tN/nCEiWyVDl6lVyuIOtjYcLw2Sm8VinmLkh6BxSYQH+rHlHVhx1rIv6rU1SDAfc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=RPxAusWO; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="RPxAusWO" Received: by mail.gandi.net (Postfix) with ESMTPSA id D81734441C; Wed, 26 Mar 2025 18:26:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1743013595; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t2hsGs3TPtjFLp63wGPsUwJ0AqSkzAmn92jic3zpuq8=; b=RPxAusWOpENU7S+0Gm6/ZorY7WocaT/IlByfoaDUzw/QcIBrAcdCo734i2ubSBsnX9hARj CXlaxA8jExPw3ZBbze+xDVOPFzaw4bLYWcucOZrGxZDlpmBk1FL7pdEx66Qhn6I8fewkE9 hVWs8cB0b8zSxpL+WJB/3imhLhZ7SHeTcQhkAzKVfvIc3gt5wZU08102nIELKlLZjfNMIX apcQ3WMsuDUn7ebSslAsiscmz1TUA9wcp1X/ai580VAEmxhIePq3rFB6+Cn80a3ipaf6c+ vJ0NlQQkKAOl5xVY+xFIWMUtot/6GK4MnbS4uursyGA5iNz1VLZxddnhVbhBTw== From: Miquel Raynal Date: Wed, 26 Mar 2025 19:26:22 +0100 Subject: [PATCH RFC 07/10] clk: Ensure all RPM enabled clocks are enabled before reparenting orphans Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250326-cross-lock-dep-v1-7-3199e49e8652@bootlin.com> References: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> In-Reply-To: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> To: "Rafael J. Wysocki" , Pavel Machek , Len Brown , Greg Kroah-Hartman , Danilo Krummrich , Michael Turquette , Stephen Boyd Cc: Thomas Petazzoni , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Chen-Yu Tsai , Lucas Stach , Laurent Pinchart , Marek Vasut , Ulf Hansson , Kevin Hilman , Fabio Estevam , Jacky Bai , Peng Fan , Shawn Guo , Shengjiu Wang , linux-imx@nxp.com, Ian Ray , =?utf-8?q?Herv?= =?utf-8?q?=C3=A9_Codina?= , Luca Ceresoli , Saravana Kannan , Miquel Raynal X-Mailer: b4 0.15-dev X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduieeivdehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepofhiqhhuvghlucftrgihnhgrlhcuoehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeelgfehvdduieefieeikeffgffggfdttdeugeffieetheeuleelfeehffdtffetveenucfkphepledtrdekledrudeifedruddvjeenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepihhnvghtpeeltddrkeelrdduieefrdduvdejpdhhvghloheplgduledvrdduieekrdegvddrgeeingdpmhgrihhlfhhrohhmpehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvkedprhgtphhtthhopehmrghrvgigseguvghngidruggvpdhrtghpthhtoheplhhinhhugidqihhmgiesnhigphdrtghomhdprhgtphhtthhopehlihhnuhigqdgtlhhksehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihgrnhdrrhgrhiesghgvhhgvrghlthhhtggrrhgvrdgtohhmpdhrtghpthhtohepmhhtuhhrqhhuvghtthgvsegsrgihlhhisghrvgdrtghomhdpr hgtphhtthhopehssghohigusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkhhhilhhmrghnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomh X-GND-Sasl: miquel.raynal@bootlin.com In order to fix the ABBA locking situation between clock and power domains, let's disimburse these two locks by preventing any runtime PM call to happen with the clk prepare_lock mutex acquired. Reparenting orphans upon introduction of a new provider means that if there is a match, the core will recalculate the rates, which requires the relevant clocks to be enabled. There is not much we can do to guess which clocks will need rate recalculation, so better ensure all registered clocks are resumed before doing the reparenting operation which obviously requires acquiring the clk prepare_lock to protect against concurrent accesses on the clk tree topology. Signed-off-by: Miquel Raynal --- drivers/clk/clk.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 95f53bc427d8980287bfe668d1c993023e0e078b..4c2f2d2b7735dfbe323fec4e0d331302534bc849 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -5032,8 +5032,16 @@ int of_clk_add_provider(struct device_node *np, mutex_unlock(&of_clk_mutex); pr_debug("Added clock from %pOF\n", np); + ret = clk_pm_runtime_get_all(); + if (ret) { + of_clk_del_provider(np); + return ret; + } + clk_core_reparent_orphans(); + clk_pm_runtime_put_all(); + ret = of_clk_set_defaults(np, true); if (ret < 0) of_clk_del_provider(np); @@ -5074,8 +5082,16 @@ int of_clk_add_hw_provider(struct device_node *np, mutex_unlock(&of_clk_mutex); pr_debug("Added clk_hw provider from %pOF\n", np); + ret = clk_pm_runtime_get_all(); + if (ret) { + of_clk_del_provider(np); + return ret; + } + clk_core_reparent_orphans(); + clk_pm_runtime_put_all(); + ret = of_clk_set_defaults(np, true); if (ret < 0) of_clk_del_provider(np); From patchwork Wed Mar 26 18:26:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 14030467 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD08F258CFA; Wed, 26 Mar 2025 18:26:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013599; cv=none; b=hrn5Kbf31Z0NKfnqIht6Ny5oaTfRZvjn1w0JDr+OAMaP5iID9BLiVnffXd+VpQFVE2aUPhZC+MGB1c6CMd6oq+2gaPzNqEb6cPxRGM56dkBCIJwHv8Rg5wgSVOzGHA7i0qBGis4QWffnKAPsfMzjH0Y/DecqyFGF2sM8SK9hRA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013599; c=relaxed/simple; bh=gJfK6+B5JQj/94XazxErSDyeIkb7T600MeCpaeGZceg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tvkxpQKbCWB102oMsAt1LmcU23rcy43mZpdZgkePhvKHvIeS80Gyk130cK0rHEjdnX6yuM8GFpBd4a6ZFhQA6rO8VOvb/Gv1dNysLxqgctMDwvooGKU4yMd8ySqlqXlE6u8ZQb7MDdq6fNEK+s21jFhQ3Z25o15be/O12D2R304= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=MIwa1tjw; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="MIwa1tjw" Received: by mail.gandi.net (Postfix) with ESMTPSA id 30DCD44440; Wed, 26 Mar 2025 18:26:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1743013596; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YQwpVU/XbRJq6paA0C/EVBzKGAJNY3Fgxupz9l/uNkA=; b=MIwa1tjwQLR5HbQmg2fPVW7fJahFLAqOE8nuTFOWA7gEfxYtBRIT03BoKDRgOUeVnfUbyC PKepVBMVy0mJzsfzGg8TtiI/9MG3ksPO8skQd5ArSsucxQ2D/QA1Qxm5hMqem3332l0dfF BYLhZj9Qz5C2upuN1nHxqeFXWZ4eH246Ph8bH4ifj932eLz3HNhmTommXMCSglfP4zPb4N tuvDkgimwP4Nskio+9s2VSb03zXE/M1gxiQqdni2fRSCLKsJkvRqwkyGiyTvFiSO7CGXMQ oR5UKi1NxSBzvhmDMHDDFLQYa5ARrTDc5+OhN7BrCKu5QiB7+TkgWFrjoJiBjA== From: Miquel Raynal Date: Wed, 26 Mar 2025 19:26:23 +0100 Subject: [PATCH RFC 08/10] clk: Move runtime PM calls out of the prepare_lock in clk_unregister() Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250326-cross-lock-dep-v1-8-3199e49e8652@bootlin.com> References: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> In-Reply-To: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> To: "Rafael J. Wysocki" , Pavel Machek , Len Brown , Greg Kroah-Hartman , Danilo Krummrich , Michael Turquette , Stephen Boyd Cc: Thomas Petazzoni , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Chen-Yu Tsai , Lucas Stach , Laurent Pinchart , Marek Vasut , Ulf Hansson , Kevin Hilman , Fabio Estevam , Jacky Bai , Peng Fan , Shawn Guo , Shengjiu Wang , linux-imx@nxp.com, Ian Ray , =?utf-8?q?Herv?= =?utf-8?q?=C3=A9_Codina?= , Luca Ceresoli , Saravana Kannan , Miquel Raynal X-Mailer: b4 0.15-dev X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduieeivdehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepofhiqhhuvghlucftrgihnhgrlhcuoehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeelgfehvdduieefieeikeffgffggfdttdeugeffieetheeuleelfeehffdtffetveenucfkphepledtrdekledrudeifedruddvjeenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgrmhepihhnvghtpeeltddrkeelrdduieefrdduvdejpdhhvghloheplgduledvrdduieekrdegvddrgeeingdpmhgrihhlfhhrohhmpehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvkedprhgtphhtthhopehmrghrvgigseguvghngidruggvpdhrtghpthhtoheplhhinhhugidqihhmgiesnhigphdrtghomhdprhgtphhtthhopehlihhnuhigqdgtlhhksehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihgrnhdrrhgrhiesghgvhhgvrghlthhhtggrrhgvrdgtohhmpdhrtghpthhtohepmhhtuhhrqhhuvghtthgvsegsrgihlhhisghrvgdrtghomhdpr hgtphhtthhopehssghohigusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkhhhilhhmrghnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomh X-GND-Sasl: miquel.raynal@bootlin.com In order to fix the ABBA locking situation between clock and power domains, let's disimburse these two locks by preventing any runtime PM call to happen with the clk prepare_lock mutex acquired. The clk_unregister() routine calls clk_core_set_parent_nolock() which can runtime resume basically any clock randomly in the system after having acquired the main clk lock. In this case the easier approach to avoid failures is to make sure we wake up all runtime PM enabled clocks in the system before acquiring the lock. We are not in a hot path anyway. Signed-off-by: Miquel Raynal --- drivers/clk/clk.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 4c2f2d2b7735dfbe323fec4e0d331302534bc849..339ebfa8cca729ffb84127e01a21f741bc270cb3 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -4574,6 +4574,9 @@ void clk_unregister(struct clk *clk) clk_debug_unregister(clk->core); + if (clk_pm_runtime_get_all()) + return; + clk_prepare_lock(); ops = clk->core->ops; @@ -4617,6 +4620,8 @@ void clk_unregister(struct clk *clk) __func__, clk->core->name); clk_prepare_unlock(); + clk_pm_runtime_put_all(); + kref_put(&clk->core->ref, __clk_release); free_clk(clk); } From patchwork Wed Mar 26 18:26:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 14030468 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9510425A647; Wed, 26 Mar 2025 18:26:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013601; cv=none; b=B4HldJYJTKc2zqR6o0lUn4W6OqVB/spXdo+b1oMNf3HIKW2B8Mba61h2UsZMd/Z5IVf3mnPP019LIEw/V5CL5txUZmNNXxXq9a/lrORpMe+r7uFfmFcUrgtyre6UfKKnedopfQj0vopoLGL9GyPVEsUowY30frPmhE2hZBzh3kw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013601; c=relaxed/simple; bh=p/SQu/txIkaclb7CmktdQaCDuOWlbdrrhqQjCNeoSGg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RRvejFURQdc9IQ23xgn4sLLPTm5tshymyxWpVr/uSmWs5q7ZTVUfq9gPGf+jMSN9t4OOsfahPfHGZBgeje9z3AzPsO+BNyybnYd2BIz8Uv/ARXfC0x0pLk0XNgT3GGQiKkOT07aWZt7yGR2I7H2FZAdDz8/aRkLToX66nffRtXo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=DHocBZj4; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="DHocBZj4" Received: by mail.gandi.net (Postfix) with ESMTPSA id 7093944446; Wed, 26 Mar 2025 18:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1743013597; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R3+Mu9M77+PpoOK75hoSqIuv6VHqsXdDyRQbbbzxiv0=; b=DHocBZj4pX8S9PdrRo5/CUny+pFhQH9TSirK/9Hz8o5d4FsIwaZS2PrrSFMObOwFxtSWTP NemWy6D+8pBsIyLoqXW06FOvNoyLdgrSwYYXT4EZ+CrnlixAd2L1rUtrGvuMHa7aKIuIpE ArH1PPcdG7TPbWgE/syqXZM9vE1A0uBgT7R9kfZqPBSxNN2t33IspnrE6k8bdXCysh3F4I 4Pz2b57XjaaatcKIjtRccjom0k6DkN2zr6hjYJuBFC0iH2UWiWrbtiNEzjHaNI2MNY/Wl7 xbv22sE35t/xAoMXfAkKGCF8uf42Sxcor9XA+Owt3WGOoQKttzWLJ6KynCYbLA== From: Miquel Raynal Date: Wed, 26 Mar 2025 19:26:24 +0100 Subject: [PATCH RFC 09/10] clk: Make sure clock parents and children are resumed when necessary Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250326-cross-lock-dep-v1-9-3199e49e8652@bootlin.com> References: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> In-Reply-To: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> To: "Rafael J. Wysocki" , Pavel Machek , Len Brown , Greg Kroah-Hartman , Danilo Krummrich , Michael Turquette , Stephen Boyd Cc: Thomas Petazzoni , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Chen-Yu Tsai , Lucas Stach , Laurent Pinchart , Marek Vasut , Ulf Hansson , Kevin Hilman , Fabio Estevam , Jacky Bai , Peng Fan , Shawn Guo , Shengjiu Wang , linux-imx@nxp.com, Ian Ray , =?utf-8?q?Herv?= =?utf-8?q?=C3=A9_Codina?= , Luca Ceresoli , Saravana Kannan , Miquel Raynal X-Mailer: b4 0.15-dev X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduieeivdehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepofhiqhhuvghlucftrgihnhgrlhcuoehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeelgfehvdduieefieeikeffgffggfdttdeugeffieetheeuleelfeehffdtffetveenucfkphepledtrdekledrudeifedruddvjeenucevlhhushhtvghrufhiiigvpeeknecurfgrrhgrmhepihhnvghtpeeltddrkeelrdduieefrdduvdejpdhhvghloheplgduledvrdduieekrdegvddrgeeingdpmhgrihhlfhhrohhmpehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvkedprhgtphhtthhopehmrghrvgigseguvghngidruggvpdhrtghpthhtoheplhhinhhugidqihhmgiesnhigphdrtghomhdprhgtphhtthhopehlihhnuhigqdgtlhhksehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihgrnhdrrhgrhiesghgvhhgvrghlthhhtggrrhgvrdgtohhmpdhrtghpthhtohepmhhtuhhrqhhuvghtthgvsegsrgihlhhisghrvgdrtghomhdpr hgtphhtthhopehssghohigusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkhhhilhhmrghnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomh X-GND-Sasl: miquel.raynal@bootlin.com Any pm_runtime_get() call will both wake up the core clock as well as its parents. But there are some cases which also require resuming the children clocks. One way to do that is to use the new pm_runtime_get_consumers() helper. It's been identified that the following situation may require resuming the children: - getting the rate - setting the rate - changing the parent (especially since it may produce rate changes) - putting the clock, which may involve reparenting as well In order to fix the ABBA locking situation between clock and power domains, let's disimburse these two locks by resuming the children outside of the prepare_lock in one function call by using this new helper. Signed-off-by: Miquel Raynal --- drivers/clk/clk.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 339ebfa8cca729ffb84127e01a21f741bc270cb3..26af3a134fa7b9d7f4a77ff473df7e79fd465789 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -119,6 +119,20 @@ static int clk_pm_runtime_get(struct clk_core *core) return pm_runtime_resume_and_get(core->dev); } +static int clk_pm_runtime_get_and_consumers(struct clk_core *core) +{ + int ret; + + if (!core || !core->rpm_enabled) + return 0; + + ret = pm_runtime_resume_and_get(core->dev); + if (!ret) + pm_runtime_get_consumers(core->dev); + + return ret; +} + static int clk_pm_runtime_get_if_active(struct clk_core *core) { int ret; @@ -141,6 +155,16 @@ static void clk_pm_runtime_put(struct clk_core *core) pm_runtime_put_sync(core->dev); } +static void clk_pm_runtime_put_and_consumers(struct clk_core *core) +{ + if (!core || !core->rpm_enabled) + return; + + pm_runtime_put_consumers(core->dev); + + pm_runtime_put_sync(core->dev); +} + /** * clk_pm_runtime_get_all() - Runtime "get" all clk provider devices * @@ -2010,10 +2034,15 @@ unsigned long clk_get_rate(struct clk *clk) if (!clk) return 0; + if (clk_pm_runtime_get_and_consumers(clk->core)) + return 0; + clk_prepare_lock(); rate = clk_core_get_rate_recalc(clk->core); clk_prepare_unlock(); + clk_pm_runtime_put_and_consumers(clk->core); + return rate; } EXPORT_SYMBOL_GPL(clk_get_rate); @@ -2605,6 +2634,10 @@ int clk_set_rate(struct clk *clk, unsigned long rate) if (!clk) return 0; + ret = clk_pm_runtime_get_and_consumers(clk->core); + if (ret) + return ret; + /* prevent racing with updates to the clock topology */ clk_prepare_lock(); @@ -2618,6 +2651,8 @@ int clk_set_rate(struct clk *clk, unsigned long rate) clk_prepare_unlock(); + clk_pm_runtime_put_and_consumers(clk->core); + return ret; } EXPORT_SYMBOL_GPL(clk_set_rate); @@ -2648,6 +2683,10 @@ int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) if (!clk) return 0; + ret = clk_pm_runtime_get_and_consumers(clk->core); + if (ret) + return ret; + /* prevent racing with updates to the clock topology */ clk_prepare_lock(); @@ -2665,6 +2704,8 @@ int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) clk_prepare_unlock(); + clk_pm_runtime_put_and_consumers(clk->core); + return ret; } EXPORT_SYMBOL_GPL(clk_set_rate_exclusive); @@ -2755,12 +2796,18 @@ int clk_set_rate_range(struct clk *clk, unsigned long min, unsigned long max) if (!clk) return 0; + ret = clk_pm_runtime_get_and_consumers(clk->core); + if (ret) + return ret; + clk_prepare_lock(); ret = clk_set_rate_range_nolock(clk, min, max); clk_prepare_unlock(); + clk_pm_runtime_put_and_consumers(clk->core); + return ret; } EXPORT_SYMBOL_GPL(clk_set_rate_range); @@ -2964,6 +3011,10 @@ int clk_set_parent(struct clk *clk, struct clk *parent) if (!clk) return 0; + ret = clk_pm_runtime_get_and_consumers(clk->core); + if (ret) + return ret; + clk_prepare_lock(); if (clk->exclusive_count) @@ -2977,6 +3028,8 @@ int clk_set_parent(struct clk *clk, struct clk *parent) clk_prepare_unlock(); + clk_pm_runtime_put_and_consumers(clk->core); + return ret; } EXPORT_SYMBOL_GPL(clk_set_parent); @@ -3459,10 +3512,16 @@ static int clk_rate_set(void *data, u64 val) struct clk_core *core = data; int ret; + ret = clk_pm_runtime_get_and_consumers(core); + if (ret) + return ret; + clk_prepare_lock(); ret = clk_core_set_rate_nolock(core, val); clk_prepare_unlock(); + clk_pm_runtime_put_and_consumers(core); + return ret; } @@ -3518,11 +3577,18 @@ DEFINE_DEBUGFS_ATTRIBUTE(clk_prepare_enable_fops, clk_prepare_enable_get, static int clk_rate_get(void *data, u64 *val) { struct clk_core *core = data; + int ret; + + ret = clk_pm_runtime_get_and_consumers(core); + if (ret) + return ret; clk_prepare_lock(); *val = clk_core_get_rate_recalc(core); clk_prepare_unlock(); + clk_pm_runtime_put_and_consumers(core); + return 0; } @@ -3659,12 +3725,18 @@ static ssize_t current_parent_write(struct file *file, const char __user *ubuf, if (!parent) return -ENOENT; + err = clk_pm_runtime_get_and_consumers(parent); + if (err) + return err; + clk_prepare_lock(); err = clk_core_set_parent_nolock(core, parent); clk_prepare_unlock(); if (err) return err; + clk_pm_runtime_put_and_consumers(parent); + return count; } @@ -4762,6 +4834,9 @@ void __clk_put(struct clk *clk) if (!clk || WARN_ON_ONCE(IS_ERR(clk))) return; + if (clk_pm_runtime_get_and_consumers(clk->core)) + return; + clk_prepare_lock(); /* @@ -4784,6 +4859,8 @@ void __clk_put(struct clk *clk) clk_prepare_unlock(); + clk_pm_runtime_put_and_consumers(clk->core); + owner = clk->core->owner; kref_put(&clk->core->ref, __clk_release); module_put(owner); From patchwork Wed Mar 26 18:26:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 14030469 Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73EB825D524; Wed, 26 Mar 2025 18:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013602; cv=none; b=B+lfBENgT2i0m0j9XCMJUrrFx3sp1z9up6o6nPZjRToas81YhbKhR9n3ObH5vWgPEuMHL0QkeEWwHz2vq89ZEccT6+FhFI7JgpD6gcrpeXnc9xYN9cGcX+ENg47XjF5z6JSnh0/d8BU59P+o6BzG9rcCOdBo9sIb/TzQsqLbeco= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743013602; c=relaxed/simple; bh=2hOOkKfJ2O24FeBerSRc7TzBcA7RAdNIvqDCbUOqPBs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bIMeYPny+SRWPFKI0XKfB8Q9o3AFAU43srAyHanFMTgfVnNj4Fg+2paIFXEhfZ3GS59BC9pZtNpidXgfGteCTJPMSuPLvemvG7il5/3zQ0feBXLBGbpW8p5FG5AAwaXLpXq53cEtgGoa1NvxkMqp/jJ+4BBIt2xDiIxEZxHsRWg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=WQBePKR6; arc=none smtp.client-ip=217.70.183.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="WQBePKR6" Received: by mail.gandi.net (Postfix) with ESMTPSA id BD6F844447; Wed, 26 Mar 2025 18:26:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1743013598; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G6fDJAgeivWwEjOlUOt+sxMAv2+TjUSgdeW6xREfgQ4=; b=WQBePKR6H4Qi0pPpju+j0GA4z4uw2abs39R6ZvrmXUT7QQXG06s56xvKtQtO4KjWqdF7Df dpT/YQ+1W6kwCwSyqW5+tjpfVHHzIO7tqSJA6+/0WUtzbpDlMCnHdEw8jMrzTPnlmIObSK 8vUfxrXsB+MtbES6OucJb75vs1SRo8cWbcHk/7m5OzXaD2pqSNWeIsg6oDca6m9kLRw2CD PQZUTQsucwmimu2Yl3CYP0VIZrfNDvNJr398UMc4+x4Iu5MIlwJD2F6CQW3d2ZYKzF2Tv6 0mbek6lj9SZIX133MF4YJtQ33N8t8yElehLWVozJtTLRsqIvOfycZjMwUxP2Vw== From: Miquel Raynal Date: Wed, 26 Mar 2025 19:26:25 +0100 Subject: [PATCH RFC 10/10] clk: Fix the ABBA locking issue with runtime PM subcalls Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250326-cross-lock-dep-v1-10-3199e49e8652@bootlin.com> References: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> In-Reply-To: <20250326-cross-lock-dep-v1-0-3199e49e8652@bootlin.com> To: "Rafael J. Wysocki" , Pavel Machek , Len Brown , Greg Kroah-Hartman , Danilo Krummrich , Michael Turquette , Stephen Boyd Cc: Thomas Petazzoni , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Chen-Yu Tsai , Lucas Stach , Laurent Pinchart , Marek Vasut , Ulf Hansson , Kevin Hilman , Fabio Estevam , Jacky Bai , Peng Fan , Shawn Guo , Shengjiu Wang , linux-imx@nxp.com, Ian Ray , =?utf-8?q?Herv?= =?utf-8?q?=C3=A9_Codina?= , Luca Ceresoli , Saravana Kannan , Miquel Raynal X-Mailer: b4 0.15-dev X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdduieeivdehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepofhiqhhuvghlucftrgihnhgrlhcuoehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpeelgfehvdduieefieeikeffgffggfdttdeugeffieetheeuleelfeehffdtffetveenucfkphepledtrdekledrudeifedruddvjeenucevlhhushhtvghrufhiiigvpeeknecurfgrrhgrmhepihhnvghtpeeltddrkeelrdduieefrdduvdejpdhhvghloheplgduledvrdduieekrdegvddrgeeingdpmhgrihhlfhhrohhmpehmihhquhgvlhdrrhgrhihnrghlsegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvkedprhgtphhtthhopehmrghrvgigseguvghngidruggvpdhrtghpthhtoheplhhinhhugidqihhmgiesnhigphdrtghomhdprhgtphhtthhopehlihhnuhigqdgtlhhksehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepihgrnhdrrhgrhiesghgvhhgvrghlthhhtggrrhgvrdgtohhmpdhrtghpthhtohepmhhtuhhrqhhuvghtthgvsegsrgihlhhisghrvgdrtghomhdpr hgtphhtthhopehssghohigusehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkhhhilhhmrghnsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehthhhomhgrshdrphgvthgriiiiohhnihessghoohhtlhhinhdrtghomh X-GND-Sasl: miquel.raynal@bootlin.com The clock subsystem is calling runtime PM callbacks after having acquired its own lock, which is in general problematic, especially because when PM callbacks enter the power domain subsystem, we have the following scenario: mutex_lock(prepare_lock) mutex_lock(genpd_lock) But on the other side, devices may enable power domains, which themselves might require clocks, forcing the following path: mutex_lock(genpd_lock) mutex_lock(prepare_lock) The clk core has been modified in order to avoid the need for "late" runtime PM calls (ie. inside the clk prepare_lock), so what remains to be done is to simply remove these inner runtime calls. Signed-off-by: Miquel Raynal --- drivers/clk/clk.c | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 26af3a134fa7b9d7f4a77ff473df7e79fd465789..652551860201f2d4ed606c55079dc4fb655d9fa0 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1961,10 +1961,9 @@ static unsigned long clk_recalc(struct clk_core *core, { unsigned long rate = parent_rate; - if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { + if (core->ops->recalc_rate) rate = core->ops->recalc_rate(core->hw, parent_rate); - clk_pm_runtime_put(core); - } + return rate; } @@ -2458,9 +2457,6 @@ static void clk_change_rate(struct clk_core *core) best_parent_rate = core->parent->rate; } - if (clk_pm_runtime_get(core)) - return; - if (core->flags & CLK_SET_RATE_UNGATE) { clk_core_prepare(core); clk_core_enable_lock(core); @@ -2523,8 +2519,6 @@ static void clk_change_rate(struct clk_core *core) /* handle the new child who might not be in core->children yet */ if (core->new_child) clk_change_rate(core->new_child); - - clk_pm_runtime_put(core); } static unsigned long clk_core_req_round_rate_nolock(struct clk_core *core, @@ -2562,7 +2556,6 @@ static int clk_core_set_rate_nolock(struct clk_core *core, { struct clk_core *top, *fail_clk; unsigned long rate; - int ret; if (!core) return 0; @@ -2582,28 +2575,21 @@ static int clk_core_set_rate_nolock(struct clk_core *core, if (!top) return -EINVAL; - ret = clk_pm_runtime_get(core); - if (ret) - return ret; - /* notify that we are about to change rates */ fail_clk = clk_propagate_rate_change(top, PRE_RATE_CHANGE); if (fail_clk) { pr_debug("%s: failed to set %s rate\n", __func__, fail_clk->name); clk_propagate_rate_change(top, ABORT_RATE_CHANGE); - ret = -EBUSY; - goto err; + return -EBUSY; } /* change the rates */ clk_change_rate(top); core->req_rate = req_rate; -err: - clk_pm_runtime_put(core); - return ret; + return 0; } /** @@ -2953,16 +2939,12 @@ static int clk_core_set_parent_nolock(struct clk_core *core, p_rate = parent->rate; } - ret = clk_pm_runtime_get(core); - if (ret) - return ret; - /* propagate PRE_RATE_CHANGE notifications */ ret = __clk_speculate_rates(core, p_rate); /* abort if a driver objects */ if (ret & NOTIFY_STOP_MASK) - goto runtime_put; + return ret; /* do the re-parent */ ret = __clk_set_parent(core, parent, p_index); @@ -2975,9 +2957,6 @@ static int clk_core_set_parent_nolock(struct clk_core *core, __clk_recalc_accuracies(core); } -runtime_put: - clk_pm_runtime_put(core); - return ret; }