Re: [PATCH] printk: avoid livelock if another CPU printks continuously

From: Denys Vlasenko
Date: Tue Feb 09 2016 - 11:41:33 EST


On 02/09/2016 04:50 PM, Steven Rostedt wrote:
> On Tue, 09 Feb 2016 16:24:29 +0100
>>>>>> + /* Good, other CPU entered "for(;;)" loop */
>>>>>> + goto out;
>>>>>> + }
>>>>>> + }
>>>>>> + /* No one seems to be willing to take it... */
>>>>>> + if (console_trylock())
>>>>>> + goto again; /* we took it */
>>>>>
>>>>> Perhaps add a few loops to the taking of the console sem.
>>>>
>>>> Why?
>>>>
>>>> If we fail to take the lock, another CPU took it.
>>>> There is no need to try harder, as soon as we know that any
>>>> other CPU took that lock, we can safely exit this function.
>>>
>>> Because if this CPU is the one spamming the other CPU, it will widen
>>> the window to be the one that takes the lock.
>>
>> If we reached this code, we aren't the spamming CPU. We are the CPU
>> which is being spammed (we are in the loop which services the backlog).
>
> No, I mentioned the taking of console sem. The spamming task will be
> trying that a bit, failing and then letting this CPU continue doing its
> bidding.

That's exactly what we *don't* want to happen.
We want that other CPU to get the lock.

How do you plan to achieve that, if not by giving it a grace period
when it can grab a lock?