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

From: John Ogness
Date: Mon Jun 07 2021 - 16:02:41 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-20210607.

v1 can be found here [1].

Changes since v1:

- Keep cpu lock functionality even if !CONFIG_PRINTK. Only make it a
NOP for !CONFIG_SMP.

- Rename the lock/unlock functions to reflect irq disabling/enabling.

- Change first argument of lock/unlock functions to bool. There is
no need to track the previous @printk_cpulock_owner value.

- Change the series to first move over the cpu lock implementation,
then fix ordering in a separate patch.

- Preserve the style from the dump_stack() cpu lock (i.e. goto-retry
instead of for-loop and cmpxchg() instead of try_cmpxchg()).

- Drop the patch that adds serialization to show_regs().

- Fix various typos in comments.

John Ogness

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

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

include/linux/printk.h | 13 ++++++
kernel/printk/printk.c | 101 +++++++++++++++++++++++++++++++++++++++++
lib/dump_stack.c | 41 ++---------------
3 files changed, 118 insertions(+), 37 deletions(-)

--
2.20.1