linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND] i2c: i801: Stop using pm_runtime_set_autosuspend_delay(-1)
@ 2021-09-07 20:33 Heiner Kallweit
  2021-09-15 12:09 ` Rafael J. Wysocki
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Heiner Kallweit @ 2021-09-07 20:33 UTC (permalink / raw)
  To: Jean Delvare; +Cc: linux-acpi, Andy Shevchenko, linux-i2c

The original change works as intended, but Andy pointed in [0] that now
userspace could re-enable RPM via sysfs, even though we explicitly want
to disable it. So effectively revert the original patch, just with small
improvements:
- Calls to pm_runtime_allow()/pm_runtime_forbid() don't have to be
  balanced, so we can remove the call to pm_runtime_forbid() in
  i801_remove().
- priv->acpi_reserved is accessed after i801_acpi_remove(), and according
  to Robert [1] the custom handler can't run any longer. Therefore we
  don't have to take priv->acpi_lock.

[0] https://www.spinics.net/lists/linux-i2c/msg52730.html
[1] https://lore.kernel.org/linux-acpi/BYAPR11MB32561D19A0FD9AB93E2B1E5287D39@BYAPR11MB3256.namprd11.prod.outlook.com/T/#t

Fixes: 4e60d5dd10cd ("i2c: i801: Improve disabling runtime pm")
Reported-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
- Resend because I missed to cc linux-i2c list
---
 drivers/i2c/busses/i2c-i801.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 1f929e6c3..f3c79942c 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -1623,7 +1623,7 @@ i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
 		 * BIOS is accessing the host controller so prevent it from
 		 * suspending automatically from now on.
 		 */
-		pm_runtime_set_autosuspend_delay(&pdev->dev, -1);
+		pm_runtime_get_sync(&pdev->dev);
 	}
 
 	if ((function & ACPI_IO_MASK) == ACPI_READ)
@@ -1890,9 +1890,6 @@ static void i801_remove(struct pci_dev *dev)
 {
 	struct i801_priv *priv = pci_get_drvdata(dev);
 
-	pm_runtime_forbid(&dev->dev);
-	pm_runtime_get_noresume(&dev->dev);
-
 	i801_disable_host_notify(priv);
 	i801_del_mux(priv);
 	i2c_del_adapter(&priv->adapter);
@@ -1901,6 +1898,10 @@ static void i801_remove(struct pci_dev *dev)
 
 	platform_device_unregister(priv->tco_pdev);
 
+	/* if acpi_reserved is set then usage_count is incremented already */
+	if (!priv->acpi_reserved)
+		pm_runtime_get_noresume(&dev->dev);
+
 	/*
 	 * do not call pci_disable_device(dev) since it can cause hard hangs on
 	 * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
-- 
2.33.0


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

* Re: [PATCH RESEND] i2c: i801: Stop using pm_runtime_set_autosuspend_delay(-1)
  2021-09-07 20:33 [PATCH RESEND] i2c: i801: Stop using pm_runtime_set_autosuspend_delay(-1) Heiner Kallweit
@ 2021-09-15 12:09 ` Rafael J. Wysocki
  2021-09-16  8:09 ` Jean Delvare
  2021-09-29 20:13 ` Wolfram Sang
  2 siblings, 0 replies; 4+ messages in thread
From: Rafael J. Wysocki @ 2021-09-15 12:09 UTC (permalink / raw)
  To: Heiner Kallweit
  Cc: Jean Delvare, ACPI Devel Maling List, Andy Shevchenko, linux-i2c

