Skip to contentSkip to conversation

net/ena: fix out-of-bounds Tx prefetch

PATCH In review Wenyu Su 2 participants 2 messages Nov 22 – Nov 23 Network drivers

lore
Share & tools
lore

Wenyu Su

author
#0 lore raw

PATCH 1/1 net/ena: fix out-of-bounds Tx prefetch

The Tx prefetch uses the descriptor ring mask to index the caller-provided packet array. This can read beyond the end of the array near the end of a burst.

Only prefetch when the lookahead index is within the burst.

Fixes 1173fca25af9 ("ena: add polling-mode driver")
---
 .mailmap                     | 1 +
 drivers/net/ena/ena_ethdev.c | 4 ++--
 drivers/net/ena/ena_ethdev.h | 1 -
 3 files changed, 3 insertions(+), 3 deletions(-)
.mailmap +1 -0
index a0096fb97a..b0ac17ea0c 100644
@@ -1874,6 +1874,7 @@ Wentao Cui <[email protected]>
 Wenwu Ma <[email protected]>
 Wenxiang Qian <[email protected]>
 Wenxuan Wu <[email protected]>
+Wenyu Su <[email protected]>
 Wenzhuo Lu <[email protected]>
 Weqaar Janjua <[email protected]>
 Wiktor Pilarczyk <[email protected]>
drivers/net/ena/ena_ethdev.c +2 -2
index c2d0194e51..7ea6deea70 100644
@@ -3425,8 +3425,8 @@ static uint16_t eth_ena_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
 		if (ena_xmit_mbuf(tx_ring, tx_pkts[sent_idx]))
 			break;
 		tx_ring->pkts_without_db = true;
-		rte_prefetch0(tx_pkts[ENA_IDX_ADD_MASKED(sent_idx, 4,
-			tx_ring->size_mask)]);
+		if (likely((sent_idx + 4) < nb_pkts))
+			rte_prefetch0(tx_pkts[sent_idx + 4]);
 	}
 
 	/* If there are ready packets to be xmitted... */
drivers/net/ena/ena_ethdev.h +0 -1
index b204b07767..bd25cff8ca 100644
@@ -60,7 +60,6 @@
 #define ENA_MAX_CUSTOMER_METRICS	6
 
 #define ENA_IDX_NEXT_MASKED(idx, mask) (((idx) + 1) & (mask))
-#define ENA_IDX_ADD_MASKED(idx, n, mask) (((idx) + (n)) & (mask))
 
 
 #define ENA_HASH_KEY_SIZE		40
Signature · 1 line
2.39.5 (Apple Git-154)
#1 lore raw
Quoted 10 lines · On Sun, 22 Nov 2026 21:47:23 +0000 Wenyu Su <[email protected]> wrote:

The Tx prefetch uses the descriptor ring mask to index the caller-provided packet array. This can read beyond the end of the array near the end of a burst.

Only prefetch when the lookahead index is within the burst.

Fixes 1173fca25af9 ("ena: add polling-mode driver")

---

Looks right, applied to next-net for 27.03