* [PATCH net 0/3] Fix short frame transmission in enetc
@ 2026-04-01 17:22 Vladimir Oltean
2026-04-01 17:22 ` [PATCH net 1/3] net: enetc: fix bogus TX ring consumer index after reinitialization Vladimir Oltean
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Vladimir Oltean @ 2026-04-01 17:22 UTC (permalink / raw)
To: netdev
Cc: Zefir Kurtisi, Claudiu Manoil, Wei Fang, Clark Wang, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Ioana Ciornei, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
Simon Horman, bpf, imx, linux-kernel
This is a belated follow-up to Zefir Kurtisi's report:
https://lore.kernel.org/netdev/20260220132930.2521155-1-zefir.kurtisi@gmail.com/
My analysis shows quite a different chain of events than the one
presented by Zefir. What is common is that, indeed, the ENETC misbehaves
when transmitting packets smaller than 16 octets sans FCS: it sends them
but does not update the completed index in the transmit BD ring.
However, I did find a sentence in the reference manual explicitly
stating these short frames are not supported.
The main patch is 2/3, which Zefir already tested and confirmed working
in the thread from February.
Patch 3/3 fixes a similar issue which can be reproduced from the XDP
path.
Patch 1/3 fixes an issue I identified while reviewing the code w.r.t.
TBaCIR interaction.
Vladimir Oltean (3):
net: enetc: fix bogus TX ring consumer index after reinitialization
net: enetc: pad short frames in software
net: enetc: pad short XDP frames coming from devmap
drivers/net/ethernet/freescale/enetc/enetc.c | 9 ++++++++-
include/net/xdp.h | 17 +++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net 1/3] net: enetc: fix bogus TX ring consumer index after reinitialization
2026-04-01 17:22 [PATCH net 0/3] Fix short frame transmission in enetc Vladimir Oltean
@ 2026-04-01 17:22 ` Vladimir Oltean
2026-04-01 17:22 ` [PATCH net 2/3] net: enetc: pad short frames in software Vladimir Oltean
2026-04-01 17:22 ` [PATCH net 3/3] net: enetc: pad short XDP frames coming from devmap Vladimir Oltean
2 siblings, 0 replies; 5+ messages in thread
From: Vladimir Oltean @ 2026-04-01 17:22 UTC (permalink / raw)
To: netdev
Cc: Zefir Kurtisi, Claudiu Manoil, Wei Fang, Clark Wang, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Ioana Ciornei, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
Simon Horman, bpf, imx, linux-kernel
The TBCIR (Transmit Buffer Descriptor Ring Consumer Index) register has
the BD index as the lower 16 bits, but the upper 16 bits contain this
field:
STAT_ID: Status identifier. Incremented each time the BDR_INDEX is
updated and an error status bit was set for one of the processed BDs.
Clears on read.
If there was any transmit error prior to the ring reinitialization and
this is the first time we re-read the TBCIR register, reading it will
give us a value with non-zero upper bits, which is saved in
bdr->next_to_clean.
If subsequently NAPI gets invoked and enetc_clean_tx_ring() runs, this
will dereference the &tx_ring->tx_swbd[] for the bogus (and huge)
next_to_clean index, and will result in an out-of-bounds memory access.
Other places like enetc_bd_ready_count() do mask out the upper bits, so
let's do that here as well.
Fixes: d4fd0404c1c9 ("enetc: Introduce basic PF and VF ENETC ethernet drivers")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/ethernet/freescale/enetc/enetc.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index a146ceaf2ed6..c9cdf9d11212 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -2593,7 +2593,8 @@ static void enetc_setup_txbdr(struct enetc_hw *hw, struct enetc_bdr *tx_ring)
/* clearing PI/CI registers for Tx not supported, adjust sw indexes */
tx_ring->next_to_use = enetc_txbdr_rd(hw, idx, ENETC_TBPIR);
- tx_ring->next_to_clean = enetc_txbdr_rd(hw, idx, ENETC_TBCIR);
+ tx_ring->next_to_clean = enetc_txbdr_rd(hw, idx, ENETC_TBCIR) &
+ ENETC_TBCIR_IDX_MASK;
/* enable Tx ints by setting pkt thr to 1 */
enetc_txbdr_wr(hw, idx, ENETC_TBICR0, ENETC_TBICR0_ICEN | 0x1);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net 2/3] net: enetc: pad short frames in software
2026-04-01 17:22 [PATCH net 0/3] Fix short frame transmission in enetc Vladimir Oltean
2026-04-01 17:22 ` [PATCH net 1/3] net: enetc: fix bogus TX ring consumer index after reinitialization Vladimir Oltean
@ 2026-04-01 17:22 ` Vladimir Oltean
2026-04-02 15:37 ` Jakub Kicinski
2026-04-01 17:22 ` [PATCH net 3/3] net: enetc: pad short XDP frames coming from devmap Vladimir Oltean
2 siblings, 1 reply; 5+ messages in thread
From: Vladimir Oltean @ 2026-04-01 17:22 UTC (permalink / raw)
To: netdev
Cc: Zefir Kurtisi, Claudiu Manoil, Wei Fang, Clark Wang, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Ioana Ciornei, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
Simon Horman, bpf, imx, linux-kernel
The ENETC does not support BUF_LEN or FRM_LEN in TX buffer descriptors
less than 16. This is written in the reference manual of all SoCs
supported by the driver: LS1028A, i.MX943, i.MX95 etc.
Frames must not have a FRM_LEN that is less than 16 bytes. Frames of
0-15 bytes are not supported.
(...)
The first descriptor in a chain must not have a BUFF_LEN that is less
than 16 bytes.
I don't think proper attention was paid to this during development, we
found the text at the end of a bug investigation. Therefore, the driver
does not enforce this.
But the frame length is out of the driver's control, and the network
stack can actually send packets with skb->len smaller than that. The
result is unpleasant, as will be explained below, so for simplicity
sake, we just pad anything shorter than ETH_ZLEN.
Zefir Kurtisi found a case where transmitting L2 WNM keep-alive frames
through ENETC would soft-lockup the host through an IRQ storm. He later
distilled this into a small enetc-killer.c user space program which
sends a packet with MAC DA, MAC SA and EtherType IPv4 (14 octets in
length) through an AF_PACKET raw socket.
The IRQ storm is actually a curious effect of a chain of events.
The hardware behaviour, when an invalid BD is put in its TX ring, is
that it would transmit the packet as normal, update counters, raise
completion interrupt as normal, but it would just not advance the
consumer index of the ring (TBaCIR) to signify that the BD has been
consumed and is available for software to free. The ring will also get
its TBaSR[BUSY] bit persistently set to 1 afterwards.
It deserves an explanation why the behaviour above would lead to an
IRQ storm, since ENETC interrupts are message-based (MSI-X), and an
unhandled interrupt would typically just be lost rather than retrigger
itself as a wired interrupt would.
NAPI processing in ENETC has 3 steps:
I. the enetc_msix() hardirq handler disables RBaIER, TBaIER and sets
softirq processing to the 'pending' state.
II. the enetc_poll() softirq handler for the IRQ vector walks through
the TX rings affine to that vector, checks which ones have a TBCIR
updated since last time - enetc_bd_ready_count() - processes those
completed frames, and clears pending interrupts in these updated TX
rings by writing to TBaIDR. (I've excluded RX processing due to it
being irrelevant).
III. After the softirq handler does its round of checking all RX and TX
rings for updates, it re-enables all interrupts in RBaIER and
TBaIER that were previously disabled by the hardirq handler, and
exits.
Because the TX ring with the short frame is skipped at step II (TBCIR
wasn't updated as part of HW malfunction), its pending IRQ is not
cleared in TBaIDR by enetc_clean_tx_ring().
But because enetc_msix() disables TBaIER at step I and re-enables it at
step III, another MSI will be fired upon re-enabling it. This is what
completes the cycle and the driver goes back to step I.
So the driver misinterprets the mixed signals it's getting from the
hardware, and ends up causing a software-amplified IRQ storm.
Fixes: d4fd0404c1c9 ("enetc: Introduce basic PF and VF ENETC ethernet drivers")
Reported-by: Zefir Kurtisi <zefir.kurtisi@westermo.com>
Closes: https://lore.kernel.org/netdev/b3d9136c-2803-4203-b1ea-1f9e62de80a1@gmail.com/
Tested-by: Zefir Kurtisi <zefir.kurtisi@westermo.com>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/ethernet/freescale/enetc/enetc.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index c9cdf9d11212..4b87fbfde0d6 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -1050,6 +1050,9 @@ netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev)
u8 udp, msgtype, twostep;
u16 offset1, offset2;
+ if (eth_skb_pad(skb))
+ return NETDEV_TX_OK;
+
/* Mark tx timestamp type on enetc_cb->flag if requires */
if ((skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
(priv->active_offloads & ENETC_F_TX_TSTAMP_MASK))
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net 3/3] net: enetc: pad short XDP frames coming from devmap
2026-04-01 17:22 [PATCH net 0/3] Fix short frame transmission in enetc Vladimir Oltean
2026-04-01 17:22 ` [PATCH net 1/3] net: enetc: fix bogus TX ring consumer index after reinitialization Vladimir Oltean
2026-04-01 17:22 ` [PATCH net 2/3] net: enetc: pad short frames in software Vladimir Oltean
@ 2026-04-01 17:22 ` Vladimir Oltean
2 siblings, 0 replies; 5+ messages in thread
From: Vladimir Oltean @ 2026-04-01 17:22 UTC (permalink / raw)
To: netdev
Cc: Zefir Kurtisi, Claudiu Manoil, Wei Fang, Clark Wang, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Ioana Ciornei, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
Simon Horman, bpf, imx, linux-kernel
Similar to the skb path issue explained in the previous change, ENETC
could end up transmitting short frames coming from XDP.
The way in which this could happen is a bit contrived, but it involves
XDP_REDIRECT from a veth interface pair.
Introduce a xdp_frame_pad() generic helper and call it from enetc's
ndo_xdp_xmit() implementation. This should be safe, because
ndo_xdp_xmit() is the hand-off function where the XDP frames become the
responsibility of the driver, so modifying them is fine. AFAIU, struct
xdp_frame doesn't have multiple copies.
Fixes: 9d2b68cc108d ("net: enetc: add support for XDP_REDIRECT")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
drivers/net/ethernet/freescale/enetc/enetc.c | 3 +++
include/net/xdp.h | 17 +++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index 4b87fbfde0d6..3ceb9dfd2316 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -1801,6 +1801,9 @@ int enetc_xdp_xmit(struct net_device *ndev, int num_frames,
prefetchw(ENETC_TXBD(*tx_ring, tx_ring->next_to_use));
for (k = 0; k < num_frames; k++) {
+ if (unlikely(xdp_frame_pad(frames[k])))
+ break;
+
xdp_tx_bd_cnt = enetc_xdp_frame_to_xdp_tx_swbd(tx_ring,
xdp_redirect_arr,
frames[k]);
diff --git a/include/net/xdp.h b/include/net/xdp.h
index aa742f413c35..0cdeb23c6bd7 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -477,6 +477,23 @@ xdp_get_frame_len(const struct xdp_frame *xdpf)
return len;
}
+static inline int xdp_frame_pad(struct xdp_frame *xdpf)
+{
+ void *sinfo;
+
+ if (likely(xdpf->len >= ETH_ZLEN))
+ return 0;
+
+ sinfo = xdp_get_shared_info_from_frame(xdpf);
+ if (unlikely(xdpf->data + ETH_ZLEN > sinfo))
+ return -ENOMEM;
+
+ memset(xdpf->data + xdpf->len, 0, ETH_ZLEN - xdpf->len);
+ xdpf->len = ETH_ZLEN;
+
+ return 0;
+}
+
int __xdp_rxq_info_reg(struct xdp_rxq_info *xdp_rxq,
struct net_device *dev, u32 queue_index,
unsigned int napi_id, u32 frag_size);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net 2/3] net: enetc: pad short frames in software
2026-04-01 17:22 ` [PATCH net 2/3] net: enetc: pad short frames in software Vladimir Oltean
@ 2026-04-02 15:37 ` Jakub Kicinski
0 siblings, 0 replies; 5+ messages in thread
From: Jakub Kicinski @ 2026-04-02 15:37 UTC (permalink / raw)
To: Vladimir Oltean
Cc: netdev, Zefir Kurtisi, Claudiu Manoil, Wei Fang, Clark Wang,
Andrew Lunn, David S. Miller, Eric Dumazet, Paolo Abeni,
Ioana Ciornei, Alexei Starovoitov, Daniel Borkmann,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
Simon Horman, bpf, imx, linux-kernel
On Wed, 1 Apr 2026 20:22:45 +0300 Vladimir Oltean wrote:
> The ENETC does not support BUF_LEN or FRM_LEN in TX buffer descriptors
> less than 16. This is written in the reference manual of all SoCs
> supported by the driver: LS1028A, i.MX943, i.MX95 etc.
>
> Frames must not have a FRM_LEN that is less than 16 bytes. Frames of
> 0-15 bytes are not supported.
> (...)
> The first descriptor in a chain must not have a BUFF_LEN that is less
> than 16 bytes.
>
> I don't think proper attention was paid to this during development, we
> found the text at the end of a bug investigation. Therefore, the driver
> does not enforce this.
AI points out that the frame may be longer than 16B but fragmented.
Only the Ethernet header is guaranteed to be in the linear part.
So you may need to also toss something like pskb_may_pull(16) after
that padding call.
--
pw-bot: cr
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-02 15:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01 17:22 [PATCH net 0/3] Fix short frame transmission in enetc Vladimir Oltean
2026-04-01 17:22 ` [PATCH net 1/3] net: enetc: fix bogus TX ring consumer index after reinitialization Vladimir Oltean
2026-04-01 17:22 ` [PATCH net 2/3] net: enetc: pad short frames in software Vladimir Oltean
2026-04-02 15:37 ` Jakub Kicinski
2026-04-01 17:22 ` [PATCH net 3/3] net: enetc: pad short XDP frames coming from devmap Vladimir Oltean
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox