Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp1489223imc; Mon, 11 Mar 2019 15:11:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVTDdoa+1q56CnhCw2eiLOygcQRGR08pMEk3HQk6B2sM2RpzoAKEV8QhyxQ3x5ws8yubAt X-Received: by 2002:aa7:8384:: with SMTP id u4mr34666518pfm.190.1552342296615; Mon, 11 Mar 2019 15:11:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552342296; cv=none; d=google.com; s=arc-20160816; b=GCerPM/6gWL4qkxmuz5ZHAaXkdOwj3DE7ecFk5H+zh8BFFWeyl1/tP/czAygW6q4LA ZLVxWywkfIuDIKa6rzdlY6L2h1duZIigBwWekg63KM460EafLCoSsQsdPHzmMXI4hk2+ HUwL2SivqP7Aa+c6vo28bJs99HyXbsQlMyoc8hWNjRPEI6NVqOKaUGoTbQUCymyoQJLK jBrDCp7ctDOMKnk2kLxCcB/3Fc51giW4ze/aAE9qyS7HhE0nRWs82bp1iFAsrKMtXpYv i5sKLG7xkiBbkRacM+W1kvLrnvLeOmGm80sW8sQDptJDO/ZKDaOBsz+lQY+UltBqjKFv 6E+Q== 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=ScxoVTDhZEuLcv8UjptJcIiYsz8Or/fGd3h7kl+rAjs=; b=XAh9dBb5dwdad/wP4RZTuQWoUG+nKXw66lAdchZ3G0XggUJ0NMGo4olOFh7J18s6Yt xPFRektueFmkBUjRujK5U6G/s4vbHFr+bVAe1m7aQVdmA+1wXUxZ9ZEheK1+z7yhNuzb 8jIG+Wk6N0DHZg8rSWIg1l3byS46gQnrycs3pfvmBErTov0L5zT5df12azETZB9yUmIV 4xUakdWnvsGSbfh6TKwNw8xlV66SxoBPRaQhsD38XICjK7UIHdzDkyigojqredM6Ex4Y zlBHNSM5gOxp+SVJFYBwznKmI+mU9oQl7nUfXenByYjnMOFdXuuNvF7lJ6bAFIq9xLCC 0uUw== 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 cm8si6823794plb.47.2019.03.11.15.11.20; Mon, 11 Mar 2019 15:11:36 -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 S1728392AbfCKWKH (ORCPT + 99 others); Mon, 11 Mar 2019 18:10:07 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43130 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728313AbfCKWKH (ORCPT ); Mon, 11 Mar 2019 18:10:07 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2BM9iAM122257 for ; Mon, 11 Mar 2019 18:10:05 -0400 Received: from e12.ny.us.ibm.com (e12.ny.us.ibm.com [129.33.205.202]) by mx0a-001b2d01.pphosted.com with ESMTP id 2r5uemn37k-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 11 Mar 2019 18:10:05 -0400 Received: from localhost by e12.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 11 Mar 2019 22:10:04 -0000 Received: from b01cxnp22033.gho.pok.ibm.com (9.57.198.23) by e12.ny.us.ibm.com (146.89.104.199) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 11 Mar 2019 22:10:00 -0000 Received: from b01ledav003.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp22033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x2BM9xqg25165980 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Mar 2019 22:09:59 GMT Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2D416B2087; Mon, 11 Mar 2019 22:09:59 +0000 (GMT) Received: from b01ledav003.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F353DB2080; Mon, 11 Mar 2019 22:09:58 +0000 (GMT) Received: from paulmck-ThinkPad-W541 (unknown [9.70.82.188]) by b01ledav003.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 11 Mar 2019 22:09:58 +0000 (GMT) Received: by paulmck-ThinkPad-W541 (Postfix, from userid 1000) id E67B616C34A1; Mon, 11 Mar 2019 15:10:00 -0700 (PDT) Date: Mon, 11 Mar 2019 15:10:00 -0700 From: "Paul E. McKenney" To: NeilBrown Cc: Herbert Xu , Thomas Graf , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, rcu@vger.kernel.org, neeraju@codeaurora.org Subject: Re: [PATCH 2/5] rhashtable: don't hold lock on first table throughout insertion. Reply-To: paulmck@linux.ibm.com References: <20180725152250.GN12945@linux.vnet.ibm.com> <87r2jpmqu2.fsf@notabene.neil.brown.name> <20180727031815.GW24813@linux.vnet.ibm.com> <20180727145731.GA2780@linux.vnet.ibm.com> <87zhy8s05i.fsf@notabene.neil.brown.name> <20180731041425.GI24813@linux.vnet.ibm.com> <87lg9sro5r.fsf@notabene.neil.brown.name> <20180731144429.GM24813@linux.vnet.ibm.com> <20190311152752.GA10700@linux.ibm.com> <874l89qdwy.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <874l89qdwy.fsf@notabene.neil.brown.name> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-GCONF: 00 x-cbid: 19031122-0060-0000-0000-0000031A81E6 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00010741; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000281; SDB=6.01172997; UDB=6.00613254; IPR=6.00953652; MB=3.00025936; MTD=3.00000008; XFM=3.00000015; UTC=2019-03-11 22:10:02 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19031122-0061-0000-0000-00004893D96F Message-Id: <20190311221000.GO13351@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-11_16:,, 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-1903110151 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 12, 2019 at 08:50:05AM +1100, NeilBrown wrote: > On Mon, Mar 11 2019, Paul E. McKenney wrote: > > > On Tue, Jul 31, 2018 at 07:44:29AM -0700, Paul E. McKenney wrote: > >> On Tue, Jul 31, 2018 at 03:04:48PM +1000, NeilBrown wrote: > >> > On Mon, Jul 30 2018, Paul E. McKenney wrote: > >> > > >> > > On Tue, Jul 31, 2018 at 10:45:45AM +1000, NeilBrown wrote: > >> > >> On Fri, Jul 27 2018, Paul E. McKenney wrote: > >> > >> > >> > >> > On Thu, Jul 26, 2018 at 08:18:15PM -0700, Paul E. McKenney wrote: > >> > >> >> On Fri, Jul 27, 2018 at 11:04:37AM +1000, NeilBrown wrote: > >> > >> >> > On Wed, Jul 25 2018, Paul E. McKenney wrote: > >> > >> >> > >> > >> > >> >> > >> Looks good ... except ... naming is hard. > >> > >> >> > >> > >> > >> >> > >> is_after_call_rcu_init() asserts where in the lifecycle we are, > >> > >> >> > >> is_after_call_rcu() tests where in the lifecycle we are. > >> > >> >> > >> > >> > >> >> > >> The names are similar but the purpose is quite different. > >> > >> >> > >> Maybe s/is_after_call_rcu_init/call_rcu_init/ ?? > >> > >> >> > > > >> > >> >> > > How about rcu_head_init() and rcu_head_after_call_rcu()? > >> > >> >> > >> > >> >> Very well, I will pull this change in on my next rebase. > >> > >> > > >> > >> > Like this? > >> > >> > >> > >> Hard to say - unwinding white-space damage in my head is too challenging > >> > >> when newlines have been deleted :-( > >> > > > >> > > What??? Don't you like block-structured code? > >> > > > >> > > All kidding aside, how about the following more conventionally formatted > >> > > version? > >> > > >> > Wow - it's like I just got new glasses! > >> > Yes - nice an clear and now flaws to be found. Thanks a lot. > >> > >> Now that flaws are to be found, please feel free to report them. ;-) > > > > Hello, Neil, > > > > Any plans to use these functions? There are still no upstream uses. > > On the other hand, if they proved unuseful, I will remove them. If I > > don't hear otherwise from you, I will pull them in v5.2. > > Hi Paul, > yes, I do still have plans for them. I've got quite a few things I > want to add to rhashtables including this, but got stalled late last > year and I haven't managed to get back to it. > Thanks for your prompting - I'll make an effort to post some patches > soon, particularly the one that makes use of this new functionality. OK, I won't remove it. Not just yet, anyway. ;-) Thanx, Paul > Thanks, > NeilBrown > > > > > > Thanx, Paul > > > >> > NeilBrown > >> > > >> > > > >> > > Thanx, Paul > >> > > > >> > > ------------------------------------------------------------------------ > >> > > > >> > > commit e3408141ed7d702995b2fdc94703af88aadd226b > >> > > Author: Paul E. McKenney > >> > > Date: Tue Jul 24 15:28:09 2018 -0700 > >> > > > >> > > rcu: Provide functions for determining if call_rcu() has been invoked > >> > > > >> > > This commit adds rcu_head_init() and rcu_head_after_call_rcu() functions > >> > > to help RCU users detect when another CPU has passed the specified > >> > > rcu_head structure and function to call_rcu(). The rcu_head_init() > >> > > should be invoked before making the structure visible to RCU readers, > >> > > and then the rcu_head_after_call_rcu() may be invoked from within > >> > > an RCU read-side critical section on an rcu_head structure that > >> > > was obtained during a traversal of the data structure in question. > >> > > The rcu_head_after_call_rcu() function will return true if the rcu_head > >> > > structure has already been passed (with the specified function) to > >> > > call_rcu(), otherwise it will return false. > >> > > > >> > > If rcu_head_init() has not been invoked on the rcu_head structure > >> > > or if the rcu_head (AKA callback) has already been invoked, then > >> > > rcu_head_after_call_rcu() will do WARN_ON_ONCE(). > >> > > > >> > > Reported-by: NeilBrown > >> > > Signed-off-by: Paul E. McKenney > >> > > [ paulmck: Apply neilb naming feedback. ] > >> > > > >> > > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h > >> > > index e4f821165d0b..4db8bcacc51a 100644 > >> > > --- a/include/linux/rcupdate.h > >> > > +++ b/include/linux/rcupdate.h > >> > > @@ -857,6 +857,46 @@ static inline notrace void rcu_read_unlock_sched_notrace(void) > >> > > #endif /* #else #ifdef CONFIG_ARCH_WEAK_RELEASE_ACQUIRE */ > >> > > > >> > > > >> > > +/* Has the specified rcu_head structure been handed to call_rcu()? */ > >> > > + > >> > > +/* > >> > > + * rcu_head_init - Initialize rcu_head for rcu_head_after_call_rcu() > >> > > + * @rhp: The rcu_head structure to initialize. > >> > > + * > >> > > + * If you intend to invoke rcu_head_after_call_rcu() to test whether a > >> > > + * given rcu_head structure has already been passed to call_rcu(), then > >> > > + * you must also invoke this rcu_head_init() function on it just after > >> > > + * allocating that structure. Calls to this function must not race with > >> > > + * calls to call_rcu(), rcu_head_after_call_rcu(), or callback invocation. > >> > > + */ > >> > > +static inline void rcu_head_init(struct rcu_head *rhp) > >> > > +{ > >> > > + rhp->func = (rcu_callback_t)~0L; > >> > > +} > >> > > + > >> > > +/* > >> > > + * rcu_head_after_call_rcu - Has this rcu_head been passed to call_rcu()? > >> > > + * @rhp: The rcu_head structure to test. > >> > > + * @func: The function passed to call_rcu() along with @rhp. > >> > > + * > >> > > + * Returns @true if the @rhp has been passed to call_rcu() with @func, > >> > > + * and @false otherwise. Emits a warning in any other case, including > >> > > + * the case where @rhp has already been invoked after a grace period. > >> > > + * Calls to this function must not race with callback invocation. One way > >> > > + * to avoid such races is to enclose the call to rcu_head_after_call_rcu() > >> > > + * in an RCU read-side critical section that includes a read-side fetch > >> > > + * of the pointer to the structure containing @rhp. > >> > > + */ > >> > > +static inline bool > >> > > +rcu_head_after_call_rcu(struct rcu_head *rhp, rcu_callback_t f) > >> > > +{ > >> > > + if (READ_ONCE(rhp->func) == f) > >> > > + return true; > >> > > + WARN_ON_ONCE(READ_ONCE(rhp->func) != (rcu_callback_t)~0L); > >> > > + return false; > >> > > +} > >> > > + > >> > > + > >> > > /* Transitional pre-consolidation compatibility definitions. */ > >> > > > >> > > static inline void synchronize_rcu_bh(void) > >> > > diff --git a/kernel/rcu/rcu.h b/kernel/rcu/rcu.h > >> > > index 5dec94509a7e..4c56c1d98fb3 100644 > >> > > --- a/kernel/rcu/rcu.h > >> > > +++ b/kernel/rcu/rcu.h > >> > > @@ -224,6 +224,7 @@ void kfree(const void *); > >> > > */ > >> > > static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head) > >> > > { > >> > > + rcu_callback_t f; > >> > > unsigned long offset = (unsigned long)head->func; > >> > > > >> > > rcu_lock_acquire(&rcu_callback_map); > >> > > @@ -234,7 +235,9 @@ static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head) > >> > > return true; > >> > > } else { > >> > > RCU_TRACE(trace_rcu_invoke_callback(rn, head);) > >> > > - head->func(head); > >> > > + f = head->func; > >> > > + WRITE_ONCE(head->func, (rcu_callback_t)0L); > >> > > + f(head); > >> > > rcu_lock_release(&rcu_callback_map); > >> > > return false; > >> > > } > >> > >>