Skip to content

Commit

Permalink
rcu/tree: Move kfree_rcu_cpu locking/unlocking to separate functions
Browse files Browse the repository at this point in the history
Introduce helpers to lock and unlock per-cpu "kfree_rcu_cpu"
structures. That will make kfree_call_rcu() more readable
and prevent programming errors.

Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
  • Loading branch information
Uladzislau Rezki (Sony) authored and Paul E. McKenney committed Jun 29, 2020
1 parent 3af8486 commit 952371d
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions kernel/rcu/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -3035,6 +3035,27 @@ debug_rcu_bhead_unqueue(struct kfree_rcu_bulk_data *bhead)
#endif
}

static inline struct kfree_rcu_cpu *
krc_this_cpu_lock(unsigned long *flags)
{
struct kfree_rcu_cpu *krcp;

local_irq_save(*flags); // For safely calling this_cpu_ptr().
krcp = this_cpu_ptr(&krc);
if (likely(krcp->initialized))
raw_spin_lock(&krcp->lock);

return krcp;
}

static inline void
krc_this_cpu_unlock(struct kfree_rcu_cpu *krcp, unsigned long flags)
{
if (likely(krcp->initialized))
raw_spin_unlock(&krcp->lock);
local_irq_restore(flags);
}

/*
* This function is invoked in workqueue context after a grace period.
* It frees all the objects queued on ->bhead_free or ->head_free.
Expand Down Expand Up @@ -3260,11 +3281,7 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
struct kfree_rcu_cpu *krcp;
void *ptr;

local_irq_save(flags); // For safely calling this_cpu_ptr().
krcp = this_cpu_ptr(&krc);
if (krcp->initialized)
raw_spin_lock(&krcp->lock);

krcp = krc_this_cpu_lock(&flags);
ptr = (void *)head - (unsigned long)func;

// Queue the object but don't yet schedule the batch.
Expand Down Expand Up @@ -3295,9 +3312,7 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
}

unlock_return:
if (krcp->initialized)
raw_spin_unlock(&krcp->lock);
local_irq_restore(flags);
krc_this_cpu_unlock(krcp, flags);
}
EXPORT_SYMBOL_GPL(kfree_call_rcu);

Expand Down

0 comments on commit 952371d

Please sign in to comment.