Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp60300ybp; Thu, 3 Oct 2019 10:10:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFsTuGsDShG96Em4jZ9IycOEtMNdN7L1zfshOHZfMbQUH+MKsfZhEcTK3FTsykmMnnoC3l X-Received: by 2002:a05:6402:1a4c:: with SMTP id bf12mr10693107edb.277.1570122608634; Thu, 03 Oct 2019 10:10:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570122608; cv=none; d=google.com; s=arc-20160816; b=UoKCUFgGpAsEzV2VCs8X2RCv2M1NDFYy+XAtycccP4jdhPoR71cCvyo1K9ycR7++NQ TzMHc6r3H0mKSqP5rUg0J6m+u4jp0neH2ljvqwK3wzV0M9rXwpDt6Tlkz7z378YBACPq STI0dvSq82l537t3qki5F1zH3d2N9ATVgm8xYah3v0to7iAPAGcDN+u42fGjrArrpCqv XN7w/7CIrYr0YvLErKzg+fC1OCOy+PKTogdsixE9qA3uTnFoRZVjOlq0AOIPcTV2Xj/z YyvQRnhRNJYV04xK7Iq5ViuxS06Za9bdQGAHHj6gOOm8mCb1wohE1wfhqF6twdZ26BCC 4zkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=6vFLz6hjT/E6jAGrCza0pDvCRKmeewzGZqcKlSfdW4A=; b=biICjzUIIMoSwtS9j1Au4cPKmyPVoYyU1OzYYrX5Q0N0h0PgNw0N/tpv+G/HS4Ozgz EhBP+Y8DtrN9YJEGjVi8S1sxUox5zRh2mBbJTdkYVWQydj9bQ8kH4bY7GJuiEkXDpXDA IwS5L6FpMmikQWHqpT1tC+LS7u6g7S9jxctgwSrhSMXpy48KRo83aIBpdfSwID0zyNVa 5ao4sb9SH+auz9YdbGPAwwgEuvurIbUzN1PTBqIXUiuCJTD0aSF6fwwtQIy7nYROWT2g tNPaPDQvrz0g8Kzx5nBS5KkoQni2RTadcx3pXMayqVdW+vOZFaMlj7FJU9UwhnZ+CDlS BtRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=WiHMjRyu; 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=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t18si1587388ejx.135.2019.10.03.10.09.44; Thu, 03 Oct 2019 10:10:08 -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; dkim=pass header.i=@efficios.com header.s=default header.b=WiHMjRyu; 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=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393105AbfJCRIP (ORCPT + 99 others); Thu, 3 Oct 2019 13:08:15 -0400 Received: from mail.efficios.com ([167.114.142.138]:42486 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404097AbfJCQfd (ORCPT ); Thu, 3 Oct 2019 12:35:33 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id CAAE033AE1C; Thu, 3 Oct 2019 12:35:31 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id k_jYdgfrH5Lv; Thu, 3 Oct 2019 12:35:31 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 36A5033AE16; Thu, 3 Oct 2019 12:35:31 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 36A5033AE16 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1570120531; bh=6vFLz6hjT/E6jAGrCza0pDvCRKmeewzGZqcKlSfdW4A=; h=Date:From:To:Message-ID:MIME-Version; b=WiHMjRyu9CrlZZmS1uV+PBnIFNCHRHBU6xcvtIcfVgLOHYL4GmGfCx3jyqzAUOTTT QltC1AZkRd0yqNiqz/cN2GqlaTiOdvJSaHuP8KRlCwjdM7ESdmlnWCK8eA2pl5QlUv k1+m6wNt1lLkGPmctjlSUshWEmIl3OFYoqR9lk+SrKyORpVTltPP+OpzlOPwhDMwEC QPDhttXiavrQuPUQpc+VbGSjEBBZj/pQqGNg/ScbD7dwCPxtSd86493PAIRSxtAumC SQLggu4OkLjLIt9+iUs9/qu1id2y74ys6eljERcGDQrUd/q6JQVHfKFD1PgPKKCZY8 GoUIjY/U7vZNg== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id 8mFuFfAugPSn; Thu, 3 Oct 2019 12:35:31 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id 135EF33AE0D; Thu, 3 Oct 2019 12:35:31 -0400 (EDT) Date: Thu, 3 Oct 2019 12:35:30 -0400 (EDT) From: Mathieu Desnoyers To: paulmck Cc: rcu , linux-kernel , Ingo Molnar , Lai Jiangshan , dipankar , Andrew Morton , Josh Triplett , Thomas Gleixner , Peter Zijlstra , rostedt , David Howells , Eric Dumazet , fweisbec , Oleg Nesterov , "Joel Fernandes, Google" , Bart Van Assche , Christoph Hellwig , Hannes Reinecke , Johannes Thumshirn , Shane M Seymour , Martin Message-ID: <644598334.955.1570120530976.JavaMail.zimbra@efficios.com> In-Reply-To: <20191003014310.13262-1-paulmck@kernel.org> References: <20191003014153.GA13156@paulmck-ThinkPad-P72> <20191003014310.13262-1-paulmck@kernel.org> Subject: Re: [PATCH tip/core/rcu 1/9] rcu: Upgrade rcu_swap_protected() to rcu_replace() MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.138] X-Mailer: Zimbra 8.8.15_GA_3847 (ZimbraWebClient - FF69 (Linux)/8.8.15_GA_3847) Thread-Topic: Upgrade rcu_swap_protected() to rcu_replace() Thread-Index: RcnUW8sQqVWa96y2rcR60UQZx5RREw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Oct 2, 2019, at 9:43 PM, paulmck paulmck@kernel.org wrote: > From: "Paul E. McKenney" > > Although the rcu_swap_protected() macro follows the example of swap(), > the interactions with RCU make its update of its argument somewhat > counter-intuitive. This commit therefore introduces an rcu_replace() > that returns the old value of the RCU pointer instead of doing the > argument update. Once all the uses of rcu_swap_protected() are updated > to instead use rcu_replace(), rcu_swap_protected() will be removed. We expose the rcu_xchg_pointer() API in liburcu (Userspace RCU) project. Any reason for not going that way and keep the kernel and user-space RCU APIs alike ? It's of course fine if they diverge, but we might want to at least consider if using the same API name would be OK. Thanks, Mathieu > > Link: > https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/ > Reported-by: Linus Torvalds > Signed-off-by: Paul E. McKenney > Cc: Bart Van Assche > Cc: Christoph Hellwig > Cc: Hannes Reinecke > Cc: Johannes Thumshirn > Cc: Shane M Seymour > Cc: Martin K. Petersen > --- > include/linux/rcupdate.h | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h > index 75a2ede..3b73287 100644 > --- a/include/linux/rcupdate.h > +++ b/include/linux/rcupdate.h > @@ -383,6 +383,24 @@ do { \ > } while (0) > > /** > + * rcu_replace() - replace an RCU pointer, returning its old value > + * @rcu_ptr: RCU pointer, whose old value is returned > + * @ptr: regular pointer > + * @c: the lockdep conditions under which the dereference will take place > + * > + * Perform a replacement, where @rcu_ptr is an RCU-annotated > + * pointer and @c is the lockdep argument that is passed to the > + * rcu_dereference_protected() call used to read that pointer. The old > + * value of @rcu_ptr is returned, and @rcu_ptr is set to @ptr. > + */ > +#define rcu_replace(rcu_ptr, ptr, c) \ > +({ \ > + typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c)); \ > + rcu_assign_pointer((rcu_ptr), (ptr)); \ > + __tmp; \ > +}) > + > +/** > * rcu_swap_protected() - swap an RCU and a regular pointer > * @rcu_ptr: RCU pointer > * @ptr: regular pointer > -- > 2.9.5 -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com