All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] timers: Provide a better debugobjects hint for delayed works
@ 2022-05-11 20:19 Stephen Boyd
  2022-05-14 15:43 ` [tip: timers/core] " tip-bot2 for Stephen Boyd
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Boyd @ 2022-05-11 20:19 UTC (permalink / raw
  To: John Stultz, Thomas Gleixner
  Cc: linux-kernel, patches, Tejun Heo, Lai Jiangshan, Guenter Roeck

With debugobjects enabled the timer hint for freeing of active timers
embedded inside delayed works is always the same, i.e. the hint is
delayed_work_timer_fn, even though the function the delayed work is
going to run can be wildly different depending on what work was queued.
Enabling workqueue debugobjects doesn't help either because the delayed
work isn't considered active until it is actually queued to run on a
workqueue. If the work is freed while the timer is pending the work
isn't considered active so we don't get any information from workqueue
debugobjects.

Special case delayed works in the timer debugobjects hint logic so that
the delayed work function is returned instead of the
delayed_work_timer_fn. This will help us understand what delayed work
was pending that got freed. Apply the same treatment for
kthread_delayed_work because it follows the same pattern.

Cc: Tejun Heo <tj@kernel.org>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>
Cc: Guenter Roeck <groeck@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---

Feel free to reassign authorship to tglx.

Changes from v1 (https://lore.kernel.org/r/20220504223148.644228-1-swboyd@chromium.org):
 * Use counter proposed patch from tglx
 * Deref function pointer to get proper hint
 * Add 't' the function pointer to make checkpatch quiet

 kernel/time/timer.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 9dd2a39cb3b0..8637990a3842 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -615,9 +615,39 @@ static void internal_add_timer(struct timer_base *base, struct timer_list *timer
 
 static const struct debug_obj_descr timer_debug_descr;
 
+struct timer_hint {
+	void	(*function)(struct timer_list *t);
+	long	offset;
+};
+
+#define TIMER_HINT(fn, container, timr, hintfn)			\
+	{							\
+		.function = fn,					\
+		.offset	  = offsetof(container, hintfn) -	\
+			    offsetof(container, timr)		\
+	}
+
+static const struct timer_hint timer_hints[] = {
+	TIMER_HINT(delayed_work_timer_fn,
+		   struct delayed_work, timer, work.func),
+	TIMER_HINT(kthread_delayed_work_timer_fn,
+		   struct kthread_delayed_work, timer, work.func),
+};
+
 static void *timer_debug_hint(void *addr)
 {
-	return ((struct timer_list *) addr)->function;
+	struct timer_list *timer = addr;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(timer_hints); i++) {
+		if (timer_hints[i].function == timer->function) {
+			void (**fn)(void) = addr + timer_hints[i].offset;
+
+			return *fn;
+		}
+	}
+
+	return timer->function;
 }
 
 static bool timer_is_static_object(void *addr)

base-commit: 672c0c5173427e6b3e2a9bbb7be51ceeec78093a
-- 
https://chromeos.dev


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

* [tip: timers/core] timers: Provide a better debugobjects hint for delayed works
  2022-05-11 20:19 [PATCH v2] timers: Provide a better debugobjects hint for delayed works Stephen Boyd
@ 2022-05-14 15:43 ` tip-bot2 for Stephen Boyd
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Stephen Boyd @ 2022-05-14 15:43 UTC (permalink / raw
  To: linux-tip-commits; +Cc: Thomas Gleixner, Stephen Boyd, x86, linux-kernel

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     317f29c14d0cca09952f1022491454b23455ebcb
Gitweb:        https://git.kernel.org/tip/317f29c14d0cca09952f1022491454b23455ebcb
Author:        Stephen Boyd <swboyd@chromium.org>
AuthorDate:    Wed, 11 May 2022 13:19:51 -07:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Sat, 14 May 2022 17:40:36 +02:00

timers: Provide a better debugobjects hint for delayed works

With debugobjects enabled the timer hint for freeing of active timers
embedded inside delayed works is always the same, i.e. the hint is
delayed_work_timer_fn, even though the function the delayed work is going
to run can be wildly different depending on what work was queued.  Enabling
workqueue debugobjects doesn't help either because the delayed work isn't
considered active until it is actually queued to run on a workqueue. If the
work is freed while the timer is pending the work isn't considered active
so there is no information from workqueue debugobjects.

Special case delayed works in the timer debugobjects hint logic so that the
delayed work function is returned instead of the delayed_work_timer_fn.
This will help to understand which delayed work was pending that got
freed.

Apply the same treatment for kthread_delayed_work because it follows the
same pattern.

Suggested-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20220511201951.42408-1-swboyd@chromium.org
---
 kernel/time/timer.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index ef082d4..a0666d9 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -638,9 +638,39 @@ static void internal_add_timer(struct timer_base *base, struct timer_list *timer
 
 static const struct debug_obj_descr timer_debug_descr;
 
+struct timer_hint {
+	void	(*function)(struct timer_list *t);
+	long	offset;
+};
+
+#define TIMER_HINT(fn, container, timr, hintfn)			\
+	{							\
+		.function = fn,					\
+		.offset	  = offsetof(container, hintfn) -	\
+			    offsetof(container, timr)		\
+	}
+
+static const struct timer_hint timer_hints[] = {
+	TIMER_HINT(delayed_work_timer_fn,
+		   struct delayed_work, timer, work.func),
+	TIMER_HINT(kthread_delayed_work_timer_fn,
+		   struct kthread_delayed_work, timer, work.func),
+};
+
 static void *timer_debug_hint(void *addr)
 {
-	return ((struct timer_list *) addr)->function;
+	struct timer_list *timer = addr;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(timer_hints); i++) {
+		if (timer_hints[i].function == timer->function) {
+			void (**fn)(void) = addr + timer_hints[i].offset;
+
+			return *fn;
+		}
+	}
+
+	return timer->function;
 }
 
 static bool timer_is_static_object(void *addr)

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

end of thread, other threads:[~2022-05-14 15:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-11 20:19 [PATCH v2] timers: Provide a better debugobjects hint for delayed works Stephen Boyd
2022-05-14 15:43 ` [tip: timers/core] " tip-bot2 for Stephen Boyd

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.