Received: by 10.223.185.116 with SMTP id b49csp1021936wrg; Wed, 21 Feb 2018 10:42:54 -0800 (PST) X-Google-Smtp-Source: AH8x224431UuGVoN6il7YjzQytIckPyzw3CrmPRsOvG2bCE58H6nwxg/j+UiEJif3gcPQAttT70N X-Received: by 10.99.66.135 with SMTP id p129mr3522311pga.220.1519238573953; Wed, 21 Feb 2018 10:42:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519238573; cv=none; d=google.com; s=arc-20160816; b=ZOcYiNp1Xr3qyJXfvS3aXD17DAUI+RZE1OIfsA/fW6sZFcambgvsPDBhH8x/YsNfmh QPRFlkQnR34f95Jelhav6oGhhXbtX2u7bwYpzl45hCwjgcrqX4Tn4/BuX1y9QyBHcXZm j95PVQAyTmk0DqrhrX5eMjXXpOfP/Zvq07SylBUMhlpR6DPcEQGuASsD+v3vYt8t3DOs NERmYjIETnO5T3DnGIZDaUkTTvzxtU+RlvZIf8spwsMNfv+bjDveK5j8oSYCHqDPnbhf OznCnPRFBLOb16b4dKtFx4eY8dnzM33xly7S+QIInS5rLvk4TUEQ7pC0YmO7XwgoaDGj 54qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=2WCjR2p951LrgzwPOikUqGZ5MiinHRQ2mbfXYttvVpY=; b=r+CCtHmhCCbf9umsHUmnIbHM7R2bbitdNQp6jdgf0TwofKyo4773eXJORGqgNZvgbG LYDTJgRydKi3eDSvwYdDxshibGW1loOqC83FBYl1FyFjRGUOJknKro/pDbQQZc/wttbX p7H/fldgfn0GBQXOVnKez7uncCsPAr5ALtLcoNxVrcsBrilkpK2FcY365nZD9rIRuMGn yM4Nl9keN2p3RA4AbxxPdhqzzjpZV+GBtKGYGpmtsXBlK403Y7dnwgnp3rjwJCOV2hkM vq+yf6r1wFagDPTmq7Zo1QjSIvhjzoe14W2N2Y79i156aod2FDShF3HxWcs2A0hCxW/Y jjvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kcKd4d9p; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7si1694865pgv.473.2018.02.21.10.42.38; Wed, 21 Feb 2018 10:42:53 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kcKd4d9p; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965683AbeBUNZH (ORCPT + 99 others); Wed, 21 Feb 2018 08:25:07 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:35676 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932152AbeBUNZF (ORCPT ); Wed, 21 Feb 2018 08:25:05 -0500 Received: by mail-wr0-f195.google.com with SMTP id l43so4467377wrc.2; Wed, 21 Feb 2018 05:25:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=2WCjR2p951LrgzwPOikUqGZ5MiinHRQ2mbfXYttvVpY=; b=kcKd4d9paccLIgtuPTlQG90pKLoyU7j+6D4yRyGMBGrMWrUphUvsv5h2dpRtJYwXWx 6AQ+xP05CLEJwW+yQ2WIbjSQsAMylpIb6UFUnxp+YZCoSsgRuU/tO6AJ/8iAElFWwWva vO6ZhbMcjIVXqD6TjwSCyG1x/uLo7eyRLdQewWtAPKoNqTZJM3qec9RpXDrRueGIQein bNBgaWoMvSvf0fYgygbytNDM0hb4KQlVexImHhHM8h5pT3Z6WQpd3jAKxcMIp0YERGhz OcYnadHMMS7VLgTKnquVUlD2U0X3+EJ//UPNSWSvjpQemC3C13LoYmzJP0FtQT2Oijc2 RpVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=2WCjR2p951LrgzwPOikUqGZ5MiinHRQ2mbfXYttvVpY=; b=uYa9xfJ7GuSs/zxWe4QqDAdawH5s+zQCWTeA4jVnVpxRI7sn+w+C9BOpgZgYme3ij2 weSqVBogzwaYbXhZcZtf3s89NT6vfTS6ykRqtWsHuVHlxw1JCuq37tLQAdqyj6dipXIG MYlO/cs2XAxR2fJ+IMyIVcAV4XcnKJBqCAIxgstPzdjuOwMcqIn306Oae4fvJqkIFeQp km05UMZl374P3dOFmpA6303UH2dMtGXXHMyFF8Cc67tC3It8Wx0zIPWyCPBYyTiYXfF8 WieBkhZgMM9+5AcsSsTGO19XJgi4wWN9WUJzSZiVPhUAtm9OK2qPBqI5amLA6FdobqrR r7SA== X-Gm-Message-State: APf1xPDktIngGqwJfUYQgGCvgQf6Wtj9eW7T+pgPGIf8i+rvh4lTYDQR lVCypc9qLmhhjXUVh2jgRnSsJV7V X-Received: by 10.223.172.75 with SMTP id v69mr3173222wrc.269.1519219503239; Wed, 21 Feb 2018 05:25:03 -0800 (PST) Received: from andrea (86.100.broadband17.iol.cz. [109.80.100.86]) by smtp.gmail.com with ESMTPSA id x194sm10631470wmd.4.2018.02.21.05.25.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Feb 2018 05:25:02 -0800 (PST) Date: Wed, 21 Feb 2018 14:24:55 +0100 From: Andrea Parri To: Will Deacon Cc: Ingo Molnar , "Paul E. McKenney" , Alan Stern , Richard Henderson , Ivan Kokshaysky , Matt Turner , linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] xchg/alpha: Add unconditional memory barrier to cmpxchg Message-ID: <20180221132455.GA16111@andrea> References: <1519152356-4804-1-git-send-email-parri.andrea@gmail.com> <20180221112137.GA6165@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180221112137.GA6165@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 21, 2018 at 11:21:38AM +0000, Will Deacon wrote: > Hi Andrea, > > On Tue, Feb 20, 2018 at 07:45:56PM +0100, Andrea Parri wrote: > > Continuing along with the fight against smp_read_barrier_depends() [1] > > (or rather, against its improper use), add an unconditional barrier to > > cmpxchg. This guarantees that dependency ordering is preserved when a > > dependency is headed by an unsuccessful cmpxchg. As it turns out, the > > change could enable further simplification of LKMM as proposed in [2]. > > > > [1] https://marc.info/?l=linux-kernel&m=150884953419377&w=2 > > https://marc.info/?l=linux-kernel&m=150884946319353&w=2 > > https://marc.info/?l=linux-kernel&m=151215810824468&w=2 > > https://marc.info/?l=linux-kernel&m=151215816324484&w=2 > > > > [2] https://marc.info/?l=linux-kernel&m=151881978314872&w=2 > > > > Signed-off-by: Andrea Parri > > Acked-by: Peter Zijlstra > > Cc: Will Deacon > > Cc: "Paul E. McKenney" > > Cc: Alan Stern > > Cc: Richard Henderson > > Cc: Ivan Kokshaysky > > Cc: Matt Turner > > Cc: linux-alpha@vger.kernel.org > > Cc: linux-kernel@vger.kernel.org > > --- > > arch/alpha/include/asm/xchg.h | 15 +++++++-------- > > 1 file changed, 7 insertions(+), 8 deletions(-) > > > > diff --git a/arch/alpha/include/asm/xchg.h b/arch/alpha/include/asm/xchg.h > > index 68dfb3cb71454..e2660866ce972 100644 > > --- a/arch/alpha/include/asm/xchg.h > > +++ b/arch/alpha/include/asm/xchg.h > > @@ -128,10 +128,9 @@ ____xchg(, volatile void *ptr, unsigned long x, int size) > > * store NEW in MEM. Return the initial value in MEM. Success is > > * indicated by comparing RETURN with OLD. > > * > > - * The memory barrier should be placed in SMP only when we actually > > - * make the change. If we don't change anything (so if the returned > > - * prev is equal to old) then we aren't acquiring anything new and > > - * we don't need any memory barrier as far I can tell. > > + * The memory barrier is placed in SMP unconditionally, in order to > > + * guarantee that dependency ordering is preserved when a dependency > > + * is headed by an unsuccessful operation. > > */ > > > > static inline unsigned long > > @@ -150,8 +149,8 @@ ____cmpxchg(_u8, volatile char *m, unsigned char old, unsigned char new) > > " or %1,%2,%2\n" > > " stq_c %2,0(%4)\n" > > " beq %2,3f\n" > > - __ASM__MB > > "2:\n" > > + __ASM__MB > > ".subsection 2\n" > > "3: br 1b\n" > > ".previous" > > It might be better just to add smp_read_barrier_depends() into the cmpxchg > macro, then remove all of the __ASM__MB stuff. Mmh, it might be better to add smp_mb() into the cmpxchg macro (after the operation), then remove all the __ASM__MB stuff. > > That said, I don't actually understand how the Alpha cmpxchg or xchg > implementations satisfy the memory model, since they only appear to have > a barrier after the operation. > > So MP using xchg: > > WRITE_ONCE(x, 1) > xchg(y, 1) > > smp_load_acquire(y) == 1 > READ_ONCE(x) == 0 > > would be allowed. What am I missing? Good question ;-) The absence of an smp_mb() (or of an __ASM__MB) before the operation did upset me. If this question remains pending, I'll send a patch to add these barriers. > > Since I'm in the mood for dumb questions, do we need to care about > this_cpu_cmpxchg? I'm sure I've seen code that allows concurrent access to > per-cpu variables, but the asm-generic implementation of this_cpu_cmpxchg > doesn't use READ_ONCE. Frankly, I'm not sure if this's an issue in the generic implementation of this_cpu_* or, rather, in that code. let me dig a bit more into this ... Andrea > > Will