From: Eric Dumazet <eric.dumazet@gmail.com>
To: Changli Gao <xiaosuo@gmail.com>
Cc: David Miller <davem@davemloft.net>,
netdev <netdev@vger.kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Subject: [PATCH net-next-2.6 v2] net: build_ehash_secret() and rt_bind_peer() cleanups
Date: Thu, 19 Aug 2010 18:10:45 +0200 [thread overview]
Message-ID: <1282234245.25476.3.camel@edumazet-laptop> (raw)
In-Reply-To: <AANLkTinpqNa3cgEb=86H0sYXdLmo-RP1G2icJgWpfyN1@mail.gmail.com>
Le jeudi 19 août 2010 à 23:58 +0800, Changli Gao a écrit :
> > - if (peer)
> > + peer = cmpxchg(&rt->peer, NULL, peer);
> > +
> > + if (unlikely(peer))
>
> It isn't correct, and should be
> if (unlikely(cmpxchg(&rt->peer, NULL, peer) != NULL))
>
> > inet_putpeer(peer);
> > }
>
>
Good catch, thanks !
I was trying to take into account peer being NULL...
[PATCH net-next-2.6] net: build_ehash_secret() and rt_bind_peer() cleanups
Now cmpxchg() is available on all arches, we can use it in
build_ehash_secret() and rt_bind_peer() instead of using spinlocks.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
CC: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
net/ipv4/af_inet.c | 8 +++-----
net/ipv4/route.c | 9 +--------
2 files changed, 4 insertions(+), 13 deletions(-)
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 6a1100c..f581f77 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -227,18 +227,16 @@ EXPORT_SYMBOL(inet_ehash_secret);
/*
* inet_ehash_secret must be set exactly once
- * Instead of using a dedicated spinlock, we (ab)use inetsw_lock
*/
void build_ehash_secret(void)
{
u32 rnd;
+
do {
get_random_bytes(&rnd, sizeof(rnd));
} while (rnd == 0);
- spin_lock_bh(&inetsw_lock);
- if (!inet_ehash_secret)
- inet_ehash_secret = rnd;
- spin_unlock_bh(&inetsw_lock);
+
+ cmpxchg(&inet_ehash_secret, 0, rnd);
}
EXPORT_SYMBOL(build_ehash_secret);
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 3f56b6e..85a67c9 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1268,18 +1268,11 @@ skip_hashing:
void rt_bind_peer(struct rtable *rt, int create)
{
- static DEFINE_SPINLOCK(rt_peer_lock);
struct inet_peer *peer;
peer = inet_getpeer(rt->rt_dst, create);
- spin_lock_bh(&rt_peer_lock);
- if (rt->peer == NULL) {
- rt->peer = peer;
- peer = NULL;
- }
- spin_unlock_bh(&rt_peer_lock);
- if (peer)
+ if (peer && cmpxchg(&rt->peer, NULL, peer) != NULL)
inet_putpeer(peer);
}
next prev parent reply other threads:[~2010-08-19 16:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-19 15:46 [PATCH net-next-2.6] net: build_ehash_secret() and rt_bind_peer() cleanups Eric Dumazet
2010-08-19 15:58 ` Changli Gao
2010-08-19 16:10 ` Eric Dumazet [this message]
2010-08-20 7:51 ` [PATCH net-next-2.6 v2] " David Miller
2010-08-19 16:10 ` [PATCH net-next-2.6] " Changli Gao
2010-08-19 16:13 ` Mathieu Desnoyers
2010-08-19 16:30 ` Mathieu Desnoyers
2010-08-19 16:28 ` Mathieu Desnoyers
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=1282234245.25476.3.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=davem@davemloft.net \
--cc=mathieu.desnoyers@polymtl.ca \
--cc=netdev@vger.kernel.org \
--cc=xiaosuo@gmail.com \
/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