Skip to contentSkip to conversation

net: fixup time stamping batch #1

PATCH In review Richard Cochran 2 participants 9 messages Jun 19, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover net: fixup time stamping batch #1

As Eric Dumazet helpfully pointed out, the placing the transmit time stamp hook after giving the skb to hardware races with the completion ISR, for those drivers which free the buffer in the ISR.

This series fixes up the first batch of time stamping hook patches.

Richard Cochran (7):
net: correct comment on where to place transmit time stamp hook.
fec: fix race in transmit time stamping.
tg3: fix race in transmit time stamping.
r6040: fix race in transmit time stamping.
stmmac: fix race in transmit time stamping.
smsc9420: fix race in transmit time stamping.
davinci_emac: fix race in transmit time stamping.

 drivers/net/davinci_emac.c       |    3 ++-
 drivers/net/fec.c                |    4 ++--
 drivers/net/r6040.c              |    5 +++--
 drivers/net/smsc9420.c           |    4 ++--
 drivers/net/stmmac/stmmac_main.c |    4 ++--
 drivers/net/tg3.c                |    4 ++--
 include/linux/skbuff.h           |    3 +--
 7 files changed, 14 insertions(+), 13 deletions(-)
#1 lore raw

PATCH 1/7 net: correct comment on where to place transmit time stamp hook.

The comment for the skb_tx_timestamp() function suggests calling it just after a buffer is released to the hardware for transmission. However, for drivers that free the buffer in an ISR, this produces a race between the time stamp code and the ISR. This commit changes the comment to advise placing the call just before handing the buffer over to the hardware.

---
 include/linux/skbuff.h |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
include/linux/skbuff.h +1 -2
index c0a4f3a..3e54337 100644
@@ -2028,8 +2028,7 @@ static inline void sw_tx_timestamp(struct sk_buff *skb)
  * skb_tx_timestamp() - Driver hook for transmit timestamping
  *
  * Ethernet MAC Drivers should call this function in their hard_xmit()
- * function as soon as possible after giving the sk_buff to the MAC
- * hardware, but before freeing the sk_buff.
+ * function immediately before giving the sk_buff to the MAC hardware.
  *
  * @skb: A socket buffer.
  */
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH 2/7 fec: fix race in transmit time stamping.

In reply to Richard Cochran
---
 drivers/net/fec.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/fec.c +2 -2
index 965fe90..7ae3f28 100644
@@ -324,10 +324,10 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
 
 	fep->cur_tx = bdp;
 
-	spin_unlock_irqrestore(&fep->hw_lock, flags);
-
 	skb_tx_timestamp(skb);
 
+	spin_unlock_irqrestore(&fep->hw_lock, flags);
+
 	return NETDEV_TX_OK;
 }
 
Signature · 1 line
1.7.0.4
#3 lore raw

PATCH 3/7 tg3: fix race in transmit time stamping.

In reply to Richard Cochran
---
 drivers/net/tg3.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/tg3.c +2 -2
index 743d997..34ea37d 100644
@@ -6088,11 +6088,11 @@ static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
 		entry = NEXT_TX(tnapi->tx_prod);
 	}
 
+	skb_tx_timestamp(skb);
+
 	/* Packets are ready, update Tx producer idx local and on card. */
 	tw32_tx_mbox(tnapi->prodmbox, entry);
 
-	skb_tx_timestamp(skb);
-
 	tnapi->tx_prod = entry;
 	if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) {
 		netif_tx_stop_queue(txq);
Signature · 1 line
1.7.0.4
#4 lore raw

PATCH 4/7 r6040: fix race in transmit time stamping.

In reply to Richard Cochran
---
 drivers/net/r6040.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/r6040.c +3 -2
index 5ee5f8f..00f06e9 100644
@@ -836,6 +836,9 @@ static netdev_tx_t r6040_start_xmit(struct sk_buff *skb,
 	descptr->buf = cpu_to_le32(pci_map_single(lp->pdev,
 		skb->data, skb->len, PCI_DMA_TODEVICE));
 	descptr->status = DSC_OWNER_MAC;
+
+	skb_tx_timestamp(skb);
+
 	/* Trigger the MAC to check the TX descriptor */
 	iowrite16(0x01, ioaddr + MTPR);
 	lp->tx_insert_ptr = descptr->vndescp;
@@ -846,8 +849,6 @@ static netdev_tx_t r6040_start_xmit(struct sk_buff *skb,
 
 	spin_unlock_irqrestore(&lp->lock, flags);
 
-	skb_tx_timestamp(skb);
-
 	return NETDEV_TX_OK;
 }
 
Signature · 1 line
1.7.0.4
#5 lore raw

PATCH 5/7 stmmac: fix race in transmit time stamping.

In reply to Richard Cochran
---
 drivers/net/stmmac/stmmac_main.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/stmmac/stmmac_main.c +2 -2
index 5b85f4c..d4adc80 100644
@@ -1079,10 +1079,10 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	dev->stats.tx_bytes += skb->len;
 
-	priv->hw->dma->enable_dma_transmission(priv->ioaddr);
-
 	skb_tx_timestamp(skb);
 
+	priv->hw->dma->enable_dma_transmission(priv->ioaddr);
+
 	return NETDEV_TX_OK;
 }
 
Signature · 1 line
1.7.0.4
#6 lore raw

PATCH 6/7 smsc9420: fix race in transmit time stamping.

In reply to Richard Cochran
---
 drivers/net/smsc9420.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/smsc9420.c +2 -2
index 2d84f92..ae4d60a 100644
@@ -1030,12 +1030,12 @@ static netdev_tx_t smsc9420_hard_start_xmit(struct sk_buff *skb,
 	pd->tx_ring[index].status = TDES0_OWN_;
 	wmb();
 
+	skb_tx_timestamp(skb);
+
 	/* kick the DMA */
 	smsc9420_reg_write(pd, TX_POLL_DEMAND, 1);
 	smsc9420_pci_flush_write(pd);
 
-	skb_tx_timestamp(skb);
-
 	return NETDEV_TX_OK;
 }
 
Signature · 1 line
1.7.0.4
#7 lore raw

PATCH 7/7 davinci_emac: fix race in transmit time stamping.

In reply to Richard Cochran
---
 drivers/net/davinci_emac.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/net/davinci_emac.c +2 -1
index f5688ff..55c8245 100644
@@ -1083,6 +1083,8 @@ static int emac_dev_xmit(struct sk_buff *skb, struct net_device *ndev)
 		goto fail_tx;
 	}
 
+	skb_tx_timestamp(skb);
+
 	ret_code = cpdma_chan_submit(priv->txchan, skb, skb->data, skb->len,
 				     GFP_KERNEL);
 	if (unlikely(ret_code != 0)) {
@@ -1090,7 +1092,6 @@ static int emac_dev_xmit(struct sk_buff *skb, struct net_device *ndev)
 			dev_err(emac_dev, "DaVinci EMAC: desc submit failed");
 		goto fail_tx;
 	}
-	skb_tx_timestamp(skb);
 
 	return NETDEV_TX_OK;
 
Signature · 1 line
1.7.0.4
maintainer
#8 lore raw
In reply to Richard Cochran

From: Richard Cochran <[email protected]>
Date: Sun, 19 Jun 2011 15:31:38 +0200

Quoted 5 lines

As Eric Dumazet helpfully pointed out, the placing the transmit time stamp hook after giving the skb to hardware races with the completion ISR, for those drivers which free the buffer in the ISR.

This series fixes up the first batch of time stamping hook patches.

Series applied, thanks.