Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Vladimir Oltean
Wed, 18 Nov 2026 23:50
[PATCH v2 net 3/4] net: enetc: fall back to software TX csum for too long L3 headers
Author: Vladimir Oltean
Date: Wed, 18 Nov 2026 23:50
Date: Wed, 18 Nov 2026 23:50
114 lines
21525 bytes
21525 bytes
For L4 checksum offload, enetc_map_tx_buffs() programs the following TX
BD fields: ENETC_TX_BD_L3_START <- skb_network_offset(skb) and
ENETC_TX_BD_L3_HDR_LEN <- skb_network_header_len(skb) / 4.
These fields are passed this way so that the hardware simultaneously
knows the L3 header start (for computing the pseudo-header) and the L4
header start (by summing up L3_START + 4 x L3_HDR_SIZE) which is the
csum_start.
Section 106.3.5.1.2.1.3.5 Transmit Checksum Offload of the i.MX95 RM
has this statement:
BD[L3_START] + (BD[L3_HDR_SIZE] x 4) is set to the offset within the
packet to begin checksumming. (BD[L3_START] + (BD[L3_HDR_SIZE] x 4) +
any hardware inserted tags) must be smaller than 127 bytes.
We have no test for this condition, and with IPv6 extension headers it
is possible for that sum to actually exceed 127 bytes. For example, when
using the Segment Routing Header, 4 Segment Identifiers (SIDs) will
produce an L4 header offset of 126 bytes (OK), while 5 SIDs will produce
an L4 offset of 142 bytes (not OK).
The hardware picks up these packets from the TX ring, identifies the
incorrect header length, refuses to send them, updates the TX BD
writeback with the STATUS field set to 1, meaning:
Programming error
An error exists in either the Tx BD, the Tx ring registers, or some
combination of these which meant that this frame could not be
transmitted.
releases the buffer and updates tx_ring->stats.packets and
tx_ring->stats.bytes as if the packets were sent (but no MAC counter
updates).
This error can only be seen through manual code instrumentation, since
the driver only checks the writeback when it sets tx_swbd->check_wb, and
it does that for taprio offload and for 2-step TX timestamping.
Issue found while investigating Sashiko's question "Can a 256-byte
header still break the hardware LSO path because lso->hdr_len is a u8?":
https://lore.kernel.org/imx/sashiko-outbox-211955@kernel.org/
and was reproduced using:
https://gist.github.com/vladimiroltean/7cecf636b788b29f361a2fbdae646010
Turns out, LSO breaks sooner than the assumed 256 byte limit, because of
the checksum offload feature it depends on.
LS1028A also declares the NETIF_F_HW_CSUM feature in order for GSO to be
passed to the driver for software segmentation, but performs the
checksum in software - either through csum_partial()/csum_block_add()
for GSO, or through skb_checksum_help() for non-GSO. Point being, it
does not use the HW offload engine, does not have the limitation, and is
the reason why we need to discern using the ENETC_F_TXCSUM bit from
priv->active_offloads instead.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
v1->v2: patch is new
---
drivers/net/ethernet/freescale/enetc/enetc.c | 16 ++++++++++++++++
drivers/net/ethernet/freescale/enetc/enetc.h | 1 +
2 files changed, 17 insertions(+)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index 7f089a84d9a6..6cc519eea5bd 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -1114,6 +1114,16 @@ netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev)
}
EXPORT_SYMBOL_GPL(enetc_xmit);
+static bool enetc_skb_l4_too_deep(const struct sk_buff *skb)
+{
+ unsigned int l4_offset = skb_checksum_start_offset(skb);
+
+ if (skb_vlan_tag_present(skb))
+ l4_offset += VLAN_HLEN;
+
+ return l4_offset >= ENETC_TX_CSUM_MAX_L4_OFFSET;
+}
+
netdev_features_t enetc_features_check(struct sk_buff *skb,
struct net_device *ndev,
netdev_features_t features)
@@ -1122,6 +1132,12 @@ netdev_features_t enetc_features_check(struct sk_buff *skb,
features = vlan_features_check(skb, features);
+ if (priv->active_offloads & ENETC_F_TXCSUM &&
+ skb->ip_summed == CHECKSUM_PARTIAL && enetc_skb_l4_too_deep(skb)) {
+ features &= ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
+ return features;
+ }
+
if (!skb_is_gso(skb) || enetc_skb_uses_lso(priv, skb))
return features;
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h
index 1e3290d1a388..5b8cffd589c7 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc.h
@@ -75,6 +75,7 @@ struct enetc_lso_t {
int total_len; /* total data length, not include LSO header */
};
+#define ENETC_TX_CSUM_MAX_L4_OFFSET 127
#define ENETC_LSO_MAX_DATA_LEN SZ_256K
#define ENETC_RX_MAXFRM_SIZE ENETC_MAC_MAXFRM_SIZE
--
2.53.0
Re: [PATCH v2 net 3/4] net: enetc: fall back to software TX csum for too long L3 headers
Author: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 00:28
Date: Mon, 23 Nov 2026 00:28
170 lines
15023 bytes
15023 bytes
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] net: enetc: L4 offset check in enetc_features_check() misses
CHECKSUM_NONE GSO
- [Low] The commit "net: enetc: fall back to software TX csum for too
long L3 headers" has no Fixes: tag, but it fixes a real bug.
- [Low] The macro's name says inclusive maximum, but its only user treats
it as an exclusive bound.
--
net: enetc: fall back to software TX csum for too long L3 headers
This patch makes enetc_features_check() strip the checksum and GSO
features from CHECKSUM_PARTIAL skbs when the hardware TX checksum engine
is in use and the L4 offset (plus any hwaccel VLAN tag) reaches 127 bytes.
The i.MX95 hardware rejects such frames as a programming error, but the
driver still counts them as sent.
> diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
> index 7f089a84d9a65..6cc519eea5bd3 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc.c
> +++ b/drivers/net/ethernet/freescale/enetc/enetc.c
> @@ -1114,6 +1114,16 @@ netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev)
> }
> EXPORT_SYMBOL_GPL(enetc_xmit);
>
> +static bool enetc_skb_l4_too_deep(const struct sk_buff *skb)
> +{
> + unsigned int l4_offset = skb_checksum_start_offset(skb);
> +
> + if (skb_vlan_tag_present(skb))
> + l4_offset += VLAN_HLEN;
> +
> + return l4_offset >= ENETC_TX_CSUM_MAX_L4_OFFSET;
[Severity: Low]
This isn't a bug, but is the name ENETC_TX_CSUM_MAX_L4_OFFSET a bit
misleading? enetc.h defines it as:
#define ENETC_TX_CSUM_MAX_L4_OFFSET 127
This comparison treats it as an exclusive bound, so the largest L4 offset
actually allowed is 126. The ">=" matches the RM text ("must be smaller
than 127 bytes"). The "MAX" in the name, though, suggests that 127 itself
is allowed.
Someone reusing the macro could reasonably write
"> ENETC_TX_CSUM_MAX_L4_OFFSET" and let a 127 byte offset through, which
the hardware would reject. Would a name like
ENETC_TX_CSUM_L4_OFFSET_LIMIT, or a value of 126 compared with ">", make
the definition and its use agree?
The mismatch is still there at the end of the series. The later patch
"net: enetc: let core segment GSO skb when headers exceed TSO_HEADER_SIZE"
also cites this macro in its commit message.
> +}
> +
> netdev_features_t enetc_features_check(struct sk_buff *skb,
> struct net_device *ndev,
> netdev_features_t features)
> @@ -1122,6 +1132,12 @@ netdev_features_t enetc_features_check(struct sk_buff *skb,
>
> features = vlan_features_check(skb, features);
>
> + if (priv->active_offloads & ENETC_F_TXCSUM &&
> + skb->ip_summed == CHECKSUM_PARTIAL && enetc_skb_l4_too_deep(skb)) {
> + features &= ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
> + return features;
> + }
> +
[Severity: Medium]
Does this check catch GSO skbs that reach enetc_features_check() with
skb->ip_summed set to something other than CHECKSUM_PARTIAL?
There are at least two ways to get such an skb here:
- validate_xmit_skb() changes a non-fraglist GSO skb marked
CHECKSUM_UNNECESSARY into CHECKSUM_NONE before it calls
netif_skb_features(). One example is a TCPv6 skb with an SRH that
GRO coalesced and that is then forwarded or bridged out of the
ENETC port.
- __virtio_net_hdr_to_skb() builds CHECKSUM_NONE GSO skbs when
VIRTIO_NET_HDR_F_NEEDS_CSUM is not set. Local users of tun/tap,
macvtap, vhost-net or AF_PACKET can trigger this.
For those skbs the ip_summed test fails and enetc_skb_l4_too_deep() is
never called. NETIF_F_TSO6 and NETIF_F_HW_CSUM stay set in features.
netif_needs_gso() is then true because the skb is not
CHECKSUM_PARTIAL. validate_xmit_skb() goes through __skb_gso_segment()
into tcp6_gso_segment(), which switches the skb to CHECKSUM_PARTIAL
via __tcp_v6_send_check(). tcp_gso_segment() then returns NULL without
segmenting, because skb_gso_ok() still sees NETIF_F_TSO6 in features.
The skb reaches enetc_start_xmit() and enetc_lso_hw_offload() whole.
enetc_lso_map_hdr() then sets ENETC_TXBD_FLAGS_CSUM_LSO,
ENETC_TXBD_FLAGS_LSO and ENETC_TXBD_FLAGS_L4CS with an L4 offset of
127 bytes or more. Wouldn't the hardware reject that with the same
programming error described in the commit message? The frame would be
dropped while tx_ring->stats still counts it as sent.
At this point in the series nothing bounds the GSO header length
either. Headers of 256 bytes or more on this path also wrap the u8
lso->hdr_len and lso->l3_hdr_len fields that enetc_lso_start() fills
in.
The TSO_HEADER_SIZE - VLAN_HLEN check added later by "net: enetc: let
core segment GSO skb when headers exceed TSO_HEADER_SIZE" removes the
wrap. It does not close this hole, though. A GSO skb with an L4 offset
between 127 and 232 bytes and no more than 252 bytes of headers still
keeps NETIF_F_TSO6 at the end of the series.
csum_start is only meaningful for CHECKSUM_PARTIAL, so the ip_summed
test is needed as long as enetc_skb_l4_too_deep() uses
skb_checksum_start_offset(). Would it work to use
skb_transport_offset() for GSO skbs regardless of ip_summed, and keep
the csum_start based check for non-GSO CHECKSUM_PARTIAL skbs?
[Severity: Low]
Should this patch have a Fixes: tag? The other three patches in the
series each carry "Fixes: fb8629e2cbfc", but this one has none.
The L3_START/L3_HDR_LEN programming in enetc_map_tx_buffs() that this
check guards came from commit d9a093d2d12a ("net: enetc: add Tx checksum
offload for i.MX95 ENETC"):
temp_bd.l3_aux0 = FIELD_PREP(ENETC_TX_BD_L3_START,
skb_network_offset(skb));
temp_bd.l3_aux1 = FIELD_PREP(ENETC_TX_BD_L3_HDR_LEN,
skb_network_header_len(skb) / 4);
enetc_lso_map_hdr() has the same unbounded programming. It came from
commit 69797ff888d3 ("net: enetc: add LSO support for i.MX95 ENETC PF"),
and LSO depends on the same checksum engine:
txbd_tmp.l3_aux0 = FIELD_PREP(ENETC_TX_BD_L3_START, lso->l3_start);
/* l3_hdr_size in 32-bits (4 bytes) */
txbd_tmp.l3_aux1 = FIELD_PREP(ENETC_TX_BD_L3_HDR_LEN,
lso->l3_hdr_len / 4);
Without a tag, stable trees that contain d9a093d2d12a (December 2024 and
later) may not get this fix. Frames such as IPv6 with a 5 SID SRH would
then still be dropped silently by the hardware while being counted as
sent.
Would something like this be appropriate?
Fixes: d9a093d2d12a ("net: enetc: add Tx checksum offload for i.MX95 ENETC")
> if (!skb_is_gso(skb) || enetc_skb_uses_lso(priv, skb))
> return features;
>
[ ... ]
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118235055.1225115-1-vladimir.oltean%40nxp.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads