From patchwork Thu Sep 2 13:53:46 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 63481 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 15D2EB7135 for ; Thu, 2 Sep 2010 23:53:57 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752927Ab0IBNxw (ORCPT ); Thu, 2 Sep 2010 09:53:52 -0400 Received: from mail-ey0-f174.google.com ([209.85.215.174]:33879 "EHLO mail-ey0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751966Ab0IBNxv (ORCPT ); Thu, 2 Sep 2010 09:53:51 -0400 Received: by eyb6 with SMTP id 6so245581eyb.19 for ; Thu, 02 Sep 2010 06:53:50 -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 :content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=5gIqIOFiMPsdHRYpYnyGVNCvOJd4AS9tXsdMpTFkCsU=; b=S96+EN2Th581+glUj2jEOTqph9er0ByEK3QodbZNvhJ/5+Rc+TW36gfr/bJo3yPUAp XZiO2FU631iR4mU2L0y6ZitWmvCKPjvBDY3BJj1/DamONqNE7fju1JSyJZD+DPSUZmo3 7VPnHfwvGYCCxbmmS4OHkahGJrAlilZ/Wdx1M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; b=QGficsuiO5JSHsft2f2xYWzZRG3XliBWmwWV75nuQ6b27b6rr4m4xkLyPH21Il3OBK SBgC71YL+FzBPcB68zIXK5gHGr644jxROEYmyEfcSd4YzVDVdbLPslSHUz6xSx9S7Z5f Sl6smXh0JAx6JH4blzzKz4pzmGaERNVku+Ass= Received: by 10.216.52.135 with SMTP id e7mr9328215wec.98.1283435630539; Thu, 02 Sep 2010 06:53:50 -0700 (PDT) Received: from [10.150.51.214] (gw0.net.jmsp.net [212.23.165.14]) by mx.google.com with ESMTPS id p45sm354269weq.21.2010.09.02.06.53.48 (version=SSLv3 cipher=RC4-MD5); Thu, 02 Sep 2010 06:53:49 -0700 (PDT) Subject: [PATCN net-next-2.6] net: dev_add_pack() & __dev_remove_pack() changes From: Eric Dumazet To: David Miller Cc: netdev Date: Thu, 02 Sep 2010 15:53:46 +0200 Message-ID: <1283435626.2454.764.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 Add a small helper ptype_head() to get the head to manipulate dev_add_pack() & __dev_remove_pack() can use a spinlock without blocking BH, since softirq use RCU, and these functions are run from process context only. Signed-off-by: Eric Dumazet --- net/core/dev.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 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/core/dev.c b/net/core/dev.c index d8c43e7..efd318d 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -371,6 +371,14 @@ static inline void netdev_set_addr_lockdep_class(struct net_device *dev) * --ANK (980803) */ +static inline struct list_head *ptype_head(const struct packet_type *pt) +{ + if (pt->type == htons(ETH_P_ALL)) + return &ptype_all; + else + return &ptype_base[ntohs(pt->type) & PTYPE_HASH_MASK]; +} + /** * dev_add_pack - add packet handler * @pt: packet type declaration @@ -386,16 +394,11 @@ static inline void netdev_set_addr_lockdep_class(struct net_device *dev) void dev_add_pack(struct packet_type *pt) { - int hash; + struct list_head *head = ptype_head(pt); - spin_lock_bh(&ptype_lock); - if (pt->type == htons(ETH_P_ALL)) - list_add_rcu(&pt->list, &ptype_all); - else { - hash = ntohs(pt->type) & PTYPE_HASH_MASK; - list_add_rcu(&pt->list, &ptype_base[hash]); - } - spin_unlock_bh(&ptype_lock); + spin_lock(&ptype_lock); + list_add_rcu(&pt->list, head); + spin_unlock(&ptype_lock); } EXPORT_SYMBOL(dev_add_pack); @@ -414,15 +417,10 @@ EXPORT_SYMBOL(dev_add_pack); */ void __dev_remove_pack(struct packet_type *pt) { - struct list_head *head; + struct list_head *head = ptype_head(pt); struct packet_type *pt1; - spin_lock_bh(&ptype_lock); - - if (pt->type == htons(ETH_P_ALL)) - head = &ptype_all; - else - head = &ptype_base[ntohs(pt->type) & PTYPE_HASH_MASK]; + spin_lock(&ptype_lock); list_for_each_entry(pt1, head, list) { if (pt == pt1) { @@ -433,7 +431,7 @@ void __dev_remove_pack(struct packet_type *pt) printk(KERN_WARNING "dev_remove_pack: %p not found.\n", pt); out: - spin_unlock_bh(&ptype_lock); + spin_unlock(&ptype_lock); } EXPORT_SYMBOL(__dev_remove_pack);