From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.127.231.28 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796554857; b=K6EuEYK+aMQa5bW9B7nJv3UDJhQS0HtiXwsaXD64a8o1QbCBokJBBjYh2cNIiXmV+y53 zfyADQoQx19VVWLUK/PwH70pND1HkoYnEOizuI+rFy4jv9zmOrRrJN/NW0BdexUiUpAAP BNduBCt9AtBZcMq8JQ9QWrAHpSp99gyZcEeFGaKpV1jOs5ui3nkSFAPS7V492u/aWNCF+ 9mqU4J/w3DyJN5fZsb5vuIjyA4991xpKNJrF3P2m3INg4xJ98//RDPtAzn6PGC+bK/EVR yukXNcgEJyaTM30DsoOBf3V9N0WLMPJ35NGl12Ymov3PK0fnkao8T5B84hfdy6kvKag== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796554857; h=DMARC-Filter:DKIM-Signature:References:Subject:Content-Type: User-Agent:To:From:Received:In-Reply-To:Cc:Date:Message-Id: Mime-Version:X-Original-From:Content-Transfer-Encoding: X-Lms-Return-Path; bh=pHe3FwklBjXQodnivizVX78TrdmUvRsyZHjfbtcQ1kg=; b=xr1MtigkjVrRv02PQMfUYPgimXvdYyB2Vym6imKzhVBTotwNEXzQu789KEQmY//r+9b/ 1082KdzGUOnYJPkGzMVd9Vu001HwQ6Vy2jwnqt2P+fUxzPulIBEFIKhIDt4puCTV4507v 1KPSRAm1ow4o5eyVraO1YMucrQXSe09Qee/jXgct+i8BaLZxuTMb5PdIE7Z6in/S6wJwE FxBA+dlYp1qBLm0YTyRpqkaYKB4MF37xQ6JC6sjXwIQXJLyIkWDWKWuqfYu7R/9QRceDn 8OxMuD8eg6Z2aAG0iXs87lUK0CYwDOetYdgPb2Z0d3GviILmvmdJAm4AOlvf/sZdcjg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=yunsilicon.com; spf=pass smtp.mailfrom=yunsilicon.com; dkim=pass header.d=yunsilicon.com header.i=@yunsilicon.com header.a=rsa-sha256 header.s=feishu2403070942 header.b="Xrh/unG4"; arc=none smtp.remote-ip=209.127.231.28 Received: from va-2-28.ptr.blmpb.com (va-2-28.ptr.blmpb.com [209.127.231.28]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9F6D606A31F for ; Sun, 6 Dec 2026 11:00:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E9F6D606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=yunsilicon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yunsilicon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=yunsilicon.com header.i=@yunsilicon.com header.a=rsa-sha256 header.s=feishu2403070942 header.b=Xrh/unG4 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=feishu2403070942; d=yunsilicon.com; t=1796554851; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=pHe3FwklBjXQodnivizVX78TrdmUvRsyZHjfbtcQ1kg=; b=Xrh/unG4BwOFNmjCJxHnihjiYwBnu1kje4z4rUycicaSzfZmf6C4dbjxfwfYpViTEwVPie iwd87MtD9B+5iAr7dqRPYzUDHA10kUz8ZBcBBOheVldGWsLz4XbrmxnPdfgB2H+RYqbjYy 2JgPHCioaOVNetBuRZYF7FXoUdV95j+MCXS4dmJRSRxAXlrBxALUuUe+KamFORFpxoNfrL 5mCABAKAX/sK2KJIWL+Yvr8InygrikW2gVgKzX//yU4zabHZSPmTj1BA/C0QzKwSKXdbcc tf2a3vo1+F/mQS9BriWgTEACRzAp2MV5uVgU0jPUr8jUFCv1GZY9o4bD6jbr5Q== References: <20261126145740.70868-11-tianx@yunsilicon.com> <179579508443.3135.6949667103028918025@kernel.org> Subject: Re: [PATCH v2 10/11] net/xsc: add the transmit path Content-Type: text/plain; charset=UTF-8 User-Agent: Mozilla Thunderbird To: From: "Xin Tian" Received: from [127.0.0.1] ([183.193.56.225]) by smtp.feishu.cn with ESMTPS; Sun, 06 Dec 2026 19:00:48 +0800 In-Reply-To: <179579508443.3135.6949667103028918025@kernel.org> Cc: , , , , , , , , , , , , Date: Sun, 6 Dec 2026 19:00:46 +0800 Message-Id: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Original-From: Xin Tian Content-Transfer-Encoding: quoted-printable X-Lms-Return-Path: On 11/27/2026 11:58 PM, netdev-bot+sashiko@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 7 potential > issue(s) to consider. > > Critical: 0 =C2=B7 High: 1 =C2=B7 Medium: 5 =C2=B7 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 patchwor= k > know by including "pw-bot: cr" as a separate line at the end of your repl= y > (one such reply per series is enough). > > - [High] net/xsc: lockless TX queue stop/wake race in xsc_eth_xmit() > - [Medium] The new transmit path in xsc_eth_xmit() > (drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_tx.c) drops frames=E2= =80=A6 > - [Medium] The RX and TX paths fill the same hardware descriptor, struct > xsc_wqe_data_seg, with a raw DMA address in ->va, but they set ->mkey= =E2=80=A6 > - [Medium] The SQ and its completion queue are sized from unrelated > capabilities, while the new TX path asks for one CQE per WQE and=E2=80= =A6 > - [Medium] net/xsc: unconditional CQ doorbell MMIO write in > xsc_poll_tx_cq() > - [Medium] net/xsc: xsc_poll_tx_cq() frees completed TX skbs with > dev_kfree_skb_any() > - [Low] xsc_eth_xmit() starts with `if (!adapter->opened) return > NETDEV_TX_BUSY;`. > > -- > > net/xsc: add the transmit path > > This adds an ndo_start_xmit implementation to the xsc ethernet driver. It > posts linear skbs to the send queue and rings the doorbell. A TX completi= on > handler unmaps and frees the skbs once they have been sent. > >> diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_tx.c b/driv= ers/net/ethernet/yunsilicon/xsc/net/xsc_eth_tx.c >> new file mode 100644 >> index 0000000000000..580af1f231056 >> --- /dev/null >> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_tx.c >> @@ -0,0 +1,87 @@ > [ ... ] > >> +netdev_tx_t xsc_eth_xmit(struct sk_buff *skb, struct net_device *netdev= ) >> +{ > [ ... ] > >> + if (!adapter->opened) >> + return NETDEV_TX_BUSY; > [Severity: Low] > Is this check needed? adapter->opened is a plain bool. xsc_eth_open() and > xsc_eth_close() write it without WRITE_ONCE(), and this code reads it > without a lock or READ_ONCE(). KCSAN would likely report the pair as a da= ta > race. > > On close, the core has already quiesced TX before ndo_stop runs. > > On open, the queue is woken and the carrier is turned on before the flag = is > set: > > xsc_eth_activate_channel() > netif_tx_start_queue(psq->txq); > ... > xsc_eth_open() > netif_carrier_on(adapter->netdev); > ... > adapter->opened =3D true; > > In that window, could a PACKET_QDISC_BYPASS sender going through > __dev_direct_xmit() reach xsc_eth_xmit()? It would get NETDEV_TX_BUSY on = an > awake queue, and its skb would be dropped. > > The driver API also discourages returning NETDEV_TX_BUSY without stopping > the queue. Could this check be removed so that queue start/stop ordering > handles it, or could the accesses at least be annotated? Keeping it as a cheap guard, but read with READ_ONCE(); the stop/wake ordering doesn't depend on it anymore. >> + >> + if (unlikely(skb_is_nonlinear(skb) || skb->len =3D=3D 0 || >> + skb->len > sq->hw_mtu)) >> + goto err_drop; >> + >> + pi =3D xsc_wq_cyc_ctr2ix(&sq->wq, sq->pc); >> + wqe =3D xsc_wq_cyc_get_wqe(&sq->wq, pi); >> + memset(wqe, 0, xdev->caps.send_ds_num * XSC_SEND_WQE_DS); > [ ... ] > >> + cseg->data3 =3D cpu_to_le32(XSC_WQE_CTRL_SEG_DATA3_CE); >> + wqe->data[0].data0 =3D >> + cpu_to_le32(FIELD_PREP(XSC_WQE_DATA_SEG_DATA0_SEG_LEN_MASK, >> + skb->len)); >> + wqe->data[0].va =3D cpu_to_le64(dma_addr); > [Severity: Medium] > Should data[0].mkey be set here too? The memset() leaves it at 0. > > The RX path fills the same struct xsc_wqe_data_seg with a raw DMA address > and marks it with XSC_INVALID_LKEY: > > drivers/net/ethernet/yunsilicon/xsc/net/main.c:xsc_eth_alloc_rq() { > ... > wqe->data[0].mkey =3D cpu_to_le32(XSC_INVALID_LKEY); > ... > } > > Suppose the device treats any mkey other than XSC_INVALID_LKEY (0x100) as= a > real memory key. Would every TX descriptor then be checked against MR 0 a= nd > complete with an error, or put the wrong data on the wire? > > The tree doesn't show whether the hardware reads mkey on raw ethernet sen= d > WQEs. Still, the two writers of this descriptor disagree. Could the TX pa= th > set mkey to cpu_to_le32(XSC_INVALID_LKEY) the same way RX does? The two encodings are the same thing in hardware, but changed so they read the same: the MPT index is mkey >> 17 and both 0 and 0x100 (XSC_INVALID_LKEY) give 0, the reserved local-DMA MPT[0]. There is no MR table in this driver so that's the only entry either encoding can hit. TX now writes XSC_INVALID_LKEY explicitly instead of relying on the memset leaving 0. >> + >> + sq->pc++; >> + if (unlikely(!xsc_wqc_has_room_for(&sq->wq, sq->cc, sq->pc, >> + sq->stop_room))) >> + netif_tx_stop_queue(sq->txq); > [Severity: Medium] > Can the SQ completion queue overflow here? Every WQE sets > XSC_WQE_CTRL_SEG_DATA3_CE, so every posted WQE produces a CQE. The queue > is only stopped when the SQ ring itself is full. > > xsc_eth_build_queue_param() sizes the SQ and its CQ from different > capabilities: > > adapter->nic_param.sq_size =3D min_t(u32, > BIT(xdev->caps.log_max_qp_depth), > XSC_SQCQ_ELE_NUM); > ... > } else if (type =3D=3D XSC_QUEUE_TYPE_SQCQ) { > attr->ele_num =3D min_t(int, XSC_SQCQ_ELE_NUM, > xdev->caps.max_cqes); > > caps.max_cqes is 1 << log_max_cq_sz as reported by firmware. If > log_max_cq_sz is below 10 while log_max_qp_depth is 10 or more, up to 102= 4 > WQEs, and so up to 1024 CQEs, can be outstanding against a smaller CQ > before NAPI reaps them. > > If that happens, the CQ error event would only be logged by > xsc_eth_cq_error_event(), and TX completions would stall. > > Neither xsc_eth_xmit() nor xsc_wqc_has_room_for() takes the CQ capacity > into account. Should sq_size be clamped to the SQ CQ size? Fixed, every ring is now clamped to its CQ size (one CQE per WQE). >> + >> + if (!netdev_xmit_more() || netif_xmit_stopped(sq->txq)) >> + xsc_update_tx_db(xdev, sq->sqn, sq->pc << ds_num_log); >> + >> + return NETDEV_TX_OK; >> + >> +err_drop: >> + dev_kfree_skb_any(skb); > [Severity: Medium] > Are these drops counted anywhere? Four cases end up here: non-linear skbs= , > zero-length skbs, skbs longer than sq->hw_mtu, and dma_map_single() > failures. Nothing calls dev_core_stats_tx_dropped_inc() or updates a driv= er > counter. > > Successful sends aren't counted either. No tx_packets or tx_bytes are kep= t, > and xsc_netdev_ops has only ndo_open, ndo_stop and ndo_start_xmit, with n= o > ndo_get_stats64. This seems to still be the case after the later commit > "net/xsc: add the receive path". > > Won't ip -s link then show no TX activity and no TX drops for this device= , > even when DMA mapping fails or frames are rejected? Intentional for now, it's a minimal data path (single channel, fixed MTU, no XDP). Stats will land as one set (ethtool + ndo_get_stats64) rather than an isolated TX counter. >> + if (!netdev_xmit_more() || netif_xmit_stopped(sq->txq)) >> + xsc_update_tx_db(xdev, sq->sqn, sq->pc << ds_num_log); >> + return NETDEV_TX_OK; >> +} > [ ... ] > >> diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_txrx.c b/dr= ivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_txrx.c >> --- /dev/null >> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/xsc_eth_txrx.c >> @@ -0,0 +1,70 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> +/* Copyright (C) 2021-2026, Shanghai Yunsilicon Technology Co., Ltd. >> + * All rights reserved. >> + */ >> + >> +#include "xsc_eth.h" >> +#include "xsc_eth_txrx.h" >> + >> +struct xsc_cqe *xsc_cqwq_get_cqe(struct xsc_cqwq *wq) >> +{ >> + struct xsc_cqe *cqe =3D xsc_frag_buf_get_wqe(&wq->fbc, >> + xsc_cqwq_get_ci(wq)); >> + >> + if (!!(le32_to_cpu(cqe->data1) & XSC_CQE_DATA1_OWNER) !=3D >> + (xsc_cqwq_get_wrap_cnt(wq) & 1)) >> + return NULL; >> + >> + return cqe; >> +} >> + >> +int xsc_poll_tx_cq(struct xsc_cq *cq, int budget) >> +{ >> + struct xsc_cqe *cqe; >> + struct device *dev; >> + struct xsc_sq *sq; >> + u16 sqcc; >> + int i =3D 0; >> + >> + sq =3D container_of(cq, struct xsc_sq, cq); >> + if (!test_bit(XSC_ETH_SQ_STATE_ENABLED, &sq->state)) >> + return 0; >> + >> + dev =3D sq->channel->adapter->dev; >> + sqcc =3D sq->cc; >> + >> + while (i < budget) { >> + struct xsc_tx_wqe_info *wi; >> + struct sk_buff *skb; >> + >> + cqe =3D xsc_cqwq_get_cqe(&cq->wq); >> + if (!cqe) >> + break; >> + /* ensure cqe content is read after cqe ownership bit */ >> + dma_rmb(); >> + >> + xsc_cqwq_pop(&cq->wq); >> + wi =3D &sq->wqe_info[xsc_wq_cyc_ctr2ix(&sq->wq, sqcc)]; >> + >> + skb =3D wi->skb; >> + wi->skb =3D NULL; >> + if (skb) { >> + dma_unmap_single(dev, wi->dma_addr, skb->len, >> + DMA_TO_DEVICE); >> + dev_kfree_skb_any(skb); >> + } >> + >> + sqcc++; >> + i++; >> + } >> + >> + xsc_update_cq_ci(cq->xdev, cq->xcq.cqn, cq->wq.cc); >> + >> + sq->cc =3D sqcc; >> + >> + if (netif_tx_queue_stopped(sq->txq) && >> + xsc_wqc_has_room_for(&sq->wq, sq->cc, sq->pc, sq->stop_room)) >> + netif_tx_wake_queue(sq->txq); >> + >> + return i =3D=3D budget; >> +} > [Severity: Medium] > Is dev_kfree_skb_any() the right call for a completed TX skb? It goes > through dev_kfree_skb_any_reason() with SKB_DROP_REASON_NOT_SPECIFIED. > Every frame that was transmitted successfully would then be reported > as a drop by the skb:kfree_skb tracepoint and by drop_monitor. > > This runs from the channel NAPI poll, so napi_consume_skb() would > account the skb as consumed. It would also let the skb use the NAPI > bulk free path. That needs the NAPI budget to reach > xsc_poll_tx_cq(), with a budget of 0 passed through when called from > netpoll. Would napi_consume_skb(skb, budget) work here, or at least > dev_consume_skb_any()? Fixed, switched to napi_consume_skb(skb, budget). > [Severity: High] > What orders the queue stop in xsc_eth_xmit() against the wake here? > xsc_poll_tx_cq() runs from NAPI without the TX queue lock. Neither > side has the barriers that netif_txq_maybe_stop() and > netif_txq_completed_wake() provide. > > In xsc_eth_xmit(), netif_tx_stop_queue() is called based on a plain > read of sq->cc. There is no smp_mb__after_atomic() and no re-check > of xsc_wqc_has_room_for() afterwards. Here, sq->cc =3D sqcc is followed > directly by netif_tx_queue_stopped() with no smp_mb() in between. > Couldn't this interleave as: > > CPU0 (xsc_eth_xmit) CPU1 (xsc_poll_tx_cq) > reads old sq->cc, ring full > sq->cc =3D sqcc > netif_tx_queue_stopped() =3D=3D false > netif_tx_stop_queue() > > That would leave the queue stopped with free descriptors and no > further completions to wake it. > > The other direction looks worse. Suppose this function observes > __QUEUE_STATE_DRV_XOFF but loads a stale sq->pc from before the > final post. It can then call netif_tx_wake_queue() on a full ring, > even on a poll that reaped no CQEs. Nothing orders the state bit > test before the sq->pc load. > > xsc_eth_xmit() never checks for room before deriving pi from sq->pc. > The next frame would then overwrite the WQE and sq->wqe_info[pi] of a > descriptor the device still owns, leaking that skb and its DMA > mapping. Once sq->pc is more than a ring size ahead of sq->cc, > xsc_wqc_has_room_for() wraps and reports room again. The queue would > stay awake and keep overwriting in-flight entries. > > Would it make sense to use netif_txq_maybe_stop() and > netif_txq_completed_wake() from include/net/netdev_queues.h? That > would go with READ_ONCE()/WRITE_ONCE() on sq->cc and sq->pc. Could > xsc_eth_xmit() also stop the queue and return NETDEV_TX_BUSY if it is > ever entered without room? Agreed, reworked the whole stop/wake path: free descriptors come from xsc_sq_free_desc(), xmit stops via netif_txq_maybe_stop() and returns NETDEV_TX_BUSY before advancing pi, pc is published with WRITE_ONCE and maybe_stop is re-checked, the doorbell keys off __netdev_tx_sent_queue(), and the poll side does WRITE_ONCE(cc) then netif_txq_completed_wake(). xsc_free_tx_wqe() drains netdev_tx_completed_queue() so dql stays exact. > [Severity: Medium] > Does this need to ring the CQ consumer doorbell when nothing was > reaped? If xsc_cqwq_get_cqe() returns NULL on the first iteration, > i is 0 and cq->wq.cc has not moved. xsc_update_cq_ci() still issues > a wmb() and an uncached writel() to DB_CQ_CID_DIRECT_MEM_ADDR. > > The channel NAPI poll will call this on every pass, including passes > that only have RX work. With RX-heavy traffic or idle TX, most of > these MMIO writes would be redundant. The sq->cc =3D sqcc store is also > unconditional and dirties the cacheline that xsc_eth_xmit() reads on > the transmitting CPU. > > Could the doorbell and the sq->cc update be skipped when i =3D=3D 0? Fixed in the stop/wake rework, zero reaps now return early before the doorbell and the cc update. Thanks, Xin