Skip to contentSkip to conversation

net: hsr: fix super-packet forwarding

PATCH Superseded Xin Xie 3 participants 12 messages Nov 12 – Nov 16

Subsystems (6)

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Xin Xie

author
#0 lore raw

v9 cover net: hsr: fix super-packet forwarding

HSR and PRP tag, number and de-duplicate each frame on the wire. GRO and GSO can hand them one skb holding several frames, which the lower device then drops or which goes out with a single tag or RCT and sequence number.

Patch 1 keeps software GRO off on HSR/PRP ports. GRO_HW that the driver keeps on is left alone.

Patch 2 refuses bridge, bond, team and OVS masters as ports, a macvlan or MACsec device on top of a bridge, bond, team or HSR/PRP master, and devices that already have a master or cannot take an RX handler. This fixes the syzbot recursive seqnr_lock report, as Sebastian suggested [1].

A port check cannot catch every path back into an HSR master, such as a tc/BPF redirect or a tunnel; those still nest the lock and can deadlock on the same device. Fixing them without dropping traffic needs seqnr_lock released before the port transmit, which can reorder frames for receivers without aae9d6b616b5 ("hsr: Implement more robust duplicate discard for HSR"). That is left to net-next, where Hangbin's patch [2] fits. He dropped it in favor of this series [3]; as this series no longer narrows seqnr_lock, it can go ahead there.

Patch 3 segments GSO skbs before per-frame processing, outside seqnr_lock. GSO reaches an HSR/PRP port even with GRO off, typically from a container attached to a PRP RedBox interlink through veth:

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

Some old Linux PRP senders put one RCT on a whole GSO skb; patch 3 drops such aggregates when it can detect them. With GRO_HW off on virtio-net, the host may segment them first and the RCT arrives as payload; upgrade the sender or disable GSO and TSO on its HSR/PRP master.

Patch 4 adds selftests.

Tested on a lockdep kernel: the new selftests (also with Python 3.9) and the existing hsr selftests pass, and the syzbot reproducer no longer reports recursive locking. No new W=1 warnings.

No stable backport is requested. The remaining HSR dev->stats races are left to a separate series, as Paolo suggested [4].

Based on net 30c71476d842; also applies to net-next. Patch 3 conflicts with Sebastian's pending net-next series [5]; its notes give the resolution.

Changes since v8:
- Patch 1: the message and comments say which ports the rule covers.
- Patch 2: macvlan and MACsec are refused only on top of a bridge, bond, team or HSR/PRP master; all ports are checked before any is changed.
- Patch 3: copy a head shared with a clone before segmenting.
- Patch 4: no fixed sleep, no need for iproute2 to print the HSR version, new refusal cases.

[1] https://lore.kernel.org/netdev/[email protected]/
[2] https://lore.kernel.org/netdev/[email protected]/
[3] https://lore.kernel.org/netdev/anXnxn-PBv8qH6VB@fedora/
[4] https://lore.kernel.org/netdev/[email protected]/
[5] https://lore.kernel.org/netdev/[email protected]/

v8: https://lore.kernel.org/netdev/[email protected]/
v7: https://lore.kernel.org/netdev/[email protected]/
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: refuse forwarding devices as HSR/PRP ports
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                     |    8 +
 net/core/dev.c                                |   15 +
 net/hsr/hsr_device.c                          |   13 +-
 net/hsr/hsr_forward.c                         |  158 ++
 net/hsr/hsr_forward.h                         |    1 +
 net/hsr/hsr_slave.c                           |  145 +-
 net/hsr/hsr_slave.h                           |    2 +
 tools/testing/selftests/net/hsr/Makefile      |    7 +-
 tools/testing/selftests/net/hsr/config        |   10 +
 .../selftests/net/hsr/hsr_gro_superpacket.py  | 1456 +++++++++++++++++
 .../selftests/net/hsr/hsr_gro_superpacket.sh  |    9 +
 .../net/hsr/hsr_ordered_forwarding.sh         |    9 +
 13 files changed, 1819 insertions(+), 15 deletions(-)
 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: 30c71476d842b094651bd7712f6c8ee8716147d0

Signature · 1 line
2.53.0
author
#1 lore raw

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

HSR and PRP tag and de-duplicate each wire frame separately. GRO on a member device merges several frames into one skb that cannot get valid per-frame metadata, and userspace can turn GRO back on at any time.

Mark direct members (slave A/B, interlink) with a kernel role bit. While it is set, __netdev_update_features() drops software GRO and configurable GRO_HW from wanted_features as well as from the computed features, before ndo_fix_features(). GRO_HW that the driver keeps on is left alone. The request has to go too: veth adds and deletes its NAPI instances according to wanted_features, so with GRO still requested, closing an attached veth spins in napi_disable(), and detaching a veth that was attached while down and then brought up hits the BUG_ON() in napi_enable(). As for LRO disabled by an upper device, GRO is not restored when the port leaves; ethtool can turn it back on. The rule covers every direct member, PRP ports and ports with HSR offload included: one simple rule is preferred to per-port exceptions, at some cost in receive throughput.

