Thread (55 messages) 55 messages, 6 authors, 2013-06-10

Re: [PATCH v2] rcu: fix a race in hlist_nulls_for_each_entry_rcu macro

From: Roman Gushchin <hidden>
Date: 2013-05-29 10:09:38
Also in: lkml

On 29.05.2013 09:08, Eric Dumazet wrote:
On Tue, 2013-05-28 at 18:31 -0700, Paul E. McKenney wrote:
quoted
On Tue, May 28, 2013 at 05:34:53PM -0700, Eric Dumazet wrote:
quoted
On Tue, 2013-05-28 at 13:10 +0400, Roman Gushchin wrote:
quoted
On 28.05.2013 04:12, Eric Dumazet wrote:
About your earlier question, I really don't know why compiler would
cache a memory read if we explicitly use barrier() to prevent this from
happening.
I agree.
BTW Roman patch generates a double load as in :

2cb1:       49 8b 07                mov    (%r15),%rax
2cb4:       49 8b 07                mov    (%r15),%rax


...
2ea2:       e8 f9 dc ff ff          callq  ba0 <sock_put>
2ea7:       8b 0c 24                mov    (%rsp),%ecx
2eaa:       e9 02 fe ff ff          jmpq   2cb1 <udp4_lib_lookup2+0x91>

because of ACCESS_ONCE() used twice, once explicitly in
hlist_nulls_for_each_entry_rcu(), and once in rcu_dereference_raw()

While barrier();ptr = rcu_dereference(X); does generate a single load.
It's true.

Unfortunately, using barrier() can also prevent gcc from making some
(acceptable) code optimizations, because barrier() has a global effect,
and everything we want to reload is the (head->first) pointer.
So, to be absolutely precise, we have to introduce and use
the ACCESS_FIELD_ONCE() macro.

In any case, it doesn't look like a big problem.
In my mind, the best solution is to use the ACCESS_FIELD_ONCE() macro,
but using barrier() is also an acceptable solution.

Regards,
Roman
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help