From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751505AbdFHMUA (ORCPT ); Thu, 8 Jun 2017 08:20:00 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:51415 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751413AbdFHMT7 (ORCPT ); Thu, 8 Jun 2017 08:19:59 -0400 Date: Thu, 8 Jun 2017 14:19:44 +0200 From: Peter Zijlstra To: Will Deacon Cc: Vlastimil Babka , "Kirill A. Shutemov" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, mark.rutland@arm.com, akpm@linux-foundation.org, Punit.Agrawal@arm.com, mgorman@suse.de, steve.capper@arm.com Subject: Re: [PATCH 2/3] mm/page_ref: Ensure page_ref_unfreeze is ordered against prior accesses Message-ID: <20170608121944.yx7z7bv47it6zxpq@hirez.programming.kicks-ass.net> References: <1496771916-28203-1-git-send-email-will.deacon@arm.com> <1496771916-28203-3-git-send-email-will.deacon@arm.com> <20170608104056.ujuytybmwumuty64@black.fi.intel.com> <20170608112433.GH6071@arm.com> <20170608121641.lpomved4hi74worl@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170608121641.lpomved4hi74worl@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 08, 2017 at 02:16:41PM +0200, Peter Zijlstra wrote: > On Thu, Jun 08, 2017 at 12:24:33PM +0100, Will Deacon wrote: > > The horribly out-of-date atomic_ops.txt isn't so useful: > > > > | If a caller requires memory barrier semantics around an atomic_t > > | operation which does not return a value, a set of interfaces are > > | defined which accomplish this:: > > | > > | void smp_mb__before_atomic(void); > > | void smp_mb__after_atomic(void); > > | > > | For example, smp_mb__before_atomic() can be used like so:: > > | > > | obj->dead = 1; > > | smp_mb__before_atomic(); > > | atomic_dec(&obj->ref_count); > > | > > | It makes sure that all memory operations preceding the atomic_dec() > > | call are strongly ordered with respect to the atomic counter > > | operation. In the above example, it guarantees that the assignment of > > | "1" to obj->dead will be globally visible to other cpus before the > > | atomic counter decrement. > > | > > | Without the explicit smp_mb__before_atomic() call, the > > | implementation could legally allow the atomic counter update visible > > | to other cpus before the "obj->dead = 1;" assignment. > > > > which makes it sound more like the barrier is ordering all prior accesses > > against the atomic operation itself (without going near cumulativity...), > > and not with respect to anything later in program order. > > This is correct. Ah, my bad, It orders against everything later, the first of which is (obviously) the atomic op itself. It being a full barrier means both the Read and the Write of the RmW must happen _after_ everything preceding. > > Anyway, I think that's sufficient for what we want here, but we should > > probably iron out the semantics of this thing. > > s/smp_mb__\(before\|after\)_atomic/smp_mb/g > > should not change the semantics of the code in _any_ way, just make it > slower on architectures that already have SC atomic primitives (like > x86). >