Skip to content

Commit e99637b

Browse files
joelagnelpaulmckrcu
authored andcommitted
rcu: Add support for debug_objects debugging for kfree_rcu()
This commit applies RCU's debug_objects debugging to the new batched kfree_rcu() implementations. The object is queued at the kfree_rcu() call and dequeued during reclaim. Tested that enabling CONFIG_DEBUG_OBJECTS_RCU_HEAD successfully detects double kfree_rcu() calls. Signed-off-by: Joel Fernandes (Google) <[email protected]> [ paulmck: Fix IRQ per kbuild test robot <[email protected]> feedback. ] Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 0392beb commit e99637b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

kernel/rcu/tree.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,6 +2749,7 @@ static void kfree_rcu_work(struct work_struct *work)
27492749
for (; head; head = next) {
27502750
next = head->next;
27512751
// Potentially optimize with kfree_bulk in future.
2752+
debug_rcu_head_unqueue(head);
27522753
__rcu_reclaim(rcu_state.name, head);
27532754
cond_resched_tasks_rcu_qs();
27542755
}
@@ -2855,6 +2856,12 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
28552856
spin_lock(&krcp->lock);
28562857

28572858
// Queue the object but don't yet schedule the batch.
2859+
if (debug_rcu_head_queue(head)) {
2860+
// Probable double kfree_rcu(), just leak.
2861+
WARN_ONCE(1, "%s(): Double-freed call. rcu_head %p\n",
2862+
__func__, head);
2863+
goto unlock_return;
2864+
}
28582865
head->func = func;
28592866
head->next = krcp->head;
28602867
krcp->head = head;
@@ -2866,6 +2873,7 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
28662873
schedule_delayed_work(&krcp->monitor_work, KFREE_DRAIN_JIFFIES);
28672874
}
28682875

2876+
unlock_return:
28692877
if (krcp->initialized)
28702878
spin_unlock(&krcp->lock);
28712879
local_irq_restore(flags);

0 commit comments

Comments
 (0)