From patchwork Tue May 24 23:56:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 9134463 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1FF5460221 for ; Tue, 24 May 2016 23:57:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1251627811 for ; Tue, 24 May 2016 23:57:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06F632821B; Tue, 24 May 2016 23:57:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2E5C327811 for ; Tue, 24 May 2016 23:57:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b5MC7-0005zG-O9; Tue, 24 May 2016 23:57:03 +0000 Received: from mout.gmx.net ([212.227.17.22]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b5MC5-0005yG-Kt for linux-rockchip@lists.infradead.org; Tue, 24 May 2016 23:57:02 +0000 Received: from [192.168.178.39] ([78.43.221.200]) by mail.gmx.com (mrgmx103) with ESMTPSA (Nemesis) id 0MUYiV-1axHJb1B59-00RM4S; Wed, 25 May 2016 01:56:24 +0200 Subject: Re: [PATCH v2] ethernet:arc: Fix racing of TX ring buffer To: Francois Romieu References: <20160517.142456.2247845107325931733.davem@davemloft.net> <20160518000153.GA21757@electric-eye.fr.zoreil.com> <573CD09D.1060307@gmx.de> <20160518225529.GA18671@electric-eye.fr.zoreil.com> <573E2D0C.604@gmx.de> <20160520003145.GA22420@electric-eye.fr.zoreil.com> <20160521160910.GA14945@debian-dorm> <5740E82F.8040903@gmx.de> <20160522091742.GA8681@debian-dorm> <57419853.9050701@gmx.de> <20160522223659.GB5086@electric-eye.fr.zoreil.com> <5743A9DD.8010202@gmx.de> From: Lino Sanfilippo Message-ID: <5744EA24.7060806@gmx.de> Date: Wed, 25 May 2016 01:56:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: <5743A9DD.8010202@gmx.de> X-Provags-ID: V03:K0:JI8ush+VWo8qGYcYYCki2tDtNr4oQCluDy0bxFtze6LqEkww+yC x2rp4MOiP7H5IKZF/Lne+E5XFAdfgdrjAb5hIAFiW5AaFj2kMPHV62pwAXYUGOA7t3s646o u4Uej/oNiG5dSpWRb2eJG4S/buU1/1veB2s0QxMH0SblD08JHOr+fc417eKtmDmU1mARM0/ NCU7OveCKbxXBDlEL7k0g== X-UI-Out-Filterresults: notjunk:1; V01:K0:oBxrmYxS4sY=:dEqdww5XqRC/eE9j53jgNH 4iWEsZysUE99loSB751WglACwx215/cdXPeZD1MNBMoL0gqMflTFnt7OKH5i2U5dTq7lyoZQ+ kPViIdc1q9FsND/WNotCPfOcUDcmJHEoEPUTWtGh7LD+LZHbzeobl41est0T67Ur5jvbIfAfA zXlZY8zpb5w94dpyZqtfBS4jNJrjb3IWqE767GtlKcg7iM9561z5JA1CU7q4yvhgE2VlWv2ff nmWt9KISn4p4N8cK+Tur0emMcqzTNQMJ86hdvwzj/0RR2R6moX2CytJnZLJiC4ewW3jqf7fqE bm8rkWO0ZUtHZ+XPQS5CNeejNIiOLrXhsp123Q7mZbwnkwIjQ9Y7L65SSgV3OXM10wFSGFlTK wKGSjS6G08S/ak5T8RLxrLo15XyGsnA7P9kbub4KOdniMZVvRfHpGCflxViGR6zCQlC26djh5 o58YWRSUVa42zPPMJiRsHOYJSChuKr3DnElKzg+2wM1cYQUks4S9539kn6TgTi4Zjidps6Wfi gnTwufecf4kxRH5GTfQANgucyPdKLL4KDVQkmPubWo2sZTGVDIlnDopwsdQ6eQB2x3z6/Atp+ iwU7flRcp5Z4PbBYNvovQzQu3AUOQdyn2v6GIBeE0GYPa5wtsDf3mCRt3XTj3sXpqOLGwW3b/ pfSGIRyHvFzB0b9229C2KWXac2jqOd3Xr62NrMjtQfU3w6TWml8nlAKXqhPRtEwX2VO5qZz5i Btdn1/MjqHlelPKRFDOL8C/nWB63N2Tpxu/Hnc+2M6EKYVrK+Q17C7D823OXiO9+W0MVPqify tVq7jwh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160524_165702_033450_75415175 X-CRM114-Status: GOOD ( 15.58 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Shuyu Wei , heiko@sntech.de, al.kochet@gmail.com, netdev@vger.kernel.org, linux-rockchip@lists.infradead.org, David Miller , wxt@rock-chips.com Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Francois, Shuyu, this is the patch with the discussed changes. Shuyu it would be great if you could test this one. If it passes and there are no further objections I will resend it as a regular patch (including commit message, etc.) to the mailing list. diff --git a/drivers/net/ethernet/arc/emac_main.c b/drivers/net/ethernet/arc/emac_main.c index a3a9392..ec656b3 100644 --- a/drivers/net/ethernet/arc/emac_main.c +++ b/drivers/net/ethernet/arc/emac_main.c @@ -153,18 +153,29 @@ static void arc_emac_tx_clean(struct net_device *ndev) { struct arc_emac_priv *priv = netdev_priv(ndev); struct net_device_stats *stats = &ndev->stats; + unsigned int curr = priv->txbd_curr; unsigned int i; + /* Make sure buffers and txbd_curr are consistent */ + smp_rmb(); + for (i = 0; i < TX_BD_NUM; i++) { unsigned int *txbd_dirty = &priv->txbd_dirty; struct arc_emac_bd *txbd = &priv->txbd[*txbd_dirty]; struct buffer_state *tx_buff = &priv->tx_buff[*txbd_dirty]; - struct sk_buff *skb = tx_buff->skb; - unsigned int info = le32_to_cpu(txbd->info); + unsigned int info; + struct sk_buff *skb; - if ((info & FOR_EMAC) || !txbd->data || !skb) + if (*txbd_dirty == curr) break; + info = le32_to_cpu(txbd->info); + + if (info & FOR_EMAC) + break; + + skb = tx_buff->skb; + if (unlikely(info & (DROP | DEFR | LTCL | UFLO))) { stats->tx_errors++; stats->tx_dropped++; @@ -195,8 +206,8 @@ static void arc_emac_tx_clean(struct net_device *ndev) *txbd_dirty = (*txbd_dirty + 1) % TX_BD_NUM; } - /* Ensure that txbd_dirty is visible to tx() before checking - * for queue stopped. + /* Ensure that txbd_dirty is visible to tx() and we see the most recent + * value for txbd_curr. */ smp_mb(); @@ -680,27 +691,24 @@ static int arc_emac_tx(struct sk_buff *skb, struct net_device *ndev) dma_unmap_len_set(&priv->tx_buff[*txbd_curr], len, len); priv->txbd[*txbd_curr].data = cpu_to_le32(addr); - - /* Make sure pointer to data buffer is set */ - wmb(); + priv->tx_buff[*txbd_curr].skb = skb; skb_tx_timestamp(skb); *info = cpu_to_le32(FOR_EMAC | FIRST_OR_LAST_MASK | len); - /* Make sure info word is set */ + /* 1. Make sure that with respect to tx_clean everything is set up + * properly before we advance txbd_curr. + * 2. Make sure writes to DMA descriptors are completed before we inform + * the hardware. + */ wmb(); - priv->tx_buff[*txbd_curr].skb = skb; - /* Increment index to point to the next BD */ *txbd_curr = (*txbd_curr + 1) % TX_BD_NUM; - /* Ensure that tx_clean() sees the new txbd_curr before - * checking the queue status. This prevents an unneeded wake - * of the queue in tx_clean(). - */ - smp_mb(); + /* Ensure tx_clean() sees the updated value of txbd_curr */ + smp_wmb(); if (!arc_emac_tx_avail(priv)) { netif_stop_queue(ndev);