The attach fails if software GRO stays active. A failed attach does not restore the GRO request either. The next patch checks all ports before any of them is changed, so only a failure at run time, for example a driver that cannot turn GRO off or the upper device nesting limit (-EMLINK), leaves a port with its GRO request dropped. GSO skbs can still arrive, for example from a stacked member whose lower device runs GRO; a later patch segments them.

Fixes 5055cccfc2d1 ("net: hsr: Provide RedBox support (HSR-SAN)")
---
 .../networking/net_cachelines/net_device.rst  |  1 +
 include/linux/netdevice.h                     |  8 +++
 net/core/dev.c                                | 15 ++++++
 net/hsr/hsr_slave.c                           | 54 +++++++++++++++++++
 4 files changed, 78 insertions(+)
Documentation/networking/net_cachelines/net_device.rst +1 -0
index 8eceaa80b686..0d87e4d92a58 100644
@@ -169,6 +169,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 +8 -0
index 435be7880d7e..0d13c7ecdd1f 100644
@@ -2110,6 +2110,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
@@ -2531,6 +2532,13 @@ 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. While set,
+	 * software GRO and configurable GRO_HW are dropped from the
+	 * request and before ndo_fix_features(); GRO_HW that the driver
+	 * keeps on is left alone. 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 +15 -0
index df1a840b0334..c8c2de212556 100644
@@ -11269,6 +11269,21 @@ int __netdev_update_features(struct net_device *dev)
 
 	features = netdev_get_wanted_features(dev);
 
+	/* A direct HSR/PRP port needs per-frame metadata. Drop software
+	 * GRO and configurable GRO_HW from the request as well as from the
+	 * features passed to ndo_fix_features(), as the core does for
+	 * upper-disabled features: drivers such as veth derive state from
+	 * wanted_features and need the requested and the active bit to
+	 * agree. Fixed-on or driver-required GRO_HW is left to the driver.
+	 */
+	if (dev->hsr_port) {
+		netdev_features_t gro = NETIF_F_GRO |
+					(dev->hw_features & NETIF_F_GRO_HW);
+
+		dev->wanted_features &= ~gro;
+		features &= ~gro;
+	}
+
 	if (dev->netdev_ops->ndo_fix_features)
 		features = dev->netdev_ops->ndo_fix_features(dev, features);
 
net/hsr/hsr_slave.c +54 -0

85 lines not on this page · raw message

Signature · 1 line
2.53.0
#2 lore raw

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

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The patch puts HSR-specific policy into the generic core function __netdev_update_features() in net/core/dev.c (lines 11279-11285):…

--

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

This commit adds an hsr_port bit to struct net_device. HSR sets the bit on its direct members (slave A/B and interlink). While the bit is set, __netdev_update_features() clears NETIF_F_GRO and configurable NETIF_F_GRO_HW from both wanted_features and the computed features, and an attach fails if software GRO stays on.

Quoted 12 lines
net/core/dev.c +4 -0
index df1a840b03343..c8c2de2125567 100644
@@ -11269,6 +11269,21 @@ int __netdev_update_features(struct net_device *dev)
 
 	features = netdev_get_wanted_features(dev);
 
+	/* A direct HSR/PRP port needs per-frame metadata. Drop software
+	 * GRO and configurable GRO_HW from the request as well as from the
+	 * features passed to ndo_fix_features(), as the core does for
+	 * upper-disabled features: drivers such as veth derive state from

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

Quoted 10 lines
net/core/dev.c +10 -0
+	 * wanted_features and need the requested and the active bit to
+	 * agree. Fixed-on or driver-required GRO_HW is left to the driver.
+	 */
+	if (dev->hsr_port) {
+		netdev_features_t gro = NETIF_F_GRO |
+					(dev->hw_features & NETIF_F_GRO_HW);
+
+		dev->wanted_features &= ~gro;
+		features &= ~gro;
+	}

[Severity: Low]

The comment says this follows what "the core does for upper-disabled features". Is that right?

netdev_sync_upper_features() runs inside the lower device's own update. It masks only the computed features and does not touch the request:

    if (!(upper->wanted_features & feature)
        && (features & feature)) {
        ...
        features &= ~feature;
    }

Only netdev_sync_lower_features() clears lower->wanted_features, and it does that once, when the upper device turns the feature off. In this patch, the request is cleared inside the same update that is supposed to apply it.

Can this make the legacy ETHTOOL_SFEATURES ioctl report success for a GRO request that was never applied? ethtool_set_features() sets wanted_features and then runs:

