rcu/kvfree: Invoke debug_rcu_bhead_unqueue() after checking bnode->gp_snap
authorZqiang <qiang1.zhang@intel.com>
Wed, 5 Apr 2023 02:13:59 +0000 (10:13 +0800)
committerPaul E. McKenney <paulmck@kernel.org>
Wed, 10 May 2023 00:26:21 +0000 (17:26 -0700)
If kvfree_rcu_bulk() sees that the required grace period has failed to
elapse, it leaks the memory because readers might still be using it.
But in that case, the debug-objects subsystem still marks the relevant
structures as having been freed, even though they are instead being
leaked.

This commit fixes this mismatch by invoking debug_rcu_bhead_unqueue()
only when we are actually going to free the objects.

Signed-off-by: Zqiang <qiang1.zhang@intel.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
kernel/rcu/tree.c

index 7452ba97ba34e52311237061d83ac3cc1c02004a..426f1f3bb5f2818c47fd4afb756f5d8e5a13b91f 100644 (file)
@@ -2922,8 +2922,8 @@ kvfree_rcu_bulk(struct kfree_rcu_cpu *krcp,
        unsigned long flags;
        int i;
 
-       debug_rcu_bhead_unqueue(bnode);
        if (!WARN_ON_ONCE(!poll_state_synchronize_rcu_full(&bnode->gp_snap))) {
+               debug_rcu_bhead_unqueue(bnode);
                rcu_lock_acquire(&rcu_callback_map);
                if (idx == 0) { // kmalloc() / kfree().
                        trace_rcu_invoke_kfree_bulk_callback(