From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev, John Ogness <john.ogness@linutronix.de>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Petr Mladek <pmladek@suse.com>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.15 060/110] printk: Consolidate console deferred printing
Date: Wed, 20 Sep 2023 13:31:58 +0200 [thread overview]
Message-ID: <20230920112832.656468075@linuxfoundation.org> (raw)
In-Reply-To: <20230920112830.377666128@linuxfoundation.org>
5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Ogness <john.ogness@linutronix.de>
[ Upstream commit 696ffaf50e1f8dbc66223ff614473f945f5fb8d8 ]
Printing to consoles can be deferred for several reasons:
- explicitly with printk_deferred()
- printk() in NMI context
- recursive printk() calls
The current implementation is not consistent. For printk_deferred(),
irq work is scheduled twice. For NMI und recursive, panic CPU
suppression and caller delays are not properly enforced.
Correct these inconsistencies by consolidating the deferred printing
code so that vprintk_deferred() is the top-level function for
deferred printing and vprintk_emit() will perform whichever irq_work
queueing is appropriate.
Also add kerneldoc for wake_up_klogd() and defer_console_output() to
clarify their differences and appropriate usage.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20230717194607.145135-6-john.ogness@linutronix.de
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/printk/printk.c | 35 ++++++++++++++++++++++++++++-------
kernel/printk/printk_safe.c | 9 ++-------
2 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 8d856b7c2e5af..8b110b245d92c 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2269,7 +2269,11 @@ asmlinkage int vprintk_emit(int facility, int level,
preempt_enable();
}
- wake_up_klogd();
+ if (in_sched)
+ defer_console_output();
+ else
+ wake_up_klogd();
+
return printed_len;
}
EXPORT_SYMBOL(vprintk_emit);
@@ -3277,11 +3281,33 @@ static void __wake_up_klogd(int val)
preempt_enable();
}
+/**
+ * wake_up_klogd - Wake kernel logging daemon
+ *
+ * Use this function when new records have been added to the ringbuffer
+ * and the console printing of those records has already occurred or is
+ * known to be handled by some other context. This function will only
+ * wake the logging daemon.
+ *
+ * Context: Any context.
+ */
void wake_up_klogd(void)
{
__wake_up_klogd(PRINTK_PENDING_WAKEUP);
}
+/**
+ * defer_console_output - Wake kernel logging daemon and trigger
+ * console printing in a deferred context
+ *
+ * Use this function when new records have been added to the ringbuffer,
+ * this context is responsible for console printing those records, but
+ * the current context is not allowed to perform the console printing.
+ * Trigger an irq_work context to perform the console printing. This
+ * function also wakes the logging daemon.
+ *
+ * Context: Any context.
+ */
void defer_console_output(void)
{
/*
@@ -3298,12 +3324,7 @@ void printk_trigger_flush(void)
int vprintk_deferred(const char *fmt, va_list args)
{
- int r;
-
- r = vprintk_emit(0, LOGLEVEL_SCHED, NULL, fmt, args);
- defer_console_output();
-
- return r;
+ return vprintk_emit(0, LOGLEVEL_SCHED, NULL, fmt, args);
}
int _printk_deferred(const char *fmt, ...)
diff --git a/kernel/printk/printk_safe.c b/kernel/printk/printk_safe.c
index ef0f9a2044da1..6d10927a07d83 100644
--- a/kernel/printk/printk_safe.c
+++ b/kernel/printk/printk_safe.c
@@ -38,13 +38,8 @@ asmlinkage int vprintk(const char *fmt, va_list args)
* Use the main logbuf even in NMI. But avoid calling console
* drivers that might have their own locks.
*/
- if (this_cpu_read(printk_context) || in_nmi()) {
- int len;
-
- len = vprintk_store(0, LOGLEVEL_DEFAULT, NULL, fmt, args);
- defer_console_output();
- return len;
- }
+ if (this_cpu_read(printk_context) || in_nmi())
+ return vprintk_deferred(fmt, args);
/* No obstacles. */
return vprintk_default(fmt, args);
--
2.40.1
next prev parent reply other threads:[~2023-09-20 12:47 UTC|newest]
Thread overview: 123+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-20 11:30 [PATCH 5.15 000/110] 5.15.133-rc1 review Greg Kroah-Hartman
2023-09-20 11:30 ` [PATCH 5.15 001/110] autofs: fix memory leak of waitqueues in autofs_catatonic_mode Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 002/110] btrfs: output extra debug info if we failed to find an inline backref Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 003/110] locks: fix KASAN: use-after-free in trace_event_raw_event_filelock_lock Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 004/110] ACPICA: Add AML_NO_OPERAND_RESOLVE flag to Timer Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 005/110] kernel/fork: beware of __put_task_struct() calling context Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 006/110] rcuscale: Move rcu_scale_writer() schedule_timeout_uninterruptible() to _idle() Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 007/110] scftorture: Forgive memory-allocation failure if KASAN Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 008/110] ACPI: video: Add backlight=native DMI quirk for Lenovo Ideapad Z470 Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 009/110] perf/smmuv3: Enable HiSilicon Erratum 162001900 quirk for HIP08/09 Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 010/110] perf/imx_ddr: speed up overflow frequency of cycle Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 011/110] hw_breakpoint: fix single-stepping when using bpf_overflow_handler Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 012/110] ACPI: x86: s2idle: Catch multiple ACPI_TYPE_PACKAGE objects Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 013/110] devlink: remove reload failed checks in params get/set callbacks Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 014/110] crypto: lrw,xts - Replace strlcpy with strscpy Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 015/110] wifi: ath9k: fix fortify warnings Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 016/110] wifi: ath9k: fix printk specifier Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 017/110] wifi: mwifiex: fix fortify warning Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 018/110] wifi: wil6210: fix fortify warnings Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 019/110] crypto: lib/mpi - avoid null pointer deref in mpi_cmp_ui() Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 020/110] tpm_tis: Resend command to recover from data transfer errors Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 021/110] mmc: sdhci-esdhc-imx: improve ESDHC_FLAG_ERR010450 Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 022/110] alx: fix OOB-read compiler warning Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 023/110] wifi: mac80211: check S1G action frame size Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 024/110] netfilter: ebtables: fix fortify warnings in size_entry_mwt() Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 025/110] wifi: mac80211_hwsim: drop short frames Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 026/110] libbpf: Free btf_vmlinux when closing bpf_object Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 027/110] drm/bridge: tc358762: Instruct DSI host to generate HSE packets Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 028/110] arm64: dts: qcom: sm6125-pdx201: correct ramoops pmsg-size Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 029/110] arm64: dts: qcom: sm8150-kumano: " Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 030/110] arm64: dts: qcom: sm8250-edo: " Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 031/110] samples/hw_breakpoint: Fix kernel BUG invalid opcode: 0000 Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 032/110] ALSA: hda: intel-dsp-cfg: add LunarLake support Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 033/110] drm/amd/display: Blocking invalid 420 modes on HDMI TMDS for DCN31 Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 034/110] drm/exynos: fix a possible null-pointer dereference due to data race in exynos_drm_crtc_atomic_disable() Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 035/110] bus: ti-sysc: Configure uart quirks for k3 SoC Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 036/110] md: raid1: fix potential OOB in raid1_remove_disk() Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 037/110] ext2: fix datatype of block number in ext2_xattr_set2() Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 038/110] fs/jfs: prevent double-free in dbUnmount() after failed jfs_remount() Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 039/110] jfs: fix invalid free of JFS_IP(ipimap)->i_imap in diUnmount Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 040/110] ARM: 9317/1: kexec: Make smp stop calls asynchronous Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 041/110] powerpc/pseries: fix possible memory leak in ibmebus_bus_init() Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 042/110] PCI: fu740: Set the number of MSI vectors Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 043/110] media: dvb-usb-v2: af9035: Fix null-ptr-deref in af9035_i2c_master_xfer Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 044/110] media: dw2102: Fix null-ptr-deref in dw2102_i2c_transfer() Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 045/110] media: af9005: Fix null-ptr-deref in af9005_i2c_xfer Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 046/110] media: anysee: fix null-ptr-deref in anysee_master_xfer Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 047/110] media: az6007: Fix null-ptr-deref in az6007_i2c_xfer() Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 048/110] media: dvb-usb-v2: gl861: Fix null-ptr-deref in gl861_i2c_master_xfer Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 049/110] media: tuners: qt1010: replace BUG_ON with a regular error Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 050/110] media: pci: cx23885: replace BUG with error return Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 051/110] usb: cdns3: Put the cdns set active part outside the spin lock Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 052/110] usb: gadget: fsl_qe_udc: validate endpoint index for ch9 udc Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 053/110] tools: iio: iio_generic_buffer: Fix some integer type and calculation Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 054/110] scsi: target: iscsi: Fix buffer overflow in lio_target_nacl_info_show() Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 055/110] serial: cpm_uart: Avoid suspicious locking Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 056/110] usb: ehci: add workaround for chipidea PORTSC.PEC bug Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 057/110] media: pci: ipu3-cio2: Initialise timing struct to avoid a compiler warning Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 058/110] kobject: Add sanity check for kset->kobj.ktype in kset_register() Greg Kroah-Hartman
2023-09-20 11:31 ` [PATCH 5.15 059/110] interconnect: Fix locking for runpm vs reclaim Greg Kroah-Hartman
2023-09-20 11:31 ` Greg Kroah-Hartman [this message]
2023-09-20 11:31 ` [PATCH 5.15 061/110] jbd2: refactor wait logic for transaction updates into a common function Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 062/110] jbd2: fix use-after-free of transaction_t race Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 063/110] jbd2: kill t_handle_lock transaction spinlock Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 064/110] jbd2: rename jbd_debug() to jbd2_debug() Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 065/110] jbd2: correct the end of the journal recovery scan range Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 066/110] mtd: rawnand: brcmnand: Allow SoC to provide I/O operations Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 067/110] mtd: rawnand: brcmnand: Fix ECC level field setting for v7.2 controller Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 068/110] MIPS: Use "grep -E" instead of "egrep" Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 069/110] perf jevents: Switch build to use jevents.py Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 070/110] perf build: Update build rule for generated files Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 071/110] perf test: Remove bash construct from stat_bpf_counters.sh test Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 072/110] perf test shell stat_bpf_counters: Fix test on Intel Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 073/110] btrfs: move btrfs_pinned_by_swapfile prototype into volumes.h Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 074/110] btrfs: add a helper to read the superblock metadata_uuid Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 075/110] btrfs: compare the correct fsid/metadata_uuid in btrfs_validate_super Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 076/110] drm: gm12u320: Fix the timeout usage for usb_bulk_msg() Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 077/110] scsi: qla2xxx: Fix NULL vs IS_ERR() bug for debugfs_create_dir() Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 078/110] selftests: tracing: Fix to unmount tracefs for recovering environment Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 079/110] scsi: lpfc: Fix the NULL vs IS_ERR() bug for debugfs_create_file() Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 080/110] x86/boot/compressed: Reserve more memory for page tables Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 081/110] x86/purgatory: Remove LTO flags Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 082/110] netfilter: nf_tables: make validation state per table Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 083/110] netfilter: nf_tables: GC transaction API to avoid race with control plane Greg Kroah-Hartman
2023-09-20 14:02 ` Pablo Neira Ayuso
2023-09-21 9:28 ` Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 084/110] netfilter: nf_tables: adapt set backend to use GC transaction API Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 085/110] netfilter: nft_set_hash: mark set element as dead when deleting from packet path Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 086/110] netfilter: nf_tables: remove busy mark and gc batch API Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 087/110] netfilter: nf_tables: fix kdoc warnings after gc rework Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 088/110] netfilter: nf_tables: fix GC transaction races with netns and netlink event exit path Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 089/110] netfilter: nf_tables: GC transaction race with netns dismantle Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 090/110] samples/hw_breakpoint: fix building without module unloading Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 091/110] md/raid1: fix error: ISO C90 forbids mixed declarations Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 092/110] attr: block mode changes of symlinks Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 093/110] ovl: fix failed copyup of fileattr on a symlink Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 094/110] ovl: fix incorrect fdput() on aio completion Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 095/110] btrfs: fix lockdep splat and potential deadlock after failure running delayed items Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 096/110] btrfs: release path before inode lookup during the ino lookup ioctl Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 097/110] tracing: Have tracing_max_latency inc the trace array ref count Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 098/110] tracing: Have current_trace " Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 099/110] tracing: Have option files " Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 100/110] nfsd: fix change_info in NFSv4 RENAME replies Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 101/110] tracefs: Add missing lockdown check to tracefs_create_dir() Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 102/110] i2c: aspeed: Reset the i2c controller when timeout occurs Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 103/110] ata: libata: disallow dev-initiated LPM transitions to unsupported states Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 104/110] scsi: megaraid_sas: Fix deadlock on firmware crashdump Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 105/110] scsi: pm8001: Setup IRQs on resume Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 106/110] ext4: fix rec_len verify error Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 107/110] drm/amd/display: fix the white screen issue when >= 64GB DRAM Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 108/110] drm/amdgpu: fix amdgpu_cs_p1_user_fence Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 109/110] net/sched: Retire rsvp classifier Greg Kroah-Hartman
2023-09-20 11:32 ` [PATCH 5.15 110/110] drm/amd/display: enable cursor degamma for DCN3+ DRM legacy gamma Greg Kroah-Hartman
2023-09-20 14:21 ` [PATCH 5.15 000/110] 5.15.133-rc1 review SeongJae Park
2023-09-20 18:47 ` Florian Fainelli
2023-09-23 8:21 ` Greg Kroah-Hartman
2023-09-20 21:34 ` Shuah Khan
2023-09-21 12:25 ` Guenter Roeck
2023-09-21 13:55 ` Naresh Kamboju
2023-09-21 16:01 ` Guenter Roeck
2023-09-21 20:38 ` Joel Fernandes
2023-09-21 22:05 ` Ron Economos
2023-09-22 9:19 ` Jon Hunter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230920112832.656468075@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=john.ogness@linutronix.de \
--cc=patches@lists.linux.dev \
--cc=pmladek@suse.com \
--cc=sashal@kernel.org \
--cc=senozhatsky@chromium.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox