Skip to contentSkip to conversation

debugobjects: insulate non-fixup logic related to static obj from fixup callbacks

PATCH New [email protected] 1 participant 1 message May 20, 2016

Subsystems (5)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 15/117 debugobjects: insulate non-fixup logic related to static obj from fixup callbacks

From: "Du, Changbin" <[email protected]>
Subject: debugobjects: insulate non-fixup logic related to static obj from fixup callbacks

When activating a static object we need make sure that the object is tracked in the object tracker. If it is a non-static object then the activation is illegal.

In previous implementation, each subsystem need take care of this in their fixup callbacks. Actually we can put it into debugobjects core. Thus we can save duplicated code, and have *pure* fixup callbacks.

To achieve this, a new callback "is_static_object" is introduced to let the type specific code decide whether a object is static or not. If yes, we take it into object tracker, otherwise give warning and invoke fixup callback.

This change has paassed debugobjects selftest, and I also do some test with all debugobjects supports enabled.

At last, I have a concern about the fixups that can it change the object which is in incorrect state on fixup? Because the 'addr' may not point to any valid object if a non-static object is not tracked. Then Change such object can overwrite someone's memory and cause unexpected behaviour. For example, the timer_fixup_activate bind timer to function stub_timer.

[[email protected]: improve code comments where invoke the new is_static_object callback]
Cc Jonathan Corbet <[email protected]>
Cc Josh Triplett <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Christian Borntraeger <[email protected]>

---

 include/linux/debugobjects.h |    2 +
 kernel/rcu/update.c          |   26 ++---------------
 kernel/time/hrtimer.c        |    7 ----
 kernel/time/timer.c          |   43 +++++++++-------------------
 kernel/workqueue.c           |   42 +++++-----------------------
 lib/debugobjects.c           |   49 +++++++++++++++++++++------------
 6 files changed, 60 insertions(+), 109 deletions(-)
include/linux/debugobjects.h renamed from include/linux/debugobjects.h~debugobjects-insulate-non-fixup-logic-related-to-static-obj-from-fixup-callbacks +2 -0
diff -puN include/linux/debugobjects.h~debugobjects-insulate-non-fixup-logic-related-to-static-obj-from-fixup-callbacks include/linux/debugobjects.h
@@ -38,6 +38,7 @@ struct debug_obj {
  * @name:		name of the object typee
  * @debug_hint:		function returning address, which have associated
  *			kernel symbol, to allow identify the object
+ * @is_static_object	return true if the obj is static, otherwise return false
  * @fixup_init:		fixup function, which is called when the init check
  *			fails. All fixup functions must return true if fixup
  *			was successful, otherwise return false
@@ -53,6 +54,7 @@ struct debug_obj {
 struct debug_obj_descr {
 	const char		*name;
 	void *(*debug_hint)(void *addr);
+	bool (*is_static_object)(void *addr);
 	bool (*fixup_init)(void *addr, enum debug_obj_state state);
 	bool (*fixup_activate)(void *addr, enum debug_obj_state state);
 	bool (*fixup_destroy)(void *addr, enum debug_obj_state state);
kernel/rcu/update.c renamed from kernel/rcu/update.c~debugobjects-insulate-non-fixup-logic-related-to-static-obj-from-fixup-callbacks +3 -23
diff -puN kernel/rcu/update.c~debugobjects-insulate-non-fixup-logic-related-to-static-obj-from-fixup-callbacks kernel/rcu/update.c
@@ -380,29 +380,9 @@ void destroy_rcu_head(struct rcu_head *h
 	debug_object_free(head, &rcuhead_debug_descr);
 }
 
-/*
- * fixup_activate is called when:
- * - an active object is activated
- * - an unknown object is activated (might be a statically initialized object)
- * Activation is performed internally by call_rcu().
- */
-static bool rcuhead_fixup_activate(void *addr, enum debug_obj_state state)
+static bool rcuhead_is_static_object(void *addr)
 {
-	struct rcu_head *head = addr;
-
-	switch (state) {
-
-	case ODEBUG_STATE_NOTAVAILABLE:
-		/*
-		 * This is not really a fixup. We just make sure that it is
-		 * tracked in the object tracker.
-		 */
-		debug_object_init(head, &rcuhead_debug_descr);
-		debug_object_activate(head, &rcuhead_debug_descr);
-		return false;
-	default:
-		return true;
-	}
+	return true;
 }
 
 /**
@@ -440,7 +420,7 @@ EXPORT_SYMBOL_GPL(destroy_rcu_head_on_st
 
 struct debug_obj_descr rcuhead_debug_descr = {
 	.name = "rcu_head",
-	.fixup_activate = rcuhead_fixup_activate,
+	.is_static_object = rcuhead_is_static_object,
 };
 EXPORT_SYMBOL_GPL(rcuhead_debug_descr);
 #endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
kernel/time/hrtimer.c renamed from kernel/time/hrtimer.c~debugobjects-insulate-non-fixup-logic-related-to-static-obj-from-fixup-callbacks +1 -6
diff -puN kernel/time/hrtimer.c~debugobjects-insulate-non-fixup-logic-related-to-static-obj-from-fixup-callbacks kernel/time/hrtimer.c
@@ -351,16 +351,11 @@ static bool hrtimer_fixup_init(void *add
 /*
  * fixup_activate is called when:
  * - an active object is activated
- * - an unknown object is activated (might be a statically initialized object)
+ * - an unknown non-static object is activated
  */
 static bool hrtimer_fixup_activate(void *addr, enum debug_obj_state state)
 {
 	switch (state) {
-
-	case ODEBUG_STATE_NOTAVAILABLE:
-		WARN_ON_ONCE(1);
-		return false;
-
 	case ODEBUG_STATE_ACTIVE:
 		WARN_ON(1);
 
kernel/time/timer.c renamed from kernel/time/timer.c~debugobjects-insulate-non-fixup-logic-related-to-static-obj-from-fixup-callbacks +14 -29

74 lines not on this page · raw message

kernel/workqueue.c renamed from kernel/workqueue.c~debugobjects-insulate-non-fixup-logic-related-to-static-obj-from-fixup-callbacks +8 -34

61 lines not on this page · raw message

lib/debugobjects.c renamed from lib/debugobjects.c~debugobjects-insulate-non-fixup-logic-related-to-static-obj-from-fixup-callbacks +31 -16

79 lines not on this page · raw message