From patchwork Thu Jan 24 11:54:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Vadai X-Patchwork-Id: 215333 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 B4E632C007B for ; Thu, 24 Jan 2013 22:54:56 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753941Ab3AXLyw (ORCPT ); Thu, 24 Jan 2013 06:54:52 -0500 Received: from eu1sys200aog117.obsmtp.com ([207.126.144.143]:58287 "HELO eu1sys200aog117.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1753440Ab3AXLyj (ORCPT ); Thu, 24 Jan 2013 06:54:39 -0500 Received: from mtlsws123.lab.mtl.com ([82.166.227.17]) (using TLSv1) by eu1sys200aob117.postini.com ([207.126.147.11]) with SMTP ID DSNKUQEg+gc88xSI1oNXaGsuzg4uHZ7q/JsN@postini.com; Thu, 24 Jan 2013 11:54:39 UTC Received: from r-vnc07.mtr.labs.mlnx (r-vnc07.mtr.labs.mlnx [10.208.0.119]) by mtlsws123.lab.mtl.com (8.13.8/8.13.8) with ESMTP id r0OBtHsW010194; Thu, 24 Jan 2013 13:55:23 +0200 From: Amir Vadai To: "David S. Miller" Cc: netdev@vger.kernel.org, Or Gerlitz , Amir Vadai , Eric Dumazet , Yevgeny Petrilin , Eugenia Emantayev Subject: [PATCH net-next V2 5/6] net/mlx4_en: Fix a race when closing TX queue Date: Thu, 24 Jan 2013 13:54:18 +0200 Message-Id: <1359028459-30961-6-git-send-email-amirv@mellanox.com> X-Mailer: git-send-email 1.7.8.2 In-Reply-To: <1359028459-30961-1-git-send-email-amirv@mellanox.com> References: <1359028459-30961-1-git-send-email-amirv@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There is a possible race where the TX completion handler can clean the entire TX queue between the decision that the queue is full and actually closing it. To avoid this situation, check again if the queue is really full, if not, reopen the transmit and continue with sending the packet. CC: Eric Dumazet Signed-off-by: Yevgeny Petrilin Signed-off-by: Eugenia Emantayev Signed-off-by: Amir Vadai --- drivers/net/ethernet/mellanox/mlx4/en_tx.c | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c index 16af338..1e793e3 100644 --- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c +++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c @@ -588,7 +588,21 @@ netdev_tx_t mlx4_en_xmit(struct sk_buff *skb, struct net_device *dev) netif_tx_stop_queue(ring->tx_queue); priv->port_stats.queue_stopped++; - return NETDEV_TX_BUSY; + /* If queue was emptied after the if, and before the + * stop_queue - need to wake the queue, or else it will remain + * stopped forever. + * Need a memory barrier to make sure ring->cons was not + * updated before queue was stopped. + */ + wmb(); + + if (unlikely(((int)(ring->prod - ring->cons)) <= + ring->size - HEADROOM - MAX_DESC_TXBBS)) { + netif_tx_wake_queue(ring->tx_queue); + priv->port_stats.wake_queue++; + } else { + return NETDEV_TX_BUSY; + } } /* Track current inflight packets for performance analysis */