locking/lockdep: Fix bad recursion pattern
authorPeter Zijlstra <peterz@infradead.org>
Fri, 13 Mar 2020 08:56:38 +0000 (09:56 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 20 Mar 2020 12:06:25 +0000 (13:06 +0100)
commit10476e6304222ced7df9b3d5fb0a043b3c2a1ad8
treeffabb7c1514caad90cace22b593c01300d05a7a8
parent25016bd7f4caf5fc983bbab7403d08e64cba3004
locking/lockdep: Fix bad recursion pattern

There were two patterns for lockdep_recursion:

Pattern-A:
if (current->lockdep_recursion)
return

current->lockdep_recursion = 1;
/* do stuff */
current->lockdep_recursion = 0;

Pattern-B:
current->lockdep_recursion++;
/* do stuff */
current->lockdep_recursion--;

But a third pattern has emerged:

Pattern-C:
current->lockdep_recursion = 1;
/* do stuff */
current->lockdep_recursion = 0;

And while this isn't broken per-se, it is highly dangerous because it
doesn't nest properly.

Get rid of all Pattern-C instances and shore up Pattern-A with a
warning.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200313093325.GW12561@hirez.programming.kicks-ass.net
kernel/locking/lockdep.c