From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Josh Triplett <josh@joshtriplett.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Stephen Hemminger <stephen@networkplumber.org>,
lttng-dev@lists.lttng.org, sparse@chrisli.org,
linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rcu: Make rcu_assign_pointer's assignment volatile and type-safe
Date: Sun, 1 Sep 2013 19:01:37 -0700 [thread overview]
Message-ID: <20130902020137.GI3871@linux.vnet.ibm.com> (raw)
In-Reply-To: <20130901234251.GB25057@leaf>
On Sun, Sep 01, 2013 at 04:42:52PM -0700, Josh Triplett wrote:
> 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 *<noident>
> test.c:25:9: got struct foo [noderef] <asn:1>*badsrc
>
> Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Queued for 3.13, thank you very much!
Thanx, Paul
> ---
> include/linux/rcupdate.h | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> 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)
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
prev parent reply other threads:[~2013-09-02 2:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20130822213318.49a57fa2@nehalam.linuxnetplumber.net>
[not found] ` <20130823164637.GB3871@linux.vnet.ibm.com>
[not found] ` <20130823171653.GA16558@Krystal>
[not found] ` <20130823210822.GD3871@linux.vnet.ibm.com>
2013-08-30 0:57 ` [RFC] adding into middle of RCU list Paul E. McKenney
2013-08-30 2:16 ` Josh Triplett
2013-08-31 21:32 ` Paul E. McKenney
2013-09-01 20:42 ` Josh Triplett
2013-09-01 22:26 ` Paul E. McKenney
2013-09-01 22:43 ` Josh Triplett
2013-09-01 23:42 ` [PATCH] rcu: Make rcu_assign_pointer's assignment volatile and type-safe Josh Triplett
2013-09-02 2:01 ` Paul E. McKenney [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130902020137.GI3871@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sparse@vger.kernel.org \
--cc=lttng-dev@lists.lttng.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=sparse@chrisli.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).