public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] PCI/PM: Elevate PM usage during reset probing
@ 2025-04-22 23:05 Alex Williamson
  2025-04-22 23:05 ` [PATCH 1/2] PM: runtime: Define pm_runtime_put cleanup helper Alex Williamson
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Alex Williamson @ 2025-04-22 23:05 UTC (permalink / raw)
  To: bhelgaas, rafael; +Cc: Alex Williamson, linux-pci, linux-pm, linux-kernel

I encountered a confusing scenario where a device reports NoSoftRst- and
doesn't have any associated quirks to set PCI_DEV_FLAGS_NO_PM_RESET, but
it refuses to probe for PM reset support using the sysfs reset_method
attribute.  The reason turns out to be that we don't increment the usage
count while probing, the driver has the device in D3, where this system
seems to support D3cold, and the PM control register is read back as
0xffff.

The cleanup __free helper seems to be the cleanest solution here, versus
refactoring to a common exit point or wrappers around reset_fn, but feel
free to suggest otherwise.  I see a couple potential other use cases for
this helper in the vfio code.

Please review.  Thanks,

Alex

Alex Williamson (2):
  PM: runtime: Define pm_runtime_put cleanup helper
  PCI: Increment PM usage counter when probing reset methods

 drivers/pci/pci-sysfs.c    | 3 +++
 include/linux/pm_runtime.h | 2 ++
 2 files changed, 5 insertions(+)

-- 
2.48.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] PM: runtime: Define pm_runtime_put cleanup helper
  2025-04-22 23:05 [PATCH 0/2] PCI/PM: Elevate PM usage during reset probing Alex Williamson
@ 2025-04-22 23:05 ` Alex Williamson
  2025-04-23 12:21   ` Rafael J. Wysocki
  2025-04-22 23:05 ` [PATCH 2/2] PCI: Increment PM usage counter when probing reset methods Alex Williamson
  2025-04-23 21:10 ` [PATCH 0/2] PCI/PM: Elevate PM usage during reset probing Bjorn Helgaas
  2 siblings, 1 reply; 5+ messages in thread
From: Alex Williamson @ 2025-04-22 23:05 UTC (permalink / raw)
  To: bhelgaas, rafael; +Cc: Alex Williamson, linux-pci, linux-pm, linux-kernel

Define a cleanup helper for use with __free to automatically drop the
device usage count when out of scope.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 include/linux/pm_runtime.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
index 7fb5a459847e..69d4b2929ee6 100644
--- a/include/linux/pm_runtime.h
+++ b/include/linux/pm_runtime.h
@@ -466,6 +466,8 @@ static inline int pm_runtime_put(struct device *dev)
 	return __pm_runtime_idle(dev, RPM_GET_PUT | RPM_ASYNC);
 }
 
+DEFINE_FREE(pm_runtime_put, struct device *, if (_T) pm_runtime_put(_T))
+
 /**
  * __pm_runtime_put_autosuspend - Drop device usage counter and queue autosuspend if 0.
  * @dev: Target device.
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] PCI: Increment PM usage counter when probing reset methods
  2025-04-22 23:05 [PATCH 0/2] PCI/PM: Elevate PM usage during reset probing Alex Williamson
  2025-04-22 23:05 ` [PATCH 1/2] PM: runtime: Define pm_runtime_put cleanup helper Alex Williamson
@ 2025-04-22 23:05 ` Alex Williamson
  2025-04-23 21:10 ` [PATCH 0/2] PCI/PM: Elevate PM usage during reset probing Bjorn Helgaas
  2 siblings, 0 replies; 5+ messages in thread
From: Alex Williamson @ 2025-04-22 23:05 UTC (permalink / raw)
  To: bhelgaas, rafael; +Cc: Alex Williamson, linux-pci, linux-pm, linux-kernel

We can get different results probing reset methods for a device
depending on its power state.  For example, reading the PM control
register of a device in D3cold will always indicate NoSoftRst+,
preventing us from correctly probing PM reset support.

Increment the PM usage counter before any probes and use the cleanup
__free facility to automatically drop the usage counter out of scope.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 drivers/pci/pci-sysfs.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index c6cda56ca52c..71a36f57ef57 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1475,6 +1475,9 @@ static ssize_t reset_method_store(struct device *dev,
 		return count;
 	}
 
