On Wed, 13 Aug 2025 16:53:10 +0800 Gu Bowen gubowen5@huawei.com wrote:
Our syztester report the lockdep WARNING [1]. kmemleak_scan_thread() invokes scan_block() which may invoke a nomal printk() to print warning message. This can cause a deadlock in the scenario reported below:
CPU0 CPU1 ---- ----
lock(kmemleak_lock); lock(&port->lock); lock(kmemleak_lock); lock(console_owner);
To solve this problem, switch to printk_safe mode before printing warning message, this will redirect all printk()-s to a special per-CPU buffer, which will be flushed later from a safe context (irq work), and this deadlock problem can be avoided. The proper API to use should be printk_deferred_enter()/printk_deferred_exit() if we want to deferred the printing [2].
This patch also fixes other similar case that need to use the printk deferring [3].
...
--- a/mm/kmemleak.c +++ b/mm/kmemleak.c
I'm not sure which kernel version this was against, but kmemleak.c has changed quite a lot.
Could we please see a patch against a latest kernel version? Linus mainline will suit.
Thanks.