Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: bigeasy@linutronix.de
Cc: netdev@vger.kernel.org, j-rameshbabu@ti.com,
	andrew+netdev@lunn.ch, danishanwar@ti.com, d-qiu@ti.com,
	davem@davemloft.net, fmaurer@redhat.com, kuba@kernel.org,
	neelima@ti.com, pabeni@redhat.com, praneeth@ti.com,
	pratheesh@ti.com, richardcochran@gmail.com, horms@kernel.org,
	vigneshr@ti.com, willemdebruijn.kernel@gmail.com,
	daniel.machon@microchip.com, edumazet@kernel.org
Subject: Re: [PATCH net-next v14 2/8] hsr: Use skb_clone() while adding the HSR header
Date: Fri, 04 Dec 2026 17:55:49 +0000	[thread overview]
Message-ID: <179640694996.3146.70057174470778615@kernel.org> (raw)
In-Reply-To: <20261203-hsr_ptp-v14-2-1511ffd4c362@linutronix.de>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 (1) · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] hsr: hsr_create_tagged_frame() retains TX timestamp flags on
  unowned clones
- [Low] prp_create_tagged_frame() (net/hsr/hsr_forward.c) still builds
  tagged frames with skb_copy_expand().

Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but
  hsr_create_tagged_frame() returns a bare skb_clone() in two places…

--

hsr: Use skb_clone() while adding the HSR header

This commit replaces __pskb_copy() in hsr_create_tagged_frame() with
skb_clone() followed by skb_cow_head(). This keeps skb_shared_info, and any
timestamp request in it, on the HSR tagged frame. The NETIF_F_HW_HSR_TAG_INS
case now shares the same clone path, and skb_postpush_data_move() and
skb_reset_mac_len() move the header and metadata and update mac_len.

> diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c
> index 44f6d9c83180a..b183358207506 100644
> --- a/net/hsr/hsr_forward.c
> +++ b/net/hsr/hsr_forward.c

[ ... ]

> @@ -342,33 +341,40 @@ struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
>  		/* set the lane id properly */
>  		hsr_set_path_id(frame, hsr_ethhdr, port);
>  		return skb_clone(frame->skb_hsr, GFP_ATOMIC);
> -	} else if (port->dev->features & NETIF_F_HW_HSR_TAG_INS) {
> -		return skb_clone(frame->skb_std, GFP_ATOMIC);
>  	}
>  
> -	/* Create the new skb with enough headroom to fit the HSR tag */
> -	skb = __pskb_copy(frame->skb_std,
> -			  skb_headroom(frame->skb_std) + HSR_HLEN, GFP_ATOMIC);
> +	skb = skb_clone(frame->skb_std, GFP_ATOMIC);
>  	if (!skb)
>  		return NULL;
> -	skb_reset_mac_header(skb);
>  
> -	if (skb->ip_summed == CHECKSUM_PARTIAL)
> -		skb->csum_start += HSR_HLEN;
> +	if (port->dev->features & NETIF_F_HW_HSR_TAG_INS)
> +		return skb;

[Severity: Medium]
Before this patch, __pskb_copy() went through skb_copy_header(), which
only carries over the gso fields of skb_shared_info. The software
tagged frames handed to the slaves therefore never had any SKBTX_* bits
set. With skb_clone() that changes.

__skb_clone() sets n->sk to NULL. Since frame->skb_std is still alive,
skb_header_cloned() is true here, so skb_cow_head() always ends up in
pskb_expand_head(). That copies the old skb_shared_info, tx_flags and
tskey included, into the new private one.

So the frames for SLAVE_A and SLAVE_B now reach the slave drivers with
SKBTX_HW_TSTAMP still set and skb->sk == NULL. Drivers such as igb only
look at the flag:

