[PATCH v6 1/2] debugobjects: Add a can_fill_pool() helper for debug_objects_fill_pool()
From: Waiman Long
Date: Sun Jun 07 2026 - 22:24:04 EST
The conditional check in debug_objects_fill_pool() for determining
if fill_pool() can be called is now quite complicated. Add a new
can_fill_pool() helper to break down the conditions individually to
make them easier to understand. No functional change is expected.
Suggested-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Signed-off-by: Waiman Long <longman@xxxxxxxxxx>
---
lib/debugobjects.c | 35 ++++++++++++++++++++++++++---------
1 file changed, 26 insertions(+), 9 deletions(-)
diff --git a/lib/debugobjects.c b/lib/debugobjects.c
index b18a682fe3da..1d826689611f 100644
--- a/lib/debugobjects.c
+++ b/lib/debugobjects.c
@@ -720,6 +720,30 @@ static inline bool debug_objects_is_pi_blocked_on(void)
#endif
}
+static inline bool can_fill_pool(void)
+{
+ /*
+ * On !RT enabled kernels there are no restrictions and spinlock_t and
+ * raw_spinlock_t are the same types.
+ */
+ if (!IS_ENABLED(CONFIG_PREEMPT_RT))
+ return true;
+
+ /*
+ * On RT enabled kernels the pool refill must happen in preemptible
+ * context and the task must not be blocked on a lock as that could
+ * corrupt the PI state when blocking on a lock in the allocation path.
+ */
+ if (preemptible() && !debug_objects_is_pi_blocked_on())
+ return true;
+
+ /*
+ * Allow refilling to happen early in the boot with disabled interrupts
+ * as long as the scheduler is not operational.
+ */
+ return system_state < SYSTEM_SCHEDULING;
+}
+
static void debug_objects_fill_pool(void)
{
if (!static_branch_likely(&obj_cache_enabled))
@@ -734,18 +758,11 @@ static void debug_objects_fill_pool(void)
if (likely(!pool_should_refill(&pool_global)))
return;
- /*
- * On RT enabled kernels the pool refill must happen in preemptible
- * context and not enqueued on an rt_mutex -- for !RT kernels we rely
- * on the fact that spinlock_t and raw_spinlock_t are basically the
- * same type and this lock-type inversion works just fine.
- */
- if (!IS_ENABLED(CONFIG_PREEMPT_RT) || system_state < SYSTEM_SCHEDULING ||
- (preemptible() && !debug_objects_is_pi_blocked_on())) {
+ if (can_fill_pool()) {
/*
* Annotate away the spinlock_t inside raw_spinlock_t warning
* by temporarily raising the wait-type to LD_WAIT_CONFIG, matching
- * the preemptible() condition above.
+ * the preemptible() condition in can_fill_pool().
*/
static DEFINE_WAIT_OVERRIDE_MAP(fill_pool_map, LD_WAIT_CONFIG);
lock_map_acquire_try(&fill_pool_map);
--
2.54.0