All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: davem@davemloft.net, netdev@vger.kernel.org
Cc: yangbo.lu@nxp.com, xiaoliang.yang_1@nxp.com,
	UNGLinuxDriver@microchip.com, claudiu.manoil@nxp.com,
	alexandre.belloni@bootlin.com, andrew@lunn.ch,
	vivien.didelot@gmail.com, f.fainelli@gmail.com, kuba@kernel.org
Subject: [PATCH v2 net 1/8] net: mscc: ocelot: fix race condition with TX timestamping
Date: Fri, 18 Sep 2020 04:07:23 +0300	[thread overview]
Message-ID: <20200918010730.2911234-2-olteanv@gmail.com> (raw)
In-Reply-To: <20200918010730.2911234-1-olteanv@gmail.com>

From: Vladimir Oltean <vladimir.oltean@nxp.com>

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: 4e3b0468e6d7 ("net: mscc: PTP Hardware Clock (PHC) support")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
Changes in v2:
None.

 drivers/net/ethernet/mscc/ocelot_net.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c
index 0668d23cdbfa..cacabc23215a 100644
--- a/drivers/net/ethernet/mscc/ocelot_net.c
+++ b/drivers/net/ethernet/mscc/ocelot_net.c
@@ -330,6 +330,7 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)
 	u8 grp = 0; /* Send everything on CPU group 0 */
 	unsigned int i, count, last;
 	int port = priv->chip_port;
+	bool do_tstamp;
 
 	val = ocelot_read(ocelot, QS_INJ_STATUS);
 	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)
 	info.vid = skb_vlan_tag_get(skb);
 
 	/* Check if timestamping is needed */
+	do_tstamp = (ocelot_port_add_txtstamp_skb(ocelot_port, skb) == 0);
+
 	if (ocelot->ptp && shinfo->tx_flags & SKBTX_HW_TSTAMP) {
 		info.rew_op = ocelot_port->ptp_cmd;
-		if (ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP)
+		if (ocelot_port->ptp_cmd == IFH_REW_OP_TWO_STEP_PTP) {
 			info.rew_op |= (ocelot_port->ts_id  % 4) << 3;
+			ocelot_port->ts_id++;
+		}
 	}
 
 	ocelot_gen_ifh(ifh, &info);
@@ -380,12 +385,9 @@ static int ocelot_port_xmit(struct sk_buff *skb, struct net_device *dev)
 	dev->stats.tx_packets++;
 	dev->stats.tx_bytes += skb->len;
 
-	if (!ocelot_port_add_txtstamp_skb(ocelot_port, skb)) {
-		ocelot_port->ts_id++;
-		return NETDEV_TX_OK;
-	}
+	if (!do_tstamp)
+		dev_kfree_skb_any(skb);
 
-	dev_kfree_skb_any(skb);
 	return NETDEV_TX_OK;
 }
 
-- 
2.25.1


  reply	other threads:[~2020-09-18  1:07 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-18  1:07 [PATCH v2 net 0/8] Bugfixes in Microsemi Ocelot switch driver Vladimir Oltean
2020-09-18  1:07 ` Vladimir Oltean [this message]
2020-09-18 15:23   ` [PATCH v2 net 1/8] net: mscc: ocelot: fix race condition with TX timestamping Alexandre Belloni
2020-09-18 15:24   ` Alexandre Belloni
2020-09-18 15:24   ` Alexandre Belloni
2020-09-18 15:24   ` Alexandre Belloni
2020-09-18 15:24   ` Alexandre Belloni
2020-09-18 15:25   ` Alexandre Belloni
2020-09-18 15:25   ` Alexandre Belloni
2020-09-18 15:26   ` Alexandre Belloni
2020-09-18 15:27     ` Alexandre Belloni
2020-09-18  1:07 ` [PATCH v2 net 2/8] net: mscc: ocelot: add locking for the port TX timestamp ID Vladimir Oltean
2020-09-18  2:37   ` Florian Fainelli
2020-09-18 15:27   ` Alexandre Belloni
2020-09-18  1:07 ` [PATCH v2 net 3/8] net: dsa: seville: fix buffer size of the queue system Vladimir Oltean
2020-09-18  2:37   ` Florian Fainelli
2020-09-18 15:27   ` Alexandre Belloni
2020-09-18  1:07 ` [PATCH v2 net 4/8] net: mscc: ocelot: check for errors on memory allocation of ports Vladimir Oltean
2020-09-18  2:35   ` Florian Fainelli
2020-09-18 15:27   ` Alexandre Belloni
2020-09-18  1:07 ` [PATCH v2 net 5/8] net: mscc: ocelot: error checking when calling ocelot_init() Vladimir Oltean
2020-09-18  2:35   ` Florian Fainelli
2020-09-18 15:28   ` Alexandre Belloni
2020-09-18  1:07 ` [PATCH v2 net 6/8] net: mscc: ocelot: refactor ports parsing code into a dedicated function Vladimir Oltean
2020-09-18  2:34   ` Florian Fainelli
2020-09-18 15:28   ` Alexandre Belloni
2020-09-18  1:07 ` [PATCH v2 net 7/8] net: mscc: ocelot: unregister net devices on unbind Vladimir Oltean
2020-09-18  2:34   ` Florian Fainelli
2020-09-18 15:28   ` Alexandre Belloni
2020-09-18  1:07 ` [PATCH v2 net 8/8] net: mscc: ocelot: deinitialize only initialized ports Vladimir Oltean
2020-09-18  2:36   ` Florian Fainelli
2020-09-18 15:29   ` Alexandre Belloni
2020-09-18 20:52 ` [PATCH v2 net 0/8] Bugfixes in Microsemi Ocelot switch driver David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200918010730.2911234-2-olteanv@gmail.com \
    --to=olteanv@gmail.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andrew@lunn.ch \
    --cc=claudiu.manoil@nxp.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=vivien.didelot@gmail.com \
    --cc=xiaoliang.yang_1@nxp.com \
    --cc=yangbo.lu@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.