drivers/net/ethernet/intel/igb/igb_main.c:igb_xmit_frame_ring() {
    ...
	if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
		...
		if (adapter->tstamp_config.tx_type == HWTSTAMP_TX_ON &&
		    !test_and_set_bit_lock(__IGB_PTP_TX_IN_PROGRESS,
					   &adapter->state)) {
    ...
}

The timestamp they eventually report is then thrown away by the !sk
check in __skb_tstamp_tx(). Requesting SOF_TIMESTAMPING_TX_HARDWARE
needs no privileges, so any socket sending over hsr0 can now take the
single TX timestamp slot on both slaves for nothing. A ptp4l frame sent
at the same time can then be skipped (tx_hwtstamp_skipped).

"hsr: Assign a socket for cloned skbs" later in the series only calls
skb_set_owner_w() when frame->req_tx_port != HSR_PT_NONE.
hsr_dev_xmit() sets that only for ETH_P_1588 frames carrying the
HSR_INLINE_HDR magic header. All other traffic still ends up with this
combination at the end of the series.

This path already owns a private skb_shared_info after skb_cow_head().
Would it make sense to clear SKBTX_ANY_TSTAMP there when the clone has
no socket?

Also, the commit message says skb_shared_info is shared via skb_clone()
and skb_cow_head(). On this path pskb_expand_head() makes a private
copy of it instead. Could that sentence be reworded?

[Severity: Medium]
This isn't a bug introduced by this patch, but the clone returned here
still shares its head with frame->skb_std and with the clone made for the
other port. The same applies to skb_clone(frame->skb_hsr) above. Is that
safe, given what hsr_xmit() writes into the header afterwards?

When frame->port_rcv is the master, hsr_xmit() does:

net/hsr/hsr_forward.c:hsr_xmit() {
    ...
	if (frame->port_rcv->type == HSR_PT_MASTER) {
		hsr_addr_subst_dest(frame->node_src, skb, port);
		...
		ether_addr_copy(eth_hdr(skb)->h_source, port->dev->dev_addr);
	}
    ...
}

hsr_addr_subst_dest() rewrites h_dest for only one of the ports:

net/hsr/hsr_framereg.c:hsr_addr_subst_dest() {
    ...
	if (port->type != node_dst->addr_B_port)
		return;

	if (is_valid_ether_addr(node_dst->macaddress_B))
		ether_addr_copy(eth_hdr(skb)->h_dest, node_dst->macaddress_B);
}

The h_source writes look harmless, because hsr_dev_finalize() gives both
slaves the same MAC address. The h_dest substitution is per port, though.

Take a slave with NETIF_F_HW_HSR_TAG_INS but without NETIF_F_HW_HSR_DUP,
and a unicast destination node with a valid macaddress_B on SLAVE_B. Could
port A's frame, still queued, go out with port B's macaddress_B as its
destination? Taps that share the head would also see the rewritten
addresses.

The comment above hsr_create_tagged_frame() says "Otherwise, create a
private frame especially tagged for 'port'", but only the non-offloaded
path provides that. Should these clones also get a private header before
they are returned?

[ ... ]

>  	/* skb_put_padto free skb on error and hsr_fill_tag returns NULL in
>  	 * that case
>  	 */
>  	return hsr_fill_tag(skb, frame, port, port->hsr->prot_version);
> +err:
> +	kfree_skb(skb);
> +	return NULL;
>  }
>  
>  struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,

[Severity: Low]
prp_create_tagged_frame() still builds its tagged frame with
skb_copy_expand():

	skb = skb_copy_expand(frame->skb_std, skb_headroom(frame->skb_std),
			      skb_tailroom(frame->skb_std) + HSR_HLEN,
			      GFP_ATOMIC);

skb_copy_expand() ends in skb_copy_header(), which copies only gso_size,
gso_segs and gso_type from skb_shared_info. Doesn't that mean PRP frames
still lose the SKBTX_* tx_flags and tskey, the same loss this commit fixes
for HSR?

A later patch in the series, "hsr: Assign a socket for cloned skbs", says
PRP is left out on purpose:

  "This does not consider PRP part of the stack. The specification says
  that PTP-PRP packets do not have the RCT therefore these packets can be
  sent directly from userland skipping the stack."

PRP also adds an RCT trailer rather than an HSR header, so it is outside
the scope of this patch. Could the commit message say that PRP is
intentionally left unchanged?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-hsr_ptp-v14-0-1511ffd4c362%40linutronix.de

  reply	other threads:[~2026-12-04 17:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 17:44 [PATCH net-next v14 0/8] hsr: Allow to send packets on specific port and pass the timestamp Sebastian Andrzej Siewior
2026-12-03 17:44 ` [PATCH net-next v14 1/8] hsr: Add header_ops::parse_protocol Sebastian Andrzej Siewior
2026-12-03 17:44 ` [PATCH net-next v14 2/8] hsr: Use skb_clone() while adding the HSR header Sebastian Andrzej Siewior
2026-12-04 17:55   ` netdev-bot+sashiko [this message]
2026-12-03 17:44 ` [PATCH net-next v14 3/8] hsr: Add a magic header for sending PTP packets Sebastian Andrzej Siewior
2026-12-04 17:55   ` netdev-bot+sashiko
2026-12-03 17:44 ` [PATCH net-next v14 4/8] hsr: Drop received " Sebastian Andrzej Siewior
2026-12-03 17:44 ` [PATCH net-next v14 5/8] hsr: Use the port and header information in hsr_forward_skb() Sebastian Andrzej Siewior
2026-12-04 17:55   ` netdev-bot+sashiko
2026-12-03 17:44 ` [PATCH net-next v14 6/8] hsr: Assign a socket for cloned skbs Sebastian Andrzej Siewior
2026-12-04 17:55   ` netdev-bot+sashiko
2026-12-03 17:44 ` [PATCH net-next v14 7/8] hsr: Move struct hsr_ethhdr to a global header Sebastian Andrzej Siewior
2026-12-03 17:44 ` [PATCH net-next v14 8/8] selftests: hsr: Add test for the inline PTP header on HSR Sebastian Andrzej Siewior
2026-12-04 17:55   ` netdev-bot+sashiko

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=179640694996.3146.70057174470778615@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=bigeasy@linutronix.de \
    --cc=d-qiu@ti.com \
    --cc=daniel.machon@microchip.com \
    --cc=danishanwar@ti.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fmaurer@redhat.com \
    --cc=horms@kernel.org \
    --cc=j-rameshbabu@ti.com \
    --cc=kuba@kernel.org \
    --cc=neelima@ti.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=praneeth@ti.com \
    --cc=pratheesh@ti.com \
    --cc=richardcochran@gmail.com \
    --cc=vigneshr@ti.com \
    --cc=willemdebruijn.kernel@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox