Skip to content

Commit 9dda66a

Browse files
vladimirolteandavem330
authored andcommitted
net: mscc: ocelot: fix race condition with TX timestamping
The TX-timestampable skb is added late to the ocelot_port->tx_skbs. It is in a race with the TX timestamp IRQ, which checks that queue trying to match the timestamp with the skb by the ts_id. The skb should be added to the queue before the IRQ can fire. Fixes: 4e3b046 ("net: mscc: PTP Hardware Clock (PHC) support") Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Horatiu Vultur <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5f6857e commit 9dda66a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/net/ethernet/mscc/ocelot_net.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)
330330
u8 grp = 0; /* Send everything on CPU group 0 */
331331
unsigned int i, count, last;
332332
int port = priv->chip_port;
333+
bool do_tstamp;
333334

334335
val = ocelot_read(ocelot, QS_INJ_STATUS);
335336
if (!(val & QS_INJ_STATUS_FIFO_RDY(BIT(grp))) ||
@@ -344,10 +345,14 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)
344345
info.vid = skb_vlan_tag_get(skb);
345346

346347
/* Check if timestamping is needed */
348+
do_tstamp = (ocelot_port_add_txtstamp_skb(ocelot_port, skb) == 0);
349+
347350
if (ocelot->ptp && shinfo->tx_flags & SKBTX_HW_TSTAMP) {
348351
info.rew_op = ocelot_port->ptp_cmd;
349-
if (ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP)
352+
if (ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) {
350353
info.rew_op |= (ocelot_port->ts_id % 4) << 3;
354+
ocelot_port->ts_id++;
355+
}
351356
}
352357

353358
ocelot_gen_ifh(ifh, &info);
@@ -380,12 +385,9 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)
380385
dev->stats.tx_packets++;
381386
dev->stats.tx_bytes += skb->len;
382387

383-
if (!ocelot_port_add_txtstamp_skb(ocelot_port, skb)) {
384-
ocelot_port->ts_id++;
385-
return NETDEV_TX_OK;
386-
}
388+
if (!do_tstamp)
389+
dev_kfree_skb_any(skb);
387390

388-
dev_kfree_skb_any(skb);
389391
return NETDEV_TX_OK;
390392
}
391393

0 commit comments

Comments
 (0)