mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-25 23:15:26 +07:00
b9fdac7f66
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. Link: http://lkml.kernel.org/r/1462576157-14539-1-git-send-email-changbin.du@intel.com [changbin.du@intel.com: improve code comments where invoke the new is_static_object callback] Link: http://lkml.kernel.org/r/1462777431-8171-1-git-send-email-changbin.du@intel.com Signed-off-by: Du, Changbin <changbin.du@intel.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Josh Triplett <josh@kernel.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tejun Heo <tj@kernel.org> Cc: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
114 lines
3.9 KiB
C
114 lines
3.9 KiB
C
#ifndef _LINUX_DEBUGOBJECTS_H
|
|
#define _LINUX_DEBUGOBJECTS_H
|
|
|
|
#include <linux/list.h>
|
|
#include <linux/spinlock.h>
|
|
|
|
enum debug_obj_state {
|
|
ODEBUG_STATE_NONE,
|
|
ODEBUG_STATE_INIT,
|
|
ODEBUG_STATE_INACTIVE,
|
|
ODEBUG_STATE_ACTIVE,
|
|
ODEBUG_STATE_DESTROYED,
|
|
ODEBUG_STATE_NOTAVAILABLE,
|
|
ODEBUG_STATE_MAX,
|
|
};
|
|
|
|
struct debug_obj_descr;
|
|
|
|
/**
|
|
* struct debug_obj - representaion of an tracked object
|
|
* @node: hlist node to link the object into the tracker list
|
|
* @state: tracked object state
|
|
* @astate: current active state
|
|
* @object: pointer to the real object
|
|
* @descr: pointer to an object type specific debug description structure
|
|
*/
|
|
struct debug_obj {
|
|
struct hlist_node node;
|
|
enum debug_obj_state state;
|
|
unsigned int astate;
|
|
void *object;
|
|
struct debug_obj_descr *descr;
|
|
};
|
|
|
|
/**
|
|
* struct debug_obj_descr - object type specific debug description structure
|
|
*
|
|
* @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
|
|
* @fixup_activate: fixup function, which is called when the activate check
|
|
* fails
|
|
* @fixup_destroy: fixup function, which is called when the destroy check
|
|
* fails
|
|
* @fixup_free: fixup function, which is called when the free check
|
|
* fails
|
|
* @fixup_assert_init: fixup function, which is called when the assert_init
|
|
* check fails
|
|
*/
|
|
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);
|
|
bool (*fixup_free)(void *addr, enum debug_obj_state state);
|
|
bool (*fixup_assert_init)(void *addr, enum debug_obj_state state);
|
|
};
|
|
|
|
#ifdef CONFIG_DEBUG_OBJECTS
|
|
extern void debug_object_init (void *addr, struct debug_obj_descr *descr);
|
|
extern void
|
|
debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr);
|
|
extern int debug_object_activate (void *addr, struct debug_obj_descr *descr);
|
|
extern void debug_object_deactivate(void *addr, struct debug_obj_descr *descr);
|
|
extern void debug_object_destroy (void *addr, struct debug_obj_descr *descr);
|
|
extern void debug_object_free (void *addr, struct debug_obj_descr *descr);
|
|
extern void debug_object_assert_init(void *addr, struct debug_obj_descr *descr);
|
|
|
|
/*
|
|
* Active state:
|
|
* - Set at 0 upon initialization.
|
|
* - Must return to 0 before deactivation.
|
|
*/
|
|
extern void
|
|
debug_object_active_state(void *addr, struct debug_obj_descr *descr,
|
|
unsigned int expect, unsigned int next);
|
|
|
|
extern void debug_objects_early_init(void);
|
|
extern void debug_objects_mem_init(void);
|
|
#else
|
|
static inline void
|
|
debug_object_init (void *addr, struct debug_obj_descr *descr) { }
|
|
static inline void
|
|
debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr) { }
|
|
static inline int
|
|
debug_object_activate (void *addr, struct debug_obj_descr *descr) { return 0; }
|
|
static inline void
|
|
debug_object_deactivate(void *addr, struct debug_obj_descr *descr) { }
|
|
static inline void
|
|
debug_object_destroy (void *addr, struct debug_obj_descr *descr) { }
|
|
static inline void
|
|
debug_object_free (void *addr, struct debug_obj_descr *descr) { }
|
|
static inline void
|
|
debug_object_assert_init(void *addr, struct debug_obj_descr *descr) { }
|
|
|
|
static inline void debug_objects_early_init(void) { }
|
|
static inline void debug_objects_mem_init(void) { }
|
|
#endif
|
|
|
|
#ifdef CONFIG_DEBUG_OBJECTS_FREE
|
|
extern void debug_check_no_obj_freed(const void *address, unsigned long size);
|
|
#else
|
|
static inline void
|
|
debug_check_no_obj_freed(const void *address, unsigned long size) { }
|
|
#endif
|
|
|
|
#endif
|