Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3198367imu; Fri, 23 Nov 2018 23:55:13 -0800 (PST) X-Google-Smtp-Source: AJdET5fp1TZEOqU136mycyELNMAoa5rliJDnce4Ct2IrloEOxXd2sjJtNsZyreo/8TT73pVcRZyu X-Received: by 2002:a62:3305:: with SMTP id z5mr19627232pfz.112.1543046113235; Fri, 23 Nov 2018 23:55:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543046113; cv=none; d=google.com; s=arc-20160816; b=t/q87MGUkz/J6XVn87fTfkhgKW+XDBFBvVGzsDupXFcojaFHkjSpjmi07wWmc/nlIb U7k1/zJUbYB404qP5fOWXM/iVrikkCv4gwuq1QMAMfWpGX91bHFiufvi27ZUcU+aPwIM b09zWYAN6EVPc9HrD98XOiAu2WCxWyWTeNdmc7nrlvOZ2WruQRs5TISLFlHaEWnh9Ct8 ISFl7M+PA2OGTIgBcwaDNl4TsMl3/gmIZ6UdZRp6JtVt47IAMXlxd+YElgSyb4HpDayJ JXp3p0zdcr0yQQCiWFkJ6XcPpGkYCMqx0t70RVORceyGIexL+gOg6+STTFD6N4yCipte z75Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=60EkmrQep9lIy9FzJ8p7iSAXTBk/HCQZiJiIFeGUYT4=; b=hXmTcF/0w4S380avSybArNq8lij7F4Tys/IGNlnsevisfiIc8Uc2PWdrAbOgS7eUcn 2PpYQA/WOwm5urb4oTsyfI1I8a26Pwu0nRUHtyyVzhc+U49nWkUr73xb08ngy2ZCRLfS m0gfOjQ9YPhCtlDYwr8VXi7ncZvIsQmMalImBpaLbcmpzgbutOL6MO3BSuFPGVyw+Uzs vfML2mla+R45O3gcbxdRPzvwqOTb/i2FwmbfvHPVhiYgoGVIcA3W8Z9KnKF9kEAeYFPv Ab1rPaoc6XR+98Cg7Wa1BlLsvQZOGTM91JEqPp7/yLsMdbJ0PLzq7kv623FDFA85ZHyo FlOQ== 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 f1si18516375pld.92.2018.11.23.23.54.59; Fri, 23 Nov 2018 23:55:13 -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 S2501903AbeKWNeF (ORCPT + 99 others); Fri, 23 Nov 2018 08:34:05 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:15581 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2392981AbeKWNeF (ORCPT ); Fri, 23 Nov 2018 08:34:05 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 4A75238FC0DC; Fri, 23 Nov 2018 10:51:44 +0800 (CST) Received: from [10.151.23.176] (10.151.23.176) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 23 Nov 2018 10:51:38 +0800 Subject: Re: [PATCH 05/10] staging: erofs: add a full barrier in erofs_workgroup_unfreeze To: Andrea Parri CC: Greg Kroah-Hartman , , , Chao Yu , LKML , , Miao Xie 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> From: Gao Xiang Message-ID: Date: Fri, 23 Nov 2018 10:51:33 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20181122185058.GA3466@andrea> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.151.23.176] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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... 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? Thanks, Gao Xiang > > Andrea > > >> >> Thanks, >> Gao Xiang >> >>> >>> thanks, >>> >>> greg k-h