Re: [PATCH] printk: Correctly handle preemption in console_unlock()

From: Sergey Senozhatsky
Date: Wed Jan 18 2017 - 02:30:07 EST


On (01/18/17 14:45), Sergey Senozhatsky wrote:
[..]
>
> there is a function that clears @console_may_schedule out of
> console_sem scope - console_flush_on_panic().
> so I *may be* can think about a worst case scenario of race
> condition between
> console_flush_on_panic()->console_may_schedule = 0 on panic CPU
> and
> console_unlock()->console_may_schedule = 1 from CPU that panic CPU
> failed to stop (smp_send_stop() can return with secondary CPUs still being
> online).

what I mean, is that we can have, let's say, 2 CPUs spinning in
console_unlock(), both with @console_may_schedule == 1 (because secondary
CPU restores global @console_may_schedule value). now, suppose, we have
misbehaving scheduler (well, we are in panic after all). secondary CPU
will cond_resched() and may be lockup somewhere in the scheduler. which is
fine, we don't care about that secondary CPU anyway. but the same can happen
to panic CPU as well.

what do you think?

-ss