net/ethtool/ioctl.c:ethtool_set_features() {
    ...
	__netdev_update_features(dev);

	if ((dev->wanted_features ^ dev->features) & valid)
		ret |= ETHTOOL_F_WISH;
    ...
}

When hsr_port is set, GRO is already gone from both wanted_features and features when the XOR runs. So ETHTOOL_F_WISH is not set for GRO, and the ioctl reports full success while GRO stays off. A later ethtool -k shows GRO off without the "[requested on]" marker.

Compare LRO disabled by an upper device: there the request stays in wanted_features and ETHTOOL_F_WISH is returned. The netlink path, ethnl_set_features(), still reports the mismatch, because it compares against its local req_wanted copy.

The comment on the new struct net_device field also says "Kernel role state only; no user ABI", but the field changes behaviour that ethtool users can see. It also puts HSR-specific policy into the generic __netdev_update_features() under a "net: hsr:" subject. Later patches in the series do not touch net/core/dev.c, so this is still the case at the end of the series.

Would it work to mask only the computed features here, the way netdev_sync_upper_features() does? Or, if the request has to be cleared for veth, could the comment stop citing the upper-disable path as the model and mention the ETHTOOL_F_WISH change?

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

PATCH v9 2/4 net: hsr: refuse forwarding devices as HSR/PRP ports

In reply to Xin Xie

syzbot reported recursive locking with an HSR device whose slave is a bridge, and that bridge has the master of a second HSR device as a port. The first device transmits its supervision frames with its seqnr_lock held; the bridge floods them to the second HSR master, whose hsr_dev_xmit() takes the seqnr_lock of that device:

WARNING: possible recursive locking detected
...

   hsr_dev_xmit+0x18a/0x210 net/hsr/hsr_device.c:234
   ...
   br_dev_xmit+0x1202/0x1b40
   ...
   hsr_forward_skb+0x171c/0x2ac0 net/hsr/hsr_forward.c:728
   send_hsr_supervision_frame+0x63b/0xcc0 net/hsr/hsr_device.c:351
   hsr_announce+0x1f8/0x3a0 net/hsr/hsr_device.c:408

Interlink RX forwards to the slaves with the same lock held. A chain of two devices does not deadlock, but such a port makes no sense: an HSR ring and the two PRP LANs are attached to the node directly.

Refuse bridge and OVS masters and bond and team masters (also without ports, since ports can be added later) as slave or interlink, and a macvlan or MACsec device when an HSR/PRP, bridge, bond or team master is below it; on an ordinary NIC or veth such a device stays valid. This also refuses one on a DSA user port whose conduit is a bond or team, since it can gain ports later too. A macvlan takes its GRO setting from its lower device, so it is accepted only if GRO is off there when it is attached. The lower devices of other ports are not checked, because a DSA user port is an upper of its conduit and can offload HSR. VLAN devices are already refused. The check runs at attach; later changes below a stacked device are not rechecked. Not covered are a tunnel whose route leads back through the HSR master, a tc or BPF redirect to it, other stacked devices, and a software device without an identifying flag such as batman-adv. Narrowing seqnr_lock, planned for net-next, addresses that class as a whole.

Also refuse a device whose RX handler is in use or not supported (IFF_NO_RX_HANDLER: ipvlan, VRF), or that already has a master, such as a VRF port, with an extack message and the same error codes. All ports are checked before any of them is changed. Some of these devices, such as a macvlan lower, ipvlan or VRF, used to fail only in netdev_rx_handler_register(), after the previous patch had dropped their GRO request; a refused device now keeps its state, and so do the ports given with it.

A bridge can no longer be used directly as the interlink; connect it through a veth pair.

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/hsr_device.c |  7 ++++
 net/hsr/hsr_slave.c  | 79 ++++++++++++++++++++++++++++++++++++++++++--
 net/hsr/hsr_slave.h  |  2 ++
 3 files changed, 86 insertions(+), 2 deletions(-)
net/hsr/hsr_device.c +7 -0
index fc512204600c..90ee55eb3c19 100644
@@ -758,6 +758,13 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],
 	INIT_LIST_HEAD(&hsr->proxy_node_db);
 	spin_lock_init(&hsr->list_lock);
 
+	/* Refuse a bad port before any port is changed. The same checks
+	 * in hsr_add_port() remain as a safety net.
+	 */
+	res = hsr_check_ports(slave, interlink, extack);
+	if (res)
+		return res;
+
 	eth_hw_addr_set(hsr_dev, slave[0]->dev_addr);
 
 	/* initialize protocol specific functions */
net/hsr/hsr_slave.c +77 -2

108 lines not on this page · raw message

net/hsr/hsr_slave.h +2 -0
index edc4612bb009..e19c779b500d 100644
@@ -14,6 +14,8 @@
 #include <linux/rtnetlink.h>
 #include "hsr_main.h"
 