On Tue, Sep 7, 2021 at 10:33 PM Heiner Kallweit <hkallweit1@gmail.com> wrote:
>
> The original change works as intended, but Andy pointed in [0] that now
> userspace could re-enable RPM via sysfs, even though we explicitly want
> to disable it. So effectively revert the original patch, just with small
> improvements:
> - Calls to pm_runtime_allow()/pm_runtime_forbid() don't have to be
>   balanced, so we can remove the call to pm_runtime_forbid() in
>   i801_remove().
> - priv->acpi_reserved is accessed after i801_acpi_remove(), and according
>   to Robert [1] the custom handler can't run any longer. Therefore we
>   don't have to take priv->acpi_lock.
>
> [0] https://www.spinics.net/lists/linux-i2c/msg52730.html
> [1] https://lore.kernel.org/linux-acpi/BYAPR11MB32561D19A0FD9AB93E2B1E5287D39@BYAPR11MB3256.namprd11.prod.outlook.com/T/#t
>
> Fixes: 4e60d5dd10cd ("i2c: i801: Improve disabling runtime pm")
> Reported-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>

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

> ---
> - Resend because I missed to cc linux-i2c list
> ---
>  drivers/i2c/busses/i2c-i801.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
> index 1f929e6c3..f3c79942c 100644
> --- a/drivers/i2c/busses/i2c-i801.c
> +++ b/drivers/i2c/busses/i2c-i801.c
> @@ -1623,7 +1623,7 @@ i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
>                  * BIOS is accessing the host controller so prevent it from
>                  * suspending automatically from now on.
>                  */
> -               pm_runtime_set_autosuspend_delay(&pdev->dev, -1);
> +               pm_runtime_get_sync(&pdev->dev);
>         }
>
>         if ((function & ACPI_IO_MASK) == ACPI_READ)
> @@ -1890,9 +1890,6 @@ static void i801_remove(struct pci_dev *dev)
>  {
>         struct i801_priv *priv = pci_get_drvdata(dev);
>
> -       pm_runtime_forbid(&dev->dev);
> -       pm_runtime_get_noresume(&dev->dev);
> -
>         i801_disable_host_notify(priv);
>         i801_del_mux(priv);
>         i2c_del_adapter(&priv->adapter);
> @@ -1901,6 +1898,10 @@ static void i801_remove(struct pci_dev *dev)
>
>         platform_device_unregister(priv->tco_pdev);
>
> +       /* if acpi_reserved is set then usage_count is incremented already */
> +       if (!priv->acpi_reserved)
> +               pm_runtime_get_noresume(&dev->dev);
> +
>         /*
>          * do not call pci_disable_device(dev) since it can cause hard hangs on
>          * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
> --
> 2.33.0
>

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

* Re: [PATCH RESEND] i2c: i801: Stop using pm_runtime_set_autosuspend_delay(-1)
  2021-09-07 20:33 [PATCH RESEND] i2c: i801: Stop using pm_runtime_set_autosuspend_delay(-1) Heiner Kallweit
  2021-09-15 12:09 ` Rafael J. Wysocki
@ 2021-09-16  8:09 ` Jean Delvare
  2021-09-29 20:13 ` Wolfram Sang
  2 siblings, 0 replies; 4+ messages in thread
From: Jean Delvare @ 2021-09-16  8:09 UTC (permalink / raw)
  To: Heiner Kallweit; +Cc: linux-acpi, Andy Shevchenko, linux-i2c

Hi Heiner,

On Tue, 07 Sep 2021 22:33:02 +0200, Heiner Kallweit wrote:
> The original change works as intended, but Andy pointed in [0] that now
> userspace could re-enable RPM via sysfs, even though we explicitly want
> to disable it. So effectively revert the original patch, just with small
> improvements:
> - Calls to pm_runtime_allow()/pm_runtime_forbid() don't have to be
>   balanced, so we can remove the call to pm_runtime_forbid() in
>   i801_remove().
> - priv->acpi_reserved is accessed after i801_acpi_remove(), and according
>   to Robert [1] the custom handler can't run any longer. Therefore we
>   don't have to take priv->acpi_lock.
> 
> [0] https://www.spinics.net/lists/linux-i2c/msg52730.html
> [1] https://lore.kernel.org/linux-acpi/BYAPR11MB32561D19A0FD9AB93E2B1E5287D39@BYAPR11MB3256.namprd11.prod.outlook.com/T/#t
> 
> Fixes: 4e60d5dd10cd ("i2c: i801: Improve disabling runtime pm")
> Reported-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
> - Resend because I missed to cc linux-i2c list
> ---
>  drivers/i2c/busses/i2c-i801.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
> index 1f929e6c3..f3c79942c 100644
> --- a/drivers/i2c/busses/i2c-i801.c
> +++ b/drivers/i2c/busses/i2c-i801.c
> @@ -1623,7 +1623,7 @@ i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
>  		 * BIOS is accessing the host controller so prevent it from
>  		 * suspending automatically from now on.
>  		 */
> -		pm_runtime_set_autosuspend_delay(&pdev->dev, -1);
> +		pm_runtime_get_sync(&pdev->dev);
>  	}
>  
>  	if ((function & ACPI_IO_MASK) == ACPI_READ)
> @@ -1890,9 +1890,6 @@ static void i801_remove(struct pci_dev *dev)
>  {
>  	struct i801_priv *priv = pci_get_drvdata(dev);
>  
> -	pm_runtime_forbid(&dev->dev);
> -	pm_runtime_get_noresume(&dev->dev);
> -
>  	i801_disable_host_notify(priv);
>  	i801_del_mux(priv);
>  	i2c_del_adapter(&priv->adapter);
> @@ -1901,6 +1898,10 @@ static void i801_remove(struct pci_dev *dev)
>  
>  	platform_device_unregister(priv->tco_pdev);
>  
> +	/* if acpi_reserved is set then usage_count is incremented already */
> +	if (!priv->acpi_reserved)
> +		pm_runtime_get_noresume(&dev->dev);
> +
>  	/*
>  	 * do not call pci_disable_device(dev) since it can cause hard hangs on
>  	 * some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)

Thanks for following up. I'm not familiar with power management so I'll
trust you, Andy and Robert on that.

Reviewed-by: Jean Delvare <jdelvare@suse.de>

-- 
Jean Delvare
SUSE L3 Support

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

* Re: [PATCH RESEND] i2c: i801: Stop using pm_runtime_set_autosuspend_delay(-1)
  2021-09-07 20:33 [PATCH RESEND] i2c: i801: Stop using pm_runtime_set_autosuspend_delay(-1) Heiner Kallweit
  2021-09-15 12:09 ` Rafael J. Wysocki
  2021-09-16  8:09 ` Jean Delvare
@ 2021-09-29 20:13 ` Wolfram Sang
  2 siblings, 0 replies; 4+ messages in thread
From: Wolfram Sang @ 2021-09-29 20:13 UTC (permalink / raw)
  To: Heiner Kallweit; +Cc: Jean Delvare, linux-acpi, Andy Shevchenko, linux-i2c

[-- Attachment #1: Type: text/plain, Size: 1072 bytes --]

On Tue, Sep 07, 2021 at 10:33:02PM +0200, Heiner Kallweit wrote:
> The original change works as intended, but Andy pointed in [0] that now
> userspace could re-enable RPM via sysfs, even though we explicitly want
> to disable it. So effectively revert the original patch, just with small
> improvements:
> - Calls to pm_runtime_allow()/pm_runtime_forbid() don't have to be
>   balanced, so we can remove the call to pm_runtime_forbid() in
>   i801_remove().
> - priv->acpi_reserved is accessed after i801_acpi_remove(), and according
>   to Robert [1] the custom handler can't run any longer. Therefore we
>   don't have to take priv->acpi_lock.
> 
> [0] https://www.spinics.net/lists/linux-i2c/msg52730.html
> [1] https://lore.kernel.org/linux-acpi/BYAPR11MB32561D19A0FD9AB93E2B1E5287D39@BYAPR11MB3256.namprd11.prod.outlook.com/T/#t
> 
> Fixes: 4e60d5dd10cd ("i2c: i801: Improve disabling runtime pm")
> Reported-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>

Applied to for-next, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2021-09-29 20:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-07 20:33 [PATCH RESEND] i2c: i801: Stop using pm_runtime_set_autosuspend_delay(-1) Heiner Kallweit
2021-09-15 12:09 ` Rafael J. Wysocki
2021-09-16  8:09 ` Jean Delvare
2021-09-29 20:13 ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).