mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Petr Mladek <pmladek@suse.cz>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	linux-kernel@vger.kernel.org, jkosina@suse.cz,
	paulmck@linux.vnet.ibm.com, Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [RFC][PATCH] printk: Fixup the nmi printk mess
Date: Wed, 10 Jun 2015 17:29:17 +0200	[thread overview]
Message-ID: <20150610152917.GI3644@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <20150610143155.GD9409@pathway.suse.cz>

On Wed, Jun 10, 2015 at 04:31:55PM +0200, Petr Mladek wrote:
> > +static void __printk_nmi_flush(struct irq_work *work)
> > +{
> > +	struct nmi_seq_buf *s = container_of(work, struct nmi_seq_buf, work);
> > +	int len, last_i = 0, i = 0;
> > +
> > +again:
> > +	len = seq_buf_used(&s->seq);
> > +	if (!len)
> > +		return;
> > +
> > +	/* Print line by line. */
> > +	for (; i < len; i++) {
> > +		if (s->buffer[i] == '\n') {
> > +			print_seq_line(s, last_i, i);
> > +			last_i = i + 1;
> > +		}
> > +	}
> > +	/* Check if there was a partial line. */
> > +	if (last_i < len) {
> > +		print_seq_line(s, last_i, len - 1);
> > +		pr_cont("\n");
> > +	}
> > +
> > +	/*
> > +	 * Another NMI could have come in while we were printing
> > +	 * check if nothing has been added to the buffer.
> > +	 */
> > +	if (cmpxchg_local(&s->seq.len, len, 0) != len)
> > +		goto again;
> 
> If another NMI comes at this point, it will start filling the buffer
> from the beginning. If it is fast enough, it might override the text
> that we print above.

How so? If the cmpxchg succeeded and len == 0, we flushed everything and
are done with it, if another NMI comes in and 'overwrites' it, that's
fine, right?

> > +static int vprintk_nmi(const char *fmt, va_list args)
> > +{
> > +	struct nmi_seq_buf *s = this_cpu_ptr(&nmi_print_seq);
> > +	unsigned int len = seq_buf_used(&s->seq);
> > +
> > +	irq_work_queue(&s->work);
> > +	seq_buf_vprintf(&s->seq, fmt, args);
> 
> This is more critical. seq_buf_vprintf() has the following code:
> 
> 	len = vsnprintf(s->buffer + s->len, s->size - s->len, fmt, args);
> 
> The race might look like:
> 
> CPU0					CPU1
> 

No, everything is strictly per cpu.

> To be honest, I am not familiar with cmpxchg_local(). But I think that
> it can't do much difference. The value has to be synced to the other
> CPUs one day.

Nope..

  parent reply	other threads:[~2015-06-10 15:36 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-10 12:55 Peter Zijlstra
2015-06-10 14:31 ` Petr Mladek
2015-06-10 14:57   ` Petr Mladek
2015-06-10 15:32     ` Peter Zijlstra
2015-06-10 15:54       ` Steven Rostedt
2015-06-10 15:29   ` Peter Zijlstra [this message]
2015-06-10 19:23     ` Peter Zijlstra
2015-06-10 19:36       ` Peter Zijlstra
2015-06-10 19:36       ` Steven Rostedt
2015-06-11 14:55       ` Petr Mladek
2015-06-12 12:00         ` Peter Zijlstra
2015-06-12 14:28           ` Petr Mladek
2015-06-12 15:35             ` Petr Mladek
2015-06-25 18:14               ` Peter Zijlstra
2015-06-26  8:06                 ` Petr Mladek
2015-06-11  9:57     ` Petr Mladek
2015-06-10 15:53 ` Steven Rostedt
2015-06-10 16:02 ` Steven Rostedt
2015-06-10 16:19   ` Joe Perches
2015-06-10 19:25     ` Peter Zijlstra
2015-06-10 19:35       ` Steven Rostedt
2015-06-10 19:39       ` Joe Perches

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=20150610152917.GI3644@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=pmladek@suse.cz \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /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

Powered by JetHome