Skip to contentSkip to conversation

net: hsr: fix super-packet forwarding and ordering

PATCH Superseded Xin Xie 4 participants 21 messages Oct 9 – Nov 23

Subsystems (6)

v7 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Xin Xie

author
#0 lore raw

v7 cover net: hsr: fix super-packet forwarding and ordering

HSR/PRP requires per-wire-frame tags/RCTs and sequence numbers, and duplicate discard is per frame. RX GRO and TX GSO can present multiple frames as one skb and violate that assumption: a super-skb is either rejected by a constrained lower device, or forwarded without valid per-frame trailers and sequence numbers. An oversized PRP aggregate can also truncate the RCT's 12-bit LSDU size field.

Patch 1 keeps software GRO off while devices are direct HSR/PRP members, without rewriting wanted features. Fixed-on or driver-required GRO_HW may remain enabled.

Patch 2 replaces the forwarding lock with one consumer to avoid stacked-HSR deadlocks. It preserves per-lower submission order for locally numbered frames, so old HSR peers that drop late sequence numbers keep working. Only sequence allocation holds the short counter lock; forwarding runs after it is released.

Patch 3 segments valid GSO before per-frame processing, so each wire frame gets its own tag/RCT and sequence number. Patch 4 tests member GRO policy, GSO forwarding and local submission order.

A typical GSO source is a container connected to a PRP RedBox interlink through veth. An existing TCP/UDP GSO skb can reach the interlink with GRO disabled:

  container/netns                  host PRP RedBox
  prp0-peer ---- veth ---- prp0-int (interlink RX)
                                  |
                           split GSO into frames
                                  |
                           sequence number + RCT
                              /          \
                           LAN A        LAN B

Compatibility with older PRP senders:

Valid PRP frames from older senders remain supported. Patch 2 preserves submission order for locally numbered frames without changing the PRP frame format or requiring peers to upgrade.

Some old Linux PRP senders incorrectly append one RCT to an entire GSO skb. This violates the per-frame PRP requirement. Patch 3 drops such intact aggregates when trailing bytes extend past a known, nonzero IP length; zero lengths and GSO_PARTIAL are not covered by that check.

The mixed-version test uses two PRP VMs; the host runs no PRP. On virtio-net/TAP paths, disabling GRO_HW in patch 1 can make the host segment an old sender's malformed aggregate before it reaches the receiving VM. The RCT then becomes transport payload, which the receiver cannot reliably identify or remove. In our QEMU 8.2.2 UDP test this produced an extra six-byte datagram; the base receiver delivered the original data correctly. Upgrade the sender or disable GSO/TSO on its HSR/PRP master; the latter avoided the failure in the test.

Validation:

On the net test kernel (7.3.0-rc5-gb0fe53dd6370), the installed ordered selftest passed 5/5 cases, including supervision, concurrent producers and sequence wrap, with complete, loss-free captures.

GRO passed 11/11 with the preceding helper. The later cleanup-only fix does not affect GRO cases. Failure-injection checks confirmed error reporting and cleanup.

Earlier queue-stress and PREEMPT_RT results are retained. Paired W=1 builds had no additional diagnostics. These checks were not repeated for the helper update.

Based on net 6dc989ea46b9 (2026-10-05). Integration preserves the upstream interlink promiscuous-mode exception and setup-failure cleanup. The series applies directly to this base.

Patch 3 depends on patch 2; no stable backport is requested here. The remaining HSR dev->stats races are left to a separate series, as Paolo suggested [1]. Pre-existing shared-skb mutations are also handled separately.

[1] https://lore.kernel.org/netdev/[email protected]/

Changes since v6, including the NIPA and Gemini review responses:

- Replace recursive, one-time GRO disabling with persistent member policy and restoration of the latest wanted state.
- Preserve submission order with one consumer; remove the bitmap prerequisite and use core per-CPU counters for new RX/TX drops.
- Handle bounded 802.1Q/802.1AD VLAN stacks and reject trailing data beyond a known nonzero IP length before segmentation.
- Replace child-process signalling and fixed readiness sleeps with namespace-bound sockets registered before traffic. Bound cleanup under signals and preserve failures.
- Check packet contents, retransmissions and capture completeness, rather than throughput or average sizes. Use a standalone Python helper, with no embedded Python in the shell entries.

Veth tests do not validate hardware GRO_HW. The generic GSO bit need not be off, so tests now check GSO_MASK member types. The claim that the old test always failed was not supported by its actual feature state and recorded passing runs. Shared-skb mutation is a separate existing issue; both reports about new drop accounting are addressed by the per-CPU counters.

Previous postings (earlier design, newest first):
v6: https://lore.kernel.org/netdev/[email protected]/
v5: https://lore.kernel.org/netdev/[email protected]/
v4: https://lore.kernel.org/netdev/[email protected]/
v3: https://lore.kernel.org/netdev/[email protected]/
v2: https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/

Xin Xie (4):
net: hsr: keep GRO disabled on HSR/PRP ports
net: hsr: preserve submission order without a forwarding lock
net: hsr: segment GSO before per-frame forwarding
selftests: net: hsr: verify GRO policy and ordered forwarding

 .../networking/net_cachelines/net_device.rst      |    1 +
 include/linux/netdevice.h                         |    6 +
 net/core/dev.c                                    |   10 +
 net/hsr/Makefile                                  |    3 +-
 net/hsr/hsr_device.c                              |   66 +-
 net/hsr/hsr_forward.c                             |  233 +++-
 net/hsr/hsr_forward.h                             |   37 +
 net/hsr/hsr_forward_queue.c                       |  294 +++++
 net/hsr/hsr_main.h                                |   18 +
 net/hsr/hsr_netlink.c                             |    4 +-
 net/hsr/hsr_slave.c                               |   60 +-
 tools/testing/selftests/net/hsr/Makefile          |    3 +
 tools/testing/selftests/net/hsr/config            |    1 +
 .../selftests/net/hsr/hsr_gro_superpacket.py      | 1088 +++++++++++++++++++
 .../selftests/net/hsr/hsr_gro_superpacket.sh      |    9 +
 .../selftests/net/hsr/hsr_ordered_forwarding.sh   |    9 +
 16 files changed, 1784 insertions(+), 58 deletions(-)
 create mode 100644 net/hsr/hsr_forward_queue.c
 create mode 100755 tools/testing/selftests/net/hsr/hsr_gro_superpacket.py
 create mode 100755 tools/testing/selftests/net/hsr/hsr_gro_superpacket.sh
 create mode 100755 tools/testing/selftests/net/hsr/hsr_ordered_forwarding.sh

base-commit: 6dc989ea46b96ce170840174b4a38c4a387fb005

Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v7 1/4 net: hsr: keep GRO disabled on HSR/PRP ports

HSR/PRP add tags and sequence numbers per wire frame. GRO can merge plain interlink traffic before those fields are added, and userspace can re-enable GRO after the port is attached.

Mark slave A/B and interlink devices with a kernel role bit. Filter software GRO and configurable GRO_HW requests before ndo_fix_features() without changing wanted_features. Filtering before the driver keeps feature dependencies intact; fixed-on or driver-required GRO_HW is left enabled.

Apply the policy before registering the RX handler and reject attach if software GRO remains enabled. On failure or detach, unlink the upper before clearing the role and recomputing features, restoring the user's last request.

GSO skbs may still arrive. A later patch segments valid GSO before HSR/PRP processing.

Fixes 5055cccfc2d1 ("net: hsr: Provide RedBox support (HSR-SAN)")
---
 .../networking/net_cachelines/net_device.rst  |  1 +
 include/linux/netdevice.h                     |  6 +++
 net/core/dev.c                                | 10 ++++
 net/hsr/hsr_slave.c                           | 47 +++++++++++++++++++
 4 files changed, 64 insertions(+)
Documentation/networking/net_cachelines/net_device.rst +1 -0
index 512f6d6fa3d8..114a29b2ff4c 100644
@@ -168,6 +168,7 @@ unsigned_long:1                     see_all_hwtstamp_requests
 unsigned_long:1                     change_proto_down
 unsigned_long:1                     netns_immutable
 unsigned_long:1                     fcoe_mtu
+unsigned_long:1                     hsr_port
 struct list_head                    net_notifier_list
 struct macsec_ops*                  macsec_ops
 struct udp_tunnel_nic_info*         udp_tunnel_nic_info
