RE: [PATCH v7 net-next 9/9] net: dsa: netc: add PTP one-step timestamping support
From: Wei Fang
Date: Tue Nov 17 2026 - 23:18:22 EST
> > + if (np->onestep_state == NETC_ONESTEP_IN_FLIGHT &&
> > + time_is_before_jiffies64(expire_time))
> > + return true;
>
> [Severity: Low]
> Is it safe to treat PM_SINGLE_STEP as free based only on elapsed time?
>
> After netc_port_onestep_work() programs the register and calls
> onestep_sync_xmit(), the tagged frame may not have left yet. It can still
> be in the conduit qdisc, the ENETC TX ring, or a switch egress queue (for
> example under pause/PFC or a closed Qbv gate).
>
> Three paths seem to reprogram the register without knowing whether the
> previous subtype 3 frame has gone out:
>
> netc_port_onestep_sync_enqueue(), once netc_onestep_timeout() is true
>
> netc_port_tstamp_timeout_work(), which sets resume_onestep after 5 s
>
> netc_mac_link_down()->netc_port_disable_onestep() followed by
> netc_mac_link_up()->netc_port_enable_onestep(), which sets
> NETC_ONESTEP_IDLE without tracking frames already handed to the conduit
>
> Suppose the old frame goes out after the register has been rewritten for
> a new Sync with a different layout (L2 vs UDPv4 vs UDPv6, or VLAN vs
> untagged). Would the MAC then apply the new correction offset and CH bit
> to the old frame?
>
> The NETC_ONESTEP_VALID_WINDOW comment says such a frame "is already
> invalid, whether it has been dropped or not". In this case, though, the
> hardware could add the residence time at the wrong byte offset, for
> example inside the IPv4 header or the originTimestamp. It could also
> update or skip the UDP checksum wrongly. The frame on the wire would then
> be malformed, not just carrying a stale correction field.
>
Old frames will be discarded by the receiver due to format errors or checksum
errors, so there is nothing to worry about.
> This depends on when the hardware latches PM_SINGLE_STEP. That point is
> inferred from the commit message, not checked against a datasheet.
>
> [ ... ]
>
> > +void netc_port_onestep_sync_enqueue(struct dsa_switch *ds, int port,
> > + struct sk_buff *skb)
> > +{
> > + struct netc_port *np = NETC_PORT(ds, port);
> > +
> > + spin_lock_bh(&np->onestep_lock);
> > + if (unlikely(np->onestep_state == NETC_ONESTEP_PORT_INACTIVE))
> > + goto free_skb;
> > +
> > + if (unlikely(skb_queue_len(&np->onestep_queue) >=
> NETC_ONESTEP_QTH))
> > + goto free_skb;
>
> [Severity: Low]
> Can an unprivileged local sender crowd the real Sync frames out of
> onestep_queue?
>
> SOF_TIMESTAMPING_TX_HARDWARE needs no capability. ptp_classify_raw()
> treats any UDP datagram to port 319 as a PTP event, and the sender
I think this is an overreaction; ptp_classify_raw() is designed to filter PTP
frames.
> controls the payload (msgtype Sync, twoStepFlag clear). With
> HWTSTAMP_TX_ONESTEP_SYNC set, such frames take this path:
>
> dsa_user_xmit()
> dsa_skb_tx_timestamp()
> netc_port_txtstamp()
> netc_port_prepare_onestep_sync() /* NETC_PTP_FLAG_ONESTEP */
> netc_xmit()
> netc_port_onestep_sync_enqueue() /* shared FIFO, drop at 512 */
> netc_port_onestep_work() /* one frame per response */
>
> These frames share the single per-port onestep_queue with the ptp4l
> Syncs. A flood would delay the real Syncs, or get them dropped once
> NETC_ONESTEP_QTH is reached.
>
> The same sender can also send non-Sync event frames. Those take the
> two-step path and can use up the 16-entry ts_req_id pool. Then
> netc_port_onestep_work() drops the real Syncs when netc_get_ts_req_id()
> fails. If tagged frames are also lost in the conduit, the queue stays
> stuck until the window check fires on a later enqueue or the 5 s timeout
> runs.
>
> The ts_req_id pool exhaustion already exists before this patch. What is
> new is the serialized one-step FIFO.
>
> [ ... ]
>
> > @@ -409,6 +718,67 @@ int netc_port_hwtstamp_get(struct dsa_switch *ds,
> int port,
> > return 0;
> > }
> >
> > +static void netc_port_prepare_onestep_sync(struct netc_port *np,
> > + struct sk_buff *skb,
> > + u32 ptp_class, bool *twostep)
> > +{
>
> [ ... ]
>
> > + /* Ensure the buffer is linear and writable so the packet can be
> > + * parsed and updated in place. Otherwise, fall back to two-step.
> > + */
> > + if (unlikely(skb_linearize_cow(skb))) {
> > + *twostep = true;
> > + return;
> > + }
>
> [Severity: Medium]
> What happens here if the frame really is a one-step Sync (msgtype Sync,
> twoStepFlag clear)?
>
> skb_linearize_cow() makes a GFP_ATOMIC copy whenever the skb is cloned
> or
> nonlinear. A clone is common, for example from dev_queue_xmit_nit() when
> tcpdump is attached to the user port. So this can fail under memory
> pressure before the message type is checked.
>
> netc_port_txtstamp() then sends the frame down the two-step path:
>
> if (tx_type == HWTSTAMP_TX_ON || twostep)
> netc_port_prepare_twostep(np, skb);
>
> netc_xmit() then gives the frame a subtype 2 tag. On this path
> originTimestamp is never written, PM_SINGLE_STEP is not programmed, and
> the correction field is not updated. The frame still says it is one-step,
> so no Follow_Up will be sent.
>
> Would the slave then compute its offset from whatever originTimestamp
> user space left in the frame? The socket would also get an unexpected
> hardware TX timestamp through skb_complete_tx_timestamp().
>
> The commit message says:
>
> "Frames that are not one-step Sync still fall back to two-step
> timestamping."
>
> and:
>
> "If the originTimestamp field of the sync frame is not in the linear
> buffer of the skb or the correction offset exceeds the hardware
> capability, the frame will be dropped."
>
> Should this path drop the frame and count it in tx_dropped, like the
> offset check further down? The ptp_parse_header() failure falls back the
> same way. There the header is incomplete, though, so that frame cannot be
> a well-formed Sync.
>From a software perspective, this is a trade-off and cannot completely solve
the problem unless skb_linearize_cow() never fails; otherwise, the driver
cannot parse the message type. The issue raised by Sashiko can indeed occur,
but only under memory pressure. Once the memory pressure subsides, PTP
synchronization will return to normal. So there is nothing we can do this issue,
I would like to leave it as it is.
NXP Confidential