linux/include/soc/mscc
Vladimir Oltean ebb4c6a990 net: mscc: ocelot: cross-check the sequence id from the timestamp FIFO with the skb PTP header
The sad reality is that when a PTP frame with a TX timestamping request
is transmitted, it isn't guaranteed that it will make it all the way to
the wire (due to congestion inside the switch), and that a timestamp
will be taken by the hardware and placed in the timestamp FIFO where an
IRQ will be raised for it.

The implication is that if enough PTP frames are silently dropped by the
hardware such that the timestamp ID has rolled over, it is possible to
match a timestamp to an old skb.

Furthermore, nobody will match on the real skb corresponding to this
timestamp, since we stupidly matched on a previous one that was stale in
the queue, and stopped there.

So PTP timestamping will be broken and there will be no way to recover.

It looks like the hardware parses the sequenceID from the PTP header,
and also provides that metadata for each timestamp. The driver currently
ignores this, but it shouldn't.

As an extra resiliency measure, do the following:

- check whether the PTP sequenceID also matches between the skb and the
  timestamp, treat the skb as stale otherwise and free it

- if we see a stale skb, don't stop there and try to match an skb one
  more time, chances are there's one more skb in the queue with the same
  timestamp ID, otherwise we wouldn't have ever found the stale one (it
  is by timestamp ID that we matched it).

While this does not prevent PTP packet drops, it at least prevents
the catastrophic consequences of incorrect timestamp matching.

Since we already call ptp_classify_raw in the TX path, save the result
in the skb->cb of the clone, and just use that result in the interrupt
code path.

Fixes: 4e3b0468e6 ("net: mscc: PTP Hardware Clock (PHC) support")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-10-12 17:35:18 -07:00
..
ocelot_ana.h net: mscc: ocelot: fix fields offset in SG_CONFIG_REG_3 2020-09-24 20:00:40 -07:00
ocelot_dev.h net: mscc: ocelot: convert port registers to regmap 2020-07-13 17:40:01 -07:00
ocelot_hsio.h
ocelot_ptp.h net: mscc: ocelot: avoid overflowing the PTP timestamp FIFO 2021-10-12 17:35:17 -07:00
ocelot_qsys.h net: mscc: ocelot: add ops for decoding watermark threshold and occupancy 2021-01-15 20:02:34 -08:00
ocelot_sys.h net: mscc: ocelot: convert SYS_PAUSE_CFG register access to regfield 2020-07-13 17:40:02 -07:00
ocelot_vcap.h net: mscc: ocelot: fix VCAP filters remaining active after being deleted 2021-10-01 15:13:20 -07:00
ocelot.h net: mscc: ocelot: cross-check the sequence id from the timestamp FIFO with the skb PTP header 2021-10-12 17:35:18 -07:00