Re: [PATCH 2/2] kdb: Call vkdb_printf() from vprintk_default() only when wanted

From: Petr Mladek
Date: Tue Nov 22 2016 - 07:14:45 EST


On Sun 2016-10-23 22:23:43, Sergey Senozhatsky wrote:
> On (10/21/16 14:50), Petr Mladek wrote:
> [..]
> > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> > index d5e397315473..db73e33811e7 100644
> > --- a/kernel/printk/printk.c
> > +++ b/kernel/printk/printk.c
> > @@ -1941,7 +1941,9 @@ int vprintk_default(const char *fmt, va_list args)
> > int r;
> >
> > #ifdef CONFIG_KGDB_KDB
> > - if (unlikely(kdb_trap_printk)) {
> > + /* Allow to pass printk() to kdb but avoid a recursion. */
> > + if (unlikely(kdb_trap_printk &&
> > + kdb_printf_cpu != smp_processor_id())) {
> ^^^^^
> aren't we are in preemptible here?

Yeah, I looked on this from one side only. "kdb_printf_cpu" is set
with disabled IRQs. Therefore the preemption is disabled if we
are in the recursion scenario. But you are right that we might
get a false positive if we are preempted in the middle of this check
and later scheduled on the CPU that called kdb_vprintf before.

Best Regards,
Petr