From patchwork Sun Sep 1 23:42:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Triplett X-Patchwork-Id: 2852621 Return-Path: X-Original-To: patchwork-linux-sparse@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2664EC0AB5 for ; Mon, 2 Sep 2013 00:09:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E402920258 for ; Mon, 2 Sep 2013 00:09:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0AC8E20257 for ; Mon, 2 Sep 2013 00:09:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753920Ab3IBAJQ (ORCPT ); Sun, 1 Sep 2013 20:09:16 -0400 Received: from slow1-d.mail.gandi.net ([217.70.178.86]:50924 "EHLO slow1-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753305Ab3IBAJQ (ORCPT ); Sun, 1 Sep 2013 20:09:16 -0400 X-Greylist: delayed 1510 seconds by postgrey-1.27 at vger.kernel.org; Sun, 01 Sep 2013 20:09:15 EDT Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by slow1-d.mail.gandi.net (Postfix) with ESMTP id D148247A21F for ; Mon, 2 Sep 2013 01:43:22 +0200 (CEST) Received: from mfilter18-d.gandi.net (mfilter18-d.gandi.net [217.70.178.146]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 9372141C074; Mon, 2 Sep 2013 01:42:58 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter18-d.gandi.net Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by mfilter18-d.gandi.net (mfilter18-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id J3YHgMyNMF-l; Mon, 2 Sep 2013 01:42:56 +0200 (CEST) X-Originating-IP: 50.43.39.152 Received: from leaf (static-50-43-39-152.bvtn.or.frontiernet.net [50.43.39.152]) (Authenticated sender: josh@joshtriplett.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 4AB3641C07B; Mon, 2 Sep 2013 01:42:54 +0200 (CEST) Date: Sun, 1 Sep 2013 16:42:52 -0700 From: Josh Triplett To: "Paul E. McKenney" Cc: Mathieu Desnoyers , Stephen Hemminger , lttng-dev@lists.lttng.org, sparse@chrisli.org, linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rcu: Make rcu_assign_pointer's assignment volatile and type-safe Message-ID: <20130901234251.GB25057@leaf> References: <20130822213318.49a57fa2@nehalam.linuxnetplumber.net> <20130823164637.GB3871@linux.vnet.ibm.com> <20130823171653.GA16558@Krystal> <20130823210822.GD3871@linux.vnet.ibm.com> <20130830005733.GA20664@linux.vnet.ibm.com> <20130830021637.GA21862@leaf> <20130831213228.GF3871@linux.vnet.ibm.com> <20130901204209.GA20802@leaf> <20130901222619.GH3871@linux.vnet.ibm.com> <20130901224317.GA25057@leaf> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20130901224317.GA25057@leaf> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP rcu_assign_pointer needs to use ACCESS_ONCE to make the assignment to the destination pointer volatile, to protect against compilers too clever for their own good. In addition, since rcu_assign_pointer force-casts the source pointer to add the __rcu address space (overriding any existing address space), add an explicit check that the source pointer has the __kernel address space to start with. This new check produces warnings like this, when attempting to assign from a __user pointer: test.c:25:9: warning: incorrect type in argument 2 (different address spaces) test.c:25:9: expected struct foo * test.c:25:9: got struct foo [noderef] *badsrc Signed-off-by: Josh Triplett --- include/linux/rcupdate.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h index 4b14bdc..3f62def 100644 --- a/include/linux/rcupdate.h +++ b/include/linux/rcupdate.h @@ -510,8 +510,17 @@ static inline void rcu_preempt_sleep_check(void) #ifdef __CHECKER__ #define rcu_dereference_sparse(p, space) \ ((void)(((typeof(*p) space *)p) == p)) +/* The dummy first argument in __rcu_assign_pointer_typecheck makes the + * typechecked pointer the second argument, matching rcu_assign_pointer itself; + * this avoids confusion about argument numbers in warning messages. */ +#define __rcu_assign_pointer_check_kernel(v) \ + do { \ + extern void __rcu_assign_pointer_typecheck(int, typeof(*(v)) __kernel *); \ + __rcu_assign_pointer_typecheck(0, v); \ + } while (0) #else /* #ifdef __CHECKER__ */ #define rcu_dereference_sparse(p, space) +#define __rcu_assign_pointer_check_kernel(v) do { } while (0) #endif /* #else #ifdef __CHECKER__ */ #define __rcu_access_pointer(p, space) \ @@ -555,7 +564,8 @@ static inline void rcu_preempt_sleep_check(void) #define __rcu_assign_pointer(p, v, space) \ do { \ smp_wmb(); \ - (p) = (typeof(*v) __force space *)(v); \ + __rcu_assign_pointer_check_kernel(v); \ + ACCESS_ONCE(p) = (typeof(*(v)) __force space *)(v); \ } while (0)