From: Eric Dumazet <eric.dumazet@gmail.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: David Miller <davem@davemloft.net>, netdev <netdev@vger.kernel.org>
Subject: Re: [PATCH net-next] inet: remove rcu protection on tw_net
Date: Wed, 14 Dec 2011 23:28:10 +0100 [thread overview]
Message-ID: <1323901690.2631.15.camel@edumazet-laptop> (raw)
In-Reply-To: <m1d3bqaowg.fsf@fess.ebiederm.org>
Le mercredi 14 décembre 2011 à 12:17 -0800, Eric W. Biederman a écrit :
> Eric Dumazet <eric.dumazet@gmail.com> writes:
>
> > commit b099ce2602d806 (net: Batch inet_twsk_purge) added rcu protection
> > on tw_net for no obvious reason.
>
> From that commit I see:
>
> sk_nulls_for_each_rcu(sk, node, &head->twchain) {
> tw = inet_twsk(sk);
> - if (!net_eq(twsk_net(tw), net) ||
> - tw->tw_family != family)
> + if ((tw->tw_family != family) ||
> + atomic_read(&twsk_net(tw)->count))
>
> That atomic_read is a new dereference of twsk_net in an only rcu
> protected section. That seems like an obvious reason to me.
>
Absolutely not.
As I said twsk_net() cannot change in a tw lifetime.
(If it could, this code would be bogus anyway, you should use :
net = twsk_net(tw);
if (tw->tw_family != family || !net || atomic_read(&net->count))
...
> > struct net are refcounted anyway since timewait sockets escape from rcu
> > protected sections. tw_net stay valid for the whole timwait lifetime.
>
> What? twsk_net_set does not bump the struct net ref count.
>
The commit I mentioned did not change anything in this respect.
> There is that stupid hold_net/release_net over designed debugging
> thinko that makes it look like we have a refcount. We should probably
> just kill that thing. But a time wait socket unlike a normal socket
> does not keep a network namespace alive. Which is why we have to purge
> pending timewait sockets when a network namespace exits.
>
Since you do a cleanup _before_ removing "struct net", you have absolute
guarantee tw_net is stable, you dont need rcu_dereference() (and implied
smb_rmb()) at all.
Why pay the price twice, once in the super heavy inet_twsk_purge()
function, once in every twsk_net() calls ?
[ By the way, rcu_dereference_raw() dubious use is another sign we dont
really know what RCU invariant is respected when calling twsk_net(tw) ]
> > This also removes a lot of sparse errors.
>
> What is sparse saying that we are doing wrong?
>
CONFIG_SPARSE_RCU_POINTER=y
make C=2 net/ipv4/inet_timewait_sock.o
CHECK net/ipv4/inet_timewait_sock.c
include/net/inet_timewait_sock.h:222:16: error: incompatible types in
comparison expression (different address spaces)
[ repeat NN times ]
comparison expression (different address spaces)
include/net/inet_timewait_sock.h:222:16: error: incompatible types in
comparison expression (different address spaces)
include/net/inet_timewait_sock.h:222:16: error: incompatible types in
comparison expression (different address spaces)
include/net/inet_timewait_sock.h:222:16: error: incompatible types in
comparison expression (different address spaces)
include/net/inet_timewait_sock.h:222:16: error: too many errors
> There may be constraints that are strong enough that we can get away
> this but I am at least a little dubious.
>
Thanks for reviewing and comments !
prev parent reply other threads:[~2011-12-14 22:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-14 14:58 [PATCH net-next] inet: remove rcu protection on tw_net Eric Dumazet
2011-12-14 18:35 ` David Miller
2011-12-14 20:17 ` Eric W. Biederman
2011-12-14 22:28 ` Eric Dumazet [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=1323901690.2631.15.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=ebiederm@xmission.com \
--cc=netdev@vger.kernel.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