[PATCH next v3 0/2] introduce printk cpu lock

From: John Ogness
Date: Tue Jun 15 2021 - 13:49:52 EST


Hello,

While working on removing the safe buffers for printk [0] we
stumbled on a cpu-reentrant spinning lock used by dump_stack(). This
type of lock (dubbed a cpu lock) will cause deadlock risks once we
introduce atomic consoles because atomic consoles also need such a
lock.

Although we are not yet ready to introduce atomic consoles, this is
an appropriate time to provide an official cpu lock to be used for
all things relating to printk (including the atomic consoles, once
they are introduced).

This series is against next-20210615.

v2 can be found here [1].

Changes since v2:

- Remove @lock_flag argument from lock/unlock functions. Since there
is only 1 global printk cpu lock, the @lock_flag can be a static
global variable inside printk.c. Also, that flag is renamed to
@printk_cpulock_nested.

- Use typical irqsave/irqrestore calling conventions. This means
changing the lock/unlock functions to macros and set the irq flags
within those macros, rather than passing the irq flags as a
function argument.

- Split the lock function into 2 functions: trylock and wait. This
simplifies the macro implementation. Later, for atomic consoles,
this will be useful because atomic consoles will implement the
waiting component differently.

- Fix a "used uninitialized" warning for !CONFIG_SMP, reported by
the kbuild robot.

- Extend memory barrier comments to cover both "previous to current"
and "current to next" guarantees.

John Ogness

[0] https://lore.kernel.org/lkml/YGW63%2FelFr%2FgYW1u@alley
[1] https://lore.kernel.org/lkml/20210607200232.22211-1-john.ogness@xxxxxxxxxxxxx

John Ogness (2):
dump_stack: move cpu lock to printk.c
printk: fix cpu lock ordering

include/linux/printk.h | 41 +++++++++++++++
kernel/printk/printk.c | 114 +++++++++++++++++++++++++++++++++++++++++
lib/dump_stack.c | 38 +-------------
3 files changed, 157 insertions(+), 36 deletions(-)

--
2.20.1