OSDN Git Service

sched/core: Fix DEBUG_SPINLOCK annotation for rq->lock
authorPeter Zijlstra <peterz@infradead.org>
Tue, 6 Feb 2018 16:52:13 +0000 (17:52 +0100)
committerIngo Molnar <mingo@kernel.org>
Tue, 13 Feb 2018 10:44:41 +0000 (11:44 +0100)
commit269d599271fa604f09d5cb0093c5dd5d59964dd5
treee6cb32acb59211a8842d78f3590ba54165ae8491
parenta7711602c7b79950ea437178f601b52ab08ef659
sched/core: Fix DEBUG_SPINLOCK annotation for rq->lock

Mark noticed that he had sporadic "spinlock recursion" warnings from
the DEBUG_SPINLOCK code. Now rq->lock is special in that the owner
changes in the middle of a context switch.

It so happens that we fix up the lock.owner too late, @prev can run
(remotely) the moment prev->on_cpu is cleared, this then allows @prev
to again try and acquire this rq->lock and trigger this warning.

So we have to switch lock.owner before clearing prev->on_cpu.

Do this by moving the DEBUG_SPINLOCK annotation from after switch_to()
to before switch_to() and collect all lockdep annotations there into
prepare_lock_switch() to mirror the existing finish_lock_switch().

Debugged-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/sched/core.c