Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lockdep: Raise default stack trace limits when KASAN is enabled

KASAN-enabled kernels with LOCKDEP and PREEMPT_FULL hit
"BUG: MAX_STACK_TRACE_ENTRIES too low!" within 9-23 hours of normal
desktop use.

The root cause is a feedback loop between KASAN slab tracking and
lockdep: every KASAN-tracked slab allocation saves a stack trace via
stack_trace_save() -> arch_stack_walk(). The unwinder calls
is_bpf_text_address(), which under PREEMPT_FULL can trigger RCU
deferred quiescent-state processing -> swake_up_one() -> lock_acquire()
-> lockdep validate_chain() -> save_trace(). This means KASAN's own
stack captures indirectly generate new lockdep dependency chains,
consuming the buffer from both directions.

/proc/lockdep_stats at the moment of overflow confirms that
stack-trace entries is the sole exhausted resource:

stack-trace entries: 524288 [max: 524288] <- 100% full
number of stack traces: 22080 <- unique after dedup
dependency chains: 164665 [max: 524288] <- only 31% used
direct dependencies: 45270 [max: 65536] <- 69%
lock-classes: 2811 [max: 8192] <- 34%

22080 genuinely unique traces averaging ~24 frames each fill the
buffer in under a day. The hash-based deduplication (12593b7467f9) is
working correctly -- the traces are simply all different due to the
deep and varied call stacks from GPU + filesystem + Wine/Proton + KASAN
instrumentation.

Raise the LOCKDEP_STACK_TRACE_BITS default from 19 to 21 when KASAN is
enabled (2M entries, +12MB). This is negligible compared to KASAN's
own shadow memory overhead (~12.5% of total RAM). Scale
LOCKDEP_STACK_TRACE_HASH_BITS accordingly to maintain dedup efficiency.

Signed-off-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20260313171118.1702954-2-mikhail.v.gavrilov@gmail.com

authored by

Mikhail Gavrilov and committed by
Peter Zijlstra
89162697 2deccd5c

+8
+8
lib/Kconfig.debug
··· 1617 1617 int "Size for MAX_STACK_TRACE_ENTRIES (as Nth power of 2)" 1618 1618 depends on LOCKDEP && !LOCKDEP_SMALL 1619 1619 range 10 26 1620 + default 21 if KASAN 1620 1621 default 19 1621 1622 help 1622 1623 Try increasing this value if you hit "BUG: MAX_STACK_TRACE_ENTRIES too low!" message. 1624 + 1625 + KASAN significantly increases stack trace consumption because its 1626 + slab tracking interacts with lockdep's dependency validation under 1627 + PREEMPT_FULL, creating a feedback loop. The higher default when 1628 + KASAN is enabled costs ~12MB extra, which is negligible compared to 1629 + KASAN's own shadow memory overhead. 1623 1630 1624 1631 config LOCKDEP_STACK_TRACE_HASH_BITS 1625 1632 int "Size for STACK_TRACE_HASH_SIZE (as Nth power of 2)" 1626 1633 depends on LOCKDEP && !LOCKDEP_SMALL 1627 1634 range 10 26 1635 + default 16 if KASAN 1628 1636 default 14 1629 1637 help 1630 1638 Try increasing this value if you need large STACK_TRACE_HASH_SIZE.