From patchwork Tue May 17 15:25:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuyu Wei X-Patchwork-Id: 9113801 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7C41ABF29F for ; Tue, 17 May 2016 15:26:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 37B342025A for ; Tue, 17 May 2016 15:26:30 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 274A72022A for ; Tue, 17 May 2016 15:26:29 +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 1b2gt8-0007aj-PJ; Tue, 17 May 2016 15:26:26 +0000 Received: from mail-pa0-x243.google.com ([2607:f8b0:400e:c03::243]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b2gt7-0007MA-0U for linux-rockchip@lists.infradead.org; Tue, 17 May 2016 15:26:25 +0000 Received: by mail-pa0-x243.google.com with SMTP id gh9so2186498pac.0 for ; Tue, 17 May 2016 08:26:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=atxiXRh07KabJizZxQ7PgH7n9HwX0nh+ZkNMSquMMQQ=; b=ikAUtV5O/C018AecNnC35Tdur6csGsA4wTTApdSmgqURjxl6TsMcZqFv57zz/NbksT QIfY1iM3Z5LOxf2OiSTYP3H3N3tihZJsz2SMPtWT7pwSw+hXCHA3XOkMm7Wkeor22nEq QKLdq1HsHCLPWBTkzfTt7b04xnWefxPGvJIuISMzvQCng+1sZkss+bT4AxK+X6bOK7mM tyVpH8ognnauoISB9bOVT6z6gUc+cmUBAzaXJ6BMz227x7Ed/aAKM65s3imntO1warV+ 38vRoDpkYappT5qC6onC5VHbTyd6wrdGuRVxmL26OLP5rXJQTFVhrVs2YGR9n1KIDOtz sGIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=atxiXRh07KabJizZxQ7PgH7n9HwX0nh+ZkNMSquMMQQ=; b=Gpc9OyX9RggIJnMawaggc8Psy7h4i8akNhXBCoZaVLDS1vA2nZhSCGt3wA2K2x/l/N bssn8mU+Xk7rpc51S3ZKEjdT0X8d53/5PxgQstrH/1Jd2YcjaYS5IqJQdyG6sgUY/H7s ZRhbmQwYLZVA+KTP37NgKAUg/cwY86c5ohmGtHY0xcyoPTQH+YoTtmo0wRmC80hs8/f+ L+CHK9SbRqMQOZQE+8fdMWBZ4zb0fusISzxnbb+L1CJl/VDXAx3abQNbCsppOO2S9Xaj b29v2i+Pzhmm2SQEvhZkfElolrYP3kQ4VK7rWexDwHL5UiIL45WPCZty35ogTEINiTL6 jf0w== X-Gm-Message-State: AOPr4FVjODh2cSFn4cRYU4snzNgdPbOqWkFDELa1p2Rc4+vWfmop+hYr+tQ2F+TByNj1Pw== X-Received: by 10.66.65.109 with SMTP id w13mr2906947pas.142.1463498763757; Tue, 17 May 2016 08:26:03 -0700 (PDT) Received: from debian-dorm ([222.71.85.161]) by smtp.gmail.com with ESMTPSA id n10sm5670656pax.18.2016.05.17.08.26.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 May 2016 08:26:03 -0700 (PDT) Date: Tue, 17 May 2016 23:25:20 +0800 From: Shuyu Wei To: wxt@rock-chips.com, davem@davemloft.net, romieu@fr.zoreil.com Subject: [PATCH v2] ethernet:arc: Fix racing of TX ring buffer Message-ID: <20160517152520.GA2750@debian-dorm> MIME-Version: 1.0 Content-Disposition: inline; filename="mail2.txt" User-Agent: Mutt/1.6.0 (2016-04-01) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160517_082625_085361_1BB41E8A X-CRM114-Status: GOOD ( 12.47 ) X-Spam-Score: -2.5 (--) 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: linux-rockchip@lists.infradead.org, heiko@sntech.de, netdev@vger.kernel.org Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Setting the FOR_EMAC flag should be the last step of modifying the buffer descriptor, or possible racing will occur. The loop counter i in tx_clean() is not needed, and we need to make sure it does not clear the finished txbds. Signed-off-by: Shuyu Wei --- Changes in v2: - Remove loop counter in tx_clean and check for unfinished txbds (Ueimor) - Use dma_wmb() to sync writes (Ueimor) diff --git a/drivers/net/ethernet/arc/emac_main.c b/drivers/net/ethernet/arc/emac_main.c index a3a9392..df3dfef 100644 --- a/drivers/net/ethernet/arc/emac_main.c +++ b/drivers/net/ethernet/arc/emac_main.c @@ -153,9 +153,8 @@ 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 i; - for (i = 0; i < TX_BD_NUM; i++) { + while (priv->txbd_dirty != priv->txbd_curr) { 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]; @@ -685,13 +684,15 @@ static int arc_emac_tx(struct sk_buff *skb, struct net_device *ndev) wmb(); skb_tx_timestamp(skb); + priv->tx_buff[*txbd_curr].skb = skb; + + dma_wmb(); *info = cpu_to_le32(FOR_EMAC | FIRST_OR_LAST_MASK | len); /* Make sure info word is set */ wmb(); - priv->tx_buff[*txbd_curr].skb = skb; /* Increment index to point to the next BD */ *txbd_curr = (*txbd_curr + 1) % TX_BD_NUM;