Netdev List
 help / color / mirror / Atom feed
* [PATCH] eea: do not credit TX completions without a matching descriptor
@ 2026-12-04  6:28 Hongyu Guo
  2026-12-04  6:42 ` netdev-bot+sinfo
  0 siblings, 1 reply; 3+ messages in thread
From: Hongyu Guo @ 2026-12-04  6:28 UTC (permalink / raw)
  To: netdev; +Cc: Xuan Zhuo, Wen Gu, Philo Lu, stable, 13057616121

eea_clean_tx() credits num_free for every completion it takes off the
CQ, even when it maps to no in-flight descriptor: an id outside the
ring, or a meta whose data is NULL. num_free is the only transmit
throttle, so a device that emits or replays TX completions inflates
the credit count past the free descriptors: the queue never stops,
the free-meta list runs dry, and __eea_tx_desc_fill() dereferences
the NULL returned by eea_tx_meta_get().

Advance the CQ without crediting the ring for such completions, and
fail eea_tx_desc_fill() when no free meta is available, as the RX
path already does.

Fixes: aef5055e9764 ("eea: implement packet transmit logic")
Cc: stable@vger.kernel.org
Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: Wen Gu <guwen@linux.alibaba.com>
Cc: Philo Lu <lulie@linux.alibaba.com>
Signed-off-by: Hongyu Guo <guohongyu@cmss.chinamobile.com>
---
 drivers/net/ethernet/alibaba/eea/eea_ring.c | 16 +++++++
 drivers/net/ethernet/alibaba/eea/eea_ring.h |  1 +
 drivers/net/ethernet/alibaba/eea/eea_tx.c   | 51 ++++++++++++++++++---
 3 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/alibaba/eea/eea_ring.c b/drivers/net/ethernet/alibaba/eea/eea_ring.c
index fac7d4647ecb..d084c21b5408 100644
--- a/drivers/net/ethernet/alibaba/eea/eea_ring.c
+++ b/drivers/net/ethernet/alibaba/eea/eea_ring.c
@@ -123,6 +123,22 @@ void eea_ering_cq_ack_desc(struct eea_ring *ering, u32 num)
 	ering->num_free += num;
 }
 
+/* Advance the CQ for num completions that map to no in-flight
+ * descriptor, without returning those descriptor credits.
+ */
+void eea_ering_cq_skip_desc(struct eea_ring *ering, u32 num)
+{
+	struct eea_ring_cq *cq = &ering->cq;
+
+	cq->head += num;
+	cq->hw_idx += num;
+
+	if (unlikely(cq->head >= ering->num)) {
+		cq->head -= ering->num;
+		cq->phase ^= EEA_RING_DESC_F_CQ_PHASE;
+	}
+}
+
 /* notify */
 void eea_ering_kick(struct eea_ring *ering)
 {
diff --git a/drivers/net/ethernet/alibaba/eea/eea_ring.h b/drivers/net/ethernet/alibaba/eea/eea_ring.h
index a7ce465943a5..6e43d0179f6d 100644
--- a/drivers/net/ethernet/alibaba/eea/eea_ring.h
+++ b/drivers/net/ethernet/alibaba/eea/eea_ring.h
@@ -93,6 +93,7 @@ void eea_ering_sq_commit_desc(struct eea_ring *ering);
 void eea_ering_sq_cancel(struct eea_ring *ering);
 
 void eea_ering_cq_ack_desc(struct eea_ring *ering, u32 num);
+void eea_ering_cq_skip_desc(struct eea_ring *ering, u32 num);
 
 void eea_ering_irq_active(struct eea_ring *ering, struct eea_ring *tx_ering);
 void *eea_ering_cq_get_desc(const struct eea_ring *ering);
diff --git a/drivers/net/ethernet/alibaba/eea/eea_tx.c b/drivers/net/ethernet/alibaba/eea/eea_tx.c
index c9292bca1a8b..cd48f852a94c 100644
--- a/drivers/net/ethernet/alibaba/eea/eea_tx.c
+++ b/drivers/net/ethernet/alibaba/eea/eea_tx.c
@@ -117,7 +117,7 @@ static int eea_clean_tx(struct eea_net_tx *tx, int budget)
 			if (net_ratelimit())
 				netdev_err(tx->enet->netdev, "tx invalid id %d\n",
 					   id);
-			eea_ering_cq_ack_desc(tx->ering, 1);
+			eea_ering_cq_skip_desc(tx->ering, 1);
 			continue;
 		}
 
@@ -127,15 +127,19 @@ static int eea_clean_tx(struct eea_net_tx *tx, int budget)
 			eea_tx_meta_put_and_unmap(tx, meta);
 			eea_meta_free_xmit(tx, meta, budget, desc, &stats);
 			desc_n = meta->num;
+			eea_ering_cq_ack_desc(tx->ering, desc_n);
 		} else {
 			if (net_ratelimit())
 				netdev_err(tx->enet->netdev,
 					   "tx meta->data is null. id %d num: %d\n",
 					   meta->id, meta->num);
-			desc_n = 1;
+			/* Completion without a matching in-flight descriptor.
+			 * Drop it: do not return descriptor credits to the
+			 * ring, otherwise num_free grows past the number of
+			 * free descriptors and the queue never stops.
+			 */
+			eea_ering_cq_skip_desc(tx->ering, 1);
 		}
-
-		eea_ering_cq_ack_desc(tx->ering, desc_n);
 	}
 
 	if (stats.packets) {
@@ -214,6 +218,8 @@ static struct eea_tx_meta *__eea_tx_desc_fill(struct eea_net_tx *tx,
 	struct eea_tx_desc *desc;
 
 	meta = eea_tx_meta_get(tx);
+	if (!meta)
+		return NULL;
 
 	desc = eea_ering_sq_alloc_desc(tx->ering, meta->id, last, flags);
 	desc->addr = cpu_to_le64(addr);
@@ -261,6 +267,8 @@ static struct eea_tx_meta *eea_tx_desc_fill(struct eea_net_tx *tx,
 
 	meta = __eea_tx_desc_fill(tx, head_meta, addr, len, length,
 				  last, data, flags, true);
+	if (!meta)
+		return NULL;
 
 	if (length > USHRT_MAX) {
 		if (!head_meta)
@@ -269,8 +277,24 @@ static struct eea_tx_meta *eea_tx_desc_fill(struct eea_net_tx *tx,
 		addr += USHRT_MAX;
 		len = length - USHRT_MAX;
 
-		__eea_tx_desc_fill(tx, head_meta, addr, len, 0, is_last,
-				   NULL, 0, false);
+		if (!__eea_tx_desc_fill(tx, head_meta, addr, len, 0, is_last,
+					NULL, 0, false)) {
+			/* Drop the descriptor taken for the first half of
+			 * the buffer. For a chained fragment unmap its
+			 * mapping here; for a head buffer the caller
+			 * unmaps addr on its error path.
+			 */
+			if (head_meta != meta) {
+				head_meta->next = meta->next;
+				--head_meta->num;
+				dma_unmap_page(tx->dma_dev, meta->dma_addr,
+					       meta->dma_len, DMA_TO_DEVICE);
+			}
+			meta->data = NULL;
+			meta->next = tx->free;
+			tx->free = meta;
+			return NULL;
+		}
 	}
 
 	return meta;
@@ -287,7 +311,8 @@ static int eea_tx_add_skb_frag(struct eea_net_tx *tx,
 	if (unlikely(dma_mapping_error(tx->dma_dev, addr)))
 		return -ENOMEM;
 
-	eea_tx_desc_fill(tx, head_meta, addr, len, is_last, NULL, 0);
+	if (!eea_tx_desc_fill(tx, head_meta, addr, len, is_last, NULL, 0))
+		return -ENOMEM;
 
 	return 0;
 }
@@ -332,6 +357,10 @@ static int eea_tx_post_skb(struct eea_net_tx *tx, struct sk_buff *skb)
 	flags = skb->ip_summed == CHECKSUM_PARTIAL ? EEA_DESC_F_DO_CSUM : 0;
 
 	meta = eea_tx_desc_fill(tx, NULL, addr, len, last, skb, flags);
+	if (!meta) {
+		err = -ENOMEM;
+		goto err_unmap;
+	}
 	meta->unmap_single = !!hlen;
 
 	err = eea_fill_desc_from_skb(skb, meta->desc);
@@ -360,6 +389,14 @@ static int eea_tx_post_skb(struct eea_net_tx *tx, struct sk_buff *skb)
 	eea_tx_meta_put_and_unmap(tx, meta);
 	meta->data = NULL;
 	return err;
+
+err_unmap:
+	eea_ering_sq_cancel(tx->ering);
+	if (hlen)
+		dma_unmap_single(tx->dma_dev, addr, len, DMA_TO_DEVICE);
+	else
+		dma_unmap_page(tx->dma_dev, addr, len, DMA_TO_DEVICE);
+	return err;
 }
 
 static void eea_tx_kick(struct eea_net_tx *tx)
-- 
2.43.0




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] eea: do not credit TX completions without a matching descriptor
  2026-12-04  6:28 [PATCH] eea: do not credit TX completions without a matching descriptor Hongyu Guo
@ 2026-12-04  6:42 ` netdev-bot+sinfo
  2026-12-04  7:13   ` guohongyu
  0 siblings, 1 reply; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-12-04  6:42 UTC (permalink / raw)
  To: Hongyu Guo; +Cc: netdev, Xuan Zhuo, Wen Gu, Philo Lu, stable, 13057616121

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

 - What hardware the change was tested on. For driver fixes please
   mention the device (and if relevant firmware version) used for
   testing, or say that the change was not tested on real hardware.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] eea: do not credit TX completions without a matching descriptor
  2026-12-04  6:42 ` netdev-bot+sinfo
