๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27270

Re: [PATCH] eea: do not credit TX completions without a matching descriptor

#27270
From: netdev-bot+sashiko
Date: Sat, 05 Dec 2026 06:50
196 lines
15404 bytes
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
Technical Details
Message-ID: <179645345464.3146.6215263158685742861@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377858-linux-kernel-netdev=dewy.ru
References: <20261204062855.344139-1-guohongyu@cmss.chinamobile.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377858-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH] eea: do not credit TX completions without a matching descriptor
Date: Sat, 05 Dec 2026 06:50:54 +0000
Organization: Usenet Network
Message-ID: <179645345464.3146.6215263158685742861@kernel.org>
References: <20261204062855.344139-1-guohongyu@cmss.chinamobile.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="2970944"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:vGIHkDV6JebFEbzB3nOsNAClMwU= sha256:UII13zxkEvBgSqZqC8kYckouCcDnAzcw6IL5L3h/mzc= sha1:6fBLb5WeqFRPz5Qy2MOcGeM1TF0= sha256:vry6wk5weRx2sLwnkZ/y9wML/66LO2hPtc2SbFSIe9E=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 23FEB117D88; Sat,  5 Dec 2026 09:51:19 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.641
X-Spam-Status: No, score=-3.641 tagged_above=-9999 required=6.31 tests=[DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9JedlCriKxxo; Sat,  5 Dec 2026 09:51:16 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-377858-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id E1B4C117D1F; Sat,  5 Dec 2026 09:51:05 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 3E9CB60666D; Sat,  5 Dec 2026 06:51:04 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796453461; b=DzoWcnrIc/qrrXqKSQNVZvMT+5GvF+PmwI92WXgXrjfhxlckqZK4qgp14zBr3UCEzM10 hROxod47hIRf460zHXYFMCYbsdkq7++EWU72czTwU9T1ScvWzLatrn9xgPAnlhABSXvWN 7ujnMwtzbYe9dPubIE/IOntZg4PS+Ji0+Uyw8DXKxqx0y1LYRZnfhXbkC8G/c7WAbQwBJ fH/sy2077aGccrz3tLHTTCV6JwihTSeAxxjQvqXvxDvTnuv13TsAJ0OkUO9MlBiNh8cm6 uJnlUqCUar3PgB21/MxQuoRPoE0wXzJG5v1E1zUAIIqDBjJBiqYWBjC26xSt/fydZpg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796453461; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=JHq4FZxQWEMYEGdK18tKrBWqTIvYppzhUWaHEtHvAp8=; b=SryBfjdnQ0uKk2EvqwRJqUfdKUkTw0Ui24W9JD+5Dxfng93Uko037EeFclG/CACS1A/n YloC8pURl9Gt5abXn7Z9O6l3B7PYiwLxcs4cjw8td2vUUc0njxqRVvx2rIqVJovzfo++c hLfbVt2BHkJlNhPkQax1fOIG8I6/7whEBdVxxYYe9B+KRwg0dZ6b71flOc2fWYH0Jwzby CsKv4uHRehDoeCxn9lSC8pcSl7j6t6LiYcT2E6hkKrpr6tWGqX6lU/yls7UHGU3Bggs7o 4UjWTzKBuKO6tZC8pHVo8wuAow5qZcDfU5Arq0/4MmVS3jy/eZNvFFMdffCpmcSVBVA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kbQpJtnb; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4924606A334; Sat,  5 Dec 2026 06:51:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kbQpJtnb
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796453455; b=RbtPMsqdouLL/GxBi02NYip3No2H1DOT9adKNjAvZjMh1bnrFbYXieKDCeaWDr7gAEq5 bcWC30jwIR/gEifMOset/OhNO+D+Bfp5GnQfAIncAtajHuRFjBrQmseX4Lhta8xf54yJ/ OF5iVh+TX8WLReSCg+NH7UlRG44Kql3wHL3l/gcL8VnEo2wI5VrCQ1+SgnfFjzvmwaGs+ iOe6J9j75KbN97QjOsBEEfhF14KuX8U8P478KzNZRDfJ+9W3+Ho2W/H8R/b4COMAoNz1f JiScqS0d6UsKD9IaDu5c7V7mx3vFiDz7YyEclxAdEuWVVcxj+rt/yRQ4XB35YJBtyDQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796453455; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=JHq4FZxQWEMYEGdK18tKrBWqTIvYppzhUWaHEtHvAp8=; b=ayovFXJD8SKi/afFCZ+gdR8QGRGXEzDaYmX0v81yvqUOQy4TlA1aHlG+DTpKaQHcoPnr Kj6KmPYFUYDT3w2B7R1UXHpUxETZt42h7ulsmBHLJL2MmHeqwCyimrL9CwQVvhPAnwxe+ uyToUjvDIUFEqrezR2c2P2Zrt88f6yUTRwxOZwrF1OH3eeJCWyi8xU6unLTaGOyf371HB RhfYzR70P1cUomk9vL2XpdXwwkmLbpUy/Htn/S6jzgrraX7OLHWcjghgQvUEpkawnjhcs Yvyr79Q/hrX0hWG5UhYll4Nfgj2VY30eF6T95qXjKWr7qXrHV3uqCgHPuS4nAwy8i7w==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kbQpJtnb; arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDF48606A322; Sat,  5 Dec 2026 06:50:55 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 298AD1F00A07; Sat,  5 Dec 2026 06:50:55 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796453455; bh=JHq4FZxQWEMYEGdK18tKrBWqTIvYppzhUWaHEtHvAp8=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=kbQpJtnbawf7iihmODBeX1EZ6GHuhsS5tRxly7J1nEh3toCSGB2Wxp7G3kLHaUxIS 5QsP5O1i/q/lOjPvtLnmK7+I6et8v7Ir+RLrzB4hTtU4a/89oeHsXfAzQknrFIK+94 EX6+yhc8lovtDoxhxNK6w4kc8ql4ygeVe5Yo+ME5H43oLCd9w0RmLMBRg39DtPU5Rx oOdRi5x4WYqBn+W3vaZi4SCnmkFMR7TMZ8ksyZ3luy+gbDuw7psnSe60WfcXphaA/v HvzwOzD6aFxD1uCIXzhCCo3fkV/PI1wHWzeoTk/+d68PggsXItxdiKSpruBWaKFAFF XI6FwEa4iRjdw==
X-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
X-In-Reply-To: <20261204062855.344139-1-guohongyu@cmss.chinamobile.com>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list