Re: kmemleak handling of kfree_rcu

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> On Sep 12, 2023, at 9:15 AM, Matthieu Baerts <matthieu.baerts@xxxxxxxxxxxx> 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@xxxxxxx>
>> 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@xxxxxxx>
>> Reported-by: Christoph Paasch <cpaasch@xxxxxxxxx>
>> ---
>> 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





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux