From nobody Fri Oct 3 10:11:15 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.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 2682331E0FE; Tue, 2 Sep 2025 13:45:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756820740; cv=none; b=gdZF+Zm7fA83bppN3dZgSu7kxMu0S4I7I2TGFh8HnKnsP9+XLSiYrIkBg9xcgGv3X8dqZ6fm66DXvoCbCVgoHV1jRgU2RueD3GB7rog9/0jqsOUsaH50Eb4AimrMAwhlCJ4z0DjxxQQFDnunprlVjd1nBTgupEc0Gxnh+gatWxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756820740; c=relaxed/simple; bh=Ly46gaveC5fscZEchx1gdYGmcbsQ3rPXP0SznPjl8Qs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Mm5O3tOOI6IpqIy3zjg8jMedW7dFBBIIHxzL9jPAzTxrT/cLTctLVoRIZNobFksE+X/jlvLQOe2TREOBBI1B4q9xWKha7Ee9rUJ9dl77Hlzl17xpH4GoGGPAH6efWMIk0HeKgEvCKo7+O94fJ8S80jlkY77HUV2KZery8QPFBwg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WfS4hiN5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WfS4hiN5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C9ADC4CEED; Tue, 2 Sep 2025 13:45:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756820738; bh=Ly46gaveC5fscZEchx1gdYGmcbsQ3rPXP0SznPjl8Qs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WfS4hiN5Ue/ZpP3kGfKAMbbzJvQtGN+Jsl7t4BQaRX7V3hatUy9erVHWfchE3dwTf ossbXDKyLird//XSNPABf9ZuccN9pH6Ydens0/pXGdDYB+v5SICyalZVWlKl/bEi+x qEsKONUzyKI/EPoMrIg+DD9hmOvPq+3yaVbY4tF7s0ZBamaH/rUEP23cfVDTwXQf1l jkrkBnrr2R9u7JBlwPudNPh7jwfStNBP6VapS22SN3jVcgmpHkRM47jCCKaV0Rw2mJ wlx4T1OV+VCCvZjmrMLPChhI5Rr1fsPA8Jhr8l+DloJzg6hl21cshnMuqCzYrbeDzE NF/nGf4uoVGJQ== From: "Rafael J. Wysocki" To: Linux PM Cc: Greg Kroah-Hartman , LKML , Danilo Krummrich , Ulf Hansson , Saravana Kannan , Johannes Berg Subject: [PATCH v1 1/2] PM: core: Annotate loops walking device links as _srcu Date: Tue, 02 Sep 2025 15:43:50 +0200 Message-ID: <2393512.ElGaqSPkdT@rafael.j.wysocki> Organization: Linux Kernel Development In-Reply-To: <6202205.lOV4Wx5bFT@rafael.j.wysocki> References: <6202205.lOV4Wx5bFT@rafael.j.wysocki> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Rafael J. Wysocki Since SRCU is used for the protection of device link lists, the loops over device link lists in multiple places in drivers/base/power/main.c and in pm_runtime_get_suppliers() should be annotated as _srcu rather than as _rcu which is the case currently. Change the annotations accordingly. Signed-off-by: Rafael J. Wysocki Acked-by: Greg Kroah-Hartman Reviewed-by: Ulf Hansson --- drivers/base/power/main.c | 18 +++++++++--------- drivers/base/power/runtime.c | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -40,8 +40,8 @@ =20 typedef int (*pm_callback_t)(struct device *); =20 -#define list_for_each_entry_rcu_locked(pos, head, member) \ - list_for_each_entry_rcu(pos, head, member, \ +#define list_for_each_entry_srcu_locked(pos, head, member) \ + list_for_each_entry_srcu(pos, head, member, \ device_links_read_lock_held()) =20 /* @@ -281,7 +281,7 @@ * callbacks freeing the link objects for the links in the list we're * walking. */ - list_for_each_entry_rcu_locked(link, &dev->links.suppliers, c_node) + list_for_each_entry_srcu_locked(link, &dev->links.suppliers, c_node) if (READ_ONCE(link->status) !=3D DL_STATE_DORMANT) dpm_wait(link->supplier, async); =20 @@ -338,7 +338,7 @@ * continue instead of trying to continue in parallel with its * unregistration). */ - list_for_each_entry_rcu_locked(link, &dev->links.consumers, s_node) + list_for_each_entry_srcu_locked(link, &dev->links.consumers, s_node) if (READ_ONCE(link->status) !=3D DL_STATE_DORMANT) dpm_wait(link->consumer, async); =20 @@ -675,7 +675,7 @@ idx =3D device_links_read_lock(); =20 /* Start processing the device's "async" consumers. */ - list_for_each_entry_rcu_locked(link, &dev->links.consumers, s_node) + list_for_each_entry_srcu_locked(link, &dev->links.consumers, s_node) if (READ_ONCE(link->status) !=3D DL_STATE_DORMANT) dpm_async_with_cleanup(link->consumer, func); =20 @@ -1330,7 +1330,7 @@ idx =3D device_links_read_lock(); =20 /* Start processing the device's "async" suppliers. */ - list_for_each_entry_rcu_locked(link, &dev->links.suppliers, c_node) + list_for_each_entry_srcu_locked(link, &dev->links.suppliers, c_node) if (READ_ONCE(link->status) !=3D DL_STATE_DORMANT) dpm_async_with_cleanup(link->supplier, func); =20 @@ -1384,7 +1384,7 @@ =20 idx =3D device_links_read_lock(); =20 - list_for_each_entry_rcu_locked(link, &dev->links.suppliers, c_node) + list_for_each_entry_srcu_locked(link, &dev->links.suppliers, c_node) link->supplier->power.must_resume =3D true; =20 device_links_read_unlock(idx); @@ -1813,7 +1813,7 @@ =20 idx =3D device_links_read_lock(); =20 - list_for_each_entry_rcu_locked(link, &dev->links.suppliers, c_node) { + list_for_each_entry_srcu_locked(link, &dev->links.suppliers, c_node) { spin_lock_irq(&link->supplier->power.lock); link->supplier->power.direct_complete =3D false; spin_unlock_irq(&link->supplier->power.lock); @@ -2065,7 +2065,7 @@ =20 idx =3D device_links_read_lock(); =20 - list_for_each_entry_rcu_locked(link, &dev->links.suppliers, c_node) { + list_for_each_entry_srcu_locked(link, &dev->links.suppliers, c_node) { if (!device_link_test(link, DL_FLAG_PM_RUNTIME)) continue; =20 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1903,8 +1903,8 @@ =20 idx =3D device_links_read_lock(); =20 - list_for_each_entry_rcu(link, &dev->links.suppliers, c_node, - device_links_read_lock_held()) + list_for_each_entry_srcu(link, &dev->links.suppliers, c_node, + device_links_read_lock_held()) if (device_link_test(link, DL_FLAG_PM_RUNTIME)) { link->supplier_preactivated =3D true; pm_runtime_get_sync(link->supplier); From nobody Fri Oct 3 10:11:15 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.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 AD33430496B; Tue, 2 Sep 2025 13:45:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756820734; cv=none; b=e9+lcxHXCwbErWf0P1MvNPdULQ9GzWko3i6J1DXUx+dGtqNlXuStlnZMeyZMxFE0LzKx+yfPA71UU4rzlRJbdqZdQrXtfBsWySDVAaVOPWk+MPnLpbCWd5C9JbFasJ09O1x0nd0GqmWgsrif1mqGome3h5VKWuQN4kXL9WBmNOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756820734; c=relaxed/simple; bh=WhUCck38woFRSX+t14QPpBmFmTWLoKWxKgmD29RbU2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cdF5+WxQCnUR7B5P4Qjp6IWiso0AQo7c19WYbbekaYV1FexOXxyioBh9+5Ncm6jfSs7rzsQPCa/tpTl/FKKOrmlqQWOmwezL2b4QQgpKr5DIvpXv0VeTgKgXAtxwEcbyQxz6FmbxEcCP1JftsteYuHf45+edquuo1GvOuwXe4Ek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fytxUB97; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fytxUB97" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C816C4CEF4; Tue, 2 Sep 2025 13:45:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756820734; bh=WhUCck38woFRSX+t14QPpBmFmTWLoKWxKgmD29RbU2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fytxUB97SJZVHYz23yFigJ5IZXcddMgJS70zYUwHnAIesVwl4UhfVvMbUy5NF+lQH UdQIAIr9FXRsFK8cc8BttQoSN9SjjAk05DcEoLaWPLqEHMcf4dsWWZtn0C+a1Ihj67 OtAslUnk4a+7CcBvomEDmBbJ1OD6w4stx0/uYyZjcEz/zF1kNXBR8O4hQ3WkSxs/Ps xuJ9Ak7RAAYG3gq1m9B0g5UcFrxtzEv/aUK+M9ejpCkBghJnI3iFg1wnkeztwCPLhE FEMRY+vYx/LjjjdrsKNeaHjrfCUBKAqyfKecCyig4gtJYbXOUFl7vMxnKWz/v6Kg7q bp0WjyeUJviwA== From: "Rafael J. Wysocki" To: Linux PM Cc: Greg Kroah-Hartman , LKML , Danilo Krummrich , Ulf Hansson , Saravana Kannan , Johannes Berg Subject: [PATCH v1 2/2] PM: core: Add two macros for walking device links Date: Tue, 02 Sep 2025 15:45:14 +0200 Message-ID: <1944671.tdWV9SEqCh@rafael.j.wysocki> Organization: Linux Kernel Development In-Reply-To: <6202205.lOV4Wx5bFT@rafael.j.wysocki> References: <6202205.lOV4Wx5bFT@rafael.j.wysocki> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Rafael J. Wysocki Add separate macros for walking links to suppliers and consumers of a device to help device links users to avoid exposing the internals of struct dev_links_info in their code and possible coding mistakes related to that. Accordingly, use the new macros to replace open-coded device links list walks in the core power management code. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Acked-by: Greg Kroah-Hartman Reviewed-by: Ulf Hansson --- drivers/base/base.h | 8 ++++++++ drivers/base/power/main.c | 18 +++++++----------- drivers/base/power/runtime.c | 3 +-- 3 files changed, 16 insertions(+), 13 deletions(-) --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -251,6 +251,14 @@ void fw_devlink_drivers_done(void); void fw_devlink_probing_done(void); =20 +#define dev_for_each_link_to_supplier(__link, __dev) \ + list_for_each_entry_srcu(__link, &(__dev)->links.suppliers, c_node, \ + device_links_read_lock_held()) + +#define dev_for_each_link_to_consumer(__link, __dev) \ + list_for_each_entry_srcu(__link, &(__dev)->links.consumers, s_node, \ + device_links_read_lock_held()) + /* device pm support */ void device_pm_move_to_tail(struct device *dev); =20 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c @@ -40,10 +40,6 @@ =20 typedef int (*pm_callback_t)(struct device *); =20 -#define list_for_each_entry_srcu_locked(pos, head, member) \ - list_for_each_entry_srcu(pos, head, member, \ - device_links_read_lock_held()) - /* * The entries in the dpm_list list are in a depth first order, simply * because children are guaranteed to be discovered after parents, and @@ -281,7 +277,7 @@ * callbacks freeing the link objects for the links in the list we're * walking. */ - list_for_each_entry_srcu_locked(link, &dev->links.suppliers, c_node) + dev_for_each_link_to_supplier(link, dev) if (READ_ONCE(link->status) !=3D DL_STATE_DORMANT) dpm_wait(link->supplier, async); =20 @@ -338,7 +334,7 @@ * continue instead of trying to continue in parallel with its * unregistration). */ - list_for_each_entry_srcu_locked(link, &dev->links.consumers, s_node) + dev_for_each_link_to_consumer(link, dev) if (READ_ONCE(link->status) !=3D DL_STATE_DORMANT) dpm_wait(link->consumer, async); =20 @@ -675,7 +671,7 @@ idx =3D device_links_read_lock(); =20 /* Start processing the device's "async" consumers. */ - list_for_each_entry_srcu_locked(link, &dev->links.consumers, s_node) + dev_for_each_link_to_consumer(link, dev) if (READ_ONCE(link->status) !=3D DL_STATE_DORMANT) dpm_async_with_cleanup(link->consumer, func); =20 @@ -1330,7 +1326,7 @@ idx =3D device_links_read_lock(); =20 /* Start processing the device's "async" suppliers. */ - list_for_each_entry_srcu_locked(link, &dev->links.suppliers, c_node) + dev_for_each_link_to_supplier(link, dev) if (READ_ONCE(link->status) !=3D DL_STATE_DORMANT) dpm_async_with_cleanup(link->supplier, func); =20 @@ -1384,7 +1380,7 @@ =20 idx =3D device_links_read_lock(); =20 - list_for_each_entry_srcu_locked(link, &dev->links.suppliers, c_node) + dev_for_each_link_to_supplier(link, dev) link->supplier->power.must_resume =3D true; =20 device_links_read_unlock(idx); @@ -1813,7 +1809,7 @@ =20 idx =3D device_links_read_lock(); =20 - list_for_each_entry_srcu_locked(link, &dev->links.suppliers, c_node) { + dev_for_each_link_to_supplier(link, dev) { spin_lock_irq(&link->supplier->power.lock); link->supplier->power.direct_complete =3D false; spin_unlock_irq(&link->supplier->power.lock); @@ -2065,7 +2061,7 @@ =20 idx =3D device_links_read_lock(); =20 - list_for_each_entry_srcu_locked(link, &dev->links.suppliers, c_node) { + dev_for_each_link_to_supplier(link, dev) { if (!device_link_test(link, DL_FLAG_PM_RUNTIME)) continue; =20 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c @@ -1903,8 +1903,7 @@ =20 idx =3D device_links_read_lock(); =20 - list_for_each_entry_srcu(link, &dev->links.suppliers, c_node, - device_links_read_lock_held()) + dev_for_each_link_to_supplier(link, dev) if (device_link_test(link, DL_FLAG_PM_RUNTIME)) { link->supplier_preactivated =3D true; pm_runtime_get_sync(link->supplier);