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 v13 3/8] hsr: Add a magic header for sending PTP packets
Date: Tue, 01 Dec 2026 08:55:26 +0000	[thread overview]
Message-ID: <179611532644.3146.17870747976027282649@kernel.org> (raw)
In-Reply-To: <20261130-hsr_ptp-v13-3-598326208fc5@linutronix.de>

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

Critical: 0 · High: 0 · Medium: 1 · Low: 2

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] The new UAPI `struct hsr_inline_header`
  (include/uapi/linux/hsr_ptp.h) is undocumented and only partly…
- [Low] `hsr_dev_xmit()` in net/hsr/hsr_device.c now drops every skb with
  `skb->protocol == ETH_P_1588` unless `hsr_ptp_parse_header()` finds a…
- [Low] The changelog says the inline header is "mandatory if the ether
  type is ETH_P_1588" and that "PTP packets missing this information…

--

hsr: Add a magic header for sending PTP packets

This adds a UAPI struct hsr_inline_header that userspace must prepend to
ETH_P_1588 frames sent through the hsr device. The header carries the
requested TX port and whether the frame already has an HSR header.
hsr_dev_xmit() parses and strips it, drops PTP frames that lack it, and
passes the parsed values to hsr_forward_skb().

> diff --git a/include/uapi/linux/hsr_ptp.h b/include/uapi/linux/hsr_ptp.h
> new file mode 100644
> index 0000000000000..95e905441ebdc
> --- /dev/null
> +++ b/include/uapi/linux/hsr_ptp.h
> @@ -0,0 +1,20 @@

[ ... ]

