Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp3912867imc; Thu, 14 Mar 2019 08:04:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTzWaMm1dYv9RNxRbUf2u0+ICKhISQIyocWW9vruCB2R6i8nbCTcw18nZ4H1EXPslm9vuS X-Received: by 2002:a63:da43:: with SMTP id l3mr46034019pgj.164.1552575841807; Thu, 14 Mar 2019 08:04:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552575841; cv=none; d=google.com; s=arc-20160816; b=A2E/8E12BYBHBS56+Try3O1TWILFDvvQXZlrQ633U/JsCbhaNTEVuT+r7pHlF55aM3 SpX5mNkZddGKA6nwEUDMhBOExorlTf9hNVLg3MOsn94oMo0K6u5+vCFuWFeDV+a874eL Pl4YFkMbEY/eR1zlPd1QyMDsP+A6kGgEjN5qoHkUv2Vz4aL2oEyFYx9MsGbeacDWA2Wu a+eWqNVG2ZsUFN5oTHtTDnHkybSXZ1XHXfJIgAT6ij7IHr+djaB0OBpL1pJGZf7+2anH CSoEM2zQOaqUsm6jEOuXKdwdbRSFP6HdsH080JAz/ele7nwiAbaUAaSSy7cFhgTuOerU qWCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:reply-to:subject:cc:to :from:date; bh=lOpWJPM+aA3gdxSTi5Cgedw3l9cJifVdq6Q5TiiUPB4=; b=O2qyz/LsYRkLQBtDMC7yB/gmd0WYucLesVNWGBdQrAmSqswF7Agtke7qAle/L5yt17 pIHGqcsMbneRH+Kro44YRnUEZzjjauvCwUEZOdcpJ2+a9nNawjzIrqzUqf63arthWMwC 51smxIhoj8CCri4spKouDEazy2wQ2GOA44ZCfPabLIN3O+PwBLoKyHo/t25kgxi0wZXp YeUShUk4hbYtaNGgBbkLkNWUpa+JmJ2EQQRlt43G02cWLM1Y2PqVSSHjOkvWD3rC1WbI nh2oSRDReUNNi3i4drzqc9ozFFb6P2YB+X4W9JgMZQbI/GSVZZFg/QT2DBJrNr7UR4hP 4OHQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y4si13768452plk.30.2019.03.14.08.03.44; Thu, 14 Mar 2019 08:04:01 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726768AbfCNPC6 (ORCPT + 99 others); Thu, 14 Mar 2019 11:02:58 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:49288 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726337AbfCNPC5 (ORCPT ); Thu, 14 Mar 2019 11:02:57 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2EF1TAY070001 for ; Thu, 14 Mar 2019 11:02:57 -0400 Received: from e16.ny.us.ibm.com (e16.ny.us.ibm.com [129.33.205.206]) by mx0a-001b2d01.pphosted.com with ESMTP id 2r7pbrhx7n-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Mar 2019 11:02:52 -0400 Received: from localhost by e16.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 14 Mar 2019 15:02:25 -0000 Received: from b01cxnp23034.gho.pok.ibm.com (9.57.198.29) by e16.ny.us.ibm.com (146.89.104.203) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 14 Mar 2019 15:02:22 -0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x2EF2Lbt22937730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 14 Mar 2019 15:02:21 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F1B0EB2066; Thu, 14 Mar 2019 15:02:20 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C4240B2064; Thu, 14 Mar 2019 15:02:20 +0000 (GMT) Received: from paulmck-ThinkPad-W541 (unknown [9.70.82.188]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 14 Mar 2019 15:02:20 +0000 (GMT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id 5AB1F16C32B8; Thu, 14 Mar 2019 08:03:06 -0700 (PDT) Date: Thu, 14 Mar 2019 08:03:06 -0700 From: "Paul E. McKenney" To: Nikos Tsironis Cc: Mike Snitzer , hch@infradead.org, agk@redhat.com, dm-devel@redhat.com, mpatocka@redhat.com, iliastsi@arrikto.com, linux-kernel@vger.kernel.org Subject: Re: [dm-devel] [PATCH 1/3] list_bl: Add hlist_bl_add_before/behind helpers Reply-To: paulmck@linux.ibm.com References: <20181220180651.4879-1-ntsironis@arrikto.com> <20181220180651.4879-2-ntsironis@arrikto.com> <20190228213201.GB23527@redhat.com> <20190313234853.GA7797@linux.ibm.com> <20190314003027.GE4202@redhat.com> <20190314140750.GB4102@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190314140750.GB4102@linux.ibm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 19031415-0072-0000-0000-0000040B129D X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010757; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000281; SDB=6.01174283; UDB=6.00614031; IPR=6.00954947; MB=3.00025978; MTD=3.00000008; XFM=3.00000015; UTC=2019-03-14 15:02:24 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19031415-0073-0000-0000-00004B7CCA0F Message-Id: <20190314150306.GA22051@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-14_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903140106 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 14, 2019 at 07:07:50AM -0700, Paul E. McKenney wrote: > On Thu, Mar 14, 2019 at 03:28:23PM +0200, Nikos Tsironis wrote: > > On 3/14/19 2:30 AM, Mike Snitzer wrote: > > > On Wed, Mar 13 2019 at 7:48pm -0400, > > > Paul E. McKenney wrote: > > > > > Hi Paul, > > > > Thanks a lot for your feedback! > > NP, and apologies for the delay. > > > >> On Thu, Feb 28, 2019 at 04:32:02PM -0500, Mike Snitzer wrote: > > >>> On Thu, Dec 20 2018 at 1:06pm -0500, > > >>> Nikos Tsironis wrote: > > >>> > > >>>> Add hlist_bl_add_before/behind helpers to add an element before/after an > > >>>> existing element in a bl_list. > > >>>> > > >>>> Signed-off-by: Nikos Tsironis > > >>>> Signed-off-by: Ilias Tsitsimpis > > >>>> --- > > >>>> include/linux/list_bl.h | 27 +++++++++++++++++++++++++++ > > >>>> 1 file changed, 27 insertions(+) > > >>>> > > >>>> diff --git a/include/linux/list_bl.h b/include/linux/list_bl.h > > >>>> index 3fc2cc57ba1b..2fd918e5fd48 100644 > > >>>> --- a/include/linux/list_bl.h > > >>>> +++ b/include/linux/list_bl.h > > >>>> @@ -86,6 +86,33 @@ static inline void hlist_bl_add_head(struct hlist_bl_node *n, > > >>>> hlist_bl_set_first(h, n); > > >>>> } > > >>>> > > >>>> +static inline void hlist_bl_add_before(struct hlist_bl_node *n, > > >>>> + struct hlist_bl_node *next) > > >>>> +{ > > >>>> + struct hlist_bl_node **pprev = next->pprev; > > >>>> + > > >>>> + n->pprev = pprev; > > >>>> + n->next = next; > > >>>> + next->pprev = &n->next; > > >>>> + > > >>>> + /* pprev may be `first`, so be careful not to lose the lock bit */ > > >>>> + WRITE_ONCE(*pprev, > > >>>> + (struct hlist_bl_node *) > > >>>> + ((unsigned long)n | > > >>>> + ((unsigned long)*pprev & LIST_BL_LOCKMASK))); > > >> > > >> A nit, but use of uintptr_t shrinks things a bit: > > >> > > >> + (struct hlist_bl_node *) > > >> + ((uintptr_t)n | ((uintptr_t)*pprev & LIST_BL_LOCKMASK))); > > >> > > >> I am not too concerned about this, though. > > > > > > I'm fine with folding in your suggestion. > > > > Indeed, this looks better. > > > > >> The WRITE_ONCE() is to handle races with hlist_bl_empty() (which does contain > > >> the corresponding READ_ONCE()) correct? > > > > > > Correct. > > > > Yes that's correct. > > > > >>>> +} > > >>>> + > > >>>> +static inline void hlist_bl_add_behind(struct hlist_bl_node *n, > > >>>> + struct hlist_bl_node *prev) > > >>>> +{ > > >>>> + n->next = prev->next; > > >>>> + n->pprev = &prev->next; > > >>>> + WRITE_ONCE(prev->next, n); > > >> > > >> I don't see what this WRITE_ONCE() is interacting with. The traversals > > >> use plain C-language reads, and hlist_bl_empty() can't get here. All > > >> uses of hlist_bl_for_each_entry() invoke hlist_bl_lock() before starting > > >> the traversal, and hlist_bl_for_each_entry_safe() looks to be unused. > > >> (Perhaps it should be removed? Or is there some anticipated use?) > > > > I am using hlist_bl_for_each_entry_safe() in this proposed patch for > > dm-snapshot: https://patchwork.kernel.org/patch/10835709/ > > Probably should keep it, then. ;-) > > > >> > > >> I don't believe that the WRITE_ONCE() is needed. What am I missing? > > >> > > >> Other than that, looks good. > > >> > > >> Thanx, Paul > > >> > > > > > > I'd imagine it was just born out of symmetry with hlist_bl_add_before() > > > and/or caution. But let's see what Nikos has to say. > > > > I also don't believe that this WRITE_SAME() is needed. But, looking at > > hlist_add_behind() in include/linux/list.h, which, if I am not missing > > something, is used in the same way as hlist_bl_add_behind(), it also > > uses WRITE_ONCE() to update prev->next: > > > > static inline void hlist_add_behind(struct hlist_node *n, > > struct hlist_node *prev) > > { > > n->next = prev->next; > > WRITE_ONCE(prev->next, n); > > n->pprev = &prev->next; > > > > if (n->next) > > n->next->pprev = &n->next; > > } > > > > Could it be the case that the WRITE_ONCE() in hlist_add_behind() is also > > not needed? This WRITE_ONCE() was introduced by commit 1c97be677f72b3 > > ("list: Use WRITE_ONCE() when adding to lists and hlists"). > > Looks like I have no one to blame but myself! > > Would you like to remove that as part of your patch series? > > > But, since I am not an expert in lockless programming, I opted to be on > > the safe side and followed the example of hlist_add_behind(). > > > > That said, I will follow up with a new version of the patch removing the > > WRITE_ONCE() and using uintptr_t instead of unsigned long. > > Sounds good! Oh, and of course intptr_t is one character shorter than uintptr_t, and looks to work just as well in this context. ;-) Thanx, Paul