Skip to content

Commit 5f98fd0

Browse files
ctmarinasFrederic Weisbecker
authored andcommitted
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 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 <[email protected]> Reported-by: Christoph Paasch <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Cc: <[email protected]> Tested-by: Christoph Paasch <[email protected]> Reviewed-by: Paul E. McKenney <[email protected]> Signed-off-by: Joel Fernandes (Google) <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]>
1 parent d8d5b7b commit 5f98fd0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

kernel/rcu/tree.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/bitops.h>
3232
#include <linux/export.h>
3333
#include <linux/completion.h>
34+
#include <linux/kmemleak.h>
3435
#include <linux/moduleparam.h>
3536
#include <linux/panic.h>
3637
#include <linux/panic_notifier.h>
@@ -3389,6 +3390,14 @@ void kvfree_call_rcu(struct rcu_head *head, void *ptr)
33893390
success = true;
33903391
}
33913392

3393+
/*
3394+
* The kvfree_rcu() caller considers the pointer freed at this point
3395+
* and likely removes any references to it. Since the actual slab
3396+
* freeing (and kmemleak_free()) is deferred, tell kmemleak to ignore
3397+
* this object (no scanning or false positives reporting).
3398+
*/
3399+
kmemleak_ignore(ptr);
3400+
33923401
// Set timer to drain after KFREE_DRAIN_JIFFIES.
33933402
if (rcu_scheduler_active == RCU_SCHEDULER_RUNNING)
33943403
schedule_delayed_monitor_work(krcp);

0 commit comments

Comments
 (0)