🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Sebastian Andrzej Siewior Wed, 25 Nov 2026 14:31
[PATCH net-next v12 5/8] hsr: Use the port and header information in hsr_forward_skb()
#22558
Author: Sebastian Andrzej Siewior
Date: Wed, 25 Nov 2026 14:31
158 lines
15706 bytes
The upper layer can submit a port on which the skb should be sent and
whether or not a HSR header should be added. Use this information while
forwarding the packet:
- If the port set, deliver it only on the requested port.
- If a header is already present then skip parts of the stack:
  - The packet originates from the master port and we don't want to
    assign a sequence number to it, it needs to preserve the original
    one.
  - The existing h_source must be used (and not replaced).
  - The node should already exist in the node_db if "other" packets are
    exchanged. If the node information is not yet existing then
    creating it makes no sense because it is used for deduplication of
    incoming packets and this is not used in the PTP case. If no other
    packets are exchanged then the node_db will age and then removed.

This is only used in the pure software version. Hardware with any kind
of NETIF_F_HW_* offload support need to be addressed separately.

Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 net/hsr/hsr_forward.c  | 47 +++++++++++++++++++++++++++++++++++++++--------
 net/hsr/hsr_framereg.h |  2 ++
 2 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c
index f49d962337f8b..1d1d75ed8cd06 100644
--- a/net/hsr/hsr_forward.c
+++ b/net/hsr/hsr_forward.c
@@ -426,7 +426,7 @@ static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev,
 static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port,
 		    struct hsr_frame_info *frame)
 {
-	if (frame->port_rcv->type == HSR_PT_MASTER) {
+	if (frame->port_rcv->type == HSR_PT_MASTER && !frame->has_hsr_header) {
 		hsr_addr_subst_dest(frame->node_src, skb, port);
 
 		/* Address substitution (IEC62439-3 pp 26, 50): replace mac
@@ -552,6 +552,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
 
 	hsr_for_each_port(frame->port_rcv->hsr, port) {
 		struct hsr_priv *hsr = port->hsr;
+
 		/* Don't send frame back the way it came */
 		if (port == frame->port_rcv)
 			continue;
@@ -570,6 +571,20 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
 		if ((port->dev->features & NETIF_F_HW_HSR_DUP) && sent)
 			continue;
 
+		/* If this frame has a specific outgoing port specified (by the
+		 * sender) then send it on this port only.
+		 */
+		if (frame->req_tx_port != HSR_PT_NONE &&
+		    frame->req_tx_port != port->type)
+			continue;
+		/* If this TX frame already has a HSR header then forward the
+		 * frame with it and don't add one.
+		 */
+		if (frame->has_hsr_header && frame->skb_std) {
+			skb = skb_clone(frame->skb_std, GFP_ATOMIC);
+			goto inject_into_stack;
+		}
+
 		/* Don't send frame over port where it has been sent before.
 		 * Also for SAN, this shouldn't be done.
 		 */
@@ -597,6 +612,7 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
 		else
 			skb = hsr->proto_ops->get_untagged_frame(frame, port);
 
+inject_into_stack:
 		if (!skb) {
 			frame->port_rcv->dev->stats.rx_dropped++;
 			continue;
@@ -661,6 +677,13 @@ int hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,
 	struct hsr_port *port = frame->port_rcv;
 	struct hsr_priv *hsr = port->hsr;
 
+	if (frame->has_hsr_header) {
+		frame->skb_std = skb;
+
+		WARN_ON_ONCE(port->type != HSR_PT_MASTER);
+		WARN_ON_ONCE(skb->mac_len < sizeof(struct hsr_ethhdr));
+		return 0;
+	}
 	/* HSRv0 supervisory frames double as a tag so treat them as tagged. */
 	if ((!hsr->prot_version && proto == htons(ETH_P_PRP)) ||
 	    proto == htons(ETH_P_HSR)) {
@@ -702,7 +725,8 @@ int prp_fill_frame_info(__be16 proto, struct sk_buff *skb,
 }
 
 static int fill_frame_info(struct hsr_frame_info *frame,
-			   struct sk_buff *skb, struct hsr_port *port)
+			   struct sk_buff *skb, struct hsr_port *port,
+			   enum hsr_port_type req_tx_port, bool has_hsr_header)
 {
 	struct hsr_priv *hsr = port->hsr;
 	struct hsr_vlan_ethhdr *vlan_hdr;
@@ -725,10 +749,16 @@ static int fill_frame_info(struct hsr_frame_info *frame,
 	if (port->type == HSR_PT_INTERLINK)
 		n_db = &hsr->proxy_node_db;
 
-	frame->node_src = hsr_get_node(port, n_db, skb,
-				       frame->is_supervision, port->type);
-	if (!frame->node_src)
-		return -1; /* Unknown node and !is_supervision, or no mem */
+	frame->req_tx_port = req_tx_port;
+	frame->has_hsr_header = has_hsr_header;
+
+	if (!frame->has_hsr_header) {
+		frame->node_src = hsr_get_node(port, n_db, skb,
+					       frame->is_supervision,
+					       port->type);
+		if (!frame->node_src)
+			return -1; /* Unknown node and !is_supervision, or no mem */
+	}
 
 	ethhdr = (struct ethhdr *)skb_mac_header(skb);
 	frame->is_vlan = false;
@@ -777,10 +807,11 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port,
 	struct hsr_frame_info frame;
 
 	rcu_read_lock();
-	if (fill_frame_info(&frame, skb, port) < 0)
+	if (fill_frame_info(&frame, skb, port, req_tx_port, has_hsr_header) < 0)
 		goto out_drop;
 
-	hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
+	if (!frame.has_hsr_header)
+		hsr_register_frame_in(frame.node_src, port, frame.sequence_nr);
 	hsr_forward_do(&frame);
 	rcu_read_unlock();
 	/* Gets called for ingress frames as well as egress from master port.
diff --git a/net/hsr/hsr_framereg.h b/net/hsr/hsr_framereg.h
index 127a3fb64d5f0..dc13819d04098 100644
--- a/net/hsr/hsr_framereg.h
+++ b/net/hsr/hsr_framereg.h
@@ -29,6 +29,8 @@ struct hsr_frame_info {
 	bool is_from_san;
 	bool dst_in_node_db;
 	bool dst_in_proxy_node_db;
+	bool has_hsr_header;
+	enum hsr_port_type req_tx_port;
 };
 
 void hsr_del_self_node(struct hsr_priv *hsr);

-- 
2.55.0
Re: [PATCH net-next v12 5/8] hsr: Use the port and header information in hsr_forward_skb()
#23109
Author: netdev-bot+sashiko
Date: Thu, 26 Nov 2026 14:40
173 lines
13938 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 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] The commit message says the new behaviour "is only used in the
  pure software version" and that NETIF_F_HW_* offload hardware "need[s]…
- [Low] The patch makes hsr_fill_frame_info() check
  frame->has_hsr_header: it sets skb_std = skb, skips…

--

hsr: Use the port and header information in hsr_forward_skb()

This commit passes the requested TX port and the has_hsr_header flag from
the upper layer into hsr_forward_skb(). A frame is then sent only on the
requested port. When the frame already has a header, the commit skips the
sequence number assignment, the source address substitution and the node
lookup.

> diff --git a/net/hsr/hsr_forward.c b/net/hsr/hsr_forward.c
> index f49d962337f8b..1d1d75ed8cd06 100644
> --- a/net/hsr/hsr_forward.c
> +++ b/net/hsr/hsr_forward.c

[ ... ]

> @@ -570,6 +571,20 @@ static void hsr_forward_do(struct hsr_frame_info *frame)
>  		if ((port->dev->features & NETIF_F_HW_HSR_DUP) && sent)
>  			continue;
>  
> +		/* If this frame has a specific outgoing port specified (by the
> +		 * sender) then send it on this port only.
> +		 */
> +		if (frame->req_tx_port != HSR_PT_NONE &&
> +		    frame->req_tx_port != port->type)
> +			continue;
> +		/* If this TX frame already has a HSR header then forward the
> +		 * frame with it and don't add one.
> +		 */
> +		if (frame->has_hsr_header && frame->skb_std) {
> +			skb = skb_clone(frame->skb_std, GFP_ATOMIC);
> +			goto inject_into_stack;
> +		}
> +

[Severity: Medium]

The commit message says:

  This is only used in the pure software version. Hardware with any kind
  of NETIF_F_HW_* offload support need to be addressed separately.

Is this limit enforced anywhere? hsr_dev_xmit() accepts the ETH_P_1588
inline header without checking hsr->fwd_offloaded or the slave features:

net/hsr/hsr_device.c:hsr_dev_xmit() {
    ...
	if (skb->protocol == htons(ETH_P_1588) &&
	    hsr_ptp_parse_header(skb, &has_hsr_header, &req_tx_port))
		goto drop;
    ...
}

The new req_tx_port filter and the has_hsr_header clone shortcut above
then apply to every slave. That includes slaves that advertise
NETIF_F_HW_HSR_DUP or NETIF_F_HW_HSR_TAG_INS.

For example, TI ICSSG in HSR offload mode does this in
emac_ndo_start_xmit():

drivers/net/ethernet/ti/icssg/icssg_common.c:emac_ndo_start_xmit() {
    ...
	if (prueth->is_hsr_offload_mode &&
	    (ndev->features & NETIF_F_HW_HSR_DUP))
		dst_tag_id = PRUETH_UNDIRECTED_PKT_DST_TAG;

	if (prueth->is_hsr_offload_mode &&
	    (ndev->features & NETIF_F_HW_HSR_TAG_INS))
		epib[1] |= PRUETH_UNDIRECTED_PKT_TAG_INS;
    ...
}

With this, wouldn't a frame requested only for SLAVE_A or SLAVE_B go out
on both ring ports? And wouldn't a frame that already carries an HSR
header get a second tag from the hardware?

Should the inline header be rejected when the slaves have HSR offload
features (ksz9477 and xrs700x are similar)? Or should the commit message
drop the claim that this is software only?

>  		/* Don't send frame over port where it has been sent before.
>  		 * Also for SAN, this shouldn't be done.
>  		 */

[ ... ]

> @@ -661,6 +677,13 @@ int hsr_fill_frame_info(__be16 proto, struct sk_buff *skb,
>  	struct hsr_port *port = frame->port_rcv;
>  	struct hsr_priv *hsr = port->hsr;
>  
> +	if (frame->has_hsr_header) {
> +		frame->skb_std = skb;
> +
> +		WARN_ON_ONCE(port->type != HSR_PT_MASTER);
> +		WARN_ON_ONCE(skb->mac_len < sizeof(struct hsr_ethhdr));
> +		return 0;
> +	}

[Severity: Low]

Only hsr_fill_frame_info() handles has_hsr_header. What happens on a PRP
device?

hsr_ptp_parse_header() does not check hsr->prot_version, so
has_hsr_header=true can reach hsr_forward_skb() on PRP. fill_frame_info()
then skips hsr_get_node() for both protocols. However,
prp_fill_frame_info() has no matching check:

net/hsr/hsr_forward.c:prp_fill_frame_info() {
	...
	if (rct &&
	    prp_check_lsdu_size(skb, rct, frame->is_supervision)) {
		...
		frame->skb_prp = skb;
		...
	}
	handle_std_frame(skb, frame);
	...
}

If there is no valid RCT, handle_std_frame() takes hsr->sequence_nr and
increments it. The new shortcut in hsr_forward_do() then sends the frame
unchanged. The sequence number is used up but never appears on the wire.

If there is a valid RCT, skb_std is NULL and the has_hsr_header shortcut
is skipped. The frame goes through register_frame_out, drop_frame and
prp_create_tagged_frame with node_src == NULL. It only avoids a NULL
dereference because prp_register_frame_out() returns early for frames
from the master port.

hsr_ptp_parse_header() also adds HSR_HLEN to hdr_len whenever
has_hsr_header is set:

	hdr_len = ETH_HLEN;
	if (*has_hsr_header)
		hdr_len += HSR_HLEN;

PRP uses a trailer, not a header. On PRP, wouldn't this require 6 extra
pullable bytes and put the network header 6 bytes too far into the frame?

The later commit "hsr: Assign a socket for cloned skbs" says it "does not
consider PRP part of the stack". Still, nothing in the series rejects the
inline header on PRP devices.

Should PRP reject has_hsr_header, or handle it the way
hsr_fill_frame_info() does?

>  	/* HSRv0 supervisory frames double as a tag so treat them as tagged. */
>  	if ((!hsr->prot_version && proto == htons(ETH_P_PRP)) ||
>  	    proto == htons(ETH_P_HSR)) {

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125-hsr_ptp-v12-0-9ddd2a73cb90%40linutronix.de
Re: [PATCH net-next v12 5/8] hsr: Use the port and header information in hsr_forward_skb()
#23400
Author: Sebastian Andrzej Siewior
Date: Fri, 27 Nov 2026 07:58
40 lines
11162 bytes
On 2026-11-26 14:40:38 [+0000], netdev-bot+sashiko@kernel.org wrote:
> Critical: 0 · High: 0 · Medium: 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.
…
> - [Medium] The commit message says the new behaviour "is only used in the
>   pure software version" and that NETIF_F_HW_* offload hardware "need[s]…
> - [Low] The patch makes hsr_fill_frame_info() check
>   frame->has_hsr_header: it sets skb_std = skb, skips…
> 
…
> [Severity: Medium]
> 
> The commit message says:
> 
>   This is only used in the pure software version. Hardware with any kind
>   of NETIF_F_HW_* offload support need to be addressed separately.
> 
> Is this limit enforced anywhere? hsr_dev_xmit() accepts the ETH_P_1588
> inline header without checking hsr->fwd_offloaded or the slave features:
> 
…
> The new req_tx_port filter and the has_hsr_header clone shortcut above
> then apply to every slave. That includes slaves that advertise
> NETIF_F_HW_HSR_DUP or NETIF_F_HW_HSR_TAG_INS.
> 
> For example, TI ICSSG in HSR offload mode does this in
…
> Should the inline header be rejected when the slaves have HSR offload
> features (ksz9477 and xrs700x are similar)? Or should the commit message
> drop the claim that this is software only?

Yes, this was brought up earlier. Hardware supported offloading features
will be look into once the software part is done.
It wasn't working before this series so it is not a regression.

Sebastian
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads