Skip to content

Commit 44b8b03

Browse files
Waiman-Longgregkh
authored andcommitted
debugobjects: Dont call fill_pool() in early boot hardirq context
commit 0d046ae upstream. When booting a debug PREEMPT_RT kernel on an ARM64 system, a "inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage" lockdep warning message was reported to the console. During early boot, interrupts are enabled before the scheduler is enabled. In this window (before SYSTEM_SCHEDULING is set) interrupts can fire and in the hard interrupt context handler attempt to fill the pool This can lead to a deadlock when the interrupt occurred when the interrupt hits a region which holds a lock that is required to be taken in the allocation path. Add a new can_fill_pool() helper and reorder the exception rule and forbid this scenario by excluding allocations from hard interrupt context. Fixes: 06e0ae9 ("debugobjects: Allow to refill the pool before SYSTEM_SCHEDULING") Suggested-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Suggested-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Waiman Long <longman@redhat.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260605173038.495075-1-longman@redhat.com Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 3a408ca commit 44b8b03

1 file changed

Lines changed: 37 additions & 9 deletions

File tree

lib/debugobjects.c

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,41 @@ static inline bool debug_objects_is_pi_blocked_on(void)
720720
#endif
721721
}
722722

723+
static inline bool can_fill_pool(void)
724+
{
725+
/*
726+
* On !RT enabled kernels there are no restrictions and spinlock_t and
727+
* raw_spinlock_t are the same types.
728+
*/
729+
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
730+
return true;
731+
732+
/*
733+
* On RT enabled kernels, the task must not be blocked on a lock as
734+
* that could corrupt the PI state when blocking on a lock in the
735+
* allocation path.
736+
*/
737+
if (debug_objects_is_pi_blocked_on())
738+
return false;
739+
740+
/*
741+
* On RT enabled kernels the pool refill should happen in preemptible
742+
* context.
743+
*/
744+
if (preemptible())
745+
return true;
746+
747+
/*
748+
* Though during system boot before scheduling is set up, preemption is
749+
* disabled and the pool can get exhausted. Before scheduling is active
750+
* a task cannot be blocked on a sleeping lock, but it might hold a lock
751+
* and if interrupted then hard interrupt context might run into a lock
752+
* inversion. So exclude hard interrupt context from allocations before
753+
* scheduling is active.
754+
*/
755+
return system_state < SYSTEM_SCHEDULING && !in_hardirq();
756+
}
757+
723758
static void debug_objects_fill_pool(void)
724759
{
725760
if (!static_branch_likely(&obj_cache_enabled))
@@ -734,18 +769,11 @@ static void debug_objects_fill_pool(void)
734769
if (likely(!pool_should_refill(&pool_global)))
735770
return;
736771

737-
/*
738-
* On RT enabled kernels the pool refill must happen in preemptible
739-
* context and not enqueued on an rt_mutex -- for !RT kernels we rely
740-
* on the fact that spinlock_t and raw_spinlock_t are basically the
741-
* same type and this lock-type inversion works just fine.
742-
*/
743-
if (!IS_ENABLED(CONFIG_PREEMPT_RT) || system_state < SYSTEM_SCHEDULING ||
744-
(preemptible() && !debug_objects_is_pi_blocked_on())) {
772+
if (can_fill_pool()) {
745773
/*
746774
* Annotate away the spinlock_t inside raw_spinlock_t warning
747775
* by temporarily raising the wait-type to LD_WAIT_CONFIG, matching
748-
* the preemptible() condition above.
776+
* the preemptible() condition in can_fill_pool().
749777
*/
750778
static DEFINE_WAIT_OVERRIDE_MAP(fill_pool_map, LD_WAIT_CONFIG);
751779
lock_map_acquire_try(&fill_pool_map);

0 commit comments

Comments
 (0)