[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20160517.142456.2247845107325931733.davem@davemloft.net>
Date: Tue, 17 May 2016 14:24:56 -0400 (EDT)
From: David Miller <davem@...emloft.net>
To: wsy2220@...il.com
Cc: wxt@...k-chips.com, romieu@...zoreil.com, heiko@...ech.de,
linux-rockchip@...ts.infradead.org, netdev@...r.kernel.org
Subject: Re: [PATCH v2] ethernet:arc: Fix racing of TX ring buffer
From: Shuyu Wei <wsy2220@...il.com>
Date: Tue, 17 May 2016 23:25:20 +0800
> 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;
>
These memory barriers do not look correct to me.
dma_wmb() is about visibility between CPU reads/writes and device
accesses to a piece of memory. But what you're concerned about wrt.
the SKB pointer assignment is CPU to CPU accesses. Therefore something
like smp_wmb() would be appropriate.
And the wmb() looks like it should be a dma_wmb().
Powered by blists - more mailing lists