From: netdev-bot+sashiko@kernel.org
To: tianx@yunsilicon.com
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, jgg@ziepe.ca,
leon@kernel.org, huangjunxian6@hisilicon.com,
weihg@yunsilicon.com, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
kerneljasonxing@gmail.com
Subject: Re: [PATCH v2 10/11] net/xsc: add the transmit path
Date: Fri, 27 Nov 2026 15:58:04 +0000 [thread overview]
Message-ID: <179579508443.3135.6949667103028918025@kernel.org> (raw)
In-Reply-To: <20261126145740.70868-11-tianx@yunsilicon.com>
Thank you for your contribution! Sashiko AI review found 7 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 5 · 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).
- [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…
- [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…
- [Medium] The SQ and its completion queue are sized from unrelated
capabilities, while the new TX path asks for one CQE per WQE and…
- [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 completion
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/drivers/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 data
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 = 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?
> +
> + if (unlikely(skb_is_nonlinear(skb) || skb->len == 0 ||
> + skb->len > sq->hw_mtu))
> + goto err_drop;
> +
> + pi = xsc_wq_cyc_ctr2ix(&sq->wq, sq->pc);
> + wqe = xsc_wq_cyc_get_wqe(&sq->wq, pi);
> + memset(wqe, 0, xdev->caps.send_ds_num * XSC_SEND_WQE_DS);
[ ... ]
> + cseg->data3 = cpu_to_le32(XSC_WQE_CTRL_SEG_DATA3_CE);
> + wqe->data[0].data0 =
> + cpu_to_le32(FIELD_PREP(XSC_WQE_DATA_SEG_DATA0_SEG_LEN_MASK,
> + skb->len));
> + wqe->data[0].va = 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 = 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 and
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 send
WQEs. Still, the two writers of this descriptor disagree. Could the TX path
set mkey to cpu_to_le32(XSC_INVALID_LKEY) the same way RX does?
> +
> + 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 = min_t(u32,
BIT(xdev->caps.log_max_qp_depth),
XSC_SQCQ_ELE_NUM);
...
} else if (type == XSC_QUEUE_TYPE_SQCQ) {
attr->ele_num = 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 1024
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?
> +
> + 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 driver
counter.
Successful sends aren't counted either. No tx_packets or tx_bytes are kept,
and xsc_netdev_ops has only ndo_open, ndo_stop and ndo_start_xmit, with no
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?
> + 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/drivers/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 = xsc_frag_buf_get_wqe(&wq->fbc,
> + xsc_cqwq_get_ci(wq));
> +
> + if (!!(le32_to_cpu(cqe->data1) & XSC_CQE_DATA1_OWNER) !=
> + (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 = 0;
> +
> + sq = container_of(cq, struct xsc_sq, cq);
> + if (!test_bit(XSC_ETH_SQ_STATE_ENABLED, &sq->state))
> + return 0;
> +
> + dev = sq->channel->adapter->dev;
> + sqcc = sq->cc;
> +
> + while (i < budget) {
> + struct xsc_tx_wqe_info *wi;
> + struct sk_buff *skb;
> +
> + cqe = 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 = &sq->wqe_info[xsc_wq_cyc_ctr2ix(&sq->wq, sqcc)];
> +
> + skb = wi->skb;
> + wi->skb = 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 = 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 == 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()?
[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 = 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 = sqcc
netif_tx_queue_stopped() == 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?
[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 = 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 == 0?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126145711.70868-1-tianx%40yunsilicon.com
next prev parent reply other threads:[~2026-11-27 15:58 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 14:57 [PATCH v2 00/11] net/xsc: add the Yunsilicon XSC ethernet driver Xin Tian
2026-11-26 14:57 ` [PATCH v2 01/11] net/xsc: add Yunsilicon XSC ethernet PCI driver Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 02/11] net/xsc: add doorbell and cmdq MMIO accessors Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 03/11] net/xsc: add the command queue Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 04/11] net/xsc: query HCA capabilities and reset function Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 05/11] net/xsc: add event queues and MSI-X Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 06/11] net/xsc: add CQ and QP helpers Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 07/11] net/xsc: add the ethernet netdev Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 08/11] net/xsc: add the single TX/RX channel Xin Tian
2026-11-27 15:58 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 09/11] net/xsc: report link state changes Xin Tian
2026-11-27 15:58 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 10/11] net/xsc: add the transmit path Xin Tian
2026-11-27 15:58 ` netdev-bot+sashiko [this message]
2026-11-26 14:57 ` [PATCH v2 11/11] net/xsc: add the receive path Xin Tian
2026-11-27 15:58 ` netdev-bot+sashiko
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=179579508443.3135.6949667103028918025@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=huangjunxian6@hisilicon.com \
--cc=jgg@ziepe.ca \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tianx@yunsilicon.com \
--cc=weihg@yunsilicon.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
all inboxes | Powered by JetHome®