Re: [PATCH] printk: Fix spinlock deadlock in printk reenty

From: Peter Zijlstra
Date: Wed Nov 30 2016 - 06:31:25 EST


On Wed, Nov 30, 2016 at 11:56:53AM +0100, Petr Mladek wrote:
> On Wed 2016-11-30 15:15:19, linyongting@xxxxxxxxxx wrote:
> > In arm, arm64, x86 or other architecture, spinlock variable

x86 no longer uses ticket locks.

> > The solution is that In function zap_locks(), replace
> > raw_spin_lock_init(&logbuf_lock) with raw_spin_unlock(&logbuf_lock),

That's broken too. Imagine the CPU that actually holds the lock then
_also_ doing an unlock. At that point the tail is ahead of the head and
you're also up some creek without no paddle.

Note that I ran into all these scenarios many years ago..

> Another solution would be to make printk() to ignore locks
> when Oops is in progress. It was somewhere suggested by Peter
> Zijlstra. Well, it might cause some problems as well when
> there are more CPUs still running and printing.

Ignoring is the only option. There is no way to fudge the lock state and
live to tell about it.