Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Jon Hunter <jonathanh@nvidia.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Linux PM <linux-pm@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Linux PCI <linux-pci@vger.kernel.org>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Johan Hovold <johan@kernel.org>,
	Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
	Kevin Xie <kevin.xie@starfivetech.com>,
	"linux-tegra@vger.kernel.org" <linux-tegra@vger.kernel.org>
Subject: Re: [PATCH v1] PM: sleep: core: Restrict power.set_active propagation
Date: Mon, 10 Feb 2025 12:08:42 +0000	[thread overview]
Message-ID: <5a552e4d-e8b8-4557-a558-f41ef7639413@nvidia.com> (raw)
In-Reply-To: <6137505.lOV4Wx5bFT@rjwysocki.net>


On 08/02/2025 17:54, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Commit 3775fc538f53 ("PM: sleep: core: Synchronize runtime PM status of
> parents and children") exposed an issue related to simple_pm_bus_pm_ops
> that uses pm_runtime_force_suspend() and pm_runtime_force_resume() as
> bus type PM callbacks for the noirq phases of system-wide suspend and
> resume.
> 
> The problem is that pm_runtime_force_suspend() does not distinguish
> runtime-suspended devices from devices for which runtime PM has never
> been enabled, so if it sees a device with runtime PM status set to
> RPM_ACTIVE, it will assume that runtime PM is enabled for that device
> and so it will attempt to suspend it with the help of its runtime PM
> callbacks which may not be ready for that.  As it turns out, this
> causes simple_pm_bus_runtime_suspend() to crash due to a NULL pointer
> dereference.
> 
> Another problem related to the above commit and simple_pm_bus_pm_ops is
> that setting runtime PM status of a device handled by the latter to
> RPM_ACTIVE will actually prevent it from being resumed because
> pm_runtime_force_resume() only resumes devices with runtime PM status
> set to RPM_SUSPENDED.
> 
> To mitigate these issues, do not allow power.set_active to propagate
> beyond the parent of the device with DPM_FLAG_SMART_SUSPEND set that
> will need to be resumed, which should be a sufficient stop-gap for the
> time being, but they will need to be properly addressed in the future
> because in general during system-wide resume it is necessary to resume
> all devices in a dependency chain in which at least one device is going
> to be resumed.
> 
> Fixes: 3775fc538f53 ("PM: sleep: core: Synchronize runtime PM status of parents and children")
> Closes: https://lore.kernel.org/linux-pm/1c2433d4-7e0f-4395-b841-b8eac7c25651@nvidia.com/
> Reported-by: Jon Hunter <jonathanh@nvidia.com>
> Tested-by: Johan Hovold <johan+linaro@kernel.org>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>   drivers/base/power/main.c |   21 +++++++++------------
>   1 file changed, 9 insertions(+), 12 deletions(-)
> 
> --- a/drivers/base/power/main.c
> +++ b/drivers/base/power/main.c
> @@ -1191,24 +1191,18 @@
>   	return PMSG_ON;
>   }
>   
> -static void dpm_superior_set_must_resume(struct device *dev, bool set_active)
> +static void dpm_superior_set_must_resume(struct device *dev)
>   {
>   	struct device_link *link;
>   	int idx;
>   
> -	if (dev->parent) {
> +	if (dev->parent)
>   		dev->parent->power.must_resume = true;
> -		if (set_active)
> -			dev->parent->power.set_active = true;
> -	}
>   
>   	idx = device_links_read_lock();
>   
> -	list_for_each_entry_rcu_locked(link, &dev->links.suppliers, c_node) {
> +	list_for_each_entry_rcu_locked(link, &dev->links.suppliers, c_node)
>   		link->supplier->power.must_resume = true;
> -		if (set_active)
> -			link->supplier->power.set_active = true;
> -	}
>   
>   	device_links_read_unlock(idx);
>   }
> @@ -1287,9 +1281,12 @@
>   		dev->power.must_resume = true;
>   
>   	if (dev->power.must_resume) {
> -		dev->power.set_active = dev->power.set_active ||
> -			dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_SUSPEND);
> -		dpm_superior_set_must_resume(dev, dev->power.set_active);
> +		if (dev_pm_test_driver_flags(dev, DPM_FLAG_SMART_SUSPEND)) {
> +			dev->power.set_active = true;
> +			if (dev->parent && !dev->parent->power.ignore_children)
> +				dev->parent->power.set_active = true;
> +		}
> +		dpm_superior_set_must_resume(dev);
>   	}
>   
>   Complete:
> 

Thanks for fixing!

Tested-by: Jon Hunter <jonathanh@nvidia.com>

Jon

-- 
nvpublic


      parent reply	other threads:[~2025-02-10 12:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-08 17:54 [PATCH v1] PM: sleep: core: Restrict power.set_active propagation Rafael J. Wysocki
2025-02-10  9:31 ` Johan Hovold
2025-02-10 17:21   ` Rafael J. Wysocki
2025-02-10 11:31 ` Ulf Hansson
2025-02-10 12:08 ` Jon Hunter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5a552e4d-e8b8-4557-a558-f41ef7639413@nvidia.com \
    --to=jonathanh@nvidia.com \
    --cc=helgaas@kernel.org \
    --cc=johan@kernel.org \
    --cc=kevin.xie@starfivetech.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=rjw@rjwysocki.net \
    --cc=stern@rowland.harvard.edu \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox