Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp6049730ybg; Tue, 22 Oct 2019 12:17:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqztKcgVP3p849Lee2sso6czisXCEbZuOlEt1ionMVhzsy4u0vd7QZAnsjLjhTprpmFwNQgm X-Received: by 2002:a50:d713:: with SMTP id t19mr16154561edi.185.1571771874911; Tue, 22 Oct 2019 12:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571771874; cv=none; d=google.com; s=arc-20160816; b=ysjeqoqiJOrqQ6Kp4DspsD22A6ccbB9u+VDQcYw6iDc/Hxhwncs/1a5N5X74QYPZWQ mAKhpLr+tGMhgJKYGXtV0fI+DOHczDYSxvdaUkGkLuDy71Ls5IULkM7i4ICpDj/wshg4 FnLc/2QQCMk6q9yGFzwq9sV1IpR5w/lGpBW8jltqI1KODdSODnnkpovQSmAgYsKzKotg D4JZkf/3LH35P18kM7PYpewJ/QKaHU1WAVHovOy4ivEK4aZOP+yGUMfv49icN0mVZ3da ygsDeFO296HhTdqejWM6dDy/n5G6g95oM6bSYgRQ8J8jnSQdV9xB5zJEpsEAQF8X6kjT 7Z5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=SBlb9w60Sqf6l4Nc/okzt1S97E0N7NUS3u0cnLu7ed4=; b=gxrrNfmC/oFqw5kE5/fdnaespeeB6G10yxS5qVQwEY/XyF3K9bmei0HP+9mAdlwwTg pG/lcQ0S17ZdSyP+VBSlL9BAe/CWJw5B5ke13e1dp01MJJydYdnRjHFzWAGoicjUcUaP qu5ZHZZ4mkQh4vvRdnHd9QgMcTBYY5Z8Jh2GAG1RnrVGJvRvGxcjGCaWGkoDrxZtmHwT BW3COXoKtPgrCVBdEE6wsWyrb2i/bwM5PNLclEARBUEAY+kgj7/oOGMutnYu/OteI16G 5hgIGuKSPG9xIx96lZ2fHTCJvKOnnCxxw7L4l5zckIWOWKjGsHtsF52vu3N+ql8GN9PI 0Psw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BhUOdhzl; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k39si7142412edb.99.2019.10.22.12.17.30; Tue, 22 Oct 2019 12:17:54 -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=@kernel.org header.s=default header.b=BhUOdhzl; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732882AbfJVTMW (ORCPT + 99 others); Tue, 22 Oct 2019 15:12:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:43238 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729696AbfJVTMV (ORCPT ); Tue, 22 Oct 2019 15:12:21 -0400 Received: from localhost.localdomain (rrcs-50-75-166-42.nys.biz.rr.com [50.75.166.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A732021783; Tue, 22 Oct 2019 19:12:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571771540; bh=x0hWzsK+SyGvpdoXV2Qzb3lMOfU9IISAP3AHFmIYd1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BhUOdhzl+jIqtkc2bGLEztfls5oh/lSleXrwmA0zEfzyZ3CdHpJdvORmIbcIy6iyE M2DSe0i2Rvl4LOpT5JmqPShX7HkSHai0uD/jrSp5FGXPTBau97UThytdhPJfkxE1Ub eTKAIUtr2edbPEYRbVHswi/NOIJ7yJ/Sg730r+qc= From: paulmck@kernel.org To: rcu@vger.kernel.org Cc: linux-kernel@vger.kernel.org, mingo@kernel.org, jiangshanlai@gmail.com, dipankar@in.ibm.com, akpm@linux-foundation.org, mathieu.desnoyers@efficios.com, josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com, fweisbec@gmail.com, oleg@redhat.com, joel@joelfernandes.org, "Paul E. McKenney" , Bart Van Assche , Christoph Hellwig , Hannes Reinecke , Johannes Thumshirn , Shane M Seymour , "Martin K . Petersen" Subject: [PATCH tip/core/rcu 01/10] rcu: Upgrade rcu_swap_protected() to rcu_replace() Date: Tue, 22 Oct 2019 12:12:06 -0700 Message-Id: <20191022191215.25781-1-paulmck@kernel.org> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20191022191136.GA25627@paulmck-ThinkPad-P72> References: <20191022191136.GA25627@paulmck-ThinkPad-P72> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Link: https://lore.kernel.org/lkml/CAHk-=wiAsJLw1egFEE=Z7-GGtM6wcvtyytXZA1+BHqta4gg6Hw@mail.gmail.com/ Reported-by: Linus Torvalds [ paulmck: From rcu_replace() to rcu_replace_pointer() per Ingo Molnar. ] 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..185dd97 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -383,6 +383,24 @@ do { \ } while (0) /** + * rcu_replace_pointer() - 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_pointer(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