RE: [PATCH v8 net-next 9/9] net: dsa: netc: add PTP one-step timestamping support

From: Wei Fang

Date: Mon Nov 23 2026 - 01:38:31 EST


> > +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 is a one-step Sync and skb_linearize_cow()
> fails?
>
> skb_linearize_cow() runs before the message type is checked. It can return
> -ENOMEM under GFP_ATOMIC pressure for any nonlinear or cloned skb, for
> example one cloned by dev_queue_xmit_nit() while a packet tap is attached.
> When that happens, the Sync goes down the two-step path:
>
> dsa_user_xmit()
> dsa_skb_tx_timestamp()
> netc_port_txtstamp()
> netc_port_prepare_onestep_sync()
> skb_linearize_cow() fails -> *twostep = true
> netc_port_prepare_twostep()
>
> The frame gets a To_Port subtype 2 tag, or a subtype 0 tag if
> skb_clone_sk() also fails. Its twoStepFlag is still 0, but PM_SINGLE_STEP
> is never programmed, and originTimestamp and correctionField are never
> updated. Would the peer then accept a one-step Sync carrying whatever
> originTimestamp software put there?
>
> netc_port_txtstamp_handler() would also later deliver a hardware TX
> timestamp for this Sync through skb_complete_tx_timestamp(). Doesn't that
> conflict with the HWTSTAMP_TX_ONESTEP_SYNC description in
> include/uapi/linux/net_tstamp.h:
>
> In this case, transmitted Sync packets will not received a time
> stamp via the socket error queue.
>
> The commit message also says:
>
> 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.
>
> skb_linearize_cow() runs first, so the later check:
>
> if (unlikely(tstamp_offset + 10 > skb_headlen(skb) ||
> correction_offset > NETC_MAX_STEP_OFFSET)) {
> NETC_SKB_CB(skb)->ptp_flag = NETC_PTP_FLAG_DROP;
>
> only catches truncated frames. The "not linear" case falls back to
> two-step and is not dropped.
>
> Should a linearize failure on a Sync frame be handled the same way as the
> other error paths in this function, with NETC_PTP_FLAG_DROP and a
> tx_dropped increment?

>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. Therefore, we cannot discard it, as it could
be another two-step packet, such as Delay_Req, Pdelay_Req, or Pdelay_Res.
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 for this issue, I would like to leave it as it is.