Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964976AbbFJTgY (ORCPT ); Wed, 10 Jun 2015 15:36:24 -0400 Received: from casper.infradead.org ([85.118.1.10]:34076 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933679AbbFJTgQ (ORCPT ); Wed, 10 Jun 2015 15:36:16 -0400 Date: Wed, 10 Jun 2015 21:36:12 +0200 From: Peter Zijlstra To: Petr Mladek Cc: Steven Rostedt , linux-kernel@vger.kernel.org, jkosina@suse.cz, paulmck@linux.vnet.ibm.com, Ingo Molnar , Thomas Gleixner Subject: Re: [RFC][PATCH] printk: Fixup the nmi printk mess Message-ID: <20150610193612.GZ18673@twins.programming.kicks-ass.net> References: <20150610125509.GO19282@twins.programming.kicks-ass.net> <20150610143155.GD9409@pathway.suse.cz> <20150610152917.GI3644@twins.programming.kicks-ass.net> <20150610192304.GY18673@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150610192304.GY18673@twins.programming.kicks-ass.net> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1362 Lines: 46 On Wed, Jun 10, 2015 at 09:23:04PM +0200, Peter Zijlstra wrote: > +static int vprintk_nmi(const char *fmt, va_list args) > +{ > + struct nmi_seq_buf *s = this_cpu_ptr(&nmi_print_seq); > + int add = -1, len; > + > + irq_work_queue(&s->work); > + > + /* > + * head > tail; indicates someone is writing. > + * avoids the buffer being truncated. > + * > + * we rely on the memory barrier to ensure the increment > + * is visible before we start writing to the buffer. > + */ > + len = atomic_inc_return(&s->head); That wants to be: len = atomic_inc_return(&s->head) - 1; we need the value before the increment, not after it. > + > + if (len < sizeof(s->buffer)) { > + add = vsnprintf(s->buffer + len, sizeof(s->buffer) - len, fmt, args); > + /* > + * Fwd head to the right location; NMIs do not nest, therefore > + * we can use regular stores. > + */ > + atomic_set(&s->head, len + add); > + /* > + * Once the data is written and head is correct, update tail to > + * match; indicating we're complete. > + */ > + smp_wmb(); > + atomic_set(&s->tail, len + add); > + } > + > + return add; > +} -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/