lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Thu, 19 Aug 2010 23:58:03 +0800
From:	Changli Gao <xiaosuo@...il.com>
To:	Eric Dumazet <eric.dumazet@...il.com>
Cc:	David Miller <davem@...emloft.net>,
	netdev <netdev@...r.kernel.org>,
	Mathieu Desnoyers <mathieu.desnoyers@...ymtl.ca>
Subject: Re: [PATCH net-next-2.6] net: build_ehash_secret() and rt_bind_peer() cleanups

On Thu, Aug 19, 2010 at 11:46 PM, Eric Dumazet <eric.dumazet@...il.com> wrote:
> 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@...il.com>
> CC: Mathieu Desnoyers <mathieu.desnoyers@...ymtl.ca>
> ---
>  net/ipv4/af_inet.c |    8 +++-----
>  net/ipv4/route.c   |   11 +++--------
>  2 files changed, 6 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..ae3dba7 100644
> --- a/net/ipv4/route.c
> +++ b/net/ipv4/route.c
> @@ -1268,18 +1268,13 @@ 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)
> +       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);
>  }


-- 
Regards,
Changli Gao(xiaosuo@...il.com)
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