> +#define HSR_INLINE_HDR  0xaf485352
> +#define HSR_INLINE_HDR_PORT_A	1
> +#define HSR_INLINE_HDR_PORT_B	2
> +
> +struct hsr_inline_header {
> +	__u8 req_tx_port;
> +	__u8 has_hsr_header;
> +	__be32 __pad0;
> +	__be32 magic;
> +	__be16 __pad1;
> +	__be16 eth_type;
> +} __attribute__ ((packed));
> +
> +#endif
> diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c
> index 59df647d2fd45..7e79d5b34e8bb 100644
> --- a/net/hsr/hsr_device.c
> +++ b/net/hsr/hsr_device.c
> @@ -12,6 +12,8 @@
>  #include <linux/etherdevice.h>
>  #include <linux/rtnetlink.h>
>  #include <linux/pkt_sched.h>
> +#include <uapi/linux/hsr_ptp.h>
> +
>  #include "hsr_device.h"
>  #include "hsr_slave.h"
>  #include "hsr_framereg.h"
> @@ -221,26 +223,81 @@ static netdev_features_t hsr_fix_features(struct net_device *dev,
>  	return hsr_features_recompute(hsr, features);
>  }
>  
> +static int hsr_ptp_parse_header(struct sk_buff *skb, bool *has_hsr_header,
> +				enum hsr_port_type *req_tx_port)
> +{

[ ... ]

> +	skb_reset_mac_header(skb);
> +	if (!skb->sk)
> +		return -EINVAL;

[Severity: Low]
The commit message says PTP packets without the inline header will be
dropped. This check also drops any ETH_P_1588 frame that has no skb->sk.
Could the changelog mention this socket requirement too?

The commit message justifies the drop by saying that sending PTP via hsr is
pointless because the requested timestamp is not routed back. That is true
for event messages. General messages such as Announce, Signaling or
Management (for example pmc -2 over hsr0) don't need a TX timestamp. Is it
intended that those get dropped as well?

Existing ETH_P_ALL packet socket senders are also affected. In
net/packet/af_packet.c, skb->protocol is set from the socket protocol only
when it isn't ETH_P_ALL:

    if (proto != htons(ETH_P_ALL))
        skb->protocol = proto;

Otherwise packet_parse_headers() falls back to the device header_ops:

    if (!skb->protocol && sock->type == SOCK_RAW)
        skb->protocol = dev_parse_header_protocol(skb);

Before the earlier "hsr: Add header_ops::parse_protocol" change, these
senders had skb->protocol == 0 and their frames were forwarded. Now they
reach the new ETH_P_1588 check in hsr_dev_xmit() and are dropped. The only
trace is the tx_dropped counter. PRP devices use the same path.

Should the changelog list every condition under which frames are now
dropped, and explain why breaking these senders is acceptable?

> +
> +	/* need to access the magic header */
> +	if (!pskb_may_pull(skb, sizeof(struct hsr_inline_header)))
> +		return -EINVAL;
> +
> +	hsr_inline_hdr = (struct hsr_inline_header *)skb_mac_header(skb);
> +	if (hsr_inline_hdr->magic != htonl(HSR_INLINE_HDR))
> +		return -EINVAL;
> +
> +	*has_hsr_header = hsr_inline_hdr->has_hsr_header;
> +	*req_tx_port = hsr_inline_hdr->req_tx_port;
> +	if (*req_tx_port != HSR_PT_SLAVE_A && *req_tx_port != HSR_PT_SLAVE_B)
> +		return -EINVAL;
> +
> +	if (hsr_inline_hdr->__pad0 != 0 || hsr_inline_hdr->__pad1 != 0)
> +		return -EINVAL;
> +
> +	hdr_len = ETH_HLEN;
> +	if (*has_hsr_header)
> +		hdr_len += HSR_HLEN;

[Severity: Medium]
struct hsr_inline_header becomes permanent ABI once merged. Is it validated
and specified tightly enough?

has_hsr_header is copied straight into a bool, so any value from 1 to 255
counts as true. The pad fields must be zero, but this byte is not limited
to 0 or 1. If userspace ships with arbitrary non-zero values, can this byte
ever be used for flags later?

eth_type is never checked. It sits at offset 12, which is where
eth_header_parse_protocol() reads. For ETH_P_ALL raw sockets it therefore
has to be 0x88F7. Otherwise the ETH_P_1588 check in hsr_dev_xmit() never
fires, and the 14-byte inline header goes onto the wire as an Ethernet
header. Should the UAPI header or the changelog document this?

req_tx_port is compared against HSR_PT_SLAVE_A and HSR_PT_SLAVE_B, which
come from the internal enum hsr_port_type. The exported
HSR_INLINE_HDR_PORT_A and HSR_INLINE_HDR_PORT_B are never used, and no
BUILD_BUG_ON ties the two sets of values together. Reordering the internal
enum would silently change the ABI. Would it be better to validate against
the UAPI constants and map them to the internal values?

What does has_hsr_header mean on a PRP device? PRP has no HSR tag, but
HSR_HLEN is added here regardless of hsr->prot_version. That pulls 6 extra
bytes and puts the network header at offset 20.

Later in the series, prp_fill_frame_info() ignores the flag and the frame
is sent without an RCT. The "hsr: Assign a socket for cloned skbs" commit
also says PRP is not considered.

Two smaller points: hsr_device.c includes <uapi/linux/hsr_ptp.h> instead of
<linux/hsr_ptp.h>, and there is no Documentation/ text for the new ABI.

[ ... ]

>  static netdev_tx_t hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)
>  {
> +	enum hsr_port_type req_tx_port = HSR_PT_NONE;
>  	struct hsr_priv *hsr = netdev_priv(dev);
> +	bool has_hsr_header = false;
>  	struct hsr_port *master;
>  
>  	rcu_read_lock();
>  	master = hsr_port_get_hsr(hsr, HSR_PT_MASTER);

[ ... ]

> +	if (!master)
> +		goto drop;
> +
> +	skb->dev = master->dev;
> +	if (skb->protocol == htons(ETH_P_1588) &&
> +	    hsr_ptp_parse_header(skb, &has_hsr_header, &req_tx_port))
> +		goto drop;

[Severity: Low]
The changelog says the inline header is "mandatory if the ether type is
ETH_P_1588" and that "PTP packets missing this information will be
dropped". Does this check catch VLAN-tagged PTP frames?

The check only looks at skb->protocol. For an ETH_P_ALL SOCK_RAW sender
that value comes from eth_header_parse_protocol(), which returns only the
outer h_proto. A VLAN-tagged or priority-tagged PTP frame therefore reports
0x8100 and skips the check.

The same applies to sockets bound to, or sending with, an sll_protocol
other than ETH_P_1588. In that case skb->protocol is whatever userspace
chose.

These frames take the old path and are forwarded on both slave ports
without TX timestamp routing. VLAN and priority tagging is standard in the
substation PTP profiles (IEC 61850-9-3, C37.238) used with HSR/PRP.

Should the changelog be reworded, or should the check also look at the
encapsulated ethertype?

> +
> +	skb_reset_mac_header(skb);
> +	skb_reset_mac_len(skb);
> +	spin_lock_bh(&hsr->seqnr_lock);
> +	hsr_forward_skb(skb, master, req_tx_port, has_hsr_header);
> +	spin_unlock_bh(&hsr->seqnr_lock);
>  	rcu_read_unlock();

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-hsr_ptp-v13-0-598326208fc5%40linutronix.de

  reply	other threads:[~2026-12-01  8:55 UTC|newest]

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