linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] PM: core: Add pm_wakeup_pending check in device suspend_noirq
@ 2022-09-16  2:15 cy_huang
  2022-09-21 18:13 ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: cy_huang @ 2022-09-16  2:15 UTC (permalink / raw)
  To: rafael, len.brown, pavel, gregkh, keescook, anton, ccross, tony.luck
  Cc: cy_huang, gene_chen, linux-pm, linux-kernel

From: ChiYuan Huang <cy_huang@richtek.com>

In 'dpm_suspend_noirq', it will do the sychronized_irq to guarantee all
irqs are all done, and then do any wakeup flag set.

For some peripherial deivces like as I2C/SPI, to speed up the irq handling,
it may use 'pm_stay_awake' and really handle in another thread context like
as workqueue.

But in mem suspend flow, after 'dpm_suspend_noirq" stage, the next
'pm_wakeup_pending' check will be at 'syscore_suspend'.

The checkpoint seems too late and cause I2C/SPI fail during 'noirq' to
'syscore_suspend'. But some adapter was already be marked as 'suspended'
at 'noirq' callback, any I2C/SPI xfer will return the error flag '-ESHUTDOWN'.

After the code trace, it seems all device callback will do 'pm_wakeup_pending'
check, except 'noirq'.

This patch is to add 'pm_wakeup_pending' check in 'noirq' sage to prevent this
kind of usage.

Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
---
Hi,

Is there any rule to define when I2C/SPI host controller need to mark adapter as
'suspended'?

I trace 'drivers/i2c/buses'.It seems there's no common rule, Some are 'suspend',
others may did it at 'suspend_noirq'.

---
 drivers/base/power/main.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index c501392..7cd7dc5 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1210,6 +1210,11 @@ static int __device_suspend_noirq(struct device *dev, pm_message_t state, bool a
 	if (async_error)
 		goto Complete;
 
+	if (pm_wakeup_pending()) {
+		async_error = -EBUSY;
+		goto Complete;
+	}
+
 	if (dev->power.syscore || dev->power.direct_complete)
 		goto Complete;
 
-- 
2.7.4


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

* Re: [RFC] PM: core: Add pm_wakeup_pending check in device suspend_noirq
  2022-09-16  2:15 [RFC] PM: core: Add pm_wakeup_pending check in device suspend_noirq cy_huang
@ 2022-09-21 18:13 ` Rafael J. Wysocki
  2022-09-22  0:34   ` ChiYuan Huang
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2022-09-21 18:13 UTC (permalink / raw)
  To: cy_huang
  Cc: Rafael J. Wysocki, Len Brown, Pavel Machek, Greg Kroah-Hartman,
	Kees Cook, Anton Vorontsov, Colin Cross, Tony Luck, cy_huang,
	gene_chen, Linux PM, Linux Kernel Mailing List

On Fri, Sep 16, 2022 at 4:15 AM cy_huang <u0084500@gmail.com> wrote:
>
> From: ChiYuan Huang <cy_huang@richtek.com>
>
> In 'dpm_suspend_noirq', it will do the sychronized_irq to guarantee all
> irqs are all done, and then do any wakeup flag set.
>
> For some peripherial deivces like as I2C/SPI, to speed up the irq handling,
> it may use 'pm_stay_awake' and really handle in another thread context like
> as workqueue.
>
> But in mem suspend flow, after 'dpm_suspend_noirq" stage, the next
> 'pm_wakeup_pending' check will be at 'syscore_suspend'.
>
> The checkpoint seems too late and cause I2C/SPI fail during 'noirq' to
> 'syscore_suspend'

What exactly do you mean by "fail" here?

>. But some adapter was already be marked as 'suspended'
> at 'noirq' callback, any I2C/SPI xfer will return the error flag '-ESHUTDOWN'.
>
> After the code trace, it seems all device callback will do 'pm_wakeup_pending'
> check, except 'noirq'.
>
> This patch is to add 'pm_wakeup_pending' check in 'noirq' sage to prevent this
> kind of usage.
>
> Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
> ---
> Hi,
>
> Is there any rule to define when I2C/SPI host controller need to mark adapter as
> 'suspended'?
>
> I trace 'drivers/i2c/buses'.It seems there's no common rule, Some are 'suspend',
> others may did it at 'suspend_noirq'.
>
> ---
>  drivers/base/power/main.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> index c501392..7cd7dc5 100644
> --- a/drivers/base/power/main.c
> +++ b/drivers/base/power/main.c
> @@ -1210,6 +1210,11 @@ static int __device_suspend_noirq(struct device *dev, pm_message_t state, bool a
>         if (async_error)
>                 goto Complete;
>
> +       if (pm_wakeup_pending()) {
> +               async_error = -EBUSY;
> +               goto Complete;
> +       }
> +
>         if (dev->power.syscore || dev->power.direct_complete)
>                 goto Complete;
>
> --
> 2.7.4
>

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

* Re: [RFC] PM: core: Add pm_wakeup_pending check in device suspend_noirq
  2022-09-21 18:13 ` Rafael J. Wysocki
@ 2022-09-22  0:34   ` ChiYuan Huang
  0 siblings, 0 replies; 3+ messages in thread
From: ChiYuan Huang @ 2022-09-22  0:34 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Len Brown, Pavel Machek, Greg Kroah-Hartman, Kees Cook,
	Anton Vorontsov, Colin Cross, Tony Luck, cy_huang, gene_chen,
	Linux PM, Linux Kernel Mailing List

Rafael J. Wysocki <rafael@kernel.org> 於 2022年9月22日 週四 凌晨2:13寫道:
>
> On Fri, Sep 16, 2022 at 4:15 AM cy_huang <u0084500@gmail.com> wrote:
> >
> > From: ChiYuan Huang <cy_huang@richtek.com>
> >
> > In 'dpm_suspend_noirq', it will do the sychronized_irq to guarantee all
> > irqs are all done, and then do any wakeup flag set.
> >
> > For some peripherial deivces like as I2C/SPI, to speed up the irq handling,
> > it may use 'pm_stay_awake' and really handle in another thread context like
> > as workqueue.
> >
> > But in mem suspend flow, after 'dpm_suspend_noirq" stage, the next
> > 'pm_wakeup_pending' check will be at 'syscore_suspend'.
> >
> > The checkpoint seems too late and cause I2C/SPI fail during 'noirq' to
> > 'syscore_suspend'
>
> What exactly do you mean by "fail" here?
For the below case
Once the adapter is marked as 'Suspend', any i2c_xfer or spi_xfer will
directly return 'ESHUTDOWN".
There's no real I/O transferred, only the direct returned error code.

>
> >. But some adapter was already be marked as 'suspended'
> > at 'noirq' callback, any I2C/SPI xfer will return the error flag '-ESHUTDOWN'.
> >
> > After the code trace, it seems all device callback will do 'pm_wakeup_pending'
> > check, except 'noirq'.
> >
> > This patch is to add 'pm_wakeup_pending' check in 'noirq' sage to prevent this
> > kind of usage.
> >
> > Signed-off-by: ChiYuan Huang <cy_huang@richtek.com>
> > ---
> > Hi,
> >
> > Is there any rule to define when I2C/SPI host controller need to mark adapter as
> > 'suspended'?
> >
> > I trace 'drivers/i2c/buses'.It seems there's no common rule, Some are 'suspend',
> > others may did it at 'suspend_noirq'.
> >
> > ---
> >  drivers/base/power/main.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
> > index c501392..7cd7dc5 100644
> > --- a/drivers/base/power/main.c
> > +++ b/drivers/base/power/main.c
> > @@ -1210,6 +1210,11 @@ static int __device_suspend_noirq(struct device *dev, pm_message_t state, bool a
> >         if (async_error)
> >                 goto Complete;
> >
> > +       if (pm_wakeup_pending()) {
> > +               async_error = -EBUSY;
> > +               goto Complete;
> > +       }
> > +
> >         if (dev->power.syscore || dev->power.direct_complete)
> >                 goto Complete;
> >
> > --
> > 2.7.4
> >

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

end of thread, other threads:[~2022-09-22  0:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-16  2:15 [RFC] PM: core: Add pm_wakeup_pending check in device suspend_noirq cy_huang
2022-09-21 18:13 ` Rafael J. Wysocki
2022-09-22  0:34   ` ChiYuan Huang

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).