All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/3] timer: patchset focus on del_timer_sync()
@ 2010-08-24  6:58 Yong Zhang
  2010-08-24  6:58 ` [RFC PATCH 1/3] timer: fix comments of try_to_del_timer_sync() Yong Zhang
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Yong Zhang @ 2010-08-24  6:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: tglx, akpm, mingo, peterz, oleg

From: Yong Zhang <yong.zhang@windriver.com>

This is inspired by http://lkml.org/lkml/2010/8/16/291
which catch a lockdep false positive on fake_timer_lock.
When I go into del_timer_sync(), but don't find anything
which prevent del_timer_sync() from using in softirq context,
and indeed it's been used in softirq for some timer(such as
__dst_free()).

Thus, tell others it can't be used in softirq context, and
teach lockdep about that. It's realized by patch-0002.

Your comments are very appreciated.

Thanks,
Yong

---
Yong Zhang (3):
      timer: fix comments of try_to_del_timer_sync()
      timer: del_timer_sync() can be used in softirq context
      timer: warn when del_timer_sync() used in hardirq context

 kernel/timer.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)


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

* [RFC PATCH 1/3] timer: fix comments of try_to_del_timer_sync()
  2010-08-24  6:58 [RFC PATCH 0/3] timer: patchset focus on del_timer_sync() Yong Zhang
@ 2010-08-24  6:58 ` Yong Zhang
  2010-08-24 12:11   ` Oleg Nesterov
  2010-08-24  6:58 ` [RFC PATCH 2/3] timer: del_timer_sync() can be used in softirq context Yong Zhang
  2010-08-24  6:58 ` [RFC PATCH 3/3] timer: warn when del_timer_sync() used in hardirq context Yong Zhang
  2 siblings, 1 reply; 8+ messages in thread
From: Yong Zhang @ 2010-08-24  6:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: tglx, akpm, mingo, peterz, oleg

From: Yong Zhang <yong.zhang@windriver.com>

In commit fd450b7318b75343fd76b3d95416853e34e72c95, it was saying
try_to_del_timer_sync() can be used in interrupt context. So make
the comments consistent to what it should be.

Signed-off-by: Yong Zhang <yong.zhang0@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Oleg Nesterov <oleg@redhat.com>
---
 kernel/timer.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/kernel/timer.c b/kernel/timer.c
index 97bf05b..55b6a2d 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -943,8 +943,6 @@ EXPORT_SYMBOL(del_timer);
  *
  * This function tries to deactivate a timer. Upon successful (ret >= 0)
  * exit the timer is not queued and the handler is not running on any CPU.
- *
- * It must not be called from interrupt contexts.
  */
 int try_to_del_timer_sync(struct timer_list *timer)
 {
-- 
1.7.0.4


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

* [RFC PATCH 2/3] timer: del_timer_sync() can be used in softirq context
  2010-08-24  6:58 [RFC PATCH 0/3] timer: patchset focus on del_timer_sync() Yong Zhang
  2010-08-24  6:58 ` [RFC PATCH 1/3] timer: fix comments of try_to_del_timer_sync() Yong Zhang
@ 2010-08-24  6:58 ` Yong Zhang
  2010-08-24  6:58 ` [RFC PATCH 3/3] timer: warn when del_timer_sync() used in hardirq context Yong Zhang
  2 siblings, 0 replies; 8+ messages in thread
From: Yong Zhang @ 2010-08-24  6:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: tglx, akpm, mingo, peterz, oleg

From: Yong Zhang <yong.zhang@windriver.com>

Actually we have used del_timer_sync() in softirq context for a long
time, such as: __dst_free()::cancel_delayed_work() and maybe the
DEBUG_OBJECTS_TIMERS fundamental code.

So change the comments of it to warn on hardirq context only,
and make lockdep know about this change.

Signed-off-by: Yong Zhang <yong.zhang0@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <peterz@infradead.org>
---
 kernel/timer.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/kernel/timer.c b/kernel/timer.c
index 55b6a2d..08c9559 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -981,7 +981,7 @@ EXPORT_SYMBOL(try_to_del_timer_sync);
  *
  * Synchronization rules: Callers must prevent restarting of the timer,
  * otherwise this function is meaningless. It must not be called from
- * interrupt contexts. The caller must not hold locks which would prevent
+ * hardirq contexts. The caller must not hold locks which would prevent
  * completion of the timer's handler. The timer's handler must not call
  * add_timer_on(). Upon exit the timer is not queued and the handler is
  * not running on any CPU.
