This is a note to let you know that I've just added the patch titled printk: declare printk_deferred_{enter,safe}() in include/linux/printk.h to the 4.19-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: printk-declare-printk_deferred_-enter-safe-in-include-linux-printk.h.patch and it can be found in the queue-4.19 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From stable-owner@xxxxxxxxxxxxxxx Sun May 14 06:41:59 2023 From: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> Date: Sun, 14 May 2023 13:41:40 +0900 Subject: printk: declare printk_deferred_{enter,safe}() in include/linux/printk.h To: stable@xxxxxxxxxxxxxxx Cc: John Ogness <john.ogness@xxxxxxxxxxxxx>, Petr Mladek <pmladek@xxxxxxxx>, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Message-ID: <6416445d-cb8e-d7d7-20c0-5df72b2ba664@xxxxxxxxxxxxxxxxxxx> From: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> commit 85e3e7fbbb720b9897fba9a99659e31cbd1c082e upstream. [This patch implements subset of original commit 85e3e7fbbb72 ("printk: remove NMI tracking") where commit 1007843a9190 ("mm/page_alloc: fix potential deadlock on zonelist_update_seq seqlock") depends on, for commit 3d36424b3b58 ("mm/page_alloc: fix race condition between build_all_zonelists and page allocation") was backported to stable.] All NMI contexts are handled the same as the safe context: store the message and defer printing. There is no need to have special NMI context tracking for this. Using in_nmi() is enough. There are several parts of the kernel that are manually calling into the printk NMI context tracking in order to cause general printk deferred printing: arch/arm/kernel/smp.c arch/powerpc/kexec/crash.c kernel/trace/trace.c For arm/kernel/smp.c and powerpc/kexec/crash.c, provide a new function pair printk_deferred_enter/exit that explicitly achieves the same objective. For ftrace, remove the printk context manipulation completely. It was added in commit 03fc7f9c99c1 ("printk/nmi: Prevent deadlock when accessing the main log buffer in NMI"). The purpose was to enforce storing messages directly into the ring buffer even in NMI context. It really should have only modified the behavior in NMI context. There is no need for a special behavior any longer. All messages are always stored directly now. The console deferring is handled transparently in vprintk(). Signed-off-by: John Ogness <john.ogness@xxxxxxxxxxxxx> [pmladek@xxxxxxxx: Remove special handling in ftrace.c completely. Signed-off-by: Petr Mladek <pmladek@xxxxxxxx> Link: https://lore.kernel.org/r/20210715193359.25946-5-john.ogness@xxxxxxxxxxxxx [penguin-kernel: Copy only printk_deferred_{enter,safe}() definition ] Signed-off-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- include/linux/printk.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) --- a/include/linux/printk.h +++ b/include/linux/printk.h @@ -525,4 +525,23 @@ static inline void print_hex_dump_debug( } #endif +#ifdef CONFIG_PRINTK +extern void __printk_safe_enter(void); +extern void __printk_safe_exit(void); +/* + * The printk_deferred_enter/exit macros are available only as a hack for + * some code paths that need to defer all printk console printing. Interrupts + * must be disabled for the deferred duration. + */ +#define printk_deferred_enter __printk_safe_enter +#define printk_deferred_exit __printk_safe_exit +#else +static inline void printk_deferred_enter(void) +{ +} +static inline void printk_deferred_exit(void) +{ +} +#endif + #endif Patches currently in stable-queue which might be from stable-owner@xxxxxxxxxxxxxxx are queue-4.19/serial-8250-fix-serial8250_tx_empty-race-with-dma-tx.patch queue-4.19/printk-declare-printk_deferred_-enter-safe-in-include-linux-printk.h.patch queue-4.19/pci-pciehp-fix-ab-ba-deadlock-between-reset_lock-and-device_lock.patch queue-4.19/tty-prevent-writing-chars-during-tcsetattr-tcsadrain-flush.patch queue-4.19/pci-pciehp-use-down_read-write_nested-reset_lock-to-fix-lockdep-errors.patch