Re: [tip: locking/core] lockdep: Fix lockdep recursion

From: Peter Zijlstra
Date: Tue Oct 13 2020 - 06:27:42 EST


On Mon, Oct 12, 2020 at 11:11:10AM +0800, Boqun Feng wrote:

> I think this happened because in this commit debug_lockdep_rcu_enabled()
> didn't adopt to the change that made lockdep_recursion a percpu
> variable?
>
> Qian, mind to try the following?
>
> Although, arguably the problem still exists, i.e. we still have an RCU
> read-side critical section inside lock_acquire(), which may be called on

There is actual RCU usage from the trace_lock_acquire().

> a yet-to-online CPU, which RCU doesn't watch. I think this used to be OK
> because we don't "free" anything from lockdep, IOW, there is no
> synchronize_rcu() or call_rcu() that _needs_ to wait for the RCU
> read-side critical sections inside lockdep. But now we lock class
> recycling, so it might be a problem.
>
> That said, currently validate_chain() and lock class recycling are
> mutually excluded via graph_lock, so we are safe for this one ;-)

We should have a comment on that somewhere, could you write one?

> ----------->8
> diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
> index 39334d2d2b37..35d9bab65b75 100644
> --- a/kernel/rcu/update.c
> +++ b/kernel/rcu/update.c
> @@ -275,8 +275,8 @@ EXPORT_SYMBOL_GPL(rcu_callback_map);
>
> noinstr int notrace debug_lockdep_rcu_enabled(void)
> {
> - return rcu_scheduler_active != RCU_SCHEDULER_INACTIVE && debug_locks &&
> - current->lockdep_recursion == 0;
> + return rcu_scheduler_active != RCU_SCHEDULER_INACTIVE &&
> + __lockdep_enabled;
> }
> EXPORT_SYMBOL_GPL(debug_lockdep_rcu_enabled);

Urgh, I didn't expect (and forgot to grep) lockdep_recursion users
outside of lockdep itself :/ It looks like this is indeed the only one.