Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp5787352imm; Sat, 19 May 2018 09:37:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo4x/W3gg3nwcpzJdIl0/V5TZf/wOTZbGywxchQdAemdNVjk/CkKCt8Ks4cSuX/W4Uqt/9n X-Received: by 2002:a62:22db:: with SMTP id p88-v6mr13875423pfj.239.1526747827827; Sat, 19 May 2018 09:37:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526747827; cv=none; d=google.com; s=arc-20160816; b=iX9LXw+5ZuBedHlTnqLfBF7fwR4xY+j9hFmHuqFuVqPyeibaX5wzx9oJE86dqu/rhA 7BhmVxtylvEY2IRNksOBpxsCktchxsLAXbQNJplKnZ57NLkTkF7wOJHivUN1ROAL7CzT 7mXl2Mhw+a6zyJHIg5pHEH8ldWPzzjq9OoMwqCh9q1+QKqqSwDAC7v3yevyguagqCKtT CW2ROE+Az/oMJyGZANdzv4XFYYZlpnxLi38//WqYrh3QTJe1qO1B284vo1uCPRkCAStH oQYriUfxi4uKQr7B/G52EwyDiIV2BXNH2KeyNbQ160bI8VUpMWZO3GXEz6RFCIdIdvcV cuzg== 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:arc-authentication-results; bh=KSEXlmwo4+VDeuumj9P9VDUBpB0am/kJIWyFNMjd+IQ=; b=fDYry4L3j8gqPN8TlL252NXxrZ4kyvgSDJm3UZN2S8JadkAFeDhLfqSj+/KCWlHMV+ jA0xnZpGp4DMcS+VBN4SLtpwdN7VHCYVRcS/ZimSKr+CTJa92rHP/Fvb+OReGyHHVdI3 3lAgIEnTx1o5chvIIujfVV4WziXLL/g22QG4qAxrJfy/rV6A+Ta0jSpJWCFMRuqO5bDW FY8gHdh/cpSBsJEoHFW1CqM0OFwhy5vHAAXJ80nyQ001A7AdyqqsEl+Aq59n8Beak4q1 kHJDSen+3EJuh4NaIZCYybNcLobQbwa/3ofOgp0ae1G3O1M9r6ka+Qgqjx55l+pJ2ewL ZElA== 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 m15-v6si1613433pgr.9.2018.05.19.09.36.22; Sat, 19 May 2018 09:37:07 -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 S1752462AbeESQgM (ORCPT + 99 others); Sat, 19 May 2018 12:36:12 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:36740 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752344AbeESQgK (ORCPT ); Sat, 19 May 2018 12:36:10 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4JGY278062264 for ; Sat, 19 May 2018 12:36:07 -0400 Received: from e19.ny.us.ibm.com (e19.ny.us.ibm.com [129.33.205.209]) by mx0a-001b2d01.pphosted.com with ESMTP id 2j2g39mr18-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 19 May 2018 12:36:07 -0400 Received: from localhost by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sat, 19 May 2018 12:36:06 -0400 Received: from b01cxnp22036.gho.pok.ibm.com (9.57.198.26) by e19.ny.us.ibm.com (146.89.104.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sat, 19 May 2018 12:36:01 -0400 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4JGa1IV55902218; Sat, 19 May 2018 16:36:01 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CD4CDB2064; Sat, 19 May 2018 13:37:54 -0400 (EDT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 976C5B205F; Sat, 19 May 2018 13:37:54 -0400 (EDT) Received: from paulmck-ThinkPad-W541 (unknown [9.85.187.109]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Sat, 19 May 2018 13:37:54 -0400 (EDT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id A817216C1362; Sat, 19 May 2018 09:37:35 -0700 (PDT) Date: Sat, 19 May 2018 09:37:35 -0700 From: "Paul E. McKenney" To: Roman Pen Cc: linux-block@vger.kernel.org, linux-rdma@vger.kernel.org, Jens Axboe , Christoph Hellwig , Sagi Grimberg , Bart Van Assche , Or Gerlitz , Doug Ledford , Swapnil Ingle , Danil Kipnis , Jack Wang , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 01/26] rculist: introduce list_next_or_null_rr_rcu() Reply-To: paulmck@linux.vnet.ibm.com References: <20180518130413.16997-1-roman.penyaev@profitbricks.com> <20180518130413.16997-2-roman.penyaev@profitbricks.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180518130413.16997-2-roman.penyaev@profitbricks.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 18051916-0056-0000-0000-00000450D270 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009052; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000261; SDB=6.01034644; UDB=6.00529136; IPR=6.00813773; MB=3.00021203; MTD=3.00000008; XFM=3.00000015; UTC=2018-05-19 16:36:04 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18051916-0057-0000-0000-00000894EA98 Message-Id: <20180519163735.GX3803@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-05-19_09:,, 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 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1805190170 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 18, 2018 at 03:03:48PM +0200, Roman Pen wrote: > Function is going to be used in transport over RDMA module > in subsequent patches. > > Function returns next element in round-robin fashion, > i.e. head will be skipped. NULL will be returned if list > is observed as empty. > > Signed-off-by: Roman Pen > Cc: Paul E. McKenney > Cc: linux-kernel@vger.kernel.org > --- > include/linux/rculist.h | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > > diff --git a/include/linux/rculist.h b/include/linux/rculist.h > index 127f534fec94..b0840d5ab25a 100644 > --- a/include/linux/rculist.h > +++ b/include/linux/rculist.h > @@ -339,6 +339,25 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, > }) > > /** > + * list_next_or_null_rr_rcu - get next list element in round-robin fashion. > + * @head: the head for the list. > + * @ptr: the list head to take the next element from. > + * @type: the type of the struct this is embedded in. > + * @memb: the name of the list_head within the struct. > + * > + * Next element returned in round-robin fashion, i.e. head will be skipped, > + * but if list is observed as empty, NULL will be returned. > + * > + * This primitive may safely run concurrently with the _rcu list-mutation > + * primitives such as list_add_rcu() as long as it's guarded by rcu_read_lock(). Of course, all the set of list_next_or_null_rr_rcu() invocations that are round-robining a given list must all be under the same RCU read-side critical section. For example, the following will break badly: struct foo *take_rr_step(struct list_head *head, struct foo *ptr) { struct foo *ret; rcu_read_lock(); ret = list_next_or_null_rr_rcu(head, ptr, struct foo, foolist); rcu_read_unlock(); /* BUG */ return ret; } You need a big fat comment stating this, at the very least. The resulting bug can be very hard to trigger and even harder to debug. And yes, I know that the same restriction applies to list_next_rcu() and friends. The difference is that if you try to invoke those in an infinite loop, you will be rapped on the knuckles as soon as you hit the list header. Without that knuckle-rapping, RCU CPU stall warnings might tempt people to do something broken like take_rr_step() above. Is it possible to instead do some sort of list_for_each_entry_rcu()-like macro that makes it more obvious that the whole thing need to be under a single RCU read-side critical section? Such a macro would of course be an infinite loop if the list never went empty, so presumably there would be a break or return statement in there somewhere. > + */ > +#define list_next_or_null_rr_rcu(head, ptr, type, memb) \ > +({ \ > + list_next_or_null_rcu(head, ptr, type, memb) ?: \ > + list_next_or_null_rcu(head, READ_ONCE((ptr)->next), type, memb); \ Are there any uses for this outside of RDMA? If not, I am with Linus. Define this within RDMA, where a smaller number of people can more easily be kept aware of the restrictions on use. If it turns out to be more generally useful, we can take a look at exactly what makes sense more globally. Even within RDMA, I strongly recommend the big fat comment called out above. And the list_for_each_entry_rcu()-like formulation, if that can be made to work within RDMA's code structure. Seem reasonable, or am I missing something here? Thanx, Paul > +}) > + > +/** > * list_for_each_entry_rcu - iterate over rcu list of given type > * @pos: the type * to use as a loop cursor. > * @head: the head for your list. > -- > 2.13.1 >