From: Steven Rostedt <rostedt@goodmis.org>
To: Guenter Roeck <linux@roeck-us.net>
Cc: linux-kernel@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Stephen Boyd <sboyd@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Felipe Balbi <balbi@kernel.org>, Johan Hovold <johan@kernel.org>,
Alan Stern <stern@rowland.harvard.edu>,
Mathias Nyman <mathias.nyman@linux.intel.com>,
Kai-Heng Feng <kai.heng.feng@canonical.com>,
Matthias Kaehlcke <mka@chromium.org>,
Michael Grzeschik <m.grzeschik@pengutronix.de>,
Bhuvanesh Surachari <Bhuvanesh_Surachari@mentor.com>,
Dan Carpenter <dan.carpenter@oracle.com>,
linux-usb@vger.kernel.org, Tejun Heo <tj@kernel.org>,
Lai Jiangshan <jiangshanlai@gmail.com>,
John Stultz <jstultz@google.com>
Subject: Re: [RFC][PATCH v2 20/31] timers: usb: Use del_timer_shutdown() before freeing timer
Date: Fri, 28 Oct 2022 14:10:07 -0400 [thread overview]
Message-ID: <20221028141007.05f5c490@gandalf.local.home> (raw)
In-Reply-To: <20221028140129.040d9acc@gandalf.local.home>
On Fri, 28 Oct 2022 14:01:29 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:
> @@ -813,6 +839,14 @@ void destroy_timer_on_stack(struct timer_list *timer)
> }
> EXPORT_SYMBOL_GPL(destroy_timer_on_stack);
>
> +static struct timer_base *lock_timer_base(struct timer_list *timer,
> + unsigned long *flags);
> +
> +void __timer_reinit_debug_objects(struct timer_list *timer)
> +{
> + return;
> +}
> +
> #else
> static inline void debug_timer_init(struct timer_list *timer) { }
> static inline void debug_timer_activate(struct timer_list *timer) { }
Bah, the above chunk was leftover from some debugging.
Updated patch:
-- Steve
include/linux/timer.h | 38 +++++++++++++++++++++++++++++++++--
include/linux/workqueue.h | 4 ++--
kernel/time/timer.c | 42 +++++++++++++++++++++++++++++++++------
kernel/workqueue.c | 12 +++++++++++
4 files changed, 86 insertions(+), 10 deletions(-)
diff --git a/include/linux/timer.h b/include/linux/timer.h
index 45392b0ac2e1..27e3a8676ff8 100644
--- a/include/linux/timer.h
+++ b/include/linux/timer.h
@@ -8,6 +8,12 @@
#include <linux/debugobjects.h>
#include <linux/stringify.h>
+enum timer_debug_state {
+ TIMER_DEBUG_DISABLED,
+ TIMER_DEBUG_ENABLED,
+ TIMER_DEBUG_WORK,
+};
+
struct timer_list {
/*
* All fields that change during normal runtime grouped to the
@@ -18,6 +24,9 @@ struct timer_list {
void (*function)(struct timer_list *);
u32 flags;
+#ifdef CONFIG_DEBUG_OBJECTS_TIMERS
+ enum timer_debug_state enabled;
+#endif
#ifdef CONFIG_LOCKDEP
struct lockdep_map lockdep_map;
#endif
@@ -128,6 +137,31 @@ static inline void init_timer_on_stack_key(struct timer_list *timer,
init_timer_on_stack_key((_timer), (_fn), (_flags), NULL, NULL)
#endif
+#ifdef CONFIG_DEBUG_OBJECTS_TIMERS
+#define __init_timer_debug(_timer, _fn, _flags) \
+ do { \
+ (_timer)->enabled = TIMER_DEBUG_DISABLED; \
+ __init_timer((_timer), (_fn), (_flags)); \
+ } while (0)
+#define __init_timer_work(_timer, _fn, _flags) \
+ do { \
+ (_timer)->enabled = TIMER_DEBUG_WORK; \
+ __init_timer((_timer), (_fn), (_flags)); \
+ } while (0)
+#define __init_timer_work_on_stack(_timer, _fn, _flags) \
+ do { \
+ (_timer)->enabled = TIMER_DEBUG_WORK; \
+ __init_timer_on_stack((_timer), (_fn), (_flags)); \
+ } while (0)
+#else
+#define __init_timer_debug(_timer, _fn, _flags) \
+ __init_timer((_timer), (_fn), (_flags))
+#define __init_timer_work(_timer, _fn, _flags) \
+ __init_timer((_timer), (_fn), (_flags))
+#define __init_timer_work_on_stack(_timer, _fn, _flags) \
+ __init_timer_on_stack((_timer), (_fn), (_flags))
+#endif
+
/**
* timer_setup - prepare a timer for first use
* @timer: the timer in question
@@ -139,7 +173,7 @@ static inline void init_timer_on_stack_key(struct timer_list *timer,
* be used and must be balanced with a call to destroy_timer_on_stack().
*/
#define timer_setup(timer, callback, flags) \
- __init_timer((timer), (callback), (flags))
+ __init_timer_debug((timer), (callback), (flags))
#define timer_setup_on_stack(timer, callback, flags) \
__init_timer_on_stack((timer), (callback), (flags))
@@ -243,7 +277,7 @@ static inline int del_timer_shutdown(struct timer_list *timer)
return __del_timer_sync(timer, true);
}
-#define del_singleshot_timer_sync(t) del_timer_sync(t)
+#define del_singleshot_timer_sync(t) del_timer_shutdown(t)
extern void init_timers(void);
struct hrtimer;
diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index a0143dd24430..290c96429ce1 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -250,7 +250,7 @@ static inline unsigned int work_static(struct work_struct *work) { return 0; }
#define __INIT_DELAYED_WORK(_work, _func, _tflags) \
do { \
INIT_WORK(&(_work)->work, (_func)); \
- __init_timer(&(_work)->timer, \
+ __init_timer_work(&(_work)->timer, \
delayed_work_timer_fn, \
(_tflags) | TIMER_IRQSAFE); \
} while (0)
@@ -258,7 +258,7 @@ static inline unsigned int work_static(struct work_struct *work) { return 0; }
#define __INIT_DELAYED_WORK_ONSTACK(_work, _func, _tflags) \
do { \
INIT_WORK_ONSTACK(&(_work)->work, (_func)); \
- __init_timer_on_stack(&(_work)->timer, \
+ __init_timer_work_on_stack(&(_work)->timer, \
delayed_work_timer_fn, \
(_tflags) | TIMER_IRQSAFE); \
} while (0)
diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 5179ac2335a0..ac2e8beb4235 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -691,7 +691,11 @@ static bool timer_fixup_init(void *addr, enum debug_obj_state state)
switch (state) {
case ODEBUG_STATE_ACTIVE:
- del_timer_sync(timer);
+ if (timer->enabled != TIMER_DEBUG_WORK)
+ timer->enabled = TIMER_DEBUG_ENABLED;
+ del_timer_shutdown(timer);
+ if (timer->enabled != TIMER_DEBUG_WORK)
+ timer->enabled = TIMER_DEBUG_DISABLED;
debug_object_init(timer, &timer_debug_descr);
return true;
default:
@@ -737,8 +741,10 @@ static bool timer_fixup_free(void *addr, enum debug_obj_state state)
switch (state) {
case ODEBUG_STATE_ACTIVE:
- del_timer_sync(timer);
+ del_timer_shutdown(timer);
debug_object_free(timer, &timer_debug_descr);
+ if (timer->enabled != TIMER_DEBUG_WORK)
+ timer->enabled = TIMER_DEBUG_DISABLED;
return true;
default:
return false;
@@ -774,16 +780,36 @@ static const struct debug_obj_descr timer_debug_descr = {
static inline void debug_timer_init(struct timer_list *timer)
{
+ if (timer->enabled == TIMER_DEBUG_ENABLED)
+ return;
+
debug_object_init(timer, &timer_debug_descr);
}
static inline void debug_timer_activate(struct timer_list *timer)
{
+ if (timer->enabled == TIMER_DEBUG_ENABLED)
+ return;
+
+ if (timer->enabled == TIMER_DEBUG_DISABLED)
+ timer->enabled = TIMER_DEBUG_ENABLED;
+
debug_object_activate(timer, &timer_debug_descr);
}
-static inline void debug_timer_deactivate(struct timer_list *timer)
+static inline void debug_timer_deactivate(struct timer_list *timer, bool free)
{
+ switch (timer->enabled) {
+ case TIMER_DEBUG_DISABLED:
+ return;
+ case TIMER_DEBUG_ENABLED:
+ if (!free)
+ return;
+ timer->enabled = TIMER_DEBUG_DISABLED;
+ break;
+ case TIMER_DEBUG_WORK:
+ break;
+ }
debug_object_deactivate(timer, &timer_debug_descr);
}
@@ -828,7 +854,7 @@ static inline void debug_init(struct timer_list *timer)
static inline void debug_deactivate(struct timer_list *timer)
{
- debug_timer_deactivate(timer);
+ debug_timer_deactivate(timer, false);
trace_timer_cancel(timer);
}
@@ -1251,8 +1277,10 @@ int __del_timer(struct timer_list *timer, bool free)
if (timer_pending(timer)) {
base = lock_timer_base(timer, &flags);
ret = detach_if_pending(timer, base, true);
- if (free && ret)
+ if (free) {
timer->function = NULL;
+ debug_timer_deactivate(timer, true);
+ }
raw_spin_unlock_irqrestore(&base->lock, flags);
}
@@ -1272,8 +1300,10 @@ static int __try_to_del_timer_sync(struct timer_list *timer, bool free)
if (base->running_timer != timer)
ret = detach_if_pending(timer, base, true);
- if (free)
+ if (free) {
timer->function = NULL;
+ debug_timer_deactivate(timer, true);
+ }
raw_spin_unlock_irqrestore(&base->lock, flags);
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 47a7124bbea4..9a48213fc4e4 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1225,6 +1225,16 @@ static void pwq_dec_nr_in_flight(struct pool_workqueue *pwq, unsigned long work_
put_pwq(pwq);
}
+static void deactivate_timer(struct work_struct *work, bool is_dwork)
+{
+ struct delayed_work *dwork;
+
+ if (!is_dwork)
+ return;
+
+ dwork = to_delayed_work(work);
+}
+
/**
* try_to_grab_pending - steal work item from worklist and disable irq
* @work: work item to steal
@@ -3148,6 +3158,8 @@ static bool __cancel_work_timer(struct work_struct *work, bool is_dwork)
}
} while (unlikely(ret < 0));
+ deactivate_timer(work, is_dwork);
+
/* tell other tasks trying to grab @work to back off */
mark_work_canceling(work);
local_irq_restore(flags);
--
2.35.1
next prev parent reply other threads:[~2022-10-28 18:10 UTC|newest]
Thread overview: 109+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-27 15:05 [RFC][PATCH v2 00/31] timers: Use del_timer_shutdown() before freeing timers Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 01/31] timers: Add del_timer_shutdown() to be called " Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 02/31] timers: s390/cmm: Use del_timer_shutdown() before freeing timer Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 03/31] timers: sh: " Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 05/31] timers: ACPI: " Steven Rostedt
2022-10-28 16:56 ` Rafael J. Wysocki
2022-11-01 1:11 ` Jarkko Sakkinen
2022-10-27 15:05 ` [RFC][PATCH v2 06/31] timers: atm: " Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 07/31] timers: PM: Use del_timer_shutdown() Steven Rostedt
2022-10-28 17:45 ` Rafael J. Wysocki
2022-10-27 15:05 ` [RFC][PATCH v2 08/31] timers: Bluetooth: Use del_timer_shutdown() before freeing timer Steven Rostedt
2022-10-29 0:12 ` Luiz Augusto von Dentz
2022-10-29 0:33 ` Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 09/31] timers: hangcheck: " Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 10/31] timers: ipmi: " Steven Rostedt
2022-10-27 15:20 ` Corey Minyard
2022-10-27 15:22 ` Corey Minyard
2022-10-27 15:31 ` Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 11/31] timers: random: " Steven Rostedt
2022-10-27 15:55 ` Jason A. Donenfeld
2022-10-27 15:05 ` [RFC][PATCH v2 14/31] timers: HID: " Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 16/31] timers: mISDN: " Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 17/31] timers: leds: " Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 19/31] timers: net: " Steven Rostedt
2022-10-27 19:55 ` Steven Rostedt
2022-10-27 20:15 ` Linus Torvalds
2022-10-27 20:34 ` Steven Rostedt
2022-10-27 20:48 ` Linus Torvalds
2022-10-27 21:07 ` Steven Rostedt
2022-10-27 21:15 ` Steven Rostedt
2022-10-27 22:35 ` Steven Rostedt
2022-10-28 22:31 ` Steven Rostedt
2022-10-28 22:46 ` Jakub Kicinski
2022-10-30 17:22 ` Paolo Abeni
2022-11-03 21:51 ` Steven Rostedt
2022-11-04 0:00 ` Eric Dumazet
2022-11-04 5:51 ` Steven Rostedt
2022-11-04 16:14 ` Guenter Roeck
2022-10-27 21:07 ` Steven Rostedt
2022-10-28 15:16 ` Guenter Roeck
2022-10-27 15:05 ` [RFC][PATCH v2 20/31] timers: usb: " Steven Rostedt
2022-10-27 20:38 ` Alan Stern
2022-10-27 20:42 ` Steven Rostedt
2022-10-27 21:22 ` Steven Rostedt
2022-10-28 5:23 ` Guenter Roeck
2022-10-28 10:14 ` Steven Rostedt
2022-10-28 14:00 ` Steven Rostedt
2022-10-28 18:01 ` Steven Rostedt
2022-10-28 18:10 ` Steven Rostedt [this message]
2022-10-28 19:59 ` Guenter Roeck
2022-10-28 20:40 ` Steven Rostedt
2022-10-28 23:25 ` Guenter Roeck
2022-10-28 23:29 ` Steven Rostedt
2022-10-29 14:52 ` Guenter Roeck
2022-10-29 19:19 ` Steven Rostedt
2022-10-29 22:56 ` Guenter Roeck
2022-10-30 15:48 ` Steven Rostedt
2022-10-31 15:50 ` Guenter Roeck
2022-10-31 20:14 ` Guenter Roeck
2022-10-27 15:05 ` [RFC][PATCH v2 21/31] timers: cgroup: " Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 22/31] timers: workqueue: " Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 23/31] timers: nfc: pn533: " Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 24/31] timers: pcmcia: " Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 25/31] timers: scsi: " Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 26/31] timers: tty: " Steven Rostedt
2022-10-31 8:34 ` Jiri Slaby
2022-10-27 15:05 ` [RFC][PATCH v2 27/31] timers: ext4: " Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 28/31] timers: fs/nilfs2: " Steven Rostedt
2022-10-28 5:12 ` Ryusuke Konishi
2022-10-27 15:05 ` [RFC][PATCH v2 29/31] timers: ALSA: " Steven Rostedt
2022-10-28 9:17 ` Takashi Iwai
2022-10-27 15:05 ` [RFC][PATCH v2 30/31] timers: x86/mce: Use __init_timer() for resetting timers Steven Rostedt
2022-10-27 15:05 ` [RFC][PATCH v2 31/31] timers: Expand DEBUG_OBJECTS_TIMER to check if it ever was used Steven Rostedt
[not found] ` <20221027150925.819019339@goodmis.org>
2022-10-27 15:19 ` [RFC][PATCH v2 04/31] timers: block: Use del_timer_shutdown() before freeing timer Steven Rostedt
2022-10-28 8:26 ` Christoph Hellwig
2022-10-28 10:24 ` Steven Rostedt
2022-10-28 13:56 ` Jens Axboe
2022-10-28 14:06 ` Steven Rostedt
2022-10-28 14:11 ` Jens Axboe
2022-10-28 14:30 ` Steven Rostedt
2022-10-28 15:11 ` Guenter Roeck
[not found] ` <20221027150927.371916000@goodmis.org>
2022-10-27 15:20 ` [RFC][PATCH v2 12/31] timers: dma-buf: " Steven Rostedt
[not found] ` <20221027150927.611233945@goodmis.org>
2022-10-27 15:20 ` [RFC][PATCH v2 13/31] timers: drm: " Steven Rostedt
[not found] ` <20221027150927.992061541@goodmis.org>
2022-10-27 15:21 ` [RFC][PATCH v2 15/31] timers: Input: " Steven Rostedt
2022-10-27 16:38 ` Dmitry Torokhov
2022-10-27 15:52 ` [RFC][PATCH v2 00/31] timers: Use del_timer_shutdown() before freeing timers Jason A. Donenfeld
2022-10-27 16:01 ` Sebastian Andrzej Siewior
2022-10-27 17:23 ` Steven Rostedt
2022-10-27 18:58 ` Guenter Roeck
2022-10-27 19:02 ` Steven Rostedt
2022-10-27 19:11 ` Guenter Roeck
2022-10-27 19:11 ` Linus Torvalds
2022-10-27 19:16 ` Steven Rostedt
2022-10-27 19:44 ` Guenter Roeck
2022-10-27 19:20 ` Steven Rostedt
2022-10-27 19:27 ` Steven Rostedt
2022-10-27 19:38 ` Guenter Roeck
2022-10-27 22:24 ` Guenter Roeck
2022-10-27 22:58 ` Steven Rostedt
2022-10-27 23:24 ` Guenter Roeck
2022-10-27 23:55 ` Steven Rostedt
2022-10-28 0:54 ` Guenter Roeck
2022-10-28 15:30 ` Guenter Roeck
2022-10-28 16:10 ` Guenter Roeck
[not found] ` <20221028021815.3130-1-hdanton@sina.com>
2022-10-28 3:17 ` [RFC][PATCH v2 20/31] timers: usb: Use del_timer_shutdown() before freeing timer Steven Rostedt
2022-10-28 18:50 ` [RFC][PATCH v2 00/31] timers: Use del_timer_shutdown() before freeing timers Steven Rostedt
2022-10-28 20:12 ` Trond Myklebust
2022-10-28 20:49 ` Steven Rostedt
2022-10-28 21:57 ` Trond Myklebust
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221028141007.05f5c490@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=Bhuvanesh_Surachari@mentor.com \
--cc=balbi@kernel.org \
--cc=dan.carpenter@oracle.com \
--cc=gregkh@linuxfoundation.org \
--cc=jiangshanlai@gmail.com \
--cc=johan@kernel.org \
--cc=jstultz@google.com \
--cc=kai.heng.feng@canonical.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=m.grzeschik@pengutronix.de \
--cc=mathias.nyman@linux.intel.com \
--cc=mka@chromium.org \
--cc=sboyd@kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).