+	pm_runtime_get_sync(dev);
+	struct device *pmdev __free(pm_runtime_put) = dev;
+
 	if (sysfs_streq(buf, "default")) {
 		pci_init_reset_methods(pdev);
 		return count;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] PM: runtime: Define pm_runtime_put cleanup helper
  2025-04-22 23:05 ` [PATCH 1/2] PM: runtime: Define pm_runtime_put cleanup helper Alex Williamson
@ 2025-04-23 12:21   ` Rafael J. Wysocki
  0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2025-04-23 12:21 UTC (permalink / raw)
  To: Alex Williamson; +Cc: bhelgaas, rafael, linux-pci, linux-pm, linux-kernel

On Wed, Apr 23, 2025 at 1:05 AM Alex Williamson
<alex.williamson@redhat.com> wrote:
>
> Define a cleanup helper for use with __free to automatically drop the
> device usage count when out of scope.
>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

Acked-by: Rafael J. Wysocki <rafael@kernel.org>

> ---
>  include/linux/pm_runtime.h | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
> index 7fb5a459847e..69d4b2929ee6 100644
> --- a/include/linux/pm_runtime.h
> +++ b/include/linux/pm_runtime.h
> @@ -466,6 +466,8 @@ static inline int pm_runtime_put(struct device *dev)
>         return __pm_runtime_idle(dev, RPM_GET_PUT | RPM_ASYNC);
>  }
>
> +DEFINE_FREE(pm_runtime_put, struct device *, if (_T) pm_runtime_put(_T))
> +
>  /**
>   * __pm_runtime_put_autosuspend - Drop device usage counter and queue autosuspend if 0.
>   * @dev: Target device.
> --
> 2.48.1
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] PCI/PM: Elevate PM usage during reset probing
  2025-04-22 23:05 [PATCH 0/2] PCI/PM: Elevate PM usage during reset probing Alex Williamson
  2025-04-22 23:05 ` [PATCH 1/2] PM: runtime: Define pm_runtime_put cleanup helper Alex Williamson
  2025-04-22 23:05 ` [PATCH 2/2] PCI: Increment PM usage counter when probing reset methods Alex Williamson
@ 2025-04-23 21:10 ` Bjorn Helgaas
  2 siblings, 0 replies; 5+ messages in thread
From: Bjorn Helgaas @ 2025-04-23 21:10 UTC (permalink / raw)
  To: Alex Williamson; +Cc: bhelgaas, rafael, linux-pci, linux-pm, linux-kernel

On Tue, Apr 22, 2025 at 05:05:30PM -0600, Alex Williamson wrote:
> I encountered a confusing scenario where a device reports NoSoftRst- and
> doesn't have any associated quirks to set PCI_DEV_FLAGS_NO_PM_RESET, but
> it refuses to probe for PM reset support using the sysfs reset_method
> attribute.  The reason turns out to be that we don't increment the usage
> count while probing, the driver has the device in D3, where this system
> seems to support D3cold, and the PM control register is read back as
> 0xffff.
> 
> The cleanup __free helper seems to be the cleanest solution here, versus
> refactoring to a common exit point or wrappers around reset_fn, but feel
> free to suggest otherwise.  I see a couple potential other use cases for
> this helper in the vfio code.
> 
> Please review.  Thanks,
> 
> Alex
> 
> Alex Williamson (2):
>   PM: runtime: Define pm_runtime_put cleanup helper
>   PCI: Increment PM usage counter when probing reset methods
> 
>  drivers/pci/pci-sysfs.c    | 3 +++
>  include/linux/pm_runtime.h | 2 ++
>  2 files changed, 5 insertions(+)

Applied to pci/pm for v6.16, thanks, Alex!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-04-23 21:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-22 23:05 [PATCH 0/2] PCI/PM: Elevate PM usage during reset probing Alex Williamson
2025-04-22 23:05 ` [PATCH 1/2] PM: runtime: Define pm_runtime_put cleanup helper Alex Williamson
2025-04-23 12:21   ` Rafael J. Wysocki
2025-04-22 23:05 ` [PATCH 2/2] PCI: Increment PM usage counter when probing reset methods Alex Williamson
2025-04-23 21:10 ` [PATCH 0/2] PCI/PM: Elevate PM usage during reset probing Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox