[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250604220926.870760-2-longman@redhat.com>
Date: Wed, 4 Jun 2025 18:09:24 -0400
From: Waiman Long <longman@...hat.com>
To: Thomas Gleixner <tglx@...utronix.de>,
Andrew Morton <akpm@...ux-foundation.org>,
Anna-Maria Behnsen <anna-maria@...utronix.de>,
Frederic Weisbecker <frederic@...nel.org>
Cc: linux-kernel@...r.kernel.org,
Waiman Long <longman@...hat.com>
Subject: [PATCH 1/3] debugobjects: Add ODEBUG_FLAG_NO_ALLOC to disable memory allocation
Some of the objects associated with debug_obj may be handled
in a sensitive context that allowing debug_obj pre-allocation
in debug_objects_fill_pool() may casue deadlock. Add a new flags
parameter to the debug_obj_descr structure as well as adding the new
ODEBUG_FLAG_NO_ALLOC flag to enable us to disallow memory allocation
for those types of objects.
Signed-off-by: Waiman Long <longman@...hat.com>
---
include/linux/debugobjects.h | 6 ++++++
lib/debugobjects.c | 10 +++++-----
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/include/linux/debugobjects.h b/include/linux/debugobjects.h
index 8b95545e7924..a058c7dba898 100644
--- a/include/linux/debugobjects.h
+++ b/include/linux/debugobjects.h
@@ -41,6 +41,7 @@ struct debug_obj {
* struct debug_obj_descr - object type specific debug description structure
*
* @name: name of the object typee
+ * @flags: debug object flags
* @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
@@ -58,6 +59,7 @@ struct debug_obj {
*/
struct debug_obj_descr {
const char *name;
+ unsigned long flags;
void *(*debug_hint)(void *addr);
bool (*is_static_object)(void *addr);
bool (*fixup_init)(void *addr, enum debug_obj_state state);
@@ -67,6 +69,10 @@ struct debug_obj_descr {
bool (*fixup_assert_init)(void *addr, enum debug_obj_state state);
};
+enum debug_obj_flags {
+ ODEBUG_FLAG_NO_ALLOC = 0x1, /* Disallow debug object pre-allocation */
+};
+
#ifdef CONFIG_DEBUG_OBJECTS
extern void debug_object_init (void *addr, const struct debug_obj_descr *descr);
extern void
diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index 7f50c4480a4e..52bc77b41f48 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -694,7 +694,7 @@ static struct debug_obj *lookup_object_or_alloc(void *addr, struct debug_bucket
return NULL;
}
-static void debug_objects_fill_pool(void)
+static void debug_objects_fill_pool(bool no_alloc)
{
if (!static_branch_likely(&obj_cache_enabled))
return;
@@ -705,7 +705,7 @@ static void debug_objects_fill_pool(void)
/* Try reusing objects from obj_to_free_list */
fill_pool_from_freelist();
- if (likely(!pool_should_refill(&pool_global)))
+ if (likely(!pool_should_refill(&pool_global) || no_alloc))
return;
/*
@@ -734,7 +734,7 @@ __debug_object_init(void *addr, const struct debug_obj_descr *descr, int onstack
struct debug_bucket *db;
unsigned long flags;
- debug_objects_fill_pool();
+ debug_objects_fill_pool(descr->flags & ODEBUG_FLAG_NO_ALLOC);
db = get_bucket((unsigned long) addr);
@@ -811,7 +811,7 @@ int debug_object_activate(void *addr, const struct debug_obj_descr *descr)
if (!debug_objects_enabled)
return 0;
- debug_objects_fill_pool();
+ debug_objects_fill_pool(descr->flags & ODEBUG_FLAG_NO_ALLOC);
db = get_bucket((unsigned long) addr);
@@ -1000,7 +1000,7 @@ void debug_object_assert_init(void *addr, const struct debug_obj_descr *descr)
if (!debug_objects_enabled)
return;
- debug_objects_fill_pool();
+ debug_objects_fill_pool(descr->flags & ODEBUG_FLAG_NO_ALLOC);
db = get_bucket((unsigned long) addr);
--
2.49.0
Powered by blists - more mailing lists