From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752069AbdJDJIk (ORCPT ); Wed, 4 Oct 2017 05:08:40 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:46589 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751888AbdJDJIi (ORCPT ); Wed, 4 Oct 2017 05:08:38 -0400 Date: Wed, 4 Oct 2017 11:08:30 +0200 From: Peter Zijlstra To: Steven Rostedt Cc: pmladek@suse.com, sergey.senozhatsky@gmail.com, linux-kernel@vger.kernel.org, mingo@kernel.org, tglx@linutronix.de Subject: Re: [PATCH 3/3] early_printk: Add simple serialization to early_vprintk() Message-ID: <20171004090830.p5kwzu6ex2wimh4v@hirez.programming.kicks-ass.net> References: <20170928121823.430053219@infradead.org> <20170928122513.431444176@infradead.org> <20171003182422.025d0a67@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171003182422.025d0a67@gandalf.local.home> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 03, 2017 at 06:24:22PM -0400, Steven Rostedt wrote: > On Thu, 28 Sep 2017 14:18:26 +0200 > Peter Zijlstra wrote: > > static int early_vprintk(const char *fmt, va_list args) > > { > > + int n, cpu, old; > > char buf[512]; > > + > > + cpu = get_cpu(); > > + /* > > + * Test-and-Set inter-cpu spinlock with recursion. > > + */ > > + for (;;) { > > + /* > > + * c-cas to avoid the exclusive bouncing on spin. > > + * Depends on the memory barrier implied by cmpxchg > > + * for ACQUIRE semantics. > > + */ > > + old = READ_ONCE(early_printk_cpu); > > + if (old == -1) { > > If old != -1 and old != cpu, is it possible that the CPU could have > fetched an old value, and never try to fetch it again? What? If old != -1 and old != cpu, we'll hit the cpu_relax() and do the READ_ONCE() again. The READ_ONCE() guarantees we'll do the load again, as does the barrier() implied by cpu_relax(). > The cmpxchg memory barrier only happens when old == -1. Yeah, so? > > + old = cmpxchg(&early_printk_cpu, -1, cpu); > > + if (old == -1) > > + break; > > + } > > + /* > > + * Allow recursion for interrupts and the like. > > + */ > > + if (old == cpu) > > + break; > > + > > + cpu_relax(); > > + } > > > > n = vscnprintf(buf, sizeof(buf), fmt, args); > > early_console->write(early_console, buf, n); > > > > + /* > > + * Unlock -- in case @old == @cpu, this is a no-op. > > + */ > > + smp_store_release(&early_printk_cpu, old); > > + put_cpu(); > > + > > return n; > > }