Skip to content

Commit e2bd1b1

Browse files
committed
Merge tag 'core-debugobjects-2026-03-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull debugobjects fix from Thomas Gleixner: "A single fix for debugobjects. The deferred page initialization prevents debug objects from allocating slab pages until the initialization is complete. That causes depletion of the pool and disabling of debugobjects. The reason is that debugobjects uses __GFP_HIGH for allocations as it might be invoked from arbitrary contexts. When PREEMPT_COUNT is disabled there is no way to know whether the context is safe to set __GFP_KSWAPD_RECLAIM. This worked until v6.18. Since then allocations w/o a reclaim flag cause new_slab() to end up in alloc_frozen_pages_nolock_noprof(), which returns early when deferred page initialization has not yet completed. Work around that when PREEMPT_COUNT is enabled as the preempt counter allows debugobjects to add __GFP_KSWAPD_RECLAIM to the GFP flags when the context is preemtible. When PREEMPT_COUNT is disabled the context is unknown and the reclaim bit can't be set because the caller might hold locks which might deadlock in the allocator. That makes debugobjects depend on PREEMPT_COUNT || !DEFERRED_STRUCT_PAGE_INIT, which limits the coverage slightly, but keeps it functional for most cases" * tag 'core-debugobjects-2026-03-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: debugobject: Make it work with deferred page initialization - again
2 parents 5920da4 + fd36343 commit e2bd1b1

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/Kconfig.debug

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ source "mm/Kconfig.debug"
760760

761761
config DEBUG_OBJECTS
762762
bool "Debug object operations"
763+
depends on PREEMPT_COUNT || !DEFERRED_STRUCT_PAGE_INIT
763764
depends on DEBUG_KERNEL
764765
help
765766
If you say Y here, additional code will be inserted into the

lib/debugobjects.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,26 @@ static void fill_pool(void)
398398

399399
atomic_inc(&cpus_allocating);
400400
while (pool_should_refill(&pool_global)) {
401+
gfp_t gfp = __GFP_HIGH | __GFP_NOWARN;
401402
HLIST_HEAD(head);
402403

403-
if (!kmem_alloc_batch(&head, obj_cache, __GFP_HIGH | __GFP_NOWARN))
404+
/*
405+
* Allow reclaim only in preemptible context and during
406+
* early boot. If not preemptible, the caller might hold
407+
* locks causing a deadlock in the allocator.
408+
*
409+
* If the reclaim flag is not set during early boot then
410+
* allocations, which happen before deferred page
411+
* initialization has completed, will fail.
412+
*
413+
* In preemptible context the flag is harmless and not a
414+
* performance issue as that's usually invoked from slow
415+
* path initialization context.
416+
*/
417+
if (preemptible() || system_state < SYSTEM_SCHEDULING)
418+
gfp |= __GFP_KSWAPD_RECLAIM;
419+
420+
if (!kmem_alloc_batch(&head, obj_cache, gfp))
404421
break;
405422

406423
guard(raw_spinlock_irqsave)(&pool_lock);

0 commit comments

Comments
 (0)