Skip to content

Commit 175f4b0

Browse files
ctmarinasgregkh
authored andcommitted
rcu: kmemleak: Ignore kmemleak false positives when RCU-freeing objects
commit 5f98fd0 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3c1c1af commit 175f4b0

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/percpu.h>
3637
#include <linux/notifier.h>
@@ -3547,6 +3548,14 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
35473548

35483549
WRITE_ONCE(krcp->count, krcp->count + 1);
35493550

3551+
/*
3552+
* The kvfree_rcu() caller considers the pointer freed at this point
3553+
* and likely removes any references to it. Since the actual slab
3554+
* freeing (and kmemleak_free()) is deferred, tell kmemleak to ignore
3555+
* this object (no scanning or false positives reporting).
3556+
*/
3557+
kmemleak_ignore(ptr);
3558+
35503559
// Set timer to drain after KFREE_DRAIN_JIFFIES.
35513560
if (rcu_scheduler_active == RCU_SCHEDULER_RUNNING &&
35523561
!krcp->monitor_todo) {

0 commit comments

Comments
 (0)