From: Catalin Marinas <catalin.marinas@arm.com>
To: Breno Leitao <leitao@debian.org>
Cc: Gu Bowen <gubowen5@huawei.com>,
Andrew Morton <akpm@linux-foundation.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Waiman Long <llong@redhat.com>,
stable@vger.kernel.org, linux-mm@kvack.org,
John Ogness <john.ogness@linutronix.de>,
Lu Jialin <lujialin4@huawei.com>
Subject: Re: [PATCH v5] mm: Fix possible deadlock in kmemleak
Date: Thu, 25 Sep 2025 15:33:22 +0100 [thread overview]
Message-ID: <aNVSsmY86yi-cV_e@arm.com> (raw)
In-Reply-To: <5ohuscufoavyezhy6n5blotk4hovyd2e23pfqylrfwhpu45nby@jxwe6jmkwdzb>
On Fri, Sep 19, 2025 at 03:37:27AM -0700, Breno Leitao wrote:
> On Fri, Aug 22, 2025 at 03:35:41PM +0800, Gu Bowen wrote:
> > 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.
>
> I am still thinking about this problem, given I got another deadlock
> issue that I was not able to debug further given I do not have the
> crashdump.
Do you have some kernel log? I thought we covered all cases in
kmemleak.c (well, might have missed some).
> Should we have a wrapper around raw_spin_lock_irqsave(kmemleak_lock,
> flags), that would defer printk at all?
>
> Then, we can simply replace the raw_spin_lock_irqsave() by the helper,
> avoiding spreading these printk_deferred_enter() in the kmemleak code.
>
> For instance, something as this completely untested code, just to show
> the idea.
>
> void kmemleak_lock(unsigned long *flags) {
> printk_deferred_enter();
> raw_spin_lock_irqsave(&kmemleak_lock, flags);
> }
>
> void kmemleak_lock(unsigned long flags) {
> raw_spin_unlock_irqrestore(&kmemleak_lock, flags);
> printk_deferred_exit();
> }
The way we added the printk deferring recently is around the actual
printk() calls. Given that you can't get an interrupt under
raw_spin_lock_irqsave(), I don't think printk_deferred_exit() would
trigger a console flush. So we could simply add them around those
kmemleak_warn() or pr_*() calls rather than together with the spinlocks.
But we do need to be able to reproduce the problem and show that any
potential patch fixes it.
--
Catalin
next prev parent reply other threads:[~2025-09-25 14:33 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-22 7:35 [PATCH v5] mm: Fix possible deadlock in kmemleak Gu Bowen
2025-08-26 8:23 ` Breno Leitao
2025-08-26 19:37 ` Catalin Marinas
2025-08-26 23:23 ` Waiman Long
2025-09-19 10:37 ` Breno Leitao
2025-09-25 14:33 ` Catalin Marinas [this message]
2025-09-26 14:57 ` Breno Leitao
2025-09-29 14:07 ` John Ogness
2025-09-29 14:40 ` Breno Leitao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aNVSsmY86yi-cV_e@arm.com \
--to=catalin.marinas@arm.com \
--cc=akpm@linux-foundation.org \
--cc=gregkh@linuxfoundation.org \
--cc=gubowen5@huawei.com \
--cc=john.ogness@linutronix.de \
--cc=leitao@debian.org \
--cc=linux-mm@kvack.org \
--cc=llong@redhat.com \
--cc=lujialin4@huawei.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox