netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ethernet:arc: Fix racing of TX ring buffer
@ 2016-05-17 15:25 Shuyu Wei
  2016-05-17 16:36 ` Aw: " Lino Sanfilippo
  2016-05-17 18:24 ` David Miller
  0 siblings, 2 replies; 26+ messages in thread
From: Shuyu Wei @ 2016-05-17 15:25 UTC (permalink / raw)
  To: wxt, davem, romieu; +Cc: heiko, linux-rockchip, netdev

[-- Attachment #1: mail2.txt --]
[-- Type: text/plain, Size: 1487 bytes --]

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 <sy.w@outlook.com>
---
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;

^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2016-06-08  7:54 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-17 15:25 [PATCH v2] ethernet:arc: Fix racing of TX ring buffer Shuyu Wei
2016-05-17 16:36 ` Aw: " Lino Sanfilippo
2016-05-17 18:24 ` David Miller
     [not found]   ` <20160517.142456.2247845107325931733.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2016-05-18  0:01     ` Francois Romieu
     [not found]       ` <20160518000153.GA21757-lmTtMILVy1jWQcoT9B9Ug5SCg42XY1Uw0E9HWUfgJXw@public.gmane.org>
2016-05-18 20:29         ` Lino Sanfilippo
     [not found]           ` <573CD09D.1060307-Mmb7MZpHnFY@public.gmane.org>
2016-05-18 22:55             ` Francois Romieu
     [not found]               ` <20160518225529.GA18671-lmTtMILVy1jWQcoT9B9Ug5SCg42XY1Uw0E9HWUfgJXw@public.gmane.org>
2016-05-19 21:15                 ` Lino Sanfilippo
     [not found]                   ` <573E2D0C.604-Mmb7MZpHnFY@public.gmane.org>
2016-05-20  0:31                     ` Francois Romieu
2016-05-21 16:09                       ` Shuyu Wei
2016-05-21 19:47                         ` Francois Romieu
     [not found]                           ` <20160521194733.GA30557-lmTtMILVy1jWQcoT9B9Ug5SCg42XY1Uw0E9HWUfgJXw@public.gmane.org>
2016-05-21 23:04                             ` Lino Sanfilippo
     [not found]                               ` <5740E98A.5050803-Mmb7MZpHnFY@public.gmane.org>
2016-05-22 21:21                                 ` Francois Romieu
2016-05-21 22:58                         ` Lino Sanfilippo
2016-05-22  9:17                           ` Shuyu Wei
2016-05-22 11:30                             ` Lino Sanfilippo
     [not found]                               ` <57419853.9050701-Mmb7MZpHnFY@public.gmane.org>
2016-05-22 22:36                                 ` Francois Romieu
     [not found]                                   ` <20160522223659.GB5086-lmTtMILVy1jWQcoT9B9Ug5SCg42XY1Uw0E9HWUfgJXw@public.gmane.org>
2016-05-24  1:09                                     ` Lino Sanfilippo
     [not found]                                       ` <5743A9DD.8010202-Mmb7MZpHnFY@public.gmane.org>
2016-05-24 19:02                                         ` Francois Romieu
2016-05-24 23:56                                         ` Lino Sanfilippo
2016-05-28  6:43                                           ` Shuyu Wei
2016-05-30 21:41                                             ` Lino Sanfilippo
2016-06-05 14:02                                               ` Shuyu Wei
2016-06-08  7:54                                                 ` Lino Sanfilippo
2016-05-23 11:36                               ` Shuyu Wei
2016-05-24  1:14                                 ` Lino Sanfilippo
2016-05-21 13:46                   ` Shuyu Wei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).