Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3217942imu; Sat, 24 Nov 2018 00:21:10 -0800 (PST) X-Google-Smtp-Source: AFSGD/W2lnesBkypx21lfd1eskEIqILOSaDNaPC1rMohtPxeRXs0QnGFJM+WRLJ2Ud/2+X6pFYUp X-Received: by 2002:a63:9c1a:: with SMTP id f26mr17288086pge.381.1543047670328; Sat, 24 Nov 2018 00:21:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543047670; cv=none; d=google.com; s=arc-20160816; b=cVo48nyskOhXfmyC9MSvbxyg/9WKb0z3tBJHmDmTddl2Hmp8M//n1yqxmfaNDWvgDH ZIAnkgSKa6z3rBWjbxE0OK82LS58/S+KJil7S6pwBpt/pwVyDizsoROcikEWbSPJHEri DDqXqk1/6AUAJ/9TluIklAmOhYplpZC7YRTAHrllfwDkNtahc8vIhnZl+e3hlr29KZzL F95rExFF0KxJOHTPiIOaSCbLkD11S44Z+BciWxL0fo/mLdt+NTBFN8WgdI6idBM8MD0x 8xE7uFGX9hv3DSy8nmcOfY9lgf0iicc/RFbENY0wXjW0CJCa70V20AVX0mIunZ9qtb1i wq+A== 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; bh=B905NUlu7NO/lkKENI+4l+00+wjv/xrHDHnjASuen4U=; b=FtNbf8Ofg5DSqdfaYwOz3WdRadmFds9GGgrd1AFLfEH6JaTugCeNH3NPoKSg0KmGei 0hwiBPDNLflqSwgcoJgNb4tgjWyig/wudsO9neF6e0Mmhp5VlGxVfJPdQxliWbf0pLHU E+zbNwfQeQPhxHAdUCYWVBb6MvNzDBl8IAbdb5SwUeZtJTQip/ql9zYe0vR+92opulOi 3jASLQ42gdkK+hMJy+8jFwatgaIYN1b3Oea1EQhIQ3hRNS2A8ydnnwrOU7KuXZpuampJ LSBU/Gc/cKAeit1SIp4BwxztAwpoGLNaJWhACfAaJ569W2NAAU2uHOT2kX7PzmT58W3N /0VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=RHBwBLXd; 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 q13si56631986pgj.86.2018.11.24.00.20.56; Sat, 24 Nov 2018 00:21:10 -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=@amarulasolutions.com header.s=google header.b=RHBwBLXd; 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 S2405468AbeKWUfK (ORCPT + 99 others); Fri, 23 Nov 2018 15:35:10 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:38739 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387976AbeKWUfJ (ORCPT ); Fri, 23 Nov 2018 15:35:09 -0500 Received: by mail-ed1-f65.google.com with SMTP id h50so9776864ede.5 for ; Fri, 23 Nov 2018 01:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=B905NUlu7NO/lkKENI+4l+00+wjv/xrHDHnjASuen4U=; b=RHBwBLXdk16SM6wRpqu+HsKSUhbia94DKMlHmvAiopsC9UWoazgMBUwbsMhEZy9/Wu QDYFuMQCl9mUwSsfdtkWGvyKY8I55ggR+YXeoH11JpTlAdPhihCO+ISzKmPiDkQLWahN XlUOZc29xef58VEgPUH/XHknHcGSGvxeR2tDo= 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=B905NUlu7NO/lkKENI+4l+00+wjv/xrHDHnjASuen4U=; b=fSUDVAOnwh0bvD6VcqeDSht9F5RMcf4cmQpb636qCU/KOG0OuFbRIyQZ5h52/o6UZT nZpaX5bYKQhOBD38pPK4JqP6qEm7JYFTf6demHszg0YkUG2dTE/3Ug8GYAS5Ipnoy1YD 8Cot83WFiSXA35CmjNAKvrETHh2wL4fpwH0+c5iIcLuPD8E7tDNKpn/PjUq4XMrEN2rt kclJwMTqjzxdRm3e6WvKFOyGn1UKinM1a4EBs+JrEYYXpenaRMDRUMZbb/xhDfbDaHGu RJnQoUOmXelY+bLOE0t0X9qp4+M6eu2HkQmxqPLMxD7EVLRZT6um2qVgEdsKfT+AtoTn 47DQ== X-Gm-Message-State: AA+aEWaaKteIZ0Wpn8c0mf0IIoiw7cgE36LnwrJur8MkEx5PECxWZ0pz VX9fFEkV5sfsWehurstP5PaPAQ== X-Received: by 2002:a05:6402:13d6:: with SMTP id a22mr12011207edx.39.1542966694718; Fri, 23 Nov 2018 01:51:34 -0800 (PST) Received: from andrea (85.100.broadband17.iol.cz. [109.80.100.85]) by smtp.gmail.com with ESMTPSA id b11-v6sm4015511ejd.16.2018.11.23.01.51.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Nov 2018 01:51:34 -0800 (PST) Date: Fri, 23 Nov 2018 10:51:28 +0100 From: Andrea Parri To: Gao Xiang Cc: Greg Kroah-Hartman , devel@driverdev.osuosl.org, linux-erofs@lists.ozlabs.org, Chao Yu , LKML , weidu.du@huawei.com, Miao Xie Subject: Re: [PATCH 05/10] staging: erofs: add a full barrier in erofs_workgroup_unfreeze Message-ID: <20181123094739.GA3487@andrea> References: <20181120143425.43637-1-gaoxiang25@huawei.com> <20181120143425.43637-6-gaoxiang25@huawei.com> <20181122102230.GF3189@kroah.com> <1d1fd688-0cb5-cbac-9213-f56f7e356bca@huawei.com> <20181122185058.GA3466@andrea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 23, 2018 at 10:51:33AM +0800, Gao Xiang wrote: > Hi Andrea, > > On 2018/11/23 2:50, Andrea Parri wrote: > > On Thu, Nov 22, 2018 at 06:56:32PM +0800, Gao Xiang wrote: > >> Hi Greg, > >> > >> On 2018/11/22 18:22, Greg Kroah-Hartman wrote: > >>> Please document this memory barrier. It does not make much sense to > >>> me... > >> > >> Because we need to make the other observers noticing the latest values modified > >> in this locking period before unfreezing the whole workgroup, one way is to use > >> a memory barrier and the other way is to use ACQUIRE and RELEASE. we selected > >> the first one. > >> > >> Hmmm...ok, I will add a simple message to explain this, but I think that is > >> plain enough for a lock... > > > > Sympathizing with Greg's request, let me add some specific suggestions: > > > > 1. It wouldn't hurt to indicate a pair of memory accesses which are > > intended to be "ordered" by the memory barrier in question (yes, > > this pair might not be unique, but you should be able to provide > > an example). > > > > 2. Memory barriers always come matched by other memory barriers, or > > dependencies (it really does not make sense to talk about a full > > barrier "in isolation"): please also indicate (an instance of) a > > matching barrier or the matching barriers. > > > > 3. How do the hardware threads communicate? In the acquire/release > > pattern you mentioned above, the load-acquire *reads from* a/the > > previous store-release, a memory access that follows the acquire > > somehow communicate with a memory access preceding the release... > > > > 4. It is a good practice to include the above information within an > > (inline) comment accompanying the added memory barrier (in fact, > > IIRC, checkpatch.pl gives you a "memory barrier without comment" > > warning when you omit to do so); not just in the commit message. > > > > Hope this helps. Please let me know if something I wrote is unclear, > > Thanks for taking time on the detailed explanation. I think it is helpful for me. :) > And you are right, barriers should be in pairs, and I think I need to explain more: > > 255 static inline bool erofs_workgroup_get(struct erofs_workgroup *grp, int *ocnt) > 256 { > 257 int o; > 258 > 259 repeat: > 260 o = erofs_wait_on_workgroup_freezed(grp); > 261 > 262 if (unlikely(o <= 0)) > 263 return -1; > 264 > 265 if (unlikely(atomic_cmpxchg(&grp->refcount, o, o + 1) != o)) <- * > 266 goto repeat; > imply a memory barrier here > 267 > 268 *ocnt = o; > 269 return 0; > 270 } > > I think atomic_cmpxchg implies a memory barrier semantics when the value comparison (*) succeeds... Correct. This is informally documented in Documentation/atomic_t.txt and formalized within tools/memory-model/. > > I don't know whether my understanding is correct, If I am wrong..please correct me, or > I need to add more detailed code comments to explain in the code? Yes, please; please review the above points (including 1. and 3.) and try to address them with inline comments. Maybe (if that matches the *behavior*/guarantee you have in mind...) something like: [in erofs_workgroup_unfreeze()] /* * Orders the store/load to/from [???] and the store to * ->refcount performed by the atomic_set() below. * * Matches the atomic_cmpxchg() in erofs_workgroup_get(). * * Guarantees that if a successful atomic_cmpxchg() reads * the value stored by the atomic_set() then [???]. */ smp_mb(); atomic_set(&grp->refcount, v); [in erofs_workgroup_get()] /* * Orders the load from ->refcount performed by the * atomic_cmpxchg() below and the store/load [???]. * * See the comment for the smp_mb() in * erofs_workgroup_unfreeze(). */ if (unlikely(atomic_cmpxchg(&grp->refcount, o, o + 1) != o)) goto repeat; Thanks, Andrea > > Thanks, > Gao Xiang > > > > > > Andrea > > > > > >> > >> Thanks, > >> Gao Xiang > >> > >>> > >>> thanks, > >>> > >>> greg k-h