@ 2026-12-04  7:13   ` guohongyu
  0 siblings, 0 replies; 3+ messages in thread
From: guohongyu @ 2026-12-04  7:13 UTC (permalink / raw)
  To: netdev-bot+sinfo; +Cc: netdev, Xuan Zhuo, Wen Gu, Philo Lu, 13057616121

Hi,

Answers to the questions:

The issue was found by manual code inspection of the eea driver
(commit aef5055e9764, new in v7.2). I was auditing the TX completion
path against the RX path and noticed the asymmetry: eea_rx_desc_to_ctx()
verifies the meta state (ctx->meta->in_use) before accepting a
completion, while eea_clean_tx() acks every completion it reads,
including one whose id has no in-flight descriptor.

The issue was not triggered at runtime. It needs a device to emit a
TX completion that maps to no in-flight descriptor (bogus or replayed
completion), which I have no way to produce. The impact statement in
the commit message follows from reading the code: the phantom credit
grows num_free past the free descriptors, the queue never stops, and
the next eea_tx_meta_get() returns NULL, which
__eea_tx_desc_fill() dereferences.

The change was not tested on real hardware. I have no EEA adapter.
The code compiles and there is no behavior change on the happy path
where every completion maps to an in-flight descriptor. Testing on
real EEA hardware would be appreciated.

Best regards,
Hongyu Guo



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-04  7:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  6:28 [PATCH] eea: do not credit TX completions without a matching descriptor Hongyu Guo
2026-12-04  6:42 ` netdev-bot+sinfo
2026-12-04  7:13   ` guohongyu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox