From: Waiman Long <llong@redhat.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
Waiman Long <llong@redhat.com>
Cc: Gu Bowen <gubowen5@huawei.com>,
Andrew Morton <akpm@linux-foundation.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, linux-mm@kvack.org,
Breno Leitao <leitao@debian.org>,
John Ogness <john.ogness@linutronix.de>,
Lu Jialin <lujialin4@huawei.com>
Subject: Re: [PATCH v4] mm: Fix possible deadlock in kmemleak
Date: Wed, 20 Aug 2025 11:01:00 -0400 [thread overview]
Message-ID: <fed73718-8001-4db6-af36-86c60e85d224@redhat.com> (raw)
In-Reply-To: <aKWrSfLD5f1r5rg_@arm.com>
On 8/20/25 7:02 AM, Catalin Marinas wrote:
> On Tue, Aug 19, 2025 at 11:27:23PM -0400, Waiman Long wrote:
>> On 8/18/25 5:09 AM, Gu Bowen wrote:
>>> @@ -858,8 +870,14 @@ static void delete_object_part(unsigned long ptr, size_t size,
>>> object = __find_and_remove_object(ptr, 1, objflags);
>>> if (!object) {
>>> #ifdef DEBUG
>>> + /*
>>> + * Printk deferring due to the kmemleak_lock held.
>>> + * This is done to avoid deadlock.
>>> + */
>>> + printk_deferred_enter();
>>> kmemleak_warn("Partially freeing unknown object at 0x%08lx (size %zu)\n",
>>> ptr, size);
>>> + printk_deferred_exit();
>>> #endif
>> This particular warning message can be moved after unlock by adding a
>> warning flag. Locking is done outside of the other two helper functions
>> above, so it is easier to use printk_deferred_enter/exit() for those.
> I thought about this as well but the above is under an #ifdef DEBUG so
> we end up adding more lines on the unlock path (not sure which one looks
> better; I'd say the above, marginally).
>
> Another option would be to remove the #ifdef and try to identify the
> call sites that trigger the warning. Last time I checked (many years
> ago) they were fairly benign and decided to hide them before an #ifdef.
A bit more code change required the printing is moved.
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index 84265983f239..eb4e0af5edba 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -856,13 +856,8 @@ static void delete_object_part(unsigned long ptr,
size_t size,
raw_spin_lock_irqsave(&kmemleak_lock, flags);
object = __find_and_remove_object(ptr, 1, objflags);
- if (!object) {
-#ifdef DEBUG
- kmemleak_warn("Partially freeing unknown object at
0x%08lx (size %zu)\n",
- ptr, size);
-#endif
+ if (!object)
goto unlock;
- }
/*
* Create one or two objects that may result from the memory block
@@ -882,8 +877,14 @@ static void delete_object_part(unsigned long ptr,
size_t size,
unlock:
raw_spin_unlock_irqrestore(&kmemleak_lock, flags);
- if (object)
+ if (object) {
__delete_object(object);
+ } else {
+#ifdef DEBUG
+ kmemleak_warn("Partially freeing unknown object at
0x%08lx (size %zu)\n",
+ ptr, size);
+#endif
+ }
Anyway, I am not against using printk_deferred_enter/exit here. It is
just that they should be used as a last resort if there is no easy way
to work around it.
Cheers,
Longman
next prev parent reply other threads:[~2025-08-20 15:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-18 9:09 Gu Bowen
2025-08-19 15:30 ` Catalin Marinas
2025-08-19 22:49 ` Andrew Morton
2025-08-20 1:23 ` Gu Bowen
2025-08-20 3:27 ` Waiman Long
2025-08-20 11:02 ` Catalin Marinas
2025-08-20 15:01 ` Waiman Long [this message]
2025-08-20 17:00 ` Catalin Marinas
2025-08-21 11:45 ` Gu Bowen
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=fed73718-8001-4db6-af36-86c60e85d224@redhat.com \
--to=llong@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=gregkh@linuxfoundation.org \
--cc=gubowen5@huawei.com \
--cc=john.ogness@linutronix.de \
--cc=leitao@debian.org \
--cc=linux-mm@kvack.org \
--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