From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 298AD1F00A07; Sat, 5 Dec 2026 06:50:55 +0000 (UTC) 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== Subject: Re: [PATCH] eea: do not credit TX completions without a matching descriptor 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 Date: Sat, 05 Dec 2026 06:50:54 +0000 Message-ID: <179645345464.3146.6215263158685742861@kernel.org> In-Reply-To: <20261204062855.344139-1-guohongyu@cmss.chinamobile.com> References: <20261204062855.344139-1-guohongyu@cmss.chinamobile.com> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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