@@ -991,12 +991,10 @@ EXPORT_SYMBOL(try_to_del_timer_sync);
 int del_timer_sync(struct timer_list *timer)
 {
 #ifdef CONFIG_LOCKDEP
-	unsigned long flags;
-
-	local_irq_save(flags);
+	local_bh_disable();
 	lock_map_acquire(&timer->lockdep_map);
 	lock_map_release(&timer->lockdep_map);
-	local_irq_restore(flags);
+	local_bh_enable();
 #endif
 
 	for (;;) {
-- 
1.7.0.4


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

* [RFC PATCH 3/3] timer: warn when del_timer_sync() used in hardirq context
  2010-08-24  6:58 [RFC PATCH 0/3] timer: patchset focus on del_timer_sync() Yong Zhang
  2010-08-24  6:58 ` [RFC PATCH 1/3] timer: fix comments of try_to_del_timer_sync() Yong Zhang
  2010-08-24  6:58 ` [RFC PATCH 2/3] timer: del_timer_sync() can be used in softirq context Yong Zhang
@ 2010-08-24  6:58 ` Yong Zhang
  2 siblings, 0 replies; 8+ messages in thread
From: Yong Zhang @ 2010-08-24  6:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: tglx, akpm, mingo, peterz, oleg

From: Yong Zhang <yong.zhang@windriver.com>

Add explict warning to prevent del_timer_sync() from using
in hardirq context.

Signed-off-by: Yong Zhang <yong.zhang0@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>
---
 kernel/timer.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/kernel/timer.c b/kernel/timer.c
index 08c9559..1bc4b4a 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -996,7 +996,11 @@ int del_timer_sync(struct timer_list *timer)
 	lock_map_release(&timer->lockdep_map);
 	local_bh_enable();
 #endif
-
+	/*
+	 * don't use it in hardirq context, because it
+	 * could lead to deadlock.
+	 */
+	WARN_ON(in_irq());
 	for (;;) {
 		int ret = try_to_del_timer_sync(timer);
 		if (ret >= 0)
-- 
1.7.0.4


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

* Re: [RFC PATCH 1/3] timer: fix comments of try_to_del_timer_sync()
  2010-08-24  6:58 ` [RFC PATCH 1/3] timer: fix comments of try_to_del_timer_sync() Yong Zhang
@ 2010-08-24 12:11   ` Oleg Nesterov
  2010-08-24 12:49     ` Yong Zhang
  0 siblings, 1 reply; 8+ messages in thread
From: Oleg Nesterov @ 2010-08-24 12:11 UTC (permalink / raw)
  To: Yong Zhang; +Cc: linux-kernel, tglx, akpm, mingo, peterz

On 08/24, Yong Zhang wrote:
>
> From: Yong Zhang <yong.zhang@windriver.com>
>
> In commit fd450b7318b75343fd76b3d95416853e34e72c95, it was saying
> try_to_del_timer_sync() can be used in interrupt context.

Yes, but not in UP case.

Please remove "#ifdef CONFIG_SMP" from set_running_timer(), then iirc
it can be used from irq.

Oleg.


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

* Re: [RFC PATCH 1/3] timer: fix comments of try_to_del_timer_sync()
  2010-08-24 12:11   ` Oleg Nesterov
@ 2010-08-24 12:49     ` Yong Zhang
  2010-08-24 16:31       ` Oleg Nesterov
  0 siblings, 1 reply; 8+ messages in thread
From: Yong Zhang @ 2010-08-24 12:49 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: linux-kernel, tglx, akpm, mingo, peterz

On Tue, Aug 24, 2010 at 02:11:09PM +0200, Oleg Nesterov wrote:
> On 08/24, Yong Zhang wrote:
> >
> > From: Yong Zhang <yong.zhang@windriver.com>
> >
> > In commit fd450b7318b75343fd76b3d95416853e34e72c95, it was saying
> > try_to_del_timer_sync() can be used in interrupt context.
> 
> Yes, but not in UP case.

Yeah, but in UP case there is no try_to_del_timer_sync(), it's redefined
to del_timer().

> 
> Please remove "#ifdef CONFIG_SMP" from set_running_timer(), then iirc
> it can be used from irq.

I have noticed your comments in the commit log, but I think it's about
introducing the same semantic of try_to_del_timer_sync() on UP as well
as SMP. But this patch is focusing on the current code(SMP special).
Not about realizing try_to_del_timer_sync() on UP case. Do we need
to do that?

Thanks,
Yong

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

* Re: [RFC PATCH 1/3] timer: fix comments of try_to_del_timer_sync()
  2010-08-24 12:49     ` Yong Zhang
@ 2010-08-24 16:31       ` Oleg Nesterov
  2010-08-25  1:56         ` Yong Zhang
  0 siblings, 1 reply; 8+ messages in thread
From: Oleg Nesterov @ 2010-08-24 16:31 UTC (permalink / raw)
  To: Yong Zhang; +Cc: linux-kernel, tglx, akpm, mingo, peterz

On 08/24, Yong Zhang wrote:
>
> On Tue, Aug 24, 2010 at 02:11:09PM +0200, Oleg Nesterov wrote:
> > On 08/24, Yong Zhang wrote:
> > >
> > > From: Yong Zhang <yong.zhang@windriver.com>
> > >
> > > In commit fd450b7318b75343fd76b3d95416853e34e72c95, it was saying
> > > try_to_del_timer_sync() can be used in interrupt context.
> >
> > Yes, but not in UP case.
>
> Yeah, but in UP case there is no try_to_del_timer_sync(), it's redefined
> to del_timer().

Ah, indeed, I forgot. This was another reason for the comment.

> > Please remove "#ifdef CONFIG_SMP" from set_running_timer(), then iirc
> > it can be used from irq.
>
> I have noticed your comments in the commit log, but I think it's about
> introducing the same semantic of try_to_del_timer_sync() on UP as well
> as SMP. But this patch is focusing on the current code(SMP special).
> Not about realizing try_to_del_timer_sync() on UP case. Do we need
> to do that?

I dunno.

But look, currently try_to_del_timer_sync() is not allowed from interrupt
even if it works with CONFIG_SMP.

If we "officially" allow it to use from irq, it should work on UP too but
it doesn't. del_timer() can't hang, but it can never return -1 to indicate
we hit the running timer.

Consider:

	// runs in interrup context

	if (try_do_del_timer_sync(&TIMER) > 0)
		kfree(something_which_can_be_used_by_TIMER_func);		

This is unsafe on UP.


del_timer_sync == del_timer is fine on UP. Since it must not be called
from irq, it can never hit the running timer.

Oleg.


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

* Re: [RFC PATCH 1/3] timer: fix comments of try_to_del_timer_sync()
  2010-08-24 16:31       ` Oleg Nesterov
@ 2010-08-25  1:56         ` Yong Zhang
  0 siblings, 0 replies; 8+ messages in thread
From: Yong Zhang @ 2010-08-25  1:56 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: linux-kernel, tglx, akpm, mingo, peterz

On Wed, Aug 25, 2010 at 12:31 AM, Oleg Nesterov <oleg@redhat.com> wrote:
> Ah, indeed, I forgot. This was another reason for the comment.
>
>> > Please remove "#ifdef CONFIG_SMP" from set_running_timer(), then iirc
>> > it can be used from irq.
>>
>> I have noticed your comments in the commit log, but I think it's about
>> introducing the same semantic of try_to_del_timer_sync() on UP as well
>> as SMP. But this patch is focusing on the current code(SMP special).
>> Not about realizing try_to_del_timer_sync() on UP case. Do we need
>> to do that?
>
> I dunno.
>
> But look, currently try_to_del_timer_sync() is not allowed from interrupt
> even if it works with CONFIG_SMP.
>
> If we "officially" allow it to use from irq, it should work on UP too

OK. I see.

> but
> it doesn't. del_timer() can't hang, but it can never return -1 to indicate
> we hit the running timer.
>
> Consider:
>
>        // runs in interrup context
>
>        if (try_do_del_timer_sync(&TIMER) > 0)
>                kfree(something_which_can_be_used_by_TIMER_func);
>
> This is unsafe on UP.

You are right. It's unsafe here.

I will try to update this patch which introduce try_do_del_timer_sync()
on UP case.

Thanks,
Yong

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

end of thread, other threads:[~2010-08-25  1:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-24  6:58 [RFC PATCH 0/3] timer: patchset focus on del_timer_sync() Yong Zhang
2010-08-24  6:58 ` [RFC PATCH 1/3] timer: fix comments of try_to_del_timer_sync() Yong Zhang
2010-08-24 12:11   ` Oleg Nesterov
2010-08-24 12:49     ` Yong Zhang
2010-08-24 16:31       ` Oleg Nesterov
2010-08-25  1:56         ` Yong Zhang
2010-08-24  6:58 ` [RFC PATCH 2/3] timer: del_timer_sync() can be used in softirq context Yong Zhang
2010-08-24  6:58 ` [RFC PATCH 3/3] timer: warn when del_timer_sync() used in hardirq context Yong Zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.