+int hsr_check_ports(struct net_device *slave[2], struct net_device *interlink,
+		    struct netlink_ext_ack *extack);
 int hsr_add_port(struct hsr_priv *hsr, struct net_device *dev,
 		 enum hsr_port_type pt, struct netlink_ext_ack *extack);
 void hsr_del_port(struct hsr_port *port);
Signature · 1 line
2.53.0
#4 lore raw

Re: [PATCH net v9 2/4] net: hsr: refuse forwarding devices as HSR/PRP ports

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

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

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

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).

- [High] The patch is meant to stop recursive seqnr_lock acquisition from the HSR transmit path, but it only refuses a list of device types as…

--

net: hsr: refuse forwarding devices as HSR/PRP ports

This patch stops bridge, OVS, bond and team masters from being used as HSR/PRP slave or interlink ports. It also refuses macvlan or MACsec devices that sit on top of such masters or on top of an HSR master. It adds checks for a busy or unsupported RX handler and for an existing master, and hsr_dev_finalize() now checks every port before changing any of them.

Quoted 4 lines
net/hsr/hsr_slave.c +0 -0
index b7765a4bb9920..666220b24dee4 100644

[ ... ]

Quoted 9 lines
net/hsr/hsr_slave.c +3 -2
@@ -131,13 +163,56 @@ static int hsr_check_dev_ok(struct net_device *dev,
 		return -EOPNOTSUPP;
 	}
 
-	/* HSR over bonded devices has not been tested, but I'm not sure it
-	 * won't work...
+	/* Forwarding devices feed HSR frames into another device's
+	 * transmit path and can nest seqnr_lock through a second HSR
+	 * device. A bridge, bond, team or OVS master makes no sense as a

net/hsr/hsr_slave.c static int hsr_check_dev_ok(struct net_device *dev, · line 178

Quoted 10 lines
net/hsr/hsr_slave.c +10 -0
+	 * ring or LAN port and is refused by type. A macvlan or MACsec
+	 * device is refused if such a master or an HSR/PRP master is
+	 * below it. Other devices keep their lower devices unchecked:
+	 * DSA user ports are uppers of their conduit.
+	 */
+	if (netif_is_any_bridge_master(dev) || netif_is_lag_master(dev)) {
+		NL_SET_ERR_MSG_MOD(extack,
+				   "Cannot use a bridge, bond, team or OVS master as HSR port.");
+		return -EINVAL;
+	}

[Severity: High]
If a routed L2 tunnel is used as a slave, can its transmit path come back into the same HSR master while seqnr_lock is still held?

A gretap, VXLAN or Geneve device is ARPHRD_ETHER with ETH_ALEN. It has no rx_handler and no master. It is not a VLAN, bridge, LAG, macvlan or MACsec device, so it passes every check in hsr_check_dev_ok().

Suppose the tunnel's remote address, or its ARP, is routed through hsr0, for example because hsr0 has an address on the remote's subnet. Then the announce timer alone looks like enough to trigger it:

hsr_announce()
send_hsr_supervision_frame()

    spin_lock_bh(&hsr->seqnr_lock);
    hsr_forward_skb()
      hsr_xmit()
        dev_queue_xmit(gretap0)
          gre_tap_xmit()
            ip_tunnel_xmit()
              iptunnel_xmit()
                ip_local_out()
                  ip_finish_output2()
                    dev_queue_xmit(hsr0)
                      hsr_dev_xmit()
                        spin_lock_bh(&hsr->seqnr_lock);

ip_tunnel_xmit() only rejects a route that goes back through the tunnel device itself:

net/ipv4/ip_tunnel.c:ip_tunnel_xmit() {
    ...
	if (rt->dst.dev == dev) {
		ip_rt_put(rt);
		DEV_STATS_INC(dev, collisions);
		goto tx_error;
	}
    ...
}

hsr_dev_setup() sets IFF_NO_QUEUE and lltx on hsr0, so __dev_queue_xmit() takes the no-qdisc path. netif_tx_owned() does not see the recursion, because xmit_lock_owner is not set for lltx devices. dev_xmit_recursion() is also far below XMIT_RECURSION_LIMIT at this depth.

In the syzbot report the two locks belonged to two different HSR devices. Here both belong to the same HSR device. So instead of a lockdep warning, this looks like the CPU deadlocking on a seqnr_lock it already holds, with BH disabled. User traffic through hsr_dev_xmit() would follow the same path. A user with CAP_NET_ADMIN in a user namespace can create both the HSR and the gretap links.

The commit message says this case is not handled:

Not covered are a tunnel whose route leads back through the HSR master, a tc or BPF redirect to it, other stacked devices, and a software device without an identifying flag such as batman-adv. Narrowing seqnr_lock, planned for net-next, addresses that class as a whole.

