mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jann Horn <jannh@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Petr Mladek <pmladek@suse.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Cc: linux-kernel@vger.kernel.org, Dennis Zhou <dennis@kernel.org>,
	Tejun Heo <tj@kernel.org>, Christoph Lameter <cl@linux.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Frederic Weisbecker <frederic@kernel.org>
Subject: [PATCH 2/2] printk: Reinitialize klogd percpu state for secondary CPUs
Date: Thu, 26 Mar 2020 17:32:45 +0100	[thread overview]
Message-ID: <20200326163245.119670-3-jannh@google.com> (raw)
In-Reply-To: <20200326163245.119670-1-jannh@google.com>

When printk_deferred() is used before percpu initialization, it will queue
up wake_up_klogd_work and set printk_pending on the boot CPU; percpu
initialization then copies the the pending work's state and the
printk_pending flag to all secondary CPUs. The end result is that e.g.
if you run "dmesg -w" when the system is up, it won't notice new printk
messages.
To ensure that the secondary CPUs don't think that they already have
pending printk work, reset the secondary CPUs' work items and
printk_pending state.

Signed-off-by: Jann Horn <jannh@google.com>
---
 kernel/printk/printk.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index fada22dc4ab6..e531407188f1 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2964,6 +2964,29 @@ static DEFINE_PER_CPU(struct irq_work, wake_up_klogd_work) = {
 	.flags = ATOMIC_INIT(IRQ_WORK_LAZY),
 };
 
+/*
+ * If we called defer_console_output() before fully initializing the percpu
+ * subsystem, e.g. via printk_deferred(), the irq_work flags and the
+ * printk_pending flag may have been copied from the boot CPU to the others
+ * while work was pending.
+ * To fix that, manually reset the percpu data for all secondary processors
+ * before bringing up SMP.
+ */
+static int __init klogd_percpu_fixup(void)
+{
+	int cpu;
+
+	for_each_possible_cpu(cpu) {
+		if (cpu == smp_processor_id())
+			continue;
+		atomic_set(&per_cpu(wake_up_klogd_work.flags, cpu),
+			   IRQ_WORK_LAZY);
+		per_cpu(printk_pending, cpu) = 0;
+	}
+	return 0;
+}
+early_initcall(klogd_percpu_fixup)
+
 void wake_up_klogd(void)
 {
 	preempt_disable();
-- 
2.25.1.696.g5e7596f4ac-goog


  parent reply	other threads:[~2020-03-26 16:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-26 16:32 [PATCH 0/2] Make printk_deferred() work properly before percpu setup is done Jann Horn
2020-03-26 16:32 ` [PATCH 1/2] irq_work: Reinitialize list heads for secondary CPUs Jann Horn
2020-03-26 16:32 ` Jann Horn [this message]
2020-03-27  2:45 ` [PATCH 0/2] Make printk_deferred() work properly before percpu setup is done Sergey Senozhatsky
2020-03-27  3:05   ` Jann Horn
2020-03-27  3:11     ` Sergey Senozhatsky

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=20200326163245.119670-3-jannh@google.com \
    --to=jannh@google.com \
    --cc=cl@linux.com \
    --cc=dennis@kernel.org \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=tj@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

all inboxes | Powered by JetHome®