include/linux/netdevice.h +6 -0
index 3cff2174dc03..0a917906fe2a 100644
@@ -2102,6 +2102,7 @@ enum netdev_reg_state {
  *	@change_proto_down: device supports setting carrier via IFLA_PROTO_DOWN
  *	@netns_immutable: interface can't change network namespaces
  *	@fcoe_mtu:	device supports maximum FCoE MTU, 2158 bytes
+ *	@hsr_port:	direct HSR/PRP member (slave A/B or interlink)
  *
  *	@net_notifier_list:	List of per-net netdev notifier block
  *				that follow this device when it is moved
@@ -2522,6 +2523,11 @@ struct net_device {
 	unsigned long		change_proto_down:1;
 	unsigned long		netns_immutable:1;
 	unsigned long		fcoe_mtu:1;
+	/* Direct HSR/PRP member: slave A/B or interlink.
+	 * Software GRO is filtered off while set. Kernel role
+	 * state only; no user ABI or offload capability.
+	 */
+	unsigned long		hsr_port:1;
 
 	struct list_head	net_notifier_list;
 
net/core/dev.c +10 -0
index 18dc88990510..0c53b59af439 100644
@@ -11111,6 +11111,16 @@ int __netdev_update_features(struct net_device *dev)
 
 	features = netdev_get_wanted_features(dev);
 
+	/* A direct HSR/PRP port needs per-frame metadata: filter
+	 * software GRO and configurable GRO_HW requests before the
+	 * driver fix runs, keeping the existing driver and core
+	 * feature coupling.
+	 */
+	if (dev->hsr_port) {
+		features &= ~NETIF_F_GRO;
+		features &= ~(dev->hw_features & NETIF_F_GRO_HW);
+	}
+
 	if (dev->netdev_ops->ndo_fix_features)
 		features = dev->netdev_ops->ndo_fix_features(dev, features);
 
net/hsr/hsr_slave.c +47 -0

78 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#7 lore raw

PATCH v7 2/4 net: hsr: preserve submission order without a forwarding lock

In reply to Xin Xie

Holding seqnr_lock across dev_queue_xmit() serializes numbering and submission, but creates transmit-lock dependencies that can deadlock stacked HSR devices. Merely shrinking the lock to the counter lets one CPU send frame N after another has sent N+1; old HSR peers discard the late N as stale.

Use one consumer for master TX, interlink RX and internally generated supervision frames. An idle caller processes its own input inline; contended inputs wait in a FIFO drained by one BH work item. Allocate sequence numbers only when the consumer executes a frame, and submit it to every lower before numbering the next frame. The short counter lock is released before forwarding.

Limit queued inputs to 1024 jobs and 8 MiB, reserving capacity for internal supervision. Carry transmit recursion depth across deferred execution, cancel the worker and purge the queue on teardown, and count queue drops once through core per-CPU statistics. LAN A/B reception stays synchronous and tagged frames retain their received numbers. The ordering guarantee is per-lower submission, not physical wire order across multiple TX queues.

On PREEMPT_RT, high-priority load preempted both the inline consumer and BH worker while another CPU continued to enqueue inputs. All 2118 inputs completed without drops; the finite data workload completed 4.07 seconds after the load ended.

Reported-by [email protected]
Fixes 06afd2c31d33 ("hsr: Synchronize sending frames to have always incremented outgoing seq nr.")
Fixes 430d67bdcb04 ("net: hsr: Use the seqnr lock for frames received via interlink port.")
---
 net/hsr/Makefile            |   3 +-
 net/hsr/hsr_device.c        |  64 +++++---
 net/hsr/hsr_forward.c       |  87 +++++++---
 net/hsr/hsr_forward.h       |  32 ++++
 net/hsr/hsr_forward_queue.c | 306 ++++++++++++++++++++++++++++++++++++
 net/hsr/hsr_main.h          |  18 +++
 net/hsr/hsr_netlink.c       |   4 +-
 net/hsr/hsr_slave.c         |  13 +-
 8 files changed, 470 insertions(+), 57 deletions(-)
 create mode 100644 net/hsr/hsr_forward_queue.c
net/hsr/Makefile +2 -1
index 34e581db5c41..223b66fe8577 100644
@@ -6,7 +6,8 @@
 obj-$(CONFIG_HSR)	+= hsr.o
 
 hsr-y			:= hsr_main.o hsr_framereg.o hsr_device.o \
-			   hsr_netlink.o hsr_slave.o hsr_forward.o
+			   hsr_netlink.o hsr_slave.o hsr_forward.o \
+			   hsr_forward_queue.o
 hsr-$(CONFIG_DEBUG_FS) += hsr_debugfs.o
 
 obj-$(CONFIG_PRP_DUP_DISCARD_KUNIT_TEST) += prp_dup_discard_test.o
net/hsr/hsr_device.c +39 -25

117 lines not on this page · raw message

net/hsr/hsr_forward.c +66 -21

143 lines not on this page · raw message

net/hsr/hsr_forward.h +32 -0
index 206636750b30..0fde1972c0a5 100644
@@ -13,7 +13,39 @@
 #include <linux/netdevice.h>
 #include "hsr_main.h"
 
+/* Per-frame execution source, carried explicitly down the call chain. */
+enum hsr_exec_source {
+	HSR_EXEC_DIRECT_LAN,	/* synchronous LAN A/B receive path */
+	HSR_EXEC_INLINE,	/* inline consumer activation */
+	HSR_EXEC_WORKER,	/* BH worker consumer */
+};
+
+/* Input class, stored with the immutable queue charge. */
+enum hsr_job_class {
+	HSR_JOB_NORMAL,
+	HSR_JOB_INTERNAL_SUP,
+};
+
+/* Return codes of proto_ops->fill_frame_info(): frame completed from a
+ * wire tag/RCT (0), untagged input left for the caller to complete with
+ * its execution source (HSR_FRAME_PLAIN), or error (< 0).
+ */
+#define HSR_FRAME_PLAIN	1
+
 void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port);
+void hsr_forward_sup_skb(struct sk_buff *skb, struct hsr_port *port);
+void hsr_forward_frame(struct sk_buff *skb, struct hsr_port *port,
+		       enum hsr_exec_source source);
+void hsr_assign_sup_seq(struct sk_buff *skb, struct hsr_priv *hsr,
+			enum hsr_exec_source source);
+
+/* Ordered forwarding queue (hsr_forward_queue.c) */
+void hsr_queue_submit(struct sk_buff *skb, struct hsr_port *port,
+		      enum hsr_job_class class);
+void hsr_forward_init(struct hsr_priv *hsr);
+void hsr_forward_stop(struct hsr_priv *hsr);
+void hsr_forward_forget_port(struct hsr_priv *hsr, struct net_device *dev);
+
 struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,
 					struct hsr_port *port);
 struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
net/hsr/hsr_forward_queue.c new file +306 -0

306 lines not on this page · raw message

net/hsr/hsr_main.h +18 -0
index 53e95bae0ee2..294c61f5068d 100644
@@ -14,6 +14,7 @@
 #include <linux/list.h>
 #include <linux/if_vlan.h>
 #include <linux/if_hsr.h>
+#include <linux/workqueue.h>
 
 /* Time constants as specified in the HSR specification (IEC-62439-3 2010)
  * Table 8.
@@ -25,6 +26,13 @@
 #define HSR_ANNOUNCE_INTERVAL		  100 /* ms */
 #define HSR_ENTRY_FORGET_TIME		  400 /* ms */
 
+/* Ordered-forwarding queue and work bounds. */
+#define HSR_FWD_JOBS_MAX		1024
+#define HSR_FWD_ORD_JOBS_MAX		960
+#define HSR_FWD_BYTES_MAX		(8 * 1024 * 1024)
+#define HSR_FWD_ORD_BYTES_MAX		(HSR_FWD_BYTES_MAX - 64 * 1024)
+#define HSR_FWD_BUDGET_MAX		64
+
 /* By how much may slave1 and slave2 timestamps of latest received frame from
  * each node differ before we notify of communication problem?
  */
@@ -202,6 +210,16 @@ struct hsr_priv {
 	enum hsr_version prot_version;	/* Indicate if HSRv0, HSRv1 or PRPv1 */
 	spinlock_t seqnr_lock;	/* locking for sequence_nr */
 	spinlock_t list_lock;	/* locking for node list */
+	/* Ordered-forwarding queue (hsr_forward_queue.c) */
+	spinlock_t fwd_lock;
+	struct list_head fwd_queue;
+	struct work_struct fwd_work;
+	unsigned int fwd_jobs;
+	unsigned int fwd_ord_jobs;
+	unsigned int fwd_bytes;
+	unsigned int fwd_ord_bytes;
+	bool fwd_owned;		/* consumer execution ownership */
+	bool fwd_stopped;
 	const struct hsr_proto_ops	*proto_ops;
 #define PRP_LAN_ID	0x5     /* 0x1010 for A and 0x1011 for B. Bit 0 is set
 				 * based on SLAVE_A or SLAVE_B
net/hsr/hsr_netlink.c +3 -1
index 88940e8014b2..971751bf38a1 100644
@@ -12,6 +12,7 @@
 #include <net/rtnetlink.h>
 #include <net/genetlink.h>
 #include "hsr_main.h"
+#include "hsr_forward.h"
 #include "hsr_device.h"
 #include "hsr_framereg.h"
 
@@ -137,6 +138,7 @@ static void hsr_dellink(struct net_device *dev, struct list_head *head)
 	timer_delete_sync(&hsr->announce_timer);
 	timer_delete_sync(&hsr->announce_proxy_timer);
 
+	hsr_forward_stop(hsr);
 	hsr_debugfs_term(hsr);
 	hsr_del_ports(hsr);
 
@@ -173,7 +175,7 @@ static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev)
 
 	if (nla_put(skb, IFLA_HSR_SUPERVISION_ADDR, ETH_ALEN,
 		    hsr->sup_multicast_addr) ||
-	    nla_put_u16(skb, IFLA_HSR_SEQ_NR, hsr->sequence_nr))
+	    nla_put_u16(skb, IFLA_HSR_SEQ_NR, READ_ONCE(hsr->sequence_nr)))
 		goto nla_put_failure;
 	if (hsr->prot_version == PRP_V1)
 		proto = HSR_PROTOCOL_PRP;
net/hsr/hsr_slave.c +4 -9
index 1afcacac6b3c..c93bd12a6749 100644
@@ -74,16 +74,10 @@ static rx_handler_result_t hsr_handle_frame(struct sk_buff **pskb)
 	}
 	skb_reset_mac_len(skb);
 
-	/* Only the frames received over the interlink port will assign a
-	 * sequence number and require synchronisation vs other sender.
+	/* Interlink RX is locally numbered and takes the ordered
+	 * consumer; the LAN A/B receive path stays synchronous.
 	 */
-	if (port->type == HSR_PT_INTERLINK) {
-		spin_lock_bh(&hsr->seqnr_lock);
-		hsr_forward_skb(skb, port);
-		spin_unlock_bh(&hsr->seqnr_lock);
-	} else {
-		hsr_forward_skb(skb, port);
-	}
+	hsr_forward_skb(skb, port);
 
 finish_consume:
 	return RX_HANDLER_CONSUMED;
@@ -289,6 +283,7 @@ void hsr_del_port(struct hsr_port *port)
 		netdev_update_features(master->dev);
 		dev_set_mtu(master->dev, hsr_get_max_mtu(hsr));
 		netdev_rx_handler_unregister(port->dev);
+		hsr_forward_forget_port(hsr, port->dev);
 		if (!port->hsr->fwd_offloaded || port->type == HSR_PT_INTERLINK)
 			dev_set_promiscuity(port->dev, -1);
 		if (port->type == HSR_PT_SLAVE_A || port->type == HSR_PT_SLAVE_B)
Signature · 1 line
2.43.0
author
#15 lore raw

PATCH v7 3/4 net: hsr: segment GSO before per-frame forwarding

In reply to Xin Xie

HSR/PRP require a tag/RCT and sequence number for each wire frame. Adding them to a GSO aggregate before segmentation cannot provide valid per-frame metadata.

Use the core GSO segmenter before normal per-frame processing. Each segment follows the usual local-delivery and forwarding paths. Remove GSO_MASK types from the master's hw_features so core TX also segments local traffic before ndo_start_xmit().

Classify by inner protocol, not ingress port. Use the core's bounded VLAN decoder for 802.1Q, 802.1AD and nested or accelerated tags. Reject inner HSR/PRP aggregates, unreadable fragments and undecodable headers. Also reject trailing bytes beyond a known nonzero IP length:
otherwise an old PRP sender's erroneous whole-aggregate RCT becomes transport payload. This check also rejects locally destined malformed inputs that the base kernel accepted. Zero IP lengths and GSO_PARTIAL are left to the segmenter because they provide no full IP extent for this check.

The preceding ordered-consumer patch is required for per-segment local numbering. Charge the worker budget by the actual segment count, or one on failure, and count each rejected input once through core per-CPU statistics on its entry device.

Fixes f421436a591d ("net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)")
---
 net/hsr/hsr_device.c        |   2 +-
 net/hsr/hsr_forward.c       | 148 +++++++++++++++++++++++++++++++++++-
 net/hsr/hsr_forward.h       |   5 ++
 net/hsr/hsr_forward_queue.c |  22 ++----
 4 files changed, 158 insertions(+), 19 deletions(-)
net/hsr/hsr_device.c +1 -1
index 68cd64a865fd..a67d85551abe 100644
@@ -698,7 +698,7 @@ void hsr_dev_setup(struct net_device *dev)
 	dev->needs_free_netdev = true;
 
 	dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA |
-			   NETIF_F_GSO_MASK | NETIF_F_HW_CSUM |
+			   NETIF_F_HW_CSUM |
 			   NETIF_F_HW_VLAN_CTAG_TX |
 			   NETIF_F_HW_VLAN_CTAG_FILTER;
 
net/hsr/hsr_forward.c +147 -1

166 lines not on this page · raw message

net/hsr/hsr_forward.h +5 -0
index 0fde1972c0a5..12fdf1bff4a3 100644
@@ -36,6 +36,11 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port);
 void hsr_forward_sup_skb(struct sk_buff *skb, struct hsr_port *port);
 void hsr_forward_frame(struct sk_buff *skb, struct hsr_port *port,
 		       enum hsr_exec_source source);
+unsigned int hsr_forward_input(struct sk_buff *skb, struct hsr_port *port,
+			       enum hsr_job_class class,
+			       enum hsr_exec_source source);
+void hsr_fwd_drop_stat(struct net_device *dev, enum hsr_port_type type,
+		       enum hsr_job_class class);
 void hsr_assign_sup_seq(struct sk_buff *skb, struct hsr_priv *hsr,
 			enum hsr_exec_source source);
 
net/hsr/hsr_forward_queue.c +5 -17
index 5e96c24dec00..c97cc722eaca 100644
@@ -28,18 +28,7 @@ struct hsr_job {
 	unsigned int		charge;	/* immutable skb->truesize */
 };
 
