• Vladimir Oltean's avatar
    net: mscc: ocelot: cross-check the sequence id from the timestamp FIFO with the skb PTP header · ebb4c6a9
    Vladimir Oltean authored
    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: 4e3b0468 ("net: mscc: PTP Hardware Clock (PHC) support")
    Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
    Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
    ebb4c6a9
ocelot.h 27.3 KB