net: hsr: fix GRO/GSO super-packet handling
Subsystems (5)
v5 cover net: hsr: fix GRO/GSO super-packet handling
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.
Patch 1 adds netif_disable_gro()/dev_disable_gro() and disables GRO and GRO_HW on lower devices at HSR/PRP enslavement time, mirroring the existing LRO treatment. Disabling is explicitly
best-effort: a later privileged override can re-enable GRO, and devices with fixed-on GRO_HW (for example a virtio-net device negotiating guest TSO without VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) cannot be forced off, so enslavement succeeds whether or not the feature could be cleared.
Patch 2 shrinks hsr->seqnr_lock from whole hsr_forward_skb() calls to the sequence counter updates, so the segmentation work of patch 3 never runs under the global sequence lock. The outer lock also incidentally serialized the tx statistics updates in hsr_forward_skb(); those now use the atomic DEV_STATS_* helpers.
Patch 3 unfolds GSO super-packets at the forward entry with the top-level GSO dispatch (__skb_gso_segment()), so each wire frame gets its own tag/RCT and sequence number. Admission is decided by a content-based classifier, not by the ingress port: plain-Ethernet aggregates are segmented on every ingress role (master, interlink, and LAN slaves), while aggregates whose effective protocol is ETH_P_HSR or ETH_P_PRP carry per-frame trailers that software segmentation cannot reconstruct and are dropped. The classifier unwraps accelerated VLAN and one in-band VLAN level, and treats NETIF_F_HW_HSR_TAG_RM lowers as plain by construction. The trailer-free premise of the plain-aggregate path is proven for in-tree software GRO: its IPv4 and IPv6 length checks reject frames with trailing bytes beyond the L3 length, so an RCT-bearing PRP frame is not merged. Device-specific fixed-on GRO_HW output is not claimed to be completely covered. Locally destined segments are delivered to the host; the rest are forwarded per frame.
Patch 4 adds a kselftest covering the series, including a LAN-slave plain-GSO regression: a plain SAN aggregate entering a PRP LAN slave must be segmented, with local delivery and per-frame arrival proven by independent counter oracles.
Patch 1 is a safe, partial, best-effort mitigation and is independently stable-selectable; patch 3, named by subject in its message, is the fallback for plain, trailer-free GSO aggregates. Patch 3 depends on patch 2, and patches 2 and 3 are selected for stable only on 7.0 and newer, where sparse-bitmap duplicate discard accepts out-of-order arrival. Older branches need adapted backports.
Validation:
* the v5 kernel builds cleanly;
* LAN-slave plain-GSO regression: the same frozen script fails on the v4 kernel (the early slave-port drop collapses the stream into retransmit-only single segments) and passes on the v5 kernel:
aggregates arrive at the PRP master and are delivered per-frame;
* fixed-on GRO_HW: with a virtio guest negotiating TSO without VIRTIO_NET_F_CTRL_GUEST_OFFLOADS (rx-gro-hw on [fixed]), HSR setup succeeds on both kernels; the v4 kernel emits
"failed to disable GRO!" and the v5 kernel does not;
* the interlink super-packet test and hsr_ping, hsr_redbox, link_faults and prp_ping all pass;
* the series applies cleanly with plain git am on current net.
Note on the contest report: this series conflicts with our own PRP RedBox support now merged in net-next
(https://lore.kernel.org/netdev/[email protected]/).
On current net it applies cleanly (re-verified by a full-series git am). For net-next the conflict is confined to two sites:
1. net/hsr/hsr_device.c, send_prp_supervision_frame(): net-next added the PRP RedBox Type-30 TLV and EOT construction where patch 2/4 shrinks the seqnr_lock critical section. Resolution:
keep the lock release immediately after the sup_sequence_nr update (as in this patch), build the whole TLV chain (LifeCheck payload, Type-30 RedBox-MAC TLV, EOT) unlocked, and drop the two stale unlocks from the padding-error and normal-exit paths.
2. tools/testing/selftests/net/hsr/Makefile: insert hsr_gro_superpacket.sh at its sorted position.
This resolution was applied and validated on the previous net-next (2fbade662450): the composed tree builds cleanly and hsr_prp_redbox.sh passes on the composed kernel.
---
Changes in v5:
Both v4 Sashiko reports (NIPA and Gemini) were reviewed in full. The two blocking findings are the patch 1 and patch 3 changes below; v5 also addresses the server-wait and message findings. The remaining reports concern pre-existing issues, intentional behavior, disproven claims, or non-blocking test/documentation suggestions.
- Patch 3: a plain GSO aggregate arriving on a LAN slave is no longer dropped. Admission now uses a content-based, VLAN/offload-aware classifier (hsr_gso_effective_proto()): plain aggregates are segmented on every ingress role, restoring local delivery and valid forwarding; only aggregates whose effective protocol is ETH_P_HSR or ETH_P_PRP are dropped as unrecoverable.
- Patch 1: the netdev_WARN() in netif_disable_gro() is removed. Devices with fixed-on GRO_HW (for example virtio-net guests without VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) no longer splat on ordinary HSR setup, and enslavement succeeds whether or not GRO could be disabled. The commit message states the best-effort contract and names patch 3 as the fallback
for plain, trailer-free GSO aggregates; Ali's Reviewed-by and Tested-by from the v3 thread are not carried since the payload changed.
- Patch 4: adds the LAN-slave plain-GSO regression and bounds the iperf3 server wait.
- Patch 2 is payload- and message-identical to v4.
Previous postings (newest first):
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: fix packet drops caused by GRO superpackets
net: hsr: shrink seqnr_lock to sequence counter updates
net: hsr: unfold GSO super-packets at the forward entry
selftests: net: hsr: cover GSO super-packets on PRP slave ingress
include/linux/netdevice.h | 2 + net/core/dev.c | 15 + net/core/dev_api.c | 21 + net/hsr/hsr_device.c | 17 +- net/hsr/hsr_forward.c | 111 ++- net/hsr/hsr_slave.c | 16 +- tools/testing/selftests/net/hsr/Makefile | 1 + .../selftests/net/hsr/hsr_gro_superpacket.sh | 631 ++++++++++++++++++ 8 files changed, 787 insertions(+), 27 deletions(-) create mode 100755 tools/testing/selftests/net/hsr/hsr_gro_superpacket.sh
Signature · 1 line
2.43.0
PATCH v5 1/4 net: hsr: fix packet drops caused by GRO superpackets
HSR/PRP process each wire frame separately for tagging and duplicate discard. GRO on a lower device hides multiple frames in one skb, which cannot be forwarded with valid per-frame metadata.
Disable GRO and GRO_HW when a lower device is enslaved, matching the existing LRO handling.
This is best effort because GRO may be re-enabled and some devices cannot disable GRO_HW. The forward-entry segmentation fix handles plain, trailer-free GSO skbs that still arrive; device-specific fixed-on GRO_HW output is outside this guarantee.
--- include/linux/netdevice.h | 2 ++ net/core/dev.c | 15 +++++++++++++++ net/core/dev_api.c | 21 +++++++++++++++++++++ net/hsr/hsr_slave.c | 5 +++++ 4 files changed, 43 insertions(+)
include/linux/netdevice.h +2 -0
@@ -3434,6 +3434,8 @@ void dev_close(struct net_device *dev);void netif_close_many (struct list_head *head,bool unlink);void netif_disable_lro (struct net_device *dev);void dev_disable_lro (struct net_device *dev); +void netif_disable_gro (struct net_device *dev); +void dev_disable_gro (struct net_device *dev);int dev_loopback_xmit (struct net *net,struct sock *sk,struct sk_buff *newskb);u16 dev_pick_tx_zero (struct net_device *dev,struct sk_buff *skb,struct net_device *sb_dev);
net/core/dev.c +15 -0
@@ -1840,6 +1840,21 @@ void netif_disable_lro(struct net_device *dev) } } +void netif_disable_gro (struct net_device *dev) +{ +struct net_device *lower_dev; +struct list_head *iter; + + dev->wanted_features &= ~(NETIF_F_GRO |NETIF_F_GRO_HW ); +netdev_update_features (dev); + +netdev_for_each_lower_dev (dev, lower_dev, iter) { +netdev_lock_ops (lower_dev); +netif_disable_gro (lower_dev); +netdev_unlock_ops (lower_dev); + } +} +/** * dev_disable_gro_hw - disable HW Generic Receive Offload on a device * @dev: device
net/core/dev_api.c +21 -0
@@ -269,6 +269,27 @@ void dev_disable_lro(struct net_device *dev) }EXPORT_SYMBOL (dev_disable_lro); +/** +* dev_disable_gro() - disable Generic Receive Offload on a device +* @dev: device +* +* Best-effort disable of Generic Receive Offload (GRO) on a net +* device. Must be called under RTNL. This is needed if received +* packets may be forwarded to another interface. +* +* The disable is best-effort: a device with a fixed-on feature (for +* example GRO_HW on a virtio-net device negotiated without +* VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) keeps it enabled. Callers that +* need a hard guarantee must inspect the resulting feature state. +*/ +void dev_disable_gro (struct net_device *dev) +{ +netdev_lock_ops (dev); +netif_disable_gro (dev); +netdev_unlock_ops (dev); +} +EXPORT_SYMBOL (dev_disable_gro); +/** * dev_set_promiscuity() - update promiscuity count on a device * @dev: device
net/hsr/hsr_slave.c +5 -0
@@ -171,6 +171,11 @@ static int hsr_portdev_setup(struct hsr_priv *hsr, struct net_device *dev, goto fail_rx_handler;dev_disable_lro (dev); +/* GRO disabling is best-effort: devices with fixed-on +* GRO/GRO_HW cannot be forced off. +*/ +dev_disable_gro (dev); +return 0 ; fail_rx_handler:
Signature · 1 line
2.43.0
PATCH v5 2/4 net: hsr: shrink seqnr_lock to sequence counter updates
In reply to Xin Xieseqnr_lock currently covers the whole forwarding path although only the sequence counters need serialization. Limit it to the counter updates.
The old lock also serialized the tx statistics; use DEV_STATS_INC() and DEV_STATS_ADD() for their now-concurrent updates. Concurrently forwarded frames may be emitted out of allocation order, which sparse-bitmap duplicate discard tolerates.
The GSO segmentation patch depends on this shorter critical section. Apply both only to 7.0 and newer, where sparse-bitmap duplicate discard is present; older trees require an adapted backport.
--- net/hsr/hsr_device.c | 15 ++++----------- net/hsr/hsr_forward.c | 9 +++++---- net/hsr/hsr_slave.c | 11 +---------- 3 files changed, 10 insertions(+), 25 deletions(-)
net/hsr/hsr_device.c +4 -11
@@ -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); }else {dev_core_stats_tx_dropped_inc (dev);dev_kfree_skb_any (skb);
@@ -335,6 +333,7 @@ static void send_hsr_supervision_frame(struct hsr_port *port, hsr_stag->sequence_nr =htons (hsr->sequence_nr); hsr->sequence_nr++; } +spin_unlock_bh (&hsr->seqnr_lock); hsr_stag->tlv.HSR_TLV_type = type;/* HSRv0 has 6 unused bytes after the MAC */
@@ -356,14 +355,10 @@ static void send_hsr_supervision_frame(struct hsr_port *port,ether_addr_copy (hsr_sp->macaddress_A, hsr->macaddress_redbox); } -if (skb_put_padto (skb,ETH_ZLEN )) { -spin_unlock_bh (&hsr->seqnr_lock); +if (skb_put_padto (skb,ETH_ZLEN ))return ; - }hsr_forward_skb (skb, port); -spin_unlock_bh (&hsr->seqnr_lock); -return ; } static void send_prp_supervision_frame(struct hsr_port *master,
@@ -390,6 +385,7 @@ static void send_prp_supervision_frame(struct hsr_port *master,spin_lock_bh (&hsr->seqnr_lock); hsr_stag->sequence_nr =htons (hsr->sup_sequence_nr); hsr->sup_sequence_nr++; +spin_unlock_bh (&hsr->seqnr_lock); hsr_stag->tlv.HSR_TLV_type =PRP_TLV_LIFE_CHECK_DD ; hsr_stag->tlv.HSR_TLV_length =sizeof (struct hsr_sup_payload );
@@ -397,13 +393,10 @@ static void send_prp_supervision_frame(struct hsr_port *master, hsr_sp =skb_put (skb,sizeof (struct hsr_sup_payload ));ether_addr_copy (hsr_sp->macaddress_A, master->dev->dev_addr); -if (skb_put_padto (skb,ETH_ZLEN )) { -spin_unlock_bh (&hsr->seqnr_lock); +if (skb_put_padto (skb,ETH_ZLEN ))return ; - }hsr_forward_skb (skb, master); -spin_unlock_bh (&hsr->seqnr_lock); }/* Announce (supervision frame) timer function
net/hsr/hsr_forward.c +5 -4
@@ -621,9 +621,10 @@ static void handle_std_frame(struct sk_buff *skb,if (port->type ==HSR_PT_MASTER || port->type ==HSR_PT_INTERLINK ) {/* Sequence nr for the master/interlink node */ -lockdep_assert_held (&hsr->seqnr_lock); +spin_lock_bh (&hsr->seqnr_lock); frame->sequence_nr = hsr->sequence_nr; hsr->sequence_nr++; +spin_unlock_bh (&hsr->seqnr_lock); } }
@@ -746,8 +747,8 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port)* So check and increment stats for master port only here. */ if (port->type ==HSR_PT_MASTER || port->type ==HSR_PT_INTERLINK ) { - port->dev->stats.tx_packets++; - port->dev->stats.tx_bytes += skb->len; +DEV_STATS_INC (port->dev, tx_packets); +DEV_STATS_ADD (port->dev, tx_bytes, skb->len); }kfree_skb (frame.skb_hsr);
@@ -757,6 +758,6 @@ void hsr_forward_skb(struct sk_buff *skb, struct hsr_port *port) out_drop:rcu_read_unlock (); - port->dev->stats.tx_dropped++; +DEV_STATS_INC (port->dev, tx_dropped);kfree_skb (skb); }
net/hsr/hsr_slave.c +1 -10
@@ -73,16 +73,7 @@ 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. -*/ -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 ;
Signature · 1 line
2.43.0
PATCH v5 3/4 net: hsr: unfold GSO super-packets at the forward entry
In reply to Xin XieHSR/PRP require per-wire-frame tags and sequence numbers. Treating a GSO skb as one frame breaks those semantics.
Classify GSO skbs at the forward entry by effective protocol rather than ingress port. Segment plain aggregates and process every segment normally, preserving local delivery and forwarding. Drop ETH_P_HSR, ETH_P_PRP and unreadable aggregates because their per-frame metadata cannot be rebuilt. HSR supports one 802.1Q C-tag, so unsupported stacked or S-tag GSO input is rejected before segmentation.
In-tree software GRO does not merge PRP RCT frames because its IPv4 and IPv6 length checks reject trailing bytes. This guarantee does not cover device-specific fixed-on GRO_HW output.
Also remove GSO features from the HSR master's hw_features when possible. This patch depends on patch 2 and the sparse-bitmap duplicate discard in 7.0 and newer; older trees require an adapted backport.
--- net/hsr/hsr_device.c | 2 +- net/hsr/hsr_forward.c | 102 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 2 deletions(-)
net/hsr/hsr_device.c +1 -1
@@ -652,7 +652,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 +101 -1
117 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v5 4/4 selftests: net: hsr: cover GSO super-packets on PRP slave ingress
In reply to Xin XieAdd a PRP LAN-slave GSO case which verifies that plain aggregates are segmented and delivered locally to the master. Also bound the iperf3 server readiness wait.
--- tools/testing/selftests/net/hsr/Makefile | 1 + .../selftests/net/hsr/hsr_gro_superpacket.sh | 631 ++++++++++++++++++ 2 files changed, 632 insertions(+) create mode 100755 tools/testing/selftests/net/hsr/hsr_gro_superpacket.sh
tools/testing/selftests/net/hsr/Makefile +1 -0
@@ -3,6 +3,7 @@ top_srcdir = ../../../../.. TEST_PROGS := \ + hsr_gro_superpacket.sh \ hsr_ping.sh \ hsr_redbox.sh \ link_faults.sh \
tools/testing/selftests/net/hsr/hsr_gro_superpacket.sh new file +631 -0
631 lines not on this page · raw message
Signature · 1 line
2.43.0