From: netdev-bot+sashiko@kernel.org
To: guohongyu@cmss.chinamobile.com
Cc: netdev@vger.kernel.org, xuanzhuo@linux.alibaba.com,
guwen@linux.alibaba.com, lulie@linux.alibaba.com,
stable@vger.kernel.org, 13057616121@163.com, kuba@kernel.org
Subject: Re: [PATCH] eea: do not credit TX completions without a matching descriptor
Date: Sat, 05 Dec 2026 06:50:54 +0000 [thread overview]
Message-ID: <179645345464.3146.6215263158685742861@kernel.org> (raw)
In-Reply-To: <20261204062855.344139-1-guohongyu@cmss.chinamobile.com>
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
prev parent reply other threads:[~2026-12-05 6:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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
2026-12-05 6:50 ` netdev-bot+sashiko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179645345464.3146.6215263158685742861@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=13057616121@163.com \
--cc=guohongyu@cmss.chinamobile.com \
--cc=guwen@linux.alibaba.com \
--cc=kuba@kernel.org \
--cc=lulie@linux.alibaba.com \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox