[1/2] PM / wakeup: Remove timer from wakeup_source_remove()

Message ID 621452804d6d22f72438614b6687f37282d883f5.1552038717.git.viresh.kumar@linaro.org
State New
Headers show
Series
  • [1/2] PM / wakeup: Remove timer from wakeup_source_remove()
Related show

Commit Message

Viresh Kumar March 8, 2019, 9:53 a.m.
wakeup_source_remove() is the counterpart of wakeup_source_add() helper
and must undo the initializations done by wakeup_source_add(). Currently
the timer is initialized by wakeup_source_add() but removed from
wakeup_source_drop(), which doesn't look logically correct. Also it
should be okay to call wakeup_source_add() right after calling
wakeup_source_remove(), and in that case we may end up calling
timer_setup() for a potentially scheduled timer which is surely
incorrect.

Move the timer removal part to wakeup_source_remove() instead.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

---
 drivers/base/power/wakeup.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

-- 
2.21.0.rc0.269.g1a574e7a288b

Comments

Rafael J. Wysocki March 11, 2019, 12:05 p.m. | #1
On Friday, March 8, 2019 10:53:11 AM CET Viresh Kumar wrote:
> wakeup_source_remove() is the counterpart of wakeup_source_add() helper

> and must undo the initializations done by wakeup_source_add(). Currently

> the timer is initialized by wakeup_source_add() but removed from

> wakeup_source_drop(), which doesn't look logically correct. Also it

> should be okay to call wakeup_source_add() right after calling

> wakeup_source_remove(), and in that case we may end up calling

> timer_setup() for a potentially scheduled timer which is surely

> incorrect.

> 

> Move the timer removal part to wakeup_source_remove() instead.

> 

> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> ---

>  drivers/base/power/wakeup.c | 3 ++-

>  1 file changed, 2 insertions(+), 1 deletion(-)

> 

> diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c

> index f1fee72ed970..18333962e3da 100644

> --- a/drivers/base/power/wakeup.c

> +++ b/drivers/base/power/wakeup.c

> @@ -118,7 +118,6 @@ void wakeup_source_drop(struct wakeup_source *ws)

>  	if (!ws)

>  		return;

>  

> -	del_timer_sync(&ws->timer);

>  	__pm_relax(ws);

>  }

>  EXPORT_SYMBOL_GPL(wakeup_source_drop);

> @@ -205,6 +204,8 @@ void wakeup_source_remove(struct wakeup_source *ws)

>  	list_del_rcu(&ws->entry);

>  	raw_spin_unlock_irqrestore(&events_lock, flags);

>  	synchronize_srcu(&wakeup_srcu);

> +

> +	del_timer_sync(&ws->timer);

>  }

>  EXPORT_SYMBOL_GPL(wakeup_source_remove);

>  

> 


I've merged it with the [2/2], rewritten the subject and changelog and
queued the result as commit d856f39ac1cc ("PM / wakeup: Rework wakeup
source timer cancellation").
Viresh Kumar March 12, 2019, 3:28 a.m. | #2
On 11-03-19, 13:05, Rafael J. Wysocki wrote:
> On Friday, March 8, 2019 10:53:11 AM CET Viresh Kumar wrote:

> > wakeup_source_remove() is the counterpart of wakeup_source_add() helper

> > and must undo the initializations done by wakeup_source_add(). Currently

> > the timer is initialized by wakeup_source_add() but removed from

> > wakeup_source_drop(), which doesn't look logically correct. Also it

> > should be okay to call wakeup_source_add() right after calling

> > wakeup_source_remove(), and in that case we may end up calling

> > timer_setup() for a potentially scheduled timer which is surely

> > incorrect.

> > 

> > Move the timer removal part to wakeup_source_remove() instead.

> > 

> > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> > ---

> >  drivers/base/power/wakeup.c | 3 ++-

> >  1 file changed, 2 insertions(+), 1 deletion(-)

> > 

> > diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c

> > index f1fee72ed970..18333962e3da 100644

> > --- a/drivers/base/power/wakeup.c

> > +++ b/drivers/base/power/wakeup.c

> > @@ -118,7 +118,6 @@ void wakeup_source_drop(struct wakeup_source *ws)

> >  	if (!ws)

> >  		return;

> >  

> > -	del_timer_sync(&ws->timer);

> >  	__pm_relax(ws);

> >  }

> >  EXPORT_SYMBOL_GPL(wakeup_source_drop);

> > @@ -205,6 +204,8 @@ void wakeup_source_remove(struct wakeup_source *ws)

> >  	list_del_rcu(&ws->entry);

> >  	raw_spin_unlock_irqrestore(&events_lock, flags);

> >  	synchronize_srcu(&wakeup_srcu);

> > +

> > +	del_timer_sync(&ws->timer);

> >  }

> >  EXPORT_SYMBOL_GPL(wakeup_source_remove);

> >  

> > 

> 

> I've merged it with the [2/2], rewritten the subject and changelog and

> queued the result as commit d856f39ac1cc ("PM / wakeup: Rework wakeup

> source timer cancellation").


Okay, thanks. We (Android guys) want this to be backported into 4.4+
kernels via the stable tree. Can we mark this for stable in the commit
itself ? Else I would be required to send this separately for all the
kernels. I should have marked it for stable initially though, sorry
about forgetting then.

-- 
viresh
Rafael J. Wysocki March 12, 2019, 9:03 a.m. | #3
On Tue, Mar 12, 2019 at 4:28 AM Viresh Kumar <viresh.kumar@linaro.org> wrote:
>

> On 11-03-19, 13:05, Rafael J. Wysocki wrote:

> > On Friday, March 8, 2019 10:53:11 AM CET Viresh Kumar wrote:

> > > wakeup_source_remove() is the counterpart of wakeup_source_add() helper

> > > and must undo the initializations done by wakeup_source_add(). Currently

> > > the timer is initialized by wakeup_source_add() but removed from

> > > wakeup_source_drop(), which doesn't look logically correct. Also it

> > > should be okay to call wakeup_source_add() right after calling

> > > wakeup_source_remove(), and in that case we may end up calling

> > > timer_setup() for a potentially scheduled timer which is surely

> > > incorrect.

> > >

> > > Move the timer removal part to wakeup_source_remove() instead.

> > >

> > > Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>

> > > ---

> > >  drivers/base/power/wakeup.c | 3 ++-

> > >  1 file changed, 2 insertions(+), 1 deletion(-)

> > >

> > > diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c

> > > index f1fee72ed970..18333962e3da 100644

> > > --- a/drivers/base/power/wakeup.c

> > > +++ b/drivers/base/power/wakeup.c

> > > @@ -118,7 +118,6 @@ void wakeup_source_drop(struct wakeup_source *ws)

> > >     if (!ws)

> > >             return;

> > >

> > > -   del_timer_sync(&ws->timer);

> > >     __pm_relax(ws);

> > >  }

> > >  EXPORT_SYMBOL_GPL(wakeup_source_drop);

> > > @@ -205,6 +204,8 @@ void wakeup_source_remove(struct wakeup_source *ws)

> > >     list_del_rcu(&ws->entry);

> > >     raw_spin_unlock_irqrestore(&events_lock, flags);

> > >     synchronize_srcu(&wakeup_srcu);

> > > +

> > > +   del_timer_sync(&ws->timer);

> > >  }

> > >  EXPORT_SYMBOL_GPL(wakeup_source_remove);

> > >

> > >

> >

> > I've merged it with the [2/2], rewritten the subject and changelog and

> > queued the result as commit d856f39ac1cc ("PM / wakeup: Rework wakeup

> > source timer cancellation").

>

> Okay, thanks. We (Android guys) want this to be backported into 4.4+

> kernels via the stable tree. Can we mark this for stable in the commit

> itself ? Else I would be required to send this separately for all the

> kernels. I should have marked it for stable initially though, sorry

> about forgetting then.


Queued up with a CC-stable tag for 4.4 an later, thanks!
Pavel Machek March 12, 2019, 9:04 a.m. | #4
On Tue 2019-03-12 08:58:02, Viresh Kumar wrote:
> On 11-03-19, 13:05, Rafael J. Wysocki wrote:

> > On Friday, March 8, 2019 10:53:11 AM CET Viresh Kumar wrote:

> > > wakeup_source_remove() is the counterpart of wakeup_source_add() helper

> > > and must undo the initializations done by wakeup_source_add(). Currently

> > > the timer is initialized by wakeup_source_add() but removed from

> > > wakeup_source_drop(), which doesn't look logically correct. Also it

> > > should be okay to call wakeup_source_add() right after calling

> > > wakeup_source_remove(), and in that case we may end up calling

> > > timer_setup() for a potentially scheduled timer which is surely

> > > incorrect.

> > > 

> > > Move the timer removal part to wakeup_source_remove() instead.


> > 

> > I've merged it with the [2/2], rewritten the subject and changelog and

> > queued the result as commit d856f39ac1cc ("PM / wakeup: Rework wakeup

> > source timer cancellation").

> 

> Okay, thanks. We (Android guys) want this to be backported into 4.4+

> kernels via the stable tree. Can we mark this for stable in the commit

> itself ? Else I would be required to send this separately for all the

> kernels. I should have marked it for stable initially though, sorry

> about forgetting then.


Greg is normally pretty agressive about backporting everything
remotely looking like a fix...

But better changelog would help. How is the bug actually affecting
users?

Best regards,
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Viresh Kumar March 12, 2019, 11:41 a.m. | #5
On 12-03-19, 10:04, Pavel Machek wrote:
> On Tue 2019-03-12 08:58:02, Viresh Kumar wrote:

> > On 11-03-19, 13:05, Rafael J. Wysocki wrote:

> > > On Friday, March 8, 2019 10:53:11 AM CET Viresh Kumar wrote:

> > > > wakeup_source_remove() is the counterpart of wakeup_source_add() helper

> > > > and must undo the initializations done by wakeup_source_add(). Currently

> > > > the timer is initialized by wakeup_source_add() but removed from

> > > > wakeup_source_drop(), which doesn't look logically correct. Also it

> > > > should be okay to call wakeup_source_add() right after calling

> > > > wakeup_source_remove(), and in that case we may end up calling

> > > > timer_setup() for a potentially scheduled timer which is surely

> > > > incorrect.

> > > > 

> > > > Move the timer removal part to wakeup_source_remove() instead.

> 

> > > 

> > > I've merged it with the [2/2], rewritten the subject and changelog and

> > > queued the result as commit d856f39ac1cc ("PM / wakeup: Rework wakeup

> > > source timer cancellation").

> > 

> > Okay, thanks. We (Android guys) want this to be backported into 4.4+

> > kernels via the stable tree. Can we mark this for stable in the commit

> > itself ? Else I would be required to send this separately for all the

> > kernels. I should have marked it for stable initially though, sorry

> > about forgetting then.

> 

> Greg is normally pretty agressive about backporting everything

> remotely looking like a fix...

> 

> But better changelog would help. How is the bug actually affecting

> users?


The Android wakelock infrastructure (not in mainline) is based on the
wakeup sources stuff and that is where we found the issue. A wakelock
was taken due to a bug in user driver and the board never attempts
going into suspend anymore.

If this patch doesn't go into the stable kernels, I would be required
to send this separately for Android kernels and the Android guys will
suggest getting it via stable tree.

And because this fixes a potential issue it was worth trying getting
it via the stable kernel :)

-- 
viresh

Patch

diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index f1fee72ed970..18333962e3da 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -118,7 +118,6 @@  void wakeup_source_drop(struct wakeup_source *ws)
 	if (!ws)
 		return;
 
-	del_timer_sync(&ws->timer);
 	__pm_relax(ws);
 }
 EXPORT_SYMBOL_GPL(wakeup_source_drop);
@@ -205,6 +204,8 @@  void wakeup_source_remove(struct wakeup_source *ws)
 	list_del_rcu(&ws->entry);
 	raw_spin_unlock_irqrestore(&events_lock, flags);
 	synchronize_srcu(&wakeup_srcu);
+
+	del_timer_sync(&ws->timer);
 }
 EXPORT_SYMBOL_GPL(wakeup_source_remove);