Files
Linux/include/linux
Sergey Senozhatsky 099f1c84c0 printk: introduce per-cpu safe_print seq buffer
This patch extends the idea of NMI per-cpu buffers to regions
that may cause recursive printk() calls and possible deadlocks.
Namely, printk() can't handle printk calls from schedule code
or printk() calls from lock debugging code (spin_dump() for instance);
because those may be called with `sem->lock' already taken or any
other `critical' locks (p->pi_lock, etc.). An example of deadlock
can be

 vprintk_emit()
  console_unlock()
   up()                        << raw_spin_lock_irqsave(&sem->lock, flags);
    wake_up_process()
     try_to_wake_up()
      ttwu_queue()
       ttwu_activate()
        activate_task()
         enqueue_task()
          enqueue_task_fair()
           cfs_rq_of()
            task_of()
             WARN_ON_ONCE(!entity_is_task(se))
              vprintk_emit()
               console_trylock()
                down_trylock()
                 raw_spin_lock_irqsave(&sem->lock, flags)
                 ^^^^ deadlock

and some other cases.

Just like in NMI implementation, the solution uses a per-cpu
`printk_func' pointer to 'redirect' printk() calls to a 'safe'
callback, that store messages in a per-cpu buffer and flushes
them back to logbuf buffer later.

Usage example:

 printk()
  printk_safe_enter_irqsave(flags)
  //
  //  any printk() call from here will endup in vprintk_safe(),
  //  that stores messages in a special per-CPU buffer.
  //
  printk_safe_exit_irqrestore(flags)

The 'redirection' mechanism, though, has been reworked, as suggested
by Petr Mladek. Instead of using a per-cpu @print_func callback we now
keep a per-cpu printk-context variable and call either default or nmi
vprintk function depending on its value. printk_nmi_entrer/exit and
printk_safe_enter/exit, thus, just set/celar corresponding bits in
printk-context functions.

The patch only adds printk_safe support, we don't use it yet.

Link: http://lkml.kernel.org/r/[email protected]
Cc: Andrew Morton <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Calvin Owens <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Peter Hurley <[email protected]>
Cc: [email protected]
Signed-off-by: Sergey Senozhatsky <[email protected]>
Signed-off-by: Petr Mladek <[email protected]>
Reviewed-by: Steven Rostedt (VMware) <[email protected]>
2017-02-08 11:07:11 +01:00
..
…
…
…
…
2016-11-17 23:19:00 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
…
2016-12-22 22:58:37 -05:00
…
…
…
…
2016-10-19 14:34:36 -04:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2016-12-08 13:31:11 -05:00
2016-12-17 21:27:44 -05:00
…
…
…
…
…
…
…
…
2016-10-25 11:08:28 +08:00
…
…
2016-12-08 16:37:33 -08:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2016-12-05 19:01:16 -05:00
…
…
…
…
…
…
…
2016-10-28 08:48:16 -06:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2016-11-25 10:15:13 -08:00
…
…
…
…
…
…
2016-12-05 19:01:16 -05:00
…
…
…
…
…
…
…
…
…
…
…
2016-12-05 18:58:32 -05:00
2016-12-25 17:21:22 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2016-12-25 17:21:22 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2016-11-30 14:36:01 +11:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2016-12-12 18:55:06 -08:00
2016-12-25 17:21:23 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2016-11-17 08:24:48 -07:00
…
2016-12-06 11:05:46 +01:00
…
…
…
…
…
…
…
…
…
2016-12-16 00:13:41 +02:00
2016-11-26 11:18:02 -08:00
…
…
…
…
…
…
…
…
…
…
…
…
…
2016-12-08 13:18:35 -05:00
…
2016-11-16 18:32:02 -05:00
…
2016-12-19 17:29:44 -05:00
…
…
…
…
…
…
…
…
…
2016-12-12 18:55:07 -08:00
…
…
…
…
2016-11-10 17:03:35 +01:00
…
…
…
…
…
…
…
2016-12-06 10:17:03 +02:00
…
…
…
…
…
…
…
…
…
2016-12-08 14:21:47 -05:00
…
2016-10-31 16:18:30 -04:00
2016-10-14 11:36:59 -07:00
…
…
…
…
…
…
…
…
…
…
…
…
2016-11-15 16:34:27 -08:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2016-10-31 15:45:18 -07:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2016-12-25 17:21:22 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
2016-12-25 17:21:22 +01:00
…
…
…
…
…
…
…
…
…
…
…
…
2016-12-09 22:12:21 -05:00
…
…
…
…
…
…
…
…
…
…
…
…
…
2016-12-12 18:55:08 -08:00
…
…
…
…
…
2016-12-25 17:21:22 +01:00
…
…
…
…
…
…
…
…
…
…
…