Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp1643185imb; Sun, 3 Mar 2019 01:29:16 -0800 (PST) X-Google-Smtp-Source: APXvYqy4p1vltxJqDTYtkmglCQ+5hoNd9ZDuD0tf90IBNSVlqAstEqw8AmcBZEUEkyUffoxQ/wSx X-Received: by 2002:a65:608c:: with SMTP id t12mr13385705pgu.400.1551605356432; Sun, 03 Mar 2019 01:29:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551605356; cv=none; d=google.com; s=arc-20160816; b=kD65CVxBc7vYXfTIxh0AmTqPqZxamgQT/WaMR6gzxdlNzxP1y8MvlcQM6BZuA8HTiQ 9qprcJzC9rIIUuJeyyLcxBcXT1YcW2Za5CdQyMdmunilYY9vTPtH6gn+bCAlE3vBXHhS NkLWInXHLs/DaT4dfHb0h7BXfoXwEDaYrVP/F+2M0slWO/WFsKUt4Ll3o3ZL5oKVNJYr DFFAhy29v2dxHs+v3lBlVa6ZmlI3j9fwt4iAeWUBkcQW3PZARvL0KPBAGtxG14M+indY 3lajiY+iju79mypeswGSv+m40zmkJjbZfzkZCoRVqbxoN0lbVwg0u7MFpUBww2H2Q+Hg vhug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=JQik9syv89UNojO6S5bWEnQYvpA0xTZOUGdX6G1tszE=; b=R5GHz/nqLLUfe1zy0n64PpC4vvTyjOtXKpxU+7X9rSXbXUJR2ghmGf9ETn0zJguAKq 7CHore8avzch/UZqpJCJYXOlzcC+NO+K/lWnlSNtPXzxbbrgwdqY3gaJITXR9elnPLI2 oERwxZVIPz78BEPm80G+FOaesNK6+mFQlGXHA5w0ZPvRrLV5UiEOetSJkuMThNxye8qj m4qH8qyJzeIUdLJRIlpuS4R6AYqeWIf2TOX49xEBQxzj1ka17DP84uCUjMdc3BzS3EqW qr7tgVPwYQXzFhZuA32Cnib0wOCF2X+zsZwckh1ldrl/tkc8zJ0ByjCn40/wAsCIkwCS wT7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3si2559919pfd.250.2019.03.03.01.28.33; Sun, 03 Mar 2019 01:29:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726022AbfCCJ0o (ORCPT + 99 others); Sun, 3 Mar 2019 04:26:44 -0500 Received: from ozlabs.org ([203.11.71.1]:47799 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725877AbfCCJ0n (ORCPT ); Sun, 3 Mar 2019 04:26:43 -0500 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 44ByTS2pX4z9s4Y; Sun, 3 Mar 2019 20:26:36 +1100 (AEDT) From: Michael Ellerman To: Nicholas Piggin , linux-arch@vger.kernel.org, Will Deacon Cc: Andrea Parri , Arnd Bergmann , Benjamin Herrenschmidt , Rich Felker , David Howells , Daniel Lustig , linux-kernel@vger.kernel.org, "Maciej W. Rozycki" , Ingo Molnar , Palmer Dabbelt , Paul Burton , "Paul E. McKenney" , Peter Zijlstra , Alan Stern , Tony Luck , Linus Torvalds , Yoshinori Sato Subject: Re: [PATCH 01/20] asm-generic/mmiowb: Add generic implementation of mmiowb() tracking In-Reply-To: <1551575210.6lwpiqtg5k.astroid@bobo.none> References: <20190301140348.25175-1-will.deacon@arm.com> <20190301140348.25175-2-will.deacon@arm.com> <1551575210.6lwpiqtg5k.astroid@bobo.none> Date: Sun, 03 Mar 2019 20:26:35 +1100 Message-ID: <87tvgkia0k.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Nicholas Piggin writes: > Will Deacon's on March 2, 2019 12:03 am: >> In preparation for removing all explicit mmiowb() calls from driver >> code, implement a tracking system in asm-generic based loosely on the >> PowerPC implementation. This allows architectures with a non-empty >> mmiowb() definition to have the barrier automatically inserted in >> spin_unlock() following a critical section containing an I/O write. > > Is there a reason to call this "mmiowb"? We already have wmb that > orders cacheable stores vs mmio stores don't we? > > Yes ia64 "sn2" is broken in that case, but that can be fixed (if > anyone really cares about the platform any more). Maybe that's > orthogonal to what you're doing here, I just don't like seeing > "mmiowb" spread. > > This series works for spin locks, but you would want a driver to > be able to use wmb() to order locks vs mmio when using a bit lock > or a mutex or whatever else. Calling your wmb-if-io-is-pending > version io_mb_before_unlock() would kind of match with existing > patterns. > >> +static inline void mmiowb_set_pending(void) >> +{ >> + struct mmiowb_state *ms = __mmiowb_state(); >> + ms->mmiowb_pending = ms->nesting_count; >> +} >> + >> +static inline void mmiowb_spin_lock(void) >> +{ >> + struct mmiowb_state *ms = __mmiowb_state(); >> + ms->nesting_count++; >> +} >> + >> +static inline void mmiowb_spin_unlock(void) >> +{ >> + struct mmiowb_state *ms = __mmiowb_state(); >> + >> + if (unlikely(ms->mmiowb_pending)) { >> + ms->mmiowb_pending = 0; >> + mmiowb(); >> + } >> + >> + ms->nesting_count--; >> +} > > Humour me for a minute and tell me what this algorithm is doing, or > what was broken about the powerpc one, which is basically: > > static inline void mmiowb_set_pending(void) > { > struct mmiowb_state *ms = __mmiowb_state(); > ms->mmiowb_pending = 1; > } > > static inline void mmiowb_spin_lock(void) > { > } The current powerpc code clears io_sync in spin_lock(). ie, it would be equivalent to: static inline void mmiowb_spin_lock(void) { ms->mmiowb_pending = 0; } Which means that: spin_lock(a); writel(x, y); spin_lock(b); ... spin_unlock(b); spin_unlock(a); Does no barrier. cheers