Sergey Senozhatsky ab6f762f0f printk: queue wake_up_klogd irq_work only if per-CPU areas are ready
printk_deferred(), similarly to printk_safe/printk_nmi, does not
immediately attempt to print a new message on the consoles, avoiding
calls into non-reentrant kernel paths, e.g. scheduler or timekeeping,
which potentially can deadlock the system.

Those printk() flavors, instead, rely on per-CPU flush irq_work to print
messages from safer contexts.  For same reasons (recursive scheduler or
timekeeping calls) printk() uses per-CPU irq_work in order to wake up
user space syslog/kmsg readers.

However, only printk_safe/printk_nmi do make sure that per-CPU areas
have been initialised and that it's safe to modify per-CPU irq_work.
This means that, for instance, should printk_deferred() be invoked "too
early", that is before per-CPU areas are initialised, printk_deferred()
will perform illegal per-CPU access.

Lech Perczak [0] reports that after commit 1b710b1b10ef ("char/random:
silence a lockdep splat with printk()") user-space syslog/kmsg readers
are not able to read new kernel messages.

The reason is printk_deferred() being called too early (as was pointed
out by Petr and John).

Fix printk_deferred() and do not queue per-CPU irq_work before per-CPU
areas are initialized.

Link: https://lore.kernel.org/lkml/aa0732c6-5c4e-8a8b-a1c1-75ebe3dca05b@camlintechnologies.com/
Reported-by: Lech Perczak <l.perczak@camlintechnologies.com>
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Tested-by: Jann Horn <jannh@google.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-04-10 13:18:57 -07:00
..
2020-04-03 15:05:35 -07:00
2020-03-31 21:29:04 +02:00
2020-04-08 21:25:49 -07:00
2019-12-11 09:12:38 +01:00
2019-11-12 11:43:29 -05:00
2020-04-08 21:29:10 -07:00
2020-01-31 14:40:36 -08:00
2020-04-01 18:18:18 -07:00
2020-03-30 10:14:19 +02:00
2020-04-10 12:55:20 -07:00
2020-04-03 15:05:35 -07:00
2020-04-07 19:44:52 -07:00
2020-04-07 13:51:39 -07:00
2020-04-02 15:50:04 -07:00
2020-04-08 21:03:40 -07:00
2020-03-31 10:05:01 -07:00
2020-03-27 12:04:34 -06:00
2020-03-30 11:43:51 -07:00
2020-03-30 01:34:00 +02:00
2020-01-23 00:35:50 +01:00
2020-04-08 11:00:00 -07:00
2019-10-09 19:33:43 -07:00
2020-03-09 11:12:19 +01:00
2020-02-27 14:58:01 +01:00
2019-11-28 11:16:43 -08:00
2019-12-03 11:20:37 +01:00
2020-02-17 13:37:00 +01:00
2020-01-27 11:09:31 +01:00
2020-01-18 09:19:18 -05:00
2020-03-13 12:49:51 -07:00
2020-04-04 11:58:55 -07:00
2019-12-11 12:22:38 -08:00
2020-03-06 11:06:15 +01:00
2020-03-30 11:20:13 -07:00
2020-03-27 20:19:24 -03:00
2020-01-15 16:21:28 +10:00
2019-11-08 08:46:49 -08:00
2019-10-04 12:31:46 -07:00
2019-10-15 13:34:25 +02:00
2020-03-21 16:00:24 +01:00
2019-12-04 19:44:14 -08:00
2020-01-31 17:33:54 +00:00
2020-02-20 21:17:24 +01:00
2019-12-11 09:12:38 +01:00
2020-03-30 18:51:47 -07:00
2020-04-08 21:03:40 -07:00
2020-03-06 11:56:59 +01:00
2020-04-07 10:43:38 -07:00
2020-04-07 10:43:39 -07:00
2020-04-08 21:03:40 -07:00
2020-02-01 10:01:52 -08:00
2019-12-09 10:55:03 +01:00
2020-03-21 16:00:24 +01:00
2019-11-14 19:06:47 -08:00
2020-01-15 10:54:33 -05:00
2020-04-07 13:51:39 -07:00
2020-01-14 12:20:48 +01:00
2019-12-11 16:37:02 +08:00
2020-04-02 09:35:27 -07:00
2020-04-07 10:43:38 -07:00
2019-11-13 19:09:47 +08:00
2020-04-03 14:25:02 -07:00
2020-01-15 16:30:28 +00:00
2020-04-03 14:25:02 -07:00
2020-04-09 12:15:35 -05:00
2020-03-17 18:31:05 +01:00
2020-01-13 18:16:43 -08:00
2019-12-05 11:43:31 -08:00
2019-11-14 13:07:48 +08:00
2020-03-21 16:00:24 +01:00
2020-02-21 10:31:18 +01:00
2020-04-07 10:43:42 -07:00
2020-02-04 03:05:24 +00:00
2020-03-30 12:18:49 -07:00
2020-03-21 16:00:24 +01:00
2020-03-02 14:04:31 -07:00
2019-11-13 12:15:34 -08:00
2020-02-04 03:05:26 +00:00
2020-03-23 13:41:55 +01:00
2020-04-02 09:35:27 -07:00
2020-01-29 19:38:34 -08:00
2020-03-30 18:51:47 -07:00
2020-02-21 11:22:15 -08:00
2020-01-14 12:20:48 +01:00
2020-03-23 17:01:47 +01:00
2020-04-01 12:06:26 -04:00
2020-04-01 12:06:26 -04:00
2020-03-21 18:56:06 -07:00
2020-04-01 12:06:26 -04:00
2019-11-14 12:20:02 +08:00