This patch has Fixes: tags for the commits that added the seqnr_lock coverage. Would narrowing seqnr_lock be a better fix here than a list of refused device types that will have to be replaced later anyway?

At the end of the series, after "net: hsr: segment GSO before per-frame forwarding", hsr_forward_frame() in net/hsr/hsr_forward.c still holds the lock around forwarding:

	if (numbered)
		spin_lock_bh(&hsr->seqnr_lock);
	hsr_forward_skb(skb, port);
	if (numbered)
		spin_unlock_bh(&hsr->seqnr_lock);

Both supervision senders also still hold seqnr_lock across hsr_forward_skb(). So this recursion still seems reachable after the full series.

[ ... ]

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

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

In reply to Xin Xie

HSR and PRP tag and de-duplicate each wire frame separately. A GSO super-packet reaching the forwarding path hides several wire frames, which cannot be tagged or numbered per frame. Such skbs reach a member even with GRO off, for example from a container or VM attached through veth, tap or virtio to a software RedBox, or from a member whose GRO_HW cannot be turned off.

Add one forwarding entry, hsr_forward_input(), for master TX and for frames received on any port. It segments GSO input outside seqnr_lock; each segment is then numbered and submitted under the lock, one frame at a time as before, and follows the normal forwarding and local delivery paths. Master TX and interlink RX now take the lock there instead of in their callers.

Classify by the effective inner protocol with the core's bounded VLAN decoder (802.1Q, 802.1AD, nested or accelerated). Drop aggregates with inner HSR/PRP, unreadable fragments or undecodable headers, and IPv4 or IPv6 aggregates whose nonzero IP length ends before the skb does, since the trailing bytes would become segment payload. GSO_PARTIAL and zero IP lengths are left to the segmenter. Drops are counted once on the entry device in the core per-CPU drop counters. Segmentation writes the control block, the headers and the L4 checksum, so a still-shared input is unshared first, and a head still shared with a clone, for example from a packet socket, is copied.

Older HSR and PRP senders can pass a whole GSO skb with one tag or one RCT, for example over tap or virtio. Such aggregates, including locally destined ones, are now dropped instead of being delivered.

Remove the NETIF_F_GSO_MASK types from the master's hw_features so the core segments local traffic before ndo_start_xmit(). This also holds over ports with HSR tag insertion offload, at some cost in performance.

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

---
Integration with net-next: Sebastian's pending series "hsr: Allow to send packets on specific port and pass the timestamp" (v10) changes hsr_forward_skb() to take the requested TX port and a has_hsr_header flag, and keeps seqnr_lock in hsr_dev_xmit() and in the interlink path of hsr_handle_frame(). With both series:
- keep v10's PTP header parsing in hsr_dev_xmit(), then call hsr_forward_input(skb, master, req_tx_port, has_hsr_header) without taking seqnr_lock there;
- call hsr_forward_input(skb, port, HSR_PT_NONE, false) from hsr_handle_frame(), without the interlink lock;
- add both arguments to hsr_forward_input() and hsr_forward_frame() and pass them to hsr_forward_skb() for the skb and for each segment;
- keep both include sets in hsr_forward.c.
A frame with the PTP header is not GSO and takes the single-frame path under the lock, as in v10. A GSO input with the header is classified after the pull: with an HSR header it is dropped like any inner HSR/PRP aggregate, otherwise each segment keeps req_tx_port.
Checked: on net-next fa5196392691 with v10 applied, this series with the resolution builds without warnings, and on a lockdep kernel hsr_ptp.sh, the two tests of patch 4 and the existing hsr selftests pass.

 net/hsr/hsr_device.c  |   6 +-
 net/hsr/hsr_forward.c | 158 ++++++++++++++++++++++++++++++++++++++++++
 net/hsr/hsr_forward.h |   1 +
 net/hsr/hsr_slave.c   |  12 ++--
 4 files changed, 165 insertions(+), 12 deletions(-)
net/hsr/hsr_device.c +2 -4
index 90ee55eb3c19..5db71b49d08e 100644
@@ -232,9 +232,7 @@ static netdev_tx_t hsr_dev_xmit(struct sk_buff *skb, struct net_device *dev)
 		skb->dev = master->dev;
 		skb_reset_mac_header(skb);
 		skb_reset_mac_len(skb);
-		spin_lock_bh(&hsr->seqnr_lock);
-		hsr_forward_skb(skb, master);
-		spin_unlock_bh(&hsr->seqnr_lock);
+		hsr_forward_input(skb, master);
 	} else {
 		dev_core_stats_tx_dropped_inc(dev);
 		dev_kfree_skb_any(skb);
@@ -686,7 +684,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 +158 -0

167 lines not on this page · raw message

net/hsr/hsr_forward.h +1 -0
index 206636750b30..ec08c4330259 100644
@@ -14,6 +14,7 @@
 #include "hsr_main.h"
 
 void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port);
