From patchwork Thu Aug 19 16:10:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 62193 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 5E8E6B70EF for ; Fri, 20 Aug 2010 02:11:24 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752819Ab0HSQKv (ORCPT ); Thu, 19 Aug 2010 12:10:51 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:34423 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752696Ab0HSQKt (ORCPT ); Thu, 19 Aug 2010 12:10:49 -0400 Received: by wwi17 with SMTP id 17so2642386wwi.1 for ; Thu, 19 Aug 2010 09:10:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:cc :in-reply-to:references:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; bh=fb931D+6zcZ2HebD+xsTNBaykzlKLzOQrwkvntXyAWI=; b=KcSwl6RoGxcYG4l4tAIjGkhU6Esm7pE031I2TvzWhfiQ7F2DgxUTBh5DTL6cmEOx14 2mfGkXsdlJaV8Na51CWQ41xoj3iyzWpFLiE3a5iV40MZLBHSdlrXfrSkA25ZG17k3NNd 7VY9DUuRPx4/1palmj+S3Utq4gyCSFQAy4VOc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding; b=uC5mwMet35T2/PyGLyEyc8TfcVAzI/hDi60VQmQQVdcJNw/5d/PixTBXyOVSWlzvxq D/hzBzKPuylhyUTuGgCN9gV2cxPIPaxcvLE7mLySXYpC2a81QmXPAugvcEBlyf62bUbr WcCKgPqEzbgvDWkbEbtHYyQiCceYjbPORJInA= Received: by 10.227.135.78 with SMTP id m14mr57399wbt.47.1282234248066; Thu, 19 Aug 2010 09:10:48 -0700 (PDT) Received: from [127.0.0.1] ([85.17.35.125]) by mx.google.com with ESMTPS id b23sm1169232wbb.22.2010.08.19.09.10.46 (version=SSLv3 cipher=RC4-MD5); Thu, 19 Aug 2010 09:10:47 -0700 (PDT) Subject: [PATCH net-next-2.6 v2] net: build_ehash_secret() and rt_bind_peer() cleanups From: Eric Dumazet To: Changli Gao Cc: David Miller , netdev , Mathieu Desnoyers In-Reply-To: References: <1282232815.2549.61.camel@edumazet-laptop> Date: Thu, 19 Aug 2010 18:10:45 +0200 Message-ID: <1282234245.25476.3.camel@edumazet-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 CC: Mathieu Desnoyers --- net/ipv4/af_inet.c | 8 +++----- net/ipv4/route.c | 9 +-------- 2 files changed, 4 insertions(+), 13 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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); }