From: Joel Fernandes <joel@joelfernandes.org>
To: Matthieu Baerts <matthieu.baerts@tessares.net>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
Christoph Paasch <cpaasch@apple.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, MPTCP Upstream <mptcp@lists.linux.dev>,
rcu@vger.kernel.org
Subject: Re: kmemleak handling of kfree_rcu
Date: Tue, 12 Sep 2023 09:32:46 -0400 [thread overview]
Message-ID: <5FAC49DB-0849-4F83-9802-571E62819ACC@joelfernandes.org> (raw)
In-Reply-To: <6bd9f6cc-84d0-4f6a-bfd7-912dcb8e476a@tessares.net>
> On Sep 12, 2023, at 9:15 AM, Matthieu Baerts <matthieu.baerts@tessares.net> wrote:
> Hi Catalin,
>
> On 06/09/2023 19:15, Catalin Marinas wrote:
>
> (...)
>
>> I had a patch already but got distracted by a few (real) leaks reported
>> while testing it. Feel free to pick it up and change _ignore to
>> _not_leak if you find that more suitable. Well, it would be good for
>> Christoph to test it as I haven't managed to reproduce the false
>> positive.
>
> Thank you for the patch!
>
>> ----------------------8<--------------------------
>> From b25350cb6f8a906a6164b625bfd57021190cb105 Mon Sep 17 00:00:00 2001
>> From: Catalin Marinas <catalin.marinas@arm.com>
>> Date: Wed, 6 Sep 2023 17:52:45 +0100
>> Subject: [PATCH] rcu: kmemleak: Ignore kmemleak false positives when
>> RCU-freeing objects
>>
>> Since the actual slab freeing is deferred when calling kvfree_rcu(), so
>> is the kmemleak_free() callback informing kmemleak of the object
>> deletion. From the perspective of the kvfree_rcu() caller, the object is
>> freed and it may remove any references to it. Since kmemleak does not
>> scan the tree RCU internal data storing the pointer, it will report such
>> objects as leaks during the grace period.
>>
>> Tell kmemleak to ignore such objects on the kvfree_call_rcu() path. Note
>> that the tiny RCU implementation does not have such issue since the
>> objects can be tracked from the rcu_ctrlblk structure.
>>
>> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
>> Reported-by: Christoph Paasch <cpaasch@apple.com>
>> ---
>> kernel/rcu/tree.c | 9 +++++++++
>> 1 file changed, 9 insertions(+)
>>
>> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
>> index cb1caefa8bd0..2ac39b5705df 100644
>> --- a/kernel/rcu/tree.c
>> +++ b/kernel/rcu/tree.c
>> @@ -31,6 +31,7 @@
>> #include <linux/bitops.h>
>> #include <linux/export.h>
>> #include <linux/completion.h>
>> +#include <linux/kmemleak.h>
>> #include <linux/moduleparam.h>
>> #include <linux/panic.h>
>> #include <linux/panic_notifier.h>
>> @@ -3388,6 +3389,14 @@ void kvfree_call_rcu(struct rcu_head *head, void *ptr)
>> success = true;
>> }
>>
>> + /*
>> + * The kvfree_rcu() caller considers the pointer freed at this point
>> + * and likely removes any references to it. Since the the actual slab
>
> Just in case you didn't send this patch, checkpatch.pl noticed that the
> word "the" was repeated in the comment here above ("Since the the actual").
Sounds like you detected a leak in the word the. :-)
(Sorry could not resist).
- Joel
>
> Cheers,
> Matt
>
>> + * freeing (and kmemleak_free()) is deferred, tell kmemleak to ignore
>> + * this object (no scanning or false positives reporting).
>> + */
>> + kmemleak_ignore(ptr);
>> +
>> // Set timer to drain after KFREE_DRAIN_JIFFIES.
>> if (rcu_scheduler_active == RCU_SCHEDULER_RUNNING)
>> schedule_delayed_monitor_work(krcp);
>
> --
> Tessares | Belgium | Hybrid Access Solutions
> www.tessares.net
next prev parent reply other threads:[~2023-09-12 13:34 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <F903A825-F05F-4B77-A2B5-7356282FBA2C@apple.com>
2023-09-04 21:22 ` kmemleak handling of kfree_rcu Catalin Marinas
2023-09-05 11:17 ` Joel Fernandes
2023-09-05 14:41 ` Catalin Marinas
2023-09-06 14:35 ` Joel Fernandes
2023-09-06 17:15 ` Catalin Marinas
2023-09-06 19:11 ` Paul E. McKenney
2023-09-06 21:37 ` Catalin Marinas
2023-09-06 22:02 ` Paul E. McKenney
2023-09-06 23:10 ` Joel Fernandes
2023-09-12 13:15 ` Matthieu Baerts
2023-09-12 13:32 ` Joel Fernandes [this message]
2023-09-05 21:22 ` Christoph Paasch
2023-09-06 17:21 ` Catalin Marinas
2023-09-10 23:10 ` Joel Fernandes
2023-09-11 17:41 ` Christoph Paasch
2023-09-12 9:52 ` Catalin Marinas
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=5FAC49DB-0849-4F83-9802-571E62819ACC@joelfernandes.org \
--to=joel@joelfernandes.org \
--cc=akpm@linux-foundation.org \
--cc=catalin.marinas@arm.com \
--cc=cpaasch@apple.com \
--cc=linux-mm@kvack.org \
--cc=matthieu.baerts@tessares.net \
--cc=mptcp@lists.linux.dev \
--cc=rcu@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).