From patchwork Wed Jul 21 15:59:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Zolotarov X-Patchwork-Id: 59449 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 4F0E3B70AF for ; Thu, 22 Jul 2010 01:59:24 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932070Ab0GUP7T (ORCPT ); Wed, 21 Jul 2010 11:59:19 -0400 Received: from mms2.broadcom.com ([216.31.210.18]:4745 "EHLO mms2.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755572Ab0GUP7S (ORCPT ); Wed, 21 Jul 2010 11:59:18 -0400 Received: from [10.9.200.131] by mms2.broadcom.com with ESMTP (Broadcom SMTP Relay (Email Firewall v6.3.2)); Wed, 21 Jul 2010 08:59:04 -0700 X-Server-Uuid: D3C04415-6FA8-4F2C-93C1-920E106A2031 Received: from mail-irva-12.broadcom.com (10.11.16.101) by IRVEXCHHUB01.corp.ad.broadcom.com (10.9.200.131) with Microsoft SMTP Server id 8.2.247.2; Wed, 21 Jul 2010 08:59:04 -0700 Received: from [10.185.6.94] (lb-tlvb-vladz.il.broadcom.com [10.185.6.94]) by mail-irva-12.broadcom.com (Postfix) with ESMTP id A8BFF69CA8; Wed, 21 Jul 2010 08:59:02 -0700 (PDT) Subject: [PATCH 1/3 net-2.6] bnx2x: Protect a SM state change From: "Vladislav Zolotarov" To: "Dave Miller" cc: "netdev list" , "Eilon Greenstein" , "Dmitry Kravkov" Date: Wed, 21 Jul 2010 18:59:01 +0300 Message-ID: <1279727941.14094.42.camel@lb-tlvb-vladz> MIME-Version: 1.0 X-Mailer: Evolution 2.28.3 X-WSS-ID: 6059C6C210037813747-01-01 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Bug fix: Protect the statistics state machine state update with a spinlock. Otherwise there was a race condition that would cause the statistics stay enabled despite they were disabled in the LINK_DOWN event handler. Signed-off-by: Vladislav Zolotarov Signed-off-by: Dmitry Kravkov Signed-off-by: Eilon Greenstein --- drivers/net/bnx2x.h | 4 ++++ drivers/net/bnx2x_main.c | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/net/bnx2x.h b/drivers/net/bnx2x.h index 8bd2368..bb0872a 100644 --- a/drivers/net/bnx2x.h +++ b/drivers/net/bnx2x.h @@ -1062,6 +1062,10 @@ struct bnx2x { /* used to synchronize stats collecting */ int stats_state; + + /* used for synchronization of concurrent threads statistics handling */ + spinlock_t stats_lock; + /* used by dmae command loader */ struct dmae_command stats_dmae; int executer_idx; diff --git a/drivers/net/bnx2x_main.c b/drivers/net/bnx2x_main.c index 57ff5b3..3dc876c 100644 --- a/drivers/net/bnx2x_main.c +++ b/drivers/net/bnx2x_main.c @@ -4849,16 +4849,18 @@ static const struct { static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event) { - enum bnx2x_stats_state state = bp->stats_state; + enum bnx2x_stats_state state; if (unlikely(bp->panic)) return; - bnx2x_stats_stm[state][event].action(bp); + /* Protect a state change flow */ + spin_lock_bh(&bp->stats_lock); + state = bp->stats_state; bp->stats_state = bnx2x_stats_stm[state][event].next_state; + spin_unlock_bh(&bp->stats_lock); - /* Make sure the state has been "changed" */ - smp_wmb(); + bnx2x_stats_stm[state][event].action(bp); if ((event != STATS_EVENT_UPDATE) || netif_msg_timer(bp)) DP(BNX2X_MSG_STATS, "state %d -> event %d -> state %d\n", @@ -9908,6 +9910,7 @@ static int __devinit bnx2x_init_bp(struct bnx2x *bp) mutex_init(&bp->port.phy_mutex); mutex_init(&bp->fw_mb_mutex); + spin_lock_init(&bp->stats_lock); #ifdef BCM_CNIC mutex_init(&bp->cnic_mutex); #endif