+void hsr_forward_input(struct sk_buff *skb, struct hsr_port *port);
 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_slave.c +4 -8
index 666220b24dee..7fe7fa68af9e 100644
@@ -76,15 +76,11 @@ 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.
+	 * sequence number and require synchronisation vs other sender;
+	 * hsr_forward_input() takes seqnr_lock for them, one frame at a
+	 * time.
 	 */
-	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_input(skb, port);
 
 finish_consume:
 	return RX_HANDLER_CONSUMED;
Signature · 1 line
2.53.0
#6 lore raw

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

Quoted 1 line · Xin Xie
(quoted diff) +0 -0
@@ -794,3 +797,158 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port)

…

Quoted 2 lines
(quoted diff) +2 -0
+void hsr_forward_input(struct sk_buff *skb, struct hsr_port *port)
+{

…

Review

Quoted 7 lines
(quoted diff) +7 -0
+	consume_skb(skb);
+	while (segs) {
+		next = segs->next;
+		segs->next = NULL;
+		hsr_forward_frame(segs, port);
+		segs = next;
+	}

Should you repost:

net/hsr/hsr_forward.c +2 -4
index 9aefc5f0249f6..5e49f2bb9e39b 100644
@@ -940,11 +940,9 @@ void hsr_forward_input(struct sk_buff *skb, struct hsr_port *port)
 		goto drop;
 
 	consume_skb(skb);
-	while (segs) {
-		next = segs->next;
-		segs->next = NULL;
+	skb_list_walk_safe(segs, segs, next) {
+		skb_mark_not_on_list(segs);
 		hsr_forward_frame(segs, port);
-		segs = next;
 	}
 	return;
 

Sebastian

author
#7 lore raw

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

Quoted 21 lines · Sebastian Andrzej Siewior

Should you repost:

net/hsr/hsr_forward.c +2 -4
index 9aefc5f0249f6..5e49f2bb9e39b 100644
@@ -940,11 +940,9 @@ void hsr_forward_input(struct sk_buff *skb, struct hsr_port *port)
 		goto drop;
 
 	consume_skb(skb);
-	while (segs) {
-		next = segs->next;
-		segs->next = NULL;
+	skb_list_walk_safe(segs, segs, next) {
+		skb_mark_not_on_list(segs);
 		hsr_forward_frame(segs, port);
-		segs = next;
 	}
 	return;
 
Quoted 1 line

Sebastian

Thanks for the review. I will switch the loop to skb_list_walk_safe() and skb_mark_not_on_list() if the series needs a repost.

Signature · 1 line
Xin
author
#8 lore raw

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

In reply to Xin Xie

Add two tests, run by shell entries that exec one installed Python helper.

hsr_gro_superpacket.sh checks the member GRO policy: GRO is off, requested and active, while a veth is a member and after it leaves, and can then be turned on again; a device refused at attach keeps its request. It covers close and reopen of an attached veth, a veth attached while down, the master's GSO type mask, a refused bridge port that leaves the port given before it unchanged, a busy macvlan lower, the refusal of bridge, bond and ipvlan devices, of a macvlan on a bridge or on a bond and of a VRF port without leaving an upper link or a promiscuity reference on any port, a macvlan whose lower device runs GRO that is refused as second port with the first port unchanged, and a macvlan on a veth without GRO that is accepted. Natural TCP from the interlink is compared byte for byte, retransmissions included, with both LAN captures. TCP from a SAN on one PRP LAN, in plain and VLAN forms, is compared the same way with the ingress LAN and the local delivery, and its reply must appear once on each LAN. Tags/RCT, sequence numbers and VLAN stacks are checked.

hsr_ordered_forwarding.sh checks local data around interlink data and UDP GSO aggregates, local and proxy supervision, two concurrent producers and an observed sequence-number wrap.

Work is bounded to 120 seconds and cleanup to 20; INT/TERM remove the test's namespaces. Packets are judged only on complete captures without socket loss or truncation. A missing prerequisite SKIPs the affected case; query errors and missing packet evidence FAIL, and the cases after a failure are reported as not ok.

---
 tools/testing/selftests/net/hsr/Makefile      |    7 +-
 tools/testing/selftests/net/hsr/config        |   10 +
 .../selftests/net/hsr/hsr_gro_superpacket.py  | 1456 +++++++++++++++++
 .../selftests/net/hsr/hsr_gro_superpacket.sh  |    9 +
 .../net/hsr/hsr_ordered_forwarding.sh         |    9 +
 5 files changed, 1490 insertions(+), 1 deletion(-)
 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 +6 -1
index 2150e487ac7d..70f8a804b44a 100644
@@ -3,6 +3,8 @@
 top_srcdir = ../../../../..
 
 TEST_PROGS := \
+	hsr_gro_superpacket.sh \
+	hsr_ordered_forwarding.sh \
 	hsr_ping.sh \
 	hsr_prp_redbox.sh \
 	hsr_redbox.sh \
@@ -10,6 +12,9 @@ TEST_PROGS := \
 	prp_ping.sh \
 # end of TEST_PROGS
 
-TEST_FILES += hsr_common.sh
+TEST_FILES += \
+	hsr_common.sh \
+	hsr_gro_superpacket.py \
+# end of TEST_FILES
 
 include ../../lib.mk
tools/testing/selftests/net/hsr/config +10 -0
index 205cc4d3d64b..d9463ae0025a 100644
@@ -1,6 +1,16 @@
+CONFIG_BONDING=y
 CONFIG_BRIDGE=y
 CONFIG_HSR=y
+CONFIG_INET=y
+CONFIG_IP_ADVANCED_ROUTER=y
+CONFIG_IP_MULTIPLE_TABLES=y
 CONFIG_IPV6=y
+CONFIG_IPV6_MULTIPLE_TABLES=y
+CONFIG_IPVLAN=y
+CONFIG_MACVLAN=y
+CONFIG_NET_L3_MASTER_DEV=y
 CONFIG_NET_SCH_NETEM=m
+CONFIG_NET_VRF=y
+CONFIG_PACKET=y
 CONFIG_VETH=y
 CONFIG_VLAN_8021Q=m
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +1456 -0

1,456 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
#9 lore raw

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

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

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

Critical: 0 · High: 0 · Medium: 1 · 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] In tcp_prp(), the check for 'no tag/RCT on local delivery' can never fail.
- [Low] The commit message overstates what the second refusal group in port_types() checks…
- [Low] In tcp_prp(), a Skip raised by verify_stream() bypasses the PRP reply checks.
- [Low] Lab.close() closes every owned socket (lines 367-368) before it joins the producer threads (lines 369-373).

--

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

This adds two HSR/PRP selftests, hsr_gro_superpacket.sh and hsr_ordered_forwarding.sh. Both exec one shared Python helper. The gro mode checks the member GRO policy, the refusal of unsupported port types, and byte-exact TCP forwarding over an HSR interlink and over PRP LANs. The ordered mode checks sequence ordering of local, interlink, supervision and concurrent traffic, including a sequence wrap.

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

[ ... ]

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

Quoted 11 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +11 -0
+    def close(self):
+        """Stop threads, close sockets and delete owned namespaces."""
+        self.stop.set()
+        end, errors = time.monotonic() + 20, []
+        for sock in self.sockets:
+            sock.close()
+        for thread in self.threads:
+            if thread.ident is not None:
+                thread.join(max(0, end - time.monotonic()))
+            if thread.is_alive():
+                errors.append("sender thread did not stop")

[Severity: Low]
This isn't a bug, but the docstring says "Stop threads, close sockets". Lab.close() closes the sockets before it joins the producer threads started by ordered_concurrent().

If a producer is still running here, its sendto() on the closed socket gets EBADF. Its except (OSError, ValueError, RuntimeError) clause catches that. The 1 second timeout from ordered_socket() and the lab.stop check limit how long it can run. The main thread opens no new fds until the join returns, so fd reuse does not look possible.

Would joining the threads before closing the sockets match the docstring order?

[ ... ]

Quoted 6 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +6 -0
+    # A refused second port leaves the first port as it was.
+    for dev in ("w", "g"):
+        local_pair(lab, ns, dev)
+    set_gro(lab, ns, "p", "on")
+    set_gro(lab, ns, "g", "on")
+    first, second = link_state(lab, ns, "p"), []

[ ... ]

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

Quoted 13 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +13 -0
+    for kind, dev, error in second:
+        label = f"{kind} as slave2"
+        result = lab.ip(ns, "link", "add", "name", "hsr0", "type", "hsr",
+                        "slave1", "p", "slave2", dev, "version", "1", check=False)
+        require(result.returncode != 0 and error in result.stderr,
+                f"{label}: missing refusal message: {result.stderr.strip()}")
+        require(lab.ip(ns, "link", "show", "dev", "hsr0", check=False).returncode,
+                label + ": HSR device left behind")
+        after = link_state(lab, ns, "p")
+        require("master" not in after and after["promiscuity"] == first["promiscuity"],
+                f"{label}: first port p changed by the refused attach")
+        gro_state(lab, ns, "p", "on", label + ": first port p")
+        refused.append(label)

[Severity: Low]
Does this second refusal group in port_types() check what the commit message describes? The message says:

... and of a VRF port without leaving an upper link or a promiscuity reference on any port ...

and:

... a device refused at attach keeps its request.

Only p is snapshotted here (first = link_state(lab, ns, "p")), and only p is compared after each refused attach. The refused VRF port w and the macvlan mvg have no baseline. Their promiscuity is never compared, and the GRO state of mvg is never read back.

The first refusal group snapshots every candidate device in before and checks each one again, so the two groups do not match. A leaked promiscuity reference on w or mvg would still pass this case.

Should w and mvg also go into the before/after comparison?

[ ... ]

Quoted 2 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +2 -0
+def tcp_prp(lab, row):
+    """TCP GSO from a SAN on one PRP LAN is delivered locally, segmented."""

[ ... ]

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

Quoted 2 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +2 -0
+    lab.cmd(tx, "ethtool", "-K", lower, "tso", "on", "gso", "on")
+    caps = [lab.capture(tx, lower, pkttype=4), lab.capture(dut, "pm", pkttype=0)]

[Severity: Medium]
Can the check for no tag/RCT on local delivery ever fail for this capture?

The pm capture is opened with the default prp=False. decode() only recognises a PRP RCT when prp is set:

    elif prp and end >= off + 6 and raw[-2:] == b"\x88\xfb":

So every frame captured on pm decodes with tag=False and encoding="plain". The TCP payload ends at the IPv4 total length, so 6 trailing RCT bytes are silently ignored.

verify_stream(..., local=True) then calls:

wire_rows(captures[1].rows, port, stack, tagged=False)

and this check in wire_rows() is always true here:

    require(row["tag"] == tagged, "flow tag/RCT missing or unexpected")

The size limit does not catch it either. A 1514 byte segment plus a 6 byte RCT is exactly 1520, which passes
row["size"] <= 1520 + 4 * len(stack).

Suppose the PRP master delivered frames locally with the RCT still attached. The IP stack would trim the trailer and TCP would still complete, so this case would pass. The commit message says "Tags/RCT, sequence numbers and VLAN stacks are checked".

Would opening the pm capture with prp=True make this check effective?

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

Quoted 5 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +5 -0
+    ingress = lab.capture(dut, "d" + side.lower(), prp=True)
+    lanes = [lab.capture(dut, dev, pkttype=4, prp=True) for dev in ("da", "db")]
+    payload, reply = tcp_transfer(lab, tx, dut, sender, "10.68.0.2", "10.68.0.1", 5201)
+    lab.finish(fin_seen(caps + lanes + [ingress], 5201))
+    verify_stream(caps, 5201, payload, stack, local=True, inband=inband, ingress=ingress)

[Severity: Low]
What happens to the PRP reply checks below when verify_stream() raises Skip? verify_stream() ends with:

if not aggregate:
raise Skip("no sender GSO aggregate observed")

The comment above it says this gap is reported only "after transfer and all other checks". In tcp_prp(), though, the reply checks run only after verify_stream() returns: exactly once per LAN, RCT present, LAN id 10 + index, encoding "prp", identical copies. Nothing here catches Skip, so main() prints "ok N - ... # SKIP".

When the sender capture shows no payload larger than 1500 bytes, a missing, duplicated or wrongly tagged PRP reply would be reported as SKIP, not FAIL. This seems to contradict "its reply must appear once on each LAN" in the commit message.

Could the Skip be held back until the reply checks in tcp_prp() have run?

Quoted 7 lines
tools/testing/selftests/net/hsr/hsr_gro_superpacket.py new file +7 -0
+    copies = []
+    for index, cap in enumerate(lanes):
+        cap.validate()
+        rows = [frame for frame in cap.rows if frame["ports"] and
+                frame["ports"][0] == 5201 and frame["payload"]]
+        require(len(rows) == 1 and rows[0]["payload"] == reply,
+                "PRP reply not exactly once per LAN")

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112153333.20-1-xiexinet%40gmail.com
#10 lore raw
In reply to Xin Xie
Quoted 4 lines · Xin Xie

HSR and PRP tag, number and de-duplicate each frame on the wire. GRO and GSO can hand them one skb holding several frames, which the lower device then drops or which goes out with a single tag or RCT and sequence number.

I did not forget you. Thanks for the repost. I try to handle it before Monday.

Sebastian

Reviewed-by on the v9 series
#11 lore raw
In reply to Xin Xie
Quoted 5 lines · Xin Xie

HSR and PRP tag, number and de-duplicate each frame on the wire. GRO and GSO can hand them one skb holding several frames, which the lower device then drops or which goes out with a single tag or RCT and sequence number.

…

Quoted 5 lines

Xin Xie (4):
net: hsr: keep GRO disabled on HSR/PRP ports
net: hsr: refuse forwarding devices as HSR/PRP ports
net: hsr: segment GSO before per-frame forwarding
selftests: net: hsr: verify GRO policy and ordered forwarding

The test covers the aggregated frames which are unfolded which is nice. It looks good from what I can tell.

Sebastian