From patchwork Sat May 14 16:16:02 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuyu Wei X-Patchwork-Id: 9095171 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 544F09F441 for ; Sat, 14 May 2016 16:16:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4E8D120220 for ; Sat, 14 May 2016 16:16:39 +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 6C546201CE for ; Sat, 14 May 2016 16:16:38 +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 1b1cF2-0001Og-AG; Sat, 14 May 2016 16:16:36 +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 1b1cEz-0001L6-W5 for linux-rockchip@lists.infradead.org; Sat, 14 May 2016 16:16:34 +0000 Received: by mail-pa0-x243.google.com with SMTP id xm6so205076pab.3 for ; Sat, 14 May 2016 09:16:11 -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=j79xVozyNhgPDaXTYsQ0OnNWK93d/QT9S5Ujk7xQ+QM=; b=kAlG1Hd/l4pjEXHToOtPzIUNxsKYlHSNGCxq6Q245SxffDXW7/84UW79lWV/Jmc/Ac d4JngUKUI81vH0+8XaKqCAPzRCAt0c9auxss+XEqr4M/++rVgCoVfO4Z1PvmYm8H3FvU dugdbUWT0UvZVOgCrZbIaQ5UieHqD9IfK5A6Vjxy8/JYG7hIzVYEfPDDopVhof8x6hBb Y/znO0J0xD0NYM50FHYq4HMgfzMn+NL6xskHYM9ws1lDGV5s5zF4G/jHMPgjYhgcGOC9 oZQ/07TCu2OB3avgcyAZO0L7/OdBFYt8b9zxMMoWxrcoFLyAR9P4xcWUlGrdzpVBuvob gepQ== 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=j79xVozyNhgPDaXTYsQ0OnNWK93d/QT9S5Ujk7xQ+QM=; b=IGHW3pFw+ZeKr5w+F1yk/zbzingOojsRFW7ybrc0XD6Ye5UozqCQoFKdGafYtHb8Dq K6SEZ4KeETsXI3xuyvau6DlO+ob56bz8MKKoB5SPavcFgZWbslGHrAcXqGca8VLlSWwF ZbicZSa+arTb4/lEGhDM88Qrq74lr59NyHnr9jxWVrJuyDxx+lUQT+OQGyf4PxaU/Wst O++8I9Ezvs7pz1Xr0nnizCsoHIfWIQh79f5Z6iYQtr2OQ0I5Z8oKdCgcm5oAjLzhWejM fvd42Ib4GQNYeSHgCz+RHCakJcrFmWbZMB82z78Pif+9Cs5BWaHz4u+8rCqC+7rlv/PS xMJg== X-Gm-Message-State: AOPr4FXxBcthqbwBNIE6JBUJ9IoI1RfyrvPFJrdsDXro8jCgshNQyM9uBobiZzdLeMnX4A== X-Received: by 10.66.171.41 with SMTP id ar9mr31962520pac.125.1463242571561; Sat, 14 May 2016 09:16:11 -0700 (PDT) Received: from debian-dorm ([222.71.85.161]) by smtp.gmail.com with ESMTPSA id qb1sm35572260pac.44.2016.05.14.09.16.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 May 2016 09:16:10 -0700 (PDT) Date: Sun, 15 May 2016 00:16:02 +0800 From: Shuyu Wei To: wxt@rock-chips.com, davem@davemloft.net Subject: [PATCH] ethernet:arc: Fix racing of TX ring buffer Message-ID: <20160514161602.GA3347@debian-dorm> MIME-Version: 1.0 Content-Disposition: inline; filename="mail1.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-20160514_091634_062855_DE735AED X-CRM114-Status: GOOD ( 10.73 ) 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 The tail of the ring buffer(txbd_dirty) should never go ahead of the head(txbd_curr) or the ring buffer will corrupt. This is the root cause of racing. Besides, setting the FOR_EMAC flag should be the last step of modifying the buffer descriptor, or possible racing will occur. Signed-off-by: Shuyu Wei diff --git a/drivers/net/ethernet/arc/emac_main.c b/drivers/net/ethernet/arc/emac_main.c index a3a9392..5ece05b 100644 --- a/drivers/net/ethernet/arc/emac_main.c +++ b/drivers/net/ethernet/arc/emac_main.c @@ -155,7 +155,7 @@ static void arc_emac_tx_clean(struct net_device *ndev) struct net_device_stats *stats = &ndev->stats; unsigned int i; - for (i = 0; i < TX_BD_NUM; i++) { + for (i = priv->txbd_dirty; i != priv->txbd_curr; i = (i + 1) % TX_BD_NUM) { 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]; @@ -686,12 +686,12 @@ static int arc_emac_tx(struct sk_buff *skb, struct net_device *ndev) skb_tx_timestamp(skb); + priv->tx_buff[*txbd_curr].skb = skb; *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;