-/* Queue-stage drop: one count per dropped original input on the held
- * entry device.  Ordinary interlink RX is an RX drop; master TX and
- * internally generated supervision frames are TX drops.
- */
-static void hsr_fwd_drop_stat(struct net_device *dev, enum hsr_port_type type,
-			      enum hsr_job_class class)
-{
-	if (class == HSR_JOB_NORMAL && type == HSR_PT_INTERLINK)
-		dev_core_stats_rx_dropped_inc(dev);
-	else
-		dev_core_stats_tx_dropped_inc(dev);
-}
+/* Queue-stage drops share the mapping in hsr_forward.c. */
 
 static void hsr_job_drop(struct hsr_job *job)
 {
@@ -113,6 +102,7 @@ static unsigned int hsr_job_process(struct hsr_priv *hsr, struct hsr_job *job,
 {
 	struct hsr_port *port;
 	unsigned int raised = 0;
+	unsigned int cost;
 
 	rcu_read_lock();
 	port = hsr_job_port(hsr, job);
@@ -129,7 +119,7 @@ static unsigned int hsr_job_process(struct hsr_priv *hsr, struct hsr_job *job,
 
 	if (job->class == HSR_JOB_INTERNAL_SUP)
 		hsr_assign_sup_seq(job->skb, hsr, source);
-	hsr_forward_frame(job->skb, port, source);
+	cost = hsr_forward_input(job->skb, port, job->class, source);
 
 	while (raised) {
 		dev_xmit_recursion_dec();
@@ -140,10 +130,8 @@ static unsigned int hsr_job_process(struct hsr_priv *hsr, struct hsr_job *job,
 	dev_put(job->dev);
 	kfree(job);
 
-	/* One input is one budget unit; GSO per-frame accounting is
-	 * added by the segmentation change.
-	 */
-	return 1;
+	/* Actual per-frame units consumed; a failed aggregate costs 1. */
+	return cost;
 }
 
 static void hsr_queue_owned_release(struct hsr_priv *hsr)
Signature · 1 line
2.43.0
author
#18 lore raw

PATCH v7 4/4 selftests: net: hsr: verify GRO policy and ordered forwarding

In reply to Xin Xie

Add member GRO policy and ordered-forwarding tests with two shell entry points and one installed Python helper.

Exercise attach, feature requests, detach and failed attachment, including a busy RX handler. Check wanted-state restoration, the master's GSO type mask and continued delivery through the busy handler.

Capture actual TCP and UDP GSO traffic and compare every input with both LAN outputs. Count retransmitted TCP bytes separately so a retry cannot hide a dropped aggregate. Check payloads, tag/RCT, VLAN stack and sequence numbers, requiring complete captures without socket loss or truncation before any packet verdict.

Cover PRP LAN-ingress local delivery, plain and VLAN traffic, local and proxy supervision, concurrent producers and sequence wrap. Concurrency tests check per-LAN ordering and contents, without claiming proof of a worker handoff.

One process owns the namespace-bound sockets and capture. Work and cleanup are bounded; INT/TERM release owned resources and preserve failures. Missing prerequisites SKIP the affected case; feature-query errors and missing packet evidence FAIL.

---
 tools/testing/selftests/net/hsr/Makefile      |    3 +
 tools/testing/selftests/net/hsr/config        |    1 +
 .../selftests/net/hsr/hsr_gro_superpacket.py  | 1088 +++++++++++++++++
 .../selftests/net/hsr/hsr_gro_superpacket.sh  |    9 +
 .../net/hsr/hsr_ordered_forwarding.sh         |    9 +
 5 files changed, 1110 insertions(+)
 create mode 100755 tools/testing/selftests/net/hsr/hsr_gro_superpacket.py
 create mode 100755 tools/testing/selftests/net/hsr/hsr_gro_superpacket.sh
 create mode 100755 tools/testing/selftests/net/hsr/hsr_ordered_forwarding.sh
tools/testing/selftests/net/hsr/Makefile +3 -0
index 2150e487ac7d..81e55309ed20 100644
@@ -8,8 +8,11 @@ TEST_PROGS := \
 	hsr_redbox.sh \
 	link_faults.sh \
 	prp_ping.sh \
+	hsr_gro_superpacket.sh \
+	hsr_ordered_forwarding.sh \
 # end of TEST_PROGS
 
 TEST_FILES += hsr_common.sh
+TEST_FILES += hsr_gro_superpacket.py
 
 include ../../lib.mk
tools/testing/selftests/net/hsr/config +1 -0
index 205cc4d3d64b..724fbe3a6eab 100644
@@ -2,5 +2,6 @@ CONFIG_BRIDGE=y
 CONFIG_HSR=y
 CONFIG_IPV6=y
 CONFIG_NET_SCH_NETEM=m
+CONFIG_PACKET=y
 CONFIG_VETH=y
 CONFIG_VLAN_8021Q=m
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +1088 -0

1,088 lines not on this page · raw message

tools/testing/selftests/net/hsr/hsr_gro_superpacket.sh new file +9 -0
new file mode 100755
index 000000000000..9da711ad2ab2
@@ -0,0 +1,9 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+if ! command -v python3 > /dev/null; then
+	echo "SKIP: missing python3"
+	exit 4
+fi
+
+exec python3 -B "$(dirname "$0")/hsr_gro_superpacket.py" gro "$@"
tools/testing/selftests/net/hsr/hsr_ordered_forwarding.sh new file +9 -0
new file mode 100755
index 000000000000..b43218709455
@@ -0,0 +1,9 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+if ! command -v python3 > /dev/null; then
+	echo "SKIP: missing python3"
+	exit 4
+fi
+
+exec python3 -B "$(dirname "$0")/hsr_gro_superpacket.py" ordered "$@"
Signature · 1 line
2.53.0
author
#8 lore raw

Re: [PATCH net v7 2/4] net: hsr: preserve submission order without a forwarding lock

In reply to Xin Xie

One integration note for net-next:

This series targets net. Contest reports conflicts in three files. We handled the differences in those files as follows in our net-next integration:

- In send_hsr_supervision_frame() and handle_std_frame(), net-next already uses WRITE_ONCE() for hsr->sequence_nr. Remove the old numbering blocks as this patch does, and keep the new consumer-side numbering and WRITE_ONCE() updates. The supervision builder keeps the zero sequence placeholder.

- In hsr_fill_info(), net-next already has READ_ONCE() and the updated RCU handling. Omit only this patch's redundant sequence-read hunk and keep the net-next RCU handling unchanged.

This resolution was included in the previously built and reviewed integration series based on net-next cfb7793d1bc0. I also confirmed that net/hsr is byte-for-byte identical in net-next-2026-10-10--00-00, so the same resolution applies to these conflicts. I have not rebuilt the series on that snapshot.

Signature · 1 line
Xin
#2 lore raw

Re: [PATCH net v7 1/4] net: hsr: keep GRO disabled on HSR/PRP ports

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

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

Critical: 1 · High: 0 · Medium: 0 · 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).

- [Critical] The new HSR filter in __netdev_update_features() (net/core/dev.c) removes NETIF_F_GRO from dev->features but leaves it…
- [Low] (Baseline: not confirmed as a remaining bug.) The GRO policy only clears NETIF_F_GRO on the device directly enslaved to HSR/PRP.

--

net: hsr: keep GRO disabled on HSR/PRP ports

This patch adds a hsr_port role bit to struct net_device. While the bit is set, __netdev_update_features() filters NETIF_F_GRO and configurable NETIF_F_GRO_HW out of the computed features and leaves wanted_features alone. HSR sets the role before it registers the RX handler and rejects the port if software GRO stays on. On failure or detach it clears the role and recomputes features.

Quoted 7 lines
net/core/dev.c +0 -0
index 18dc88990510a..0c53b59af439a 100644
@@ -11111,6 +11111,16 @@ int __netdev_update_features(struct net_device *dev)
 
 	features = netdev_get_wanted_features(dev);

net/core/dev.c int __netdev_update_features(struct net_device *dev) · line 11122

Quoted 10 lines
net/core/dev.c +9 -0
 
+	/* A direct HSR/PRP port needs per-frame metadata: filter
+	 * software GRO and configurable GRO_HW requests before the
+	 * driver fix runs, keeping the existing driver and core
+	 * feature coupling.
+	 */
+	if (dev->hsr_port) {
+		features &= ~NETIF_F_GRO;
+		features &= ~(dev->hw_features & NETIF_F_GRO_HW);
+	}

[Severity: Critical]
Can this leave veth's NAPI state out of sync? After this filter runs, NETIF_F_GRO is clear in dev->features but still set in dev->wanted_features. veth depends on those two agreeing.

veth_set_features() adds or deletes NAPI when the effective GRO bit changes:

drivers/net/veth.c:veth_set_features() {
    ...
	if (!(changed & NETIF_F_GRO) || !(dev->flags & IFF_UP) || priv->_xdp_prog)
		return 0;
    ...
	} else {
		...
		veth_napi_del(dev);
	}
}

veth_open() and veth_close() (and the xdp enable/disable paths) decide whether NAPI exists from wanted_features instead:

drivers/net/veth.c:veth_gro_requested() {
	return !!(dev->wanted_features & NETIF_F_GRO);
}
drivers/net/veth.c:veth_close() {
    ...
	else if (veth_gro_requested(dev))
		veth_napi_del(dev);
}

Take veth0 that is up with gro on and gets added as an HSR slave. This call chain deletes the NAPIs:

hsr_portdev_role_set()->netdev_change_features()->veth_set_features()

A later "ip link set veth0 down" or "ip link del veth0" then reaches veth_close(). veth_gro_requested() is still true, so veth_napi_del() runs a second time.

Wouldn't napi_disable_locked() then spin forever while holding RTNL and the instance lock? The first disable left NAPIF_STATE_SCHED and NAPIF_STATE_NPSVC set.

The reverse order looks like a problem as well. Suppose veth0 has gro on while it is down, gets attached, and is then brought up. veth_open() enables NAPI because of wanted_features. On detach, hsr_portdev_role_clear() restores NETIF_F_GRO in features, and veth_set_features() calls veth_napi_enable() again.

Would that hit the WARN_ON for an already listed NAPI in netif_napi_add(), overwrite and leak the existing page_pool and ptr_ring, and then hit BUG_ON(!test_bit(NAPI_STATE_SCHED, &val)) in napi_enable_locked()?

Both sequences only need CAP_NET_ADMIN in a network namespace, and the HSR selftests use veth slaves. No later patch in the series touches veth or this filter.

[ ... ]

Quoted 4 lines
net/hsr/hsr_slave.c +0 -0
index a546f70f9cc8b..1afcacac6b3c8 100644

[ ... ]

net/hsr/hsr_slave.c static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev, · line 206

Quoted 11 lines
net/hsr/hsr_slave.c +7 -0
@@ -169,6 +197,19 @@ static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev,
 	if (res)
 		goto fail_upper_dev_link;
 
+	/* Enable the member role and recompute before the RX handler
+	 * is published: software GRO must be off before frames can
+	 * arrive.  A still-active software GRO rejects the port, a
+	 * remaining GRO_HW alone does not.
+	 */
+	hsr_portdev_role_set(dev);
+	if (dev->features & NETIF_F_GRO) {

[Severity: Low]
Does this check cover stacked members such as bond, team, macvlan or ipvlan, which hsr_check_dev_ok() accepts? For those devices GRO runs on the lower physical device. NETIF_F_UPPER_DISABLES is only NETIF_F_LRO, so nothing pushes GRO-off down to the lower device.

GRO-merged skbs can then still reach hsr_handle_frame() when bond_handle_frame() or macvlan_handle_frame() returns RX_HANDLER_ANOTHER, and this check still passes. For stacked members, the comment's statement that "software GRO must be off before frames can arrive" does not hold.

The commit message already says GSO skbs may still arrive. The later commit "net: hsr: segment GSO before per-frame forwarding" adds hsr_forward_input(), which segments any skb_is_gso() input before per-frame processing. By the end of the series the merged frames are therefore handled.

Could the comment say that only direct members are covered?

Quoted 5 lines
net/hsr/hsr_slave.c +5 -0
+		NL_SET_ERR_MSG_MOD(extack,
+				   "software GRO still on after feature update, cannot join");
+		res = -EBUSY;
+		goto fail_role_policy;
+	}

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261009201324.17-1-xiexinet%40gmail.com
#9 lore raw

Re: [PATCH net v7 2/4] net: hsr: preserve submission order without a forwarding lock

In reply to Xin Xie
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider.

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

Critical: 0 · High: 0 · Medium: 3 · Low: 5

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_queue_fits() (net/hsr/hsr_forward_queue.c) only checks HSR_JOB_INTERNAL_SUP jobs against the shared total (HSR_FWD_JOBS_MAX =…
- [Medium] The patch replaces seqnr_lock with hsr->fwd_owned, a bool that acts as an open-coded exclusive lock over the whole forwarding path…
- [Medium] Untrusted interlink RX frames and locally originated master TX frames share one ordinary-class admission budget (HSR_FWD_ORD_JOBS_MAX…
- [Low] net/hsr/hsr_forward_queue.c: hsr_job_process() always returns 1, and its comment says GSO per-frame accounting "is added by the…
- [Low] hsr_queue_submit() (net/hsr/hsr_forward_queue.c) allocates a struct hsr_job with GFP_ATOMIC, calls skb_dst_force() and calls…
- [Low] The concern says the commit message hides the scope of the
redesign: a new 306-line file, a deferred-execution engine and a…
- [Low] The same input class is counted differently depending on which stage drops it.
- [Low] hsr_queue_submit() pins job->dev with an untracked dev_hold(), which is netdev_hold(dev, NULL, GFP_ATOMIC).

--

net: hsr: preserve submission order without a forwarding lock

This patch stops holding seqnr_lock across dev_queue_xmit(). Master TX, interlink RX and internally generated supervision frames now go to a single per-instance consumer: an idle caller runs its frame inline, and contended callers queue it in a bounded FIFO that one BH work item drains. Sequence numbers are assigned at execution time under a short counter lock, and the queue is limited to 1024 jobs and 8 MiB, with a reserve for supervision frames.

Quoted 2 lines
Fixes 06afd2c31d33 ("hsr: Synchronize sending frames to have always incremented outgoing seq nr.")
Fixes 430d67bdcb04 ("net: hsr: Use the seqnr lock for frames received via interlink port.")

[Severity: Low]
This isn't a bug, but this patch carries both Fixes: tags and also adds a new 306-line forwarding queue, a BH worker, and a new return convention for proto_ops->fill_frame_info() (HSR_FRAME_PLAIN). The commit message does describe the design.

Would it be easier to review and backport if the deadlock fix were split from the queueing redesign? Or is the whole thing intended for stable as one change?

Quoted 4 lines
net/hsr/hsr_forward.c +0 -0
index 7734a521a96c2..e8b53367bf3ec 100644

[ ... ]

Quoted 10 lines
net/hsr/hsr_forward.c +0 -6
@@ -640,13 +652,20 @@ static void handle_std_frame(struct sk_buff *skb,
 	if (port->type != HSR_PT_MASTER)
 		frame->is_from_san = true;
 
-	if (port->type == HSR_PT_MASTER ||
-	    port->type == HSR_PT_INTERLINK) {
-		/* Sequence nr for the master/interlink node */
-		lockdep_assert_held(&hsr->seqnr_lock);
-		frame->sequence_nr = hsr->sequence_nr;
-		hsr->sequence_nr++;

net/hsr/hsr_forward.c static void handle_std_frame(struct sk_buff *skb, · line 663

Quoted 10 lines
net/hsr/hsr_forward.c +9 -1
-	}
+	if (!hsr_needs_local_numbering(port))
+		return;
+
+	/* Sequence nr for the master/interlink node.  Local sequence
+	 * numbers are assigned only by the single consumer; the
+	 * explicit call-chain source proves it, shared ownership state
+	 * does not.
+	 */
+	WARN_ON_ONCE(source == HSR_EXEC_DIRECT_LAN);

[Severity: Low]
This isn't a bug, but is the enum hsr_exec_source parameter needed? In handle_std_frame() and hsr_assign_sup_seq() its only use is this WARN_ON_ONCE(). hsr_forward_skb() routes on the same predicate:

hsr_forward_skb()

    if (hsr_needs_local_numbering(port)) {
        hsr_queue_submit(skb, port, HSR_JOB_NORMAL);
        return;
    }
    hsr_forward_frame(skb, port, HSR_EXEC_DIRECT_LAN);

so a master or interlink port can never reach this point with HSR_EXEC_DIRECT_LAN.

Also, hsr_job_process() always returns 1 in this patch, so the saturating budget arithmetic in hsr_queue_work() has no effect yet. The comment there says per-frame accounting "is added by the segmentation change". The next patch in the series ("net: hsr: segment GSO before per-frame forwarding") replaces it with the return value of hsr_forward_input(), so that part gets resolved later in the series.

Quoted 6 lines
net/hsr/hsr_forward.c +5 -0
+	spin_lock_bh(&hsr->seqnr_lock);
+	seq = hsr->sequence_nr;
+	WRITE_ONCE(hsr->sequence_nr, seq + 1);
+	spin_unlock_bh(&hsr->seqnr_lock);
+	frame->sequence_nr = seq;
 }

[ ... ]

Quoted 6 lines
net/hsr/hsr_forward_queue.c new file +0 -0
new file mode 100644
index 0000000000000..5e96c24dec005
@@ -0,0 +1,306 @@

[ ... ]

net/hsr/hsr_forward_queue.c line 42

Quoted 12 lines
net/hsr/hsr_forward_queue.c new file +12 -0
+/* Queue-stage drop: one count per dropped original input on the held
+ * entry device.  Ordinary interlink RX is an RX drop; master TX and
+ * internally generated supervision frames are TX drops.
+ */
+static void hsr_fwd_drop_stat(struct net_device *dev, enum hsr_port_type type,
+			      enum hsr_job_class class)
+{
+	if (class == HSR_JOB_NORMAL && type == HSR_PT_INTERLINK)
+		dev_core_stats_rx_dropped_inc(dev);
+	else
+		dev_core_stats_tx_dropped_inc(dev);
+}

[Severity: Low]
Should an interlink RX drop be counted differently depending on where it happens? When an ordinary interlink frame is dropped at queue admission, it is counted here with dev_core_stats_rx_dropped_inc(). If the same frame fails fill_frame_info() one step later, hsr_forward_frame() counts it as:

out_drop:

	rcu_read_unlock();
	port->dev->stats.tx_dropped++;

So userspace sees rx_dropped for one case and tx_dropped for the other, and the two sites use different counter sets (core per-CPU stats vs dev->stats).

Later in the series hsr_fwd_drop_stat() moves to hsr_forward.c and maps every non-master normal input to rx_dropped. The out_drop path in hsr_forward_frame() does not change, so the mismatch is still there.

[ ... ]

net/hsr/hsr_forward_queue.c line 62

Quoted 6 lines
net/hsr/hsr_forward_queue.c new file +6 -0
+static bool hsr_queue_fits(struct hsr_priv *hsr, struct hsr_job *job)
+{
+	if (hsr->fwd_jobs >= HSR_FWD_JOBS_MAX)
+		return false;
+	if (job->charge > HSR_FWD_BYTES_MAX - hsr->fwd_bytes)
+		return false;

[Severity: Medium]
Can internal supervision frames fill all HSR_FWD_JOBS_MAX slots? Only HSR_JOB_NORMAL jobs have their own cap. HSR_JOB_INTERNAL_SUP jobs are limited only by the shared total.

hsr_proxy_announce() sends one supervision frame per proxy_node_db entry in a single timer callback:

	list_for_each_entry_rcu(node, &hsr->proxy_node_db, mac_list) {
		if (hsr_addr_is_redbox(hsr, node->macaddress_A))
			continue;
		hsr->proto_ops->send_sv_frame(interlink, &interval,
					      node->macaddress_A);
	}

proxy_node_db is filled from source MACs seen on the interlink, and it doesn't seem to have a size limit.

If that burst arrives while another context owns the consumer (fwd_owned is true), supervision jobs can use all 1024 slots. Every master TX and interlink RX frame then fails the fwd_jobs check above and is dropped by hsr_job_drop() until the worker clears the burst, at 64 jobs per activation. Before this patch those frames waited on seqnr_lock instead of being dropped.

Should the supervision class have a cap as well?

net/hsr/hsr_forward_queue.c line 70

Quoted 8 lines
net/hsr/hsr_forward_queue.c new file +8 -0
+	if (job->class == HSR_JOB_NORMAL) {
+		if (hsr->fwd_ord_jobs >= HSR_FWD_ORD_JOBS_MAX)
+			return false;
+		if (job->charge > HSR_FWD_ORD_BYTES_MAX - hsr->fwd_ord_bytes)
+			return false;
+	}
+	return true;
+}

[Severity: Medium]
Interlink RX and local master TX share this one ordinary budget. With this patch, contended interlink receivers in hsr_handle_frame() queue the frame and return instead of spinning on seqnr_lock. A SAN-side host flooding the interlink, possibly from several RX CPUs on a multi-queue NIC, could keep fwd_ord_jobs at HSR_FWD_ORD_JOBS_MAX.

Would locally originated frames then be dropped here?

hsr_dev_xmit()
hsr_forward_skb(skb, master)
hsr_queue_submit(skb, master, HSR_JOB_NORMAL)
hsr_queue_fits() returns false
hsr_job_drop(job)

Before this patch, interlink load could slow master TX through lock contention, but it could not get master TX frames dropped at an internal admission check. Every remote frame also gets a GFP_ATOMIC job allocation before this check runs.

Should master TX have a reserve that is separate from interlink RX?

[ ... ]

Quoted 7 lines
net/hsr/hsr_forward_queue.c new file +7 -0
+static void hsr_queue_owned_release(struct hsr_priv *hsr)
+{
+	if (!hsr->fwd_stopped && !list_empty(&hsr->fwd_queue))
+		queue_work(system_bh_wq, &hsr->fwd_work);
+	else
+		hsr->fwd_owned = false;
+}

[ ... ]

Quoted 16 lines
net/hsr/hsr_forward_queue.c new file +16 -0
+static void hsr_queue_inline_one(struct hsr_priv *hsr, struct hsr_job *job)
+{
+	local_bh_disable();
+	hsr_job_process(hsr, job, HSR_EXEC_INLINE);
+	spin_lock_bh(&hsr->fwd_lock);
+	hsr_queue_owned_release(hsr);
+	spin_unlock_bh(&hsr->fwd_lock);
+	local_bh_enable();
+}
+
+void hsr_queue_submit(struct sk_buff *skb, struct hsr_port *port,
+		      enum hsr_job_class class)
+{
+	struct hsr_priv *hsr = port->hsr;
+	struct hsr_job *job;
+	bool inline_owner = false;

net/hsr/hsr_forward_queue.c line 217

Quoted 10 lines
net/hsr/hsr_forward_queue.c new file +10 -0
+
+	RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
+			 "HSR queue submit outside RCU read-side");
+
+	job = kzalloc_obj(*job, GFP_ATOMIC);
+	if (!job) {
+		hsr_fwd_drop_stat(port->dev, port->type, class);
+		kfree_skb(skb);
+		return;
+	}

[Severity: Low]
This allocation, plus the skb_dst_force() and dev_hold() below, runs for every master TX, interlink RX and supervision frame. All of it happens before fwd_lock is taken to check whether the consumer is idle. In the uncontended inline case the job never enters the queue, so is a heap allocation needed there?

It also adds a new drop path: if the GFP_ATOMIC allocation fails, the frame is dropped through hsr_fwd_drop_stat() and kfree_skb(). Before this patch, hsr_dev_xmit() and the interlink RX path allocated nothing at this point.

Would an on-stack job for the inline case, or allocating only when the job has to be queued, avoid both the per-packet cost and this new failure mode?

net/hsr/hsr_forward_queue.c line 225

Quoted 8 lines
net/hsr/hsr_forward_queue.c new file +8 -0
+	job->skb = skb;
+	job->dev = port->dev;
+	job->type = port->type;
+	job->class = class;
+	job->depth = dev_recursion_level();
+	job->charge = skb->truesize;
+	skb_dst_force(skb);
+	dev_hold(job->dev);

[Severity: Low]
This isn't a bug, but this reference is passed to system_bh_wq and can outlive the submitting context. Would netdev_hold() with a netdevice_tracker in struct hsr_job work better than an untracked dev_hold()?

With CONFIG_NET_DEV_REFCNT_TRACKER, a leaked job reference would then show the owner's stack, not just the generic "waiting for <dev> to become free" message.

Quoted 17 lines
net/hsr/hsr_forward_queue.c new file +17 -0
+
+	spin_lock_bh(&hsr->fwd_lock);
+	if (hsr->fwd_stopped) {
+		spin_unlock_bh(&hsr->fwd_lock);
+		hsr_job_drop(job);
+		return;
+	}
+	if (!hsr->fwd_owned) {
+		/* Idle: take the execution ownership and process this
+		 * input directly.  The job never enters the public queue
+		 * and does not consume queued charge.
+		 */
+		hsr->fwd_owned = true;
+		inline_owner = true;
+	} else if (hsr_queue_fits(hsr, job)) {
+		list_add_tail(&job->list, &hsr->fwd_queue);
+		hsr_queue_charge_add(hsr, job);

net/hsr/hsr_forward_queue.c line 252

Quoted 10 lines
net/hsr/hsr_forward_queue.c new file +10 -0
+	} else {
+		spin_unlock_bh(&hsr->fwd_lock);
+		hsr_job_drop(job);
+		return;
+	}
+	spin_unlock_bh(&hsr->fwd_lock);
+
+	if (inline_owner)
+		hsr_queue_inline_one(hsr, job);
+}

[Severity: Medium]
fwd_owned acts as an exclusive lock over the whole forwarding path:
fill_frame_info(), hsr_forward_do() and dev_queue_xmit() to every lower. Contenders never wait on it, though. They add to fwd_queue and return.

Does this lose the priority inheritance that seqnr_lock gave on PREEMPT_RT? There, spinlock_t is rt_mutex based, so a high-priority contender would boost a low-priority holder. Now suppose a low-priority task takes ownership in hsr_dev_xmit() and is preempted inside hsr_queue_inline_one():

	local_bh_disable();
	hsr_job_process(hsr, job, HSR_EXEC_INLINE);

local_bh_disable() does not prevent preemption on RT, and nothing boosts the owner. Master TX, interlink RX and supervision frames from every CPU wait in the queue until it runs again. Once the queue fills, they are dropped.

The commit message seems to describe forwarding stopping for as long as the load ran:

On PREEMPT_RT, high-priority load preempted both the inline consumer and BH worker while another CPU continued to enqueue inputs. All 2118 inputs completed without drops; the finite data workload completed 4.07 seconds after the load ended.

On non-RT, hsr_queue_owned_release() hands ownership to the worker:

	queue_work(system_bh_wq, &hsr->fwd_work);

system_bh_wq is per-CPU, so the backlog for the whole instance drains only on the CPU that queued the work. If that CPU is busy, can inputs from all the other CPUs pile up to the 960/1024 limits and get dropped?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261009201324.17-1-xiexinet%40gmail.com
#19 lore raw

Re: [PATCH net v7 4/4] selftests: net: hsr: verify GRO policy and ordered forwarding

In reply to Xin Xie
Thank you for your contribution! Sashiko AI review found 10 potential issue(s) to consider.

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

Critical: 0 · High: 0 · Medium: 7 · Low: 3

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 'busy-handler rollback' case (rollback_macvlan() in hsr_gro_superpacket.py) needs a macvlan device, but…
- [Medium] set_gro() accepts a rejected GRO request only when ethtool's stdout is exactly "Actual changes:\nrx-gro: off [requested on]\n" and…
- [Medium] decode() treats any non-HSR frame whose last two bytes are 0x88fb as PRP (elif end >= off + 6 and raw[-2:] == b"\x88\xfb":) and…
- [Medium] Capture.__init__ creates the AF_PACKET socket with protocol htons(ETH_P_ALL) (line 120), then calls setsockopt twice, and only…
- [Medium] SIGINT/SIGTERM are handled by interrupt(), which raises InterruptedError in the main thread at the next bytecode boundary.
- [Medium] Lab.finish() decides transmission is complete after 100 ms with no captured frame (`if empty and time.monotonic() - quiet >= 0.1:…
- [Medium] Lab.finish() removes the capture hooks one capture at a time (for cap in active: ... cap.socket.bind(("lo", 0))).
- [Low] Lab.finish() takes every capture in self.captures that is not yet complete, so a case that raises Skip after creating captures but…
- [Low] hsr_gro_superpacket.py contains about 1088 lines of its own
framework: a hand-written TAP emitter, ctypes setns() namespace entry,…
- [Low] In ordered_concurrent(), if a producer fails before reaching the barrier (for example, os.sched_setaffinity() raises), its except block…

--

selftests: net: hsr: verify GRO policy and ordered forwarding

This adds a Python helper with two shell entry points. It tests HSR/PRP member GRO handling across attach, detach and failed attachment, the master's GSO type mask, and TCP/UDP GSO segmentation through HSR and PRP. It also uses AF_PACKET captures on every lane to check ordered forwarding of local, interlink, supervision and concurrent traffic, plus sequence number wrap.

[ ... ]

tools/testing/selftests/net/hsr/config CONFIG_BRIDGE=y · line 7

Quoted 11 lines
tools/testing/selftests/net/hsr/config +1 -0
index 205cc4d3d64bd..724fbe3a6eab7 100644
@@ -2,5 +2,6 @@ CONFIG_BRIDGE=y
 CONFIG_HSR=y
 CONFIG_IPV6=y
 CONFIG_NET_SCH_NETEM=m
+CONFIG_PACKET=y
 CONFIG_VETH=y
 CONFIG_VLAN_8021Q=m

[Severity: Medium]
Should CONFIG_MACVLAN be added here too?

The busy-handler rollback case in rollback_macvlan() creates a macvlan on top of m:

    result = lab.ip(ns, "link", "add", "link", "m", "name", "mv",
                    "type", "macvlan", "mode", "bridge", check=False)

On a kernel built from this fragment, that command fails with "Unknown device type", and rollback_macvlan() turns the failure into a SKIP:

if "unknown device type" in error or "operation not supported" in error:
raise Skip("macvlan device kind unavailable: " + result.stderr.strip())

No other case reaches the -EBUSY path in hsr_portdev_setup(), where netdev_rx_handler_register() fails because macvlan already owns the rx_handler. CI kernels built from net/hsr/config would lose that coverage and still report success.

Quoted 6 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +0 -0
new file mode 100755
index 0000000000000..d39bf1af291f8
@@ -0,0 +1,1088 @@

[ ... ]

Quoted 1 line

+def decode(raw, ancillary=()):

[ ... ]

Quoted 4 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +4 -0
+    end = len(raw)
+    if proto == 0x892f:
+        require(off + 6 <= end, "short HSR tag")
+        field, seq, proto = struct.unpack_from("!HHH", raw, off)

tools/testing/selftests/net/hsr/hsr_gro_superpacket.py line 81

Quoted 10 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +10 -0
+        row.update(seq=seq, path=field >> 12, tag=True, encoding="hsr")
+        expected = len(raw) - 14 - (4 if raw[12:14] == b"\x81\x00" else 0)
+        require(field & 0xfff == expected, "HSR LSDU size differs")
+        off += 6
+    elif end >= off + 6 and raw[-2:] == b"\x88\xfb":
+        seq, field, suffix = struct.unpack_from("!HHH", raw, end - 6)
+        expected = len(raw) - 14 - (4 if raw[12:14] == b"\x81\x00" else 0)
+        require(field & 0xfff == expected, "PRP LSDU size differs")
+        row.update(seq=seq, path=field >> 12, tag=True, encoding="prp")
+        end -= 6

[Severity: Medium]
Can an ordinary untagged frame that happens to end in 88:fb fail the whole run here?

decode() treats any non-HSR frame whose last two bytes are 0x88fb as PRP, and an LSDU mismatch then raises an error. The kernel handles a mismatched LSDU size by falling back to a plain frame, in prp_fill_frame_info():

    if (rct &&
        prp_check_lsdu_size(skb, rct, frame->is_supervision)) {
        ...
        return 0;
    }
    return HSR_FRAME_PLAIN;

Capture.drain() calls decode() on every frame that matches pkttype. That includes captures on non-PRP links such as dil, t0 and m/mv.

A pure TCP ACK ends in the low 16 bits of TSecr. An IPv6 NS/RS/MLD frame can end in the last two bytes of a random interface MAC. In either case drain() raises ValueError, the case fails, and every later case is reported as not ok.

Would it be better to treat an LSDU mismatch as a plain frame, as the kernel does?

[ ... ]

tools/testing/selftests/net/hsr/hsr_gro_superpacket.py line 123

Quoted 11 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +11 -0
+class Capture:
+    def __init__(self, lab, ns, dev, pkttype=None):
+        self.lab, self.rows, self.seen = lab, [], 0
+        self.ns, self.dev, self.packets = ns, dev, None
+        self.pkttype, self.name = pkttype, ns + "/" + dev
+        self.complete, self.drops, self.truncated = False, None, 0
+        self.last_seen = time.monotonic()
+        self.socket = lab.sock(ns, socket.AF_PACKET, socket.SOCK_RAW, socket.htons(3))
+        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 8 * 1024 * 1024)
+        self.socket.setsockopt(263, 8, 1)
+        self.socket.bind((dev, 0))

[Severity: Medium]
Can frames from other interfaces end up in this capture?

Creating the socket with htons(ETH_P_ALL) registers the hook right away in packet_create(), with no device restriction:

    if (proto) {
        po->prot_hook.type = proto;
        __register_prot_hook(sk);
    }

Frames that arrive on any device in the namespace before bind((dev, 0)) stay in the socket queue. Capture.drain() checks only addr[2] (pkttype) and never addr[0] (ifname):

    if self.pkttype is None or addr[2] == self.pkttype:
        self.rows.append(decode(raw, anc))

For example, while ordered_lanes() is creating the db capture, a supervision or ND frame sent on da can be recorded as db traffic. verify_supervision() then fails with "wrong supervision tag kind/path", a protocol_order() error, or "data/supervision LAN order differs".

Would either of these avoid it: creating the socket with protocol 0 and passing ETH_P_ALL to bind(), or filtering on addr[0] in drain()?

[ ... ]

Quoted 2 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +2 -0
+class Lab:
+    def __init__(self, deadline):

[ ... ]

tools/testing/selftests/net/hsr/hsr_gro_superpacket.py line 183

Quoted 2 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +2 -0
+    def ns(self, label):
+        name = "hsrp4-%s-%d" % (self.token, len(self.names))

[Severity: Low]
This isn't a bug, but this file carries its own test framework: a hand-written TAP emitter, namespace entry through ctypes setns(), a manager for namespace/socket/capture lifetimes, and ip/ethtool wrappers.

tools/testing/selftests/net/lib/py already provides ksft_run, NetNS, NetNSEnter, defer, ip, ethtool and cmd. Could this use net/lib/py instead? The custom layer has no per-case teardown, which leads to the cross-case coupling in Lab.finish() noted below.

Some of the code is unused. Lab.ns() ignores label, and tcp_transfer() never uses its captures argument.

[ ... ]

Quoted 4 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +4 -0
+    @contextmanager
+    def enter(self, ns):
+        descriptor = os.open("/var/run/netns/" + ns, os.O_RDONLY)
+        try:

tools/testing/selftests/net/hsr/hsr_gro_superpacket.py line 212

Quoted 10 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +10 -0
+            self.setns(descriptor)
+            yield
+        finally:
+            try:
+                self.setns(self.original)
+            except BaseException:
+                self.restore_failed = True
+                raise
+            finally:
+                os.close(descriptor)

[Severity: Medium]
Can a SIGINT or SIGTERM here leak every namespace the test owns?

interrupt() raises InterruptedError at the next bytecode boundary. If that happens during or just after self.setns(self.original), restore_failed is set even though the libc setns() call already succeeded.

Lab.close() then skips every ip netns del and never retries the restore:

if self.restore_failed:
errors.append("namespace restoration failed; no namespace commands attempted")

All hsrp4-* namespaces are left behind, along with their veths and HSR devices.

main()'s finally block has a similar window:

finally:
for sig in (signal.SIGINT, signal.SIGTERM):
signal.signal(sig, signal.SIG_IGN)
try:
lab.close()

The handlers are switched one at a time. A second signal that arrives before both are ignored raises InterruptedError inside the finally block, and lab.close() never runs.

The commit message says:

INT/TERM release owned resources and preserve failures.

Would blocking the signals with signal.pthread_sigmask() around these sections make that statement hold?

[ ... ]

tools/testing/selftests/net/hsr/hsr_gro_superpacket.py line 238

Quoted 2 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +2 -0
+    def finish(self):
+        active = [cap for cap in self.captures if not cap.complete]

[Severity: Low]
This collects every incomplete capture from the whole run, not only those of the current case. If a case raised Skip after creating captures but before calling finish(), the next case's finish() would run the cutoff and validate() on them.

As far as I can tell, the only such path today is the Skip in ordered_data():

except OSError as error:
if error.errno in (errno.ENOPROTOOPT, errno.EOPNOTSUPP):
raise Skip("UDP GSO unavailable") from error

udp_lib_setsockopt() cannot return those errnos for UDP_SEGMENT:

    case UDP_SEGMENT:
        if (val < 0 || val > USHRT_MAX)
            return -EINVAL;
        WRITE_ONCE(up->gso_size, val);

So the path can't be reached in the current tree. Would it still be safer to limit captures to the case that created them?

tools/testing/selftests/net/hsr/hsr_gro_superpacket.py line 250

Quoted 12 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +12 -0
+        end = min(self.deadline, time.monotonic() + 2)
+        quiet = time.monotonic()
+        while time.monotonic() < end:
+            self.observe(0.01)
+            empty = True
+            for cap in active:
+                count, drained = cap.drain()
+                if count or not drained:
+                    empty = False
+            quiet = max([quiet] + [cap.last_seen for cap in active])
+            if empty and time.monotonic() - quiet >= 0.1:
+                break

[Severity: Medium]
Is 100 ms with no captured frame enough to conclude that the kernel has finished transmitting?

In this tree, contended master TX, interlink RX and supervision frames are queued and drained by a BH work item. In net/hsr/hsr_forward_queue.c, hsr_queue_owned_release() does:

    queue_work(system_bh_wq, &hsr->fwd_work);

hsr_queue_work() requeues itself when its budget runs out.

Suppose that worker is delayed by more than about 100 ms after the last captured frame, for example under load on PREEMPT_RT. The remaining frames then go out after the hooks have been moved to lo, and verify_udp() fails with "UDP payload/ID set differs". ordered_send() also allows only lab.observe(0.1) before returning.

The packets == seen + drops check only shows that the socket queue was drained. Could finish() instead wait until every expected payload has been seen on both lanes, with the deadline as the upper bound?

Quoted 2 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +2 -0
+        else:
+            raise ValueError("capture failed to drain within fixed deadline")

[ ... ]

tools/testing/selftests/net/hsr/hsr_gro_superpacket.py line 269

Quoted 6 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +6 -0
+        for cap in active:
+            require(time.monotonic() < end, "capture cutoff/drain deadline expired")
+            require(cap.dev != "lo", "capture already uses the cutoff device")
+            cap.socket.bind(("lo", 0))
+            require(cap.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) == errno.ENETDOWN,
+                    cap.name + ": capture cutoff did not report ENETDOWN")

[Severity: Medium]
Can the da and db captures stop at different points in the stream?

The hooks are removed one capture at a time. Each bind() of a running socket goes through packet_do_bind()->__unregister_prot_hook(sk, true), which calls synchronize_net().

In ordered_supervision(), the HSR master and interlink are still up when finish() runs:

    lab.observe(10)
    lab.finish()

hsr_announce() and hsr_proxy_announce() keep sending supervision frames during the cutoff. A frame sent after the da hook is removed, but before the db hook is removed, is captured only on db.

Both captures pass their completeness checks, but verify_supervision() fails:

    require(observed[0] == observed[1], "supervision LAN copies differ")
    require(all_frames[0] == all_frames[1], "data/supervision LAN order differs")

Would it help to stop the supervision senders before the cutoff, or to compare only the prefix that both lanes have in common?

[ ... ]

tools/testing/selftests/net/hsr/hsr_gro_superpacket.py line 474

Quoted 7 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +7 -0
+def set_gro(lab, ns, dev, wanted, active=None):
+    result = lab.cmd(ns, "ethtool", "-K", dev, "gro", wanted, check=False)
+    forced = (active == "off" and wanted == "on" and result.returncode == 1
+              and result.stdout == "Actual changes:\nrx-gro: off [requested on]\n"
+              and result.stderr == "Could not change any device features\n")
+    require(result.returncode == 0 or forced,
+            "%s: GRO setter rc%d %s" % (dev, result.returncode, result.stderr.strip()))

[Severity: Medium]
Does this depend on the exact output format of ethtool?

A rejected request is accepted only when stdout and stderr match these strings byte for byte. The code right below already reads back the actual state with lab.features() and checks it against active.

forced becomes false if an ethtool build reports the change differently, for example:

- the ioctl fallback, which uses legacy names such as generic-receive-offload
- an extra line for a dependent feature

policy() goes through this path on every iteration:

    for wanted in ("on", "off", last):
        set_gro(lab, ns, "m", wanted, active="off")

When it fails here, every remaining gro-mode case is reported as not ok.

Could this rely on the read-back state, and check only the return code here?

[ ... ]

Quoted 5 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +5 -0
+    def producer(index):
+        try:
+            # Socket namespace binding was completed before threads existed.
+            os.sched_setaffinity(0, {cpus[index]})
+            barrier.wait(timeout=2)

[ ... ]

Quoted 13 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +13 -0
+        except Exception as error:
+            errors.append(error)
+            stop.set()
+            barrier.abort()
+
+    threads = [threading.Thread(target=producer, args=(index,))
+               for index in range(2)]
+    unfinished = []
+    try:
+        for thread in threads:
+            lab.threads.append(thread)
+            thread.start()
+        barrier.wait(timeout=2)

[ ... ]

tools/testing/selftests/net/hsr/hsr_gro_superpacket.py line 843

Quoted 2 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +2 -0
+    if errors:
+        raise errors[0]

[Severity: Low]
What happens when a producer fails before reaching the barrier, for example in os.sched_setaffinity()?

The producer calls barrier.abort(), and the main thread's barrier.wait() raises threading.BrokenBarrierError. That exception propagates through the finally block, so the recorded producer error is never raised.

main() then prints "not ok N - two-functional-producers: " with an empty message, and the real cause is lost.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261009201324.17-1-xiexinet%40gmail.com
author
#20 lore raw

Re: [PATCH net v7 4/4] selftests: net: hsr: verify GRO policy and ordered forwarding

Quoted 2 lines

[Severity: Critical]
Can this leave veth's NAPI state out of sync?

Confirmed. veth decides its NAPI lifetime from wanted_features in veth_open()/veth_close(), so an attached veth with GRO still requested can disable NAPI twice on close, or enable it twice on detach. I will fix this in v8 and address the reports on patches 2 and 4 there too.

pw-bot: cr

--
Xin

#3 lore raw

Re: [PATCH net v7 1/4] net: hsr: keep GRO disabled on HSR/PRP ports

In reply to Xin Xie
Quoted 15 lines · Xin Xie

HSR/PRP add tags and sequence numbers per wire frame. GRO can merge plain interlink traffic before those fields are added, and userspace can re-enable GRO after the port is attached.

Mark slave A/B and interlink devices with a kernel role bit. Filter software GRO and configurable GRO_HW requests before ndo_fix_features() without changing wanted_features. Filtering before the driver keeps feature dependencies intact; fixed-on or driver-required GRO_HW is left enabled.

Apply the policy before registering the RX handler and reject attach if software GRO remains enabled. On failure or detach, unlink the upper before clearing the role and recomputing features, restoring the user's last request.

Quoted 5 lines

GSO skbs may still arrive. A later patch segments valid GSO before HSR/PRP processing.

Fixes 5055cccfc2d1 ("net: hsr: Provide RedBox support (HSR-SAN)")

This looks better than what I remember from the previous version. Are the bot's complains legitime?

Sebastian

#10 lore raw

Re: [PATCH net v7 2/4] net: hsr: preserve submission order without a forwarding lock

In reply to Xin Xie
Quoted 5 lines · Xin Xie

Holding seqnr_lock across dev_queue_xmit() serializes numbering and submission, but creates transmit-lock dependencies that can deadlock stacked HSR devices. Merely shrinking the lock to the counter lets one CPU send frame N after another has sent N+1; old HSR peers discard the late N as stale.

What are stacked HSR devices? Looking from the setup in the referenced report this is a bridge device attached to a HSR ring.
An announce frame is sent and this goes to hsr_dev_xmit(). This does not look like a normal setup. Is this something you use or is this something the bot came up with?

Quoted 15 lines

Use one consumer for master TX, interlink RX and internally generated supervision frames. An idle caller processes its own input inline; contended inputs wait in a FIFO drained by one BH work item. Allocate sequence numbers only when the consumer executes a frame, and submit it to every lower before numbering the next frame. The short counter lock is released before forwarding.

Limit queued inputs to 1024 jobs and 8 MiB, reserving capacity for internal supervision. Carry transmit recursion depth across deferred execution, cancel the worker and purge the queue on teardown, and count queue drops once through core per-CPU statistics. LAN A/B reception stays synchronous and tagged frames retain their received numbers. The ordering guarantee is per-lower submission, not physical wire order across multiple TX queues.

Quoted 4 lines

On PREEMPT_RT, high-priority load preempted both the inline consumer and BH worker while another CPU continued to enqueue inputs. All 2118 inputs completed without drops; the finite data workload completed 4.07 seconds after the load ended.

This looks very complex and I am not a big fan of it. I would prefer to break lock chain early assuming the setup is valid/ sane (see above).

The ID by itself can be assigned with an atomic_inc() but then you don't have the transmit ordering. So you introduce the workqueue for the ordering which is ugh. I'm not sure how this works if you get submissions from two CPUs given the lock is gone and the workqueue is per-CPU.

Quoted 5 lines
Reported-by [email protected]
Fixes 06afd2c31d33 ("hsr: Synchronize sending frames to have always incremented outgoing seq nr.")
Fixes 430d67bdcb04 ("net: hsr: Use the seqnr lock for frames received via interlink port.")

Sebastian

#16 lore raw

Re: [PATCH net v7 3/4] net: hsr: segment GSO before per-frame forwarding

In reply to Xin Xie
Quoted 19 lines · Xin Xie

HSR/PRP require a tag/RCT and sequence number for each wire frame. Adding them to a GSO aggregate before segmentation cannot provide valid per-frame metadata.

Use the core GSO segmenter before normal per-frame processing. Each segment follows the usual local-delivery and forwarding paths. Remove GSO_MASK types from the master's hw_features so core TX also segments local traffic before ndo_start_xmit().

Classify by inner protocol, not ingress port. Use the core's bounded VLAN decoder for 802.1Q, 802.1AD and nested or accelerated tags. Reject inner HSR/PRP aggregates, unreadable fragments and undecodable headers. Also reject trailing bytes beyond a known nonzero IP length:
otherwise an old PRP sender's erroneous whole-aggregate RCT becomes transport payload. This check also rejects locally destined malformed inputs that the base kernel accepted. Zero IP lengths and GSO_PARTIAL are left to the segmenter because they provide no full IP extent for this check.

Quoted 6 lines

The preceding ordered-consumer patch is required for per-segment local numbering. Charge the worker budget by the actual segment count, or one on failure, and count each rejected input once through core per-CPU statistics on its entry device.

Fixes f421436a591d ("net/hsr: Add support for the High-availability Seamless Redundancy protocol (HSRv0)")

I've been re-reading the old mails. The whole thing is needed for GSO when it can not be disabled, right? And VETH interface has been named as an example.
There was also a bridge device. With HSR you form a ring. With a bridge you attach other (physical) devices within the ring. This does not sound like real life use-case. Do I miss something?

Quoted 1 line

Sebastian

author
#4 lore raw

Re: [PATCH net v7 1/4] net: hsr: keep GRO disabled on HSR/PRP ports

In reply to Sebastian Andrzej Siewior
Quoted 2 lines

This looks better than what I remember from the previous version. Are the bot's complains legitime?

Yes, the Critical one is real.

veth creates and deletes its NAPI instances based on wanted_features (veth_gro_requested() in veth_open() and veth_close()). This patch only clears NETIF_F_GRO from the active features. So after the attach, wanted_features still says "GRO on" while the feature is off.

Two things can go wrong because of that:

- The member is up with GRO on, then gets attached. veth_set_features() deletes the NAPIs. Later the member is set down and veth_close() deletes them a second time. napi_disable() then waits forever.

- The member is down with GRO on, gets attached, is set up, and is then detached while still up. veth_open() created the NAPIs, and the detach creates them again. That ends in the BUG_ON() in napi_enable().

The v7 selftests always attach and detach the member while it is up, so they did not see either case. I already replied to the bot with "pw-bot: cr", but by mistake under the patch 4 report.

My plan for v8: keep the persistent filter, but at the same place also clear GRO from the member's wanted_features. This is what netdev_sync_lower_features() does for the UPPER_DISABLES bits. Then requested and active GRO always agree, and veth does not need a change. The downside: after the member is detached, GRO stays off, and the user has to enable it again. LRO behaves the same way today.

If you or the other maintainers prefer that veth is fixed instead, so that it looks at the active feature, I can do that.

The Low one is only a comment problem. For stacked members (bond, macvlan, ...) GRO runs on the lower device, so "software GRO must be off before frames can arrive" is only true for direct members. Patch 3 segments any GSO input anyway. I will fix the comment.

Signature · 1 line
Xin
author
#11 lore raw

Re: [PATCH net v7 2/4] net: hsr: preserve submission order without a forwarding lock

In reply to Sebastian Andrzej Siewior
Quoted 5 lines

What are stacked HSR devices? Looking from the setup in the referenced report this is a bridge device attached to a HSR ring.
An announce frame is sent and this goes to hsr_dev_xmit(). This does not look like a normal setup. Is this something you use or is this something the bot came up with?

It is the setup from the syzbot report, not something we use. In that report the slave port of one HSR device is a bridge, and one bridge port is a second HSR device. The announce frame of the first device holds its seqnr_lock, goes through the bridge, and ends in hsr_dev_xmit() of the second device, which takes its own seqnr_lock. Lockdep sees the same lock class twice and reports it. With two devices this is not a real deadlock. It only becomes one when the transmit path comes back to the same device.

Quoted 2 lines

This looks very complex and I am not a big fan of it. I would prefer to break lock chain early assuming the setup is valid/ sane (see above).

I understand. The queue exists only for the ordering you pointed out in v6: frame N must reach every lower device before frame N+1 gets its number, otherwise a receiver without the bitmap discard (aae9d6b616b5) drops N as stale. In our test an unpatched HSRv0 peer received 19128 of 20000 frames with the narrowed lock, and all 20000 with the queue.

Quoted 5 lines

The ID by itself can be assigned with an atomic_inc() but then you don't have the transmit ordering. So you introduce the workqueue for the ordering which is ugh. I'm not sure how this works if you get submissions from two CPUs given the lock is gone and the workqueue is per-CPU.

The FIFO and the owner flag are protected by fwd_lock. Only one context owns the consumer at a time: either the CPU that found it idle and processes its own frame, or the single work item of this HSR device. A frame submitted from another CPU meanwhile is appended to the FIFO and processed after the current frame, in that order. The work item is one work_struct per device, so the per-CPU workqueue cannot run it twice at the same time. But I agree it is a lot of code for this, and it also serializes all forwarding of one device, like the lock does today.

So for v8 I see two simple options:
(a) Keep seqnr_lock across the submission like today and only break the re-entry: a frame that enters HSR transmit while this CPU is already inside HSR forwarding is dropped and counted. Ordering is kept, but all forwarding of one device stays serialized.
(b) Narrow the lock to the counter update, as in v6 and in Hangbin's patch [1]. Several CPUs can forward in parallel. A receiver without the bitmap discard can drop a reordered frame, so the patch would carry "Cc: <[email protected]> # aae9d6b616b5: ..." as Simon suggested there, and the TX statistics move to per-CPU counters.

I would prefer (b) because of the parallel forwarding, if the old receiver limitation is acceptable to you. Otherwise (a).

Hangbin, Simon, your view is welcome too.

Patch 3 works with both: it segments before the lock, and each segment is numbered and submitted under the lock.

[1] https://lore.kernel.org/netdev/[email protected]/

Signature · 1 line
Xin
author
#17 lore raw

Re: [PATCH net v7 3/4] net: hsr: segment GSO before per-frame forwarding

In reply to Sebastian Andrzej Siewior
Quoted 3 lines

I've been re-reading the old mails. The whole thing is needed for GSO when it can not be disabled, right? And VETH interface has been named as an example.

Not only. GRO can be disabled, and patch 1 does that. Patch 3 is for GSO skbs that arrive without any GRO. The case is the one from the cover letter: a software PRP RedBox on a Linux host, with containers or VMs on the SAN side and two NICs for the PRP LANs.

  container/netns                  host PRP RedBox
  prp0-peer ---- veth ---- prp0-int (interlink RX)
                                  |
                           split GSO into frames
                                  |
                           sequence number + RCT
                              /          \
                           LAN A        LAN B

When the container sends a large TCP or UDP skb, veth hands it to prp0-int as one GSO skb. Nothing on that path segments it, and GRO on prp0-int plays no role. The same happens with virtio or tap. PRP must give every wire frame its own sequence number and RCT, so patch 3 splits the skb before that. A NIC with GRO_HW that cannot be switched off is the second case. Local traffic from the HSR master is handled by removing the GSO features, so the core segments it before ndo_start_xmit().

Quoted 3 lines

There was also a bridge device. With HSR you form a ring. With a bridge you attach other (physical) devices within the ring. This does not sound like real life use-case. Do I miss something?

The bridge only came up in the v6 discussion as a comparison: when a bridge forwards a GSO skb to a physical port, the TX path segments it, but it cannot add a PRP RCT and sequence number to each segment. We do not use a bridge inside the ring.

Signature · 1 line
Xin
#12 lore raw

Re: [PATCH net v7 2/4] net: hsr: preserve submission order without a forwarding lock

In reply to Xin Xie
Quoted 5 lines · Xin Xie
Quoted 5 lines

What are stacked HSR devices? Looking from the setup in the referenced report this is a bridge device attached to a HSR ring.
An announce frame is sent and this goes to hsr_dev_xmit(). This does not look like a normal setup. Is this something you use or is this something the bot came up with?

Quoted 8 lines

It is the setup from the syzbot report, not something we use. In that report the slave port of one HSR device is a bridge, and one bridge port is a second HSR device. The announce frame of the first device holds its seqnr_lock, goes through the bridge, and ends in hsr_dev_xmit() of the second device, which takes its own seqnr_lock. Lockdep sees the same lock class twice and reports it. With two devices this is not a real deadlock. It only becomes one when the transmit path comes back to the same device.

Okay. In that case, could you please teach HSR to reject bridge ports at the very least?

Given that HSR is a ring and PRP faces two networks, I don't think a bridge setup would make sense here. So rejecting this should be any easy fix.

…

Quoted 11 lines

So for v8 I see two simple options:
(a) Keep seqnr_lock across the submission like today and only break the re-entry: a frame that enters HSR transmit while this CPU is already inside HSR forwarding is dropped and counted. Ordering is kept, but all forwarding of one device stays serialized.
(b) Narrow the lock to the counter update, as in v6 and in Hangbin's patch [1]. Several CPUs can forward in parallel. A receiver without the bitmap discard can drop a reordered frame, so the patch would carry "Cc: <[email protected]> # aae9d6b616b5: ..." as Simon suggested there, and the TX statistics move to per-CPU counters.

Quoted 7 lines

I would prefer (b) because of the parallel forwarding, if the old receiver limitation is acceptable to you. Otherwise (a).

Hangbin, Simon, your view is welcome too.

Patch 3 works with both: it segments before the lock, and each segment is numbered and submitted under the lock.

Or (c) tell HSR to reject bridge ports. This should avoid the case and the problem.

Sebastian

author
#13 lore raw

Re: [PATCH net v7 2/4] net: hsr: preserve submission order without a forwarding lock

Quoted 6 lines · Sebastian Andrzej Siewior

Okay. In that case, could you please teach HSR to reject bridge ports at the very least?

Given that HSR is a ring and PRP faces two networks, I don't think a bridge setup would make sense here. So rejecting this should be any easy fix.

Yes. The same chain also exists with a bond or team device as the port, and with a macvlan or ipvlan whose lower device is an HSR master. So I will make the check "a port must not have lower devices", for slave A/B and for the interlink. A physical NIC or a veth passes; bridge, bond, team, macvlan and ipvlan are refused. The only real setup this excludes is a bridge used directly as the interlink; a veth into that bridge still works.

Quoted 2 lines

Or (c) tell HSR to reject bridge ports. This should avoid the case and the problem.

Nobody else has commented in the meantime, so I will go with your suggestion. In v8 the lock stays as it is today, and patch 2 becomes the port check with the syzbot Reported-by. Narrowing the lock can be a separate change later, outside this fix series. Patch 3 then segments before taking seqnr_lock and numbers each segment under it.

Hangbin, you dropped your patch in August because this series covered the same place. With this the syzbot report is closed by the port check, and narrowing seqnr_lock becomes a separate change. If you want to pick your patch up again for that, I have no objection; the stable prerequisite tag Simon suggested and the per-CPU TX counters would then belong there.

One case the check cannot see is a tunnel device used as a port whose route goes over the HSR master itself. I would leave that alone unless you want the re-entry guard from (a) as well.

Signature · 1 line
Xin
#14 lore raw

Re: [PATCH net v7 2/4] net: hsr: preserve submission order without a forwarding lock

Quoted 8 lines · Xin Xie
Quoted 6 lines · Sebastian Andrzej Siewior

Okay. In that case, could you please teach HSR to reject bridge ports at the very least?

Given that HSR is a ring and PRP faces two networks, I don't think a bridge setup would make sense here. So rejecting this should be any easy fix.

Quoted 7 lines

Yes. The same chain also exists with a bond or team device as the port, and with a macvlan or ipvlan whose lower device is an HSR master. So I will make the check "a port must not have lower devices", for slave A/B and for the interlink. A physical NIC or a veth passes; bridge, bond, team, macvlan and ipvlan are refused. The only real setup this excludes is a bridge used directly as the interlink; a veth into that bridge still works.

Thanks. Sounds good. veth is needed for testing ;)

Quoted 8 lines
Quoted 2 lines

Or (c) tell HSR to reject bridge ports. This should avoid the case and the problem.

Nobody else has commented in the meantime, so I will go with your suggestion. In v8 the lock stays as it is today, and patch 2 becomes the port check with the syzbot Reported-by. Narrowing the lock can be a separate change later, outside this fix series. Patch 3 then segments before taking seqnr_lock and numbers each segment under it.

I will look at it once it gets there.

Sebastian

maintainer
#5 lore raw

Re: [PATCH net v7 1/4] net: hsr: keep GRO disabled on HSR/PRP ports

In reply to Xin Xie
Quoted 15 lines · Xin Xie

HSR/PRP add tags and sequence numbers per wire frame. GRO can merge plain interlink traffic before those fields are added, and userspace can re-enable GRO after the port is attached.

Mark slave A/B and interlink devices with a kernel role bit. Filter software GRO and configurable GRO_HW requests before ndo_fix_features() without changing wanted_features. Filtering before the driver keeps feature dependencies intact; fixed-on or driver-required GRO_HW is left enabled.

Apply the policy before registering the RX handler and reject attach if software GRO remains enabled. On failure or detach, unlink the upper before clearing the role and recomputing features, restoring the user's last request.

Quoted 5 lines

GSO skbs may still arrive. A later patch segments valid GSO before HSR/PRP processing.

Fixes 5055cccfc2d1 ("net: hsr: Provide RedBox support (HSR-SAN)")

I don't agree with the goal of this patch. The kernel allows a very large number of bad configuration. Explicitly preventing one of them may lead to regressions and leaves the lower device in an inconsistent state.

Please drop this patch.

/P

author
#6 lore raw

Re: [PATCH net v7 1/4] net: hsr: keep GRO disabled on HSR/PRP ports

Quoted 9 lines · Paolo Abeni

I don't agree with the goal of this patch. The kernel allows a very large number of bad configuration. Explicitly preventing one of them may lead to regressions and leaves the lower device in an inconsistent state.

Please drop this patch.

/P

Thanks, understood, and I agree. The patch is still 1/4 in v10; v11 will not have it. The macvlan GRO check in v10 2/4 and the selftest cases for the GRO policy depend on it and go as well.

The segmentation patch splits GSO input on every port, so aggregates from a port with GRO on are still forwarded frame by frame.

Keeping GRO off on the ports is then a configuration matter. I am working on a userspace configuration tool for HSR/PRP setups, which can take care of settings like this one.

Signature · 1 line
Xin