* [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
2026-12-05 6:50 ` netdev-bot+sashiko
0 siblings, 2 replies; 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-05 6:50 ` netdev-bot+sashiko
1 sibling, 0 replies; 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:28 [PATCH] eea: do not credit TX completions without a matching descriptor Hongyu Guo
2026-12-04 6:42 ` netdev-bot+sinfo
@ 2026-12-05 6:50 ` netdev-bot+sashiko
1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 6:50 UTC (permalink / raw)
To: guohongyu; +Cc: netdev, xuanzhuo, guwen, lulie, stable, 13057616121, kuba
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 1
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] Replayed completions are only partly handled, so the commit
message claims more than the patch covers.
- [Medium] The new error path in eea_tx_add_skb_frag() leaks the
fragment's DMA mapping.
- [Low] eea: duplicate CQ advance logic in eea_ering_cq_skip_desc()
--
eea: do not credit TX completions without a matching descriptor
This patch adds a new eea_ering_cq_skip_desc() helper. eea_clean_tx() uses
it to advance the CQ without crediting num_free when a completion has an
out of range id or points to a meta whose data is NULL. The patch also makes
__eea_tx_desc_fill() and eea_tx_desc_fill() fail when eea_tx_meta_get()
returns NULL, and adds error handling for that failure in the transmit path.
> diff --git a/drivers/net/ethernet/alibaba/eea/eea_tx.c b/drivers/net/ethernet/alibaba/eea/eea_tx.c
> index c9292bca1a8bd..cd48f852a94c7 100644
> --- a/drivers/net/ethernet/alibaba/eea/eea_tx.c
> +++ b/drivers/net/ethernet/alibaba/eea/eea_tx.c
[ ... ]
> @@ -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);
[Severity: Medium]
The commit message says this handles "a device that emits or replays TX
completions". What happens when a replayed completion carries an id that a
newer packet is already using?
The only validity check here is meta->data != NULL. The free list is LIFO.
eea_tx_meta_put_and_unmap() pushes the completed chain onto tx->free, and
eea_tx_meta_get() pops from the head. So the meta just freed for id X will
probably be the head meta of the next eea_tx_post_skb(), with meta->data
set to the new skb.
If the device then replays the completion for X, eea_clean_tx() takes this
branch for the new packet:
eea_clean_tx()
eea_tx_meta_put_and_unmap() <- unmaps the new packet's buffers
eea_meta_free_xmit() <- napi_consume_skb() on the new skb
eea_ering_cq_ack_desc(tx->ering, meta->num)
That credits num_free for SQ slots the device still owns. As a result,
eea_tx_check_free_num() can let more packets in, and
eea_ering_sq_alloc_desc() can overwrite descriptors the device has not
fetched yet.
When the real completion for the new packet arrives, it is either skipped
or it completes another reused packet too early.
The NULL dereference described in the commit message does look fixed,
because num_free now tracks the free-meta count. Could the commit message
be narrowed to the cases this patch handles? Alternatively, could a
stronger check be added here? One option is comparing meta->desc against
the SQ slot at cq->head, but that only works if the device always completes
strictly in order.
> } else {
> if (net_ratelimit())
> netdev_err(tx->enet->netdev,
> "tx meta->data is null. id %d num: %d\n",
> meta->id, meta->num);
[ ... ]
> @@ -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);
> + }
[ ... ]
> @@ -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;
[Severity: Medium]
Does this leak the fragment's DMA mapping?
The fragment is mapped with skb_frag_dma_map() just above. Suppose the
first __eea_tx_desc_fill() call in eea_tx_desc_fill() fails because
eea_tx_meta_get() returns NULL. Then eea_tx_desc_fill() returns NULL
through the new early return without unmapping addr, and this function
returns -ENOMEM.
The caller then jumps to err_cancel in eea_tx_post_skb():
err_cancel:
eea_ering_sq_cancel(tx->ering);
eea_tx_meta_put_and_unmap(tx, meta);
meta->data = NULL;
return err;
eea_tx_meta_put_and_unmap() only walks the head_meta chain. No meta for
this fragment was ever linked into that chain, so addr is never unmapped.
The new comment in eea_tx_desc_fill() says "For a chained fragment unmap
its mapping here", but only the second-half failure branch does that.
Should the first-half failure in eea_tx_desc_fill() also unmap addr when
head_meta is set, the same way the second-half branch does?
After this patch's accounting fix, running out of free metas may not happen
in normal operation, because eea_tx_xmit() checks num_free first. Still,
the new error path exists for exactly that case, and each time it is hit it
would leak an IOVA or swiotlb slot.
[ ... ]
> diff --git a/drivers/net/ethernet/alibaba/eea/eea_ring.c b/drivers/net/ethernet/alibaba/eea/eea_ring.c
> --- 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)
> {
[Severity: Low]
This new helper copies the CQ advance in eea_ering_cq_ack_desc()
line for line. Both bump cq->head and cq->hw_idx by num, wrap
cq->head at ering->num, and flip cq->phase. The only difference is
the ering->num_free += num at the end of the ack variant.
There is no runtime bug here. The concern is that the wraparound and
phase toggle now live in two places, so a later fix to one copy can
easily miss the other. Could eea_ering_cq_ack_desc() instead call
eea_ering_cq_skip_desc(ering, num) and then add num to
ering->num_free? A shared static helper used by both would also
work.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204062855.344139-1-guohongyu%40cmss.chinamobile.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-05 6:50 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-05 6:50 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox